aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/held.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/federation/held.rs')
-rw-r--r--src/federation/held.rs32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/federation/held.rs b/src/federation/held.rs
index 8f48c65..f8825e5 100644
--- a/src/federation/held.rs
+++ b/src/federation/held.rs
@@ -77,12 +77,13 @@ impl Kept {
}
}
-/// The store a node holds, if its swarm holds one, the file it keeps its own in, and the
-/// checkpoint its operator pins.
+/// The store a node holds, if its swarm holds one, the file it keeps its own in, the
+/// checkpoint its operator pins, and the party its operator says it is of.
#[derive(Default)]
pub(crate) struct Holding {
file: Option<(PathBuf, Arc<Files>)>,
pin: Option<Id>,
+ party: Option<String>,
// A std mutex: never held while waiting for the document.
inner: Mutex<Inner>,
}
@@ -115,11 +116,18 @@ pub(crate) struct Unread {
impl Holding {
/// Keeping the node's own in the file at `path`, if any, which holds what it kept
/// before: a missing file nothing. One that doesn't read is an error: the node would
- /// take what it refused. Its store starts from the checkpoint `pin`, if any.
- pub(crate) fn open(path: Option<PathBuf>, files: Arc<Files>, pin: Option<Id>) -> Result<Self> {
+ /// take what it refused. Its store starts from the checkpoint `pin`, if any; the node
+ /// is of `party`.
+ pub(crate) fn open(
+ path: Option<PathBuf>,
+ files: Arc<Files>,
+ pin: Option<Id>,
+ party: Option<String>,
+ ) -> Result<Self> {
let Some(path) = path else {
return Ok(Holding {
pin,
+ party,
..Holding::default()
});
};
@@ -139,6 +147,7 @@ impl Holding {
Ok(Holding {
file: Some((path, files)),
pin,
+ party,
inner: Mutex::new(Inner {
kept,
..Inner::default()
@@ -307,6 +316,11 @@ impl Holding {
.unwrap_or_default()
}
+ /// The party its operator says the node is of (`--store-party`).
+ pub(crate) fn party(&self) -> Option<&str> {
+ self.party.as_deref()
+ }
+
/// `f` of the store, where the node holds one.
pub(crate) fn with<T>(&self, f: impl FnOnce(&Store<Federation>) -> T) -> Option<T> {
self.inner.lock_or_recover().store.as_ref().map(f)
@@ -521,7 +535,7 @@ mod tests {
assert_ne!(pin, Id::of(&root));
let files = Arc::new(Files::default());
- let pinned = Holding::open(None, Arc::clone(&files), Some(pin)).unwrap();
+ let pinned = Holding::open(None, Arc::clone(&files), Some(pin), None).unwrap();
read(&pinned, &doc, 0);
assert_eq!(pinned.with(|store| Id::of(store.checkpoint())), Some(pin));
let taken = |holding: &Holding| {
@@ -534,7 +548,7 @@ mod tests {
pinned.with(|store| store.holds(&Id::of(&beside))),
Some(false)
);
- let elsewhere = Holding::open(None, files, Some(Id::of(b"elsewhere"))).unwrap();
+ let elsewhere = Holding::open(None, files, Some(Id::of(b"elsewhere")), None).unwrap();
read(&elsewhere, &doc, 0);
assert!(elsewhere.with(|_| ()).is_none());
}
@@ -638,7 +652,7 @@ mod tests {
let dir = crate::files::scratch_dir("held");
let path = dir.join("store.json");
let files = Arc::new(Files::default());
- let holding = Holding::open(Some(path.clone()), Arc::clone(&files), None).unwrap();
+ let holding = Holding::open(Some(path.clone()), Arc::clone(&files), None, None).unwrap();
let mut doc = events::started(Federation::NAME, &root).unwrap();
for event in before.iter().copied().chain([&first_taken]) {
put(&mut doc, event);
@@ -650,12 +664,12 @@ mod tests {
assert!(!taken(&holding).contains(&Id::of(&later)));
// Restarted: the store read anew, all at once, refuses the later as before.
- let anew = Holding::open(Some(path.clone()), Arc::clone(&files), None).unwrap();
+ let anew = Holding::open(Some(path.clone()), Arc::clone(&files), None, None).unwrap();
read(&anew, &all, 0);
assert!(taken(&anew).contains(&Id::of(&first_taken)));
assert!(!taken(&anew).contains(&Id::of(&later)));
std::fs::write(&path, b"{\"refused\": [\"not an ID\"]}").unwrap();
- assert!(Holding::open(Some(path), files, None).is_err());
+ assert!(Holding::open(Some(path), files, None, None).is_err());
}
}