pub struct Toggle<TBehaviour> { /* private fields */ }
Expand description
Implementation of NetworkBehaviour
that can be either in the disabled or enabled state.
The state can only be chosen at initialization.
Implementations
sourceimpl<TBehaviour> Toggle<TBehaviour>
impl<TBehaviour> Toggle<TBehaviour>
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns true
if Toggle
is enabled and false
if it’s disabled.
Trait Implementations
sourceimpl<TBehaviour> NetworkBehaviour for Toggle<TBehaviour> where
TBehaviour: NetworkBehaviour,
impl<TBehaviour> NetworkBehaviour for Toggle<TBehaviour> where
TBehaviour: NetworkBehaviour,
type ProtocolsHandler = ToggleIntoProtoHandler<<TBehaviour as NetworkBehaviour>::ProtocolsHandler>
type ProtocolsHandler = ToggleIntoProtoHandler<<TBehaviour as NetworkBehaviour>::ProtocolsHandler>
Handler for all the protocols the network behaviour supports.
type OutEvent = <TBehaviour as NetworkBehaviour>::OutEvent
type OutEvent = <TBehaviour as NetworkBehaviour>::OutEvent
Event generated by the NetworkBehaviour
and that the swarm will report back.
sourcepub fn new_handler(
&mut self
) -> <Toggle<TBehaviour> as NetworkBehaviour>::ProtocolsHandler
pub fn new_handler(
&mut self
) -> <Toggle<TBehaviour> as NetworkBehaviour>::ProtocolsHandler
Creates a new ProtocolsHandler
for a connection with a peer. Read more
sourcepub fn addresses_of_peer(&mut self, peer_id: &PeerId) -> Vec<Multiaddr, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn addresses_of_peer(&mut self, peer_id: &PeerId) -> Vec<Multiaddr, Global>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Addresses that this behaviour is aware of for this specific peer, and that may allow reaching the peer. Read more
sourcepub fn inject_connected(&mut self, peer_id: &PeerId)
pub fn inject_connected(&mut self, peer_id: &PeerId)
Indicates the behaviour that we connected to the node with the given peer id. Read more
sourcepub fn inject_disconnected(&mut self, peer_id: &PeerId)
pub fn inject_disconnected(&mut self, peer_id: &PeerId)
Indicates the behaviour that we disconnected from the node with the given peer id. Read more
sourcepub fn inject_connection_established(
&mut self,
peer_id: &PeerId,
connection: &ConnectionId,
endpoint: &ConnectedPoint
)
pub fn inject_connection_established(
&mut self,
peer_id: &PeerId,
connection: &ConnectionId,
endpoint: &ConnectedPoint
)
Informs the behaviour about a newly established connection to a peer.
sourcepub fn inject_connection_closed(
&mut self,
peer_id: &PeerId,
connection: &ConnectionId,
endpoint: &ConnectedPoint
)
pub fn inject_connection_closed(
&mut self,
peer_id: &PeerId,
connection: &ConnectionId,
endpoint: &ConnectedPoint
)
Informs the behaviour about a closed connection to a peer. Read more
sourcepub fn inject_event(
&mut self,
peer_id: PeerId,
connection: ConnectionId,
event: <<<Toggle<TBehaviour> as NetworkBehaviour>::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent
)
pub fn inject_event(
&mut self,
peer_id: PeerId,
connection: ConnectionId,
event: <<<Toggle<TBehaviour> as NetworkBehaviour>::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::OutEvent
)
Informs the behaviour about an event generated by the handler dedicated to the peer identified by peer_id
.
for the behaviour. Read more
sourcepub fn inject_addr_reach_failure(
&mut self,
peer_id: Option<&PeerId>,
addr: &Multiaddr,
error: &dyn Error
)
pub fn inject_addr_reach_failure(
&mut self,
peer_id: Option<&PeerId>,
addr: &Multiaddr,
error: &dyn Error
)
Indicates to the behaviour that we tried to reach an address, but failed. Read more
sourcepub fn inject_dial_failure(&mut self, peer_id: &PeerId)
pub fn inject_dial_failure(&mut self, peer_id: &PeerId)
Indicates to the behaviour that we tried to dial all the addresses known for a node, but failed. Read more
sourcepub fn inject_new_listen_addr(&mut self, addr: &Multiaddr)
pub fn inject_new_listen_addr(&mut self, addr: &Multiaddr)
Indicates to the behaviour that we have started listening on a new multiaddr.
sourcepub fn inject_expired_listen_addr(&mut self, addr: &Multiaddr)
pub fn inject_expired_listen_addr(&mut self, addr: &Multiaddr)
Indicates to the behaviour that a new multiaddr we were listening on has expired, which means that we are no longer listening in it. Read more
sourcepub fn inject_new_external_addr(&mut self, addr: &Multiaddr)
pub fn inject_new_external_addr(&mut self, addr: &Multiaddr)
Indicates to the behaviour that we have discovered a new external address for us.
sourcepub fn poll(
&mut self,
cx: &mut Context<'_>,
params: &mut impl PollParameters
) -> Poll<NetworkBehaviourAction<<<<Toggle<TBehaviour> as NetworkBehaviour>::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::InEvent, <Toggle<TBehaviour> as NetworkBehaviour>::OutEvent>>
pub fn poll(
&mut self,
cx: &mut Context<'_>,
params: &mut impl PollParameters
) -> Poll<NetworkBehaviourAction<<<<Toggle<TBehaviour> as NetworkBehaviour>::ProtocolsHandler as IntoProtocolsHandler>::Handler as ProtocolsHandler>::InEvent, <Toggle<TBehaviour> as NetworkBehaviour>::OutEvent>>
Polls for things that swarm should do. Read more
sourcefn inject_address_change(
&mut self,
&PeerId,
&ConnectionId,
_old: &ConnectedPoint,
_new: &ConnectedPoint
)
fn inject_address_change(
&mut self,
&PeerId,
&ConnectionId,
_old: &ConnectedPoint,
_new: &ConnectedPoint
)
Informs the behaviour that the ConnectedPoint
of an existing connection has changed.
sourcefn inject_listener_error(
&mut self,
_id: ListenerId,
_err: &(dyn Error + 'static)
)
fn inject_listener_error(
&mut self,
_id: ListenerId,
_err: &(dyn Error + 'static)
)
A listener experienced an error.
sourcefn inject_listener_closed(
&mut self,
_id: ListenerId,
_reason: Result<(), &Error>
)
fn inject_listener_closed(
&mut self,
_id: ListenerId,
_reason: Result<(), &Error>
)
A listener closed.
sourceimpl<TEvent, TBehaviour> NetworkBehaviourEventProcess<TEvent> for Toggle<TBehaviour> where
TBehaviour: NetworkBehaviourEventProcess<TEvent>,
impl<TEvent, TBehaviour> NetworkBehaviourEventProcess<TEvent> for Toggle<TBehaviour> where
TBehaviour: NetworkBehaviourEventProcess<TEvent>,
sourcepub fn inject_event(&mut self, event: TEvent)
pub fn inject_event(&mut self, event: TEvent)
Called when one of the fields of the type you’re deriving NetworkBehaviour
on generates
an event. Read more
Auto Trait Implementations
impl<TBehaviour> RefUnwindSafe for Toggle<TBehaviour> where
TBehaviour: RefUnwindSafe,
impl<TBehaviour> Send for Toggle<TBehaviour> where
TBehaviour: Send,
impl<TBehaviour> Sync for Toggle<TBehaviour> where
TBehaviour: Sync,
impl<TBehaviour> Unpin for Toggle<TBehaviour> where
TBehaviour: Unpin,
impl<TBehaviour> UnwindSafe for Toggle<TBehaviour> where
TBehaviour: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more