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

Commit

Permalink
fix: get many should not fail if found locally (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos authored Dec 6, 2019
1 parent 6bc9bcf commit 091db13
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/content-fetching/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ module.exports = (dht) => {
const errMsg = 'Failed to lookup key! No peers from routing table!'

dht._log.error(errMsg)
throw errcode(new Error(errMsg), 'ERR_NO_PEERS_IN_ROUTING_TABLE')
if (vals.length === 0) {
throw errcode(new Error(errMsg), 'ERR_NO_PEERS_IN_ROUTING_TABLE')
}
return vals
}

// we have peers, lets do the actual query to them
Expand Down
18 changes: 18 additions & 0 deletions test/kad-dht.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ describe('KadDHT', () => {
})

describe('content fetching', () => {
it('put - get same node', async function () {
this.timeout(10 * 1000)

const tdht = new TestDHT()
const key = Buffer.from('/v/hello')
const value = Buffer.from('world')

const [dht] = await tdht.spawn(2)

// Exchange data through the dht
await dht.put(key, value)

const res = await dht.get(Buffer.from('/v/hello'), { timeout: 1000 })
expect(res).to.eql(value)

return tdht.teardown()
})

it('put - get', async function () {
this.timeout(10 * 1000)

Expand Down

0 comments on commit 091db13

Please sign in to comment.