Struct libp2p::core::Network [−][src]
pub struct Network<TTrans, THandler> where
TTrans: Transport,
THandler: IntoConnectionHandler, { /* fields omitted */ }
Expand description
Implementation of Stream
that handles the nodes.
Implementations
impl<TTrans, THandler> Network<TTrans, THandler> where
TTrans: Transport,
THandler: IntoConnectionHandler,
impl<TTrans, THandler> Network<TTrans, THandler> where
TTrans: Transport,
THandler: IntoConnectionHandler,
Checks whether the network has an established connection to a peer.
Checks whether the network has an ongoing dialing attempt to a peer.
pub fn new(
transport: TTrans,
local_peer_id: PeerId,
config: NetworkConfig
) -> Network<TTrans, THandler>
pub fn new(
transport: TTrans,
local_peer_id: PeerId,
config: NetworkConfig
) -> Network<TTrans, THandler>
Creates a new node events stream.
pub 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.
Remove a previously added listener.
Returns true
if there was a listener with this ID, false
otherwise.
Returns an iterator that produces the list of addresses we are listening on.
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
.
Returns the peer id of the local node.
pub fn dial(
&mut self,
address: &Multiaddr,
handler: THandler
) -> Result<ConnectionId, DialError<THandler>> where
TTrans: Transport + Send,
<TTrans as Transport>::Output: 'static,
<TTrans as Transport>::Output: Send,
<TTrans as Transport>::Dial: 'static,
<TTrans as Transport>::Dial: Send,
<TTrans as Transport>::Error: 'static,
<TTrans as Transport>::Error: Send,
<TTrans as Transport>::Dial: 'static,
<TTrans as Transport>::Dial: Send,
pub fn dial(
&mut self,
address: &Multiaddr,
handler: THandler
) -> Result<ConnectionId, DialError<THandler>> where
TTrans: Transport + Send,
<TTrans as Transport>::Output: 'static,
<TTrans as Transport>::Output: Send,
<TTrans as Transport>::Dial: 'static,
<TTrans as Transport>::Dial: Send,
<TTrans as Transport>::Error: 'static,
<TTrans as Transport>::Error: Send,
<TTrans as Transport>::Dial: 'static,
<TTrans as Transport>::Dial: Send,
Dials a Multiaddr
that may or may not encapsulate a
specific expected remote peer ID.
The given handler
will be used to create the
Connection
upon success and the
connection ID is returned.
Returns information about the state of the Network
.
Returns an iterator for information on all pending incoming connections.
Returns a list of all connected peers, i.e. peers to whom the Network
has at least one established connection.
Checks whether the network has neither an ongoing dialing attempt, nor an established connection to a peer.
Returns a list of all the peers to whom a new outgoing connection is currently being established.
Obtains a view of a Peer
with the given ID in the network.
pub fn accept(
&mut self,
IncomingConnection<<TTrans as Transport>::ListenerUpgrade>,
handler: THandler
) -> Result<ConnectionId, (ConnectionLimit, THandler)> where
TTrans: Transport,
<TTrans as Transport>::Output: 'static,
<TTrans as Transport>::Output: 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,
IncomingConnection<<TTrans as Transport>::ListenerUpgrade>,
handler: THandler
) -> Result<ConnectionId, (ConnectionLimit, THandler)> where
TTrans: Transport,
<TTrans as Transport>::Output: 'static,
<TTrans as Transport>::Output: 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
.
pub fn poll<TMuxer>(
&'a mut self,
cx: &mut Context<'_>
) -> Poll<NetworkEvent<'a, TTrans, <<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::InEvent, <<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent, THandler>> where
TTrans: Transport<Output = (PeerId, TMuxer)>,
TMuxer: 'static + StreamMuxer + Send + Sync,
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>::Error: Debug,
<TMuxer as StreamMuxer>::OutboundSubstream: 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>::OutboundOpenInfo: Send,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error: Error,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error: Send,
<THandler as IntoConnectionHandler>::Handler: ConnectionHandler,
<THandler as IntoConnectionHandler>::Handler: Send,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Substream == SubstreamRef<Arc<TMuxer>>,
pub fn poll<TMuxer>(
&'a mut self,
cx: &mut Context<'_>
) -> Poll<NetworkEvent<'a, TTrans, <<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::InEvent, <<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::OutEvent, THandler>> where
TTrans: Transport<Output = (PeerId, TMuxer)>,
TMuxer: 'static + StreamMuxer + Send + Sync,
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>::Error: Debug,
<TMuxer as StreamMuxer>::OutboundSubstream: 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>::OutboundOpenInfo: Send,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error: Error,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error: Send,
<THandler as IntoConnectionHandler>::Handler: ConnectionHandler,
<THandler as IntoConnectionHandler>::Handler: Send,
<<THandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Substream == SubstreamRef<Arc<TMuxer>>,
Provides an API similar to Stream
, except that it does not terminate.