blob: 24ed7c749b3cb8838539151587d24575d3e32de6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
//! 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`).
//! * `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/<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(&[]));
}
}
|