mirror of https://github.com/waku-org/js-waku.git
remove log param from peerManager
This commit is contained in:
parent
a6dd49974c
commit
e897d5cd6f
|
@ -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`
|
||||
|
|
|
@ -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;
|
||||
|
@ -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<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);
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue