Trait libp2p_rs::core::Transport[][src]

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

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

pub fn listen_on(
    &mut self,
    addr: Multiaddr
) -> Result<Box<dyn TransportListener<Output = Self::Output> + 'static + Send, Global>, 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]
pub fn dial<'life0, 'async_trait>(
    &'life0 mut self,
    addr: Multiaddr
) -> Pin<Box<dyn Future<Output = Result<Self::Output, TransportError>> + 'async_trait + Send, Global>> 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.

pub fn box_clone(
    &self
) -> Box<dyn Transport<Output = Self::Output> + 'static + Send, Global>
[src]

Clones the transport and returns the trait object.

pub fn protocols(&self) -> Vec<u32, Global>[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

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

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

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

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

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

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

Loading content...

Implementors

impl Transport for TcpConfig[src]

type Output = TcpTransStream

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 as Transport>::Output: ConnectionInfo,
    <InnerTrans as Transport>::Output: AsyncRead,
    <InnerTrans as Transport>::Output: AsyncWrite,
    <InnerTrans as Transport>::Output: Send,
    <InnerTrans as Transport>::Output: Unpin,
    <InnerTrans as Transport>::Output: 'static, 
[src]

type Output = PnetStream<<InnerTrans as Transport>::Output>

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

type Output = <InnerTrans as Transport>::Output

pub fn listen_on(
    &mut self,
    addr: Multiaddr
) -> Result<Box<dyn TransportListener<Output = <TransportTimeout<InnerTrans> as Transport>::Output> + 'static + Send, Global>, TransportError>
[src]

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

pub fn dial<'life0, 'async_trait>(
    &'life0 mut self,
    addr: Multiaddr
) -> Pin<Box<dyn Future<Output = Result<<TransportTimeout<InnerTrans> as Transport>::Output, TransportError>> + 'async_trait + Send, Global>> where
    'life0: 'async_trait,
    TransportTimeout<InnerTrans>: '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,
    TMux: Upgrader<<TSec as Upgrader<<InnerTrans as Transport>::Output>>::Output> + 'static,
    TSec: Upgrader<<InnerTrans as Transport>::Output> + 'static,
    <InnerTrans as Transport>::Output: ConnectionInfo,
    <InnerTrans as Transport>::Output: AsyncRead,
    <InnerTrans as Transport>::Output: AsyncWrite,
    <InnerTrans as Transport>::Output: Unpin,
    <InnerTrans as Transport>::Output: 'static,
    <TSec as Upgrader<<InnerTrans as Transport>::Output>>::Output: SecureInfo,
    <TSec as Upgrader<<InnerTrans as Transport>::Output>>::Output: AsyncRead,
    <TSec as Upgrader<<InnerTrans as Transport>::Output>>::Output: AsyncWrite,
    <TSec as Upgrader<<InnerTrans as Transport>::Output>>::Output: Unpin,
    <TMux as Upgrader<<TSec as Upgrader<<InnerTrans as Transport>::Output>>::Output>>::Output: StreamMuxerEx,
    <TMux as Upgrader<<TSec as Upgrader<<InnerTrans as Transport>::Output>>::Output>>::Output: 'static, 
[src]

type Output = Box<dyn StreamMuxerEx + 'static, Global>

impl<T> Transport for DnsConfig<T> where
    T: Transport + Clone + 'static, 
[src]

type Output = <T as Transport>::Output

Loading content...