feat: add explicit error for case peer id not included in multiaddr (#155)

This commit is contained in:
Chris Dostert 2018-02-05 03:36:20 -08:00 committed by David Dias
parent 248d86d050
commit bd8a35aaf9
2 changed files with 6 additions and 1 deletions

View File

@ -162,7 +162,7 @@ class Node extends libp2p {
> Dials to another peer in the network.
- `peer`: can be an instance of [PeerInfo][], [PeerId][] or [multiaddr][]
- `peer`: can be an instance of [PeerInfo][], [PeerId][], [multiaddr][], or a multiaddr string
- `protocol`: String that defines the protocol (e.g '/ipfs/bitswap/1.1.0')
- `callback`: Function with signature `function (err, conn) {}` where `conn` is a [Connection](https://github.com/libp2p/interface-connection) object

View File

@ -319,7 +319,12 @@ class Node extends EventEmitter {
if (typeof peer === 'string') {
peer = multiaddr(peer)
}
const peerIdB58Str = peer.getPeerId()
if (!peerIdB58Str) {
throw new Error(`peer multiaddr instance or string must include peerId`)
}
try {
p = this.peerBook.get(peerIdB58Str)
} catch (err) {