Struct libp2p::core::Network[][src]

pub struct Network<TTrans, TInEvent, TOutEvent, THandler, TConnInfo = PeerId, TPeerId = PeerId> where
    THandler: IntoConnectionHandler<TConnInfo>,
    TTrans: Transport
{ /* fields omitted */ }

Implementation of Stream that handles the nodes.

Implementations

impl<TTrans, TInEvent, TOutEvent, TMuxer, THandler, TConnInfo, TPeerId> Network<TTrans, TInEvent, TOutEvent, THandler, TConnInfo, TPeerId> where
    THandler: IntoConnectionHandler<TConnInfo> + Send + 'static,
    TConnInfo: Debug + ConnectionInfo<PeerId = TPeerId> + Send + 'static,
    TTrans: Transport + Clone,
    TMuxer: StreamMuxer,
    TPeerId: Eq + Hash + Clone,
    <THandler as IntoConnectionHandler<TConnInfo>>::Handler: ConnectionHandler,
    <THandler as IntoConnectionHandler<TConnInfo>>::Handler: Send,
    <THandler as IntoConnectionHandler<TConnInfo>>::Handler: 'static,
    <<THandler as IntoConnectionHandler<TConnInfo>>::Handler as ConnectionHandler>::OutboundOpenInfo: Send,
    <<THandler as IntoConnectionHandler<TConnInfo>>::Handler as ConnectionHandler>::OutboundOpenInfo: 'static,
    <<THandler as IntoConnectionHandler<TConnInfo>>::Handler as ConnectionHandler>::Error: Error,
    <<THandler as IntoConnectionHandler<TConnInfo>>::Handler as ConnectionHandler>::Error: Send,
    <<THandler as IntoConnectionHandler<TConnInfo>>::Handler as ConnectionHandler>::Error: 'static,
    <<THandler as IntoConnectionHandler<TConnInfo>>::Handler as ConnectionHandler>::Substream == SubstreamRef<Arc<TMuxer>>,
    <<THandler as IntoConnectionHandler<TConnInfo>>::Handler as ConnectionHandler>::InEvent == TInEvent,
    <<THandler as IntoConnectionHandler<TConnInfo>>::Handler as ConnectionHandler>::OutEvent == TOutEvent, 
[src]

pub fn new(
    transport: TTrans,
    local_peer_id: TPeerId,
    config: NetworkConfig
) -> Network<TTrans, TInEvent, TOutEvent, THandler, TConnInfo, TPeerId>
[src]

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 as Transport>::Error>>
[src]

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
    THandler: 'a,
    TMuxer: 'a, 
[src]

Call this function in order to know which address remotes should dial to access your local node.

When receiving an observed address on a tcp connection that we initiated, the observed address contains our tcp dial port, not our tcp listen port. We know which port we are listening on, thereby we can replace the port within the observed address.

When receiving an observed address on a tcp connection that we did not initiated, the observed address should contain our listening port. In case it differs from our listening port there might be a proxy along the path.

Arguments

  • observed_addr - should be an address a remote observes you as, which can be obtained for example with the identify protocol.

pub fn local_peer_id(&self) -> &TPeerId[src]

Returns the peer id of the local node.

pub fn dial(
    &mut self,
    address: &Multiaddr,
    handler: THandler
) -> Result<ConnectionId, ConnectionLimit> where
    TInEvent: Send + 'static,
    TOutEvent: Send + 'static,
    TConnInfo: Send + 'static,
    TTrans: Transport<Output = (TConnInfo, TMuxer)>,
    TMuxer: Send + Sync + 'static,
    TPeerId: Send + 'static,
    <TTrans as Transport>::Error: Send,
    <TTrans as Transport>::Error: 'static,
    <TTrans as Transport>::Dial: Send,
    <TTrans as Transport>::Dial: 'static,
    <TMuxer as StreamMuxer>::OutboundSubstream: Send
[src]

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 = &TPeerId>[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: &TPeerId) -> bool[src]

Checks whether the network has an established connection to a peer.

pub fn is_dialing(&self, peer: &TPeerId) -> bool[src]

Checks whether the network has an ongoing dialing attempt to a peer.

pub fn is_disconnected(&self, peer: &TPeerId) -> 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 = &TPeerId>[src]

Returns a list of all the peers to whom a new outgoing connection is currently being established.

pub fn incoming_limit(&self) -> Option<usize>[src]

Gets the configured limit on pending incoming connections, i.e. concurrent incoming connection attempts.

pub fn num_connections_established(&self) -> usize[src]

The total number of established connections in the Network.

pub fn num_connections_pending(&self) -> usize[src]

The total number of pending connections in the Network.

pub fn peer(
    &mut self,
    peer_id: TPeerId
) -> Peer<'_, TTrans, TInEvent, TOutEvent, THandler, TConnInfo, TPeerId>
[src]

Obtains a view of a Peer with the given ID in the network.

pub fn accept(
    &mut self,
    connection: IncomingConnection<<TTrans as Transport>::ListenerUpgrade>,
    handler: THandler
) -> Result<ConnectionId, ConnectionLimit> where
    TInEvent: Send + 'static,
    TOutEvent: Send + 'static,
    TTrans: Transport<Output = (TConnInfo, TMuxer)>,
    TMuxer: StreamMuxer + Send + Sync + 'static,
    TPeerId: Send + 'static,
    <TMuxer as StreamMuxer>::OutboundSubstream: Send,
    <TTrans as Transport>::Error: Send,
    <TTrans as Transport>::Error: 'static,
    <TTrans as Transport>::ListenerUpgrade: Send,
    <TTrans as Transport>::ListenerUpgrade: 'static, 
[src]

Accepts a pending incoming connection obtained via NetworkEvent::IncomingConnection, adding it to the Networks 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 mut self,
    cx: &mut Context<'_>
) -> Poll<NetworkEvent<'a, TTrans, TInEvent, TOutEvent, THandler, TConnInfo, TPeerId>> where
    TInEvent: Send + 'static,
    TOutEvent: Send + 'static,
    THandler: IntoConnectionHandler<TConnInfo> + Send + 'static,
    TConnInfo: Clone,
    TTrans: Transport<Output = (TConnInfo, TMuxer)>,
    TMuxer: Send + Sync + 'static,
    TPeerId: Send + 'static,
    <TTrans as Transport>::Error: Send,
    <TTrans as Transport>::Error: 'static,
    <TTrans as Transport>::Dial: Send,
    <TTrans as Transport>::Dial: 'static,
    <TTrans as Transport>::ListenerUpgrade: Send,
    <TTrans as Transport>::ListenerUpgrade: 'static,
    <TMuxer as StreamMuxer>::OutboundSubstream: Send,
    <THandler as IntoConnectionHandler<TConnInfo>>::Handler: ConnectionHandler,
    <THandler as IntoConnectionHandler<TConnInfo>>::Handler: Send,
    <THandler as IntoConnectionHandler<TConnInfo>>::Handler: 'static,
    <<THandler as IntoConnectionHandler<TConnInfo>>::Handler as ConnectionHandler>::Error: Error,
    <<THandler as IntoConnectionHandler<TConnInfo>>::Handler as ConnectionHandler>::Error: Send,
    <<THandler as IntoConnectionHandler<TConnInfo>>::Handler as ConnectionHandler>::Error: 'static,
    <<THandler as IntoConnectionHandler<TConnInfo>>::Handler as ConnectionHandler>::Substream == SubstreamRef<Arc<TMuxer>>,
    <<THandler as IntoConnectionHandler<TConnInfo>>::Handler as ConnectionHandler>::InEvent == TInEvent,
    <<THandler as IntoConnectionHandler<TConnInfo>>::Handler as ConnectionHandler>::OutEvent == TOutEvent, 
[src]

Provides an API similar to Stream, except that it cannot error.

Trait Implementations

impl<TTrans, TInEvent, TOutEvent, THandler, TConnInfo, TPeerId> Debug for Network<TTrans, TInEvent, TOutEvent, THandler, TConnInfo, TPeerId> where
    THandler: Debug + ConnectionHandler,
    TConnInfo: Debug,
    TTrans: Debug + Transport,
    TPeerId: Debug + Eq + Hash
[src]

impl<TTrans, TInEvent, TOutEvent, THandler, TConnInfo, TPeerId> Unpin for Network<TTrans, TInEvent, TOutEvent, THandler, TConnInfo, TPeerId> where
    THandler: IntoConnectionHandler<TConnInfo>,
    TTrans: Transport
[src]

Auto Trait Implementations

impl<TTrans, TInEvent, TOutEvent, THandler, TConnInfo = PeerId, TPeerId = PeerId> !RefUnwindSafe for Network<TTrans, TInEvent, TOutEvent, THandler, TConnInfo, TPeerId>

impl<TTrans, TInEvent, TOutEvent, THandler, TConnInfo, TPeerId> Send for Network<TTrans, TInEvent, TOutEvent, THandler, TConnInfo, TPeerId> where
    TConnInfo: Send,
    THandler: Send,
    TInEvent: Send,
    TOutEvent: Send,
    TPeerId: Send,
    TTrans: Send,
    <TTrans as Transport>::Error: Send,
    <<THandler as IntoConnectionHandler<TConnInfo>>::Handler as ConnectionHandler>::Error: Send,
    <TTrans as Transport>::Listener: Send

impl<TTrans, TInEvent, TOutEvent, THandler, TConnInfo = PeerId, TPeerId = PeerId> !Sync for Network<TTrans, TInEvent, TOutEvent, THandler, TConnInfo, TPeerId>

impl<TTrans, TInEvent, TOutEvent, THandler, TConnInfo = PeerId, TPeerId = PeerId> !UnwindSafe for Network<TTrans, TInEvent, TOutEvent, THandler, TConnInfo, TPeerId>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T[src]

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[src]