From 6fa188610ce0959e0b61ecaf63f5babf826d2071 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 24 Oct 2026 04:23:38 +0200 Subject: pull missing changes Nodes push changes to their neighbours but don't relay them directly. In a partial mesh, nodes can learn about missing changes via keepalive messages and can pull them from their neighbours. --- src/swarm/topology.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/swarm/topology.rs') diff --git a/src/swarm/topology.rs b/src/swarm/topology.rs index b5880cf..dddf81b 100644 --- a/src/swarm/topology.rs +++ b/src/swarm/topology.rs @@ -33,6 +33,18 @@ pub(crate) struct NeighbourView { k: usize, unreachable: BTreeSet, neighbours: BTreeSet, + /// Every reachable member is a neighbour. + full_mesh: bool, +} + +/// Whether every reachable member is our neighbour (also while the view is unknown). +pub(crate) fn is_full_mesh(state: &AppState) -> bool { + state + .neighbours + .read() + .unwrap_or_else(|poisoned| poisoned.into_inner()) + .as_ref() + .is_none_or(|view| view.full_mesh) } /// Whether we initiate contact with `peer`: HELLOs, keepalives, dormancy checks, sync @@ -113,10 +125,15 @@ pub(crate) async fn refresh(state: &AppState) -> Option { removed = change.removed.len(), "Neighbours computed from the member list" ); + let reachable_others = current + .iter() + .filter(|m| m.as_str() != state.local_id() && !unreachable.contains(*m)) + .count(); *state .neighbours .write() .unwrap_or_else(|poisoned| poisoned.into_inner()) = Some(NeighbourView { + full_mesh: computed.len() >= reachable_others, members: current, k, unreachable, -- cgit v1.3.1