Welcome to the librats API documentation. librats is a high-performance, lightweight peer-to-peer networking library written in C++17, with a stable C ABI and language bindings.
The entry point is librats::Node — a thin, secure transport core. On its own a Node gives you an encrypted transport (Noise_XX) over TCP or UDP, a self-certifying librats::PeerId, manual dialing, a peer directory, and raw channel messaging. Everything else — discovery, pub/sub, file transfer, NAT traversal, reconnection — is an opt-in librats::Subsystem you attach with add_subsystem() before start(). You pay only for what you attach.
| Surface | API | Payload |
|---|---|---|
| Raw channel | node.on/send/broadcast(channel, …) | bytes |
| Typed JSON | node.json()->on/send(type, …) (librats::MessageJson) | librats::Json |
| Pub/sub topics | librats::PubSub subscribe/publish | bytes, GossipSub mesh |
RATS_STORAGE)RATS_SEARCH_FEATURES)Connections use the Noise_XX_25519_ChaChaPoly_SHA256 handshake by default (mutual authentication, perfect forward secrecy). The application protocol name/version is bound into the handshake prologue, so apps that disagree cannot connect. Set NodeConfig::security to Plaintext to disable encryption.
For FFI and language bindings, the canonical C API is declared in bindings/rats.h: an opaque rats_t wraps a Node, subsystems are enabled with rats_enable_*() before rats_start(), and fallible calls return rats_error_t.
| Option | Description |
|---|---|
RATS_BUILD_TESTS | Build unit tests (GoogleTest) — default ON |
RATS_BUILD_CLIENT | Build the rats-client reference application — default ON |
RATS_BUILD_EXAMPLES | Build the examples/ programs — default OFF |
RATS_BINDINGS | Build the C ABI — default ON |
RATS_INSTALL | Generate install/export targets (find_package(rats)) — default ON |
RATS_STORAGE | Enable distributed key-value storage — default OFF |
RATS_SEARCH_FEATURES | Enable BitTorrent features — default OFF |
RATS_SHARED_LIBRARY / RATS_STATIC_LIBRARY | Library linkage — default static |
RATS_ENABLE_ASAN / RATS_ENABLE_TSAN | Sanitizer builds (mutually exclusive) — default OFF |
librats is released under the MIT License.