qudag_protocol/
synchronization.rs1use crate::state::ProtocolState;
4use thiserror::Error;
5
6#[derive(Debug, Error)]
8pub enum SyncError {
9 #[error("Synchronization failed")]
11 SyncFailed,
12
13 #[error("Invalid state received")]
15 InvalidState,
16
17 #[error("Version mismatch")]
19 VersionMismatch,
20}
21
22#[derive(Debug, Clone, PartialEq, Eq)]
24pub enum SyncMode {
25 Full,
27
28 Incremental,
30
31 Partial,
33}
34
35#[derive(Debug, Clone)]
37pub struct SyncConfig {
38 pub mode: SyncMode,
40
41 pub interval: u64,
43
44 pub max_attempts: u32,
46}
47
48pub trait StateSynchronization {
50 fn init(config: SyncConfig) -> Result<(), SyncError>;
52
53 fn start_sync(&mut self) -> Result<(), SyncError>;
55
56 fn stop_sync(&mut self) -> Result<(), SyncError>;
58
59 fn request_state(&mut self) -> Result<ProtocolState, SyncError>;
61
62 fn send_state(&mut self, state: &ProtocolState) -> Result<(), SyncError>;
64
65 fn resolve_conflicts(&mut self, states: Vec<ProtocolState>)
67 -> Result<ProtocolState, SyncError>;
68}