Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

fix: false discovery #92

Merged
merged 2 commits into from
Mar 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
})
Expand Down
25 changes: 0 additions & 25 deletions test/kad-dht.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
23 changes: 23 additions & 0 deletions test/query.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
})