Struct libp2p_swarm::ExpandedSwarm[][src]

pub struct ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler> where
    THandler: IntoProtocolsHandler
{ /* fields omitted */ }

Contains the state of the network, plus the way it should behave.

Implementations

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, 
[src]

pub fn new(
    transport: Boxed<(PeerId, StreamMuxerBox)>,
    behaviour: TBehaviour,
    local_peer_id: PeerId
) -> Self
[src]

Builds a new Swarm.

pub fn network_info(me: &Self) -> NetworkInfo[src]

Returns information about the Network underlying the Swarm.

pub fn listen_on(
    me: &mut Self,
    addr: Multiaddr
) -> Result<ListenerId, TransportError<Error>>
[src]

Starts listening on the given address.

Returns an error if the address is not supported.

pub fn remove_listener(me: &mut Self, id: ListenerId) -> Result<(), ()>[src]

Remove some listener.

Returns Ok(()) if there was a listener with this ID.

pub fn dial_addr(me: &mut Self, addr: Multiaddr) -> Result<(), ConnectionLimit>[src]

Initiates a new dialing attempt to the given address.

pub fn dial(me: &mut Self, peer_id: &PeerId) -> Result<(), DialError>[src]

Initiates a new dialing attempt to the given peer.

pub fn listeners(me: &Self) -> impl Iterator<Item = &Multiaddr>[src]

Returns an iterator that produces the list of addresses we're listening on.

pub fn local_peer_id(me: &Self) -> &PeerId[src]

Returns the peer ID of the swarm passed as parameter.

pub fn external_addresses(me: &Self) -> impl Iterator<Item = &AddressRecord>[src]

Returns an iterator for AddressRecords of external addresses of the local node, in decreasing order of their current score.

pub fn add_external_address(
    me: &mut Self,
    a: Multiaddr,
    s: AddressScore
) -> AddAddressResult
[src]

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.

pub fn remove_external_address(me: &mut Self, addr: &Multiaddr) -> bool[src]

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.

pub fn ban_peer_id(me: &mut Self, peer_id: PeerId)[src]

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.

pub fn unban_peer_id(me: &mut Self, peer_id: PeerId)[src]

Unbans a peer.

pub fn is_connected(me: &Self, peer_id: &PeerId) -> bool[src]

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

pub async fn next_event(
    &mut self
) -> SwarmEvent<TBehaviour::OutEvent, THandleErr>
[src]

Returns the next event that happens in the Swarm.

Includes events from the NetworkBehaviour but also events about the connections status.

pub async fn next(&mut self) -> TBehaviour::OutEvent[src]

Returns the next event produced by the NetworkBehaviour.

Trait Implementations

impl<TBehaviour, TInEvent, TOutEvent, THandler> Deref for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler> where
    THandler: IntoProtocolsHandler
[src]

type Target = TBehaviour

The resulting type after dereferencing.

impl<TBehaviour, TInEvent, TOutEvent, THandler> DerefMut for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler> where
    THandler: IntoProtocolsHandler
[src]

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>, 
[src]

the stream of behaviour events never terminates, so we can implement fused for it

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>, 
[src]

type Item = TBehaviour::OutEvent

Values yielded by the stream.

impl<TBehaviour, TInEvent, TOutEvent, THandler> Unpin for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler> where
    THandler: IntoProtocolsHandler
[src]

Auto Trait Implementations

impl<TBehaviour, TInEvent, TOutEvent, THandler> !RefUnwindSafe for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>[src]

impl<TBehaviour, TInEvent, TOutEvent, THandler> Send for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler> where
    TBehaviour: Send,
    TInEvent: Send,
    TOutEvent: Send
[src]

impl<TBehaviour, TInEvent, TOutEvent, THandler> !Sync for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>[src]

impl<TBehaviour, TInEvent, TOutEvent, THandler> !UnwindSafe for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler>[src]

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

type Output = T

Should always be Self

impl<T> StreamExt for T where
    T: Stream + ?Sized

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<S, T, E> TryStream for S where
    S: Stream<Item = Result<T, E>> + ?Sized

type Ok = T

The type of successful values yielded by this future

type Error = E

The type of failures yielded by this future

impl<S> TryStreamExt for S where
    S: TryStream + ?Sized

impl<S> TryStreamExt for S where
    S: TryStream, 
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,