Expand description
Synchronization module for Eidetica database.
§Quick Start
// Enable sync
instance.enable_sync().await?;
let sync = instance.sync().unwrap();
// Register transports with their configurations
sync.register_transport("http", HttpTransport::builder()
.bind("127.0.0.1:8080")
).await?;
sync.register_transport("p2p", IrohTransport::builder()).await?;
// Start accepting incoming connections
sync.accept_connections().await?;
// Outbound sync works via the registered transports
sync.sync_with_peer(&Address::http("peer:8080"), Some(&tree_id)).await?;§Architecture
The sync system uses a Background Sync architecture with command-pattern communication:
Sync: Thread-safe frontend usingArc<Sync>with interior mutability (OnceLock). Provides the public API and sends commands to the background.background::BackgroundSync: Single background thread handling all sync operations via a command loop. Owns the transport and retry queue.- Write Callbacks: Automatically trigger sync when entries are committed via database write callbacks.
§Connection Model
The sync system separates outbound and inbound connection handling:
- Outbound (
Sync::sync_with_peer): Works after registering transports viaSync::register_transport. Each transport can be configured via its builder. - Inbound (
Sync::accept_connections): Must be explicitly called each time the instance starts. Starts servers on all registered transports.
This design provides security by default. Nodes don’t accept incoming connections unless explicitly opted in.
§Bootstrap Protocol
The sync protocol detects whether a client needs bootstrap or incremental sync:
- Empty tips → Full bootstrap (complete database transfer)
- Has tips → Incremental sync (only missing entries)
Use Sync::sync_with_peer which handles both cases automatically.
§Duplicate Prevention
Uses Merkle-DAG tip comparison instead of tracking individual sent entries:
- Exchange tips with peer
- Compare DAGs to find missing entries
- Send only what peer doesn’t have
- Receive only what we’re missing
This approach requires no extra storage apart from tracking relevant Merkle-DAG tips.
§Transport Layer
Two transport implementations are available:
- HTTP (
transports::http::HttpTransport): REST API at/api/v0, JSON serialization - Iroh P2P (
transports::iroh::IrohTransport): QUIC-based with NAT traversal
Transports are registered via Sync::register_transport with their builders.
State (like Iroh node identity) is automatically persisted per named instance.
Both implement the transports::SyncTransport trait.
§Peer and State Management
Peers and sync relationships are stored in a dedicated sync database (_sync):
peer_manager::PeerManager: Handles peer registration and relationshipsstate::SyncStateManager: Tracks sync cursors, metadata, and history
§Connection Behavior
- Lazy connections: Established on-demand, not at peer registration
- Periodic sync: Configurable interval (default 5 minutes)
- Retry queue: Failed sends retried with exponential backoff
Re-exports§
pub use error::SyncError;pub use peer_types::Address;pub use peer_types::ConnectionState;pub use peer_types::PeerId;pub use peer_types::PeerInfo;pub use peer_types::PeerStatus;pub use ticket::DatabaseTicket;
Modules§
- background
- Background sync engine implementation.
- error
- Error types for the synchronization module.
- handler
- Sync request handler trait and implementation.
- peer_
manager - Internal peer management for the sync module.
- peer_
types - Peer management types for the sync module.
- protocol
- Protocol definitions for sync communication.
- state
- Sync state tracking for managing synchronization progress and metadata.
- ticket
- URL-based shareable database link.
- transports
- Transport abstractions for sync communication.
- utils
- Sync-specific utility functions.
Structs§
- Auth
Params - Authentication parameters for sync operations.
- Bootstrap
Request - A bootstrap request awaiting manual approval
- Sync
- Synchronization manager for the database.
- Sync
Handle - Handle for tracking sync status with a specific peer.
- Sync
Peer Info - Information needed to register a peer for syncing.
- Sync
Status - Current sync status for a tree/peer pair.
Enums§
- Request
Status - Status of a bootstrap request