Browse Source

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.
profile-edit
William Casarin 2 years ago
parent
commit
c4206883f2
  1. 8
      damus.xcodeproj/project.pbxproj
  2. 6
      damus/Nostr/RelayConnection.swift
  3. 11
      damus/Nostr/RelayPool.swift

8
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;

6
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
}

11
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()
}
}

Loading…
Cancel
Save