bittorrent-dht
Advanced tools
Comparing version 2.7.1 to 2.7.2
@@ -470,2 +470,3 @@ module.exports = DHT | ||
var self = this | ||
id = idToBuffer(id) | ||
if (typeof opts === 'function') { | ||
@@ -475,3 +476,2 @@ cb = opts | ||
} | ||
id = idToBuffer(id) | ||
if (!opts) opts = {} | ||
@@ -487,2 +487,12 @@ if (!cb) cb = function () {} | ||
// Return local peers, if we have any in our table | ||
var peers = self.peers[idHex] && self.peers[idHex] | ||
if (peers) { | ||
peers = parsePeerInfo(peers.list) | ||
peers.forEach(function (peerAddr) { | ||
self._debug('emit peer %s %s from %s', peerAddr, idHex, 'local') | ||
self.emit('peer', peerAddr, idHex, 'local') | ||
}) | ||
} | ||
var table = new KBucket({ | ||
@@ -850,3 +860,3 @@ localNodeId: id, | ||
res.values.forEach(function (peerAddr) { | ||
self._debug('emit peer %s %s from %s', infoHashHex, peerAddr, addr) | ||
self._debug('emit peer %s %s from %s', peerAddr, infoHashHex, addr) | ||
self.emit('peer', peerAddr, infoHashHex, addr) | ||
@@ -853,0 +863,0 @@ }) |
{ | ||
"name": "bittorrent-dht", | ||
"description": "Simple, robust, BitTorrent DHT implementation", | ||
"version": "2.7.1", | ||
"version": "2.7.2", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Feross Aboukhadijeh", |
@@ -6,4 +6,4 @@ var test = require('tape') | ||
test('announce+lookup with 3-10 DHTs', function (t) { | ||
var from = 3 | ||
test('announce+lookup with 2-10 DHTs', function (t) { | ||
var from = 2 | ||
var to = 10 | ||
@@ -28,4 +28,6 @@ | ||
dht.destroy(function () { | ||
if (--numRunning === 0) t.end() | ||
process.nextTick(function () { | ||
dht.destroy(function () { | ||
if (--numRunning === 0) t.end() | ||
}) | ||
}) | ||
@@ -66,5 +68,17 @@ }) | ||
makeFriends(dhts) | ||
dhts[0].announce(infoHash, 9998, function () { | ||
dhts[1].lookup(infoHash) | ||
}) | ||
if (numInstances === 2) { | ||
// dhts[1] is the only one with the data, lookup() should find it in it's internal | ||
// table | ||
dhts[0].announce(infoHash, 9998) | ||
// wait until dhts[1] gets the announce from dhts[1] | ||
dhts[1].on('announce', function () { | ||
dhts[1].lookup(infoHash) | ||
}) | ||
} else { | ||
// lookup from other DHTs | ||
dhts[0].announce(infoHash, 9998, function () { | ||
dhts[1].lookup(infoHash) | ||
}) | ||
} | ||
}) | ||
@@ -71,0 +85,0 @@ |
57822
1547