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

Commit

Permalink
fix: find providers should yield when found locally (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Dec 5, 2019
1 parent f975bad commit e40834a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
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

0 comments on commit e40834a

Please sign in to comment.