Struct sc_network::NetworkWorker
source · [−]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
sourceimpl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H>
impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H>
sourcepub fn new(params: Params<B, H>) -> Result<NetworkWorker<B, H>, Error>
pub fn new(params: Params<B, H>) -> Result<NetworkWorker<B, H>, 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) -> SyncState
pub fn sync_state(&self) -> SyncState
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 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 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>)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn peers_debug_info(&mut self) -> Vec<(PeerId, PeerInfo<B>)>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
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.
Trait Implementations
sourceimpl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H>
impl<B: BlockT + 'static, H: ExHashT> Future for NetworkWorker<B, H>
impl<B: BlockT + 'static, H: ExHashT> Unpin for NetworkWorker<B, H>
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
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
sourceimpl<T> CheckedConversion for T
impl<T> CheckedConversion for T
sourcefn checked_from<T>(t: T) -> Option<Self> where
Self: TryFrom<T>,
fn checked_from<T>(t: T) -> Option<Self> where
Self: TryFrom<T>,
Convert from a value of T
into an equivalent instance of Option<Self>
. Read more
sourcefn checked_into<T>(self) -> Option<T> where
Self: TryInto<T>,
fn checked_into<T>(self) -> Option<T> where
Self: TryInto<T>,
Consume self to return Some
equivalent value of Option<T>
. Read more
sourceimpl<T> FutureExt for T where
T: Future + ?Sized,
impl<T> FutureExt for T where
T: Future + ?Sized,
sourcefn map<U, F>(self, f: F) -> Map<Self, F> where
F: FnOnce(Self::Output) -> U,
fn map<U, F>(self, f: F) -> Map<Self, F> where
F: FnOnce(Self::Output) -> U,
Map this future’s output to a different type, returning a new future of the resulting type. Read more
sourcefn map_into<U>(self) -> MapInto<Self, U> where
Self::Output: Into<U>,
fn map_into<U>(self) -> MapInto<Self, U> where
Self::Output: Into<U>,
Map this future’s output to a different type, returning a new future of the resulting type. Read more
sourcefn then<Fut, F>(self, f: F) -> Then<Self, Fut, F> where
F: FnOnce(Self::Output) -> Fut,
Fut: Future,
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F> where
F: FnOnce(Self::Output) -> Fut,
Fut: Future,
Chain on a computation for when a future finished, passing the result of
the future to the provided closure f
. Read more
sourcefn left_future<B>(self) -> Either<Self, B> where
B: Future<Output = Self::Output>,
fn left_future<B>(self) -> Either<Self, B> where
B: Future<Output = Self::Output>,
Wrap this future in an Either
future, making it the left-hand variant
of that Either
. Read more
sourcefn right_future<A>(self) -> Either<A, Self> where
A: Future<Output = Self::Output>,
fn right_future<A>(self) -> Either<A, Self> where
A: Future<Output = Self::Output>,
Wrap this future in an Either
future, making it the right-hand variant
of that Either
. Read more
sourcefn into_stream(self) -> IntoStream<Self>
fn into_stream(self) -> IntoStream<Self>
Convert this future into a single element stream. Read more
sourcefn flatten(self) -> Flatten<Self> where
Self::Output: Future,
fn flatten(self) -> Flatten<Self> where
Self::Output: Future,
Flatten the execution of this future when the output of this future is itself another future. Read more
sourcefn flatten_stream(self) -> FlattenStream<Self> where
Self::Output: Stream,
fn flatten_stream(self) -> FlattenStream<Self> where
Self::Output: Stream,
Flatten the execution of this future when the successful result of this future is a stream. Read more
sourcefn fuse(self) -> Fuse<Self>
fn fuse(self) -> Fuse<Self>
Fuse a future such that poll
will never again be called once it has
completed. This method can be used to turn any Future
into a
FusedFuture
. Read more
sourcefn inspect<F>(self, f: F) -> Inspect<Self, F> where
F: FnOnce(&Self::Output),
fn inspect<F>(self, f: F) -> Inspect<Self, F> where
F: FnOnce(&Self::Output),
Do something with the output of a future before passing it on. Read more
sourcefn catch_unwind(self) -> CatchUnwind<Self> where
Self: UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self> where
Self: UnwindSafe,
Catches unwinding panics while polling the future. Read more
Create a cloneable handle to this future where all handles will resolve to the same result. Read more
sourcefn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)
fn remote_handle(self) -> (Remote<Self>, RemoteHandle<Self::Output>)
Turn this future into a future that yields ()
on completion and sends
its output to another future on a separate task. Read more
sourcefn boxed<'a>(
self
) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a, Global>> where
Self: 'a + Send,
fn boxed<'a>(
self
) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a, Global>> where
Self: 'a + Send,
Wrap the future in a Box, pinning it. Read more
sourcefn boxed_local<'a>(
self
) -> Pin<Box<dyn Future<Output = Self::Output> + 'a, Global>> where
Self: 'a,
fn boxed_local<'a>(
self
) -> Pin<Box<dyn Future<Output = Self::Output> + 'a, Global>> where
Self: 'a,
Wrap the future in a Box, pinning it. Read more
sourcefn unit_error(self) -> UnitError<Self>
fn unit_error(self) -> UnitError<Self>
Turns a Future<Output = T>
into a
TryFuture<Ok = T, Error = ()
>. Read more
sourcefn never_error(self) -> NeverError<Self>
fn never_error(self) -> NeverError<Self>
Turns a Future<Output = T>
into a
TryFuture<Ok = T, Error = Never
>. Read more
sourcefn poll_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Self::Output> where
Self: Unpin,
fn poll_unpin(&mut self, cx: &mut Context<'_>) -> Poll<Self::Output> where
Self: Unpin,
A convenience for calling Future::poll
on Unpin
future types.
sourcefn now_or_never(self) -> Option<Self::Output>
fn now_or_never(self) -> Option<Self::Output>
Evaluates and consumes the future, returning the resulting output if
the future is ready after the first call to Future::poll
. Read more
sourceimpl<F> FutureExt for F where
F: Future + ?Sized,
impl<F> FutureExt for F where
F: Future + ?Sized,
sourcefn poll(&mut self, cx: &mut Context<'_>) -> Poll<Self::Output> where
Self: Unpin,
fn poll(&mut self, cx: &mut Context<'_>) -> Poll<Self::Output> where
Self: Unpin,
A convenience for calling Future::poll()
on !
Unpin
types.
sourcefn or<F>(self, other: F) -> Or<Self, F> where
F: Future<Output = Self::Output>,
fn or<F>(self, other: F) -> Or<Self, F> where
F: Future<Output = Self::Output>,
Returns the result of self
or other
future, preferring self
if both are ready. Read more
sourcefn race<F>(self, other: F) -> Race<Self, F> where
F: Future<Output = Self::Output>,
fn race<F>(self, other: F) -> Race<Self, F> where
F: Future<Output = Self::Output>,
Returns the result of self
or other
future, with no preference if both are ready. Read more
sourcefn catch_unwind(self) -> CatchUnwind<Self> where
Self: UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self> where
Self: UnwindSafe,
Catches panics while polling the future. Read more
sourceimpl<T> FutureExt for T where
T: Future + ?Sized,
impl<T> FutureExt for T where
T: Future + ?Sized,
sourcefn delay(self, dur: Duration) -> DelayFuture<Self>
fn delay(self, dur: Duration) -> DelayFuture<Self>
Returns a Future that delays execution for a specified time. Read more
sourcefn flatten(self) -> FlattenFuture<Self, <Self::Output as IntoFuture>::Future> where
Self::Output: IntoFuture,
fn flatten(self) -> FlattenFuture<Self, <Self::Output as IntoFuture>::Future> where
Self::Output: IntoFuture,
Flatten out the execution of this future when the result itself can be converted into another future. Read more
sourcefn race<F>(self, other: F) -> Race<Self, F> where
Self: Future,
F: Future<Output = Self::Output>,
fn race<F>(self, other: F) -> Race<Self, F> where
Self: Future,
F: Future<Output = Self::Output>,
Waits for one of two similarly-typed futures to complete. Read more
sourcefn try_race<F, T, E>(self, other: F) -> TryRace<Self, F> where
Self: Future<Output = Result<T, E>>,
F: Future<Output = Self::Output>,
fn try_race<F, T, E>(self, other: F) -> TryRace<Self, F> where
Self: Future<Output = Result<T, E>>,
F: Future<Output = Self::Output>,
Waits for one of two similarly-typed fallible futures to complete. Read more
sourcefn join<F>(self, other: F) -> Join<Self, F> where
Self: Future,
F: Future,
fn join<F>(self, other: F) -> Join<Self, F> where
Self: Future,
F: Future,
Waits for two similarly-typed futures to complete. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<F> IntoFuture for F where
F: Future,
impl<F> IntoFuture for F where
F: Future,
type Output = <F as Future>::Output
type Output = <F as Future>::Output
into_future
)The output that the future will produce on completion.
type Future = F
type Future = F
into_future
)Which kind of future are we turning this into?
sourcepub fn into_future(self) -> <F as IntoFuture>::Future
pub fn into_future(self) -> <F as IntoFuture>::Future
into_future
)Creates a future from a value.
sourceimpl<T> IntoFuture for T where
T: Future,
impl<T> IntoFuture for T where
T: Future,
type Future = T
type Future = T
Which kind of future are we turning this into?
sourcepub fn into_future(self) -> <T as IntoFuture>::Future
pub fn into_future(self) -> <T as IntoFuture>::Future
Create a future from a value
sourceimpl<T, Outer> IsWrappedBy<Outer> for T where
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
impl<T, Outer> IsWrappedBy<Outer> for T where
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
sourceimpl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
sourcefn saturated_from<T>(t: T) -> Self where
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Self where
Self: UniqueSaturatedFrom<T>,
Convert from a value of T
into an equivalent instance of Self
. Read more
sourcefn saturated_into<T>(self) -> T where
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> T where
Self: UniqueSaturatedInto<T>,
Consume self to return an equivalent value of T
. Read more
sourceimpl<S, T> UncheckedInto<T> for S where
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for S where
T: UncheckedFrom<S>,
sourcepub fn unchecked_into(self) -> T
pub fn unchecked_into(self) -> T
The counterpart to unchecked_from
.
sourceimpl<T, S> UniqueSaturatedInto<T> for S where
T: Bounded,
S: TryInto<T>,
impl<T, S> UniqueSaturatedInto<T> for S where
T: Bounded,
S: TryInto<T>,
sourcepub fn unique_saturated_into(self) -> T
pub fn unique_saturated_into(self) -> T
Consume self to return an equivalent value of T
.
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more