fix: fix retry logic

This commit is contained in:
Derrick Hammer 2023-08-31 02:36:23 -04:00
parent a021243c89
commit 1221d7de63
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 7 additions and 17 deletions

View File

@ -461,7 +461,7 @@ export class P2PService {
} }
} }
async connectToNode(connectionUris: URL[]): Promise<void> { async connectToNode(connectionUris: URL[], retried = false): Promise<void> {
const unsupported = new URL("http://0.0.0.0"); const unsupported = new URL("http://0.0.0.0");
unsupported.protocol = "unsupported"; unsupported.protocol = "unsupported";
@ -493,8 +493,6 @@ export class P2PService {
return; return;
} }
let retried = false;
try { try {
this.logger.verbose(`[connect] ${connectionUri}`); this.logger.verbose(`[connect] ${connectionUri}`);
if (protocol === "tcp:") { if (protocol === "tcp:") {
@ -513,26 +511,18 @@ export class P2PService {
await this.onNewPeer(peer, true); await this.onNewPeer(peer, true);
} }
} catch (e) { } catch (e) {
if (retried) return; if (retried) {
return;
}
retried = true; retried = true;
this.logger.catched(e); this.logger.catched(e);
/* if (e instanceof SocketException) { const delay = this.reconnectDelay.get(id.toString())!;
if (e.message === "Connection refused") { this.reconnectDelay.set(id.toString(), delay * 2);
this.logger.warn(`[!] ${id}: ${e}`);
} else {
this.logger.catched(e);
}
} else {
this.logger.catched(e);
}*/
const delay = this.reconnectDelay.get(id)!;
this.reconnectDelay.set(id, delay * 2);
await new Promise((resolve) => setTimeout(resolve, delay * 1000)); await new Promise((resolve) => setTimeout(resolve, delay * 1000));
await this.connectToNode(connectionUris); await this.connectToNode(connectionUris, retried);
} }
} }
} }