Struct libp2p_core::nodes::collection::CollectionStream
source · pub struct CollectionStream<TInEvent, TOutEvent, THandler, TReachErr, THandlerErr> { /* private fields */ }Expand description
Implementation of Stream that handles a collection of nodes.
Implementations
sourceimpl<TInEvent, TOutEvent, THandler, TReachErr, THandlerErr> CollectionStream<TInEvent, TOutEvent, THandler, TReachErr, THandlerErr>
impl<TInEvent, TOutEvent, THandler, TReachErr, THandlerErr> CollectionStream<TInEvent, TOutEvent, THandler, TReachErr, THandlerErr>
sourcepub fn add_reach_attempt<TFut, TMuxer>(
&mut self,
future: TFut,
handler: THandler
) -> ReachAttemptIdwhere
TFut: Future<Item = (PeerId, TMuxer), Error = TReachErr> + Send + 'static,
THandler: NodeHandler<Substream = Substream<TMuxer>, InEvent = TInEvent, OutEvent = TOutEvent, Error = THandlerErr> + Send + 'static,
TReachErr: Error + Send + 'static,
THandlerErr: Error + Send + 'static,
TInEvent: Send + 'static,
TOutEvent: Send + 'static,
THandler::OutboundOpenInfo: Send + 'static,
TMuxer: StreamMuxer + Send + Sync + 'static,
TMuxer::OutboundSubstream: Send + 'static,
pub fn add_reach_attempt<TFut, TMuxer>(
&mut self,
future: TFut,
handler: THandler
) -> ReachAttemptIdwhere
TFut: Future<Item = (PeerId, TMuxer), Error = TReachErr> + Send + 'static,
THandler: NodeHandler<Substream = Substream<TMuxer>, InEvent = TInEvent, OutEvent = TOutEvent, Error = THandlerErr> + Send + 'static,
TReachErr: Error + Send + 'static,
THandlerErr: Error + Send + 'static,
TInEvent: Send + 'static,
TOutEvent: Send + 'static,
THandler::OutboundOpenInfo: Send + 'static,
TMuxer: StreamMuxer + Send + Sync + 'static,
TMuxer::OutboundSubstream: Send + 'static,
Adds to the collection a future that tries to reach a remote.
This method spawns a task dedicated to resolving this future and processing the node’s events.
sourcepub fn interrupt(&mut self, id: ReachAttemptId) -> Result<(), InterruptError>
pub fn interrupt(&mut self, id: ReachAttemptId) -> Result<(), InterruptError>
Interrupts a reach attempt.
Returns Ok if something was interrupted, and Err if the ID is not or no longer valid.
sourcepub fn broadcast_event(&mut self, event: &TInEvent)where
TInEvent: Clone,
pub fn broadcast_event(&mut self, event: &TInEvent)where
TInEvent: Clone,
Sends an event to all nodes.
sourcepub fn peer_mut(&mut self, id: &PeerId) -> Option<PeerMut<'_, TInEvent>>
pub fn peer_mut(&mut self, id: &PeerId) -> Option<PeerMut<'_, TInEvent>>
Grants access to an object that allows controlling a peer of the collection.
Returns None if we don’t have a connection to this peer.
sourcepub fn has_connection(&self, id: &PeerId) -> bool
pub fn has_connection(&self, id: &PeerId) -> bool
Returns true if we are connected to the given peer.
This will return true only after a NodeReached event has been produced by poll().
sourcepub fn connections(&self) -> impl Iterator<Item = &PeerId>
pub fn connections(&self) -> impl Iterator<Item = &PeerId>
Returns a list of all the active connections.
Does not include reach attempts that haven’t reached any target yet.
sourcepub fn poll(
&mut self
) -> Async<CollectionEvent<'_, TInEvent, TOutEvent, THandler, TReachErr, THandlerErr>>
pub fn poll(
&mut self
) -> Async<CollectionEvent<'_, TInEvent, TOutEvent, THandler, TReachErr, THandlerErr>>
Provides an API similar to Stream, except that it cannot error.
Note: we use a regular
pollmethod instead of implementingStreamin order to remove theErrvariant, but also because we want theCollectionStreamto stay borrowed if necessary.