Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist DHT nodes #1431

Open
wants to merge 9 commits into
base: master
from

Distinguish addresses in DHT persistence test

Uses loopback for the test DHT server, a local address provided
by the network-address module for the client. This is the pattern
used in other tests.
  • Loading branch information
bookmoons committed Jul 30, 2018
commit 2852b671575a3bd76bb4e81d07dd5de9e7e0ba7f
@@ -1,33 +1,35 @@
var test = require('tape')
var tmp = require('tmp')
var fs = require('fs')
var networkAddress = require('network-address')
var DHT = require('bittorrent-dht/server')
var WebTorrent = require('../../')

var localHost = '127.0.0.1'
var loopback = '127.0.0.1'
var localAddress = networkAddress.ipv4()
var port = 9999

test('Save DHT state', function (t) {
test.only('Save DHT state', function (t) {
t.plan(4)
var saveFile = tmp.tmpNameSync()
var dhtServer = new DHT({ bootstrap: false })
dhtServer.on('error', function (err) { t.fail(err) })
dhtServer.on('warning', function (err) { t.fail(err) })
dhtServer.listen(port, function handleServerListening () {
var client = new WebTorrent({
dht: { bootstrap: false },
dht: { bootstrap: false, host: localAddress },
dhtState: saveFile
})
client.on('error', function (err) { t.fail(err) })
client.on('warning', function (err) { t.fail(err) })
client.dht.addNode({ host: localHost, port: port })
client.dht.addNode({ host: loopback, port: port })
client.dht.on('node', function handleNodeAdded () {
client.saveDhtState(function handleDhtStateSaved () {
var dhtStateJson = fs.readFileSync(saveFile)
var dhtState = JSON.parse(dhtStateJson)
var nodes = dhtState.nodes
var node = nodes[0]
t.equal(node.host, localHost)
t.equal(node.host, loopback)
t.equal(node.port, port)
client.destroy(function handleClientDestroyed (err) {
t.error(err, 'client destroyed')
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.