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

Commit f5f2e83

Browse files
committed
fix: result.Peers can be null, ensure callback is called
License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io>
1 parent faa51b4 commit f5f2e83

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/swarm/peers.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ module.exports = (send) => {
2121
return callback(err)
2222
}
2323

24+
// go-ipfs <= 0.4.4
2425
if (result.Strings) {
25-
// go-ipfs <= 0.4.4
26-
callback(null, result.Strings.map((p) => {
26+
return callback(null, result.Strings.map((p) => {
2727
const res = {}
2828

2929
if (verbose) {
@@ -40,26 +40,26 @@ module.exports = (send) => {
4040

4141
return res
4242
}))
43-
} else if (result.Peers) {
44-
// go-ipfs >= 0.4.5
45-
callback(null, result.Peers.map((p) => {
46-
const res = {
47-
addr: multiaddr(p.Addr),
48-
peer: PeerId.createFromB58String(p.Peer),
49-
muxer: p.Muxer
50-
}
43+
}
5144

52-
if (p.Latency) {
53-
res.latency = p.Latency
54-
}
45+
// go-ipfs >= 0.4.5
46+
callback(null, (result.Peers || []).map((p) => {
47+
const res = {
48+
addr: multiaddr(p.Addr),
49+
peer: PeerId.createFromB58String(p.Peer),
50+
muxer: p.Muxer
51+
}
5552

56-
if (p.Streams) {
57-
res.streams = p.Streams
58-
}
53+
if (p.Latency) {
54+
res.latency = p.Latency
55+
}
5956

60-
return res
61-
}))
62-
}
57+
if (p.Streams) {
58+
res.streams = p.Streams
59+
}
60+
61+
return res
62+
}))
6363
})
6464
})
6565
}

0 commit comments

Comments
 (0)