Skip to content

Commit

Permalink
chore: minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
danisharora099 committed Oct 3, 2024
1 parent a89e69f commit 252ec59
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 22 deletions.
8 changes: 1 addition & 7 deletions packages/core/src/lib/base_protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export class BaseProtocol implements IBaseProtocolCore {
return this.streamManager.getStream(peer);
}

//TODO: move to SDK
/**
* Returns known peers from the address book (`libp2p.peerStore`) that support
* the class protocol. Waku may or may not be currently connected to these
Expand All @@ -56,17 +55,12 @@ export class BaseProtocol implements IBaseProtocolCore {
return getPeersForProtocol(this.components.peerStore, [this.multicodec]);
}

public async connectedPeers(withOpenStreams = false): Promise<Peer[]> {
public async connectedPeers(): Promise<Peer[]> {
const peers = await this.allPeers();
return peers.filter((peer) => {
const connections = this.components.connectionManager.getConnections(
peer.id
);
if (withOpenStreams) {
return connections.some((c) =>
c.streams.some((s) => s.protocol === this.multicodec)
);
}
return connections.length > 0;
});
}
Expand Down
14 changes: 0 additions & 14 deletions packages/sdk/src/protocols/base_protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export class BaseProtocolSDK implements IBaseProtocolSDK {
this.log.info(
`Initializing BaseProtocolSDK with numPeersToUse: ${this.numPeersToUse}, maintainPeersInterval: ${maintainPeersInterval}ms`
);
// void this.setupEventListeners();
void this.startMaintainPeersInterval(maintainPeersInterval);
}

Expand Down Expand Up @@ -83,18 +82,6 @@ export class BaseProtocolSDK implements IBaseProtocolSDK {
}
}

//TODO: validate if adding event listeners for peer connect and disconnect is needed
// private setupEventListeners(): void {
// this.core.addLibp2pEventListener(
// "peer:connect",
// () => void this.maintainPeers()
// );
// this.core.addLibp2pEventListener(
// "peer:disconnect",
// () => void this.maintainPeers()
// );
// }

/**
* Checks if there are sufficient peers to send a message to.
* If `forceUseAllPeers` is `false` (default), returns `true` if there are any connected peers.
Expand Down Expand Up @@ -162,7 +149,6 @@ export class BaseProtocolSDK implements IBaseProtocolSDK {
`Starting maintain peers interval with ${interval}ms interval`
);
try {
// await this.maintainPeers();
this.maintainPeersIntervalId = setInterval(() => {
this.log.debug("Running scheduled peer maintenance");
this.maintainPeers().catch((error) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/protocols/filter/subscription_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export class SubscriptionManager implements ISubscriptionSDK {
}

public async ping(peerId?: PeerId): Promise<SDKProtocolResult> {
log.info("Sending keep-alive ping");
const peers = peerId ? [peerId] : this.getPeers().map((peer) => peer.id);

const promises = peers.map((peerId) => this.pingSpecificPeer(peerId));
Expand Down Expand Up @@ -303,7 +304,6 @@ export class SubscriptionManager implements ISubscriptionSDK {
}

this.keepAliveTimer = setInterval(() => {
log.info("Sending keep-alive ping");
void this.ping()
.then(() => log.info("Keep-alive ping successful"))
.catch((error) => log.error("Error in keep-alive ping cycle:", error));
Expand Down

0 comments on commit 252ec59

Please sign in to comment.