pub trait NetworkPeers {
Show 13 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, who: PeerId, cost_benefit: ReputationChange); fn disconnect_peer(&self, who: 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;
}
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, who: PeerId, cost_benefit: ReputationChange)

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

source

fn disconnect_peer(&self, who: 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.

Implementations on Foreign Types§

source§

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

Implementors§

source§

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