Trait sc_network::service::traits::NetworkPeers

source ·
pub trait NetworkPeers {
Show 16 methods // Required methods fn set_authorized_peers(&self, peers: HashSet<PeerId>); fn set_authorized_only(&self, reserved_only: bool); fn add_known_address(&self, peer_id: PeerId, addr: Multiaddr); fn report_peer(&self, peer_id: PeerId, cost_benefit: ReputationChange); fn peer_reputation(&self, peer_id: &PeerId) -> i32; fn disconnect_peer(&self, peer_id: PeerId, protocol: ProtocolName); fn accept_unreserved_peers(&self); fn deny_unreserved_peers(&self); fn add_reserved_peer(&self, peer: MultiaddrWithPeerId) -> Result<(), String>; fn remove_reserved_peer(&self, peer_id: PeerId); fn set_reserved_peers( &self, protocol: ProtocolName, peers: HashSet<Multiaddr>, ) -> Result<(), String>; fn add_peers_to_reserved_set( &self, protocol: ProtocolName, peers: HashSet<Multiaddr>, ) -> Result<(), String>; fn remove_peers_from_reserved_set( &self, protocol: ProtocolName, peers: Vec<PeerId>, ) -> Result<(), String>; fn sync_num_connected(&self) -> usize; fn peer_role( &self, peer_id: PeerId, handshake: Vec<u8>, ) -> Option<ObservedRole>; fn reserved_peers<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<PeerId>, ()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait;
}
Expand description

Provides low-level API for manipulating network peers.

Required Methods§

source

fn set_authorized_peers(&self, peers: HashSet<PeerId>)

Set authorized peers.

Need a better solution to manage authorized peers, but now just use reserved peers for prototyping.

source

fn set_authorized_only(&self, reserved_only: bool)

Set authorized_only flag.

Need a better solution to decide authorized_only, but now just use reserved_only flag for prototyping.

source

fn add_known_address(&self, peer_id: PeerId, addr: Multiaddr)

Adds an address known to a node.

source

fn report_peer(&self, peer_id: PeerId, cost_benefit: ReputationChange)

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

source

fn peer_reputation(&self, peer_id: &PeerId) -> i32

Get peer reputation.

source

fn disconnect_peer(&self, peer_id: PeerId, protocol: ProtocolName)

Disconnect from a node as soon as possible.

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

source

fn accept_unreserved_peers(&self)

Connect to unreserved peers and allow unreserved peers to connect for syncing purposes.

source

fn deny_unreserved_peers(&self)

Disconnect from unreserved peers and deny new unreserved peers to connect for syncing purposes.

source

fn add_reserved_peer(&self, peer: MultiaddrWithPeerId) -> Result<(), String>

Adds a PeerId and its Multiaddr as reserved for a sync protocol (default peer set).

Returns an Err if the given string is not a valid multiaddress or contains an invalid peer ID (which includes the local peer ID).

source

fn remove_reserved_peer(&self, peer_id: PeerId)

Removes a PeerId from the list of reserved peers for a sync protocol (default peer set).

source

fn set_reserved_peers( &self, protocol: ProtocolName, peers: HashSet<Multiaddr>, ) -> Result<(), String>

Sets the reserved set of a protocol to the given set of peers.

Each Multiaddr must end with a /p2p/ component containing the PeerId. It can also consist of only /p2p/<peerid>.

The node will start establishing/accepting connections and substreams to/from peers in this set, if it doesn’t have any substream open with them yet.

Note however, if a call to this function results in less peers on the reserved set, they will not necessarily get disconnected (depending on available free slots in the peer set). If you want to also disconnect those removed peers, you will have to call remove_from_peers_set on those in addition to updating the reserved set. You can omit this step if the peer set is in reserved only mode.

Returns an Err if one of the given addresses is invalid or contains an invalid peer ID (which includes the local peer ID), or if protocol does not refer to a known protocol.

source

fn add_peers_to_reserved_set( &self, protocol: ProtocolName, peers: HashSet<Multiaddr>, ) -> Result<(), String>

Add peers to a peer set.

Each Multiaddr must end with a /p2p/ component containing the PeerId. It can also consist of only /p2p/<peerid>.

Returns an Err if one of the given addresses is invalid or contains an invalid peer ID (which includes the local peer ID), or if protocol does not refer to a know protocol.

source

fn remove_peers_from_reserved_set( &self, protocol: ProtocolName, peers: Vec<PeerId>, ) -> Result<(), String>

Remove peers from a peer set.

Returns Err if protocol does not refer to a known protocol.

source

fn sync_num_connected(&self) -> usize

Returns the number of peers in the sync peer set we’re connected to.

source

fn peer_role(&self, peer_id: PeerId, handshake: Vec<u8>) -> Option<ObservedRole>

Attempt to get peer role.

Right now the peer role is decoded from the received handshake for all protocols (/block-announces/1 has other information as well). If the handshake cannot be decoded into a role, the role queried from PeerStore and if the role is not stored there either, None is returned and the peer should be discarded.

source

fn reserved_peers<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<PeerId>, ()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get the list of reserved peers.

Returns an error if the NetworkWorker is no longer running.

Implementations on Foreign Types§

source§

impl<T> NetworkPeers for Arc<T>
where T: ?Sized + NetworkPeers,

source§

fn set_authorized_peers(&self, peers: HashSet<PeerId>)

source§

fn set_authorized_only(&self, reserved_only: bool)

source§

fn add_known_address(&self, peer_id: PeerId, addr: Multiaddr)

source§

fn report_peer(&self, peer_id: PeerId, cost_benefit: ReputationChange)

source§

fn peer_reputation(&self, peer_id: &PeerId) -> i32

source§

fn disconnect_peer(&self, peer_id: PeerId, protocol: ProtocolName)

source§

fn accept_unreserved_peers(&self)

source§

fn deny_unreserved_peers(&self)

source§

fn add_reserved_peer(&self, peer: MultiaddrWithPeerId) -> Result<(), String>

source§

fn remove_reserved_peer(&self, peer_id: PeerId)

source§

fn set_reserved_peers( &self, protocol: ProtocolName, peers: HashSet<Multiaddr>, ) -> Result<(), String>

source§

fn add_peers_to_reserved_set( &self, protocol: ProtocolName, peers: HashSet<Multiaddr>, ) -> Result<(), String>

source§

fn remove_peers_from_reserved_set( &self, protocol: ProtocolName, peers: Vec<PeerId>, ) -> Result<(), String>

source§

fn sync_num_connected(&self) -> usize

source§

fn peer_role(&self, peer_id: PeerId, handshake: Vec<u8>) -> Option<ObservedRole>

source§

fn reserved_peers<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<PeerId>, ()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Implementors§

source§

impl<B, H> NetworkPeers for NetworkService<B, H>
where B: BlockT + 'static, H: ExHashT,