ouisync/protocol/
root_node.rs

1use super::{Proof, Summary};
2use crate::{
3    crypto::sign::PublicKey,
4    version_vector::VersionVector,
5    versioned::{BranchItem, Versioned},
6};
7
8pub(crate) type SnapshotId = u32;
9
10#[derive(Clone, Eq, PartialEq, Debug)]
11pub struct RootNode {
12    pub snapshot_id: SnapshotId,
13    pub proof: Proof,
14    pub summary: Summary,
15}
16
17impl Versioned for RootNode {
18    fn version_vector(&self) -> &VersionVector {
19        &self.proof.version_vector
20    }
21}
22
23impl BranchItem for RootNode {
24    fn branch_id(&self) -> &PublicKey {
25        &self.proof.writer_id
26    }
27}
28
29/// Kind of root node.
30#[derive(Eq, PartialEq, Debug)]
31pub(crate) enum RootNodeKind {
32    /// Published nodes have their version vector strictly greater than any previous node
33    /// in the same branch. Only published nodes are announced to other replicas.
34    Published,
35    /// Draft nodes have their version vector equal to that of the previous node in the same
36    /// branch. Draft nodes are neither announced to nor accepted from other replicas.
37    Draft,
38}
39
40/// What kind of nodes to load and/or create.
41pub(crate) enum RootNodeFilter {
42    /// Only published nodes.
43    Published,
44    /// Published and draft nodes.
45    Any,
46}