#include <node.h>
Public Member Functions | |
| Node (NodeConfig config) | |
| Construct a node from its configuration (see NodeConfig). | |
| ~Node () override | |
| Stops the node if still running, then releases all resources. | |
| Node (const Node &)=delete | |
| Node & | operator= (const Node &)=delete |
| template<class T > | |
| T * | add_subsystem (std::unique_ptr< T > subsystem) |
| Attach a subsystem (DHT, GossipSub, PingService…). | |
| bool | start () |
| Bring the node up: open the listener (if enabled), start the reactor pool, then start every attached subsystem. | |
| void | stop () |
| Tear the node down: stop subsystems (reverse order), close all connections, and join the reactor pool. | |
| const PeerId & | local_id () const noexcept override |
| Our self-certifying peer identity (the public key peers authenticate). | |
| uint16_t | listen_port () const noexcept override |
| The bound listen port (the actual port when the config requested 0). | |
| const std::string & | protocol_name () const noexcept |
| Application protocol identity bound into the handshake (see NodeConfig). | |
| const std::string & | protocol_version () const noexcept |
| EventBus & | events () noexcept |
| ServiceRegistry & | services () noexcept |
| void | connect (const Address &address) override |
| Dial a peer. | |
| void | connect (const std::string &host, uint16_t port) |
| Dial a peer. | |
| size_t | peer_count () const noexcept |
| Number of currently-established peers. | |
| std::vector< PeerInfo > | peers () const override |
| Snapshot of all established peers (id, addresses, direction, timing). | |
| std::optional< Peer > | peer (const PeerId &id) |
| Handle to a connected peer by id, or std::nullopt if not connected. | |
| std::vector< Address > | observed_addresses () const |
| Our own addresses as remote peers reported observing us at — their observed IP paired with our listen port. | |
| size_t | max_peers () const noexcept |
| void | set_max_peers (size_t n) noexcept |
| bool | peer_limit_reached () const noexcept |
| void | send (const PeerId &to, std::string_view channel, ByteView payload) |
| Send raw bytes to one peer on a named channel. | |
| void | broadcast (std::string_view channel, ByteView payload) |
| Send raw bytes on a named channel to every connected peer. | |
| void | on_peer_connected (PeerNetwork::PeerEventHandler cb) override |
| Subscribe to peer-connected events. The handler runs on a reactor thread. | |
| void | on_peer_disconnected (PeerNetwork::PeerDisconnectHandler cb) override |
| Subscribe to peer-disconnected events. The handler runs on a reactor thread. | |
| void | on_dial_failed (PeerNetwork::DialFailedHandler cb) override |
| Subscribe to failed-outbound-dial events. The handler runs on a reactor thread. | |
| void | on (std::string_view channel, MessageRouter::Handler cb) |
| Register a handler for inbound messages on a named channel. | |
| template<class T > | |
| T * | subsystem () noexcept |
| MessageJson * | json () noexcept |
| The JSON messaging module if one was attached (add_subsystem<MessageJson>), else nullptr. | |
| void | send (const PeerId &to, MessageType type, ByteView payload) override |
| void | broadcast (MessageType type, ByteView payload) override |
| std::vector< PeerId > | connected_peers () const override |
| void | on (MessageType type, PeerNetwork::MessageHandler cb) override |
Public Member Functions inherited from librats::PeerNetwork | |
| virtual | ~PeerNetwork ()=default |
Friends | |
| class | Peer |
Additional Inherited Members | |
Public Types inherited from librats::PeerNetwork | |
| using | MessageHandler = std::function< void(const Peer &, ByteView)> |
| using | PeerEventHandler = std::function< void(const Peer &)> |
| using | PeerDisconnectHandler = std::function< void(const PeerId &)> |
| using | DialFailedHandler = std::function< void(const Address &)> |
|
explicit |
Construct a node from its configuration (see NodeConfig).
This only loads the identity and prepares the layers; no socket is opened until start().
|
override |
Stops the node if still running, then releases all resources.
|
delete |
|
inline |
Attach a subsystem (DHT, GossipSub, PingService…).
Call before start(); the node owns it (single ownership), gives it a PeerNetwork on start(), and stops it on stop(). Returns a non-owning pointer to the just-added subsystem so the caller can drive its API without a separate get()/move dance — valid for the node's lifetime: auto* files = node.add_subsystem(std::make_unique<FileTransfer>("./dl"));
Definition at line 88 of file node.h.
References subsystem().
|
overridevirtual |
Implements librats::PeerNetwork.
| void librats::Node::broadcast | ( | std::string_view | channel, |
| ByteView | payload | ||
| ) |
Send raw bytes on a named channel to every connected peer.
|
overridevirtual |
Dial a peer.
Non-blocking: the connection (TCP + handshake) completes asynchronously and surfaces via on_peer_connected. A duplicate or self-connection is detected and dropped after the handshake.
Implements librats::PeerNetwork.
| void librats::Node::connect | ( | const std::string & | host, |
| uint16_t | port | ||
| ) |
Dial a peer.
Non-blocking: the connection (TCP + handshake) completes asynchronously and surfaces via on_peer_connected. A duplicate or self-connection is detected and dropped after the handshake.
|
overridevirtual |
Implements librats::PeerNetwork.
|
noexcept |
The JSON messaging module if one was attached (add_subsystem<MessageJson>), else nullptr.
Convenience over subsystem<MessageJson>(); defined in node.cpp.
|
inlineoverridevirtualnoexcept |
The bound listen port (the actual port when the config requested 0).
Implements librats::PeerNetwork.
|
inlineoverridevirtualnoexcept |
Our self-certifying peer identity (the public key peers authenticate).
Implements librats::PeerNetwork.
| std::vector< Address > librats::Node::observed_addresses | ( | ) | const |
Our own addresses as remote peers reported observing us at — their observed IP paired with our listen port.
De-duplicated and bounded; populated as peers send their identify message. Useful for NAT awareness / advertising.
|
inlineoverridevirtual |
Implements librats::PeerNetwork.
|
inline |
|
inlineoverridevirtual |
Subscribe to failed-outbound-dial events. The handler runs on a reactor thread.
Implements librats::PeerNetwork.
|
inlineoverridevirtual |
Subscribe to peer-connected events. The handler runs on a reactor thread.
Implements librats::PeerNetwork.
|
inlineoverridevirtual |
Subscribe to peer-disconnected events. The handler runs on a reactor thread.
Implements librats::PeerNetwork.
Handle to a connected peer by id, or std::nullopt if not connected.
|
inlinenoexcept |
|
inlinenoexcept |
|
inlineoverridevirtual |
Snapshot of all established peers (id, addresses, direction, timing).
Implements librats::PeerNetwork.
|
inlinenoexcept |
Application protocol identity bound into the handshake (see NodeConfig).
Definition at line 110 of file node.h.
References librats::NodeConfig::protocol_name.
|
inlinenoexcept |
Definition at line 111 of file node.h.
References librats::NodeConfig::protocol_version.
|
overridevirtual |
Implements librats::PeerNetwork.
| void librats::Node::send | ( | const PeerId & | to, |
| std::string_view | channel, | ||
| ByteView | payload | ||
| ) |
Send raw bytes to one peer on a named channel.
Non-blocking; the payload is copied into the peer's send queue. No-op if the peer is not connected.
| to | destination peer id |
| channel | application channel name (interned to a 16-bit id) |
| payload | message bytes (copied) |
|
inlinenoexcept |
| bool librats::Node::start | ( | ) |
Bring the node up: open the listener (if enabled), start the reactor pool, then start every attached subsystem.
Register callbacks and attach subsystems BEFORE calling this.
| void librats::Node::stop | ( | ) |
Tear the node down: stop subsystems (reverse order), close all connections, and join the reactor pool.
Safe to call once; idempotent.
|
inlinenoexcept |
Definition at line 173 of file node.h.
Referenced by add_subsystem().