Skip to main content

Crate subduction_core

Crate subduction_core 

Source
Expand description

§Subduction

Subduction is a sync protocol for local-first applications built on Sedimentree.

§Getting Started

Use SubductionBuilder to construct a [Subduction] instance. The builder tracks required fields at the type level — calling build is a compile error until signer, storage, and spawner have all been set.

use subduction_core::subduction::builder::SubductionBuilder;

// Required: signer (identity), storage + policy, and spawner.
// Everything else has sensible defaults.
let (subduction, handler, listener, manager) = SubductionBuilder::new()
    .signer(my_signer)
    .storage(my_storage, Arc::new(my_policy))
    .spawner(TokioSpawn)
    .build();

// Spawn the background tasks
tokio::spawn(listener);
tokio::spawn(manager);

// Connect to a peer and sync
let peer_id = connection.peer_id();
subduction.add_connection(connection).await?;
subduction.full_sync_with_peer(&peer_id, true, None).await;

§Optional configuration

let (subduction, handler, listener, manager) = SubductionBuilder::new()
    .signer(my_signer)
    .storage(my_storage, Arc::new(my_policy))
    .spawner(TokioSpawn)
    .discovery_id(DiscoveryId::new(b"sync.example.com"))
    .nonce_cache(NonceCache::new(Duration::from_secs(300)))
    .max_pending_blob_requests(20_000)
    .build();

For hydration from storage (e.g. Wasm), pre-populate the sedimentree map and pass it to the builder:

let sedimentrees = Arc::new(ShardedMap::new());
// ... load from storage, populate sedimentrees ...

let (subduction, handler, listener, manager) = SubductionBuilder::new()
    .signer(my_signer)
    .storage(my_storage, Arc::new(my_policy))
    .spawner(WasmSpawn)
    .sedimentrees(sedimentrees)
    .build();

See the subduction module for the full API guide covering naming conventions, API levels, and common patterns.

§Modules

For cryptographic primitives (Signer, Signed), see subduction_crypto.

Modules§

authenticated
Authenticated connection wrapper.
connection
Manage connections to peers in the network.
handler
Message handler trait for the Subduction sync protocol.
handshake
Handshake protocol for authenticating new connections.
multiplexer
Request-response multiplexer.
nonce_cache
Nonce tracking for handshake replay protection.
peer
Peers
policy
Policies for controlling access in Subduction.
remote_heads
Remote heads tracking and notification.
sharded_map
A sharded concurrent map for reducing lock contention.
storage
Storage-related types and capabilities.
subduction
The main synchronization logic and bookkeeping for Sedimentree.
timeout
Generic timeout strategies for async operations.
timestamp
Timestamps
transport
Byte-oriented transport abstraction.