Skip to main content

SyncEngine

Trait SyncEngine 

Source
pub trait SyncEngine: Send + Sync {
    // Required methods
    fn start_sync<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn stop_sync<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
    fn subscribe<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        collection: &'life1 str,
        query: &'life2 Query,
    ) -> Pin<Box<dyn Future<Output = Result<SyncSubscription, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait;
    fn is_syncing<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;

    // Provided methods
    fn set_priority<'life0, 'life1, 'async_trait>(
        &'life0 self,
        collection: &'life1 str,
        priority: Priority,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait { ... }
    fn force_sync<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait { ... }
    fn connect_to_peer<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        endpoint_id_hex: &'life1 str,
        addresses: &'life2 [String],
    ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             Self: 'async_trait { ... }
}
Expand description

Trait 3: Synchronization Control

Controls when and how documents are synchronized between peers. Abstracts over different sync strategies and protocols.

Required Methods§

Source

fn start_sync<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Start synchronization with discovered peers

Begins exchanging documents with connected peers. Discovery must be started first via PeerDiscovery::start().

Source

fn stop_sync<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Stop synchronization

Stops exchanging documents but maintains peer connections.

Source

fn subscribe<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, collection: &'life1 str, query: &'life2 Query, ) -> Pin<Box<dyn Future<Output = Result<SyncSubscription, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Create sync subscription for a collection

Tells the sync engine to actively synchronize documents in this collection. Without a subscription, documents may not sync (backend-dependent).

The subscription keeps sync active while the returned handle is alive. Drop the handle to unsubscribe.

Source

fn is_syncing<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Check if sync is currently active

Provided Methods§

Source

fn set_priority<'life0, 'life1, 'async_trait>( &'life0 self, collection: &'life1 str, priority: Priority, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Set sync priority for a collection (optional)

Backends that support priority-based sync can use this to prioritize certain collections over others.

Default implementation is a no-op.

Source

fn force_sync<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Force a sync round (push pending changes)

Most backends sync automatically, but this can force immediate sync. Useful for testing or ensuring critical updates are sent.

Default implementation is a no-op.

Source

fn connect_to_peer<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, endpoint_id_hex: &'life1 str, addresses: &'life2 [String], ) -> Pin<Box<dyn Future<Output = Result<bool, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, Self: 'async_trait,

Connect to a peer using their EndpointId and addresses (Issue #235)

Establishes a connection to a peer with a known EndpointId and network addresses. Used for static peer configuration in containerlab and similar environments.

§Arguments
  • endpoint_id_hex - The peer’s EndpointId as a hex string (64 chars)
  • addresses - List of socket addresses (e.g., “192.168.1.1:12345”)
§Returns
  • Ok(true) - Connection established successfully
  • Ok(false) - Tie-breaking: peer will connect to us instead
  • Err(e) - Connection failed

Default implementation returns Ok(false) for backends that don’t support this.

Implementors§