Skip to main content

IP2PConnection

Trait IP2PConnection 

Source
pub trait IP2PConnection<M>:
    Send
    + Sync
    + 'static {
    // Required methods
    fn send<'life0, 'async_trait>(
        &'life0 self,
        message: M,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn receive<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<DynIP2PFrame<M>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn rtt(&self) -> Option<Duration>;

    // Provided methods
    fn connection_type(&self) -> Option<ConnectionType> { ... }
    fn connection_status_updates(&self) -> Option<DynConnectionStatusUpdates> { ... }
    fn into_dyn(self) -> DynP2PConnection<M>
       where Self: Sized { ... }
}

Required Methods§

Source

fn send<'life0, 'async_trait>( &'life0 self, message: M, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Send a message over the connection. This is not required to be cancel-safe.

Takes &self so that the send and receive halves can be driven concurrently. A send parked on transport flow control must never stop the peer’s stream from being drained, or two peers that are both sending an oversized message deadlock permanently.

While send and receive may run concurrently with each other, each of them must have at most one caller at a time: a second concurrent receive would steal frames from the first and silently reorder the message stream.

Source

fn receive<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<DynIP2PFrame<M>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Receive a p2p frame from the connection. This is required to be cancel-safe. See Self::send for the concurrency contract.

Source

fn rtt(&self) -> Option<Duration>

Get the round-trip time of the connection.

Provided Methods§

Source

fn connection_type(&self) -> Option<ConnectionType>

Get the transport type currently backing this live connection.

Source

fn connection_status_updates(&self) -> Option<DynConnectionStatusUpdates>

Subscribe to notifications that the live connection metadata may have changed.

Implementations should treat these as wake-ups only. The state machine reads a fresh Self::connection_type and Self::rtt snapshot after each notification. None means notifications are unsupported, while the end of a returned stream means there will be no more notifications.

Source

fn into_dyn(self) -> DynP2PConnection<M>
where Self: Sized,

Implementations on Foreign Types§

Source§

impl<M> IP2PConnection<M> for Connection
where M: Encodable + Decodable + Serialize + DeserializeOwned + Send + 'static,

Source§

fn send<'life0, 'async_trait>( &'life0 self, message: M, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn receive<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<DynIP2PFrame<M>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn rtt(&self) -> Option<Duration>

Source§

impl<M> IP2PConnection<M> for Connection
where M: Encodable + Decodable + Serialize + DeserializeOwned + Send + 'static,

Source§

fn send<'life0, 'async_trait>( &'life0 self, message: M, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn receive<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<DynIP2PFrame<M>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source§

fn rtt(&self) -> Option<Duration>

Source§

fn connection_type(&self) -> Option<ConnectionType>

Source§

fn connection_status_updates(&self) -> Option<DynConnectionStatusUpdates>

Implementors§