From d681ae140cb443daff70bd09a492a90ce810cef2 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Wed, 10 Jul 2019 15:32:04 +0100 Subject: [PATCH 1/3] fix: make findprovs return all responses --- src/dht/findprovs.js | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/dht/findprovs.js b/src/dht/findprovs.js index 23be84068..41ef4aaeb 100644 --- a/src/dht/findprovs.js +++ b/src/dht/findprovs.js @@ -23,29 +23,26 @@ module.exports = (send) => { const handleResult = (res, callback) => { // Inconsistent return values in the browser vs node - if (Array.isArray(res)) { - res = res.find(r => r.Type === 4) + if (!Array.isArray(res)) { + res = [res] } - // callback with an empty array if no providers are found - // 4 = Provider - // https://github.com/libp2p/go-libp2p-core/blob/6e566d10f4a5447317a66d64c7459954b969bdab/routing/query.go#L20 - if (!res || res.Type !== 4) { - return callback(null, []) - } - - const responses = res.Responses.map((r) => { - const peerInfo = new PeerInfo(PeerId.createFromB58String(r.ID)) - - if (r.Addrs) { - r.Addrs.forEach((addr) => { - const ma = multiaddr(addr) - - peerInfo.multiaddrs.add(ma) - }) - } - - return peerInfo + let responses = [] + res.forEach(result => { + // 4 = Provider + if (result.Type !== 4) return + result.Responses.forEach(response => { + const peerInfo = new PeerInfo(PeerId.createFromB58String(response.ID)) + + if (response.Addrs) { + response.Addrs.forEach((addr) => { + const ma = multiaddr(addr) + peerInfo.multiaddrs.add(ma) + }) + } + + responses.push(peerInfo) + }) }) callback(null, responses) From 87cbe6aa5d1497c66a4fbabc6df8f125e59474b9 Mon Sep 17 00:00:00 2001 From: Jacob Heun Date: Wed, 10 Jul 2019 23:02:48 +0100 Subject: [PATCH 2/3] test: add test for many providers from interface-ipfs-core --- package.json | 2 +- test/interface.spec.js | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/package.json b/package.json index c417ffed7..30dd0408b 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "cross-env": "^5.2.0", "dirty-chai": "^2.0.1", "go-ipfs-dep": "~0.4.21", - "interface-ipfs-core": "~0.106.0", + "interface-ipfs-core": "ipfs/interface-js-ipfs-core#test/many-providers", "ipfsd-ctl": "~0.43.0", "nock": "^10.0.2", "stream-equal": "^1.1.1" diff --git a/test/interface.spec.js b/test/interface.spec.js index adc928289..1c7ed2b7d 100644 --- a/test/interface.spec.js +++ b/test/interface.spec.js @@ -88,10 +88,6 @@ describe('interface-ipfs-core tests', () => { reason: 'FIXME checking what is exactly go-ipfs returning https://github.com/ipfs/go-ipfs/issues/3862#issuecomment-294168090' }, // dht.findprovs - { - name: 'should provide from one node and find it through another node', - reason: 'FIXME go-ipfs endpoint doesn\'t conform with the others https://github.com/ipfs/go-ipfs/issues/5047' - }, { name: 'should take options to override timeout config', reason: 'FIXME go-ipfs does not support a timeout option' From 374aa4c8d7c1c6ae1063d5808d3da7aa2409f5ac Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Thu, 11 Jul 2019 09:59:49 +0100 Subject: [PATCH 3/3] chore: update interface-ipfs-core dep --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 30dd0408b..c4ba1493e 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "cross-env": "^5.2.0", "dirty-chai": "^2.0.1", "go-ipfs-dep": "~0.4.21", - "interface-ipfs-core": "ipfs/interface-js-ipfs-core#test/many-providers", + "interface-ipfs-core": "~0.107.0", "ipfsd-ctl": "~0.43.0", "nock": "^10.0.2", "stream-equal": "^1.1.1"