Trait libp2p_core::transport::Transport [−][src]
A transport provides connection-oriented communication between two peers through ordered streams of data (i.e. connections).
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, 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).
Additional protocols can be layered on top of the connections established
by a Transport
through an upgrade mechanism that is initiated via
upgrade
.
Note: The methods of this trait use
self
and not&self
or&mut self
. In other words, listening or dialing consumes the transport object. This has been designed so that you would implement this trait on&Foo
or&mut Foo
instead of directly onFoo
.
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.
type Error: Error
[src]
An error that occurred during connection setup.
type Listener: Stream<Item = Result<ListenerEvent<Self::ListenerUpgrade, Self::Error>, Self::Error>>
[src]
A stream of Output
s for inbound connections.
An item should be produced whenever a connection is received at the lowest level of the
transport stack. The item must be a ListenerUpgrade
future
that resolves to an Output
value once all protocol upgrades
have been applied.
If this stream produces an error, it is considered fatal and the listener is killed. It
is possible to report non-fatal errors by producing a ListenerEvent::Error
.
type ListenerUpgrade: Future<Output = Result<Self::Output, Self::Error>>
[src]
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 ListenerUpgrade
future resolves it yields the Output
of the connection setup process.
type Dial: Future<Output = Result<Self::Output, Self::Error>>
[src]
Required methods
fn listen_on(
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>> where
Self: Sized,
[src]
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>> where
Self: Sized,
Listens on the given Multiaddr
, producing a stream of pending, inbound connections
and addresses this transport is listening on (cf. ListenerEvent
).
Returning an error from the stream is considered fatal. The listener can also report
non-fatal errors by producing a ListenerEvent::Error
.
fn dial(
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>> where
Self: Sized,
[src]
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>> where
Self: Sized,
Dials the given Multiaddr
, returning a future for a pending outbound connection.
If TransportError::MultiaddrNotSupported
is returned, it may be desirable to
try an alternative Transport
, if available.
fn address_translation(
&self,
listen: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
[src]
&self,
listen: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
Performs a transport-specific mapping of an address observed
by
a remote onto a local listen
address to yield an address for
the local node that may be reachable for other peers.
Provided methods
fn boxed(self) -> Boxed<Self::Output> where
Self: Transport + Sized + Clone + Send + Sync + 'static,
Self::Dial: Send + 'static,
Self::Listener: Send + 'static,
Self::ListenerUpgrade: Send + 'static,
Self::Error: Send + Sync,
[src]
Self: Transport + Sized + Clone + Send + Sync + 'static,
Self::Dial: Send + 'static,
Self::Listener: Send + 'static,
Self::ListenerUpgrade: Send + 'static,
Self::Error: Send + Sync,
Boxes the transport, including custom transport errors.
fn map<F, O>(self, f: F) -> Map<Self, F> where
Self: Sized,
F: FnOnce(Self::Output, ConnectedPoint) -> O + Clone,
[src]
Self: Sized,
F: FnOnce(Self::Output, ConnectedPoint) -> O + Clone,
Applies a function on the connections created by the transport.
fn map_err<F, E>(self, f: F) -> MapErr<Self, F> where
Self: Sized,
F: FnOnce(Self::Error) -> E + Clone,
[src]
Self: Sized,
F: FnOnce(Self::Error) -> E + Clone,
Applies a function on the errors generated by the futures of the transport.
fn or_transport<U>(self, other: U) -> OrTransport<Self, U> where
Self: Sized,
U: Transport,
<U as Transport>::Error: 'static,
[src]
Self: Sized,
U: Transport,
<U as Transport>::Error: 'static,
Adds a fallback transport that is used when encountering errors while establishing inbound or outbound connections.
The returned transport will act like self
, except that if listen_on
or dial
return an error then other
will be tried.
fn and_then<C, F, O>(self, f: C) -> AndThen<Self, C> where
Self: Sized,
C: FnOnce(Self::Output, ConnectedPoint) -> F + Clone,
F: TryFuture<Ok = O>,
<F as TryFuture>::Error: Error + 'static,
[src]
Self: Sized,
C: FnOnce(Self::Output, ConnectedPoint) -> F + Clone,
F: TryFuture<Ok = O>,
<F as TryFuture>::Error: Error + 'static,
Applies a function producing an asynchronous result to every connection created by this transport.
This function can be used for ad-hoc protocol upgrades or for processing or adapting the output for following configurations.
For the high-level transport upgrade procedure, see Transport::upgrade
.
fn upgrade(self, version: Version) -> Builder<Self> where
Self: Sized,
Self::Error: 'static,
[src]
Self: Sized,
Self::Error: 'static,
Begins a series of protocol upgrades via an
upgrade::Builder
.
Implementors
impl Transport for MemoryTransport
[src]
type Output = Channel<Vec<u8>>
type Error = MemoryTransportError
type Listener = Listener
type ListenerUpgrade = Ready<Result<Self::Output, Self::Error>>
type Dial = DialFuture
fn listen_on(
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
fn dial(
self,
addr: Multiaddr
) -> Result<DialFuture, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<DialFuture, TransportError<Self::Error>>
fn address_translation(
&self,
_server: &Multiaddr,
_observed: &Multiaddr
) -> Option<Multiaddr>
[src]
&self,
_server: &Multiaddr,
_observed: &Multiaddr
) -> Option<Multiaddr>
impl<A, B> Transport for EitherTransport<A, B> where
B: Transport,
A: Transport,
[src]
B: Transport,
A: Transport,
type Output = EitherOutput<A::Output, B::Output>
type Error = EitherError<A::Error, B::Error>
type Listener = EitherListenStream<A::Listener, B::Listener>
type ListenerUpgrade = EitherFuture<A::ListenerUpgrade, B::ListenerUpgrade>
type Dial = EitherFuture<A::Dial, B::Dial>
fn listen_on(
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
fn dial(
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
fn address_translation(
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
[src]
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
impl<A, B> Transport for OrTransport<A, B> where
B: Transport,
A: Transport,
[src]
B: Transport,
A: Transport,
type Output = EitherOutput<A::Output, B::Output>
type Error = EitherError<A::Error, B::Error>
type Listener = EitherListenStream<A::Listener, B::Listener>
type ListenerUpgrade = EitherFuture<A::ListenerUpgrade, B::ListenerUpgrade>
type Dial = EitherFuture<A::Dial, B::Dial>
fn listen_on(
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
fn dial(
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
fn address_translation(
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
[src]
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
impl<InnerTrans> Transport for TransportTimeout<InnerTrans> where
InnerTrans: Transport,
InnerTrans::Error: 'static,
[src]
InnerTrans: Transport,
InnerTrans::Error: 'static,
type Output = InnerTrans::Output
type Error = TransportTimeoutError<InnerTrans::Error>
type Listener = TimeoutListener<InnerTrans::Listener>
type ListenerUpgrade = Timeout<InnerTrans::ListenerUpgrade>
type Dial = Timeout<InnerTrans::Dial>
fn listen_on(
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
fn dial(
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
fn address_translation(
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
[src]
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
impl<O> Transport for Boxed<O>
[src]
type Output = O
type Error = Error
type Listener = Pin<Box<dyn Stream<Item = Result<ListenerEvent<Pin<Box<dyn Future<Output = Result<O>> + Send>>, Error>>> + Send>>
type ListenerUpgrade = Pin<Box<dyn Future<Output = Result<O>> + Send>>
type Dial = Pin<Box<dyn Future<Output = Result<O>> + Send>>
fn listen_on(
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
fn dial(
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
fn address_translation(
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
[src]
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
impl<T> Transport for OptionalTransport<T> where
T: Transport,
[src]
T: Transport,
type Output = T::Output
type Error = T::Error
type Listener = T::Listener
type ListenerUpgrade = T::ListenerUpgrade
type Dial = T::Dial
fn listen_on(
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
fn dial(
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
fn address_translation(
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
[src]
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
impl<T> Transport for Multiplexed<T> where
T: Transport,
[src]
T: Transport,
type Output = T::Output
type Error = T::Error
type Listener = T::Listener
type ListenerUpgrade = T::ListenerUpgrade
type Dial = T::Dial
fn dial(
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
fn listen_on(
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
fn address_translation(
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
[src]
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
impl<T, C, D, U, E> Transport for Upgrade<T, U> where
T: Transport<Output = (PeerId, C)>,
T::Error: 'static,
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<Negotiated<C>, Output = D, Error = E>,
U: OutboundUpgrade<Negotiated<C>, Output = D, Error = E> + Clone,
E: Error + 'static,
[src]
T: Transport<Output = (PeerId, C)>,
T::Error: 'static,
C: AsyncRead + AsyncWrite + Unpin,
U: InboundUpgrade<Negotiated<C>, Output = D, Error = E>,
U: OutboundUpgrade<Negotiated<C>, Output = D, Error = E> + Clone,
E: Error + 'static,
type Output = (PeerId, D)
type Error = TransportUpgradeError<T::Error, E>
type Listener = ListenerStream<T::Listener, U>
type ListenerUpgrade = ListenerUpgradeFuture<T::ListenerUpgrade, U, C>
type Dial = DialUpgradeFuture<T::Dial, U, C>
fn dial(
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
fn listen_on(
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
fn address_translation(
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
[src]
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
impl<T, C, F, O> Transport for AndThen<T, C> where
T: Transport,
C: FnOnce(T::Output, ConnectedPoint) -> F + Clone,
F: TryFuture<Ok = O>,
F::Error: Error,
[src]
T: Transport,
C: FnOnce(T::Output, ConnectedPoint) -> F + Clone,
F: TryFuture<Ok = O>,
F::Error: Error,
type Output = O
type Error = EitherError<T::Error, F::Error>
type Listener = AndThenStream<T::Listener, C>
type ListenerUpgrade = AndThenFuture<T::ListenerUpgrade, C, F>
type Dial = AndThenFuture<T::Dial, C, F>
fn listen_on(
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
fn dial(
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
fn address_translation(
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
[src]
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
impl<T, F, D> Transport for Map<T, F> where
T: Transport,
F: FnOnce(T::Output, ConnectedPoint) -> D + Clone,
[src]
T: Transport,
F: FnOnce(T::Output, ConnectedPoint) -> D + Clone,
type Output = D
type Error = T::Error
type Listener = MapStream<T::Listener, F>
type ListenerUpgrade = MapFuture<T::ListenerUpgrade, F>
type Dial = MapFuture<T::Dial, F>
fn listen_on(
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
fn dial(
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
fn address_translation(
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
[src]
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
impl<T, F, TErr> Transport for MapErr<T, F> where
T: Transport,
F: FnOnce(T::Error) -> TErr + Clone,
TErr: Error,
[src]
T: Transport,
F: FnOnce(T::Error) -> TErr + Clone,
TErr: Error,
type Output = T::Output
type Error = TErr
type Listener = MapErrListener<T, F>
type ListenerUpgrade = MapErrListenerUpgrade<T, F>
type Dial = MapErrDial<T, F>
fn listen_on(
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
fn dial(
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
fn address_translation(
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
[src]
&self,
server: &Multiaddr,
observed: &Multiaddr
) -> Option<Multiaddr>
impl<TOut> Transport for DummyTransport<TOut>
[src]
type Output = TOut
type Error = Error
type Listener = Pending<Result<ListenerEvent<Self::ListenerUpgrade, Self::Error>, Self::Error>>
type ListenerUpgrade = Pending<Result<Self::Output, Error>>
type Dial = Pending<Result<Self::Output, Error>>
fn listen_on(
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Listener, TransportError<Self::Error>>
fn dial(
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
[src]
self,
addr: Multiaddr
) -> Result<Self::Dial, TransportError<Self::Error>>
fn address_translation(
&self,
_server: &Multiaddr,
_observed: &Multiaddr
) -> Option<Multiaddr>
[src]
&self,
_server: &Multiaddr,
_observed: &Multiaddr
) -> Option<Multiaddr>