upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-22 21:03:49 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-22 21:03:49 +0000
commit6b55efedba7c069eff7a3e335845a961d40274db (patch)
tree7e036869007cb503fda5a81d959ecd49a9b3e5a3 /src
parent1df90c609399c675e629b97294aee81a0b1e66dd (diff)
chore: cargo fmt and clippy
Diffstat (limited to 'src')
-rw-r--r--src/sync/health.rs12
-rw-r--r--src/sync/mod.rs2
-rw-r--r--src/sync/relay_connection.rs4
3 files changed, 10 insertions, 8 deletions
diff --git a/src/sync/health.rs b/src/sync/health.rs
index a10427f..2948707 100644
--- a/src/sync/health.rs
+++ b/src/sync/health.rs
@@ -136,12 +136,14 @@ impl RelayHealth {
136 136
137 // Check if we're in stability period after recovery 137 // Check if we're in stability period after recovery
138 // (recovered from failures but not yet proven stable) 138 // (recovered from failures but not yet proven stable)
139 if let (Some(last_success), Some(last_failure)) = (self.last_success_time, self.last_failure_time) { 139 if let (Some(last_success), Some(last_failure)) =
140 (self.last_success_time, self.last_failure_time)
141 {
140 // Only consider stability period if recovery happened after the last failure 142 // Only consider stability period if recovery happened after the last failure
141 if last_success > last_failure { 143 if last_success > last_failure {
142 let time_since_recovery = now.duration_since(last_success); 144 let time_since_recovery = now.duration_since(last_success);
143 let stability_period = Duration::from_secs(STABILITY_PERIOD_SECS); 145 let stability_period = Duration::from_secs(STABILITY_PERIOD_SECS);
144 146
145 if time_since_recovery < stability_period { 147 if time_since_recovery < stability_period {
146 // Still in stability period - remain degraded to prove stability 148 // Still in stability period - remain degraded to prove stability
147 return HealthState::Degraded; 149 return HealthState::Degraded;
@@ -339,9 +341,10 @@ impl RelayHealthTracker {
339 // Respect existing next_retry_at if it's later (e.g., from rate limiting) 341 // Respect existing next_retry_at if it's later (e.g., from rate limiting)
340 let new_retry_at = now + backoff; 342 let new_retry_at = now + backoff;
341 health.next_retry_at = Some( 343 health.next_retry_at = Some(
342 health.next_retry_at 344 health
345 .next_retry_at
343 .unwrap_or(new_retry_at) 346 .unwrap_or(new_retry_at)
344 .max(new_retry_at) 347 .max(new_retry_at),
345 ); 348 );
346 349
347 let new_state = health.state(); 350 let new_state = health.state();
@@ -393,7 +396,6 @@ impl RelayHealthTracker {
393 } 396 }
394 } 397 }
395 398
396
397 /// Check if relay is currently rate limited 399 /// Check if relay is currently rate limited
398 /// 400 ///
399 /// Returns true if the relay is in RateLimited state and the cooldown period 401 /// Returns true if the relay is in RateLimited state and the cooldown period
diff --git a/src/sync/mod.rs b/src/sync/mod.rs
index 6ec39e8..65affc6 100644
--- a/src/sync/mod.rs
+++ b/src/sync/mod.rs
@@ -1599,7 +1599,7 @@ impl SyncManager {
1599 write_policy: &Nip34WritePolicy, 1599 write_policy: &Nip34WritePolicy,
1600 local_relay: &LocalRelay, 1600 local_relay: &LocalRelay,
1601 ) -> ProcessResult { 1601 ) -> ProcessResult {
1602 use nostr_relay_builder::prelude::{WritePolicyResult, WritePolicy}; 1602 use nostr_relay_builder::prelude::{WritePolicy, WritePolicyResult};
1603 use std::net::{IpAddr, Ipv4Addr, SocketAddr}; 1603 use std::net::{IpAddr, Ipv4Addr, SocketAddr};
1604 // Check if event already exists 1604 // Check if event already exists
1605 match database.event_by_id(&event.id).await { 1605 match database.event_by_id(&event.id).await {
diff --git a/src/sync/relay_connection.rs b/src/sync/relay_connection.rs
index de20e0f..bd9ab80 100644
--- a/src/sync/relay_connection.rs
+++ b/src/sync/relay_connection.rs
@@ -24,7 +24,7 @@ use crate::nostr::builder::SharedDatabase;
24#[derive(Debug)] 24#[derive(Debug)]
25pub enum RelayEvent { 25pub enum RelayEvent {
26 /// A new event was received (event, subscription_id) 26 /// A new event was received (event, subscription_id)
27 Event(Event, SubscriptionId), 27 Event(Box<Event>, SubscriptionId),
28 /// End of stored events for a subscription 28 /// End of stored events for a subscription
29 EndOfStoredEvents(SubscriptionId), 29 EndOfStoredEvents(SubscriptionId),
30 /// NOTICE message from relay 30 /// NOTICE message from relay
@@ -219,7 +219,7 @@ impl RelayConnection {
219 "Received event" 219 "Received event"
220 ); 220 );
221 if event_sender 221 if event_sender
222 .send(RelayEvent::Event(*event, subscription_id.clone())) 222 .send(RelayEvent::Event(Box::new(*event), subscription_id.clone()))
223 .await 223 .await
224 .is_err() 224 .is_err()
225 { 225 {