pub struct P2PNode { /* private fields */ }
Expand description
Main P2P node structure
Implementations§
Source§impl P2PNode
impl P2PNode
Sourcepub async fn new(config: NodeConfig) -> Result<Self>
pub async fn new(config: NodeConfig) -> Result<Self>
Create a new P2P node with the given configuration
Sourcepub fn builder() -> NodeBuilder
pub fn builder() -> NodeBuilder
Create a new node builder
pub fn local_addr(&self) -> Option<String>
pub async fn subscribe(&self, topic: &str) -> Result<()>
pub async fn publish(&self, topic: &str, data: &[u8]) -> Result<()>
Sourcepub fn config(&self) -> &NodeConfig
pub fn config(&self) -> &NodeConfig
Get the node configuration
Sourcepub async fn is_running(&self) -> bool
pub async fn is_running(&self) -> bool
Check if the node is running
Sourcepub async fn listen_addrs(&self) -> Vec<Multiaddr> ⓘ
pub async fn listen_addrs(&self) -> Vec<Multiaddr> ⓘ
Get the current listen addresses
Sourcepub async fn connected_peers(&self) -> Vec<PeerId> ⓘ
pub async fn connected_peers(&self) -> Vec<PeerId> ⓘ
Get connected peers
Sourcepub async fn peer_count(&self) -> usize
pub async fn peer_count(&self) -> usize
Get peer count
Sourcepub async fn connect_peer(&self, address: &str) -> Result<PeerId>
pub async fn connect_peer(&self, address: &str) -> Result<PeerId>
Connect to a peer
Sourcepub async fn disconnect_peer(&self, peer_id: &PeerId) -> Result<()>
pub async fn disconnect_peer(&self, peer_id: &PeerId) -> Result<()>
Disconnect from a peer
Sourcepub async fn send_message(
&self,
peer_id: &PeerId,
protocol: &str,
data: Vec<u8>,
) -> Result<()>
pub async fn send_message( &self, peer_id: &PeerId, protocol: &str, data: Vec<u8>, ) -> Result<()>
Send a message to a peer
Sourcepub fn subscribe_events(&self) -> Receiver<P2PEvent>
pub fn subscribe_events(&self) -> Receiver<P2PEvent>
Subscribe to network events
Sourcepub fn mcp_server(&self) -> Option<&Arc<MCPServer>>
pub fn mcp_server(&self) -> Option<&Arc<MCPServer>>
Get MCP server reference
Sourcepub async fn register_mcp_tool(&self, tool: Tool) -> Result<()>
pub async fn register_mcp_tool(&self, tool: Tool) -> Result<()>
Register a tool in the MCP server
Sourcepub async fn call_mcp_tool(
&self,
tool_name: &str,
arguments: Value,
) -> Result<Value>
pub async fn call_mcp_tool( &self, tool_name: &str, arguments: Value, ) -> Result<Value>
Call a local MCP tool
Sourcepub async fn call_remote_mcp_tool(
&self,
peer_id: &PeerId,
tool_name: &str,
arguments: Value,
) -> Result<Value>
pub async fn call_remote_mcp_tool( &self, peer_id: &PeerId, tool_name: &str, arguments: Value, ) -> Result<Value>
Call a remote MCP tool on another node
Sourcepub async fn list_mcp_tools(&self) -> Result<Vec<String>>
pub async fn list_mcp_tools(&self) -> Result<Vec<String>>
List available tools in the local MCP server
Sourcepub async fn discover_remote_mcp_services(&self) -> Result<Vec<MCPService>>
pub async fn discover_remote_mcp_services(&self) -> Result<Vec<MCPService>>
Discover remote MCP services in the network
Sourcepub async fn list_remote_mcp_tools(
&self,
peer_id: &PeerId,
) -> Result<Vec<String>>
pub async fn list_remote_mcp_tools( &self, peer_id: &PeerId, ) -> Result<Vec<String>>
List tools available on a specific remote peer
Sourcepub async fn mcp_stats(&self) -> Result<MCPServerStats>
pub async fn mcp_stats(&self) -> Result<MCPServerStats>
Get MCP server statistics
Sourcepub async fn resource_metrics(&self) -> Result<ResourceMetrics>
pub async fn resource_metrics(&self) -> Result<ResourceMetrics>
Get production resource metrics
Sourcepub async fn health_check(&self) -> Result<()>
pub async fn health_check(&self) -> Result<()>
Check system health
Sourcepub fn production_config(&self) -> Option<&ProductionConfig>
pub fn production_config(&self) -> Option<&ProductionConfig>
Get production configuration (if enabled)
Sourcepub fn is_production_mode(&self) -> bool
pub fn is_production_mode(&self) -> bool
Check if production hardening is enabled
Sourcepub async fn add_discovered_peer(
&self,
peer_id: PeerId,
addresses: Vec<String>,
) -> Result<()>
pub async fn add_discovered_peer( &self, peer_id: PeerId, addresses: Vec<String>, ) -> Result<()>
Add a discovered peer to the bootstrap cache
Sourcepub async fn update_peer_metrics(
&self,
peer_id: &PeerId,
success: bool,
latency_ms: Option<u64>,
_error: Option<String>,
) -> Result<()>
pub async fn update_peer_metrics( &self, peer_id: &PeerId, success: bool, latency_ms: Option<u64>, _error: Option<String>, ) -> Result<()>
Update connection metrics for a peer in the bootstrap cache
Sourcepub async fn get_bootstrap_cache_stats(&self) -> Result<Option<CacheStats>>
pub async fn get_bootstrap_cache_stats(&self) -> Result<Option<CacheStats>>
Get bootstrap cache statistics
Sourcepub async fn cached_peer_count(&self) -> usize
pub async fn cached_peer_count(&self) -> usize
Get the number of cached bootstrap peers