aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/bootstrap.rs
diff options
context:
space:
mode:
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