[][src]Struct sc_network::NetworkService

pub struct NetworkService<B: BlockT + 'static, H: ExHashT> { /* fields omitted */ }

Substrate network service. Handles network IO and manages connectivity.

Methods

impl<B: BlockT + 'static, H: ExHashT> NetworkService<B, H>[src]

pub fn local_peer_id(&self) -> &PeerId[src]

Returns the local PeerId.

pub fn write_notification(
    &self,
    target: PeerId,
    engine_id: ConsensusEngineId,
    message: Vec<u8>
)
[src]

Writes a message on an open notifications channel. Has no effect if the notifications channel with this protocol name is closed.

Note: The reason why this is a no-op in the situation where we have no channel is that we don't guarantee message delivery anyway. Networking issues can cause connections to drop at any time, and higher-level logic shouldn't differentiate between the remote voluntarily closing a substream or a network error preventing the message from being delivered.

The protocol must have been registered with register_notifications_protocol.

pub fn event_stream(&self, name: &'static str) -> impl Stream<Item = Event>[src]

Returns a stream containing the events that happen on the network.

If this method is called multiple times, the events are duplicated.

The stream never ends (unless the NetworkWorker gets shut down).

The name passed is used to identify the channel in the Prometheus metrics. Note that the parameter is a &'static str, and not a String, in order to avoid accidentally having an unbounded set of Prometheus metrics, which would be quite bad in terms of memory

pub fn register_notifications_protocol(
    &self,
    engine_id: ConsensusEngineId,
    protocol_name: impl Into<Cow<'static, [u8]>>
)
[src]

Registers a new notifications protocol.

After that, you can call write_notifications.

Please call event_stream before registering a protocol, otherwise you may miss events about the protocol that you have registered.

You are very strongly encouraged to call this method very early on. Any connection open will retain the protocols that were registered then, and not any new one.

pub fn trigger_repropagate(&self)[src]

You may call this when new transactons are imported by the transaction pool.

All transactions will be fetched from the TransactionPool that was passed at initialization as part of the configuration and propagated to peers.

pub fn propagate_extrinsic(&self, hash: H)[src]

You must call when new transaction is imported by the transaction pool.

This transaction will be fetched from the TransactionPool that was passed at initialization as part of the configuration and propagated to peers.

pub fn announce_block(&self, hash: B::Hash, data: Vec<u8>)[src]

Make sure an important block is propagated to peers.

In chain-based consensus, we often need to make sure non-best forks are at least temporarily synced. This function forces such an announcement.

pub fn report_peer(&self, who: PeerId, cost_benefit: ReputationChange)[src]

Report a given peer as either beneficial (+) or costly (-) according to the given scalar.

pub fn disconnect_peer(&self, who: PeerId)[src]

Disconnect from a node as soon as possible.

This triggers the same effects as if the connection had closed itself spontaneously.

pub fn request_justification(&self, hash: &B::Hash, number: NumberFor<B>)[src]

Request a justification for the given block from the network.

On success, the justification will be passed to the import queue that was part at initialization as part of the configuration.

pub fn is_major_syncing(&self) -> bool[src]

Are we in the process of downloading the chain?

pub fn get_value(&self, key: &Key)[src]

Start getting a value from the DHT.

This will generate either a ValueFound or a ValueNotFound event and pass it as an item on the NetworkWorker stream.

pub fn put_value(&self, key: Key, value: Vec<u8>)[src]

Start putting a value in the DHT.

This will generate either a ValuePut or a ValuePutFailed event and pass it as an item on the NetworkWorker stream.

pub fn accept_unreserved_peers(&self)[src]

Connect to unreserved peers and allow unreserved peers to connect.

pub fn deny_unreserved_peers(&self)[src]

Disconnect from unreserved peers and deny new unreserved peers to connect.

pub fn remove_reserved_peer(&self, peer: PeerId)[src]

Removes a PeerId from the list of reserved peers.

pub fn add_reserved_peer(&self, peer: String) -> Result<(), String>[src]

Adds a PeerId and its address as reserved. The string should encode the address and peer ID of the remote node.

pub fn set_sync_fork_request(
    &self,
    peers: Vec<PeerId>,
    hash: B::Hash,
    number: NumberFor<B>
)
[src]

Configure an explicit fork sync request. Note that this function should not be used for recent blocks. Sync should be able to download all the recent forks normally. set_sync_fork_request should only be used if external code detects that there's a stale fork missing. Passing empty peers set effectively removes the sync request.

pub fn set_priority_group(
    &self,
    group_id: String,
    peers: HashSet<Multiaddr>
) -> Result<(), String>
[src]

Modify a peerset priority group.

pub fn num_connected(&self) -> usize[src]

Returns the number of peers we're connected to.

Trait Implementations

impl<B, H> NetworkStateInfo for NetworkService<B, H> where
    B: Block,
    H: ExHashT
[src]

fn external_addresses(&self) -> Vec<Multiaddr>[src]

Returns the local external addresses.

fn local_peer_id(&self) -> PeerId[src]

Returns the local Peer ID.

impl<B: BlockT + 'static, H: ExHashT> SyncOracle for NetworkService<B, H>[src]

impl<'a, B: BlockT + 'static, H: ExHashT> SyncOracle for &'a NetworkService<B, H>[src]

Auto Trait Implementations

impl<B, H> !RefUnwindSafe for NetworkService<B, H>

impl<B, H> Send for NetworkService<B, H> where
    <B as Block>::Hash: Send,
    <B as Block>::Header: Header,
    <<B as Block>::Header as Header>::Number: Send

impl<B, H> Sync for NetworkService<B, H> where
    <B as Block>::Hash: Send,
    <B as Block>::Header: Header,
    <<B as Block>::Header as Header>::Number: Send

impl<B, H> Unpin for NetworkService<B, H> where
    H: Unpin,
    <B as Block>::Header: Header

impl<B, H> !UnwindSafe for NetworkService<B, H>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CheckedConversion for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, Outer> IsWrappedBy<Outer> for T where
    Outer: AsRef<T> + AsMut<T> + From<T>,
    T: From<Outer>, 
[src]

fn from_ref(outer: &Outer) -> &T[src]

Get a reference to the inner from the outer.

fn from_mut(outer: &mut Outer) -> &mut T[src]

Get a mutable reference to the inner from the outer.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> SaturatedConversion for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<S, T> UncheckedInto<T> for S where
    T: UncheckedFrom<S>, 
[src]

impl<T, S> UniqueSaturatedInto<T> for S where
    S: TryInto<T>,
    T: Bounded
[src]

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