mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-29 08:51:34 +00:00
feat: add explicit error for case peer id not included in multiaddr (#155)
This commit is contained in:
committed by
David Dias
parent
248d86d050
commit
bd8a35aaf9
@ -162,7 +162,7 @@ class Node extends libp2p {
|
|||||||
|
|
||||||
> Dials to another peer in the network.
|
> 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')
|
- `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
|
- `callback`: Function with signature `function (err, conn) {}` where `conn` is a [Connection](https://github.com/libp2p/interface-connection) object
|
||||||
|
|
||||||
|
@ -319,7 +319,12 @@ class Node extends EventEmitter {
|
|||||||
if (typeof peer === 'string') {
|
if (typeof peer === 'string') {
|
||||||
peer = multiaddr(peer)
|
peer = multiaddr(peer)
|
||||||
}
|
}
|
||||||
|
|
||||||
const peerIdB58Str = peer.getPeerId()
|
const peerIdB58Str = peer.getPeerId()
|
||||||
|
if (!peerIdB58Str) {
|
||||||
|
throw new Error(`peer multiaddr instance or string must include peerId`)
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
p = this.peerBook.get(peerIdB58Str)
|
p = this.peerBook.get(peerIdB58Str)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
Reference in New Issue
Block a user