sgns::neoswarm::network::P2PNode¶
Manages a libp2p host for swarm task broadcasting and CRDT sync. More...
#include <p2p_node.hpp>
Public Classes¶
| Name | |
|---|---|
| struct | Config |
| struct | Impl |
Public Types¶
| Name | |
|---|---|
| using std::function< void(const Task &task, const std::string &from_peer)> | TaskHandler |
| using std::function< void(const std::string &crdt_data)> | CRDTHandler |
Public Functions¶
| Name | |
|---|---|
| P2PNode(std::shared_ptr< security::NodeIdentity > identity, Config cfg) | |
| P2PNode(std::shared_ptr< security::NodeIdentity > identity) | |
| ~P2PNode() | |
| outcome::result< void > | Start() Start the libp2p host and begin listening. |
| void | Stop() Stop the host and disconnect all peers. |
| bool | IsRunning() const |
| std::string | ListenAddress() const |
| std::string | PeerId() const |
| void | OnTask(TaskHandler handler) Register a handler for incoming task broadcasts. |
| void | OnCRDT(CRDTHandler handler) Register a handler for incoming CRDT sync messages. |
| outcome::result< void > | BroadcastTask(const Task & task) Broadcast a task to all connected peers via GossipSub. |
| outcome::result< void > | BroadcastCRDT(const std::string & crdt_data) Broadcast a CRDT state update to all peers. |
| std::vector< std::string > | ConnectedPeers() const Get the list of currently connected peer IDs. |
Detailed Description¶
Manages a libp2p host for swarm task broadcasting and CRDT sync.
Uses Noise protocol for encryption and Yamux for stream multiplexing. Falls back to a local stub when libp2p is not compiled in.
Public Types Documentation¶
using TaskHandler¶
using sgns::neoswarm::network::P2PNode::TaskHandler = std::function<void( const Task& task, const std::string& from_peer )>;
using CRDTHandler¶
using sgns::neoswarm::network::P2PNode::CRDTHandler = std::function<void( const std::string& crdt_data )>;
Public Functions Documentation¶
function P2PNode¶
function P2PNode¶
function ~P2PNode¶
function Start¶
Start the libp2p host and begin listening.
Return: outcome::success or NetworkError.
function Stop¶
Stop the host and disconnect all peers.
function IsRunning¶
Return: True if the node is currently running.
function ListenAddress¶
Return: Our listen multiaddress (available after Start()).
function PeerId¶
Return: Our peer ID string.
function OnTask¶
Register a handler for incoming task broadcasts.
Parameters:
- handler Callback invoked when a task is received from a peer.
function OnCRDT¶
Register a handler for incoming CRDT sync messages.
Parameters:
- handler Callback invoked when a CRDT update is received.
function BroadcastTask¶
Broadcast a task to all connected peers via GossipSub.
Parameters:
- task Task to broadcast.
Return: outcome::success or NetworkError.
function BroadcastCRDT¶
Broadcast a CRDT state update to all peers.
Parameters:
- crdt_data Serialised CRDT state.
Return: outcome::success or NetworkError.
function ConnectedPeers¶
Get the list of currently connected peer IDs.
Return: Vector of peer ID strings.
Updated on 2026-10-09 at 03:59:42 +0000