diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 16:53:03 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-12-11 16:53:03 +0000 |
| commit | 2a9160836bb87fdea3ae891563b0169c68d1c2ab (patch) | |
| tree | 583c890687beaf7f380fc0be131bdf17485f06fa /src/sync/relay_connection.rs | |
| parent | 52489d3b1a7d79e164b4cc901b53fd06c05ce1b1 (diff) | |
fix: resolve all fmt and clippy warnings
Main lib (src/):
- Add #[allow(dead_code)] for build_info field (stored to prevent Prometheus unregistration)
- Add #[allow(dead_code)] for first_seen field (reserved for future rate limiting)
- Replace .or_insert_with(RelaySyncNeeds::default) with .or_default()
- Replace manual div_ceil implementations with .div_ceil(100)
Test code (tests/):
- Replace .expect(&format!(...)) with .unwrap_or_else(|_| panic!(...))
- Remove needless borrows in fetch_metrics() calls
- Add #[allow(dead_code)] and #[allow(unused_imports)] to test helpers module
grasp-audit:
- Apply cargo fmt to fix formatting
Diffstat (limited to 'src/sync/relay_connection.rs')
| -rw-r--r-- | src/sync/relay_connection.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/sync/relay_connection.rs b/src/sync/relay_connection.rs index fae179b..4167a0c 100644 --- a/src/sync/relay_connection.rs +++ b/src/sync/relay_connection.rs | |||
| @@ -150,17 +150,21 @@ impl RelayConnection { | |||
| 150 | // | 150 | // |
| 151 | // See: nostr-sdk-0.44 Client::try_connect_relay documentation | 151 | // See: nostr-sdk-0.44 Client::try_connect_relay documentation |
| 152 | self.client | 152 | self.client |
| 153 | .try_connect_relay(&self.url, std::time::Duration::from_secs(connection_timeout_secs)) | 153 | .try_connect_relay( |
| 154 | &self.url, | ||
| 155 | std::time::Duration::from_secs(connection_timeout_secs), | ||
| 156 | ) | ||
| 154 | .await | 157 | .await |
| 155 | .map_err(|e| format!("Failed to connect to relay {}: {}", self.url, e))?; | 158 | .map_err(|e| format!("Failed to connect to relay {}: {}", self.url, e))?; |
| 156 | 159 | ||
| 157 | // Subscribe to Layer 1 (announcements) | 160 | // Subscribe to Layer 1 (announcements) |
| 158 | let filter = build_announcement_filter(since); | 161 | let filter = build_announcement_filter(since); |
| 159 | let output = self | 162 | let output = self.client.subscribe(filter, None).await.map_err(|e| { |
| 160 | .client | 163 | format!( |
| 161 | .subscribe(filter, None) | 164 | "Failed to subscribe to announcements on {}: {}", |
| 162 | .await | 165 | self.url, e |
| 163 | .map_err(|e| format!("Failed to subscribe to announcements on {}: {}", self.url, e))?; | 166 | ) |
| 167 | })?; | ||
| 164 | 168 | ||
| 165 | tracing::info!(url = %self.url, sub_id = %output.val, "Connected and subscribed to Layer 1 (announcements)"); | 169 | tracing::info!(url = %self.url, sub_id = %output.val, "Connected and subscribed to Layer 1 (announcements)"); |
| 166 | Ok(output.val) | 170 | Ok(output.val) |
| @@ -250,7 +254,8 @@ impl RelayConnection { | |||
| 250 | } | 254 | } |
| 251 | RelayMessage::Closed { message: msg, .. } => { | 255 | RelayMessage::Closed { message: msg, .. } => { |
| 252 | tracing::info!(relay = %url, message = %msg, "Relay closed subscription"); | 256 | tracing::info!(relay = %url, message = %msg, "Relay closed subscription"); |
| 253 | let _ = event_sender.send(RelayEvent::Closed(msg.to_string())).await; | 257 | let _ = |
| 258 | event_sender.send(RelayEvent::Closed(msg.to_string())).await; | ||
| 254 | break; | 259 | break; |
| 255 | } | 260 | } |
| 256 | _ => {} | 261 | _ => {} |
| @@ -421,7 +426,10 @@ impl RelayConnection { | |||
| 421 | /// - Relay doesn't actually support NIP-77 (despite claiming to) | 426 | /// - Relay doesn't actually support NIP-77 (despite claiming to) |
| 422 | /// - Network errors during reconciliation | 427 | /// - Network errors during reconciliation |
| 423 | /// - Timeout during sync | 428 | /// - Timeout during sync |
| 424 | pub async fn negentropy_sync_filter(&self, filter: Filter) -> Result<NegentropySyncResult, String> { | 429 | pub async fn negentropy_sync_filter( |
| 430 | &self, | ||
| 431 | filter: Filter, | ||
| 432 | ) -> Result<NegentropySyncResult, String> { | ||
| 425 | // Use nostr-sdk's sync method which handles the NEG-OPEN/NEG-MSG exchange | 433 | // Use nostr-sdk's sync method which handles the NEG-OPEN/NEG-MSG exchange |
| 426 | let sync_opts = SyncOptions::default(); | 434 | let sync_opts = SyncOptions::default(); |
| 427 | 435 | ||