Skip to content

Commit

Permalink
feat: add maxNumProviders to findprovs (#283)
Browse files Browse the repository at this point in the history
* feat: add maxNumProviders to findprovs

* chore: upgrade libp2p-kad-dht
  • Loading branch information
vasco-santos authored and jacobheun committed Nov 13, 2018
1 parent 714b6ec commit 970deec
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,12 @@ Required keys in the `options` object:
- `key`: Buffer
- `options`: object of options
- `options.maxTimeout`: Number milliseconds
- `options.maxNumProviders` maximum number of providers to find

#### `libp2p.contentRouting.provide(key, callback)`

- `key`: Buffer


#### `libp2p.handle(protocol, handlerFunc [, matchFunc])`

> Handle new protocol
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"libp2p-circuit": "~0.3.0",
"libp2p-delegated-content-routing": "~0.2.2",
"libp2p-delegated-peer-routing": "~0.2.2",
"libp2p-kad-dht": "~0.10.6",
"libp2p-kad-dht": "~0.11.1",
"libp2p-mdns": "~0.12.0",
"libp2p-mplex": "~0.8.2",
"libp2p-secio": "~0.10.1",
Expand Down
1 change: 1 addition & 0 deletions src/content-routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = (node) => {
* @param {CID} key The CID key of the content to find
* @param {object} options
* @param {number} options.maxTimeout How long the query should run
* @param {number} options.maxNumProviders - maximum number of providers to find
* @param {function(Error, Result<Array>)} callback
* @returns {void}
*/
Expand Down
16 changes: 16 additions & 0 deletions test/content-routing.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ describe('.contentRouting', () => {
})
})

it('nodeE.contentRouting.findProviders with limited number of providers', (done) => {
parallel([
(cb) => nodeA.contentRouting.provide(cid, cb),
(cb) => nodeB.contentRouting.provide(cid, cb),
(cb) => nodeC.contentRouting.provide(cid, cb)
], (err) => {
expect(err).to.not.exist()

nodeE.contentRouting.findProviders(cid, { maxNumProviders: 2 }, (err, providers) => {
expect(err).to.not.exist()
expect(providers).to.have.length(2)
done()
})
})
})

it('nodeC.contentRouting.findProviders for non existing record (timeout)', (done) => {
const cid = new CID('QmTp9VkYvnHyrqKQuFPiuZkiX9gPcqj6x5LJ1rmWuSnnnn')

Expand Down

0 comments on commit 970deec

Please sign in to comment.