aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-17 00:25:41 +0000
committertv <tv@krebsco.de>2026-11-17 01:47:45 +0100
commit438d4f06103ba7ae17a80f48aa589219c7d8dd61 (patch)
tree0191dceb5fa2025276e3d67429375712f8869745 /src/swarm
parent3a5bf56e644e7334536a7d3dae742a940182f856 (diff)
federation: a fork's root made, and checked by a node holding its history
`federation::fork`: a node holding a federation's history makes the root of a fork at heads it holds by a version, with the events the root keeps, as the file the fork's founders start its swarm from (`make`, `root_file`, which `--store-root` reads); and checks a fork's root it is given (`check`): whether it builds that root at its heads, byte for byte, what it holds that those heads lack, and, party by party, the keys the fork's version gives where they aren't those the party had there. The attack rows 35 and 36 have their tests.
Diffstat (limited to 'src/swarm')
-rw-r--r--src/swarm/bootstrap.rs17
1 files changed, 3 insertions, 14 deletions
diff --git a/src/swarm/bootstrap.rs b/src/swarm/bootstrap.rs
index 594db8f..b280b38 100644
--- a/src/swarm/bootstrap.rs
+++ b/src/swarm/bootstrap.rs
@@ -280,7 +280,7 @@ impl StoreStart {
/// The store `root` or `id` names, if either does: a root the federation takes as one,
/// with the events it keeps, which a store's root must be. The file `root` holds the
/// root on its first line, and, for a fork, the events it keeps, each on a line of its
- /// own: JCS, which writes no line break.
+ /// own (`federation::fork::root_file`).
pub(crate) fn of(root: Option<&Path>, id: Option<&str>, files: &Files) -> Result<Option<Self>> {
use crate::federation::fold::Federation;
use crate::federation::store::{Id, memory::Store};
@@ -293,12 +293,7 @@ impl StoreStart {
.read(FileKind::Store, path)
.with_context(|| format!("Reading the store's root {}", path.display()))?
.with_context(|| format!("The store's root {} doesn't exist", path.display()))?;
- let mut lines = file
- .split(|byte| *byte == b'\n')
- .filter(|line| !line.is_empty())
- .map(<[u8]>::to_vec);
- let root = lines.next().unwrap_or_default();
- let kept: Vec<Vec<u8>> = lines.collect();
+ let (root, kept) = crate::federation::fork::read_root_file(&file);
if let Err(refused) = Store::<Federation>::new(root.clone(), kept.clone()) {
bail!("The store's root {} is none: {}", path.display(), refused.0);
}
@@ -619,13 +614,7 @@ mod tests {
let dir = crate::files::scratch_dir("fork-root");
let (path, alone) = (dir.join("fork"), dir.join("alone"));
let files = Files::default();
- let mut file = root.clone();
- for event in &kept {
- file.push(b'\n');
- file.extend_from_slice(event);
- }
- file.push(b'\n');
- std::fs::write(&path, file).unwrap();
+ std::fs::write(&path, crate::federation::fork::root_file(&root, &kept)).unwrap();
std::fs::write(&alone, &root).unwrap();
let fork = StoreStart::of(Some(&path), None, &files).unwrap().unwrap();
assert_eq!(fork.id, Id::of(&root));