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

Commit e40834a

Browse files
authored
fix: find providers should yield when found locally (#160)
1 parent f975bad commit e40834a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/content-routing/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ module.exports = (dht) => {
9191

9292
// All done
9393
if (out.length >= n) {
94-
return out.toArray()
94+
// yield values
95+
for (const pInfo of out.toArray()) {
96+
yield pInfo
97+
}
98+
return
9599
}
96100

97101
// need more, query the network

test/kad-dht.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,23 @@ describe('KadDHT', () => {
484484

485485
return tdht.teardown()
486486
})
487+
488+
it('find one provider locally', async function () {
489+
this.timeout(20 * 1000)
490+
const val = values[0]
491+
const tdht = new TestDHT()
492+
const [dht] = await tdht.spawn(1)
493+
494+
sinon.stub(dht.providers, 'getProviders').returns([dht.peerInfo.id])
495+
496+
// Find provider
497+
const res = await all(dht.findProviders(val.cid, { maxNumProviders: 1 }))
498+
499+
expect(res).to.exist()
500+
expect(res).to.have.length(1)
501+
502+
return tdht.teardown()
503+
})
487504
})
488505

489506
describe('peer routing', () => {

0 commit comments

Comments
 (0)