Trait fedimint_core::net::peers::IPeerConnections

source ·
pub trait IPeerConnections<Msg>{
    // Required methods
    fn send<'life0, 'life1, 'async_trait>(
        &'life0 mut self,
        peers: &'life1 [PeerId],
        msg: Msg,
    ) -> Pin<Box<dyn Future<Output = Cancellable<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn receive<'life0, 'async_trait>(
        &'life0 mut self,
    ) -> Pin<Box<dyn Future<Output = Cancellable<(PeerId, Msg)>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn ban_peer<'life0, 'async_trait>(
        &'life0 mut self,
        peer: PeerId,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn into_dyn(self) -> PeerConnections<Msg>
       where Self: Sized + Send + Unpin + 'static { ... }
}
Expand description

Connection manager that tries to keep connections open to all peers

Production implementations of this trait have to ensure that:

  • Connections to peers are authenticated and encrypted
  • Messages are received exactly once and in the order they were sent
  • Connections are reopened when closed
  • Messages are cached in case of short-lived network interruptions and resent on reconnect, this avoids the need to rejoin the consensus, which is more tricky.

In case of longer term interruptions the message cache has to be dropped to avoid DoS attacks. The thus disconnected peer will need to rejoin the consensus at a later time.

Required Methods§

source

fn send<'life0, 'life1, 'async_trait>( &'life0 mut self, peers: &'life1 [PeerId], msg: Msg, ) -> Pin<Box<dyn Future<Output = Cancellable<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Send a message to a specific peer.

The message is sent immediately and cached if the peer is reachable and only cached otherwise.

source

fn receive<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Cancellable<(PeerId, Msg)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Await receipt of a message from any connected peer.

source

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

Removes a peer connection in case of misbehavior

Provided Methods§

source

fn into_dyn(self) -> PeerConnections<Msg>
where Self: Sized + Send + Unpin + 'static,

Converts the struct to a PeerConnection trait object

Implementors§