NetworkNode

Trait NetworkNode 

Source
pub trait NetworkNode {
    // Required methods
    fn local_id(&self) -> PeerId;
    fn dial(&mut self, addr: &Multiaddr) -> NetworkResult<()>;
    fn join_room(&mut self, room: &RoomId) -> NetworkResult<()>;
    fn publish_message(&mut self, data: Vec<u8>) -> NetworkResult<()>;
    fn send_message(
        &mut self,
        peer_id: &PeerId,
        data: Vec<u8>,
    ) -> NetworkResult<RequestId>;
    fn send_response(
        &mut self,
        request_id: &RequestId,
        data: Vec<u8>,
    ) -> NetworkResult<()>;
    fn dial_addrs(&self) -> Vec<Multiaddr>;
    fn bootstrap(&mut self) -> NetworkResult<()>;
    fn raw_stats(&self) -> RawStats;
    fn connected_peers(&self) -> Vec<PeerId>;
    fn is_dialing(&self, peer_id: &PeerId) -> bool;
    fn next_event(&mut self) -> impl Future<Output = Option<NetworkEvent>>;
}
Expand description

Trait implemented by every P2P backend.

Required Methods§

Source

fn local_id(&self) -> PeerId

Return the local peer/node/endpoint ID.

Source

fn dial(&mut self, addr: &Multiaddr) -> NetworkResult<()>

Dial a peer by an opaque address string (multiaddr, endpoint ticket, etc.).

Source

fn join_room(&mut self, room: &RoomId) -> NetworkResult<()>

Join a room/topic. The backend maps the room name to its internal topic mechanism.

Source

fn publish_message(&mut self, data: Vec<u8>) -> NetworkResult<()>

Publish a message to the room topic (pubsub / gossip). All room members receive this via BroadcastReceived.

Source

fn send_message( &mut self, peer_id: &PeerId, data: Vec<u8>, ) -> NetworkResult<RequestId>

Send a message to a specific peer. Returns an opaque request ID.

Source

fn send_response( &mut self, request_id: &RequestId, data: Vec<u8>, ) -> NetworkResult<()>

Respond to a received message/request.

Source

fn dial_addrs(&self) -> Vec<Multiaddr>

Get currently known dialable addresses.

Source

fn bootstrap(&mut self) -> NetworkResult<()>

Bootstrap the network (DHT, relay, etc.).

Source

fn raw_stats(&self) -> RawStats

Return raw network stats.

Source

fn connected_peers(&self) -> Vec<PeerId>

Return connected peer IDs (excluding self).

Source

fn is_dialing(&self, peer_id: &PeerId) -> bool

Return whether we have an in-flight dial to the given peer.

Source

fn next_event(&mut self) -> impl Future<Output = Option<NetworkEvent>>

Return the next network event.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§