pub enum ToSwarm<TOutEvent, TInEvent> {
GenerateEvent(TOutEvent),
Dial {
opts: DialOpts,
},
ListenOn {
opts: ListenOpts,
},
RemoveListener {
id: ListenerId,
},
NotifyHandler {
peer_id: PeerId,
handler: NotifyHandler,
event: TInEvent,
},
NewExternalAddrCandidate(Multiaddr),
ExternalAddrConfirmed(Multiaddr),
ExternalAddrExpired(Multiaddr),
CloseConnection {
peer_id: PeerId,
connection: CloseConnection,
},
}
Expand description
A command issued from a NetworkBehaviour
for the Swarm
.
Variants§
GenerateEvent(TOutEvent)
Instructs the Swarm
to return an event when it is being polled.
Dial
Instructs the swarm to start a dial.
On success, NetworkBehaviour::on_swarm_event
with ConnectionEstablished
is invoked.
On failure, NetworkBehaviour::on_swarm_event
with DialFailure
is invoked.
DialOpts
provides access to the ConnectionId
via DialOpts::connection_id
.
This ConnectionId
will be used throughout the connection’s lifecycle to associate events with it.
This allows a NetworkBehaviour
to identify a connection that resulted out of its own dial request.
ListenOn
Instructs the Swarm
to listen on the provided address.
Fields
opts: ListenOpts
RemoveListener
Instructs the Swarm
to remove the listener.
Fields
id: ListenerId
NotifyHandler
Instructs the Swarm
to send an event to the handler dedicated to a
connection with a peer.
If the Swarm
is connected to the peer, the message is delivered to the ConnectionHandler
instance identified by the peer ID and connection ID.
If the specified connection no longer exists, the event is silently dropped.
Typically the connection ID given is the same as the one passed to
NetworkBehaviour::on_connection_handler_event
, i.e. whenever the behaviour wishes to
respond to a request on the same connection (and possibly the same
substream, as per the implementation of ConnectionHandler
).
Note that even if the peer is currently connected, connections can get closed at any time and thus the event may not reach a handler.
Fields
peer_id: PeerId
The peer for whom a ConnectionHandler
should be notified.
handler: NotifyHandler
The options w.r.t. which connection handler to notify of the event.
event: TInEvent
The event to send.
NewExternalAddrCandidate(Multiaddr)
Reports a new candidate for an external address to the Swarm
.
This address will be shared with all NetworkBehaviour
s via FromSwarm::NewExternalAddrCandidate
.
This address could come from a variety of sources:
- A protocol such as identify obtained it from a remote.
- The user provided it based on configuration.
- We made an educated guess based on one of our listen addresses.
- We established a new relay connection.
ExternalAddrConfirmed(Multiaddr)
Indicates to the Swarm
that the provided address is confirmed to be externally reachable.
This is intended to be issued in response to a FromSwarm::NewExternalAddrCandidate
if we are indeed externally reachable on this address.
This address will be shared with all NetworkBehaviour
s via FromSwarm::ExternalAddrConfirmed
.
ExternalAddrExpired(Multiaddr)
Indicates to the Swarm
that we are no longer externally reachable under the provided address.
This expires an address that was earlier confirmed via ToSwarm::ExternalAddrConfirmed
.
This address will be shared with all NetworkBehaviour
s via FromSwarm::ExternalAddrExpired
.
CloseConnection
Instructs the Swarm
to initiate a graceful close of one or all connections
with the given peer.
Note: Closing a connection via
ToSwarm::CloseConnection
does not inform the
corresponding ConnectionHandler
.
Closing a connection via a ConnectionHandler
can be done
either in a collaborative manner across ConnectionHandler
s
with ConnectionHandler::connection_keep_alive
or directly with
ConnectionHandlerEvent::Close
.
Fields
connection: CloseConnection
Whether to close a specific or all connections to the given peer.
Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<TOutEvent, TInEvent> Freeze for ToSwarm<TOutEvent, TInEvent>
impl<TOutEvent, TInEvent> RefUnwindSafe for ToSwarm<TOutEvent, TInEvent>where
TOutEvent: RefUnwindSafe,
TInEvent: RefUnwindSafe,
impl<TOutEvent, TInEvent> Send for ToSwarm<TOutEvent, TInEvent>
impl<TOutEvent, TInEvent> Sync for ToSwarm<TOutEvent, TInEvent>
impl<TOutEvent, TInEvent> Unpin for ToSwarm<TOutEvent, TInEvent>
impl<TOutEvent, TInEvent> UnwindSafe for ToSwarm<TOutEvent, TInEvent>where
TOutEvent: UnwindSafe,
TInEvent: UnwindSafe,
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> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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 more