mirror of
https://github.com/waku-org/js-waku.git
synced 2025-02-20 08:08:20 +00:00
chore: improve hasPeers()
This commit is contained in:
parent
874d835117
commit
b9bfaa27c3
@ -100,28 +100,19 @@ export class BaseProtocolSDK implements IBaseProtocolSDK {
|
|||||||
`Checking for peers. forceUseAllPeers: ${forceUseAllPeers}, maxAttempts: ${maxAttempts}`
|
`Checking for peers. forceUseAllPeers: ${forceUseAllPeers}, maxAttempts: ${maxAttempts}`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!forceUseAllPeers && this.connectedPeers.length > 0) {
|
|
||||||
this.log.debug(
|
|
||||||
`At least one peer connected (${this.connectedPeers.length}), not forcing use of all peers`
|
|
||||||
);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!forceUseAllPeers) {
|
|
||||||
await this.maintainPeers();
|
|
||||||
const hasPeers = this.connectedPeers.length > 0;
|
|
||||||
this.log.debug(
|
|
||||||
`After maintenance, connected peers: ${this.connectedPeers.length}`
|
|
||||||
);
|
|
||||||
return hasPeers;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let attempts = 0; attempts < maxAttempts; attempts++) {
|
for (let attempts = 0; attempts < maxAttempts; attempts++) {
|
||||||
this.log.debug(
|
this.log.debug(
|
||||||
`Attempt ${attempts + 1}/${maxAttempts} to reach required number of peers`
|
`Attempt ${attempts + 1}/${maxAttempts} to reach required number of peers`
|
||||||
);
|
);
|
||||||
await this.maintainPeers();
|
await this.maintainPeers();
|
||||||
|
|
||||||
|
if (!forceUseAllPeers && this.connectedPeers.length > 0) {
|
||||||
|
this.log.debug(
|
||||||
|
`At least one peer connected (${this.connectedPeers.length}), not forcing use of all peers`
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.connectedPeers.length >= this.numPeersToUse) {
|
if (this.connectedPeers.length >= this.numPeersToUse) {
|
||||||
this.log.info(
|
this.log.info(
|
||||||
`Required number of peers (${this.numPeersToUse}) reached`
|
`Required number of peers (${this.numPeersToUse}) reached`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user