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 TCP transport (Noise_XX), a self-certifying librats::PeerId, manual dialing, a peer directory, and raw channel messaging. Everything else — discovery, pub/sub, file transfer, NAT port mapping, 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) | nlohmann::json |
| Pub/sub topics | librats::PubSub subscribe/publish | bytes, GossipSub mesh |
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) |
RATS_BINDINGS | Build the C ABI |
RATS_STORAGE | Enable distributed key-value storage |
RATS_SEARCH_FEATURES | Enable BitTorrent features |
RATS_SHARED_LIBRARY | Build as a shared library |
librats is released under the MIT License.