gossip_crdts library
CRDT extensions for the gossip protocol library.
This library provides Conflict-free Replicated Data Type (CRDT) support for the gossip protocol, enabling automatic conflict resolution and convergent state synchronization across distributed nodes.
Features
- Seamless Integration: Extends existing GossipNode instances with CRDT capabilities
- Multiple CRDT Types: Counters, Sets, Registers, and Maps with conflict-free semantics
- Automatic Synchronization: CRDTs sync automatically through the gossip protocol
- Type Safety: Strongly typed CRDT operations with compile-time guarantees
- Pluggable Storage: Abstract storage interface for different persistence backends
Quick Start
import 'package:gossip/gossip.dart';
import 'package:gossip_crdts/gossip_crdts.dart';
// Create a regular gossip node
final node = GossipNode(
config: GossipConfig(nodeId: 'node1'),
eventStore: MemoryEventStore(),
transport: MyTransport(),
);
await node.start();
// Enable CRDT support
final crdtManager = node.enableCRDTSupport();
// Register and use a counter CRDT
final counter = GCounter('shared-counter');
crdtManager.register(counter);
await crdtManager.performOperation('shared-counter', 'increment', {'amount': 5});
print('Counter value: ${counter.value}'); // Counter value: 5
Supported CRDT Types
Counters
- GCounter: Grow-only counter (increment only)
- PNCounter: Increment/decrement counter
Sets
- GSet: Grow-only set (add only)
- ORSet: Observed-Remove set (add and remove)
Registers
- LWWRegister: Last-Writer-Wins register
- MVRegister: Multi-Value register (preserves concurrent updates)
Maps
- ORMap: Observed-Remove map with CRDT values
- LWWMap: Last-Writer-Wins map
Sequences
- RGAArray: Replicated Growable Array (ideal for text editing)
Flags
- EnableWinsFlag: Boolean flag where enable operations win
Classes
-
CRDT<
T> - Abstract base class for all CRDT implementations.
- CRDTEnabledGossipNode
- A wrapper that combines GossipNode and CRDTManager functionality.
- CRDTManager
- Manages CRDTs for a gossip node.
- CRDTManagerStats
- Statistics about a CRDT manager.
- CRDTOperation
- Represents a CRDT operation that can be applied across replicas.
- CRDTOperationEvent
- Event emitted when a CRDT operation occurs.
- CRDTStore
- Abstract interface for CRDT state storage.
- CRDTStoreStats
- Statistics about a CRDT store's current state.
- CRDTSyncEvent
- Event emitted when CRDT synchronization occurs.
- CRDTUpdateEvent
- Event emitted when a CRDT is updated.
- EnableWinsFlag
- An enable-wins flag CRDT.
- GCounter
- A grow-only counter CRDT.
-
GSet<
T> - A grow-only set CRDT.
-
LWWMap<
K, V> - A last-writer-wins map CRDT.
-
LWWRegister<
T> - A last-writer-wins register CRDT.
- MemoryCRDTStore
- In-memory implementation of CRDTStore for development and testing.
-
MVRegister<
T> - A multi-value register CRDT that preserves concurrent updates.
-
ORMap<
K, V extends CRDT> - An observed-remove map CRDT with CRDT values.
- ORMapStats
- Statistics about an OR-Map's internal structure.
-
ORSet<
T> - An observed-remove set CRDT.
- PNCounter
- A positive-negative counter CRDT.
-
RGAArray<
T> - A replicated growable array CRDT for collaborative sequences.
Enums
- CRDTOperationSource
- Sources of CRDT operations.
- CRDTSyncType
- Types of CRDT synchronization.
- CRDTUpdateType
- Types of CRDT updates.
Mixins
-
VectorClockMixin<
T> - Mixin for CRDTs that need to track vector clocks for causality.
Extensions
- GossipNodeCRDTExtension on GossipNode
- Extension to add CRDT capabilities to existing GossipNode instances.
Exceptions / Errors
- CRDTException
- Exception thrown when CRDT operations fail.
- CRDTStoreException
- Exception thrown when CRDT storage operations fail.