pub struct NetworkServiceChain<TPlat: PlatformRef> { /* private fields */ }
Implementations§
source§impl<TPlat: PlatformRef> NetworkServiceChain<TPlat>
impl<TPlat: PlatformRef> NetworkServiceChain<TPlat>
sourcepub async fn subscribe(&self) -> Receiver<Event>
pub async fn subscribe(&self) -> Receiver<Event>
Subscribes to the networking events that happen on the given chain.
Calling this function returns a Receiver
that receives events about the chain.
The new channel will immediately receive events about all the existing connections, so
that it is able to maintain a coherent view of the network.
Note that this function is async
, but it should return very quickly.
The Receiver
must be polled continuously. When the channel is full, the networking
connections will be back-pressured until the channel isn’t full anymore.
The Receiver
never yields None
unless the NetworkService
crashes or is destroyed.
If None
is yielded and the NetworkService
is still alive, you should call
NetworkServiceChain::subscribe
again to obtain a new Receiver
.
§Panic
Panics if the given ChainId
is invalid.
sourcepub async fn ban_and_disconnect(
&self,
peer_id: PeerId,
severity: BanSeverity,
reason: &'static str,
)
pub async fn ban_and_disconnect( &self, peer_id: PeerId, severity: BanSeverity, reason: &'static str, )
Starts asynchronously disconnecting the given peer. A Event::Disconnected
will later be
generated. Prevents a new gossip link with the same peer from being reopened for a
little while.
reason
is a human-readable string printed in the logs.
Due to race conditions, it is possible to reconnect to the peer soon after, in case the
reconnection was already happening as the call to this function is still being processed.
If that happens another Event::Disconnected
will be delivered afterwards. In other
words, this function guarantees that we will be disconnected in the future rather than
guarantees that we will disconnect.
sourcepub async fn blocks_request(
self: Arc<Self>,
target: PeerId,
config: BlocksRequestConfig,
timeout: Duration,
) -> Result<Vec<BlockData>, BlocksRequestError>
pub async fn blocks_request( self: Arc<Self>, target: PeerId, config: BlocksRequestConfig, timeout: Duration, ) -> Result<Vec<BlockData>, BlocksRequestError>
Sends a blocks request to the given peer.
sourcepub async fn grandpa_warp_sync_request(
self: Arc<Self>,
target: PeerId,
begin_hash: [u8; 32],
timeout: Duration,
) -> Result<EncodedGrandpaWarpSyncResponse, WarpSyncRequestError>
pub async fn grandpa_warp_sync_request( self: Arc<Self>, target: PeerId, begin_hash: [u8; 32], timeout: Duration, ) -> Result<EncodedGrandpaWarpSyncResponse, WarpSyncRequestError>
Sends a grandpa warp sync request to the given peer.
pub async fn set_local_best_block(&self, best_hash: [u8; 32], best_number: u64)
pub async fn set_local_grandpa_state(&self, grandpa_state: GrandpaState)
sourcepub async fn storage_proof_request(
self: Arc<Self>,
target: PeerId,
config: StorageProofRequestConfig<impl Iterator<Item = impl AsRef<[u8]> + Clone>>,
timeout: Duration,
) -> Result<EncodedMerkleProof, StorageProofRequestError>
pub async fn storage_proof_request( self: Arc<Self>, target: PeerId, config: StorageProofRequestConfig<impl Iterator<Item = impl AsRef<[u8]> + Clone>>, timeout: Duration, ) -> Result<EncodedMerkleProof, StorageProofRequestError>
Sends a storage proof request to the given peer.
sourcepub async fn call_proof_request(
self: Arc<Self>,
target: PeerId,
config: CallProofRequestConfig<'_, impl Iterator<Item = impl AsRef<[u8]>>>,
timeout: Duration,
) -> Result<EncodedMerkleProof, CallProofRequestError>
pub async fn call_proof_request( self: Arc<Self>, target: PeerId, config: CallProofRequestConfig<'_, impl Iterator<Item = impl AsRef<[u8]>>>, timeout: Duration, ) -> Result<EncodedMerkleProof, CallProofRequestError>
Sends a call proof request to the given peer.
See also NetworkServiceChain::call_proof_request
.
sourcepub async fn announce_transaction(
self: Arc<Self>,
transaction: &[u8],
) -> Vec<PeerId>
pub async fn announce_transaction( self: Arc<Self>, transaction: &[u8], ) -> Vec<PeerId>
Announces transaction to the peers we are connected to.
Returns a list of peers that we have sent the transaction to. Can return an empty Vec
if we didn’t send the transaction to any peer.
Note that the remote doesn’t confirm that it has received the transaction. Because networking is inherently unreliable, successfully sending a transaction to a peer doesn’t necessarily mean that the remote has received it. In practice, however, the likelihood of a transaction not being received are extremely low. This can be considered as known flaw.
sourcepub async fn send_block_announce(
self: Arc<Self>,
target: &PeerId,
scale_encoded_header: &[u8],
is_best: bool,
) -> Result<(), QueueNotificationError>
pub async fn send_block_announce( self: Arc<Self>, target: &PeerId, scale_encoded_header: &[u8], is_best: bool, ) -> Result<(), QueueNotificationError>
sourcepub async fn discover(
&self,
list: impl IntoIterator<Item = (PeerId, impl IntoIterator<Item = Multiaddr>)>,
important_nodes: bool,
)
pub async fn discover( &self, list: impl IntoIterator<Item = (PeerId, impl IntoIterator<Item = Multiaddr>)>, important_nodes: bool, )
Marks the given peers as belonging to the given chain, and adds some addresses to these peers to the address book.
The important_nodes
parameter indicates whether these nodes are considered note-worthy
and should have additional logging.
sourcepub async fn discovered_nodes(
&self,
) -> impl Iterator<Item = (PeerId, impl Iterator<Item = Multiaddr>)>
pub async fn discovered_nodes( &self, ) -> impl Iterator<Item = (PeerId, impl Iterator<Item = Multiaddr>)>
Returns a list of nodes (their PeerId
and multiaddresses) that we know are part of
the network.
Nodes that are discovered might disappear over time. In other words, there is no guarantee
that a node that has been added through NetworkServiceChain::discover
will later be
returned by NetworkServiceChain::discovered_nodes
.
sourcepub async fn peers_list(&self) -> impl Iterator<Item = PeerId>
pub async fn peers_list(&self) -> impl Iterator<Item = PeerId>
Returns an iterator to the list of PeerId
s that we have an established connection
with.
Auto Trait Implementations§
impl<TPlat> Freeze for NetworkServiceChain<TPlat>
impl<TPlat> RefUnwindSafe for NetworkServiceChain<TPlat>where
TPlat: RefUnwindSafe,
impl<TPlat> Send for NetworkServiceChain<TPlat>
impl<TPlat> Sync for NetworkServiceChain<TPlat>
impl<TPlat> Unpin for NetworkServiceChain<TPlat>where
TPlat: Unpin,
impl<TPlat> UnwindSafe for NetworkServiceChain<TPlat>
Blanket Implementations§
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
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 more