pub struct NetworkManager { /* private fields */ }Expand description
The user-facing API for the networking stack.
NetworkManager ties together all five layers (identity, transport,
routing, discovery, application) and provides a simple interface for
sending messages, discovering peers, and subscribing to network events.
§Example
let manager = NetworkManagerBuilder::new(my_identity)
.add_transport(IpcTransport::new(None))
.with_discovery(ManualDiscovery::new())
.build();
manager.send(peer_id, "hello").await?;
let mut events = manager.subscribe();
while let Ok(event) = events.recv().await {
// handle events
}Implementations§
Source§impl NetworkManager
impl NetworkManager
Sourcepub fn identity(&self) -> &AgentIdentity
pub fn identity(&self) -> &AgentIdentity
Get this agent’s identity.
Sourcepub fn subscribe(&self) -> Receiver<NetworkEvent>
pub fn subscribe(&self) -> Receiver<NetworkEvent>
Subscribe to network events.
Sourcepub async fn peer_table(&self) -> RwLockReadGuard<'_, PeerTable>
pub async fn peer_table(&self) -> RwLockReadGuard<'_, PeerTable>
Get a read lock on the peer table.
Sourcepub async fn peer_table_mut(&self) -> RwLockWriteGuard<'_, PeerTable>
pub async fn peer_table_mut(&self) -> RwLockWriteGuard<'_, PeerTable>
Get a write lock on the peer table.
Sourcepub async fn peers(&self) -> Vec<AgentIdentity>
pub async fn peers(&self) -> Vec<AgentIdentity>
List all known peers.
Sourcepub async fn send(
&self,
target: Uuid,
payload: impl Into<Payload>,
) -> Result<()>
pub async fn send( &self, target: Uuid, payload: impl Into<Payload>, ) -> Result<()>
Send a message to a specific peer.
Sourcepub async fn broadcast(&self, payload: impl Into<Payload>) -> Result<()>
pub async fn broadcast(&self, payload: impl Into<Payload>) -> Result<()>
Broadcast a message to all known peers.
Sourcepub async fn publish(
&self,
topic: impl Into<String>,
payload: impl Into<Payload>,
) -> Result<()>
pub async fn publish( &self, topic: impl Into<String>, payload: impl Into<Payload>, ) -> Result<()>
Publish a message to a topic.
Sourcepub async fn send_envelope(&self, envelope: MessageEnvelope) -> Result<()>
pub async fn send_envelope(&self, envelope: MessageEnvelope) -> Result<()>
Send a pre-built envelope.
Sourcepub fn add_transport(&mut self, transport: Box<dyn Transport>)
pub fn add_transport(&mut self, transport: Box<dyn Transport>)
Add a transport to the manager.
Sourcepub fn set_custom_router(&mut self, router: Box<dyn Router>)
pub fn set_custom_router(&mut self, router: Box<dyn Router>)
Set a custom router (overrides the default direct router for point-to-point messages).
Sourcepub fn add_discovery(&mut self, discovery: Box<dyn Discovery>)
pub fn add_discovery(&mut self, discovery: Box<dyn Discovery>)
Add a discovery service.
Sourcepub async fn register_self(&self) -> Result<()>
pub async fn register_self(&self) -> Result<()>
Register this agent with all discovery services.
Sourcepub async fn deregister_self(&self) -> Result<()>
pub async fn deregister_self(&self) -> Result<()>
Deregister this agent from all discovery services.
Sourcepub async fn discover_peers(&self) -> Result<Vec<AgentIdentity>>
pub async fn discover_peers(&self) -> Result<Vec<AgentIdentity>>
Run discovery across all services and update the peer table.
Sourcepub fn emit(&self, event: NetworkEvent)
pub fn emit(&self, event: NetworkEvent)
Emit a network event.