Trait libp2prs_core::transport::Transport[][src]

pub trait Transport: Send {
    type Output;
    fn listen_on(
        &mut self,
        addr: Multiaddr
    ) -> Result<IListener<Self::Output>, TransportError>;
#[must_use] fn dial<'life0, 'async_trait>(
        &'life0 mut self,
        addr: Multiaddr
    ) -> Pin<Box<dyn Future<Output = Result<Self::Output, TransportError>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: 'async_trait
;
fn box_clone(&self) -> ITransport<Self::Output>;
fn protocols(&self) -> Vec<u32>; fn timeout(self, timeout: Duration) -> TransportTimeout<Self>
    where
        Self: Sized
, { ... }
fn outbound_timeout(self, timeout: Duration) -> TransportTimeout<Self>
    where
        Self: Sized
, { ... }
fn inbound_timeout(self, timeout: Duration) -> TransportTimeout<Self>
    where
        Self: Sized
, { ... } }

A transport provides connection-oriented communication between two peers through ordered streams of data (i.e. connections).

Connections are established either by accepting or dialing on a Transport. A peer that obtains a connection by listening is often referred to as the listener and the peer that initiated the connection through dialing as the dialer, in contrast to the traditional roles of server and client.

Most transports also provide a form of reliable delivery on the established connections but the precise semantics of these guarantees depend on the specific transport.

This trait is implemented for concrete connection-oriented transport protocols like TCP or Unix Domain Sockets, but also on wrappers that add additional functionality to the dialing or listening process (e.g. name resolution via the DNS).

Associated Types

type Output[src]

The result of a connection setup process, including protocol upgrades.

Typically the output contains at least a handle to a data stream (i.e. a connection or a substream multiplexer on top of a connection) that provides APIs for sending and receiving data through the connection.

Loading content...

Required methods

fn listen_on(
    &mut self,
    addr: Multiaddr
) -> Result<IListener<Self::Output>, TransportError>
[src]

Listens on the given Multiaddr, producing a IListener which can be used to accept new inbound connections.

Returning an error when there is underlying error in transport.

#[must_use]fn dial<'life0, 'async_trait>(
    &'life0 mut self,
    addr: Multiaddr
) -> Pin<Box<dyn Future<Output = Result<Self::Output, TransportError>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    Self: 'async_trait, 
[src]

Dials the given Multiaddr, returning a outbound connection.

If TransportError::MultiaddrNotSupported is returned, it means a wrong transport is used to dial for the address.

fn box_clone(&self) -> ITransport<Self::Output>[src]

Clones the transport and returns the trait object.

fn protocols(&self) -> Vec<u32>[src]

Returns the Multiaddr protocol supported by the transport.

In general, transport supports some concrete protocols, e.g. TCP transport for TCP. It should always be a match between the transport and the given Multiaddr to dial/listen. Otherwise, TransportError::MultiaddrNotSupported is returned.

Loading content...

Provided methods

fn timeout(self, timeout: Duration) -> TransportTimeout<Self> where
    Self: Sized
[src]

Adds a timeout to the connection setup (including upgrades) for all inbound and outbound connections established through the transport.

fn outbound_timeout(self, timeout: Duration) -> TransportTimeout<Self> where
    Self: Sized
[src]

Adds a timeout to the connection setup (including upgrades) for all outbound connections established through the transport.

fn inbound_timeout(self, timeout: Duration) -> TransportTimeout<Self> where
    Self: Sized
[src]

Adds a timeout to the connection setup (including upgrades) for all inbound connections established through the transport.

Loading content...

Implementors

impl Transport for DummyTransport[src]

type Output = DummyStream

impl Transport for MemoryTransport[src]

type Output = Channel

impl<InnerTrans> Transport for ProtectorTransport<InnerTrans> where
    InnerTrans: Transport + Clone + 'static,
    InnerTrans::Output: ConnectionInfo + SplittableReadWrite
[src]

type Output = PnetOutput<InnerTrans::Output>

impl<InnerTrans> Transport for TransportTimeout<InnerTrans> where
    InnerTrans: Transport + Clone + 'static,
    InnerTrans::Output: ConnectionInfo + 'static, 
[src]

type Output = InnerTrans::Output

fn listen_on(
    &mut self,
    addr: Multiaddr
) -> Result<IListener<Self::Output>, TransportError>
[src]

Creates a IListener with timeout parameter, which will be used for Ilistener to accept new connections.

fn dial<'life0, 'async_trait>(
    &'life0 mut self,
    addr: Multiaddr
) -> Pin<Box<dyn Future<Output = Result<Self::Output, TransportError>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    Self: 'async_trait, 
[src]

Creates a new outgoing connection, with the specified timeout parameter.

impl<InnerTrans, TMux, TSec> Transport for TransportUpgrade<InnerTrans, TMux, TSec> where
    InnerTrans: Transport + Clone + 'static,
    InnerTrans::Output: ConnectionInfo + ReadEx + WriteEx + Unpin + 'static,
    TSec: Upgrader<InnerTrans::Output> + 'static,
    TSec::Output: SecureInfo + ReadEx + WriteEx + Unpin,
    TMux: Upgrader<TSec::Output> + 'static,
    TMux::Output: StreamMuxerEx + 'static, 
[src]

type Output = IStreamMuxer

Loading content...