diff --git a/packages/sdk/src/protocols/base_protocol.ts b/packages/sdk/src/protocols/base_protocol.ts index 3ef5cc1df8..72295b2747 100644 --- a/packages/sdk/src/protocols/base_protocol.ts +++ b/packages/sdk/src/protocols/base_protocol.ts @@ -33,7 +33,7 @@ export class BaseProtocolSDK implements IBaseProtocolSDK { const maintainPeersInterval = options?.maintainPeersInterval ?? DEFAULT_MAINTAIN_PEERS_INTERVAL; - this.peerManager = new PeerManager(connectionManager, core, this.log); + this.peerManager = new PeerManager(connectionManager, core); this.log.info( `Initializing BaseProtocolSDK with numPeersToUse: ${this.numPeersToUse}, maintainPeersInterval: ${maintainPeersInterval}ms` diff --git a/packages/sdk/src/protocols/peer_manager.ts b/packages/sdk/src/protocols/peer_manager.ts index dcdc024f1b..422f508e15 100644 --- a/packages/sdk/src/protocols/peer_manager.ts +++ b/packages/sdk/src/protocols/peer_manager.ts @@ -5,6 +5,8 @@ import { IHealthManager } from "@waku/interfaces"; import { Logger } from "@waku/utils"; import { Mutex } from "async-mutex"; +const log = new Logger("peer-manager"); + export class PeerManager { private peers: Map = new Map(); private healthManager: IHealthManager; @@ -15,8 +17,7 @@ export class PeerManager { public constructor( private readonly connectionManager: ConnectionManager, - private readonly core: BaseProtocol, - private readonly log: Logger + private readonly core: BaseProtocol ) { this.healthManager = getHealthManager(); this.healthManager.updateProtocolHealth(this.core.multicodec, 0); @@ -35,7 +36,7 @@ export class PeerManager { this.writeLockHolder = `addPeer: ${peer.id.toString()}`; await this.connectionManager.attemptDial(peer.id); this.peers.set(peer.id.toString(), peer); - this.log.info(`Added and dialed peer: ${peer.id.toString()}`); + log.info(`Added and dialed peer: ${peer.id.toString()}`); this.healthManager.updateProtocolHealth( this.core.multicodec, this.peers.size @@ -48,7 +49,7 @@ export class PeerManager { return this.writeMutex.runExclusive(() => { this.writeLockHolder = `removePeer: ${peerId.toString()}`; this.peers.delete(peerId.toString()); - this.log.info(`Removed peer: ${peerId.toString()}`); + log.info(`Removed peer: ${peerId.toString()}`); this.healthManager.updateProtocolHealth( this.core.multicodec, this.peers.size @@ -66,7 +67,7 @@ export class PeerManager { } public async removeExcessPeers(excessPeers: number): Promise { - this.log.info(`Removing ${excessPeers} excess peer(s)`); + log.info(`Removing ${excessPeers} excess peer(s)`); const peersToRemove = Array.from(this.peers.values()).slice(0, excessPeers); for (const peer of peersToRemove) { await this.removePeer(peer.id); @@ -80,7 +81,7 @@ export class PeerManager { public async findAndAddPeers(numPeers: number): Promise { const additionalPeers = await this.findPeers(numPeers); if (additionalPeers.length === 0) { - this.log.warn("No additional peers found"); + log.warn("No additional peers found"); return []; } return this.addMultiplePeers(additionalPeers);