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 NetStreamProvider
for SocketAddr
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.
UDP is completely broken:
datagrams appear to be transmitted, but will never be received.
And local address assignment is not implemented
so .local_addr()
can return NONE
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§
Source§impl 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§
Source§impl Clone for MockNetProvider
impl Clone for MockNetProvider
Source§fn clone(&self) -> MockNetProvider
fn clone(&self) -> MockNetProvider
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for MockNetProvider
impl Debug for MockNetProvider
Source§impl Default for MockNetProvider
impl Default for MockNetProvider
Source§impl NetStreamProvider for MockNetProvider
impl NetStreamProvider for MockNetProvider
Source§type Stream = LocalStream
type Stream = LocalStream
Self::connect()
.Source§type Listener = MockNetListener
type Listener = MockNetListener
Self::listen()
.Source§fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr,
) -> Pin<Box<dyn Future<Output = IoResult<LocalStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn connect<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr,
) -> Pin<Box<dyn Future<Output = IoResult<LocalStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§impl<R: Runtime> TlsProvider<<MockNetProvider as NetStreamProvider>::Stream> for MockNetRuntime<R>
impl<R: Runtime> TlsProvider<<MockNetProvider as NetStreamProvider>::Stream> for MockNetRuntime<R>
Source§type Connector = <MockNetProvider as TlsProvider<<MockNetProvider as NetStreamProvider>::Stream>>::Connector
type Connector = <MockNetProvider as TlsProvider<<MockNetProvider as NetStreamProvider>::Stream>>::Connector
Source§type TlsStream = <MockNetProvider as TlsProvider<<MockNetProvider as NetStreamProvider>::Stream>>::TlsStream
type TlsStream = <MockNetProvider as TlsProvider<<MockNetProvider as NetStreamProvider>::Stream>>::TlsStream
Source§fn tls_connector(&self) -> Self::Connector
fn tls_connector(&self) -> Self::Connector
Source§fn supports_keying_material_export(&self) -> bool
fn supports_keying_material_export(&self) -> bool
Source§impl TlsProvider<<MockNetProvider as NetStreamProvider>::Stream> for MockRuntime
impl TlsProvider<<MockNetProvider as NetStreamProvider>::Stream> for MockRuntime
Source§type Connector = <MockNetProvider as TlsProvider<<MockNetProvider as NetStreamProvider>::Stream>>::Connector
type Connector = <MockNetProvider as TlsProvider<<MockNetProvider as NetStreamProvider>::Stream>>::Connector
Source§type TlsStream = <MockNetProvider as TlsProvider<<MockNetProvider as NetStreamProvider>::Stream>>::TlsStream
type TlsStream = <MockNetProvider as TlsProvider<<MockNetProvider as NetStreamProvider>::Stream>>::TlsStream
Source§fn tls_connector(&self) -> Self::Connector
fn tls_connector(&self) -> Self::Connector
Source§fn supports_keying_material_export(&self) -> bool
fn supports_keying_material_export(&self) -> bool
Source§impl TlsProvider<LocalStream> for MockNetProvider
impl TlsProvider<LocalStream> for MockNetProvider
Source§type Connector = MockTlsConnector
type Connector = MockTlsConnector
Source§type TlsStream = MockTlsStream
type TlsStream = MockTlsStream
Source§fn tls_connector(&self) -> MockTlsConnector
fn tls_connector(&self) -> MockTlsConnector
Source§fn supports_keying_material_export(&self) -> bool
fn supports_keying_material_export(&self) -> bool
Source§impl UdpProvider for MockNetProvider
impl UdpProvider for MockNetProvider
Source§type UdpSocket = MockUdpSocket
type UdpSocket = MockUdpSocket
Self::bind()
Source§fn bind<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr,
) -> Pin<Box<dyn Future<Output = IoResult<MockUdpSocket>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn bind<'life0, 'life1, 'async_trait>(
&'life0 self,
addr: &'life1 SocketAddr,
) -> Pin<Box<dyn Future<Output = IoResult<MockUdpSocket>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl Freeze for MockNetProvider
impl RefUnwindSafe for MockNetProvider
impl Send for MockNetProvider
impl Sync for MockNetProvider
impl Unpin for MockNetProvider
impl UnwindSafe for MockNetProvider
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more