Skip to content

Commit

Permalink
chore: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
danisharora099 committed Sep 17, 2024
1 parent 7a6247c commit 6a2d787
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions packages/core/src/lib/base_protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ export class BaseProtocol implements IBaseProtocolCore {
public async connectedPeers(): Promise<Peer[]> {
const peers = await this.allPeers();
return peers.filter((peer) => {
return (
this.components.connectionManager.getConnections(peer.id).length > 0
const connections = this.components.connectionManager.getConnections(
peer.id
);
return connections.some((c) =>
c.streams.some((s) => s.protocol === this.multicodec)
);
});
}
Expand Down
6 changes: 6 additions & 0 deletions packages/sdk/src/protocols/base_protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export class BaseProtocolSDK implements IBaseProtocolSDK {
}

this.maintainPeersLock = true;
await this.confirmPeers();
this.log.info(`Maintaining peers, current count: ${this.peers.length}`);
try {
const numPeersToAdd = this.numPeersToUse - this.peers.length;
Expand All @@ -190,6 +191,11 @@ export class BaseProtocolSDK implements IBaseProtocolSDK {
return true;
}

private async confirmPeers(): Promise<void> {
const peers = await this.core.connectedPeers();
this.updatePeers(peers);
}

/**
* Finds and adds new peers to the peers list.
* @param numPeers The number of peers to find and add.
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/protocols/filter/subscription_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ export class SubscriptionManager implements ISubscriptionSDK {
}

this.keepAliveTimer = setInterval(() => {
void this.ping().catch((error) => {
log.error("Error in keep-alive ping cycle:", error);
});
void this.ping()
.then(() => log.info("Keep-alive ping successful"))
.catch((error) => log.error("Error in keep-alive ping cycle:", error));
}, interval) as unknown as number;
}

Expand Down

0 comments on commit 6a2d787

Please sign in to comment.