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

Commit ef54889

Browse files
authored
Merge pull request #427 from ipfs/try-to-fix-swarm-peers
attempt to handle changes to ipfs swarm peers api
2 parents 723b4b0 + 23a3d49 commit ef54889

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"eslint-plugin-react": "^6.7.1",
6262
"gulp": "^3.9.1",
6363
"hapi": "^15.2.0",
64-
"interface-ipfs-core": "^0.18.3",
64+
"interface-ipfs-core": "^0.20.0",
6565
"ipfsd-ctl": "^0.17.0",
6666
"pre-commit": "^1.1.3",
6767
"socket.io": "^1.5.1",

src/api/swarm.js

+43-3
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,56 @@ module.exports = (send) => {
1212
callback = opts
1313
opts = {}
1414
}
15+
16+
const verbose = opts.v || opts.verbose
17+
1518
send({
1619
path: 'swarm/peers',
1720
qs: opts
1821
}, (err, result) => {
1922
if (err) {
2023
return callback(err)
2124
}
22-
callback(null, result.Strings.map((addr) => {
23-
return multiaddr(addr)
24-
}))
25+
26+
if (result.Strings) {
27+
// go-ipfs <= 0.4.4
28+
callback(null, result.Strings.map((p) => {
29+
const res = {}
30+
31+
if (verbose) {
32+
const parts = p.split(' ')
33+
res.addr = multiaddr(parts[0])
34+
res.latency = parts[1]
35+
} else {
36+
res.addr = multiaddr(p)
37+
}
38+
39+
res.peer = PeerId.createFromB58String(
40+
res.addr.decapsulate('ipfs')
41+
)
42+
43+
return res
44+
}))
45+
} else if (result.Peers) {
46+
// go-ipfs >= 0.4.5
47+
callback(null, result.Peers.map((p) => {
48+
const res = {
49+
addr: multiaddr(p.Addr),
50+
peer: PeerId.createFromB58String(p.Peer),
51+
muxer: p.Muxer
52+
}
53+
54+
if (p.Latency) {
55+
res.latency = p.Latency
56+
}
57+
58+
if (p.Streams) {
59+
res.streams = p.Streams
60+
}
61+
62+
return res
63+
}))
64+
}
2565
})
2666
}),
2767
connect: promisify((args, opts, callback) => {

0 commit comments

Comments
 (0)