diff options
| author | tv <tv@krebsco.de> | 2026-11-16 20:40:22 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-16 22:03:11 +0100 |
| commit | 5272813c3f8cba8d403f5a7571e0c7ddd252b198 (patch) | |
| tree | 0fde348871d8aa23a79ed0ee5946b3dfe0e2d946 | |
| parent | 66d4e00eef10f224e999474bfed28685017ddde6 (diff) | |
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.
| -rw-r--r-- | src/swarm/members.rs | 43 |
1 files changed, 42 insertions, 1 deletions
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<String> { path } +#[cfg(feature = "federation")] +fn party_path(pk: &str) -> Vec<String> { + 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<String> { + 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<String> { 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; } |
