pub struct NetworkWorker<B, H>{ /* 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>
impl<B, H> NetworkWorker<B, H>
Sourcepub fn new(params: Params<B, H, Self>) -> Result<Self, Error>
pub fn new(params: Params<B, H, Self>) -> 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>
impl<B, H> NetworkWorker<B, H>
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§
Source§impl<B, H> NetworkBackend<B, H> for NetworkWorker<B, H>
impl<B, H> NetworkBackend<B, H> for NetworkWorker<B, H>
Source§fn network_service(&self) -> Arc<dyn NetworkServiceT>
fn network_service(&self) -> Arc<dyn NetworkServiceT>
Get handle to NetworkService
of the NetworkBackend
.
Source§fn peer_store(
bootnodes: Vec<PeerId>,
metrics_registry: Option<Registry>,
) -> Self::PeerStore
fn peer_store( bootnodes: Vec<PeerId>, metrics_registry: Option<Registry>, ) -> Self::PeerStore
Create PeerStore
.
Source§fn notification_config(
protocol_name: ProtocolName,
fallback_names: Vec<ProtocolName>,
max_notification_size: u64,
handshake: Option<NotificationHandshake>,
set_config: SetConfig,
_metrics: NotificationMetrics,
_peerstore_handle: Arc<dyn PeerStoreProvider>,
) -> (Self::NotificationProtocolConfig, Box<dyn NotificationService>)
fn notification_config( protocol_name: ProtocolName, fallback_names: Vec<ProtocolName>, max_notification_size: u64, handshake: Option<NotificationHandshake>, set_config: SetConfig, _metrics: NotificationMetrics, _peerstore_handle: Arc<dyn PeerStoreProvider>, ) -> (Self::NotificationProtocolConfig, Box<dyn NotificationService>)
Create notification protocol configuration.
Source§fn request_response_config(
protocol_name: ProtocolName,
fallback_names: Vec<ProtocolName>,
max_request_size: u64,
max_response_size: u64,
request_timeout: Duration,
inbound_queue: Option<Sender<IncomingRequest>>,
) -> Self::RequestResponseProtocolConfig
fn request_response_config( protocol_name: ProtocolName, fallback_names: Vec<ProtocolName>, max_request_size: u64, max_response_size: u64, request_timeout: Duration, inbound_queue: Option<Sender<IncomingRequest>>, ) -> Self::RequestResponseProtocolConfig
Create request-response protocol configuration.
Source§fn run<'async_trait>(
self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
fn run<'async_trait>(
self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
Start NetworkBackend
event loop.
Source§type NotificationProtocolConfig = NonDefaultSetConfig
type NotificationProtocolConfig = NonDefaultSetConfig
Source§type RequestResponseProtocolConfig = ProtocolConfig
type RequestResponseProtocolConfig = ProtocolConfig
Source§type NetworkService<Block, Hash> = Arc<NetworkService<B, H>>
type NetworkService<Block, Hash> = Arc<NetworkService<B, H>>
NetworkService
for the networking backend. Read moreSource§type BitswapConfig = ProtocolConfig
type BitswapConfig = ProtocolConfig
Source§fn new(params: Params<B, H, Self>) -> Result<Self, Error>where
Self: Sized,
fn new(params: Params<B, H, Self>) -> Result<Self, Error>where
Self: Sized,
NetworkBackend
.Source§fn register_notification_metrics(
registry: Option<&Registry>,
) -> NotificationMetrics
fn register_notification_metrics( registry: Option<&Registry>, ) -> NotificationMetrics
Source§fn bitswap_server(
client: Arc<dyn BlockBackend<B> + Send + Sync>,
) -> (Pin<Box<dyn Future<Output = ()> + Send>>, Self::BitswapConfig)
fn bitswap_server( client: Arc<dyn BlockBackend<B> + Send + Sync>, ) -> (Pin<Box<dyn Future<Output = ()> + Send>>, Self::BitswapConfig)
impl<B, H> Unpin for NetworkWorker<B, H>
Auto Trait Implementations§
impl<B, H> !Freeze for NetworkWorker<B, H>
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<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> 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> 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 moreSource§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
Source§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 S
impl<T, S> UniqueSaturatedInto<T> for S
Source§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T
.