From e98a3850b6dcd3bbd5d251896ef56199cd49dc33 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Thu, 18 Dec 2025 12:06:57 +0000 Subject: sync: new connection logic --- src/sync/health.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/sync/health.rs') 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 { pub last_failure_time: Option, /// Time of the last successful connection pub last_success_time: Option, + /// Time of the last connection attempt (success or failure) + pub last_attempt_time: Option, /// Next time a connection attempt should be made pub next_retry_at: Option, } @@ -76,6 +78,7 @@ impl Default for RelayHealth { first_failure_time: None, last_failure_time: None, last_success_time: None, + last_attempt_time: None, next_retry_at: None, } } @@ -132,6 +135,17 @@ impl RelayHealthTracker { self.base_backoff_secs } + /// Record a connection attempt (updates last_attempt_time) + /// + /// This should be called before trying to connect, to track when + /// attempts are made regardless of success or failure. + pub fn record_attempt(&self, relay_url: &str) { + let now = Instant::now(); + let mut entry = self.health.entry(relay_url.to_string()).or_default(); + let health = entry.value_mut(); + health.last_attempt_time = Some(now); + } + /// Record a successful connection to a relay /// /// Resets the relay to Healthy state and clears failure counters. @@ -148,6 +162,7 @@ impl RelayHealthTracker { health.first_failure_time = None; health.last_failure_time = None; health.last_success_time = Some(now); + health.last_attempt_time = Some(now); health.next_retry_at = None; if old_state != HealthState::Healthy { -- cgit v1.2.3