Skip to main content

gent_daemon/messages/
directory.rs

1//! Version 3 directory reconciliation. A carrier describes only its own chats
2//! and the logical nodes explicitly hosted by it in signed cluster state.
3use super::Registration;
4use serde::{Deserialize, Serialize};
5use uuid::Uuid;
6
7pub const LEAF_LIMIT: usize = 16;
8pub const MAX_CHATS: usize = 16_384;
9pub const MAX_DEPTH: usize = 64;
10pub const MAX_FRONTIER: usize = 128;
11pub const PUSH_LIMIT: usize = 32;
12
13/// One replica's complete view, not an origin's claim of completeness.
14/// Sequence numbers are local to the authenticated sender; roots decide equality.
15#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
16#[serde(deny_unknown_fields)]
17pub struct Snapshot {
18    #[serde(default, skip_serializing_if = "Option::is_none")]
19    pub incarnation: Option<Uuid>,
20    pub sequence: u64,
21    pub root: Summary,
22    pub frontier: Vec<Branch>,
23}
24
25#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
26#[serde(deny_unknown_fields)]
27pub struct Branch {
28    pub prefix: String,
29    pub summary: Summary,
30}
31
32#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
33#[serde(deny_unknown_fields)]
34pub struct Summary {
35    pub hash: [u8; 32],
36    pub count: usize,
37}
38
39#[derive(Serialize, Deserialize)]
40#[serde(tag = "step", rename_all = "snake_case", deny_unknown_fields)]
41pub enum Envelope {
42    /// V4 replicas proactively send differing records. Empty pages advertise
43    /// our view when only the other replica has records to contribute.
44    Push { chats: Vec<Registration> },
45    Probe {
46        round: Uuid,
47        prefix: String,
48        root: Option<Summary>,
49        summary: Summary,
50    },
51    Reply {
52        round: Uuid,
53        prefix: String,
54        root: Summary,
55        result: Reply,
56    },
57}
58
59#[derive(Serialize, Deserialize)]
60#[serde(tag = "kind", rename_all = "snake_case", deny_unknown_fields)]
61pub enum Reply {
62    Equal,
63    Changed,
64    Branch { children: Box<[Summary; 16]> },
65    Leaves { chats: Vec<Registration> },
66}