commit c4206883f2dfc3a431909953fc9f3f0346d01444
parent eb99e6c32316d1137a72a66da12ab2bd1e7c902a
Author: William Casarin <jb55@jb55.com>
Date: Mon, 17 Oct 2022 16:17:05 -0700
Even more aggressive reconnects
Sometimes it gets stuck in a "reconnecting" state. We'll retry even
these connections if the last connection attempt is too old.
Diffstat:
3 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/damus.xcodeproj/project.pbxproj b/damus.xcodeproj/project.pbxproj
@@ -876,7 +876,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = damus/damus.entitlements;
CODE_SIGN_STYLE = Automatic;
- CURRENT_PROJECT_VERSION = 2;
+ CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
DEVELOPMENT_TEAM = XK7H4JAB3D;
ENABLE_PREVIEWS = YES;
@@ -896,7 +896,7 @@
"$(inherited)",
"$(PROJECT_DIR)",
);
- MARKETING_VERSION = 0.1.4;
+ MARKETING_VERSION = 0.1.5;
PRODUCT_BUNDLE_IDENTIFIER = com.jb55.damus2;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
@@ -915,7 +915,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = damus/damus.entitlements;
CODE_SIGN_STYLE = Automatic;
- CURRENT_PROJECT_VERSION = 2;
+ CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"damus/Preview Content\"";
DEVELOPMENT_TEAM = XK7H4JAB3D;
ENABLE_PREVIEWS = YES;
@@ -935,7 +935,7 @@
"$(inherited)",
"$(PROJECT_DIR)",
);
- MARKETING_VERSION = 0.1.4;
+ MARKETING_VERSION = 0.1.5;
PRODUCT_BUNDLE_IDENTIFIER = com.jb55.damus2;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
diff --git a/damus/Nostr/RelayConnection.swift b/damus/Nostr/RelayConnection.swift
@@ -35,12 +35,12 @@ class RelayConnection: WebSocketDelegate {
self.disconnect()
} else {
// we're already disconnected, so just connect
- self.connect()
+ self.connect(force: true)
}
}
- func connect(){
- if self.isConnected || self.isConnecting {
+ func connect(force: Bool = false){
+ if !force && (self.isConnected || self.isConnecting) {
return
}
diff --git a/damus/Nostr/RelayPool.swift b/damus/Nostr/RelayPool.swift
@@ -81,11 +81,18 @@ class RelayPool {
func connect_to_disconnected() {
for relay in relays {
let c = relay.connection
- if relay.is_broken || c.isReconnecting || c.isConnecting || c.isConnected {
+
+ let is_connecting = c.isReconnecting || c.isConnecting
+
+ if is_connecting && (Date.now.timeIntervalSince1970 - c.last_connection_attempt) > 10 {
+ print("stale connection detected (\(relay.descriptor.url.absoluteString)). retrying...")
+ relay.connection.connect(force: true)
+ } else if relay.is_broken || is_connecting || c.isConnected {
continue
+ } else {
+ relay.connection.reconnect()
}
- relay.connection.reconnect()
}
}