upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/sync/health.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2025-12-18 12:06:57 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2025-12-18 12:06:57 +0000
commite98a3850b6dcd3bbd5d251896ef56199cd49dc33 (patch)
tree8b0314c3a6633f9105a53305ada3b199e593dd84 /src/sync/health.rs
parent03f074d0d0840b946a356badde75551d61c0f84c (diff)
sync: new connection logic
Diffstat (limited to 'src/sync/health.rs')
-rw-r--r--src/sync/health.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/sync/health.rs b/src/sync/health.rs
index 0ae7dee..d919a80 100644
--- a/src/sync/health.rs
+++ b/src/sync/health.rs
@@ -64,6 +64,8 @@ pub struct RelayHealth {
64 pub last_failure_time: Option<Instant>, 64 pub last_failure_time: Option<Instant>,
65 /// Time of the last successful connection 65 /// Time of the last successful connection
66 pub last_success_time: Option<Instant>, 66 pub last_success_time: Option<Instant>,
67 /// Time of the last connection attempt (success or failure)
68 pub last_attempt_time: Option<Instant>,
67 /// Next time a connection attempt should be made 69 /// Next time a connection attempt should be made
68 pub next_retry_at: Option<Instant>, 70 pub next_retry_at: Option<Instant>,
69} 71}
@@ -76,6 +78,7 @@ impl Default for RelayHealth {
76 first_failure_time: None, 78 first_failure_time: None,
77 last_failure_time: None, 79 last_failure_time: None,
78 last_success_time: None, 80 last_success_time: None,
81 last_attempt_time: None,
79 next_retry_at: None, 82 next_retry_at: None,
80 } 83 }
81 } 84 }
@@ -132,6 +135,17 @@ impl RelayHealthTracker {
132 self.base_backoff_secs 135 self.base_backoff_secs
133 } 136 }
134 137
138 /// Record a connection attempt (updates last_attempt_time)
139 ///
140 /// This should be called before trying to connect, to track when
141 /// attempts are made regardless of success or failure.
142 pub fn record_attempt(&self, relay_url: &str) {
143 let now = Instant::now();
144 let mut entry = self.health.entry(relay_url.to_string()).or_default();
145 let health = entry.value_mut();
146 health.last_attempt_time = Some(now);
147 }
148
135 /// Record a successful connection to a relay 149 /// Record a successful connection to a relay
136 /// 150 ///
137 /// Resets the relay to Healthy state and clears failure counters. 151 /// Resets the relay to Healthy state and clears failure counters.
@@ -148,6 +162,7 @@ impl RelayHealthTracker {
148 health.first_failure_time = None; 162 health.first_failure_time = None;
149 health.last_failure_time = None; 163 health.last_failure_time = None;
150 health.last_success_time = Some(now); 164 health.last_success_time = Some(now);
165 health.last_attempt_time = Some(now);
151 health.next_retry_at = None; 166 health.next_retry_at = None;
152 167
153 if old_state != HealthState::Healthy { 168 if old_state != HealthState::Healthy {