Struct tor_rtmock::net::MockNetProvider
source · [−]pub struct MockNetProvider { /* private fields */ }
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
sourceimpl MockNetProvider
impl MockNetProvider
sourcepub fn listen_tls(
&self,
addr: &SocketAddr,
tls_cert: Vec<u8>
) -> IoResult<MockNetListener>
pub fn listen_tls(
&self,
addr: &SocketAddr,
tls_cert: Vec<u8>
) -> IoResult<MockNetListener>
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
sourceimpl Clone for MockNetProvider
impl Clone for MockNetProvider
sourcefn clone(&self) -> MockNetProvider
fn clone(&self) -> MockNetProvider
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for MockNetProvider
impl Debug for MockNetProvider
sourceimpl TcpProvider for MockNetProvider
impl TcpProvider for MockNetProvider
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()
.
sourcefn 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
sourcefn 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.
sourceimpl TlsProvider<LocalStream> for MockNetProvider
impl TlsProvider<LocalStream> for MockNetProvider
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.
sourcefn tls_connector(&self) -> MockTlsConnector
fn tls_connector(&self) -> MockTlsConnector
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more