feat: add maxNumProviders to findprovs (#283)

* feat: add maxNumProviders to findprovs

* chore: upgrade libp2p-kad-dht
This commit is contained in:
Vasco Santos 2018-11-13 10:46:51 +00:00 committed by Jacob Heun
parent 714b6ec2b9
commit 970deec2a4
4 changed files with 19 additions and 2 deletions

View File

@ -261,12 +261,12 @@ Required keys in the `options` object:
- `key`: Buffer - `key`: Buffer
- `options`: object of options - `options`: object of options
- `options.maxTimeout`: Number milliseconds - `options.maxTimeout`: Number milliseconds
- `options.maxNumProviders` maximum number of providers to find
#### `libp2p.contentRouting.provide(key, callback)` #### `libp2p.contentRouting.provide(key, callback)`
- `key`: Buffer - `key`: Buffer
#### `libp2p.handle(protocol, handlerFunc [, matchFunc])` #### `libp2p.handle(protocol, handlerFunc [, matchFunc])`
> Handle new protocol > Handle new protocol

View File

@ -67,7 +67,7 @@
"libp2p-circuit": "~0.3.0", "libp2p-circuit": "~0.3.0",
"libp2p-delegated-content-routing": "~0.2.2", "libp2p-delegated-content-routing": "~0.2.2",
"libp2p-delegated-peer-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-mdns": "~0.12.0",
"libp2p-mplex": "~0.8.2", "libp2p-mplex": "~0.8.2",
"libp2p-secio": "~0.10.1", "libp2p-secio": "~0.10.1",

View File

@ -20,6 +20,7 @@ module.exports = (node) => {
* @param {CID} key The CID key of the content to find * @param {CID} key The CID key of the content to find
* @param {object} options * @param {object} options
* @param {number} options.maxTimeout How long the query should run * @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 * @param {function(Error, Result<Array>)} callback
* @returns {void} * @returns {void}
*/ */

View File

@ -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) => { it('nodeC.contentRouting.findProviders for non existing record (timeout)', (done) => {
const cid = new CID('QmTp9VkYvnHyrqKQuFPiuZkiX9gPcqj6x5LJ1rmWuSnnnn') const cid = new CID('QmTp9VkYvnHyrqKQuFPiuZkiX9gPcqj6x5LJ1rmWuSnnnn')