sc_network::service::traits

Trait 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,