From 5272813c3f8cba8d403f5a7571e0c7ddd252b198 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 16 Nov 2026 20:40:22 +0000 Subject: members: a node's entry names its party In a swarm holding a store, a node's own entry names the party it is of (`docs/store.md`, Members): `party`, as `--store-party` says, written at registration and kept so when it changes over a restart, as the alias is; `members::party` reads it. Behind the `federation` feature. --- src/swarm/members.rs | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/swarm/members.rs b/src/swarm/members.rs index 0cadb00..de33185 100644 --- a/src/swarm/members.rs +++ b/src/swarm/members.rs @@ -15,7 +15,8 @@ //! hints for the others' transports), an `alive` stamp the node renews now and //! then: the members renewed within `--electorate-window` are the electorate of a //! remake, and where its links differ from the member list's graph (`links`, -//! `swarm::working_links`). +//! `swarm::working_links`). In a swarm holding a store, it names the party the node is of +//! (`--store-party`, `party`), behind the `federation` feature. use std::collections::{BTreeSet, HashMap}; use std::time::Duration; @@ -93,6 +94,22 @@ fn alias_path(pk: &str) -> Vec { path } +#[cfg(feature = "federation")] +fn party_path(pk: &str) -> Vec { + let mut path = member_path(pk); + path.push("party".to_owned()); + path +} + +/// The party `pk`'s entry names, in a swarm holding a store. +#[cfg(feature = "federation")] +pub(crate) fn party(doc: &impl ReadDoc, pk: &str) -> Option { + match store::read_path(doc, &party_path(pk)) { + Ok(Some(JsonValue::String(party))) => Some(party), + _ => None, + } +} + /// `pk`'s alias, if it gave itself one. pub(crate) fn alias(doc: &Document, pk: &str) -> Option { match store::read_path(doc, &alias_path(pk)) { @@ -318,6 +335,10 @@ pub(crate) fn entry(state: &AppState) -> JsonValue { if let Some(url) = &state.dashboard_url { entry["dashboard"] = json!(url); } + #[cfg(feature = "federation")] + if let Some(party) = state.holding.party() { + entry["party"] = json!(party); + } entry } @@ -426,6 +447,26 @@ pub(crate) async fn ensure_registered(state: &AppState) { } } + // The party it is of, as configured. + #[cfg(feature = "federation")] + if let Some(ours) = state.holding.party() { + let recorded = party(&state.doc.read().await.doc, &local); + if recorded.as_deref() != Some(ours) { + let (path, value) = (party_path(&local), json!(ours)); + match state + .mutate_doc(move |doc| store::write_path(doc, &path, &value)) + .await + { + Ok(()) => info!( + party = ours, + previous = recorded.as_deref(), + "Party updated in the member list" + ), + Err(error) => warn!(error = %error, "Failed to record our party"), + } + } + } + if recorded_alias == wanted { return; } -- cgit v1.3.1