From d668ce2ff8f308e54c1c7a2c145cb3479cab899d Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 26 Oct 2026 04:13:11 +0100 Subject: move protocol paths to dedicated module --- src/document/meta.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/document/meta.rs (limited to 'src/document/meta.rs') diff --git a/src/document/meta.rs b/src/document/meta.rs new file mode 100644 index 0000000..482b421 --- /dev/null +++ b/src/document/meta.rs @@ -0,0 +1,45 @@ +//! The protocol's own data in the document: everything under `_continuum`. The names +//! of its parts, and the paths to them, are defined here only. +//! +//! * `members/`: the member registry (`swarm::members`). +//! * `forgotten/`: forget records (`swarm::peer`). +//! * `remakes/`: remake records (`remake::records`). +//! * `votes/`: the votes register (`remake::records`). +//! * `epochs/`: epoch metadata, written by snapshots (`remake::snapshot`). +//! * `swarm`: the swarm ID, written once by the genesis node (`swarm::bootstrap`). + +/// The key every protocol path starts with. +pub(crate) const ROOT: &str = "_continuum"; +pub(crate) const MEMBERS: &str = "members"; +pub(crate) const FORGOTTEN: &str = "forgotten"; +pub(crate) const REMAKES: &str = "remakes"; +pub(crate) const VOTES: &str = "votes"; +pub(crate) const EPOCHS: &str = "epochs"; +pub(crate) const SWARM: &str = "swarm"; + +/// The store path `_continuum/`. +pub(crate) fn path(parts: &[&str]) -> Vec { + std::iter::once(ROOT) + .chain(parts.iter().copied()) + .map(str::to_owned) + .collect() +} + +/// Whether a store path is protocol data (under `_continuum`). +pub(crate) fn is_protocol(path: &[String]) -> bool { + path.first().is_some_and(|root| root == ROOT) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn paths_start_at_the_root() { + assert_eq!(path(&[]), vec!["_continuum"]); + assert_eq!(path(&[MEMBERS, "pk"]), vec!["_continuum", "members", "pk"]); + assert!(is_protocol(&path(&[VOTES]))); + assert!(!is_protocol(&["users".to_owned()])); + assert!(!is_protocol(&[])); + } +} -- cgit v1.3.1