From 953a4be45dda7477d3db8099722856eb11eb6bb2 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 9 Jan 2026 22:47:51 +0000 Subject: fix: mark bootstrap relay with is_bootstrap flag to prevent disconnection The bootstrap relay was being registered with is_bootstrap=false, causing it to be disconnected when empty. This change adds an is_bootstrap parameter to register_relay() and passes true when registering the bootstrap relay. The existing check_disconnects() logic already skips bootstrap relays, but the flag was never being set correctly. --- src/sync/mod.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/sync/mod.rs') diff --git a/src/sync/mod.rs b/src/sync/mod.rs index 70f9dd7..479ab33 100644 --- a/src/sync/mod.rs +++ b/src/sync/mod.rs @@ -1246,7 +1246,7 @@ impl SyncManager { // 6. Connect to bootstrap relay if configured if let Some(ref bootstrap_url) = self.bootstrap_relay_url.clone() { - self.register_relay(bootstrap_url.clone()).await; + self.register_relay(bootstrap_url.clone(), true).await; self.try_connect_relay(bootstrap_url).await; } @@ -1356,7 +1356,7 @@ impl SyncManager { ); // Register relay (creates RelayConnection, initializes RelayState, updates metrics) - self.register_relay(action.relay_url.clone()).await; + self.register_relay(action.relay_url.clone(), false).await; self.try_connect_relay(&action.relay_url).await; // Connection will trigger handle_connect_or_reconnect which will process items return; @@ -1868,7 +1868,7 @@ impl SyncManager { /// Also initializes RelayState if it doesn't exist. /// Does NOT connect - connection happens via try_connect_relay or retry_disconnected_relays. /// The RelayConnection persists forever and is reused on reconnects. - async fn register_relay(&mut self, relay_url: String) { + async fn register_relay(&mut self, relay_url: String, is_bootstrap: bool) { // Create RelayConnection if not exists if !self.connections.contains_key(&relay_url) { // Get relay owner keys for NIP-42 authentication @@ -1892,7 +1892,7 @@ impl SyncManager { if !index.contains_key(&relay_url) { let new_state = RelayState { connection_status: ConnectionStatus::Disconnected, - is_bootstrap: false, + is_bootstrap, last_connected: None, disconnected_at: None, repos: HashSet::new(), @@ -1905,6 +1905,12 @@ impl SyncManager { index.insert(relay_url.clone(), new_state); true } else { + // If relay already exists and is_bootstrap is true, update the flag + if is_bootstrap { + if let Some(state) = index.get_mut(&relay_url) { + state.is_bootstrap = true; + } + } false } }; -- cgit v1.2.3