From 5710d1a367a1914d09e0eefe6984408c95a7dd2e Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 24 Oct 2026 04:16:56 +0200 Subject: sync with neighbours --- src/state.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/state.rs') diff --git a/src/state.rs b/src/state.rs index cfa5ddf..64fe6a4 100644 --- a/src/state.rs +++ b/src/state.rs @@ -321,6 +321,14 @@ impl PeerState { false } + /// No more HELLO retries (the peer isn't our neighbour any more). A HELLO in flight + /// finishes; a later handshake starts over. + pub(crate) fn stop_hello_retries(&mut self) { + if matches!(self.hello_state, HelloState::AwaitingReply { .. }) { + self.hello_state = HelloState::NotSent; + } + } + /// Moves a silent peer to Dormant. Returns true on the transition. pub(crate) fn check_dormancy(&mut self, timing: &Timing, now: Instant) -> bool { if self.liveness != Liveness::Active || self.quiet_for(now) < timing.dormant_after { @@ -495,6 +503,12 @@ pub(crate) struct AppState { /// Random per run of this node; our HELLOs carry it and replies must echo it. pub(crate) run_id: transport::RunId, + /// Target number of neighbours (`--neighbours`); up to this many + 1 members the + /// swarm is a full mesh. + pub(crate) neighbours_k: usize, + /// Our neighbours, once known (`swarm::topology`). + pub(crate) neighbours: Arc>>, + /// While rejoining a newer epoch, the previous document, served read-only (and /// marked stale) instead of answering 503. pub(crate) stale: Arc>>, @@ -751,6 +765,10 @@ impl AppState { let local = self.local_epoch(); let mut announce = Vec::new(); for (id, peer_state_mutex) in &peers { + // Others learn it from their own neighbours. + if !crate::swarm::topology::is_neighbour(self, id) { + continue; + } let mut peer_state = peer_state_mutex.lock().await; // What it said about syncing with us was about our old epoch. peer_state.syncs_with_us = None; -- cgit v1.3.1