Fixes some connectivity issues by basing the timeout from the last connection tentative instead of the drop out time.

This commit is contained in:
Vitor Pamplona 2024-02-02 16:08:36 -05:00
parent 4be4306540
commit c78239a6b7

View File

@ -77,7 +77,7 @@ class Relay(
var errorCounter = 0
var pingInMs: Long? = null
var closingTimeInSeconds = 0L
var lastConnectTentative: Long = 0L
var afterEOSEPerSubscription = mutableMapOf<String, Boolean>()
@ -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()
}