[][src]Struct libp2p_swarm::ExpandedSwarm

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

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

Methods

impl<TBehaviour, TInEvent, TOutEvent, THandler, TConnInfo, THandleErr> ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler, TConnInfo> where
    TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
    TInEvent: Clone + Send + 'static,
    TOutEvent: Send + 'static,
    TConnInfo: ConnectionInfo<PeerId = PeerId> + Debug + Clone + Send + 'static,
    THandler: IntoProtocolsHandler + Send + 'static,
    THandler::Handler: ProtocolsHandler<InEvent = TInEvent, OutEvent = TOutEvent, Error = THandleErr>,
    THandleErr: Error + Send + 'static, 
[src]

pub fn new<TTransport, TMuxer>(
    transport: TTransport,
    behaviour: TBehaviour,
    local_peer_id: PeerId
) -> Self where
    TMuxer: StreamMuxer + Send + Sync + 'static,
    TMuxer::OutboundSubstream: Send + 'static,
    <TMuxer as StreamMuxer>::OutboundSubstream: Send + 'static,
    <TMuxer as StreamMuxer>::Substream: Send + 'static,
    TTransport: Transport<Output = (TConnInfo, TMuxer)> + Clone + Send + Sync + 'static,
    TTransport::Error: Send + Sync + 'static,
    TTransport::Listener: Send + 'static,
    TTransport::ListenerUpgrade: Send + 'static,
    TTransport::Dial: Send + 'static, 
[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]

Tries to dial the given address.

Returns an error if the address is not supported.

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

Tries to initiate a dialing attempt to the given peer.

If a new dialing attempt has been initiated, Ok(true) is returned.

If there is an ongoing dialing attempt, the current addresses of the peer, as reported by NetworkBehaviour::addresses_of_peer are added to the ongoing dialing attempt, ignoring duplicates. In this case no new dialing attempt is initiated.

If no new dialing attempt has been initiated, meaning there is an ongoing dialing attempt or addresses_of_peer reports no addresses, Ok(false) is returned.

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 external_addresses(me: &Self) -> impl Iterator<Item = &Multiaddr>[src]

Returns an iterator that produces the list of addresses that other nodes can use to reach us.

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

Returns the peer ID of the swarm passed as parameter.

pub fn add_external_address(me: &mut Self, addr: Multiaddr)[src]

Adds an external address.

An external address is an address we are listening on but that accounts for things such as NAT traversal.

pub fn connection_info(me: &mut Self, peer_id: &PeerId) -> Option<TConnInfo>[src]

Returns the connection info for an arbitrary connection with the peer, or None if there is no connection to that peer.

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 is the peer is already banned.

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

Unbans 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, TConnInfo> Deref for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler, TConnInfo> where
    THandler: IntoProtocolsHandler,
    TConnInfo: ConnectionInfo<PeerId = PeerId>, 
[src]

type Target = TBehaviour

The resulting type after dereferencing.

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

impl<TBehaviour, TInEvent, TOutEvent, THandler, TConnInfo> FusedStream for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler, TConnInfo> where
    TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
    THandler: IntoProtocolsHandler + Send + 'static,
    TInEvent: Clone + Send + 'static,
    TOutEvent: Send + 'static,
    THandler::Handler: ProtocolsHandler<InEvent = TInEvent, OutEvent = TOutEvent>,
    TConnInfo: ConnectionInfo<PeerId = PeerId> + Debug + Clone + Send + 'static, 
[src]

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

impl<TBehaviour, TInEvent, TOutEvent, THandler, TConnInfo> Stream for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler, TConnInfo> where
    TBehaviour: NetworkBehaviour<ProtocolsHandler = THandler>,
    THandler: IntoProtocolsHandler + Send + 'static,
    TInEvent: Clone + Send + 'static,
    TOutEvent: Send + 'static,
    THandler::Handler: ProtocolsHandler<InEvent = TInEvent, OutEvent = TOutEvent>,
    TConnInfo: ConnectionInfo<PeerId = PeerId> + Debug + Clone + Send + 'static, 
[src]

type Item = TBehaviour::OutEvent

Values yielded by the stream.

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

Auto Trait Implementations

impl<TBehaviour, TInEvent, TOutEvent, THandler, TConnInfo = PeerId> !RefUnwindSafe for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler, TConnInfo>

impl<TBehaviour, TInEvent, TOutEvent, THandler, TConnInfo> Send for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler, TConnInfo> where
    TBehaviour: Send,
    TConnInfo: Send,
    TInEvent: Send,
    TOutEvent: Send,
    <<THandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::Error: Send,
    <THandler as IntoProtocolsHandler>::Handler: ProtocolsHandler

impl<TBehaviour, TInEvent, TOutEvent, THandler, TConnInfo = PeerId> !Sync for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler, TConnInfo>

impl<TBehaviour, TInEvent, TOutEvent, THandler, TConnInfo = PeerId> !UnwindSafe for ExpandedSwarm<TBehaviour, TInEvent, TOutEvent, THandler, TConnInfo>

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

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

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

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

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