From 9a5e3f3286ead76aee45e5802201a62ae42caf98 Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Tue, 6 Aug 2024 13:31:53 +0700 Subject: [PATCH] chore: choose peers from the connected pool, instead of dialing them --- packages/sdk/src/protocols/base_protocol.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/sdk/src/protocols/base_protocol.ts b/packages/sdk/src/protocols/base_protocol.ts index 8b6343a895..e5418b47b8 100644 --- a/packages/sdk/src/protocols/base_protocol.ts +++ b/packages/sdk/src/protocols/base_protocol.ts @@ -198,11 +198,6 @@ export class BaseProtocolSDK implements IBaseProtocolSDK { this.log.info(`Finding and adding ${numPeers} new peers`); try { const additionalPeers = await this.findAdditionalPeers(numPeers); - const dials = additionalPeers.map((peer) => - this.connectionManager.attemptDial(peer.id) - ); - - await Promise.all(dials); const updatedPeers = [...this.peers, ...additionalPeers]; this.updatePeers(updatedPeers); @@ -227,10 +222,17 @@ export class BaseProtocolSDK implements IBaseProtocolSDK { private async findAdditionalPeers(numPeers: number): Promise { this.log.info(`Finding ${numPeers} additional peers`); try { - let newPeers = await this.core.allPeers(); + let newPeers = await this.core.getPeers({ + maxBootstrapPeers: 0, + numPeers: 0 + }); if (newPeers.length === 0) { - this.log.warn("No new peers found."); + this.log.warn("No new peers found, trying with bootstrap peers"); + newPeers = await this.core.getPeers({ + maxBootstrapPeers: numPeers, + numPeers: 0 + }); } newPeers = newPeers