Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Commit

Permalink
fix: make findprovs return all responses (#1041)
Browse files Browse the repository at this point in the history
* fix: make findprovs return all responses

* test: add test for many providers from interface-ipfs-core

* chore: update interface-ipfs-core dep
  • Loading branch information
jacobheun authored and Alan Shaw committed Jul 11, 2019
1 parent 25e5209 commit 63103bd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "~0.107.0",
"ipfsd-ctl": "~0.43.0",
"nock": "^10.0.2",
"stream-equal": "^1.1.1"
Expand Down
39 changes: 18 additions & 21 deletions src/dht/findprovs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 0 additions & 4 deletions test/interface.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 63103bd

Please sign in to comment.