nodedb_types/sync/wire/resync.rs
1//! Re-sync request and throttle messages.
2
3use serde::{Deserialize, Serialize};
4
5/// Re-sync request message (bidirectional, 0x50).
6///
7/// Sent when a receiver detects:
8/// - Sequence gap: missing `mutation_id`s in the delta stream
9/// - Checksum failure: CRC32C mismatch on a delta payload
10/// - State divergence: local state inconsistent with received deltas
11///
12/// On receiving a ResyncRequest, the sender should:
13/// 1. Re-send all deltas from `from_mutation_id` onwards, OR
14/// 2. Send a full snapshot if `from_mutation_id` is 0
15#[derive(
16 Debug, Clone, Serialize, Deserialize, zerompk::ToMessagePack, zerompk::FromMessagePack,
17)]
18pub struct ResyncRequestMsg {
19 /// Reason for requesting re-sync.
20 pub reason: ResyncReason,
21 /// Resume from this mutation ID (0 = full re-sync).
22 pub from_mutation_id: u64,
23 /// Collection scope (empty = all collections).
24 pub collection: String,
25}
26
27/// Reason for a re-sync request.
28#[derive(
29 Debug, Clone, Serialize, Deserialize, zerompk::ToMessagePack, zerompk::FromMessagePack,
30)]
31pub enum ResyncReason {
32 /// Detected missing mutation IDs in the delta stream.
33 SequenceGap {
34 /// The expected next mutation ID.
35 expected: u64,
36 /// The mutation ID that was actually received.
37 received: u64,
38 },
39 /// CRC32C checksum mismatch on a delta payload.
40 ChecksumMismatch {
41 /// The mutation ID of the corrupted delta.
42 mutation_id: u64,
43 },
44 /// Corruption detected on cold start, need full re-sync.
45 CorruptedState,
46}
47
48/// Downstream throttle message (client → server, 0x52).
49///
50/// Sent by Lite when its incoming shape delta queue is overwhelmed.
51/// Origin should reduce its push rate for this peer until a
52/// `Throttle { throttle: false }` is received.
53#[derive(
54 Debug, Clone, Serialize, Deserialize, zerompk::ToMessagePack, zerompk::FromMessagePack,
55)]
56pub struct ThrottleMsg {
57 /// `true` to enable throttling, `false` to release.
58 pub throttle: bool,
59 /// Current queue depth at Lite (informational).
60 pub queue_depth: u64,
61 /// Suggested max deltas per second (0 = use server default).
62 pub suggested_rate: u64,
63}