summaryrefslogtreecommitdiffstats
path: root/src/document/meta.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/document/meta.rs')
-rw-r--r--src/document/meta.rs45
1 files changed, 45 insertions, 0 deletions
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/<pk>`: the member registry (`swarm::members`).
+//! * `forgotten/<pk>`: forget records (`swarm::peer`).
+//! * `remakes/<id>`: remake records (`remake::records`).
+//! * `votes/<pk>`: the votes register (`remake::records`).
+//! * `epochs/<generation>`: 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/<parts…>`.
+pub(crate) fn path(parts: &[&str]) -> Vec<String> {
+ 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(&[]));
+ }
+}