aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-01 02:45:46 +0100
committertv <tv@krebsco.de>2026-12-01 02:45:46 +0100
commit34bfcb661ed74bf40809576bbb388362cb7ffaa1 (patch)
tree8422db7db396dd4ae83403837cd954a94f882a7a /src/lib.rs
parent34434f7fd5a6bab1884a63c96679f48045f4bffd (diff)
parent6a06bc4a955cdf2b5a183c9ff21e25c79a4e5d9f (diff)
Merge remote-tracking branch 'events'HEADmaster
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs48
1 files changed, 43 insertions, 5 deletions
diff --git a/src/lib.rs b/src/lib.rs
index da106b9..a420555 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -81,16 +81,16 @@ fn voter(args: &config::Settings) -> Result<Option<federation::held::Voter>> {
pub async fn run() -> Result<()> {
logging::init();
- let config = config::load()?;
- if let Some((file, create)) = &config.node_id {
+ if let Some((file, create)) = config::asked_node_id() {
let new = !file.exists();
- let key = identity::NodeKey::load(file, *create)?;
+ let key = identity::NodeKey::load(&file, create)?;
if new {
eprintln!("a new node key in {}: a new node", file.display());
}
println!("{}", key.id());
return Ok(());
}
+ let config = config::load()?;
if config.print_only {
println!(
"{}",
@@ -221,11 +221,37 @@ pub async fn run() -> Result<()> {
#[cfg(feature = "federation")]
let store =
bootstrap::StoreStart::of(args.store_root.as_deref(), args.store_id.as_deref(), &files)?;
+ // Its store's own document, a set of events (`--store-document`): from its file,
+ // or from the root.
+ #[cfg(feature = "federation")]
+ let set = match (&store, &args.store_document) {
+ (Some(store), Some(path)) => store.set(
+ path,
+ &files,
+ args.store_checkpoint
+ .as_deref()
+ .and_then(federation::store::Id::from_hex),
+ args.store_keeps_forgotten,
+ args.store_both,
+ )?,
+ _ => None,
+ };
#[cfg(feature = "federation")]
let starting = match &store {
- Some(store) => {
+ Some(store) if set.is_none() || args.store_both => {
store.starting(starting, remembered.as_ref().map(|r| r.swarm_id.as_str()))?
}
+ // A set is the store's document: the one a swarm syncs otherwise stays empty.
+ Some(store) => {
+ let swarm_id = store.swarm_id();
+ if let Some(remembered) = remembered.as_ref().filter(|r| r.swarm_id != swarm_id) {
+ anyhow::bail!(
+ "The state file remembers swarm {}, not the store's ({swarm_id}): give the store's state file, or another",
+ remembered.swarm_id
+ );
+ }
+ None
+ }
None => starting,
};
let (
@@ -372,7 +398,9 @@ pub async fn run() -> Result<()> {
args.store_party.clone(),
)?
.near(args.store_neighbour_parties.clone())
- .voting(voter(args)?),
+ .voting(voter(args)?)
+ .of_both_if(args.store_both, args.store_keeps_forgotten)
+ .carrying_if(set, args.store_document.clone(), Arc::clone(&files)),
strict_keys: args
.strict_keys
.iter()
@@ -394,7 +422,13 @@ pub async fn run() -> Result<()> {
// Join the remembered swarm and no other; HELLOs claim it. A document to start on
// names its swarm itself (checked against the remembered one above).
+ #[cfg(feature = "federation")]
+ let of_a_set = state.of_a_set();
+ #[cfg(not(feature = "federation"))]
+ let of_a_set = false;
let start = match starting_swarm {
+ // A set of events is what the node starts on: its store's swarm (`bootstrap`).
+ _ if of_a_set => bootstrap::Start::FromDocument(bootstrap::Origin::Root),
Some((swarm_id, origin)) => {
state.set_expected_swarm_id(swarm_id).await?;
bootstrap::Start::FromDocument(origin)
@@ -486,6 +520,10 @@ pub async fn run() -> Result<()> {
swarm::state_file::update(&state, true).await;
swarm::document_file::flush(&state).await;
swarm::document_file::close(&state).await;
+ #[cfg(feature = "federation")]
+ if let Err(error) = state.holding.save() {
+ tracing::error!(error = %error, "Couldn't write the store's document as the node stops");
+ }
Ok(())
}