pub struct ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>where
THandler: IntoProtocolsHandler,{ /* private fields */ }
Expand description
Contains the state of the network, plus the way it should behave.
Implementations§
Source§impl<TBehaviour, TInEvent, TOutEvent, THandler, THandleErr> ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>where
TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
TInEvent: Send + 'static,
TOutEvent: Send + 'static,
THandler: IntoProtocolsHandler + Send + 'static,
THandler::Handler: ProtocolsHandler<InEvent = TInEvent, OutEvent = TOutEvent, Error = THandleErr>,
THandleErr: Error + Send + 'static,
impl<TBehaviour, TInEvent, TOutEvent, THandler, THandleErr> ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>where
TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
TInEvent: Send + 'static,
TOutEvent: Send + 'static,
THandler: IntoProtocolsHandler + Send + 'static,
THandler::Handler: ProtocolsHandler<InEvent = TInEvent, OutEvent = TOutEvent, Error = THandleErr>,
THandleErr: Error + Send + 'static,
Sourcepub fn new(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId,
) -> Self
pub fn new( transport: Boxed<(PeerId, StreamMuxerBox)>, behaviour: TBehaviour, local_peer_id: PeerId, ) -> Self
Builds a new Swarm
.
Sourcepub fn network_info(me: &Self) -> NetworkInfo
pub fn network_info(me: &Self) -> NetworkInfo
Returns information about the Network
underlying the Swarm
.
Sourcepub fn listen_on(
me: &mut Self,
addr: Multiaddr,
) -> Result<ListenerId, TransportError<Error>>
pub fn listen_on( me: &mut Self, addr: Multiaddr, ) -> Result<ListenerId, TransportError<Error>>
Starts listening on the given address.
Returns an error if the address is not supported.
Sourcepub fn remove_listener(me: &mut Self, id: ListenerId) -> Result<(), ()>
pub fn remove_listener(me: &mut Self, id: ListenerId) -> Result<(), ()>
Remove some listener.
Returns Ok(())
if there was a listener with this ID.
Sourcepub fn dial_addr(me: &mut Self, addr: Multiaddr) -> Result<(), ConnectionLimit>
pub fn dial_addr(me: &mut Self, addr: Multiaddr) -> Result<(), ConnectionLimit>
Initiates a new dialing attempt to the given address.
Sourcepub fn dial(me: &mut Self, peer_id: &PeerId) -> Result<(), DialError>
pub fn dial(me: &mut Self, peer_id: &PeerId) -> Result<(), DialError>
Initiates a new dialing attempt to the given peer.
Sourcepub fn listeners(me: &Self) -> impl Iterator<Item = &Multiaddr>
pub fn listeners(me: &Self) -> impl Iterator<Item = &Multiaddr>
Returns an iterator that produces the list of addresses we’re listening on.
Sourcepub fn local_peer_id(me: &Self) -> &PeerId
pub fn local_peer_id(me: &Self) -> &PeerId
Returns the peer ID of the swarm passed as parameter.
Sourcepub fn external_addresses(me: &Self) -> impl Iterator<Item = &AddressRecord>
pub fn external_addresses(me: &Self) -> impl Iterator<Item = &AddressRecord>
Returns an iterator for AddressRecord
s of external addresses
of the local node, in decreasing order of their current
score.
Sourcepub fn add_external_address(
me: &mut Self,
a: Multiaddr,
s: AddressScore,
) -> AddAddressResult
pub fn add_external_address( me: &mut Self, a: Multiaddr, s: AddressScore, ) -> AddAddressResult
Adds an external address record for the local node.
An external address is an address of the local node known to
be (likely) reachable for other nodes, possibly taking into
account NAT. The external addresses of the local node may be
shared with other nodes by the NetworkBehaviour
.
The associated score determines both the position of the address
in the list of external addresses (which can determine the
order in which addresses are used to connect to) as well as
how long the address is retained in the list, depending on
how frequently it is reported by the NetworkBehaviour
via
NetworkBehaviourAction::ReportObservedAddr
or explicitly
through this method.
Sourcepub fn remove_external_address(me: &mut Self, addr: &Multiaddr) -> bool
pub fn remove_external_address(me: &mut Self, addr: &Multiaddr) -> bool
Removes an external address of the local node, regardless of
its current score. See ExpandedSwarm::add_external_address
for details.
Returns true
if the address existed and was removed, false
otherwise.
Sourcepub fn ban_peer_id(me: &mut Self, peer_id: PeerId)
pub fn ban_peer_id(me: &mut Self, peer_id: PeerId)
Bans a peer by its peer ID.
Any incoming connection and any dialing attempt will immediately be rejected. This function has no effect if the peer is already banned.
Sourcepub fn unban_peer_id(me: &mut Self, peer_id: PeerId)
pub fn unban_peer_id(me: &mut Self, peer_id: PeerId)
Unbans a peer.
Sourcepub fn is_connected(me: &Self, peer_id: &PeerId) -> bool
pub fn is_connected(me: &Self, peer_id: &PeerId) -> bool
Checks whether the Network
has an established connection to a peer.
Sourcepub fn is_dialing(me: &Self, peer_id: &PeerId) -> bool
pub fn is_dialing(me: &Self, peer_id: &PeerId) -> bool
Checks whether the Network
dealing to the peer.
Sourcepub async fn next_event(
&mut self,
) -> SwarmEvent<TBehaviour::OutEvent, THandleErr>
pub async fn next_event( &mut self, ) -> SwarmEvent<TBehaviour::OutEvent, THandleErr>
Returns the next event that happens in the Swarm
.
Includes events from the NetworkBehaviour
but also events about the connections status.
Sourcepub async fn next(&mut self) -> TBehaviour::OutEvent
pub async fn next(&mut self) -> TBehaviour::OutEvent
Returns the next event produced by the NetworkBehaviour
.
pub fn disconnect_peer(&mut self, peer_id: &PeerId)
pub fn get_behaviour(&mut self) -> &mut TBehaviour
Trait Implementations§
Source§impl<TBehaviour, TInEvent, TOutEvent, THandler> Deref for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>where
THandler: IntoProtocolsHandler,
impl<TBehaviour, TInEvent, TOutEvent, THandler> Deref for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>where
THandler: IntoProtocolsHandler,
Source§impl<TBehaviour, TInEvent, TOutEvent, THandler> DerefMut for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>where
THandler: IntoProtocolsHandler,
impl<TBehaviour, TInEvent, TOutEvent, THandler> DerefMut for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>where
THandler: IntoProtocolsHandler,
Source§impl<TBehaviour, TInEvent, TOutEvent, THandler> FusedStream for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>where
TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
THandler: IntoProtocolsHandler + Send + 'static,
TInEvent: Send + 'static,
TOutEvent: Send + 'static,
THandler::Handler: ProtocolsHandler<InEvent = TInEvent, OutEvent = TOutEvent>,
the stream of behaviour events never terminates, so we can implement fused for it
impl<TBehaviour, TInEvent, TOutEvent, THandler> FusedStream for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>where
TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
THandler: IntoProtocolsHandler + Send + 'static,
TInEvent: Send + 'static,
TOutEvent: Send + 'static,
THandler::Handler: ProtocolsHandler<InEvent = TInEvent, OutEvent = TOutEvent>,
the stream of behaviour events never terminates, so we can implement fused for it
Source§fn is_terminated(&self) -> bool
fn is_terminated(&self) -> bool
true
if the stream should no longer be polled.Source§impl<TBehaviour, TInEvent, TOutEvent, THandler> Stream for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>where
TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
THandler: IntoProtocolsHandler + Send + 'static,
TInEvent: Send + 'static,
TOutEvent: Send + 'static,
THandler::Handler: ProtocolsHandler<InEvent = TInEvent, OutEvent = TOutEvent>,
impl<TBehaviour, TInEvent, TOutEvent, THandler> Stream for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>where
TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
THandler: IntoProtocolsHandler + Send + 'static,
TInEvent: Send + 'static,
TOutEvent: Send + 'static,
THandler::Handler: ProtocolsHandler<InEvent = TInEvent, OutEvent = TOutEvent>,
Source§type Item = <TBehaviour as NetworkBehaviour>::OutEvent
type Item = <TBehaviour as NetworkBehaviour>::OutEvent
impl<TBehaviour, TInEvent, TOutEvent, THandler> Unpin for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>where
THandler: IntoProtocolsHandler,
Auto Trait Implementations§
impl<TBehaviour, TInEvent, TOutEvent, THandler> !Freeze for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>
impl<TBehaviour, TInEvent, TOutEvent, THandler> !RefUnwindSafe for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>
impl<TBehaviour, TInEvent, TOutEvent, THandler> Send for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>
impl<TBehaviour, TInEvent, TOutEvent, THandler> !Sync for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>
impl<TBehaviour, TInEvent, TOutEvent, THandler> !UnwindSafe for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> StreamExt for T
impl<T> StreamExt for T
Source§fn next(&mut self) -> Next<'_, Self>where
Self: Unpin,
fn next(&mut self) -> Next<'_, Self>where
Self: Unpin,
Source§fn into_future(self) -> StreamFuture<Self>
fn into_future(self) -> StreamFuture<Self>
Source§fn map<T, F>(self, f: F) -> Map<Self, F>
fn map<T, F>(self, f: F) -> Map<Self, F>
Source§fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
Source§fn filter<Fut, F>(self, f: F) -> Filter<Self, Fut, F>
fn filter<Fut, F>(self, f: F) -> Filter<Self, Fut, F>
Source§fn filter_map<Fut, T, F>(self, f: F) -> FilterMap<Self, Fut, F>
fn filter_map<Fut, T, F>(self, f: F) -> FilterMap<Self, Fut, F>
Source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
Source§fn collect<C>(self) -> Collect<Self, C>
fn collect<C>(self) -> Collect<Self, C>
Source§fn unzip<A, B, FromA, FromB>(self) -> Unzip<Self, FromA, FromB>
fn unzip<A, B, FromA, FromB>(self) -> Unzip<Self, FromA, FromB>
Source§fn concat(self) -> Concat<Self>
fn concat(self) -> Concat<Self>
Source§fn count(self) -> Count<Self>where
Self: Sized,
fn count(self) -> Count<Self>where
Self: Sized,
Source§fn fold<T, Fut, F>(self, init: T, f: F) -> Fold<Self, Fut, T, F>
fn fold<T, Fut, F>(self, init: T, f: F) -> Fold<Self, Fut, T, F>
Source§fn any<Fut, F>(self, f: F) -> Any<Self, Fut, F>
fn any<Fut, F>(self, f: F) -> Any<Self, Fut, F>
true
if any element in stream satisfied a predicate. Read moreSource§fn all<Fut, F>(self, f: F) -> All<Self, Fut, F>
fn all<Fut, F>(self, f: F) -> All<Self, Fut, F>
true
if all element in stream satisfied a predicate. Read moreSource§fn flatten(self) -> Flatten<Self>
fn flatten(self) -> Flatten<Self>
Source§fn flatten_unordered(
self,
limit: impl Into<Option<usize>>,
) -> FlattenUnorderedWithFlowController<Self, ()>
fn flatten_unordered( self, limit: impl Into<Option<usize>>, ) -> FlattenUnorderedWithFlowController<Self, ()>
Source§fn flat_map_unordered<U, F>(
self,
limit: impl Into<Option<usize>>,
f: F,
) -> FlatMapUnordered<Self, U, F>
fn flat_map_unordered<U, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> FlatMapUnordered<Self, U, F>
StreamExt::map
but flattens nested Stream
s
and polls them concurrently, yielding items in any order, as they made
available. Read moreSource§fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>
fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>
StreamExt::fold
that holds internal state
and produces a new stream. Read moreSource§fn skip_while<Fut, F>(self, f: F) -> SkipWhile<Self, Fut, F>
fn skip_while<Fut, F>(self, f: F) -> SkipWhile<Self, Fut, F>
true
. Read moreSource§fn take_while<Fut, F>(self, f: F) -> TakeWhile<Self, Fut, F>
fn take_while<Fut, F>(self, f: F) -> TakeWhile<Self, Fut, F>
true
. Read moreSource§fn take_until<Fut>(self, fut: Fut) -> TakeUntil<Self, Fut>
fn take_until<Fut>(self, fut: Fut) -> TakeUntil<Self, Fut>
Source§fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F>
fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F>
Source§fn for_each_concurrent<Fut, F>(
self,
limit: impl Into<Option<usize>>,
f: F,
) -> ForEachConcurrent<Self, Fut, F>
fn for_each_concurrent<Fut, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> ForEachConcurrent<Self, Fut, F>
Source§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
n
items of the underlying stream. Read moreSource§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
n
items of the underlying stream. Read moreSource§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
Source§fn boxed<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a>>
fn boxed<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a>>
Source§fn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a>>where
Self: Sized + 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a>>where
Self: Sized + 'a,
Source§fn buffered(self, n: usize) -> Buffered<Self>
fn buffered(self, n: usize) -> Buffered<Self>
Source§fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>
Source§fn zip<St>(self, other: St) -> Zip<Self, St>
fn zip<St>(self, other: St) -> Zip<Self, St>
Source§fn peekable(self) -> Peekable<Self>where
Self: Sized,
fn peekable(self) -> Peekable<Self>where
Self: Sized,
peek
method. Read moreSource§fn chunks(self, capacity: usize) -> Chunks<Self>where
Self: Sized,
fn chunks(self, capacity: usize) -> Chunks<Self>where
Self: Sized,
Source§fn ready_chunks(self, capacity: usize) -> ReadyChunks<Self>where
Self: Sized,
fn ready_chunks(self, capacity: usize) -> ReadyChunks<Self>where
Self: Sized,
Source§fn forward<S>(self, sink: S) -> Forward<Self, S>
fn forward<S>(self, sink: S) -> Forward<Self, S>
Source§fn split<Item>(self) -> (SplitSink<Self, Item>, SplitStream<Self>)
fn split<Item>(self) -> (SplitSink<Self, Item>, SplitStream<Self>)
Source§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Source§fn left_stream<B>(self) -> Either<Self, B>
fn left_stream<B>(self) -> Either<Self, B>
Source§fn right_stream<B>(self) -> Either<B, Self>
fn right_stream<B>(self) -> Either<B, Self>
Source§fn poll_next_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>where
Self: Unpin,
fn poll_next_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>where
Self: Unpin,
Stream::poll_next
on Unpin
stream types.Source§fn select_next_some(&mut self) -> SelectNextSome<'_, Self>where
Self: Unpin + FusedStream,
fn select_next_some(&mut self) -> SelectNextSome<'_, Self>where
Self: Unpin + FusedStream,
Source§impl<S> TryStreamExt for S
impl<S> TryStreamExt for S
Source§fn err_into<E>(self) -> ErrInto<Self, E>
fn err_into<E>(self) -> ErrInto<Self, E>
Source§fn map_ok<T, F>(self, f: F) -> MapOk<Self, F>
fn map_ok<T, F>(self, f: F) -> MapOk<Self, F>
Source§fn map_err<E, F>(self, f: F) -> MapErr<Self, F>
fn map_err<E, F>(self, f: F) -> MapErr<Self, F>
Source§fn and_then<Fut, F>(self, f: F) -> AndThen<Self, Fut, F>
fn and_then<Fut, F>(self, f: F) -> AndThen<Self, Fut, F>
f
. Read moreSource§fn or_else<Fut, F>(self, f: F) -> OrElse<Self, Fut, F>
fn or_else<Fut, F>(self, f: F) -> OrElse<Self, Fut, F>
f
. Read moreSource§fn inspect_ok<F>(self, f: F) -> InspectOk<Self, F>
fn inspect_ok<F>(self, f: F) -> InspectOk<Self, F>
Source§fn inspect_err<F>(self, f: F) -> InspectErr<Self, F>
fn inspect_err<F>(self, f: F) -> InspectErr<Self, F>
Source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
Source§fn try_next(&mut self) -> TryNext<'_, Self>where
Self: Unpin,
fn try_next(&mut self) -> TryNext<'_, Self>where
Self: Unpin,
Source§fn try_for_each<Fut, F>(self, f: F) -> TryForEach<Self, Fut, F>
fn try_for_each<Fut, F>(self, f: F) -> TryForEach<Self, Fut, F>
Source§fn try_skip_while<Fut, F>(self, f: F) -> TrySkipWhile<Self, Fut, F>
fn try_skip_while<Fut, F>(self, f: F) -> TrySkipWhile<Self, Fut, F>
true
. Read moreSource§fn try_take_while<Fut, F>(self, f: F) -> TryTakeWhile<Self, Fut, F>
fn try_take_while<Fut, F>(self, f: F) -> TryTakeWhile<Self, Fut, F>
true
. Read moreSource§fn try_for_each_concurrent<Fut, F>(
self,
limit: impl Into<Option<usize>>,
f: F,
) -> TryForEachConcurrent<Self, Fut, F>
fn try_for_each_concurrent<Fut, F>( self, limit: impl Into<Option<usize>>, f: F, ) -> TryForEachConcurrent<Self, Fut, F>
Source§fn try_collect<C>(self) -> TryCollect<Self, C>
fn try_collect<C>(self) -> TryCollect<Self, C>
Source§fn try_chunks(self, capacity: usize) -> TryChunks<Self>where
Self: Sized,
fn try_chunks(self, capacity: usize) -> TryChunks<Self>where
Self: Sized,
Source§fn try_ready_chunks(self, capacity: usize) -> TryReadyChunks<Self>where
Self: Sized,
fn try_ready_chunks(self, capacity: usize) -> TryReadyChunks<Self>where
Self: Sized,
Source§fn try_filter<Fut, F>(self, f: F) -> TryFilter<Self, Fut, F>
fn try_filter<Fut, F>(self, f: F) -> TryFilter<Self, Fut, F>
Source§fn try_filter_map<Fut, F, T>(self, f: F) -> TryFilterMap<Self, Fut, F>
fn try_filter_map<Fut, F, T>(self, f: F) -> TryFilterMap<Self, Fut, F>
Source§fn try_flatten_unordered(
self,
limit: impl Into<Option<usize>>,
) -> TryFlattenUnordered<Self>
fn try_flatten_unordered( self, limit: impl Into<Option<usize>>, ) -> TryFlattenUnordered<Self>
Source§fn try_flatten(self) -> TryFlatten<Self>
fn try_flatten(self) -> TryFlatten<Self>
Source§fn try_fold<T, Fut, F>(self, init: T, f: F) -> TryFold<Self, Fut, T, F>
fn try_fold<T, Fut, F>(self, init: T, f: F) -> TryFold<Self, Fut, T, F>
Source§fn try_concat(self) -> TryConcat<Self>
fn try_concat(self) -> TryConcat<Self>
Source§fn try_buffer_unordered(self, n: usize) -> TryBufferUnordered<Self>
fn try_buffer_unordered(self, n: usize) -> TryBufferUnordered<Self>
Source§fn try_buffered(self, n: usize) -> TryBuffered<Self>
fn try_buffered(self, n: usize) -> TryBuffered<Self>
Source§fn try_poll_next_unpin(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Self::Ok, Self::Error>>>where
Self: Unpin,
fn try_poll_next_unpin(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Option<Result<Self::Ok, Self::Error>>>where
Self: Unpin,
TryStream::try_poll_next
on Unpin
stream types.Source§fn into_async_read(self) -> IntoAsyncRead<Self>
fn into_async_read(self) -> IntoAsyncRead<Self>
AsyncBufRead
. Read moreSource§fn try_all<Fut, F>(self, f: F) -> TryAll<Self, Fut, F>
fn try_all<Fut, F>(self, f: F) -> TryAll<Self, Fut, F>
Err
is encountered or if an Ok
item is found
that does not satisfy the predicate. Read more