aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/bootstrap.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-30 17:57:55 +0000
committertv <tv@krebsco.de>2026-11-30 17:57:55 +0000
commit08ec65219991c7413c8cdef4ce77434f2a121331 (patch)
tree2c9d6f07e435a1ae37c62571579b170374cfbb70 /src/swarm/bootstrap.rs
parent00e88cd983766abec32b5a14a8cbf20932a27f3c (diff)
A node of both kinds, for a swarm to move to sets by (--store-both)
With store-document, store-both has the node hold its store in the Automerge document too, and sync with nodes of either kind: * it says to each peer the kind that peer holds, and passes its set on to those that hold sets (swarm::set::holds_a_set), the Automerge document to the others; * what its set takes of the document goes on to the peers on sets (Holding::unpassed), and what its set takes of them is put into the document, as events it lacks are (Holding::lacking); * its entry in the document is put as its entry in the set (swarm::set::mirror_entry), and it reads the members of both; * without the set's file yet, its set is made of the store as it reads it of its document, with what store-file kept of its own. A simulation: two nodes on the Automerge document, one on a set, one of both between them; an event put on either side reaches all four.
Diffstat (limited to 'src/swarm/bootstrap.rs')
-rw-r--r--src/swarm/bootstrap.rs35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/swarm/bootstrap.rs b/src/swarm/bootstrap.rs
index b21b579..45c86e6 100644
--- a/src/swarm/bootstrap.rs
+++ b/src/swarm/bootstrap.rs
@@ -344,14 +344,16 @@ impl StoreStart {
/// at `path`: as the file has it, where there is one, which must be this store's;
/// else begun from the root, where the node is given it and pins no checkpoint; else
/// to be gathered of its peers, from the checkpoint `pin` names, or the root, by its
- /// name. What a checkpoint forgot is kept for `keeps`.
+ /// name; of `both` kinds, none without a file. What a checkpoint forgot is kept for
+ /// `keeps`.
pub(crate) fn set(
&self,
path: &Path,
files: &Files,
pin: Option<crate::federation::store::Id>,
keeps: std::time::Duration,
- ) -> Result<crate::federation::held::Begun> {
+ both: bool,
+ ) -> Result<Option<crate::federation::held::Begun>> {
use crate::federation::fold::Federation;
use crate::federation::held::Begun;
use crate::federation::store::{memory::Store, passing::Start, set::Set};
@@ -376,7 +378,12 @@ impl StoreStart {
);
}
info!(swarm_id = %self.id, path = %path.display(), "Going on with the store's document");
- return Ok(Begun::Set(Box::new(set)));
+ return Ok(Some(Begun::Set(Box::new(set))));
+ }
+ // A node of both kinds makes its set of the store as it reads it of its
+ // document (`Holding::of_both`).
+ if both {
+ return Ok(None);
}
match (&self.root, pin) {
(Some((root, kept)), None) => {
@@ -385,12 +392,12 @@ impl StoreStart {
anyhow::anyhow!("The store's root is none: {}", refused.0)
})?;
info!(swarm_id = %self.id, "Starting the swarm holding the store from its root, as a set of events (--store-document)");
- Ok(Begun::Set(Box::new(Set::new(store, keeps))))
+ Ok(Some(Begun::Set(Box::new(Set::new(store, keeps)))))
}
(_, pin) => {
let at = pin.unwrap_or(self.id);
info!(swarm_id = %self.id, from = %at, "Joining the swarm holding the store with nothing of it: its set begins from what members give by that name");
- Ok(Begun::Start(Start::new(self.id, at, keeps)))
+ Ok(Some(Begun::Start(Start::new(self.id, at, keeps))))
}
}
}
@@ -753,9 +760,9 @@ mod tests {
let files = Files::default();
let keeps = Duration::from_secs(60);
use crate::federation::held::Begun;
- let set_of = |start: &StoreStart, pin| match start.set(&path, &files, pin, keeps) {
- Ok(Begun::Set(set)) => Some(*set),
- Ok(Begun::Start(_)) => None,
+ let set_of = |start: &StoreStart, pin| match start.set(&path, &files, pin, keeps, false) {
+ Ok(Some(Begun::Set(set))) => Some(*set),
+ Ok(Some(Begun::Start(_)) | None) => None,
Err(error) => panic!("{error:#}"),
};
// No file: from the root, where given and no checkpoint is pinned; else to be
@@ -780,9 +787,17 @@ mod tests {
id: Id::of(&other_root),
root: Some((other_root, Vec::new())),
};
- assert!(other.set(&path, &files, None, keeps).is_err());
+ assert!(other.set(&path, &files, None, keeps, false).is_err());
std::fs::write(&path, b"something else").unwrap();
- assert!(store.set(&path, &files, None, keeps).is_err());
+ assert!(store.set(&path, &files, None, keeps, false).is_err());
+ // A node of both kinds: the file, where there is one; else none here.
+ std::fs::remove_file(&path).unwrap();
+ assert!(
+ store
+ .set(&path, &files, None, keeps, true)
+ .unwrap()
+ .is_none()
+ );
}
/// A fork's root, and the event it keeps on a line of its own: the swarm starts from