Back to Site
Loading...
Searching...
No Matches
node.h File Reference

The public entry point: a thin facade that wires the layers together. More...

#include "transport/connection.h"
#include "transport/reactor_pool.h"
#include "core/address.h"
#include "peer/peer_table.h"
#include "peer/peer_id.h"
#include "peer/peer_info.h"
#include "security/identity.h"
#include "security/handshaker.h"
#include "node/config.h"
#include "node/node_context.h"
#include "peer/peer.h"
#include "node/peer_network.h"
#include "wire/message_router.h"
#include <atomic>
#include <condition_variable>
#include <functional>
#include <memory>
#include <mutex>
#include <optional>
#include <string>
#include <string_view>
#include <thread>
#include <type_traits>
#include <vector>
Include dependency graph for node.h:

Go to the source code of this file.

Classes

class  librats::Node
 

Namespaces

namespace  librats
 

Detailed Description

The public entry point: a thin facade that wires the layers together.

Node owns the reactor pool, the security provider, the peer directory and the message router, and it IS the ConnectionDelegate the reactors report to. It is deliberately thin — it composes the layers and exposes a small async API; the logic lives in those layers, not here.

Threading: connect/send/broadcast are non-blocking and thread-safe — they post work to the owning reactor. Event callbacks (on_peer_connected / on(channel,…) / on_peer_disconnected) run on a reactor thread; register them before start().

── What a bare Node does, and what it does NOT ────────────────────────────── A Node on its own is just the secure transport core. Out of the box it gives you:

  • an encrypted TCP transport (Noise_XX, or plaintext per NodeConfig::security), with a self-certifying PeerId and the app protocol bound into the handshake;
  • manual dialing: connect(host, port) / connect(Address) — it never discovers peers by itself;
  • the peer directory + admission limit: peers(), peer(), peer_count(), max_peers;
  • raw channel messaging: send(to, channel, bytes) / broadcast(channel, bytes) / on(channel, …);
  • peer connect/disconnect events and the node-scoped EventBus + ServiceRegistry;
  • host network-change detection (NetworkChanged on the EventBus), if enabled;
  • identity persistence (NodeConfig::data_dir → identity.key).

Everything else is an opt-in Subsystem you attach with add_subsystem() BEFORE start(): peer discovery (DhtDiscovery, MdnsDiscovery), pub/sub (PubSub), typed JSON messaging (MessageJson), file transfer (FileTransfer), liveness (PingService), NAT port mapping (PortMappingService), automatic reconnection (ReconnectionService), distributed storage (StorageManager). None of these are wired by default — a bare Node neither discovers peers nor reconnects on its own; the application composes exactly the capabilities it wants. This is deliberate: the node stays a small, predictable core, and you pay only for what you attach.

Definition in file node.h.