Struct libp2p_core::network::Network [−][src]
Implementation of Stream
that handles the nodes.
Implementations
impl<TTrans, TInEvent, TOutEvent, TMuxer, THandler> Network<TTrans, TInEvent, TOutEvent, THandler> where
TTrans: Transport + Clone,
TMuxer: StreamMuxer,
THandler: IntoConnectionHandler + Send + 'static,
THandler::Handler: ConnectionHandler<Substream = Substream<TMuxer>, InEvent = TInEvent, OutEvent = TOutEvent> + Send,
<THandler::Handler as ConnectionHandler>::OutboundOpenInfo: Send,
<THandler::Handler as ConnectionHandler>::Error: Error + Send,
[src]
TTrans: Transport + Clone,
TMuxer: StreamMuxer,
THandler: IntoConnectionHandler + Send + 'static,
THandler::Handler: ConnectionHandler<Substream = Substream<TMuxer>, InEvent = TInEvent, OutEvent = TOutEvent> + Send,
<THandler::Handler as ConnectionHandler>::OutboundOpenInfo: Send,
<THandler::Handler as ConnectionHandler>::Error: Error + Send,
pub fn new(
transport: TTrans,
local_peer_id: PeerId,
config: NetworkConfig
) -> Self
[src]
transport: TTrans,
local_peer_id: PeerId,
config: NetworkConfig
) -> Self
Creates a new node events stream.
pub fn transport(&self) -> &TTrans
[src]
Returns the transport passed when building this object.
pub fn listen_on(
&mut self,
addr: Multiaddr
) -> Result<ListenerId, TransportError<TTrans::Error>>
[src]
&mut self,
addr: Multiaddr
) -> Result<ListenerId, TransportError<TTrans::Error>>
Start listening on the given multiaddress.
pub fn remove_listener(&mut self, id: ListenerId) -> Result<(), ()>
[src]
Remove a previously added listener.
Returns Ok(())
if a listener with this ID was in the list.
pub fn listen_addrs(&self) -> impl Iterator<Item = &Multiaddr>
[src]
Returns an iterator that produces the list of addresses we are listening on.
pub fn address_translation<'a>(
&'a self,
observed_addr: &'a Multiaddr
) -> impl Iterator<Item = Multiaddr> + 'a where
TMuxer: 'a,
THandler: 'a,
[src]
&'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
.
pub fn local_peer_id(&self) -> &PeerId
[src]
Returns the peer id of the local node.
pub fn dial(
&mut self,
address: &Multiaddr,
handler: THandler
) -> Result<ConnectionId, ConnectionLimit> where
TTrans: Transport<Output = (PeerId, TMuxer)>,
TTrans::Error: Send + 'static,
TTrans::Dial: Send + 'static,
TMuxer: Send + Sync + 'static,
TMuxer::OutboundSubstream: Send,
TInEvent: Send + 'static,
TOutEvent: Send + 'static,
[src]
&mut self,
address: &Multiaddr,
handler: THandler
) -> Result<ConnectionId, ConnectionLimit> where
TTrans: Transport<Output = (PeerId, TMuxer)>,
TTrans::Error: Send + 'static,
TTrans::Dial: Send + 'static,
TMuxer: Send + Sync + 'static,
TMuxer::OutboundSubstream: Send,
TInEvent: Send + 'static,
TOutEvent: Send + 'static,
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.
pub fn info(&self) -> NetworkInfo
[src]
Returns information about the state of the Network
.
pub fn incoming_info(&self) -> impl Iterator<Item = IncomingInfo<'_>>
[src]
Returns an iterator for information on all pending incoming connections.
pub fn unknown_dials(&self) -> impl Iterator<Item = &Multiaddr>
[src]
Returns the list of addresses we're currently dialing without knowing the PeerId
of.
pub fn connected_peers(&self) -> impl Iterator<Item = &PeerId>
[src]
Returns a list of all connected peers, i.e. peers to whom the Network
has at least one established connection.
pub fn is_connected(&self, peer: &PeerId) -> bool
[src]
Checks whether the network has an established connection to a peer.
pub fn is_dialing(&self, peer: &PeerId) -> bool
[src]
Checks whether the network has an ongoing dialing attempt to a peer.
pub fn is_disconnected(&self, peer: &PeerId) -> bool
[src]
Checks whether the network has neither an ongoing dialing attempt, nor an established connection to a peer.
pub fn dialing_peers(&self) -> impl Iterator<Item = &PeerId>
[src]
Returns a list of all the peers to whom a new outgoing connection is currently being established.
pub fn peer(
&mut self,
peer_id: PeerId
) -> Peer<'_, TTrans, TInEvent, TOutEvent, THandler>
[src]
&mut self,
peer_id: PeerId
) -> Peer<'_, TTrans, TInEvent, TOutEvent, THandler>
Obtains a view of a Peer
with the given ID in the network.
pub fn accept(
&mut self,
connection: IncomingConnection<TTrans::ListenerUpgrade>,
handler: THandler
) -> Result<ConnectionId, ConnectionLimit> where
TInEvent: Send + 'static,
TOutEvent: Send + 'static,
TMuxer: StreamMuxer + Send + Sync + 'static,
TMuxer::OutboundSubstream: Send,
TTrans: Transport<Output = (PeerId, TMuxer)>,
TTrans::Error: Send + 'static,
TTrans::ListenerUpgrade: Send + 'static,
[src]
&mut self,
connection: IncomingConnection<TTrans::ListenerUpgrade>,
handler: THandler
) -> Result<ConnectionId, ConnectionLimit> where
TInEvent: Send + 'static,
TOutEvent: Send + 'static,
TMuxer: StreamMuxer + Send + Sync + 'static,
TMuxer::OutboundSubstream: Send,
TTrans: Transport<Output = (PeerId, TMuxer)>,
TTrans::Error: Send + 'static,
TTrans::ListenerUpgrade: Send + 'static,
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<'a>(
&'a mut self,
cx: &mut Context<'_>
) -> Poll<NetworkEvent<'a, TTrans, TInEvent, TOutEvent, THandler>> where
TTrans: Transport<Output = (PeerId, TMuxer)>,
TTrans::Error: Send + 'static,
TTrans::Dial: Send + 'static,
TTrans::ListenerUpgrade: Send + 'static,
TMuxer: Send + Sync + 'static,
TMuxer::OutboundSubstream: Send,
TInEvent: Send + 'static,
TOutEvent: Send + 'static,
THandler: IntoConnectionHandler + Send + 'static,
THandler::Handler: ConnectionHandler<Substream = Substream<TMuxer>, InEvent = TInEvent, OutEvent = TOutEvent> + Send + 'static,
<THandler::Handler as ConnectionHandler>::Error: Error + Send + 'static,
[src]
&'a mut self,
cx: &mut Context<'_>
) -> Poll<NetworkEvent<'a, TTrans, TInEvent, TOutEvent, THandler>> where
TTrans: Transport<Output = (PeerId, TMuxer)>,
TTrans::Error: Send + 'static,
TTrans::Dial: Send + 'static,
TTrans::ListenerUpgrade: Send + 'static,
TMuxer: Send + Sync + 'static,
TMuxer::OutboundSubstream: Send,
TInEvent: Send + 'static,
TOutEvent: Send + 'static,
THandler: IntoConnectionHandler + Send + 'static,
THandler::Handler: ConnectionHandler<Substream = Substream<TMuxer>, InEvent = TInEvent, OutEvent = TOutEvent> + Send + 'static,
<THandler::Handler as ConnectionHandler>::Error: Error + Send + 'static,
Provides an API similar to Stream
, except that it cannot error.
Trait Implementations
impl<TTrans, TInEvent, TOutEvent, THandler> Debug for Network<TTrans, TInEvent, TOutEvent, THandler> where
TTrans: Debug + Transport,
THandler: Debug + ConnectionHandler,
[src]
TTrans: Debug + Transport,
THandler: Debug + ConnectionHandler,
impl<TTrans, TInEvent, TOutEvent, THandler> Unpin for Network<TTrans, TInEvent, TOutEvent, THandler> where
TTrans: Transport,
THandler: IntoConnectionHandler,
[src]
TTrans: Transport,
THandler: IntoConnectionHandler,
Auto Trait Implementations
impl<TTrans, TInEvent, TOutEvent, THandler> !RefUnwindSafe for Network<TTrans, TInEvent, TOutEvent, THandler>
[src]
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,
[src]
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>
[src]
impl<TTrans, TInEvent, TOutEvent, THandler> !UnwindSafe for Network<TTrans, TInEvent, TOutEvent, THandler>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,