Struct sc_network::NetworkWorker
source · pub struct NetworkWorker<B, H, Client>where
B: BlockT + 'static,
H: ExHashT,
Client: HeaderBackend<B> + 'static,{ /* 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, Client> NetworkWorker<B, H, Client>where
B: BlockT + 'static,
H: ExHashT,
Client: HeaderBackend<B> + 'static,
impl<B, H, Client> NetworkWorker<B, H, Client>where B: BlockT + 'static, H: ExHashT, Client: HeaderBackend<B> + 'static,
sourcepub fn new(params: Params<B, Client>) -> Result<Self, Error>
pub fn new(params: Params<B, Client>) -> 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<B>
pub fn status(&self) -> NetworkStatus<B>
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 num_active_peers(&self) -> usize
pub fn num_active_peers(&self) -> usize
Returns the number of peers we’re connected to and that are being queried.
sourcepub fn sync_state(&self) -> SyncStatus<B>
pub fn sync_state(&self) -> SyncStatus<B>
Current global sync state.
sourcepub fn best_seen_block(&self) -> Option<NumberFor<B>>
pub fn best_seen_block(&self) -> Option<NumberFor<B>>
Target sync block number.
sourcepub fn num_sync_peers(&self) -> u32
pub fn num_sync_peers(&self) -> u32
Number of peers participating in syncing.
sourcepub fn num_queued_blocks(&self) -> u32
pub fn num_queued_blocks(&self) -> u32
Number of blocks in the import queue.
sourcepub fn num_downloaded_blocks(&self) -> usize
pub fn num_downloaded_blocks(&self) -> usize
Returns the number of downloaded blocks.
sourcepub fn num_sync_requests(&self) -> usize
pub fn num_sync_requests(&self) -> usize
Number of active sync requests.
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 known to 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 on_block_finalized(&mut self, hash: B::Hash, header: B::Header)
pub fn on_block_finalized(&mut self, hash: B::Hash, header: B::Header)
You must call this when a new block is finalized by the client.
sourcepub fn new_best_block_imported(&mut self, hash: B::Hash, number: NumberFor<B>)
pub fn new_best_block_imported(&mut self, hash: B::Hash, number: NumberFor<B>)
Inform the network service about new best imported block.
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 peers_debug_info(&mut self) -> Vec<(PeerId, PeerInfo<B>)> ⓘ
pub fn peers_debug_info(&mut self) -> Vec<(PeerId, PeerInfo<B>)> ⓘ
Get currently connected peers.
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.
sourcepub fn reserved_peers(&self) -> impl Iterator<Item = &PeerId>
pub fn reserved_peers(&self) -> impl Iterator<Item = &PeerId>
Returns the list of reserved peers.
Trait Implementations§
source§impl<B, H, Client> Future for NetworkWorker<B, H, Client>where
B: BlockT + 'static,
H: ExHashT,
Client: HeaderBackend<B> + 'static,
impl<B, H, Client> Future for NetworkWorker<B, H, Client>where B: BlockT + 'static, H: ExHashT, Client: HeaderBackend<B> + 'static,
impl<B, H, Client> Unpin for NetworkWorker<B, H, Client>where B: BlockT + 'static, H: ExHashT, Client: HeaderBackend<B> + 'static,
Auto Trait Implementations§
impl<B, H, Client> !RefUnwindSafe for NetworkWorker<B, H, Client>
impl<B, H, Client> Send for NetworkWorker<B, H, Client>
impl<B, H, Client> !Sync for NetworkWorker<B, H, Client>
impl<B, H, Client> !UnwindSafe for NetworkWorker<B, H, Client>
Blanket Implementations§
source§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere T: Any,
§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> FutureExt for Twhere
T: Future + ?Sized,
impl<T> FutureExt for Twhere T: Future + ?Sized,
§fn map<U, F>(self, f: F) -> Map<Self, F>where
F: FnOnce(Self::Output) -> U,
Self: Sized,
fn map<U, F>(self, f: F) -> Map<Self, F>where F: FnOnce(Self::Output) -> U, Self: Sized,
§fn map_into<U>(self) -> MapInto<Self, U>where
Self::Output: Into<U>,
Self: Sized,
fn map_into<U>(self) -> MapInto<Self, U>where Self::Output: Into<U>, Self: Sized,
§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>where
F: FnOnce(Self::Output) -> Fut,
Fut: Future,
Self: Sized,
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>where F: FnOnce(Self::Output) -> Fut, Fut: Future, Self: Sized,
f
. Read more§fn left_future<B>(self) -> Either<Self, B>where
B: Future<Output = Self::Output>,
Self: Sized,
fn left_future<B>(self) -> Either<Self, B>where B: Future<Output = Self::Output>, Self: Sized,
§fn right_future<A>(self) -> Either<A, Self>where
A: Future<Output = Self::Output>,
Self: Sized,
fn right_future<A>(self) -> Either<A, Self>where A: Future<Output = Self::Output>, Self: Sized,
§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where Self: Sized,
§fn flatten(self) -> Flatten<Self>where
Self::Output: Future,
Self: Sized,
fn flatten(self) -> Flatten<Self>where Self::Output: Future, Self: Sized,
§fn flatten_stream(self) -> FlattenStream<Self>where
Self::Output: Stream,
Self: Sized,
fn flatten_stream(self) -> FlattenStream<Self>where Self::Output: Stream, Self: Sized,
§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where Self: Sized,
poll
will never again be called once it has
completed. This method can be used to turn any Future
into a
FusedFuture
. Read more§fn inspect<F>(self, f: F) -> Inspect<Self, F>where
F: FnOnce(&Self::Output),
Self: Sized,
fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: FnOnce(&Self::Output), Self: Sized,
§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where Self: Sized + UnwindSafe,
§fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where
Self: Sized,
fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)where Self: Sized,
()
on completion and sends
its output to another future on a separate task. Read more§fn boxed<'a>(
self
) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a, Global>>where
Self: Sized + Send + 'a,
fn boxed<'a>( self ) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a, Global>>where Self: Sized + Send + 'a,
§fn boxed_local<'a>(
self
) -> Pin<Box<dyn Future<Output = Self::Output> + 'a, Global>>where
Self: Sized + 'a,
fn boxed_local<'a>( self ) -> Pin<Box<dyn Future<Output = Self::Output> + 'a, Global>>where Self: Sized + 'a,
§fn unit_error(self) -> UnitError<Self>where
Self: Sized,
fn unit_error(self) -> UnitError<Self>where Self: Sized,
Future<Output = T>
into a
TryFuture<Ok = T, Error = ()
>.§fn never_error(self) -> NeverError<Self>where
Self: Sized,
fn never_error(self) -> NeverError<Self>where Self: Sized,
Future<Output = T>
into a
TryFuture<Ok = T, Error = Never
>.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<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere F: Future,
§type IntoFuture = F
type IntoFuture = F
source§fn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
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
.