Trait tor_rtcompat::TcpProvider

source ·
pub trait TcpProvider: Clone + Send + Sync + 'static {
    type TcpStream: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static;
    type TcpListener: TcpListener<TcpStream = Self::TcpStream> + Send + Sync + Unpin + 'static;

    // Required methods
    fn connect<'life0, 'life1, 'async_trait>(
        &'life0 self,
        addr: &'life1 SocketAddr,
    ) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpStream>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn listen<'life0, 'life1, 'async_trait>(
        &'life0 self,
        addr: &'life1 SocketAddr,
    ) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpListener>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

Trait for a runtime that can create and accept TCP connections.

(In Arti we use the [AsyncRead] and [AsyncWrite] traits from [futures::io] as more standard, even though the ones from Tokio can be a bit more efficient. Let’s hope that they converge in the future.)

Required Associated Types§

source

type TcpStream: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static

The type for the TCP connections returned by Self::connect().

source

type TcpListener: TcpListener<TcpStream = Self::TcpStream> + Send + Sync + Unpin + 'static

The type for the TCP listeners returned by Self::listen().

Required Methods§

source

fn connect<'life0, 'life1, 'async_trait>( &'life0 self, addr: &'life1 SocketAddr, ) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpStream>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Launch a TCP connection to a given socket address.

Note that unlike std::net:TcpStream::connect, we do not accept any types other than a single SocketAddr. We do this because, as a Tor implementation, we most be absolutely sure not to perform unnecessary DNS lookups.

source

fn listen<'life0, 'life1, 'async_trait>( &'life0 self, addr: &'life1 SocketAddr, ) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpListener>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Open a TCP listener on a given socket address.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl TcpProvider for AsyncStd

Available on (crate features native-tls or rustls) and (crate features async-std or tokio) and crate feature async-std only.
§

type TcpStream = TcpStream

§

type TcpListener = TcpListener

source§

fn connect<'life0, 'life1, 'async_trait>( &'life0 self, addr: &'life1 SocketAddr, ) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpStream>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

source§

fn listen<'life0, 'life1, 'async_trait>( &'life0 self, addr: &'life1 SocketAddr, ) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpListener>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Implementors§

source§

impl TcpProvider for AsyncStdNativeTlsRuntime

Available on (crate features native-tls or rustls) and crate feature async-std only.
source§

impl TcpProvider for AsyncStdRustlsRuntime

Available on (crate features native-tls or rustls) and crate feature async-std only.
source§

impl TcpProvider for PreferredRuntime

source§

impl TcpProvider for TokioNativeTlsRuntime

Available on (crate features native-tls or rustls) and crate feature tokio only.
§

type TcpStream = <CompoundRuntime<TokioRuntimeHandle, TokioRuntimeHandle, RealCoarseTimeProvider, TokioRuntimeHandle, NativeTlsProvider, TokioRuntimeHandle> as TcpProvider>::TcpStream

§

type TcpListener = <CompoundRuntime<TokioRuntimeHandle, TokioRuntimeHandle, RealCoarseTimeProvider, TokioRuntimeHandle, NativeTlsProvider, TokioRuntimeHandle> as TcpProvider>::TcpListener

source§

impl TcpProvider for TokioRustlsRuntime

Available on (crate features native-tls or rustls) and crate feature tokio only.
§

type TcpStream = <CompoundRuntime<TokioRuntimeHandle, TokioRuntimeHandle, RealCoarseTimeProvider, TokioRuntimeHandle, RustlsProvider, TokioRuntimeHandle> as TcpProvider>::TcpStream

§

type TcpListener = <CompoundRuntime<TokioRuntimeHandle, TokioRuntimeHandle, RealCoarseTimeProvider, TokioRuntimeHandle, RustlsProvider, TokioRuntimeHandle> as TcpProvider>::TcpListener

source§

impl<SpawnR, SleepR, CoarseTimeR, TcpR, TlsR, UdpR> TcpProvider for CompoundRuntime<SpawnR, SleepR, CoarseTimeR, TcpR, TlsR, UdpR>
where TcpR: TcpProvider + Send + Sync + 'static, SpawnR: Send + Sync + 'static, SleepR: Send + Sync + 'static, CoarseTimeR: Send + Sync + 'static, TlsR: Send + Sync + 'static, UdpR: Send + Sync + 'static,