From 1e5ff05f9ba3c2e6af065ab0e7417083b3657acc Mon Sep 17 00:00:00 2001 From: Billie Hilton <587740+billiegoose@users.noreply.github.com> Date: Mon, 24 Jun 2024 13:49:28 -0400 Subject: [PATCH 1/2] relay on initial attempt --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 036ec8a..6dc3a3b 100644 --- a/index.js +++ b/index.js @@ -161,7 +161,7 @@ module.exports = class Hyperswarm extends EventEmitter { return } - const relayThrough = this._maybeRelayConnection(peerInfo.forceRelaying) + const relayThrough = this._maybeRelayConnection(peerInfo.forceRelaying || peerInfo.attempts === 0) const conn = this.dht.connect(peerInfo.publicKey, { relayAddresses: peerInfo.relayAddresses, keyPair: this.keyPair, From af6a87b10f8de39ce1fcfce9bfe400e211a54b70 Mon Sep 17 00:00:00 2001 From: Billie Hilton <587740+billiegoose@users.noreply.github.com> Date: Mon, 24 Jun 2024 16:26:04 -0400 Subject: [PATCH 2/2] reset attempts back to 0, not to 1 --- lib/peer-info.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/peer-info.js b/lib/peer-info.js index 8ac79e5..ed1b329 100644 --- a/lib/peer-info.js +++ b/lib/peer-info.js @@ -66,11 +66,12 @@ module.exports = class PeerInfo extends EventEmitter { } _disconnected () { - if (this.connectedTime > -1) { - if ((Date.now() - this.connectedTime) >= MIN_CONNECTION_TIME) this.attempts = 0 // fast retry - this.connectedTime = -1 + if (this.connectedTime > -1 && (Date.now() - this.connectedTime) >= MIN_CONNECTION_TIME) { + this.attempts = 0 // fast retry + } else { + this.attempts++ } - this.attempts++ + this.connectedTime = -1 } _deprioritize () {