mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-25 10:32:14 +00:00
feat: add maxNumProviders to findprovs (#283)
* feat: add maxNumProviders to findprovs * chore: upgrade libp2p-kad-dht
This commit is contained in:
parent
714b6ec2b9
commit
970deec2a4
@ -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
|
||||
|
@ -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",
|
||||
|
@ -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}
|
||||
*/
|
||||
|
@ -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')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user