Skip to content

Commit

Permalink
remove log param from peerManager
Browse files Browse the repository at this point in the history
  • Loading branch information
weboko committed Oct 20, 2024
1 parent a6dd499 commit e897d5c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/sdk/src/protocols/base_protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
13 changes: 7 additions & 6 deletions packages/sdk/src/protocols/peer_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Peer> = new Map();
private healthManager: IHealthManager;
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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
Expand All @@ -66,7 +67,7 @@ export class PeerManager {
}

public async removeExcessPeers(excessPeers: number): Promise<void> {
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);
Expand All @@ -80,7 +81,7 @@ export class PeerManager {
public async findAndAddPeers(numPeers: number): Promise<Peer[]> {
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);
Expand Down

0 comments on commit e897d5c

Please sign in to comment.