pub trait Transport<Z: NetworkZone>:
Clone
+ Send
+ 'static {
type ClientConfig: Default + Clone + Debug + Send + Sync + 'static;
type ServerConfig: Default + Clone + Debug + Send + Sync + 'static;
type Stream: Stream<Item = Result<Message, BucketError>> + Unpin + Send + 'static;
type Sink: Sink<LevinMessage<Message>, Error = BucketError> + Unpin + Send + 'static;
type Listener: Stream<Item = Result<(Option<Z::Addr>, Self::Stream, Self::Sink), Error>> + Send + 'static;
// Required methods
fn connect_to_peer<'life0, 'async_trait>(
addr: Z::Addr,
config: &'life0 Self::ClientConfig,
) -> Pin<Box<dyn Future<Output = Result<(Self::Stream, Self::Sink), Error>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn incoming_connection_listener<'async_trait>(
config: Self::ServerConfig,
) -> Pin<Box<dyn Future<Output = Result<Self::Listener, Error>> + Send + 'async_trait>>
where Self: 'async_trait;
}
Expand description
An abstraction over a transport method (TCP/Tor/SOCKS5/…)
This trait implements the required methods and types for establishing connection to a
peer or instantiating a listener for the NetworkZone
Z
over a Transport
method T
.
Ultimately, multiple transports can implement the same trait for providing alternative ways for a network zone to operate (example: ClearNet can operate on both TCP and Tor.)
Required Associated Types§
Sourcetype ClientConfig: Default + Clone + Debug + Send + Sync + 'static
type ClientConfig: Default + Clone + Debug + Send + Sync + 'static
Client configuration necessary when establishing a connection to a peer.
Note: Currently, this client config is considered immutable during operational runtime. If one wish to apply modifications on the fly, they will need to make use of an inner shared and mutable reference to do so.
Sourcetype ServerConfig: Default + Clone + Debug + Send + Sync + 'static
type ServerConfig: Default + Clone + Debug + Send + Sync + 'static
Server configuration necessary when instantiating a listener for inbound connections.
Sourcetype Stream: Stream<Item = Result<Message, BucketError>> + Unpin + Send + 'static
type Stream: Stream<Item = Result<Message, BucketError>> + Unpin + Send + 'static
The stream (incoming data) type of this transport method.
Sourcetype Sink: Sink<LevinMessage<Message>, Error = BucketError> + Unpin + Send + 'static
type Sink: Sink<LevinMessage<Message>, Error = BucketError> + Unpin + Send + 'static
The sink (outgoing data) type of this transport method.
Required Methods§
Sourcefn connect_to_peer<'life0, 'async_trait>(
addr: Z::Addr,
config: &'life0 Self::ClientConfig,
) -> Pin<Box<dyn Future<Output = Result<(Self::Stream, Self::Sink), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn connect_to_peer<'life0, 'async_trait>(
addr: Z::Addr,
config: &'life0 Self::ClientConfig,
) -> Pin<Box<dyn Future<Output = Result<(Self::Stream, Self::Sink), Error>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Connects to a peer with the given address.
Take in argument the destination NetworkZone::Addr
and Self::ClientConfig
which should contain mandatory parameters
for a connection to be established.
This does not complete a handshake with the peer, to do that see the crate docs.
Returns the Self::Stream
and Self::Sink
to send messages to the peer.
Sourcefn incoming_connection_listener<'async_trait>(
config: Self::ServerConfig,
) -> Pin<Box<dyn Future<Output = Result<Self::Listener, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
fn incoming_connection_listener<'async_trait>(
config: Self::ServerConfig,
) -> Pin<Box<dyn Future<Output = Result<Self::Listener, Error>> + Send + 'async_trait>>where
Self: 'async_trait,
Instantiate a listener for inbound peer connections
Take in argument Self::ServerConfig
which should contain mandatory parameters
for the listener.
Returns the Self::Listener
to listen to new connections.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.