Skip to content

Commit 970deec

Browse files
vasco-santosjacobheun
authored andcommitted
feat: add maxNumProviders to findprovs (#283)
* feat: add maxNumProviders to findprovs * chore: upgrade libp2p-kad-dht
1 parent 714b6ec commit 970deec

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,12 @@ Required keys in the `options` object:
261261
- `key`: Buffer
262262
- `options`: object of options
263263
- `options.maxTimeout`: Number milliseconds
264+
- `options.maxNumProviders` maximum number of providers to find
264265

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

267268
- `key`: Buffer
268269

269-
270270
#### `libp2p.handle(protocol, handlerFunc [, matchFunc])`
271271

272272
> Handle new protocol

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"libp2p-circuit": "~0.3.0",
6868
"libp2p-delegated-content-routing": "~0.2.2",
6969
"libp2p-delegated-peer-routing": "~0.2.2",
70-
"libp2p-kad-dht": "~0.10.6",
70+
"libp2p-kad-dht": "~0.11.1",
7171
"libp2p-mdns": "~0.12.0",
7272
"libp2p-mplex": "~0.8.2",
7373
"libp2p-secio": "~0.10.1",

src/content-routing.js

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module.exports = (node) => {
2020
* @param {CID} key The CID key of the content to find
2121
* @param {object} options
2222
* @param {number} options.maxTimeout How long the query should run
23+
* @param {number} options.maxNumProviders - maximum number of providers to find
2324
* @param {function(Error, Result<Array>)} callback
2425
* @returns {void}
2526
*/

test/content-routing.node.js

+16
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,22 @@ describe('.contentRouting', () => {
107107
})
108108
})
109109

110+
it('nodeE.contentRouting.findProviders with limited number of providers', (done) => {
111+
parallel([
112+
(cb) => nodeA.contentRouting.provide(cid, cb),
113+
(cb) => nodeB.contentRouting.provide(cid, cb),
114+
(cb) => nodeC.contentRouting.provide(cid, cb)
115+
], (err) => {
116+
expect(err).to.not.exist()
117+
118+
nodeE.contentRouting.findProviders(cid, { maxNumProviders: 2 }, (err, providers) => {
119+
expect(err).to.not.exist()
120+
expect(providers).to.have.length(2)
121+
done()
122+
})
123+
})
124+
})
125+
110126
it('nodeC.contentRouting.findProviders for non existing record (timeout)', (done) => {
111127
const cid = new CID('QmTp9VkYvnHyrqKQuFPiuZkiX9gPcqj6x5LJ1rmWuSnnnn')
112128

0 commit comments

Comments
 (0)