Skip to main content

gent_protocol/
web_failover.rs

1//! Native carrier admission and checkpoint transport for hosted web nodes.
2//! Checkpoints contain web state only. They never contain native node keys.
3use crate::configuration_log::Head;
4use serde::{Deserialize, Serialize};
5
6pub const VERSION: u8 = 1;
7pub const LEASE_SECONDS: u64 = 30;
8pub const CHUNK_BYTES: usize = 64 * 1024;
9pub const MAX_CHUNKS: usize = 1024;
10pub const MAX_BATCH: usize = 8;
11pub const MAX_CONTROL_BYTES: usize = CHUNK_BYTES * MAX_BATCH * 4 / 3 + 8192;
12
13#[derive(Clone, Serialize, Deserialize)]
14#[serde(deny_unknown_fields)]
15pub struct Admission {
16    pub version: u8,
17    pub cluster: String,
18    pub node: String,
19    pub web: String,
20    pub head: Head,
21    pub expires_at: u64,
22    pub body_hash: [u8; 32],
23    pub signature: Vec<u8>,
24}
25
26#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
27#[serde(deny_unknown_fields)]
28pub struct Checkpoint {
29    pub generation: u64,
30    pub chunks: usize,
31    pub bytes: usize,
32    pub sha256: String,
33}
34
35impl Checkpoint {
36    pub fn valid(&self) -> bool {
37        self.generation > 0
38            && self.generation < (1 << 53)
39            && (1..=MAX_CHUNKS).contains(&self.chunks)
40            && self.bytes > 0
41            && self.bytes.div_ceil(CHUNK_BYTES) == self.chunks
42            && self.sha256.len() == 64
43            && self
44                .sha256
45                .bytes()
46                .all(|b| b.is_ascii_digit() || (b'a'..=b'f').contains(&b))
47    }
48}
49
50#[derive(Serialize, Deserialize)]
51#[serde(tag = "op", rename_all = "snake_case", deny_unknown_fields)]
52pub enum Control {
53    Inspect,
54    /// Revoke a named connector under current cluster configuration authority.
55    RevokeConnector,
56    Acquire {
57        create: bool,
58    },
59    Renew {
60        epoch: u64,
61    },
62    Read {
63        generation: u64,
64        start: usize,
65    },
66    Stage {
67        epoch: u64,
68        generation: u64,
69        start: usize,
70        chunks: Vec<String>,
71    },
72    Commit {
73        epoch: u64,
74        checkpoint: Checkpoint,
75    },
76    /// Publish a complete small checkpoint in one atomic storage operation.
77    Publish {
78        epoch: u64,
79        checkpoint: Checkpoint,
80        chunks: Vec<String>,
81    },
82    Release {
83        epoch: u64,
84    },
85    Disable {
86        epoch: u64,
87    },
88}
89
90#[derive(Clone, Serialize, Deserialize)]
91#[serde(deny_unknown_fields)]
92pub struct Lease {
93    pub owner: String,
94    pub epoch: u64,
95    pub expires_at: u64,
96    pub checkpoint: Option<Checkpoint>,
97    #[serde(default)]
98    pub revoked: bool,
99}