Struct tor_rtmock::net::MockNetProvider [−][src]
pub struct MockNetProvider { /* fields omitted */ }
Expand description
A view of a single host’s access to a MockNetwork.
Each simulated host has its own addresses that it’s allowed to listen on, and a reference to the network.
This type implements TcpProvider
so that it can be used as a
drop-in replacement for testing code that uses the network.
Limitations
There’s no randomness here, so we can’t simulate the weirdness of real networks.
So far, there’s no support for DNS or UDP.
We don’t handle localhost specially, and we don’t simulate providers that can connect to some addresses but not all.
We don’t do the right thing (block) if there is a listener that never calls accept.
We use a simple u16
counter to decide what arbitrary port
numbers to use: Once that counter is exhausted, we will fail with
an assertion. We don’t do anything to prevent those arbitrary
ports from colliding with specified ports, other than declare that
you can’t have two listeners on the same addr:port at the same
time.
We pretend to provide TLS, but there’s no actual encryption or authentication.
Implementations
Create a mock TLS listener with provided certificate.
Note that no encryption or authentication is actually performed! Other parties are simply told that their connections succeeded and were authenticated against the given certificate.
Trait Implementations
type TcpStream = LocalStream
type TcpStream = LocalStream
The type for the TCP connections returned by Self::connect()
.
type TcpListener = MockNetListener
type TcpListener = MockNetListener
The type for the TCP listeners returned by Self::listen()
.
fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<LocalStream>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<LocalStream>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Launch a TCP connection to a given socket address. Read more
fn listen<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr
) -> Pin<Box<dyn Future<Output = IoResult<Self::TcpListener>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: '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
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Open a TCP listener on a given socket address.
type Connector = MockTlsConnector
type Connector = MockTlsConnector
The Connector object that this provider can return.
type TlsStream = MockTlsStream
type TlsStream = MockTlsStream
The type of the stream returned by that connector.
Return a TLS connector for use with this runtime.
Auto Trait Implementations
impl RefUnwindSafe for MockNetProvider
impl Send for MockNetProvider
impl Sync for MockNetProvider
impl Unpin for MockNetProvider
impl UnwindSafe for MockNetProvider
Blanket Implementations
Mutably borrows from an owned value. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more