An implementation of a SWIM (Das, Gupta and Motivala, 2002) failure detector that can be embedded into other application, for example, into IoT devices.
SWIM detects failed nodes through a ping / ping-req protocol. Each member periodically pings a random peer and, on timeout, asks other members to probe the target before declaring it suspect. A suspicion sub-protocol with incarnation numbers lets falsely suspected nodes refute the claim, so only persistently unreachable nodes are marked dead. All membership updates, such as joins, suspects, and failures, are disseminated by piggybacking them on the protocol messages themselves, avoiding the need for a separate broadcast channel.
Tools like Consul and Serf from HashiCorp also build on the SWIM protocol, but they ship as standalone services that applications communicate with over RPC. In contrast, libswim is a library designed to be embedded directly into an application, making it suitable for environments where running a separate daemon is impractical, such as IoT devices or resource-constrained systems.
- CMake (>= 3.20)
- Ninja (or another CMake-supported generator)
libuuidncurses(optional — needed for the TUI example)
On Ubuntu:
sudo apt install cmake ninja-build uuid-dev libncurses-devTo build:
cmake -B build -G Ninja
cmake --build buildTo run the tests:
ctest --test-dir buildTo run clang-tidy, configure with compile commands enabled and run the
tidy target:
cmake -B build -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cmake --build build --target tidyTo format all source files with clang-format:
cmake --build build --target format