Skip to main content

Module protocol

Module protocol 

Source
Expand description

Prolly Tree sync protocol for non-git event replication.

Two replicas exchange Prolly Tree root hashes, identify divergent subtrees in O(log N), and transfer only the missing events.

The protocol is transport-agnostic: any type implementing SyncTransport can be used (TCP, HTTP, MCP, USB drive via file exchange, etc.).

This is a library module — bones does not own transport. External tools implement SyncTransport for their chosen medium and call sync / serve_sync to run the 3-round protocol.

§Protocol rounds

  1. Root hash exchange — if hashes match, replicas are identical (fast path).
  2. Event hash exchange — each side sends its full event hash list.
  3. Event transfer — each side sends events the other is missing.

§Example (in-memory, for testing)

use bones_core::sync::protocol::sync_in_memory;

let result = sync_in_memory(&local_events, &remote_events).unwrap();
// result.local_received  — events the local side was missing
// result.remote_received — events the remote side was missing
// result.local_report    — sync statistics

Structs§

InMemoryError
Error type for in-memory transport (should never happen in tests).
InMemoryTransport
A pair of in-memory channels for testing sync without real I/O.
SyncInMemoryResult
Result of an in-memory sync between two replicas.
SyncReport
Summary of a completed sync operation.

Traits§

SyncTransport
Abstraction over the wire protocol.

Functions§

serve_sync
Respond to a sync request as the remote side.
sync
Synchronise local events with a remote replica.
sync_in_memory
Run a full sync between two event sets using in-memory transport.