remove log param from peerManager

This commit is contained in:
Sasha 2024-10-20 16:02:12 +02:00
parent a6dd49974c
commit e897d5cd6f
No known key found for this signature in database
2 changed files with 8 additions and 7 deletions

View File

@ -33,7 +33,7 @@ export class BaseProtocolSDK implements IBaseProtocolSDK {
const maintainPeersInterval = const maintainPeersInterval =
options?.maintainPeersInterval ?? DEFAULT_MAINTAIN_PEERS_INTERVAL; options?.maintainPeersInterval ?? DEFAULT_MAINTAIN_PEERS_INTERVAL;
this.peerManager = new PeerManager(connectionManager, core, this.log); this.peerManager = new PeerManager(connectionManager, core);
this.log.info( this.log.info(
`Initializing BaseProtocolSDK with numPeersToUse: ${this.numPeersToUse}, maintainPeersInterval: ${maintainPeersInterval}ms` `Initializing BaseProtocolSDK with numPeersToUse: ${this.numPeersToUse}, maintainPeersInterval: ${maintainPeersInterval}ms`

View File

@ -5,6 +5,8 @@ import { IHealthManager } from "@waku/interfaces";
import { Logger } from "@waku/utils"; import { Logger } from "@waku/utils";
import { Mutex } from "async-mutex"; import { Mutex } from "async-mutex";
const log = new Logger("peer-manager");
export class PeerManager { export class PeerManager {
private peers: Map<string, Peer> = new Map(); private peers: Map<string, Peer> = new Map();
private healthManager: IHealthManager; private healthManager: IHealthManager;
@ -15,8 +17,7 @@ export class PeerManager {
public constructor( public constructor(
private readonly connectionManager: ConnectionManager, private readonly connectionManager: ConnectionManager,
private readonly core: BaseProtocol, private readonly core: BaseProtocol
private readonly log: Logger
) { ) {
this.healthManager = getHealthManager(); this.healthManager = getHealthManager();
this.healthManager.updateProtocolHealth(this.core.multicodec, 0); this.healthManager.updateProtocolHealth(this.core.multicodec, 0);
@ -35,7 +36,7 @@ export class PeerManager {
this.writeLockHolder = `addPeer: ${peer.id.toString()}`; this.writeLockHolder = `addPeer: ${peer.id.toString()}`;
await this.connectionManager.attemptDial(peer.id); await this.connectionManager.attemptDial(peer.id);
this.peers.set(peer.id.toString(), peer); 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.healthManager.updateProtocolHealth(
this.core.multicodec, this.core.multicodec,
this.peers.size this.peers.size
@ -48,7 +49,7 @@ export class PeerManager {
return this.writeMutex.runExclusive(() => { return this.writeMutex.runExclusive(() => {
this.writeLockHolder = `removePeer: ${peerId.toString()}`; this.writeLockHolder = `removePeer: ${peerId.toString()}`;
this.peers.delete(peerId.toString()); this.peers.delete(peerId.toString());
this.log.info(`Removed peer: ${peerId.toString()}`); log.info(`Removed peer: ${peerId.toString()}`);
this.healthManager.updateProtocolHealth( this.healthManager.updateProtocolHealth(
this.core.multicodec, this.core.multicodec,
this.peers.size this.peers.size
@ -66,7 +67,7 @@ export class PeerManager {
} }
public async removeExcessPeers(excessPeers: number): Promise<void> { 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); const peersToRemove = Array.from(this.peers.values()).slice(0, excessPeers);
for (const peer of peersToRemove) { for (const peer of peersToRemove) {
await this.removePeer(peer.id); await this.removePeer(peer.id);
@ -80,7 +81,7 @@ export class PeerManager {
public async findAndAddPeers(numPeers: number): Promise<Peer[]> { public async findAndAddPeers(numPeers: number): Promise<Peer[]> {
const additionalPeers = await this.findPeers(numPeers); const additionalPeers = await this.findPeers(numPeers);
if (additionalPeers.length === 0) { if (additionalPeers.length === 0) {
this.log.warn("No additional peers found"); log.warn("No additional peers found");
return []; return [];
} }
return this.addMultiplePeers(additionalPeers); return this.addMultiplePeers(additionalPeers);