From bd8a35aaf9fa7a4355b1c115ddc42fea7451475f Mon Sep 17 00:00:00 2001 From: Chris Dostert Date: Mon, 5 Feb 2018 03:36:20 -0800 Subject: [PATCH] feat: add explicit error for case peer id not included in multiaddr (#155) --- README.md | 2 +- src/index.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2ea998e3..4fc6bb27 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/index.js b/src/index.js index f056fd32..907eb86e 100644 --- a/src/index.js +++ b/src/index.js @@ -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) {