|
1 | 1 | import type { Stream } from "@libp2p/interface-connection";
|
2 | 2 | import type { Libp2p } from "@libp2p/interface-libp2p";
|
3 | 3 | import type { PeerId } from "@libp2p/interface-peer-id";
|
4 |
| -import type { Multiaddr } from "@multiformats/multiaddr"; |
| 4 | +import { isPeerId } from "@libp2p/interface-peer-id"; |
| 5 | +import type { Multiaddr, MultiaddrInput } from "@multiformats/multiaddr"; |
| 6 | +import { multiaddr } from "@multiformats/multiaddr"; |
5 | 7 | import type {
|
6 | 8 | IFilter,
|
7 | 9 | ILightPush,
|
@@ -104,10 +106,11 @@ export class WakuNode implements Waku {
|
104 | 106 | * @param protocols Waku protocols we expect from the peer; Defaults to mounted protocols
|
105 | 107 | */
|
106 | 108 | async dial(
|
107 |
| - peer: PeerId | Multiaddr, |
| 109 | + peer: PeerId | MultiaddrInput, |
108 | 110 | protocols?: Protocols[]
|
109 | 111 | ): Promise<Stream> {
|
110 | 112 | const _protocols = protocols ?? [];
|
| 113 | + const peerId = mapToPeerIdOrMultiaddr(peer); |
111 | 114 |
|
112 | 115 | if (typeof protocols === "undefined") {
|
113 | 116 | this.relay && _protocols.push(Protocols.Relay);
|
@@ -156,9 +159,9 @@ export class WakuNode implements Waku {
|
156 | 159 | }
|
157 | 160 | }
|
158 | 161 |
|
159 |
| - log(`Dialing to ${peer.toString()} with protocols ${_protocols}`); |
| 162 | + log(`Dialing to ${peerId.toString()} with protocols ${_protocols}`); |
160 | 163 |
|
161 |
| - return this.libp2p.dialProtocol(peer, codecs); |
| 164 | + return this.libp2p.dialProtocol(peerId, codecs); |
162 | 165 | }
|
163 | 166 |
|
164 | 167 | async start(): Promise<void> {
|
@@ -189,3 +192,9 @@ export class WakuNode implements Waku {
|
189 | 192 | return localMultiaddr + "/p2p/" + this.libp2p.peerId.toString();
|
190 | 193 | }
|
191 | 194 | }
|
| 195 | + |
| 196 | +function mapToPeerIdOrMultiaddr( |
| 197 | + peerId: PeerId | MultiaddrInput |
| 198 | +): PeerId | Multiaddr { |
| 199 | + return isPeerId(peerId) ? peerId : multiaddr(peerId); |
| 200 | +} |
0 commit comments