From f9731343f71beced8ec8c817d19022fdfebc4545 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 23 Oct 2026 21:15:39 +0200 Subject: catch up with a single source only --- src/state.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/state.rs') diff --git a/src/state.rs b/src/state.rs index 3ee9c6c..4fbc05b 100644 --- a/src/state.rs +++ b/src/state.rs @@ -528,6 +528,17 @@ pub(crate) struct AppState { /// While rejoining a newer epoch, the previous document, served read-only (and /// marked stale) instead of answering 503. pub(crate) stale: Arc>>, + + /// While the initial sync isn't done: the one peer we catch up from. + pub(crate) catch_up_source: Arc>>, +} + +/// The peer a catching-up node syncs with first (`swarm::sync::defer_for_catch_up`). +#[derive(Clone, Debug)] +pub(crate) struct CatchUpSource { + pub(crate) peer: String, + /// When it was chosen or last sent us something. + pub(crate) last_progress: Instant, } impl AppState { @@ -986,6 +997,10 @@ impl Host for AppState { fn reset_initial_sync(&self) { self.initial_sync_done .store(false, std::sync::atomic::Ordering::Release); + *self + .catch_up_source + .lock() + .unwrap_or_else(|poisoned| poisoned.into_inner()) = None; } fn subscribe_changes(&self) -> broadcast::Receiver> { -- cgit v1.3.1