tor_rtcompat

Trait NetStreamProvider

source
pub trait NetStreamProvider<ADDR = SocketAddr>:
    Clone
    + Send
    + Sync
    + 'static {
    type Stream: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static;
    type Listener: NetStreamListener<ADDR, Stream = Self::Stream> + Send + Sync + Unpin + 'static;

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

Trait for a runtime that can create and accept connections over network sockets.

(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 Stream: AsyncRead + AsyncWrite + Send + Sync + Unpin + 'static

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

source

type Listener: NetStreamListener<ADDR, Stream = Self::Stream> + Send + Sync + Unpin + 'static

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

Required Methods§

source

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

Launch a connection connection to a given socket address.

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

source

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

Open a listener on a given socket address.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl NetStreamProvider for AsyncStd

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

type Stream = TcpStream

source§

type Listener = TcpListener

source§

fn connect<'life0, 'life1, 'async_trait>( &'life0 self, addr: &'life1 SocketAddr, ) -> Pin<Box<dyn Future<Output = IoResult<Self::Stream>> + 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::Listener>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

source§

impl NetStreamProvider<SocketAddr> for AsyncStd

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

type Stream = UnixStream

source§

type Listener = UnixListener

source§

fn connect<'life0, 'life1, 'async_trait>( &'life0 self, addr: &'life1 SocketAddr, ) -> Pin<Box<dyn Future<Output = IoResult<Self::Stream>> + 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::Listener>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Implementors§

source§

impl NetStreamProvider for AsyncStdNativeTlsRuntime

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

impl NetStreamProvider for AsyncStdRustlsRuntime

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

impl NetStreamProvider for PreferredRuntime

source§

impl NetStreamProvider for TokioNativeTlsRuntime

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

type Stream = <CompoundRuntime<TokioRuntimeHandle, TokioRuntimeHandle, RealCoarseTimeProvider, TokioRuntimeHandle, TokioRuntimeHandle, NativeTlsProvider, TokioRuntimeHandle> as NetStreamProvider>::Stream

source§

type Listener = <CompoundRuntime<TokioRuntimeHandle, TokioRuntimeHandle, RealCoarseTimeProvider, TokioRuntimeHandle, TokioRuntimeHandle, NativeTlsProvider, TokioRuntimeHandle> as NetStreamProvider>::Listener

source§

impl NetStreamProvider for TokioRustlsRuntime

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

type Stream = <CompoundRuntime<TokioRuntimeHandle, TokioRuntimeHandle, RealCoarseTimeProvider, TokioRuntimeHandle, TokioRuntimeHandle, RustlsProvider, TokioRuntimeHandle> as NetStreamProvider>::Stream

source§

type Listener = <CompoundRuntime<TokioRuntimeHandle, TokioRuntimeHandle, RealCoarseTimeProvider, TokioRuntimeHandle, TokioRuntimeHandle, RustlsProvider, TokioRuntimeHandle> as NetStreamProvider>::Listener

source§

impl NetStreamProvider<SocketAddr> for AsyncStdNativeTlsRuntime

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

impl NetStreamProvider<SocketAddr> for AsyncStdRustlsRuntime

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

impl NetStreamProvider<SocketAddr> for PreferredRuntime

source§

impl NetStreamProvider<SocketAddr> for TokioNativeTlsRuntime

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

type Stream = <CompoundRuntime<TokioRuntimeHandle, TokioRuntimeHandle, RealCoarseTimeProvider, TokioRuntimeHandle, TokioRuntimeHandle, NativeTlsProvider, TokioRuntimeHandle> as NetStreamProvider<SocketAddr>>::Stream

source§

type Listener = <CompoundRuntime<TokioRuntimeHandle, TokioRuntimeHandle, RealCoarseTimeProvider, TokioRuntimeHandle, TokioRuntimeHandle, NativeTlsProvider, TokioRuntimeHandle> as NetStreamProvider<SocketAddr>>::Listener

source§

impl NetStreamProvider<SocketAddr> for TokioRustlsRuntime

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

type Stream = <CompoundRuntime<TokioRuntimeHandle, TokioRuntimeHandle, RealCoarseTimeProvider, TokioRuntimeHandle, TokioRuntimeHandle, RustlsProvider, TokioRuntimeHandle> as NetStreamProvider<SocketAddr>>::Stream

source§

type Listener = <CompoundRuntime<TokioRuntimeHandle, TokioRuntimeHandle, RealCoarseTimeProvider, TokioRuntimeHandle, TokioRuntimeHandle, RustlsProvider, TokioRuntimeHandle> as NetStreamProvider<SocketAddr>>::Listener

source§

impl<SpawnR, SleepR, CoarseTimeR, TcpR, UnixR, TlsR, UdpR> NetStreamProvider for CompoundRuntime<SpawnR, SleepR, CoarseTimeR, TcpR, UnixR, TlsR, UdpR>
where TcpR: NetStreamProvider<SocketAddr> + Send + Sync + 'static, SpawnR: Send + Sync + 'static, SleepR: Send + Sync + 'static, CoarseTimeR: Send + Sync + 'static, UnixR: Clone + Send + Sync + 'static, TlsR: Send + Sync + 'static, UdpR: Send + Sync + 'static,

source§

impl<SpawnR, SleepR, CoarseTimeR, TcpR, UnixR, TlsR, UdpR> NetStreamProvider<SocketAddr> for CompoundRuntime<SpawnR, SleepR, CoarseTimeR, TcpR, UnixR, TlsR, UdpR>
where UnixR: NetStreamProvider<SocketAddr> + Clone + Send + Sync + 'static, SpawnR: Send + Sync + 'static, SleepR: Send + Sync + 'static, CoarseTimeR: Send + Sync + 'static, TcpR: Send + Sync + 'static, TlsR: Send + Sync + 'static, UdpR: Send + Sync + 'static,

source§

impl<T> NetStreamProvider<SocketAddr> for T