pub struct NetworkServiceChain<TPlat: PlatformRef> { /* private fields */ }

Implementations§

source§

impl<TPlat: PlatformRef> NetworkServiceChain<TPlat>

source

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.

source

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.

source

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.

source

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.

source

pub async fn set_local_best_block(&self, best_hash: [u8; 32], best_number: u64)

source

pub async fn set_local_grandpa_state(&self, grandpa_state: GrandpaState)

source

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.

source

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.

source

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.

source

pub async fn send_block_announce( self: Arc<Self>, target: &PeerId, scale_encoded_header: &[u8], is_best: bool, ) -> Result<(), QueueNotificationError>

source

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.

source

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.

source

pub async fn peers_list(&self) -> impl Iterator<Item = PeerId>

Returns an iterator to the list of PeerIds 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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more