//! 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`). //! * `relays`: relays for the swarm's nodes, listed by an operator //! (`swarm::members::relays`). /// 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"; pub(crate) const RELAYS: &str = "relays"; /// 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(&[])); } }