diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 11:57:36 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 11:57:36 +0000 |
| commit | 4941490233a728bc7c64fa80a53d15f772a1219f (patch) | |
| tree | 7fc1bbf6114deb29b5a736b467abf785ea915f02 /src/sync/relay_connection.rs | |
| parent | 6cd7535f2d5f65477ef11b17a4661745ec3a2881 (diff) | |
sync: add sync_base_backoff_secs config for better testing
Diffstat (limited to 'src/sync/relay_connection.rs')
| -rw-r--r-- | src/sync/relay_connection.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/sync/relay_connection.rs b/src/sync/relay_connection.rs index 4f26779..9a580d2 100644 --- a/src/sync/relay_connection.rs +++ b/src/sync/relay_connection.rs | |||
| @@ -60,6 +60,9 @@ impl RelayConnection { | |||
| 60 | /// | 60 | /// |
| 61 | /// # Arguments | 61 | /// # Arguments |
| 62 | /// * `since` - Optional timestamp for incremental sync on reconnect | 62 | /// * `since` - Optional timestamp for incremental sync on reconnect |
| 63 | /// * `connection_timeout_secs` - Timeout for the connection attempt in seconds. | ||
| 64 | /// Should be no larger than base_backoff_secs to ensure the connection attempt | ||
| 65 | /// completes before the next retry would be scheduled. | ||
| 63 | /// | 66 | /// |
| 64 | /// # Returns | 67 | /// # Returns |
| 65 | /// * `Ok(SubscriptionId)` - The subscription ID on successful connection | 68 | /// * `Ok(SubscriptionId)` - The subscription ID on successful connection |
| @@ -67,6 +70,7 @@ impl RelayConnection { | |||
| 67 | pub async fn connect_and_subscribe( | 70 | pub async fn connect_and_subscribe( |
| 68 | &self, | 71 | &self, |
| 69 | since: Option<Timestamp>, | 72 | since: Option<Timestamp>, |
| 73 | connection_timeout_secs: u64, | ||
| 70 | ) -> Result<SubscriptionId, String> { | 74 | ) -> Result<SubscriptionId, String> { |
| 71 | // Add relay to client | 75 | // Add relay to client |
| 72 | self.client | 76 | self.client |
| @@ -83,13 +87,13 @@ impl RelayConnection { | |||
| 83 | // | 87 | // |
| 84 | // Using try_connect_relay gives us: | 88 | // Using try_connect_relay gives us: |
| 85 | // 1. Immediate error return on connection failure | 89 | // 1. Immediate error return on connection failure |
| 86 | // 2. Configurable timeout (5 seconds default) | 90 | // 2. Configurable timeout (set to base_backoff_secs to ensure retry timing works) |
| 87 | // 3. No conflicting retry logic (we use HealthTracker for backoff) | 91 | // 3. No conflicting retry logic (we use HealthTracker for backoff) |
| 88 | // 4. Cleaner error messages for metrics recording | 92 | // 4. Cleaner error messages for metrics recording |
| 89 | // | 93 | // |
| 90 | // See: nostr-sdk-0.44 Client::try_connect_relay documentation | 94 | // See: nostr-sdk-0.44 Client::try_connect_relay documentation |
| 91 | self.client | 95 | self.client |
| 92 | .try_connect_relay(&self.url, std::time::Duration::from_secs(5)) | 96 | .try_connect_relay(&self.url, std::time::Duration::from_secs(connection_timeout_secs)) |
| 93 | .await | 97 | .await |
| 94 | .map_err(|e| format!("Failed to connect to relay {}: {}", self.url, e))?; | 98 | .map_err(|e| format!("Failed to connect to relay {}: {}", self.url, e))?; |
| 95 | 99 | ||