Struct network::transport::DiemNetTransport
source · pub struct DiemNetTransport<TTransport> { /* private fields */ }
Expand description
The common DiemNet Transport.
The base transport layer is pluggable, so long as it provides a reliable,
ordered, connection-oriented, byte-stream abstraction (e.g., TCP). We currently
use either MemoryTransport
or TcpTransport
as this base layer.
Inbound and outbound connections are first established with the base_transport
and then negotiate a secure, authenticated transport layer (currently Noise
protocol). Finally, we negotiate common supported application protocols with
the Handshake
protocol.
Implementations§
source§impl<TTransport> DiemNetTransport<TTransport>where
TTransport: Transport<Error = Error>,
TTransport::Output: TSocket,
TTransport::Outbound: Send + 'static,
TTransport::Inbound: Send + 'static,
TTransport::Listener: Send + 'static,
impl<TTransport> DiemNetTransport<TTransport>where TTransport: Transport<Error = Error>, TTransport::Output: TSocket, TTransport::Outbound: Send + 'static, TTransport::Inbound: Send + 'static, TTransport::Listener: Send + 'static,
pub fn new( base_transport: TTransport, network_context: Arc<NetworkContext>, time_service: TimeService, identity_key: PrivateKey, auth_mode: HandshakeAuthMode, handshake_version: u8, chain_id: ChainId, application_protocols: SupportedProtocols, enable_proxy_protocol: bool ) -> Self
sourcepub fn dial(
&self,
peer_id: PeerId,
addr: NetworkAddress
) -> Result<impl Future<Output = Result<Connection<NoiseStream<TTransport::Output>>>> + Send + 'static>
pub fn dial( &self, peer_id: PeerId, addr: NetworkAddress ) -> Result<impl Future<Output = Result<Connection<NoiseStream<TTransport::Output>>>> + Send + 'static>
Dial a peer at addr
. If the addr
is not supported or formatted correctly,
return Err
. Otherwise, return a Future
that resolves to Err
if there
was some issue dialing the peer and Ok
with a fully upgraded connection
to that peer if our dial was successful.
Dialing NetworkAddress
format
We parse the dial address like:
/<base_transport>
+ /ln-noise-ik/<pubkey>/ln-handshake/<version>
If the base transport is MemoryTransport
, then /<base_transport>
is:
/memory/<port>
If the base transport is TcpTransport
, then /<base_transport>
is:
/ip4/<ipaddr>/tcp/<port>
or
/ip6/<ipaddr>/tcp/<port>
or
/dns/<ipaddr>/tcp/<port>
or
/dns4/<ipaddr>/tcp/<port>
or
/dns6/<ipaddr>/tcp/<port>
sourcepub fn listen_on(
&self,
addr: NetworkAddress
) -> Result<(impl Stream<Item = Result<(impl Future<Output = Result<Connection<NoiseStream<TTransport::Output>>>> + Send + 'static, NetworkAddress)>> + Send + 'static, NetworkAddress)>
pub fn listen_on( &self, addr: NetworkAddress ) -> Result<(impl Stream<Item = Result<(impl Future<Output = Result<Connection<NoiseStream<TTransport::Output>>>> + Send + 'static, NetworkAddress)>> + Send + 'static, NetworkAddress)>
Listen on address addr
. If the addr
is not supported or formatted correctly,
return Err
. Otherwise, return a Stream
of fully upgraded inbound connections
and the dialer’s observed network address.
Listening NetworkAddress
format
When listening, we only expect the base transport format. For example,
if the base transport is MemoryTransport
, then we expect:
/memory/<port>
If the base transport is TcpTransport
, then we expect:
/ip4/<ipaddr>/tcp/<port>
or
/ip6/<ipaddr>/tcp/<port>
Trait Implementations§
source§impl<TTransport> Transport for DiemNetTransport<TTransport>where
TTransport: Transport<Error = Error> + Send + 'static + Transport,
TTransport::Output: TSocket,
TTransport::Outbound: Send + 'static,
TTransport::Inbound: Send + 'static,
TTransport::Listener: Send + 'static,
impl<TTransport> Transport for DiemNetTransport<TTransport>where TTransport: Transport<Error = Error> + Send + 'static + Transport, TTransport::Output: TSocket, TTransport::Outbound: Send + 'static, TTransport::Inbound: Send + 'static, TTransport::Listener: Send + 'static,
§type Output = Connection<NoiseStream<<TTransport as Transport>::Output>>
type Output = Connection<NoiseStream<<TTransport as Transport>::Output>>
§type Inbound = Pin<Box<dyn Future<Output = Result<<DiemNetTransport<TTransport> as Transport>::Output, Error>> + Send + 'static, Global>>
type Inbound = Pin<Box<dyn Future<Output = Result<<DiemNetTransport<TTransport> as Transport>::Output, Error>> + Send + 'static, Global>>
§type Outbound = Pin<Box<dyn Future<Output = Result<<DiemNetTransport<TTransport> as Transport>::Output, Error>> + Send + 'static, Global>>
type Outbound = Pin<Box<dyn Future<Output = Result<<DiemNetTransport<TTransport> as Transport>::Output, Error>> + Send + 'static, Global>>
§type Listener = Pin<Box<dyn Stream<Item = Result<(<DiemNetTransport<TTransport> as Transport>::Inbound, NetworkAddress), Error>> + Send + 'static, Global>>
type Listener = Pin<Box<dyn Stream<Item = Result<(<DiemNetTransport<TTransport> as Transport>::Inbound, NetworkAddress), Error>> + Send + 'static, Global>>
Auto Trait Implementations§
impl<TTransport> RefUnwindSafe for DiemNetTransport<TTransport>where TTransport: RefUnwindSafe,
impl<TTransport> Send for DiemNetTransport<TTransport>where TTransport: Send,
impl<TTransport> Sync for DiemNetTransport<TTransport>where TTransport: Sync,
impl<TTransport> Unpin for DiemNetTransport<TTransport>where TTransport: Unpin,
impl<TTransport> UnwindSafe for DiemNetTransport<TTransport>where TTransport: UnwindSafe,
Blanket Implementations§
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> TransportExt for Twhere
T: Transport + ?Sized,
impl<T> TransportExt for Twhere T: Transport + ?Sized,
§fn boxed(self) -> BoxedTransport<Self::Output, Self::Error>where
Self: Sized + Send + 'static,
Self::Listener: Send + 'static,
Self::Inbound: Send + 'static,
Self::Outbound: Send + 'static,
fn boxed(self) -> BoxedTransport<Self::Output, Self::Error>where Self: Sized + Send + 'static, Self::Listener: Send + 'static, Self::Inbound: Send + 'static, Self::Outbound: Send + 'static,
Transport
] into an abstract boxed transport.