pub trait Transport {
    type Output;
    type Error: Error + Send + Sync + 'static;
    type Listener: Stream<Item = Result<(Self::Inbound, NetworkAddress), Self::Error>> + Send + Unpin;
    type Inbound: Future<Output = Result<Self::Output, Self::Error>> + Send;
    type Outbound: Future<Output = Result<Self::Output, Self::Error>> + Send;

    // Required methods
    fn listen_on(
        &self,
        addr: NetworkAddress
    ) -> Result<(Self::Listener, NetworkAddress), Self::Error>
       where Self: Sized;
    fn dial(
        &self,
        peer_id: PeerId,
        addr: NetworkAddress
    ) -> Result<Self::Outbound, Self::Error>
       where Self: Sized;
}
Expand description

A Transport is responsible for establishing connections with remote Peers.

Connections are established either by listening 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.

Additional protocols can be layered on top of the connections established by a Transport through utilizing the combinators in the TransportExt trait.

Required Associated Types§

source

type Output

The result of establishing a connection.

Generally this would include a socket-like streams which allows for sending and receiving of data through the connection.

source

type Error: Error + Send + Sync + 'static

The Error type of errors which can happen while establishing a connection.

source

type Listener: Stream<Item = Result<(Self::Inbound, NetworkAddress), Self::Error>> + Send + Unpin

A stream of Inbound connections and the address of the dialer.

An item should be produced whenever a connection is received at the lowest level of the transport stack. Each item is an Inbound future that resolves to an Output value once all protocol upgrades have been applied.

source

type Inbound: Future<Output = Result<Self::Output, Self::Error>> + Send

A pending Output for an inbound connection, obtained from the Listener stream.

After a connection has been accepted by the transport, it may need to go through asynchronous post-processing (i.e. protocol upgrade negotiations). Such post-processing should not block the Listener from producing the next connection, hence further connection setup proceeds asynchronously. Once a Inbound future resolves it yields the Output of the connection setup process.

source

type Outbound: Future<Output = Result<Self::Output, Self::Error>> + Send

A pending Output for an outbound connection, obtained from dialing stream.

Required Methods§

source

fn listen_on( &self, addr: NetworkAddress ) -> Result<(Self::Listener, NetworkAddress), Self::Error>where Self: Sized,

Listens on the given [NetworkAddress], returning a stream of incoming connections.

The returned [NetworkAddress] is the actual listening address, this is done to take into account OS-assigned port numbers (e.g. listening on port 0).

source

fn dial( &self, peer_id: PeerId, addr: NetworkAddress ) -> Result<Self::Outbound, Self::Error>where Self: Sized,

Dials the given [NetworkAddress], returning a future for a pending outbound connection.

Implementors§

source§

impl Transport for MemoryTransport

source§

impl Transport for TcpTransport

source§

impl<O, E> Transport for BoxedTransport<O, E>where E: Error + Send + Sync + 'static,

§

type Output = O

§

type Error = E

§

type Listener = Pin<Box<dyn Stream<Item = Result<(Pin<Box<dyn Future<Output = Result<O, E>> + Send + 'static, Global>>, NetworkAddress), E>> + Send + 'static, Global>>

§

type Inbound = Pin<Box<dyn Future<Output = Result<O, E>> + Send + 'static, Global>>

§

type Outbound = Pin<Box<dyn Future<Output = Result<O, E>> + Send + 'static, Global>>

source§

impl<T, F, Fut, O> Transport for AndThen<T, F>where T: Transport, F: FnOnce(T::Output, NetworkAddress, ConnectionOrigin) -> Fut + Send + Unpin + Clone, Fut: Future<Output = Result<O, T::Error>> + Send,

§

type Output = O

§

type Error = <T as Transport>::Error

§

type Listener = AndThenStream<<T as Transport>::Listener, F>

§

type Inbound = AndThenFuture<<T as Transport>::Inbound, Fut, F>

§

type Outbound = AndThenFuture<<T as Transport>::Outbound, Fut, F>