Trait netcore::transport::Transport [−][src]
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;
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.
Associated Types
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.
The Error type of errors which can happen while establishing a connection.
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.
Required methods
fn listen_on(
&self,
addr: NetworkAddress
) -> Result<(Self::Listener, NetworkAddress), Self::Error> where
Self: Sized,
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).
Dials the given NetworkAddress, returning a future for a pending outbound connection.