From 02976823def29127a0238d425d5912aae94df195 Mon Sep 17 00:00:00 2001 From: Sasha Date: Sat, 12 Oct 2024 14:59:01 +0200 Subject: [PATCH] ensure numPeersToUse is respected --- packages/sdk/src/protocols/base_protocol.ts | 6 +++--- packages/sdk/src/waku/waku.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/sdk/src/protocols/base_protocol.ts b/packages/sdk/src/protocols/base_protocol.ts index 4550072b84..3ef5cc1df8 100644 --- a/packages/sdk/src/protocols/base_protocol.ts +++ b/packages/sdk/src/protocols/base_protocol.ts @@ -29,12 +29,12 @@ export class BaseProtocolSDK implements IBaseProtocolSDK { ) { this.log = new Logger(`sdk:${core.multicodec}`); - this.peerManager = new PeerManager(connectionManager, core, this.log); - this.numPeersToUse = options?.numPeersToUse ?? DEFAULT_NUM_PEERS_TO_USE; const maintainPeersInterval = options?.maintainPeersInterval ?? DEFAULT_MAINTAIN_PEERS_INTERVAL; + this.peerManager = new PeerManager(connectionManager, core, this.log); + this.log.info( `Initializing BaseProtocolSDK with numPeersToUse: ${this.numPeersToUse}, maintainPeersInterval: ${maintainPeersInterval}ms` ); @@ -42,7 +42,7 @@ export class BaseProtocolSDK implements IBaseProtocolSDK { } public get connectedPeers(): Peer[] { - return this.peerManager.getPeers(); + return this.peerManager.getPeers().slice(0, this.numPeersToUse); } /** diff --git a/packages/sdk/src/waku/waku.ts b/packages/sdk/src/waku/waku.ts index c461a63ab3..1c450420cf 100644 --- a/packages/sdk/src/waku/waku.ts +++ b/packages/sdk/src/waku/waku.ts @@ -72,7 +72,7 @@ export class WakuNode implements IWaku { public constructor( public readonly pubsubTopics: PubsubTopic[], - options: WakuOptions, + options: CreateWakuNodeOptions, libp2p: Libp2p, protocolsEnabled: ProtocolsEnabled, relay?: IRelay @@ -111,12 +111,12 @@ export class WakuNode implements IWaku { } if (protocolsEnabled.lightpush) { - const lightPush = wakuLightPush(this.connectionManager); + const lightPush = wakuLightPush(this.connectionManager, options); this.lightPush = lightPush(libp2p); } if (protocolsEnabled.filter) { - const filter = wakuFilter(this.connectionManager); + const filter = wakuFilter(this.connectionManager, options); this.filter = filter(libp2p); }