From c78239a6b7b03ccdacdfd14dcbf4471bee7b1922 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 2 Feb 2024 16:08:36 -0500 Subject: [PATCH] Fixes some connectivity issues by basing the timeout from the last connection tentative instead of the drop out time. --- .../vitorpamplona/amethyst/service/relays/Relay.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/service/relays/Relay.kt b/app/src/main/java/com/vitorpamplona/amethyst/service/relays/Relay.kt index fed6828b6..5a8e02523 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/service/relays/Relay.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/service/relays/Relay.kt @@ -77,7 +77,7 @@ class Relay( var errorCounter = 0 var pingInMs: Long? = null - var closingTimeInSeconds = 0L + var lastConnectTentative: Long = 0L var afterEOSEPerSubscription = mutableMapOf() @@ -120,6 +120,8 @@ class Relay( if (socket != null) return + lastConnectTentative = TimeUtils.now() + try { val request = Request.Builder() @@ -251,7 +253,6 @@ class Relay( this.isReady = false this.usingCompression = false this.resetEOSEStatuses() - this.closingTimeInSeconds = TimeUtils.now() } fun processNewRelayMessage(newMessage: String) { @@ -331,7 +332,7 @@ class Relay( Log.d("Relay", "Relay.disconnect $url") checkNotInMainThread() - closingTimeInSeconds = TimeUtils.now() + lastConnectTentative = 0L // this is not an error, so prepare to reconnect as soon as requested. socket?.cancel() socket = null isReady = false @@ -373,7 +374,7 @@ class Relay( } } else { // waits 60 seconds to reconnect after disconnected. - if (TimeUtils.now() > closingTimeInSeconds + RECONNECTING_IN_SECONDS) { + if (TimeUtils.now() > lastConnectTentative + RECONNECTING_IN_SECONDS) { // sends all filters after connection is successful. connect() } @@ -413,7 +414,7 @@ class Relay( if (socket == null) { // waits 60 seconds to reconnect after disconnected. - if (TimeUtils.now() > closingTimeInSeconds + RECONNECTING_IN_SECONDS) { + if (TimeUtils.now() > lastConnectTentative + RECONNECTING_IN_SECONDS) { // println("sendfilter Only if Disconnected ${url} ") connect() }