pub struct Network<TTrans, TInEvent, TOutEvent, THandler> where
TTrans: Transport,
THandler: IntoConnectionHandler, { /* private fields */ }
Expand description
Implementation of Stream
that handles the nodes.
Implementations
sourceimpl<TTrans, TInEvent, TOutEvent, TMuxer, THandler> Network<TTrans, TInEvent, TOutEvent, THandler> where
TTrans: Transport + Clone,
TMuxer: StreamMuxer,
THandler: 'static + IntoConnectionHandler + Send,
<THandler as IntoConnectionHandler>::Handler: ConnectionHandler,
<THandler as IntoConnectionHandler>::Handler: Send,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutboundOpenInfo: Send,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error: Error,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error: Send,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Substream == SubstreamRef<Arc<TMuxer>>,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::InEvent == TInEvent,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent == TOutEvent,
impl<TTrans, TInEvent, TOutEvent, TMuxer, THandler> Network<TTrans, TInEvent, TOutEvent, THandler> where
TTrans: Transport + Clone,
TMuxer: StreamMuxer,
THandler: 'static + IntoConnectionHandler + Send,
<THandler as IntoConnectionHandler>::Handler: ConnectionHandler,
<THandler as IntoConnectionHandler>::Handler: Send,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutboundOpenInfo: Send,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error: Error,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error: Send,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Substream == SubstreamRef<Arc<TMuxer>>,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::InEvent == TInEvent,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent == TOutEvent,
sourcepub fn new(
transport: TTrans,
local_peer_id: PeerId,
config: NetworkConfig
) -> Network<TTrans, TInEvent, TOutEvent, THandler>
pub fn new(
transport: TTrans,
local_peer_id: PeerId,
config: NetworkConfig
) -> Network<TTrans, TInEvent, TOutEvent, THandler>
Creates a new node events stream.
sourcepub fn listen_on(
&mut self,
addr: Multiaddr
) -> Result<ListenerId, TransportError<<TTrans as Transport>::Error>>
pub fn listen_on(
&mut self,
addr: Multiaddr
) -> Result<ListenerId, TransportError<<TTrans as Transport>::Error>>
Start listening on the given multiaddress.
sourcepub fn remove_listener(&mut self, id: ListenerId) -> Result<(), ()>
pub fn remove_listener(&mut self, id: ListenerId) -> Result<(), ()>
Remove a previously added listener.
Returns Ok(())
if a listener with this ID was in the list.
sourcepub fn listen_addrs(&self) -> impl Iterator<Item = &Multiaddr>
pub fn listen_addrs(&self) -> impl Iterator<Item = &Multiaddr>
Returns an iterator that produces the list of addresses we are listening on.
sourcepub fn address_translation<'a>(
&'a self,
observed_addr: &'a Multiaddr
) -> impl Iterator<Item = Multiaddr> + 'a where
TMuxer: 'a,
THandler: 'a,
pub fn address_translation<'a>(
&'a self,
observed_addr: &'a Multiaddr
) -> impl Iterator<Item = Multiaddr> + 'a where
TMuxer: 'a,
THandler: 'a,
Maps the given observed_addr
, representing an address of the local
node observed by a remote peer, onto the locally known listen addresses
to yield one or more addresses of the local node that may be publicly
reachable.
I.e. this method incorporates the view of other peers into the listen
addresses seen by the local node to account for possible IP and port
mappings performed by intermediate network devices in an effort to
obtain addresses for the local peer that are also reachable for peers
other than the peer who reported the observed_addr
.
The translation is transport-specific. See Transport::address_translation
.
sourcepub fn local_peer_id(&self) -> &PeerId
pub fn local_peer_id(&self) -> &PeerId
Returns the peer id of the local node.
sourcepub fn dial(
&mut self,
address: &Multiaddr,
handler: THandler
) -> Result<ConnectionId, ConnectionLimit> where
TTrans: Transport<Output = (PeerId, TMuxer)>,
TMuxer: 'static + Send + Sync,
TInEvent: 'static + Send,
TOutEvent: 'static + Send,
<TTrans as Transport>::Error: 'static,
<TTrans as Transport>::Error: Send,
<TTrans as Transport>::Dial: 'static,
<TTrans as Transport>::Dial: Send,
<TMuxer as StreamMuxer>::OutboundSubstream: Send,
pub fn dial(
&mut self,
address: &Multiaddr,
handler: THandler
) -> Result<ConnectionId, ConnectionLimit> where
TTrans: Transport<Output = (PeerId, TMuxer)>,
TMuxer: 'static + Send + Sync,
TInEvent: 'static + Send,
TOutEvent: 'static + Send,
<TTrans as Transport>::Error: 'static,
<TTrans as Transport>::Error: Send,
<TTrans as Transport>::Dial: 'static,
<TTrans as Transport>::Dial: Send,
<TMuxer as StreamMuxer>::OutboundSubstream: Send,
Dials a multiaddress without expecting a particular remote peer ID.
The given handler
will be used to create the
Connection
upon success and the
connection ID is returned.
sourcepub fn info(&self) -> NetworkInfo
pub fn info(&self) -> NetworkInfo
Returns information about the state of the Network
.
sourcepub fn incoming_info(&self) -> impl Iterator<Item = IncomingInfo<'_>>
pub fn incoming_info(&self) -> impl Iterator<Item = IncomingInfo<'_>>
Returns an iterator for information on all pending incoming connections.
sourcepub fn unknown_dials(&self) -> impl Iterator<Item = &Multiaddr>
pub fn unknown_dials(&self) -> impl Iterator<Item = &Multiaddr>
Returns the list of addresses we’re currently dialing without knowing the PeerId
of.
sourcepub fn connected_peers(&self) -> impl Iterator<Item = &PeerId>
pub fn connected_peers(&self) -> impl Iterator<Item = &PeerId>
Returns a list of all connected peers, i.e. peers to whom the Network
has at least one established connection.
sourcepub fn is_connected(&self, peer: &PeerId) -> bool
pub fn is_connected(&self, peer: &PeerId) -> bool
Checks whether the network has an established connection to a peer.
sourcepub fn is_dialing(&self, peer: &PeerId) -> bool
pub fn is_dialing(&self, peer: &PeerId) -> bool
Checks whether the network has an ongoing dialing attempt to a peer.
sourcepub fn is_disconnected(&self, peer: &PeerId) -> bool
pub fn is_disconnected(&self, peer: &PeerId) -> bool
Checks whether the network has neither an ongoing dialing attempt, nor an established connection to a peer.
sourcepub fn dialing_peers(&self) -> impl Iterator<Item = &PeerId>
pub fn dialing_peers(&self) -> impl Iterator<Item = &PeerId>
Returns a list of all the peers to whom a new outgoing connection is currently being established.
sourcepub fn peer(
&mut self,
peer_id: PeerId
) -> Peer<'_, TTrans, TInEvent, TOutEvent, THandler>
pub fn peer(
&mut self,
peer_id: PeerId
) -> Peer<'_, TTrans, TInEvent, TOutEvent, THandler>
Obtains a view of a Peer
with the given ID in the network.
sourcepub fn accept(
&mut self,
connection: IncomingConnection<<TTrans as Transport>::ListenerUpgrade>,
handler: THandler
) -> Result<ConnectionId, ConnectionLimit> where
TInEvent: 'static + Send,
TOutEvent: 'static + Send,
TMuxer: 'static + StreamMuxer + Send + Sync,
TTrans: Transport<Output = (PeerId, TMuxer)>,
<TMuxer as StreamMuxer>::OutboundSubstream: Send,
<TTrans as Transport>::Error: 'static,
<TTrans as Transport>::Error: Send,
<TTrans as Transport>::ListenerUpgrade: 'static,
<TTrans as Transport>::ListenerUpgrade: Send,
pub fn accept(
&mut self,
connection: IncomingConnection<<TTrans as Transport>::ListenerUpgrade>,
handler: THandler
) -> Result<ConnectionId, ConnectionLimit> where
TInEvent: 'static + Send,
TOutEvent: 'static + Send,
TMuxer: 'static + StreamMuxer + Send + Sync,
TTrans: Transport<Output = (PeerId, TMuxer)>,
<TMuxer as StreamMuxer>::OutboundSubstream: Send,
<TTrans as Transport>::Error: 'static,
<TTrans as Transport>::Error: Send,
<TTrans as Transport>::ListenerUpgrade: 'static,
<TTrans as Transport>::ListenerUpgrade: Send,
Accepts a pending incoming connection obtained via NetworkEvent::IncomingConnection
,
adding it to the Network
s connection pool subject to the configured limits.
Once the connection is established and all transport protocol upgrades
completed, the connection is associated with the provided handler
.
sourcepub fn poll(
&'a mut self,
cx: &mut Context<'_>
) -> Poll<NetworkEvent<'a, TTrans, TInEvent, TOutEvent, THandler>> where
TTrans: Transport<Output = (PeerId, TMuxer)>,
TMuxer: 'static + Send + Sync,
TInEvent: 'static + Send,
TOutEvent: 'static + Send,
THandler: 'static + IntoConnectionHandler + Send,
<TTrans as Transport>::Error: 'static,
<TTrans as Transport>::Error: Send,
<TTrans as Transport>::Dial: 'static,
<TTrans as Transport>::Dial: Send,
<TTrans as Transport>::ListenerUpgrade: 'static,
<TTrans as Transport>::ListenerUpgrade: Send,
<TMuxer as StreamMuxer>::OutboundSubstream: Send,
<THandler as IntoConnectionHandler>::Handler: 'static,
<THandler as IntoConnectionHandler>::Handler: ConnectionHandler,
<THandler as IntoConnectionHandler>::Handler: Send,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error: 'static,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error: Error,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error: Send,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Substream == SubstreamRef<Arc<TMuxer>>,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::InEvent == TInEvent,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent == TOutEvent,
pub fn poll(
&'a mut self,
cx: &mut Context<'_>
) -> Poll<NetworkEvent<'a, TTrans, TInEvent, TOutEvent, THandler>> where
TTrans: Transport<Output = (PeerId, TMuxer)>,
TMuxer: 'static + Send + Sync,
TInEvent: 'static + Send,
TOutEvent: 'static + Send,
THandler: 'static + IntoConnectionHandler + Send,
<TTrans as Transport>::Error: 'static,
<TTrans as Transport>::Error: Send,
<TTrans as Transport>::Dial: 'static,
<TTrans as Transport>::Dial: Send,
<TTrans as Transport>::ListenerUpgrade: 'static,
<TTrans as Transport>::ListenerUpgrade: Send,
<TMuxer as StreamMuxer>::OutboundSubstream: Send,
<THandler as IntoConnectionHandler>::Handler: 'static,
<THandler as IntoConnectionHandler>::Handler: ConnectionHandler,
<THandler as IntoConnectionHandler>::Handler: Send,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error: 'static,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error: Error,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error: Send,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Substream == SubstreamRef<Arc<TMuxer>>,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::InEvent == TInEvent,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent == TOutEvent,
Provides an API similar to Stream
, except that it cannot error.
Trait Implementations
sourceimpl<TTrans, TInEvent, TOutEvent, THandler> Debug for Network<TTrans, TInEvent, TOutEvent, THandler> where
TTrans: Debug + Transport,
THandler: Debug + ConnectionHandler,
impl<TTrans, TInEvent, TOutEvent, THandler> Debug for Network<TTrans, TInEvent, TOutEvent, THandler> where
TTrans: Debug + Transport,
THandler: Debug + ConnectionHandler,
impl<TTrans, TInEvent, TOutEvent, THandler> Unpin for Network<TTrans, TInEvent, TOutEvent, THandler> where
TTrans: Transport,
THandler: IntoConnectionHandler,
Auto Trait Implementations
impl<TTrans, TInEvent, TOutEvent, THandler> !RefUnwindSafe for Network<TTrans, TInEvent, TOutEvent, THandler>
impl<TTrans, TInEvent, TOutEvent, THandler> Send for Network<TTrans, TInEvent, TOutEvent, THandler> where
THandler: Send,
TInEvent: Send,
TOutEvent: Send,
TTrans: Send,
<TTrans as Transport>::Error: Send,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error: Send,
<TTrans as Transport>::Listener: Send,
impl<TTrans, TInEvent, TOutEvent, THandler> !Sync for Network<TTrans, TInEvent, TOutEvent, THandler>
impl<TTrans, TInEvent, TOutEvent, THandler> !UnwindSafe for Network<TTrans, TInEvent, TOutEvent, THandler>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more