pub trait Network<PK: PublicKey, A: Data, D: Data>: Send + 'static {
    // Required methods
    fn add_connection(&mut self, peer: PK, address: A);
    fn remove_connection(&mut self, peer: PK);
    fn send(&self, data: D, recipient: PK);
    fn next<'life0, 'async_trait>(
        &'life0 mut self
    ) -> Pin<Box<dyn Future<Output = Option<D>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Network represents an interface for opening and closing connections with other nodes, and sending direct messages between them.

Note on Network reliability and security: it is neither assumed that the sent messages must be always delivered, nor the established connections must be secure in any way. The Network implementation might fail to deliver any specific message, so messages have to be resent while they still should be delivered.

Required Methods§

source

fn add_connection(&mut self, peer: PK, address: A)

Add the peer to the set of connected peers.

source

fn remove_connection(&mut self, peer: PK)

Remove the peer from the set of connected peers and close the connection.

source

fn send(&self, data: D, recipient: PK)

Send a message to a single peer. This function should be implemented in a non-blocking manner.

source

fn next<'life0, 'async_trait>( &'life0 mut self ) -> Pin<Box<dyn Future<Output = Option<D>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Receive a message from the network. This method’s implementation must be cancellation safe.

Implementors§