aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/lib.rs b/src/lib.rs
index da106b9..8b56399 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -221,11 +221,29 @@ 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)) => Some(store.set(path, &files, args.store_keeps_forgotten)?),
+ _ => None,
+ };
#[cfg(feature = "federation")]
let starting = match &store {
- Some(store) => {
+ Some(store) if set.is_none() => {
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 +390,8 @@ pub async fn run() -> Result<()> {
args.store_party.clone(),
)?
.near(args.store_neighbour_parties.clone())
- .voting(voter(args)?),
+ .voting(voter(args)?)
+ .carrying_if(set, args.store_document.clone(), Arc::clone(&files)),
strict_keys: args
.strict_keys
.iter()
@@ -394,7 +413,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 +511,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(())
}