diff options
Diffstat (limited to 'src/swarm')
| -rw-r--r-- | src/swarm/state_file.rs | 12 | ||||
| -rw-r--r-- | src/swarm/topology.rs | 14 |
2 files changed, 24 insertions, 2 deletions
diff --git a/src/swarm/state_file.rs b/src/swarm/state_file.rs index 3693d89..a65fa5b 100644 --- a/src/swarm/state_file.rs +++ b/src/swarm/state_file.rs @@ -1,5 +1,6 @@ //! The state file (`--state-file`): what a node remembers across restarts, so it -//! rejoins its swarm on its own: the swarm ID and some members to reach it through. +//! rejoins its swarm on its own: the swarm ID and some members to reach it through; and +//! the members' aliases, for the logs from the start (`logging`). //! Not the document: a restarted node still starts empty and syncs. //! //! Written rarely: once the node is ready, then when the remembered members change @@ -35,6 +36,9 @@ pub(crate) struct Remembered { /// them (`swarm::members::addresses`). #[serde(default)] pub(crate) seeds: Vec<String>, + /// Members' aliases, by the names that stand for them (`logging::aliases`). + #[serde(default)] + pub(crate) aliases: std::collections::BTreeMap<String, String>, } pub(crate) struct StateFile { @@ -136,7 +140,11 @@ pub(crate) async fn update(state: &AppState, now: bool) { state.clock.now_millis().as_u64(), ) }; - let remembered = Remembered { swarm_id, seeds }; + let remembered = Remembered { + swarm_id, + seeds, + aliases: crate::logging::aliases(), + }; { let inner = file.lock(); diff --git a/src/swarm/topology.rs b/src/swarm/topology.rs index c9d1266..2ba07b7 100644 --- a/src/swarm/topology.rs +++ b/src/swarm/topology.rs @@ -137,6 +137,19 @@ pub(crate) fn affects_neighbours(path: &[String]) -> bool { path.is_empty() || path.starts_with(&members::members_dir()) } +/// Hands the members' `aliases` to the logger, under every name that stands for each: +/// its node ID, and its addresses (`logging`, which renames them bare too). +fn set_aliases(state: &AppState, aliases: std::collections::HashMap<String, String>) { + let mut names = std::collections::HashMap::new(); + for (member, alias) in aliases { + for address in state.transport.identities_of(&member) { + names.insert(address, alias.clone()); + } + names.insert(member, alias); + } + crate::logging::set_aliases(names); +} + /// Recomputes the neighbours once ready, if the member list, the reachable members or /// `k` changed. pub(crate) async fn refresh(state: &AppState) -> Option<NeighbourChange> { @@ -146,6 +159,7 @@ pub(crate) async fn refresh(state: &AppState) -> Option<NeighbourChange> { let (current, stable, transports, alive) = { let replica = state.doc.read().await; members::learn_addresses(state, &replica.doc); + set_aliases(state, members::aliases(&replica.doc)); let current = members::members(&replica.doc); // Those that said they are alive within the electorate window. let alive: BTreeSet<String> = members::electorate( |
