From e92a712c1e1419c3d680396be827aa0a85748999 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 16 Nov 2026 20:51:23 +0000 Subject: topology: neighbours among the members of a node's own party, and of parties named A node of a swarm holding a store keeps some of its neighbours among the members of its own party and of the parties its operator names (`--store-neighbour-parties`), so that a party listing many nodes can't be all of them (`docs/store.md`, Members): its neighbours by the shared graph among those members alone, each as its entry names it, which every node of its party computes alike, with those among all members. --- src/swarm/topology/mod.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/swarm') diff --git a/src/swarm/topology/mod.rs b/src/swarm/topology/mod.rs index 1d42724..f2538cc 100644 --- a/src/swarm/topology/mod.rs +++ b/src/swarm/topology/mod.rs @@ -399,6 +399,39 @@ fn of_the_store( .collect() } +/// In a swarm holding a store, this node's neighbours among the members of its own party +/// and of those its operator names (`Holding::nearby`), each as its entry names it, by the +/// shared graph among those alone, as each of them computes it (`docs/store.md`, +/// Members): so that a party listing many nodes can't be all of them. +#[cfg(feature = "federation")] +async fn nearby(state: &AppState, inputs: &Inputs<'_>) -> BTreeSet { + let parties = state.holding.nearby(); + if parties.is_empty() || !state.holding.tells_members() { + return BTreeSet::new(); + } + let group: BTreeMap> = { + let replica = state.doc.read().await; + inputs + .transports + .iter() + .filter(|(member, _)| { + members::party(&replica.doc, member) + .is_some_and(|party| parties.contains(&party.as_str())) + }) + .map(|(member, transports)| (member.clone(), transports.clone())) + .collect() + }; + neighbours_across( + &RingAndPairs, + &group, + state.local_id(), + inputs.local_transports, + inputs.k, + inputs.unreachable, + inputs.stable, + ) +} + /// Whether `peer` is in the member list, as the view was last computed from it; None /// while the view isn't known. pub(crate) fn listed(state: &AppState, peer: &str) -> Option { @@ -863,6 +896,8 @@ pub(crate) async fn refresh(state: &AppState) -> Option { None => state.peer_states.read().await.keys().cloned().collect(), }; let mut computed = topology.neighbours(state.local_id(), &inputs); + #[cfg(feature = "federation")] + computed.extend(nearby(state, &inputs).await); computed.extend(outbound.iter().cloned()); #[cfg(test)] let listed_neighbours = computed.len(); -- cgit v1.3.1