pub trait NetworkPeers {
Show 15 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> ); fn add_to_peers_set( &self, protocol: ProtocolName, peers: HashSet<Multiaddr> ) -> Result<(), String>; fn remove_from_peers_set(&self, protocol: ProtocolName, peers: Vec<PeerId>); 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.

See also NetworkPeers::remove_from_peers_set, which has the same effect but also prevents the local node from re-establishing an outgoing substream to this peer until it is added again.

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.

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.

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

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

source

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

Remove peers from a peer set.

source

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

Add a peer to a set of peers.

If the set has slots available, it will try to open a substream with this peer.

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

source

fn remove_from_peers_set(&self, protocol: ProtocolName, peers: Vec<PeerId>)

Remove peers from a peer set.

If we currently have an open substream with this peer, it will soon be closed.

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§