Struct sc_network::NetworkWorker
source · pub struct NetworkWorker<B, H>where
B: BlockT + 'static,
H: ExHashT,{ /* private fields */ }
Expand description
Main network worker. Must be polled in order for the network to advance.
You are encouraged to poll this in a separate background thread or task.
Implementations§
source§impl<B, H> NetworkWorker<B, H>where
B: BlockT + 'static,
H: ExHashT,
impl<B, H> NetworkWorker<B, H>where B: BlockT + 'static, H: ExHashT,
sourcepub fn new(params: Params<B>) -> Result<Self, Error>
pub fn new(params: Params<B>) -> Result<Self, Error>
Creates the network service.
Returns a NetworkWorker
that implements Future
and must be regularly polled in order
for the network processing to advance. From it, you can extract a NetworkService
using
worker.service()
. The NetworkService
can be shared through the codebase.
sourcepub fn status(&self) -> NetworkStatus
pub fn status(&self) -> NetworkStatus
High-level network status information.
sourcepub fn total_bytes_inbound(&self) -> u64
pub fn total_bytes_inbound(&self) -> u64
Returns the total number of bytes received so far.
sourcepub fn total_bytes_outbound(&self) -> u64
pub fn total_bytes_outbound(&self) -> u64
Returns the total number of bytes sent so far.
sourcepub fn num_connected_peers(&self) -> usize
pub fn num_connected_peers(&self) -> usize
Returns the number of peers we’re connected to.
sourcepub fn add_known_address(&mut self, peer_id: PeerId, addr: Multiaddr)
pub fn add_known_address(&mut self, peer_id: PeerId, addr: Multiaddr)
Adds an address for a node.
sourcepub fn service(&self) -> &Arc<NetworkService<B, H>>
pub fn service(&self) -> &Arc<NetworkService<B, H>>
Return a NetworkService
that can be shared through the code base and can be used to
manipulate the worker.
sourcepub fn local_peer_id(&self) -> &PeerId
pub fn local_peer_id(&self) -> &PeerId
Returns the local PeerId
.
sourcepub fn listen_addresses(&self) -> impl Iterator<Item = &Multiaddr>
pub fn listen_addresses(&self) -> impl Iterator<Item = &Multiaddr>
Returns the list of addresses we are listening on.
Does NOT include a trailing /p2p/
with our PeerId
.
sourcepub fn network_state(&mut self) -> NetworkState
pub fn network_state(&mut self) -> NetworkState
Get network state.
Note: Use this only for debugging. This API is unstable. There are warnings literally everywhere about this. Please don’t use this function to retrieve actual information.
sourcepub fn remove_reserved_peer(&self, peer: PeerId)
pub fn remove_reserved_peer(&self, peer: PeerId)
Removes a PeerId
from the list of reserved peers.
sourcepub fn add_reserved_peer(&self, peer: MultiaddrWithPeerId) -> Result<(), String>
pub fn add_reserved_peer(&self, peer: MultiaddrWithPeerId) -> Result<(), String>
Adds a PeerId
and its Multiaddr
as reserved.
source§impl<B, H> NetworkWorker<B, H>where
B: BlockT + 'static,
H: ExHashT,
impl<B, H> NetworkWorker<B, H>where B: BlockT + 'static, H: ExHashT,
sourcepub async fn next_action(&mut self) -> bool
pub async fn next_action(&mut self) -> bool
Perform one action on the network.
Returns false
when the worker should be shutdown.
Use in tests only.
Trait Implementations§
Auto Trait Implementations§
impl<B, H> !RefUnwindSafe for NetworkWorker<B, H>
impl<B, H> Send for NetworkWorker<B, H>
impl<B, H> !Sync for NetworkWorker<B, H>
impl<B, H> !UnwindSafe for NetworkWorker<B, H>
Blanket Implementations§
source§impl<T> CheckedConversion for T
impl<T> CheckedConversion for 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, Outer> IsWrappedBy<Outer> for Twhere
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
impl<T, Outer> IsWrappedBy<Outer> for Twhere Outer: AsRef<T> + AsMut<T> + From<T>, T: From<Outer>,
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
source§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere Self: UniqueSaturatedFrom<T>,
source§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere Self: UniqueSaturatedInto<T>,
T
. Read moresource§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere T: UncheckedFrom<S>,
source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from
.source§impl<T, S> UniqueSaturatedInto<T> for Swhere
T: Bounded,
S: TryInto<T>,
impl<T, S> UniqueSaturatedInto<T> for Swhere T: Bounded, S: TryInto<T>,
source§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T
.