diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-09 22:47:51 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-01-09 22:47:51 +0000 |
| commit | 953a4be45dda7477d3db8099722856eb11eb6bb2 (patch) | |
| tree | 5a4c59c8968607fbb82106c2ede0fb280f921fdc /src/sync | |
| parent | f1579d1c099869de67b1741b7775cbf651b34ef0 (diff) | |
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.
Diffstat (limited to 'src/sync')
| -rw-r--r-- | src/sync/mod.rs | 14 |
1 files changed, 10 insertions, 4 deletions
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 { | |||
| 1246 | 1246 | ||
| 1247 | // 6. Connect to bootstrap relay if configured | 1247 | // 6. Connect to bootstrap relay if configured |
| 1248 | if let Some(ref bootstrap_url) = self.bootstrap_relay_url.clone() { | 1248 | if let Some(ref bootstrap_url) = self.bootstrap_relay_url.clone() { |
| 1249 | self.register_relay(bootstrap_url.clone()).await; | 1249 | self.register_relay(bootstrap_url.clone(), true).await; |
| 1250 | self.try_connect_relay(bootstrap_url).await; | 1250 | self.try_connect_relay(bootstrap_url).await; |
| 1251 | } | 1251 | } |
| 1252 | 1252 | ||
| @@ -1356,7 +1356,7 @@ impl SyncManager { | |||
| 1356 | ); | 1356 | ); |
| 1357 | 1357 | ||
| 1358 | // Register relay (creates RelayConnection, initializes RelayState, updates metrics) | 1358 | // Register relay (creates RelayConnection, initializes RelayState, updates metrics) |
| 1359 | self.register_relay(action.relay_url.clone()).await; | 1359 | self.register_relay(action.relay_url.clone(), false).await; |
| 1360 | self.try_connect_relay(&action.relay_url).await; | 1360 | self.try_connect_relay(&action.relay_url).await; |
| 1361 | // Connection will trigger handle_connect_or_reconnect which will process items | 1361 | // Connection will trigger handle_connect_or_reconnect which will process items |
| 1362 | return; | 1362 | return; |
| @@ -1868,7 +1868,7 @@ impl SyncManager { | |||
| 1868 | /// Also initializes RelayState if it doesn't exist. | 1868 | /// Also initializes RelayState if it doesn't exist. |
| 1869 | /// Does NOT connect - connection happens via try_connect_relay or retry_disconnected_relays. | 1869 | /// Does NOT connect - connection happens via try_connect_relay or retry_disconnected_relays. |
| 1870 | /// The RelayConnection persists forever and is reused on reconnects. | 1870 | /// The RelayConnection persists forever and is reused on reconnects. |
| 1871 | async fn register_relay(&mut self, relay_url: String) { | 1871 | async fn register_relay(&mut self, relay_url: String, is_bootstrap: bool) { |
| 1872 | // Create RelayConnection if not exists | 1872 | // Create RelayConnection if not exists |
| 1873 | if !self.connections.contains_key(&relay_url) { | 1873 | if !self.connections.contains_key(&relay_url) { |
| 1874 | // Get relay owner keys for NIP-42 authentication | 1874 | // Get relay owner keys for NIP-42 authentication |
| @@ -1892,7 +1892,7 @@ impl SyncManager { | |||
| 1892 | if !index.contains_key(&relay_url) { | 1892 | if !index.contains_key(&relay_url) { |
| 1893 | let new_state = RelayState { | 1893 | let new_state = RelayState { |
| 1894 | connection_status: ConnectionStatus::Disconnected, | 1894 | connection_status: ConnectionStatus::Disconnected, |
| 1895 | is_bootstrap: false, | 1895 | is_bootstrap, |
| 1896 | last_connected: None, | 1896 | last_connected: None, |
| 1897 | disconnected_at: None, | 1897 | disconnected_at: None, |
| 1898 | repos: HashSet::new(), | 1898 | repos: HashSet::new(), |
| @@ -1905,6 +1905,12 @@ impl SyncManager { | |||
| 1905 | index.insert(relay_url.clone(), new_state); | 1905 | index.insert(relay_url.clone(), new_state); |
| 1906 | true | 1906 | true |
| 1907 | } else { | 1907 | } else { |
| 1908 | // If relay already exists and is_bootstrap is true, update the flag | ||
| 1909 | if is_bootstrap { | ||
| 1910 | if let Some(state) = index.get_mut(&relay_url) { | ||
| 1911 | state.is_bootstrap = true; | ||
| 1912 | } | ||
| 1913 | } | ||
| 1908 | false | 1914 | false |
| 1909 | } | 1915 | } |
| 1910 | }; | 1916 | }; |