aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-16 20:51:23 +0000
committertv <tv@krebsco.de>2026-11-16 22:04:05 +0100
commite92a712c1e1419c3d680396be827aa0a85748999 (patch)
treefa02c2075de4590325a0a6b6ffad76ee532a8539 /src/swarm
parent1343cc9bdacb6dc7b31652b4529ec843d11d1625 (diff)
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.
Diffstat (limited to 'src/swarm')
-rw-r--r--src/swarm/topology/mod.rs35
1 files changed, 35 insertions, 0 deletions
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<String> {
+ let parties = state.holding.nearby();
+ if parties.is_empty() || !state.holding.tells_members() {
+ return BTreeSet::new();
+ }
+ let group: BTreeMap<String, BTreeSet<String>> = {
+ 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<bool> {
@@ -863,6 +896,8 @@ pub(crate) async fn refresh(state: &AppState) -> Option<NeighbourChange> {
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();