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/config/mod.rs | 40 ++++++++++++++++++++++++++++++++++++++++ src/federation/held.rs | 23 +++++++++++++++++++++++ src/main.rs | 3 ++- src/swarm/topology/mod.rs | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/config/mod.rs b/src/config/mod.rs index 726ca12..762e9a4 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -240,6 +240,14 @@ pub(crate) const OPTIONS: &[OptionSpec] = &[ None, "With store-root or store-id, which need it: the party this node is of (docs/store.md, Members), named in its entry and its handshakes. Nodes of a swarm holding a store sync with the nodes its parties list, each as its party's, and with no others.", ), + #[cfg(feature = "federation")] + option( + "store-neighbour-parties", + Kind::List, + "NAME,[NAME...]", + None, + "With store-root or store-id: parties among whose members, with those of its own party, this node keeps some of its neighbours, by the graph among those alone (docs/store.md, Members): so that a party listing many nodes can't be all of them.", + ), option( "strict-keys", Kind::List, @@ -681,6 +689,9 @@ pub(crate) struct Settings { pub(crate) store_checkpoint: Option, #[cfg(feature = "federation")] pub(crate) store_party: Option, + #[cfg(feature = "federation")] + #[serde(default)] + pub(crate) store_neighbour_parties: Vec, #[serde(default)] pub(crate) strict_keys: Vec, @@ -1156,6 +1167,10 @@ impl Settings { ("store-file", self.store_file.is_some()), ("store-checkpoint", self.store_checkpoint.is_some()), ("store-party", self.store_party.is_some()), + ( + "store-neighbour-parties", + !self.store_neighbour_parties.is_empty(), + ), ]; let set: Vec<&str> = of_a_store .iter() @@ -1181,6 +1196,13 @@ impl Settings { ), Some(_) => {} } + if let Some(party) = self + .store_neighbour_parties + .iter() + .find(|party| !crate::federation::version::is_party(party)) + { + bail!("store-neighbour-parties: {party:?} isn't a party's name"); + } let first_change = [ ("genesis", self.genesis), ("bootstrap-users", !self.bootstrap_users.is_empty()), @@ -1255,6 +1277,11 @@ impl Settings { ("store-checkpoint", self.store_checkpoint.is_some()), #[cfg(feature = "federation")] ("store-party", self.store_party.is_some()), + #[cfg(feature = "federation")] + ( + "store-neighbour-parties", + !self.store_neighbour_parties.is_empty(), + ), ("alias", self.alias.is_some()), ("dashboard-url", self.dashboard_url.is_some()), ("debug-api", self.debug_api), @@ -2350,6 +2377,19 @@ mod tests { assert!(checked(json!({ "store-id": "ab", "store-party": "tv" })).is_err()); assert!(checked(json!({ "store-party": "tv" })).is_err()); assert!(checked(json!({ "store-file": "store.json" })).is_err()); + assert!( + checked( + json!({ "store-id": id, "store-party": "tv", "store-neighbour-parties": ["lass"] }) + ) + .is_ok() + ); + assert!( + checked( + json!({ "store-id": id, "store-party": "tv", "store-neighbour-parties": ["l s"] }) + ) + .is_err() + ); + assert!(checked(json!({ "store-neighbour-parties": ["lass"] })).is_err()); assert!( checked(json!({ "store-id": id, "store-root": "root.json", "store-party": "tv" })) .is_err() diff --git a/src/federation/held.rs b/src/federation/held.rs index fe8b6a9..542aeed 100644 --- a/src/federation/held.rs +++ b/src/federation/held.rs @@ -84,6 +84,9 @@ pub(crate) struct Holding { file: Option<(PathBuf, Arc)>, pin: Option, party: Option, + /// The parties among whose members, with those of its own, the node keeps some of its + /// neighbours (`--store-neighbour-parties`). + near: Vec, /// The members the store names, each with its party, as it reads now: apart from the /// store, so that whoever asks doesn't wait while the store takes events. members: RwLock>>, @@ -151,6 +154,7 @@ impl Holding { file: Some((path, files)), pin, party, + near: Vec::new(), members: RwLock::default(), inner: Mutex::new(Inner { kept, @@ -352,6 +356,25 @@ impl Holding { self.party.as_deref() } + /// Itself, the node keeping some of its neighbours among the members of `parties`, + /// with those of its own (`--store-neighbour-parties`). + pub(crate) fn near(self, parties: Vec) -> Self { + Holding { + near: parties, + ..self + } + } + + /// The parties among whose members, with those of its own, the node keeps some of its + /// neighbours: its own first. + pub(crate) fn nearby(&self) -> Vec<&str> { + self.party + .iter() + .chain(&self.near) + .map(String::as_str) + .collect() + } + /// `f` of the store, where the node holds one. pub(crate) fn with(&self, f: impl FnOnce(&Store) -> T) -> Option { self.inner.lock_or_recover().store.as_ref().map(f) diff --git a/src/main.rs b/src/main.rs index 91b1bc8..40ae93a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -319,7 +319,8 @@ async fn main() -> Result<()> { .as_deref() .and_then(federation::store::Id::from_hex), args.store_party.clone(), - )?, + )? + .near(args.store_neighbour_parties.clone()), strict_keys: args .strict_keys .iter() 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