diff --git a/README.md b/README.md index 5c642d5c17..30b5f8192b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index b9cbd7ce8f..28c340d251 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/content-routing.js b/src/content-routing.js index 6c94bd7327..3ebacb59fa 100644 --- a/src/content-routing.js +++ b/src/content-routing.js @@ -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)} callback * @returns {void} */ diff --git a/test/content-routing.node.js b/test/content-routing.node.js index 7f8adb07fb..4bfa58e19f 100644 --- a/test/content-routing.node.js +++ b/test/content-routing.node.js @@ -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')