Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit cad96cb

Browse files
committed
fix: ping test fixes
License: MIT Signed-off-by: Alan Shaw <[email protected]>
1 parent 40268fc commit cad96cb

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/cli/commands/ping.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

3-
const pull = require('pull-stream/pull')
4-
3+
const pull = require('pull-stream')
54
const print = require('../utils').print
65

76
module.exports = {

src/core/components/ping-pull-stream.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module.exports = function pingPullStream (self) {
2626
], (err) => {
2727
if (err) {
2828
log.error(err)
29-
source.push(getPacket({ text: err.toString() }))
29+
source.push(getPacket({ success: false, text: err.toString() }))
3030
source.end(err)
3131
}
3232
})
@@ -43,16 +43,25 @@ function getPacket (msg) {
4343

4444
function getPeer (libp2pNode, statusStream, peerId, cb) {
4545
let peer
46+
4647
try {
4748
peer = libp2pNode.peerBook.get(peerId)
4849
} catch (err) {
4950
log('Peer not found in peer book, trying peer routing')
5051
// Share lookup status just as in the go implemmentation
5152
statusStream.push(getPacket({ text: `Looking up peer ${peerId}` }))
53+
5254
// Try to use peerRouting
53-
return libp2pNode.peerRouting.findPeer(PeerId.createFromB58String(peerId), cb)
55+
try {
56+
peerId = PeerId.createFromB58String(peerId)
57+
} catch (err) {
58+
return cb(err)
59+
}
60+
61+
return libp2pNode.peerRouting.findPeer(peerId, cb)
5462
}
55-
return cb(null, peer)
63+
64+
cb(null, peer)
5665
}
5766

5867
function runPing (libp2pNode, statusStream, count, peer, cb) {

0 commit comments

Comments
 (0)