Skip to content

Commit bd8a35a

Browse files
chrisdostertdaviddias
authored andcommitted
feat: add explicit error for case peer id not included in multiaddr (#155)
1 parent 248d86d commit bd8a35a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ class Node extends libp2p {
162162

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

src/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,12 @@ class Node extends EventEmitter {
319319
if (typeof peer === 'string') {
320320
peer = multiaddr(peer)
321321
}
322+
322323
const peerIdB58Str = peer.getPeerId()
324+
if (!peerIdB58Str) {
325+
throw new Error(`peer multiaddr instance or string must include peerId`)
326+
}
327+
323328
try {
324329
p = this.peerBook.get(peerIdB58Str)
325330
} catch (err) {

0 commit comments

Comments
 (0)