Type Alias libp2p::tcp::tokio::Transport

source ·
pub type Transport = Transport<Tcp>;
Expand description

A TCP Transport that works with the tokio ecosystem.

§Example

let mut transport = tcp::tokio::Transport::new(tcp::Config::default());
let id = transport.listen_on(ListenerId::next(), "/ip4/127.0.0.1/tcp/0".parse().unwrap()).unwrap();

let addr = future::poll_fn(|cx| Pin::new(&mut transport).poll(cx)).await.into_new_address().unwrap();

println!("Listening on {addr}");

Aliased Type§

struct Transport { /* private fields */ }

Implementations

source§

impl<T> Transport<T>
where T: Provider + Send,

source

pub fn new(config: Config) -> Transport<T>

Create a new instance of Transport.

If you don’t want to specify a Config, use Transport::default.

It is best to call this function through one of the type-aliases of this type:

Trait Implementations

source§

impl<T> Default for Transport<T>
where T: Provider + Send,

source§

fn default() -> Transport<T>

Creates a Transport with reasonable defaults.

This transport will have port-reuse disabled.

source§

impl<T> Transport for Transport<T>
where T: Provider + Send + 'static, <T as Provider>::Listener: Unpin, <T as Provider>::Stream: Unpin,

source§

fn address_translation( &self, listen: &Multiaddr, observed: &Multiaddr, ) -> Option<Multiaddr>

When port reuse is disabled and hence ephemeral local ports are used for outgoing connections, the returned address is the observed address with the port replaced by the port of the listen address.

If port reuse is enabled, Some(observed) is returned, as there is a chance that the observed address and port are reachable for other peers if there is a NAT in the way that does endpoint- independent filtering. Furthermore, even if that is not the case and TCP hole punching techniques must be used for NAT traversal, the observed address is still the one that a remote should connect to for the purpose of the hole punching procedure, as it represents the mapped IP and port of the NAT device in front of the local node.

None is returned if one of the given addresses is not a TCP/IP address.

source§

fn poll( self: Pin<&mut Transport<T>>, cx: &mut Context<'_>, ) -> Poll<TransportEvent<<Transport<T> as Transport>::ListenerUpgrade, <Transport<T> as Transport>::Error>>

Poll all listeners.

§

type Output = <T as Provider>::Stream

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

type Error = Error

An error that occurred during connection setup.
§

type Dial = Pin<Box<dyn Future<Output = Result<<Transport<T> as Transport>::Output, <Transport<T> as Transport>::Error>> + Send>>

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

type ListenerUpgrade = Ready<Result<<Transport<T> as Transport>::Output, <Transport<T> as Transport>::Error>>

A pending Output for an inbound connection, obtained from the Transport stream. Read more
source§

fn listen_on( &mut self, id: ListenerId, addr: Multiaddr, ) -> Result<(), TransportError<<Transport<T> as Transport>::Error>>

Listens on the given Multiaddr for inbound connections with a provided ListenerId.
source§

fn remove_listener(&mut self, id: ListenerId) -> bool

Remove a listener. Read more
source§

fn dial( &mut self, addr: Multiaddr, ) -> Result<<Transport<T> as Transport>::Dial, TransportError<<Transport<T> as Transport>::Error>>

Dials the given Multiaddr, returning a future for a pending outbound connection. Read more
source§

fn dial_as_listener( &mut self, addr: Multiaddr, ) -> Result<<Transport<T> as Transport>::Dial, TransportError<<Transport<T> as Transport>::Error>>

As Transport::dial but has the local node act as a listener on the outgoing connection. Read more
source§

fn map<F, O>(self, f: F) -> Map<Self, F>
where Self: Sized, F: FnOnce(Self::Output, ConnectedPoint) -> O,

Applies a function on the connections created by the transport.
source§

fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
where Self: Sized, F: FnOnce(Self::Error) -> E,

Applies a function on the errors generated by the futures of the transport.
source§

fn or_transport<U>(self, other: U) -> OrTransport<Self, U>
where 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. Read more
source§

fn and_then<C, F, O>(self, f: C) -> AndThen<Self, C>
where Self: Sized, C: FnOnce(Self::Output, ConnectedPoint) -> F, F: TryFuture<Ok = O>, <F as TryFuture>::Error: Error + 'static,

Applies a function producing an asynchronous result to every connection created by this transport. Read more
source§

fn upgrade(self, version: Version) -> Builder<Self>
where Self: Sized, Self::Error: 'static,

Begins a series of protocol upgrades via an upgrade::Builder.