diff --git a/src/network.js b/src/network.js index 29781ec8..edf7f234 100644 --- a/src/network.js +++ b/src/network.js @@ -122,8 +122,6 @@ class Network { return this._log.error('Failed to add to the routing table', err) } - this.dht._peerDiscovered(peer) - this._log('added to the routing table: %s', peer.id.toB58String()) }) }) diff --git a/test/kad-dht.spec.js b/test/kad-dht.spec.js index 79293be9..285f3fd0 100644 --- a/test/kad-dht.spec.js +++ b/test/kad-dht.spec.js @@ -257,31 +257,6 @@ describe('KadDHT', () => { }) }) - it('should emit a peer event when a peer is connected', function (done) { - this.timeout(10 * 1000) - const tdht = new TestDHT() - - tdht.spawn(2, (err, dhts) => { - expect(err).to.not.exist() - const dhtA = dhts[0] - const dhtB = dhts[1] - - dhtA.on('peer', (peerInfo) => { - expect(peerInfo).to.exist().mark() - }) - - dhtB.on('peer', (peerInfo) => { - expect(peerInfo).to.exist().mark() - }) - - connect(dhtA, dhtB, (err) => { - expect(err).to.not.exist() - }) - }) - - expect(2).checks(done) - }) - it('put - get', function (done) { this.timeout(10 * 1000) const tdht = new TestDHT() diff --git a/test/query.spec.js b/test/query.spec.js index 778ee684..946d1ddd 100644 --- a/test/query.spec.js +++ b/test/query.spec.js @@ -157,4 +157,27 @@ describe('Query', () => { }) }) }) + + it('should discover closer peers', (done) => { + const peer = peerInfos[0] + + // mock this so we can dial non existing peers + dht.switch.dial = (peer, callback) => callback() + + const query = (p, cb) => { + cb(null, { + closerPeers: [peerInfos[2]] + }) + } + + const q = new Query(dht, peer.id.id, () => query) + q.run([peerInfos[1].id], (err, res) => { + expect(err).to.not.exist() + }) + + dht.once('peer', (peerInfo) => { + expect(peerInfo.id).to.eql(peerInfos[2].id) + done() + }) + }) })