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

fix: find providers should yield when found locally #160

Merged
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
6 changes: 5 additions & 1 deletion src/content-routing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ module.exports = (dht) => {

// All done
if (out.length >= n) {
return out.toArray()
// yield values
for (const pInfo of out.toArray()) {
yield pInfo
}
return
}

// need more, query the network
Expand Down
17 changes: 17 additions & 0 deletions test/kad-dht.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,23 @@ describe('KadDHT', () => {

return tdht.teardown()
})

it('find one provider locally', async function () {
this.timeout(20 * 1000)
const val = values[0]
const tdht = new TestDHT()
const [dht] = await tdht.spawn(1)

sinon.stub(dht.providers, 'getProviders').returns([dht.peerInfo.id])

// Find provider
const res = await all(dht.findProviders(val.cid, { maxNumProviders: 1 }))

expect(res).to.exist()
expect(res).to.have.length(1)

return tdht.teardown()
})
})

describe('peer routing', () => {
Expand Down