code
Clone this repository
https://tangled.org/gdiazlo.tngl.sh/swim
git@tangled.org:gdiazlo.tngl.sh/swim
For self-hosted knots, clone URLs may differ based on your setup.
- test_kcas.ml: 15 tests for buffer_pool, membership, pending_acks, member transitions
- test_integration.ml: 9 cluster lifecycle tests (create, start, shutdown, stats, members, broadcast)
- Fix env type constraint to accept platform-specific Eio backends via identity cast
Total test count: 89 tests across 6 test executables
Test modules implemented:
- generators.ml: QCheck generators for all SWIM types (node_id, incarnation,
member_state, node_info, protocol_msg, packet, config, errors)
- test_codec.ml: Codec property tests (roundtrip, size accuracy) and unit tests
for encoder/decoder operations, error handling (19 tests)
- test_crypto.ml: Crypto property tests (roundtrip, overhead size) and unit tests
for key validation, tampering detection, nonce uniqueness (13 tests)
- test_pure.ml: Protocol_pure property tests (merge convergence, idempotence) and
unit tests for state transitions, invalidation, timeouts (32 tests)
All 65 tests passing.
Core library implementation with 11 modules:
- types.ml/mli: Core immutable types (node_id, incarnation, member_state, protocol_msg, packet, config, env, stats)
- codec.ml: Zero-copy binary encoding/decoding with magic bytes, version, message tags
- crypto.ml: AES-256-GCM encryption using Mirage_crypto
- buffer_pool.ml/mli: Lock-free buffer pool using Kcas_data.Queue + Eio.Semaphore
- protocol_pure.ml/mli: Pure SWIM state transitions (handle_alive/suspect/dead, suspicion_timeout, etc)
- membership.ml/mli: Kcas-based member table with Kcas_data.Hashtbl
- dissemination.ml/mli: Broadcast queue with transmit counting and message invalidation
- pending_acks.ml/mli: Ack tracking with Eio.Promise for async waiting
- transport.ml: UDP/TCP networking with Eio.Net
- protocol.ml: Main protocol loop with message handlers and probe cycles
- swim.ml: Public API with Cluster module
Design constraints followed:
- Eio only (no Lwt/Async/Mutex/Condition)
- All coordination via kcas (no locks)
- Result types for expected errors (no exceptions)
- Zero-copy buffer management