Skip to main content

aura_sync/protocols/
mod.rs

1//! Layer 5: Synchronization Protocol Implementations - Anti-Entropy, Snapshots, OTA, Epochs
2//!
3//! Complete end-to-end protocol implementations built atop Layer 4 orchestration:
4//! - **anti_entropy**: Digest-based CRDT reconciliation with state transfer (per docs/105_journal.md)
5//! - **journal**: Journal operation synchronization with causal ordering guarantees
6//! - **snapshots**: Coordinated garbage collection with writer fencing and threshold approval
7//! - **ota**: OTA upgrade coordination with epoch fencing for consistency
8//! - **receipts**: Receipt verification for multi-hop message chains (per docs/003_information_flow_contract.md)
9//! - **epochs**: Epoch rotation and identity epoch management with AMP consensus
10//!
11//! **Protocol Principles** (per docs/110_mpst_and_choreography.md):
12//! - **Effect-based**: Parameterized by effect traits (NetworkEffects, JournalEffects) for testing
13//! - **Choreographic**: Use session types (aura-mpst) for distributed coordination with deadlock freedom
14//! - **Composable**: Can be combined without tight coupling via effect composition
15//! - **Reusable**: Building blocks for services (aura-sync/services) and higher-level workflows
16//! - **Guard-integrated**: Messages flow through guard chain (CapGuard → FlowGuard → Journal)
17//!
18//! ```rust,ignore
19//! async fn sync_with_peer<E>(effects: &E, peer: DeviceId) -> SyncResult<()>
20//! where
21//!     E: JournalEffects + NetworkEffects,
22//! {
23//!     let protocol = AntiEntropyProtocol::new(config);
24//!     protocol.execute(effects, peer).await
25//! }
26//! ```
27//!
28//! ## Infrastructure Integration
29//!
30//! Protocols use infrastructure from Phase 2:
31//! - `RetryPolicy` for resilient operations
32//! - `PeerManager` for peer selection
33//! - `ConnectionPool` for connection management
34//! - `RateLimiter` for flow budget enforcement
35//!
36//! ## Clean Public APIs
37//!
38//! Each protocol exposes:
39//! - Configuration types
40//! - Result types
41//! - Main execution interface
42//! - Statistics and metrics
43
44pub mod anti_entropy;
45pub mod device_epoch_rotation;
46pub mod epochs;
47pub mod fact_sync;
48pub mod journal;
49pub mod ota;
50pub mod ota_ceremony;
51pub mod propagation;
52pub mod receipts;
53pub mod snapshots;
54
55// New authority-centric modules
56pub mod authority_journal_sync;
57pub mod namespaced_sync;
58
59use aura_core::effects::{JournalEffects, NetworkEffects, PhysicalTimeEffects};
60use aura_guards::GuardContextProvider;
61
62pub trait SyncJournalEffects: JournalEffects + Send + Sync {}
63
64impl<T> SyncJournalEffects for T where T: JournalEffects + Send + Sync {}
65
66pub trait SyncProtocolEffects:
67    SyncJournalEffects + NetworkEffects + PhysicalTimeEffects + GuardContextProvider
68{
69}
70
71impl<T> SyncProtocolEffects for T where
72    T: SyncJournalEffects + NetworkEffects + PhysicalTimeEffects + GuardContextProvider
73{
74}
75
76pub trait SyncCoreJournalEffects: JournalEffects + Send + Sync {}
77
78impl<T> SyncCoreJournalEffects for T where T: JournalEffects + Send + Sync {}
79
80pub trait SyncCoreProtocolEffects:
81    SyncCoreJournalEffects + NetworkEffects + PhysicalTimeEffects
82{
83}
84
85impl<T> SyncCoreProtocolEffects for T where
86    T: SyncCoreJournalEffects + NetworkEffects + PhysicalTimeEffects
87{
88}
89
90// Re-export key types for convenience
91pub use anti_entropy::{
92    AntiEntropyConfig, AntiEntropyProtocol, AntiEntropyRequest, AntiEntropyResult, DigestStatus,
93    JournalDigest, LoggingProgressCallback, NoOpProgressCallback, SyncProgressCallback,
94    SyncProgressEvent,
95};
96
97pub use journal::{
98    JournalSyncConfig, JournalSyncProtocol, JournalSyncResult, SyncMessage, SyncState,
99};
100
101pub use snapshots::{
102    SnapshotApproval, SnapshotConfig, SnapshotProposal, SnapshotProtocol, SnapshotResult,
103    WriterFence, WriterFenceGuard,
104};
105
106pub use ota::{OTAConfig, OTAProtocol, OTAResult, UpgradeKind, UpgradeProposal};
107
108pub use receipts::{ReceiptVerificationConfig, ReceiptVerificationProtocol, VerificationResult};
109
110pub use epochs::{
111    EpochCommit, EpochConfig, EpochConfirmation, EpochRotation, EpochRotationCoordinator,
112    EpochRotationProposal, RotationStatus,
113};
114
115pub use device_epoch_rotation::{
116    DeviceEpochAcceptance, DeviceEpochCommit, DeviceEpochProposal, DeviceEpochRotationKind,
117};
118
119/// Re-exports for EpochRotation choreography runners
120pub mod epoch_runners {
121    pub use crate::protocols::epochs::telltale_session_types_epoch_rotation::epoch_rotation::EpochRotationProtocolRole;
122    pub use crate::protocols::epochs::telltale_session_types_epoch_rotation::epoch_rotation::runners::{
123        execute_as, run_coordinator, run_participant1, run_participant2,
124        CoordinatorOutput, Participant1Output, Participant2Output,
125    };
126}
127
128pub use ota_ceremony::{
129    OTACeremonyAbort, OTACeremonyCommit, OTACeremonyConfig, OTACeremonyFact, OTACeremonyId,
130    OTACeremonyState, OTACeremonyStatus, OTAReadinessOutcome, OTAReadinessWitness,
131    ReadinessCommitment, UpgradeProposal as CeremonyUpgradeProposal,
132};
133
134/// Re-exports for the OTA activation choreography surface.
135pub mod ota_runners {
136    pub use crate::protocols::ota_ceremony::telltale_session_types_ota_activation::ota_activation::OTAActivationProtocolRole;
137}
138
139pub use fact_sync::{FactSyncConfig, FactSyncProtocol, FactSyncResult, FactSyncStats};
140
141pub use propagation::{
142    FailedPeerInfo, LoggingPropagationCallback, NoOpPropagationCallback, PropagationCallback,
143    PropagationEvent, PropagationTracker,
144};