From 44f9165143d4ec3ed7efeeb190de13c2a8c25002 Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Thu, 24 Oct 2024 19:31:55 +0530 Subject: [PATCH 01/16] feat: API allows using specific nodes for protocol --- packages/interfaces/src/protocols.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/interfaces/src/protocols.ts b/packages/interfaces/src/protocols.ts index 74462efa13..34d03d4824 100644 --- a/packages/interfaces/src/protocols.ts +++ b/packages/interfaces/src/protocols.ts @@ -106,6 +106,15 @@ export type ProtocolCreateOptions = { * List of peers to use to bootstrap the node. Ignored if defaultBootstrap is set to true. */ bootstrapPeers?: string[]; + /** + * List of nodes' multiaddrs as strings to use for each protocol. If not specified, random nodes will be used. + * This should be used only if you know what you are doing. + */ + nodesToUse?: { + store?: string[]; + filter?: string[]; + lightpush?: string[]; + }; }; export type Callback = ( From fb043d5544969fb8d061ac2448f08c597e392f84 Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Thu, 24 Oct 2024 19:32:55 +0530 Subject: [PATCH 02/16] chore: dial provided now --- packages/sdk/src/waku/waku.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/sdk/src/waku/waku.ts b/packages/sdk/src/waku/waku.ts index eea596d7a9..03a30e54aa 100644 --- a/packages/sdk/src/waku/waku.ts +++ b/packages/sdk/src/waku/waku.ts @@ -108,6 +108,15 @@ export class WakuNode implements IWaku { if (protocolsEnabled.store) { const store = wakuStore(this.connectionManager); this.store = store(libp2p); + + if (options.nodesToUse?.store) { + this.dialMultiaddr( + options.nodesToUse.store[0], + this.store.protocol.multicodec + ).catch((e) => { + log.error("Failed to dial store peer", e); + }); + } } if (protocolsEnabled.lightpush) { @@ -224,6 +233,14 @@ export class WakuNode implements IWaku { return this.connectionManager.isConnected(); } + private async dialMultiaddr( + multiaddrStr: string, + protocol: string + ): Promise { + const ma = multiaddr(multiaddrStr); + await this.libp2p.dialProtocol(ma, [protocol]); + } + private mapToPeerIdOrMultiaddr( peerId: PeerId | MultiaddrInput ): PeerId | Multiaddr { From c7d464eefb6bff68baded5a636eb2d3fd580982e Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Thu, 24 Oct 2024 19:55:15 +0530 Subject: [PATCH 03/16] chore: store uses the node --- packages/core/src/lib/base_protocol.ts | 18 +++++++++++++++++- packages/interfaces/src/protocols.ts | 6 ++---- packages/sdk/src/protocols/store/index.ts | 15 +++++++++++---- packages/sdk/src/waku/waku.ts | 23 +++++++++++++---------- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/packages/core/src/lib/base_protocol.ts b/packages/core/src/lib/base_protocol.ts index 740298ae0a..45ae85de39 100644 --- a/packages/core/src/lib/base_protocol.ts +++ b/packages/core/src/lib/base_protocol.ts @@ -3,6 +3,7 @@ import type { Peer, Stream } from "@libp2p/interface"; import type { IBaseProtocolCore, Libp2pComponents, + PeerIdStr, PubsubTopic } from "@waku/interfaces"; import { Logger } from "@waku/utils"; @@ -75,15 +76,30 @@ export class BaseProtocol implements IBaseProtocolCore { public async getPeers( { numPeers, - maxBootstrapPeers + maxBootstrapPeers, + peerIdStr }: { numPeers: number; maxBootstrapPeers: number; + peerIdStr?: PeerIdStr; } = { maxBootstrapPeers: 0, numPeers: 0 } ): Promise { + if (peerIdStr) { + const peer = (await this.connectedPeers()).find( + (p) => p.id.toString() === peerIdStr + ); + if (peer) { + return [peer]; + } + this.log.warn( + `Passed node to use for ${this.multicodec} not found: ${peerIdStr}. Attempting to use random peers.` + ); + return this.getPeers({ numPeers, maxBootstrapPeers }); + } + // Retrieve all connected peers that support the protocol & shard (if configured) const allAvailableConnectedPeers = await this.connectedPeers(); diff --git a/packages/interfaces/src/protocols.ts b/packages/interfaces/src/protocols.ts index 34d03d4824..904d711cdb 100644 --- a/packages/interfaces/src/protocols.ts +++ b/packages/interfaces/src/protocols.ts @@ -110,10 +110,8 @@ export type ProtocolCreateOptions = { * List of nodes' multiaddrs as strings to use for each protocol. If not specified, random nodes will be used. * This should be used only if you know what you are doing. */ - nodesToUse?: { - store?: string[]; - filter?: string[]; - lightpush?: string[]; + nodeToUse?: { + store?: string; }; }; diff --git a/packages/sdk/src/protocols/store/index.ts b/packages/sdk/src/protocols/store/index.ts index 01ef45d58c..b12958184a 100644 --- a/packages/sdk/src/protocols/store/index.ts +++ b/packages/sdk/src/protocols/store/index.ts @@ -23,7 +23,11 @@ const log = new Logger("waku:store:sdk"); export class Store extends BaseProtocolSDK implements IStore { public readonly protocol: StoreCore; - public constructor(connectionManager: ConnectionManager, libp2p: Libp2p) { + public constructor( + connectionManager: ConnectionManager, + libp2p: Libp2p, + private readonly peerIdStrToUse?: string + ) { super( new StoreCore(connectionManager.configuredPubsubTopics, libp2p), connectionManager, @@ -61,9 +65,11 @@ export class Store extends BaseProtocolSDK implements IStore { const peer = ( await this.protocol.getPeers({ numPeers: this.numPeersToUse, - maxBootstrapPeers: 1 + maxBootstrapPeers: 1, + peerIdStr: this.peerIdStrToUse }) )[0]; + if (!peer) { log.error("No peers available to query"); throw new Error("No peers available to query"); @@ -237,9 +243,10 @@ export class Store extends BaseProtocolSDK implements IStore { * @returns A function that takes a Libp2p instance and returns a StoreSDK instance. */ export function wakuStore( - connectionManager: ConnectionManager + connectionManager: ConnectionManager, + peerIdStrToUse?: string ): (libp2p: Libp2p) => IStore { return (libp2p: Libp2p) => { - return new Store(connectionManager, libp2p); + return new Store(connectionManager, libp2p, peerIdStrToUse); }; } diff --git a/packages/sdk/src/waku/waku.ts b/packages/sdk/src/waku/waku.ts index 03a30e54aa..b2c5ebef86 100644 --- a/packages/sdk/src/waku/waku.ts +++ b/packages/sdk/src/waku/waku.ts @@ -1,7 +1,7 @@ import type { Stream } from "@libp2p/interface"; import { isPeerId, PeerId } from "@libp2p/interface"; import { multiaddr, Multiaddr, MultiaddrInput } from "@multiformats/multiaddr"; -import { ConnectionManager, getHealthManager } from "@waku/core"; +import { ConnectionManager, getHealthManager, StoreCodec } from "@waku/core"; import type { IFilter, IHealthManager, @@ -10,6 +10,7 @@ import type { IStore, IWaku, Libp2p, + PeerIdStr, ProtocolCreateOptions, PubsubTopic } from "@waku/interfaces"; @@ -106,17 +107,15 @@ export class WakuNode implements IWaku { this.health = getHealthManager(); if (protocolsEnabled.store) { - const store = wakuStore(this.connectionManager); - this.store = store(libp2p); - - if (options.nodesToUse?.store) { - this.dialMultiaddr( - options.nodesToUse.store[0], - this.store.protocol.multicodec - ).catch((e) => { + let peerIdStr: PeerIdStr | undefined; + if (options.nodeToUse?.store) { + this.dialMultiaddr(options.nodeToUse.store, StoreCodec).catch((e) => { log.error("Failed to dial store peer", e); }); } + + const store = wakuStore(this.connectionManager, peerIdStr); + this.store = store(libp2p); } if (protocolsEnabled.lightpush) { @@ -236,9 +235,13 @@ export class WakuNode implements IWaku { private async dialMultiaddr( multiaddrStr: string, protocol: string - ): Promise { + ): Promise { const ma = multiaddr(multiaddrStr); + if (!ma.getPeerId()) { + throw new Error("Failed to dial multiaddr: missing peer ID"); + } await this.libp2p.dialProtocol(ma, [protocol]); + return ma.getPeerId()!; } private mapToPeerIdOrMultiaddr( From 9fb5b763ceb7d0bdf83289671ca0d826c7268fc1 Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Mon, 16 Dec 2024 20:02:01 +0530 Subject: [PATCH 04/16] chore: update API --- packages/interfaces/src/protocols.ts | 11 ++++++----- packages/sdk/src/waku/waku.ts | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/interfaces/src/protocols.ts b/packages/interfaces/src/protocols.ts index 904d711cdb..6eeaaf7714 100644 --- a/packages/interfaces/src/protocols.ts +++ b/packages/interfaces/src/protocols.ts @@ -28,6 +28,10 @@ export type IBaseProtocolSDK = { readonly numPeersToUse: number; }; +type StoreProtocolOptions = { + peer: string; +}; + export type NetworkConfig = StaticSharding | AutoSharding; //TODO: merge this with ProtocolCreateOptions or establish distinction: https://github.com/waku-org/js-waku/issues/2048 @@ -107,12 +111,9 @@ export type ProtocolCreateOptions = { */ bootstrapPeers?: string[]; /** - * List of nodes' multiaddrs as strings to use for each protocol. If not specified, random nodes will be used. - * This should be used only if you know what you are doing. + * Options for the Store protocol. */ - nodeToUse?: { - store?: string; - }; + store?: Partial; }; export type Callback = ( diff --git a/packages/sdk/src/waku/waku.ts b/packages/sdk/src/waku/waku.ts index b2c5ebef86..5579c953c9 100644 --- a/packages/sdk/src/waku/waku.ts +++ b/packages/sdk/src/waku/waku.ts @@ -108,8 +108,8 @@ export class WakuNode implements IWaku { if (protocolsEnabled.store) { let peerIdStr: PeerIdStr | undefined; - if (options.nodeToUse?.store) { - this.dialMultiaddr(options.nodeToUse.store, StoreCodec).catch((e) => { + if (options.store?.peer) { + this.dialMultiaddr(options.store.peer, StoreCodec).catch((e) => { log.error("Failed to dial store peer", e); }); } From 9a47085fbc64fa493103fa2c64efce3316ca73e9 Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Mon, 16 Dec 2024 20:08:30 +0530 Subject: [PATCH 05/16] chore: use protocol-level class for getting peer --- packages/core/src/lib/base_protocol.ts | 17 +------------ packages/sdk/src/protocols/store/index.ts | 30 +++++++++++++++++------ 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/packages/core/src/lib/base_protocol.ts b/packages/core/src/lib/base_protocol.ts index 45ae85de39..8f8cc9405b 100644 --- a/packages/core/src/lib/base_protocol.ts +++ b/packages/core/src/lib/base_protocol.ts @@ -76,30 +76,15 @@ export class BaseProtocol implements IBaseProtocolCore { public async getPeers( { numPeers, - maxBootstrapPeers, - peerIdStr + maxBootstrapPeers }: { numPeers: number; maxBootstrapPeers: number; - peerIdStr?: PeerIdStr; } = { maxBootstrapPeers: 0, numPeers: 0 } ): Promise { - if (peerIdStr) { - const peer = (await this.connectedPeers()).find( - (p) => p.id.toString() === peerIdStr - ); - if (peer) { - return [peer]; - } - this.log.warn( - `Passed node to use for ${this.multicodec} not found: ${peerIdStr}. Attempting to use random peers.` - ); - return this.getPeers({ numPeers, maxBootstrapPeers }); - } - // Retrieve all connected peers that support the protocol & shard (if configured) const allAvailableConnectedPeers = await this.connectedPeers(); diff --git a/packages/sdk/src/protocols/store/index.ts b/packages/sdk/src/protocols/store/index.ts index b12958184a..655c090722 100644 --- a/packages/sdk/src/protocols/store/index.ts +++ b/packages/sdk/src/protocols/store/index.ts @@ -1,3 +1,4 @@ +import type { Peer } from "@libp2p/interface-peer-id"; import { ConnectionManager, StoreCore } from "@waku/core"; import { IDecodedMessage, @@ -62,13 +63,14 @@ export class Store extends BaseProtocolSDK implements IStore { ...options }; - const peer = ( - await this.protocol.getPeers({ - numPeers: this.numPeersToUse, - maxBootstrapPeers: 1, - peerIdStr: this.peerIdStrToUse - }) - )[0]; + const peer = + (await this.getPeerToUse()) ?? + ( + await this.protocol.getPeers({ + numPeers: this.numPeersToUse, + maxBootstrapPeers: 1 + }) + )[0]; if (!peer) { log.error("No peers available to query"); @@ -234,6 +236,20 @@ export class Store extends BaseProtocolSDK implements IStore { decodersAsMap }; } + + private async getPeerToUse(): Promise { + const peer = this.connectedPeers.find( + (p) => p.id.toString() === this.peerIdStrToUse + ); + if (peer) { + return peer; + } + + log.warn( + `Passed node to use for Store not found: ${this.peerIdStrToUse}. Attempting to use random peers.` + ); + return null; + } } /** From c412aeddfbf6995b1979cab9a42be8cf1800533a Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Mon, 16 Dec 2024 20:31:45 +0530 Subject: [PATCH 06/16] chore: use ConnectionManager for dial ops --- packages/core/src/lib/base_protocol.ts | 1 - packages/core/src/lib/connection_manager.ts | 31 +++++++++++++++++++-- packages/interfaces/src/libp2p.ts | 2 ++ packages/sdk/src/protocols/store/index.ts | 2 +- packages/sdk/src/waku/waku.ts | 20 ++++--------- 5 files changed, 37 insertions(+), 19 deletions(-) diff --git a/packages/core/src/lib/base_protocol.ts b/packages/core/src/lib/base_protocol.ts index 8f8cc9405b..740298ae0a 100644 --- a/packages/core/src/lib/base_protocol.ts +++ b/packages/core/src/lib/base_protocol.ts @@ -3,7 +3,6 @@ import type { Peer, Stream } from "@libp2p/interface"; import type { IBaseProtocolCore, Libp2pComponents, - PeerIdStr, PubsubTopic } from "@waku/interfaces"; import { Logger } from "@waku/utils"; diff --git a/packages/core/src/lib/connection_manager.ts b/packages/core/src/lib/connection_manager.ts index 64bd35434f..b156874756 100644 --- a/packages/core/src/lib/connection_manager.ts +++ b/packages/core/src/lib/connection_manager.ts @@ -1,5 +1,7 @@ import type { Peer, PeerId, PeerInfo, PeerStore } from "@libp2p/interface"; +import {} from "@libp2p/peer-id"; import { TypedEventEmitter } from "@libp2p/interface"; +import { multiaddr } from "@multiformats/multiaddr"; import { ConnectionManagerOptions, DiscoveryTrigger, @@ -11,6 +13,7 @@ import { IPeersByDiscoveryEvents, IRelay, KeepAliveOptions, + MultiaddrStr, PeersByDiscoveryResult, PubsubTopic, ShardInfo @@ -219,7 +222,29 @@ export class ConnectionManager this.startNetworkStatusListener(); } - private async dialPeer(peerId: PeerId): Promise { + public async dialPeer( + peer: PeerId | MultiaddrStr, + protocols?: string[] + ): Promise { + let peerId: PeerId; + if (typeof peer === "string") { + const ma = multiaddr(peer); + const peerIdStr = ma.getPeerId(); + if (!peerIdStr) { + throw new Error("Failed to dial multiaddr: missing peer ID"); + } + const conn = this.libp2p + .getConnections() + .find((conn) => conn.remotePeer.toString() === peerIdStr); + if (conn) { + peerId = conn.remotePeer; + } else { + throw new Error("Failed to dial multiaddr: no connection found"); + } + } else { + peerId = peer; + } + this.currentActiveParallelDialCount += 1; let dialAttempt = 0; while (dialAttempt < this.options.maxDialAttemptsForPeer) { @@ -227,7 +252,9 @@ export class ConnectionManager log.info( `Dialing peer ${peerId.toString()} on attempt ${dialAttempt + 1}` ); - await this.libp2p.dial(peerId); + protocols + ? await this.libp2p.dialProtocol(peerId, protocols) + : await this.libp2p.dial(peerId); const tags = await this.getTagNamesForPeer(peerId); // add tag to connection describing discovery mechanism diff --git a/packages/interfaces/src/libp2p.ts b/packages/interfaces/src/libp2p.ts index 53bb106308..401ead09f5 100644 --- a/packages/interfaces/src/libp2p.ts +++ b/packages/interfaces/src/libp2p.ts @@ -36,3 +36,5 @@ export type CreateLibp2pOptions = Libp2pOptions & { */ filterMultiaddrs?: boolean; }; + +export type MultiaddrStr = string; diff --git a/packages/sdk/src/protocols/store/index.ts b/packages/sdk/src/protocols/store/index.ts index 655c090722..00691e86f7 100644 --- a/packages/sdk/src/protocols/store/index.ts +++ b/packages/sdk/src/protocols/store/index.ts @@ -1,4 +1,4 @@ -import type { Peer } from "@libp2p/interface-peer-id"; +import type { Peer } from "@libp2p/interface"; import { ConnectionManager, StoreCore } from "@waku/core"; import { IDecodedMessage, diff --git a/packages/sdk/src/waku/waku.ts b/packages/sdk/src/waku/waku.ts index 5579c953c9..5599d37e41 100644 --- a/packages/sdk/src/waku/waku.ts +++ b/packages/sdk/src/waku/waku.ts @@ -109,9 +109,11 @@ export class WakuNode implements IWaku { if (protocolsEnabled.store) { let peerIdStr: PeerIdStr | undefined; if (options.store?.peer) { - this.dialMultiaddr(options.store.peer, StoreCodec).catch((e) => { - log.error("Failed to dial store peer", e); - }); + this.connectionManager + .dialPeer(options.store.peer, [StoreCodec]) + .catch((e) => { + log.error("Failed to dial store peer", e); + }); } const store = wakuStore(this.connectionManager, peerIdStr); @@ -232,18 +234,6 @@ export class WakuNode implements IWaku { return this.connectionManager.isConnected(); } - private async dialMultiaddr( - multiaddrStr: string, - protocol: string - ): Promise { - const ma = multiaddr(multiaddrStr); - if (!ma.getPeerId()) { - throw new Error("Failed to dial multiaddr: missing peer ID"); - } - await this.libp2p.dialProtocol(ma, [protocol]); - return ma.getPeerId()!; - } - private mapToPeerIdOrMultiaddr( peerId: PeerId | MultiaddrInput ): PeerId | Multiaddr { From 9ef514224df5dbdfcd8efe875c864fe993328969 Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Tue, 17 Dec 2024 23:30:36 +0530 Subject: [PATCH 07/16] chore: address comments --- packages/core/src/lib/connection_manager.ts | 1 - packages/interfaces/src/protocols.ts | 2 +- packages/sdk/src/protocols/store/index.ts | 13 +++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/core/src/lib/connection_manager.ts b/packages/core/src/lib/connection_manager.ts index b156874756..75f88f9e15 100644 --- a/packages/core/src/lib/connection_manager.ts +++ b/packages/core/src/lib/connection_manager.ts @@ -1,5 +1,4 @@ import type { Peer, PeerId, PeerInfo, PeerStore } from "@libp2p/interface"; -import {} from "@libp2p/peer-id"; import { TypedEventEmitter } from "@libp2p/interface"; import { multiaddr } from "@multiformats/multiaddr"; import { diff --git a/packages/interfaces/src/protocols.ts b/packages/interfaces/src/protocols.ts index 6eeaaf7714..9cec07405f 100644 --- a/packages/interfaces/src/protocols.ts +++ b/packages/interfaces/src/protocols.ts @@ -28,7 +28,7 @@ export type IBaseProtocolSDK = { readonly numPeersToUse: number; }; -type StoreProtocolOptions = { +export type StoreProtocolOptions = { peer: string; }; diff --git a/packages/sdk/src/protocols/store/index.ts b/packages/sdk/src/protocols/store/index.ts index 00691e86f7..66bf6f6c0a 100644 --- a/packages/sdk/src/protocols/store/index.ts +++ b/packages/sdk/src/protocols/store/index.ts @@ -6,7 +6,8 @@ import { IStore, Libp2p, QueryRequestParams, - StoreCursor + StoreCursor, + StoreProtocolOptions } from "@waku/interfaces"; import { messageHash } from "@waku/message-hash"; import { ensurePubsubTopicIsConfigured, isDefined, Logger } from "@waku/utils"; @@ -27,7 +28,7 @@ export class Store extends BaseProtocolSDK implements IStore { public constructor( connectionManager: ConnectionManager, libp2p: Libp2p, - private readonly peerIdStrToUse?: string + private options?: Partial ) { super( new StoreCore(connectionManager.configuredPubsubTopics, libp2p), @@ -239,14 +240,14 @@ export class Store extends BaseProtocolSDK implements IStore { private async getPeerToUse(): Promise { const peer = this.connectedPeers.find( - (p) => p.id.toString() === this.peerIdStrToUse + (p) => p.id.toString() === this.options?.peer ); if (peer) { return peer; } log.warn( - `Passed node to use for Store not found: ${this.peerIdStrToUse}. Attempting to use random peers.` + `Passed node to use for Store not found: ${this.options?.peer}. Attempting to use random peers.` ); return null; } @@ -260,9 +261,9 @@ export class Store extends BaseProtocolSDK implements IStore { */ export function wakuStore( connectionManager: ConnectionManager, - peerIdStrToUse?: string + options?: Partial ): (libp2p: Libp2p) => IStore { return (libp2p: Libp2p) => { - return new Store(connectionManager, libp2p, peerIdStrToUse); + return new Store(connectionManager, libp2p, options); }; } From cbff9511240b176022d629c41ac57476e08f6ab6 Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Tue, 17 Dec 2024 23:35:28 +0530 Subject: [PATCH 08/16] chore: fix type error --- packages/sdk/src/waku/waku.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sdk/src/waku/waku.ts b/packages/sdk/src/waku/waku.ts index 5599d37e41..48d9b71d39 100644 --- a/packages/sdk/src/waku/waku.ts +++ b/packages/sdk/src/waku/waku.ts @@ -116,7 +116,7 @@ export class WakuNode implements IWaku { }); } - const store = wakuStore(this.connectionManager, peerIdStr); + const store = wakuStore(this.connectionManager, { peer: peerIdStr }); this.store = store(libp2p); } From 842d8ddab424b619e102f9a9ecb8e37764f39c4e Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Wed, 15 Jan 2025 16:05:24 +0530 Subject: [PATCH 09/16] chore: Waku.dial() proxies through ConnectionManager.dialPeer --- packages/core/src/lib/connection_manager.ts | 54 ++++++++++++--------- packages/interfaces/src/libp2p.ts | 2 - packages/interfaces/src/waku.ts | 4 +- packages/sdk/src/waku/waku.ts | 8 ++- 4 files changed, 37 insertions(+), 31 deletions(-) diff --git a/packages/core/src/lib/connection_manager.ts b/packages/core/src/lib/connection_manager.ts index 75f88f9e15..722a7eaf7d 100644 --- a/packages/core/src/lib/connection_manager.ts +++ b/packages/core/src/lib/connection_manager.ts @@ -1,6 +1,6 @@ import type { Peer, PeerId, PeerInfo, PeerStore } from "@libp2p/interface"; -import { TypedEventEmitter } from "@libp2p/interface"; -import { multiaddr } from "@multiformats/multiaddr"; +import { isPeerId, TypedEventEmitter } from "@libp2p/interface"; +import { multiaddr, MultiaddrInput } from "@multiformats/multiaddr"; import { ConnectionManagerOptions, DiscoveryTrigger, @@ -12,7 +12,6 @@ import { IPeersByDiscoveryEvents, IRelay, KeepAliveOptions, - MultiaddrStr, PeersByDiscoveryResult, PubsubTopic, ShardInfo @@ -222,27 +221,10 @@ export class ConnectionManager } public async dialPeer( - peer: PeerId | MultiaddrStr, + peer: PeerId | MultiaddrInput, protocols?: string[] ): Promise { - let peerId: PeerId; - if (typeof peer === "string") { - const ma = multiaddr(peer); - const peerIdStr = ma.getPeerId(); - if (!peerIdStr) { - throw new Error("Failed to dial multiaddr: missing peer ID"); - } - const conn = this.libp2p - .getConnections() - .find((conn) => conn.remotePeer.toString() === peerIdStr); - if (conn) { - peerId = conn.remotePeer; - } else { - throw new Error("Failed to dial multiaddr: no connection found"); - } - } else { - peerId = peer; - } + const peerId = this.getPeerIdFromPeerOrMultiaddr(peer); this.currentActiveParallelDialCount += 1; let dialAttempt = 0; @@ -331,6 +313,34 @@ export class ConnectionManager } } + /** + * Internal utility to extract a PeerId from either a PeerId object or multiaddr input. + * This is used internally by the connection manager to handle different peer input formats. + * @internal + * @param peer - The PeerId or MultiaddrInput to extract the PeerId from + * @returns The extracted PeerId + */ + private getPeerIdFromPeerOrMultiaddr(peer: PeerId | MultiaddrInput): PeerId { + if (isPeerId(peer)) { + return peer; + } else { + // peer is of MultiaddrInput type + const ma = multiaddr(peer); + const peerIdStr = ma.getPeerId(); + if (!peerIdStr) { + throw new Error("Failed to dial multiaddr: missing peer ID"); + } + const conn = this.libp2p + .getConnections() + .find((conn) => conn.remotePeer.toString() === peerIdStr); + if (conn) { + return conn.remotePeer; + } else { + throw new Error("Failed to dial multiaddr: no connection found"); + } + } + } + private async attemptDnsDiscovery(): Promise { if (this.libp2p.getConnections().length > 0) return; if ((await this.libp2p.peerStore.all()).length > 0) return; diff --git a/packages/interfaces/src/libp2p.ts b/packages/interfaces/src/libp2p.ts index 401ead09f5..53bb106308 100644 --- a/packages/interfaces/src/libp2p.ts +++ b/packages/interfaces/src/libp2p.ts @@ -36,5 +36,3 @@ export type CreateLibp2pOptions = Libp2pOptions & { */ filterMultiaddrs?: boolean; }; - -export type MultiaddrStr = string; diff --git a/packages/interfaces/src/waku.ts b/packages/interfaces/src/waku.ts index 4f3edf4f86..79a057e0f2 100644 --- a/packages/interfaces/src/waku.ts +++ b/packages/interfaces/src/waku.ts @@ -1,4 +1,4 @@ -import type { PeerId, Stream } from "@libp2p/interface"; +import type { PeerId } from "@libp2p/interface"; import type { MultiaddrInput } from "@multiformats/multiaddr"; import { IConnectionManager } from "./connection_manager.js"; @@ -55,7 +55,7 @@ export interface IWaku { * waku.isConnected() === true; * ``` */ - dial(peer: PeerId | MultiaddrInput, protocols?: Protocols[]): Promise; + dial(peer: PeerId | MultiaddrInput, protocols?: Protocols[]): Promise; /** * Starts all services and components related to functionality of Waku node. diff --git a/packages/sdk/src/waku/waku.ts b/packages/sdk/src/waku/waku.ts index 48d9b71d39..8992912a33 100644 --- a/packages/sdk/src/waku/waku.ts +++ b/packages/sdk/src/waku/waku.ts @@ -1,4 +1,3 @@ -import type { Stream } from "@libp2p/interface"; import { isPeerId, PeerId } from "@libp2p/interface"; import { multiaddr, Multiaddr, MultiaddrInput } from "@multiformats/multiaddr"; import { ConnectionManager, getHealthManager, StoreCodec } from "@waku/core"; @@ -153,9 +152,8 @@ export class WakuNode implements IWaku { public async dial( peer: PeerId | MultiaddrInput, protocols?: Protocols[] - ): Promise { + ): Promise { const _protocols = protocols ?? []; - const peerId = this.mapToPeerIdOrMultiaddr(peer); if (typeof protocols === "undefined") { this.relay && _protocols.push(Protocols.Relay); @@ -204,9 +202,9 @@ export class WakuNode implements IWaku { } } + const peerId = this.mapToPeerIdOrMultiaddr(peer); log.info(`Dialing to ${peerId.toString()} with protocols ${_protocols}`); - - return this.libp2p.dialProtocol(peerId, codecs); + return await this.connectionManager.dialPeer(peer, codecs); } public async start(): Promise { From 9f55f1d5ee38b52e7655f577f635ec885ae9b63e Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Wed, 15 Jan 2025 16:58:39 +0530 Subject: [PATCH 10/16] chore: fix dial --- packages/core/src/lib/connection_manager.ts | 73 ++++++++++--------- .../connection_state.spec.ts | 2 + 2 files changed, 41 insertions(+), 34 deletions(-) diff --git a/packages/core/src/lib/connection_manager.ts b/packages/core/src/lib/connection_manager.ts index 722a7eaf7d..2bf6e7de73 100644 --- a/packages/core/src/lib/connection_manager.ts +++ b/packages/core/src/lib/connection_manager.ts @@ -1,6 +1,6 @@ import type { Peer, PeerId, PeerInfo, PeerStore } from "@libp2p/interface"; import { isPeerId, TypedEventEmitter } from "@libp2p/interface"; -import { multiaddr, MultiaddrInput } from "@multiformats/multiaddr"; +import { Multiaddr, multiaddr, MultiaddrInput } from "@multiformats/multiaddr"; import { ConnectionManagerOptions, DiscoveryTrigger, @@ -222,20 +222,31 @@ export class ConnectionManager public async dialPeer( peer: PeerId | MultiaddrInput, - protocols?: string[] + protocolCodecs?: string[] ): Promise { - const peerId = this.getPeerIdFromPeerOrMultiaddr(peer); + let peerId: PeerId | undefined; + const peerDialInfo = this.getDialablePeerInfo(peer); + const peerIdStr = isPeerId(peerDialInfo) + ? peerDialInfo.toString() + : peerDialInfo.getPeerId()!; this.currentActiveParallelDialCount += 1; let dialAttempt = 0; while (dialAttempt < this.options.maxDialAttemptsForPeer) { try { - log.info( - `Dialing peer ${peerId.toString()} on attempt ${dialAttempt + 1}` - ); - protocols - ? await this.libp2p.dialProtocol(peerId, protocols) - : await this.libp2p.dial(peerId); + log.info(`Dialing peer ${peerDialInfo} on attempt ${dialAttempt + 1}`); + protocolCodecs + ? await this.libp2p.dialProtocol(peerDialInfo, protocolCodecs) + : await this.libp2p.dial(peerDialInfo); + + const conn = this.libp2p + .getConnections() + .find((conn) => conn.remotePeer.toString() === peerIdStr); + if (conn) { + peerId = conn.remotePeer; + } else { + throw new Error("Failed to dial multiaddr: no connection found"); + } const tags = await this.getTagNamesForPeer(peerId); // add tag to connection describing discovery mechanism @@ -254,21 +265,17 @@ export class ConnectionManager } catch (error) { if (error instanceof AggregateError) { // Handle AggregateError - log.error( - `Error dialing peer ${peerId.toString()} - ${error.errors}` - ); + log.error(`Error dialing peer ${peerIdStr} - ${error.errors}`); } else { // Handle generic error log.error( - `Error dialing peer ${peerId.toString()} - ${ - (error as any).message - }` + `Error dialing peer ${peerIdStr} - ${(error as any).message}` ); } - this.dialErrorsForPeer.set(peerId.toString(), error); + this.dialErrorsForPeer.set(peerIdStr, error); dialAttempt++; - this.dialAttemptsForPeer.set(peerId.toString(), dialAttempt); + this.dialAttemptsForPeer.set(peerIdStr, dialAttempt); } } @@ -279,7 +286,7 @@ export class ConnectionManager // If max dial attempts reached and dialing failed, delete the peer if (dialAttempt === this.options.maxDialAttemptsForPeer) { try { - const error = this.dialErrorsForPeer.get(peerId.toString()); + const error = this.dialErrorsForPeer.get(peerIdStr); if (error) { let errorMessage; @@ -296,31 +303,36 @@ export class ConnectionManager } log.info( - `Deleting undialable peer ${peerId.toString()} from peer store. Reason: ${errorMessage}` + `Deleting undialable peer ${peerIdStr} from peer store. Reason: ${errorMessage}` ); } - this.dialErrorsForPeer.delete(peerId.toString()); - await this.libp2p.peerStore.delete(peerId); + this.dialErrorsForPeer.delete(peerIdStr); + if (peerId) { + await this.libp2p.peerStore.delete(peerId); + } // if it was last available peer - attempt DNS discovery await this.attemptDnsDiscovery(); } catch (error) { throw new Error( - `Error deleting undialable peer ${peerId.toString()} from peer store - ${error}` + `Error deleting undialable peer ${peerIdStr} from peer store - ${error}` ); } } } /** - * Internal utility to extract a PeerId from either a PeerId object or multiaddr input. + * Internal utility to extract a PeerId or Multiaddr from a peer input. * This is used internally by the connection manager to handle different peer input formats. * @internal - * @param peer - The PeerId or MultiaddrInput to extract the PeerId from - * @returns The extracted PeerId + * @param peer - The peer to extract information from, either as a PeerId object or multiaddr input + * @returns The peer information as either a PeerId, single Multiaddr, or array of Multiaddrs + * @throws Error if the multiaddr input is missing a peer ID */ - private getPeerIdFromPeerOrMultiaddr(peer: PeerId | MultiaddrInput): PeerId { + private getDialablePeerInfo( + peer: PeerId | MultiaddrInput + ): PeerId | Multiaddr { if (isPeerId(peer)) { return peer; } else { @@ -330,14 +342,7 @@ export class ConnectionManager if (!peerIdStr) { throw new Error("Failed to dial multiaddr: missing peer ID"); } - const conn = this.libp2p - .getConnections() - .find((conn) => conn.remotePeer.toString() === peerIdStr); - if (conn) { - return conn.remotePeer; - } else { - throw new Error("Failed to dial multiaddr: no connection found"); - } + return ma; } } diff --git a/packages/tests/tests/connection-mananger/connection_state.spec.ts b/packages/tests/tests/connection-mananger/connection_state.spec.ts index 0226df443f..14ddc82006 100644 --- a/packages/tests/tests/connection-mananger/connection_state.spec.ts +++ b/packages/tests/tests/connection-mananger/connection_state.spec.ts @@ -69,7 +69,9 @@ describe("Connection state", function () { }); it("should emit `waku:offline` event only when all peers disconnect", async function () { + console.log("dial 1"); await waku.dial(nwaku1PeerId, [Protocols.Filter]); + console.log("dial 1 success"); await waku.dial(nwaku2PeerId, [Protocols.Filter]); let eventCount = 0; From 49424c2eaf426fab452d8d603558c5f042036482 Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Thu, 16 Jan 2025 12:55:51 +0530 Subject: [PATCH 11/16] chore: add ts-doc for dialPeer() --- packages/core/src/lib/connection_manager.ts | 39 +++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/core/src/lib/connection_manager.ts b/packages/core/src/lib/connection_manager.ts index 2bf6e7de73..395710378d 100644 --- a/packages/core/src/lib/connection_manager.ts +++ b/packages/core/src/lib/connection_manager.ts @@ -220,6 +220,45 @@ export class ConnectionManager this.startNetworkStatusListener(); } + /** + * Attempts to establish a connection with a peer and set up specified protocols. + * The method handles both PeerId and Multiaddr inputs, manages connection attempts, + * and maintains the connection state. + * + * The dialing process includes: + * 1. Converting input to dialable peer info + * 2. Managing parallel dial attempts + * 3. Attempting to establish protocol-specific connections + * 4. Handling connection failures and retries + * 5. Updating the peer store and connection state + * + * @param {PeerId | MultiaddrInput} peer - The peer to connect to, either as a PeerId or multiaddr + * @param {string[]} [protocolCodecs] - Optional array of protocol-specific codec strings to establish + * (e.g., for LightPush, Filter, Store protocols) + * + * @throws {Error} If the multiaddr is missing a peer ID + * @throws {Error} If the maximum dial attempts are reached and the peer cannot be dialed + * @throws {Error} If there's an error deleting an undialable peer from the peer store + * + * @example + * ```typescript + * // Dial using PeerId + * await connectionManager.dialPeer(peerId); + * + * // Dial using multiaddr with specific protocols + * await connectionManager.dialPeer(multiaddr, [ + * "/vac/waku/relay/2.0.0", + * "/vac/waku/lightpush/2.0.0-beta1" + * ]); + * ``` + * + * @remarks + * - The method implements exponential backoff through multiple dial attempts + * - Maintains a queue for parallel dial attempts (limited by maxParallelDials) + * - Integrates with the KeepAliveManager for connection maintenance + * - Updates the peer store and connection state after successful/failed attempts + * - If all dial attempts fail, triggers DNS discovery as a fallback + */ public async dialPeer( peer: PeerId | MultiaddrInput, protocolCodecs?: string[] From ba8613c30aca6876e2c3755200821a2a6207f58d Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Thu, 16 Jan 2025 12:58:04 +0530 Subject: [PATCH 12/16] chore: remove log --- .../tests/tests/connection-mananger/connection_state.spec.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/tests/tests/connection-mananger/connection_state.spec.ts b/packages/tests/tests/connection-mananger/connection_state.spec.ts index 14ddc82006..0226df443f 100644 --- a/packages/tests/tests/connection-mananger/connection_state.spec.ts +++ b/packages/tests/tests/connection-mananger/connection_state.spec.ts @@ -69,9 +69,7 @@ describe("Connection state", function () { }); it("should emit `waku:offline` event only when all peers disconnect", async function () { - console.log("dial 1"); await waku.dial(nwaku1PeerId, [Protocols.Filter]); - console.log("dial 1 success"); await waku.dial(nwaku2PeerId, [Protocols.Filter]); let eventCount = 0; From d9ac6a354d60ac86449a72791995f8cb67f03cca Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Thu, 16 Jan 2025 12:58:32 +0530 Subject: [PATCH 13/16] chore: reduce ts-doc for an internal function --- packages/core/src/lib/connection_manager.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/core/src/lib/connection_manager.ts b/packages/core/src/lib/connection_manager.ts index 395710378d..459b00f28d 100644 --- a/packages/core/src/lib/connection_manager.ts +++ b/packages/core/src/lib/connection_manager.ts @@ -365,9 +365,6 @@ export class ConnectionManager * Internal utility to extract a PeerId or Multiaddr from a peer input. * This is used internally by the connection manager to handle different peer input formats. * @internal - * @param peer - The peer to extract information from, either as a PeerId object or multiaddr input - * @returns The peer information as either a PeerId, single Multiaddr, or array of Multiaddrs - * @throws Error if the multiaddr input is missing a peer ID */ private getDialablePeerInfo( peer: PeerId | MultiaddrInput From 90fd41871cad9587887c3fb006368817e4dd7622 Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Mon, 27 Jan 2025 21:21:38 +0530 Subject: [PATCH 14/16] chore: address comments --- packages/sdk/src/protocols/store/index.ts | 17 ++++++++--------- packages/sdk/src/waku/waku.ts | 6 +++--- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/packages/sdk/src/protocols/store/index.ts b/packages/sdk/src/protocols/store/index.ts index 66bf6f6c0a..bfc308f771 100644 --- a/packages/sdk/src/protocols/store/index.ts +++ b/packages/sdk/src/protocols/store/index.ts @@ -64,14 +64,7 @@ export class Store extends BaseProtocolSDK implements IStore { ...options }; - const peer = - (await this.getPeerToUse()) ?? - ( - await this.protocol.getPeers({ - numPeers: this.numPeersToUse, - maxBootstrapPeers: 1 - }) - )[0]; + const peer = await this.getPeerToUse(); if (!peer) { log.error("No peers available to query"); @@ -249,7 +242,13 @@ export class Store extends BaseProtocolSDK implements IStore { log.warn( `Passed node to use for Store not found: ${this.options?.peer}. Attempting to use random peers.` ); - return null; + + return ( + await this.protocol.getPeers({ + numPeers: this.numPeersToUse, + maxBootstrapPeers: 1 + }) + )[0]; } } diff --git a/packages/sdk/src/waku/waku.ts b/packages/sdk/src/waku/waku.ts index 8992912a33..37c649371a 100644 --- a/packages/sdk/src/waku/waku.ts +++ b/packages/sdk/src/waku/waku.ts @@ -9,7 +9,6 @@ import type { IStore, IWaku, Libp2p, - PeerIdStr, ProtocolCreateOptions, PubsubTopic } from "@waku/interfaces"; @@ -106,7 +105,6 @@ export class WakuNode implements IWaku { this.health = getHealthManager(); if (protocolsEnabled.store) { - let peerIdStr: PeerIdStr | undefined; if (options.store?.peer) { this.connectionManager .dialPeer(options.store.peer, [StoreCodec]) @@ -115,7 +113,9 @@ export class WakuNode implements IWaku { }); } - const store = wakuStore(this.connectionManager, { peer: peerIdStr }); + const store = wakuStore(this.connectionManager, { + peer: options.store?.peer + }); this.store = store(libp2p); } From 973559486eba8ba758c9dc8123e48bd4b6c27dc1 Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Tue, 28 Jan 2025 15:03:59 +0530 Subject: [PATCH 15/16] chore: return types from connmanager.dialpeer() --- packages/core/src/lib/connection_manager.ts | 23 +++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/core/src/lib/connection_manager.ts b/packages/core/src/lib/connection_manager.ts index 459b00f28d..a3ea8492f1 100644 --- a/packages/core/src/lib/connection_manager.ts +++ b/packages/core/src/lib/connection_manager.ts @@ -1,5 +1,13 @@ -import type { Peer, PeerId, PeerInfo, PeerStore } from "@libp2p/interface"; -import { isPeerId, TypedEventEmitter } from "@libp2p/interface"; +import { + type Connection, + isPeerId, + type Peer, + type PeerId, + type PeerInfo, + type PeerStore, + type Stream, + TypedEventEmitter +} from "@libp2p/interface"; import { Multiaddr, multiaddr, MultiaddrInput } from "@multiformats/multiaddr"; import { ConnectionManagerOptions, @@ -262,8 +270,9 @@ export class ConnectionManager public async dialPeer( peer: PeerId | MultiaddrInput, protocolCodecs?: string[] - ): Promise { + ): Promise { let peerId: PeerId | undefined; + let dialResponse: Stream | Connection | undefined; const peerDialInfo = this.getDialablePeerInfo(peer); const peerIdStr = isPeerId(peerDialInfo) ? peerDialInfo.toString() @@ -274,7 +283,7 @@ export class ConnectionManager while (dialAttempt < this.options.maxDialAttemptsForPeer) { try { log.info(`Dialing peer ${peerDialInfo} on attempt ${dialAttempt + 1}`); - protocolCodecs + dialResponse = protocolCodecs ? await this.libp2p.dialProtocol(peerDialInfo, protocolCodecs) : await this.libp2p.dial(peerDialInfo); @@ -359,6 +368,12 @@ export class ConnectionManager ); } } + + if (!dialResponse) { + throw new Error(`Failed to dial peer ${peerDialInfo}`); + } + + return dialResponse; } /** From 0361cde7428d775668423486d340d81a5f0d4bac Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Tue, 28 Jan 2025 16:15:52 +0530 Subject: [PATCH 16/16] chore: reduce diff by not introducing breaking changes --- packages/core/src/lib/connection_manager.ts | 40 +++++++++++---------- packages/interfaces/src/waku.ts | 4 +-- packages/sdk/src/waku/waku.ts | 8 ++--- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/packages/core/src/lib/connection_manager.ts b/packages/core/src/lib/connection_manager.ts index a3ea8492f1..ba48a0cdc7 100644 --- a/packages/core/src/lib/connection_manager.ts +++ b/packages/core/src/lib/connection_manager.ts @@ -267,12 +267,9 @@ export class ConnectionManager * - Updates the peer store and connection state after successful/failed attempts * - If all dial attempts fail, triggers DNS discovery as a fallback */ - public async dialPeer( - peer: PeerId | MultiaddrInput, - protocolCodecs?: string[] - ): Promise { + public async dialPeer(peer: PeerId | MultiaddrInput): Promise { + let connection: Connection | undefined; let peerId: PeerId | undefined; - let dialResponse: Stream | Connection | undefined; const peerDialInfo = this.getDialablePeerInfo(peer); const peerIdStr = isPeerId(peerDialInfo) ? peerDialInfo.toString() @@ -283,18 +280,8 @@ export class ConnectionManager while (dialAttempt < this.options.maxDialAttemptsForPeer) { try { log.info(`Dialing peer ${peerDialInfo} on attempt ${dialAttempt + 1}`); - dialResponse = protocolCodecs - ? await this.libp2p.dialProtocol(peerDialInfo, protocolCodecs) - : await this.libp2p.dial(peerDialInfo); - - const conn = this.libp2p - .getConnections() - .find((conn) => conn.remotePeer.toString() === peerIdStr); - if (conn) { - peerId = conn.remotePeer; - } else { - throw new Error("Failed to dial multiaddr: no connection found"); - } + connection = await this.libp2p.dial(peerDialInfo); + peerId = connection.remotePeer; const tags = await this.getTagNamesForPeer(peerId); // add tag to connection describing discovery mechanism @@ -369,11 +356,26 @@ export class ConnectionManager } } - if (!dialResponse) { + if (!connection) { throw new Error(`Failed to dial peer ${peerDialInfo}`); } - return dialResponse; + return connection; + } + + /** + * Dial a peer with specific protocols. + * This method is a raw proxy to the libp2p dialProtocol method. + * @param peer - The peer to connect to, either as a PeerId or multiaddr + * @param protocolCodecs - Optional array of protocol-specific codec strings to establish + * @returns A stream to the peer + */ + public async rawDialPeerWithProtocols( + peer: PeerId | MultiaddrInput, + protocolCodecs: string[] + ): Promise { + const peerDialInfo = this.getDialablePeerInfo(peer); + return await this.libp2p.dialProtocol(peerDialInfo, protocolCodecs); } /** diff --git a/packages/interfaces/src/waku.ts b/packages/interfaces/src/waku.ts index 79a057e0f2..4f3edf4f86 100644 --- a/packages/interfaces/src/waku.ts +++ b/packages/interfaces/src/waku.ts @@ -1,4 +1,4 @@ -import type { PeerId } from "@libp2p/interface"; +import type { PeerId, Stream } from "@libp2p/interface"; import type { MultiaddrInput } from "@multiformats/multiaddr"; import { IConnectionManager } from "./connection_manager.js"; @@ -55,7 +55,7 @@ export interface IWaku { * waku.isConnected() === true; * ``` */ - dial(peer: PeerId | MultiaddrInput, protocols?: Protocols[]): Promise; + dial(peer: PeerId | MultiaddrInput, protocols?: Protocols[]): Promise; /** * Starts all services and components related to functionality of Waku node. diff --git a/packages/sdk/src/waku/waku.ts b/packages/sdk/src/waku/waku.ts index 37c649371a..0889b038d9 100644 --- a/packages/sdk/src/waku/waku.ts +++ b/packages/sdk/src/waku/waku.ts @@ -1,4 +1,4 @@ -import { isPeerId, PeerId } from "@libp2p/interface"; +import { isPeerId, PeerId, type Stream } from "@libp2p/interface"; import { multiaddr, Multiaddr, MultiaddrInput } from "@multiformats/multiaddr"; import { ConnectionManager, getHealthManager, StoreCodec } from "@waku/core"; import type { @@ -107,7 +107,7 @@ export class WakuNode implements IWaku { if (protocolsEnabled.store) { if (options.store?.peer) { this.connectionManager - .dialPeer(options.store.peer, [StoreCodec]) + .rawDialPeerWithProtocols(options.store.peer, [StoreCodec]) .catch((e) => { log.error("Failed to dial store peer", e); }); @@ -152,7 +152,7 @@ export class WakuNode implements IWaku { public async dial( peer: PeerId | MultiaddrInput, protocols?: Protocols[] - ): Promise { + ): Promise { const _protocols = protocols ?? []; if (typeof protocols === "undefined") { @@ -204,7 +204,7 @@ export class WakuNode implements IWaku { const peerId = this.mapToPeerIdOrMultiaddr(peer); log.info(`Dialing to ${peerId.toString()} with protocols ${_protocols}`); - return await this.connectionManager.dialPeer(peer, codecs); + return await this.connectionManager.rawDialPeerWithProtocols(peer, codecs); } public async start(): Promise {