Expand description
Peer Sync Protocol — bidirectional state synchronisation using vector clocks and CRDTs.
PeerSyncProtocol implements a production-grade, conflict-free replicated data type
(CRDT) engine. Each node maintains a VectorClock that it increments on every local
write. Remote operations are applied through PeerSyncProtocol::apply_remote_op, which
resolves write–write conflicts according to a pluggable ConflictPolicy.
§Design goals
- Convergence: any two nodes that have received the same set of operations end up in identical state regardless of delivery order.
- No data loss by default:
LastWriteWinsandHighestClockpolicies always keep one version;MergeBytesretains both. - Tombstoning: deleted keys are permanently suppressed so late-arriving puts for the same key are silently discarded.
- Delta sync:
PeerSyncProtocol::generate_deltareturns only the entries that a remote peer is missing, batched into a singleSyncOperation::Merge.
§Example
use ipfrs_network::peer_sync_protocol::{
PeerSyncProtocol, ConflictPolicy, SyncOperation, VectorClock,
};
let mut node_a = PeerSyncProtocol::new("node-a".to_string(), ConflictPolicy::LastWriteWins);
let entry = node_a.local_put("greeting".to_string(), b"hello".to_vec(), 1000);
let mut node_b = PeerSyncProtocol::new("node-b".to_string(), ConflictPolicy::LastWriteWins);
let op = SyncOperation::Put { entry };
node_b.apply_remote_op("node-a", op, 1001).unwrap();
assert_eq!(node_b.get("greeting").unwrap().value, b"hello");Structs§
- Peer
Sync Protocol - Bidirectional state-synchronisation protocol backed by vector clocks and CRDTs.
- PspSync
Stats - A snapshot of key metrics for a
PeerSyncProtocolinstance. - Sync
Entry - A key-value record annotated with causal metadata.
- Sync
State - The replicated state held by a single node.
- Vector
Clock - A logical clock that tracks causality per node.
Enums§
- Conflict
Policy - Strategy used to resolve write–write conflicts (concurrent updates to the same key).
- Sync
Error - Errors returned by
PeerSyncProtocoloperations. - Sync
Operation - An atomic operation that can be applied to a
PeerSyncProtocol.