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§
Set authorized peers.
Need a better solution to manage authorized peers, but now just use reserved peers for prototyping.
Set authorized_only flag.
Need a better solution to decide authorized_only, but now just use reserved_only flag for prototyping.
Sourcefn add_known_address(&self, peer_id: PeerId, addr: Multiaddr)
fn add_known_address(&self, peer_id: PeerId, addr: Multiaddr)
Adds an address known to a node.
Sourcefn report_peer(&self, peer_id: PeerId, cost_benefit: ReputationChange)
fn report_peer(&self, peer_id: PeerId, cost_benefit: ReputationChange)
Report a given peer as either beneficial (+) or costly (-) according to the given scalar.
Sourcefn peer_reputation(&self, peer_id: &PeerId) -> i32
fn peer_reputation(&self, peer_id: &PeerId) -> i32
Get peer reputation.
Sourcefn disconnect_peer(&self, peer_id: PeerId, protocol: ProtocolName)
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.
Sourcefn accept_unreserved_peers(&self)
fn accept_unreserved_peers(&self)
Connect to unreserved peers and allow unreserved peers to connect for syncing purposes.
Sourcefn deny_unreserved_peers(&self)
fn deny_unreserved_peers(&self)
Disconnect from unreserved peers and deny new unreserved peers to connect for syncing purposes.
Sourcefn add_reserved_peer(&self, peer: MultiaddrWithPeerId) -> Result<(), String>
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).
Sourcefn remove_reserved_peer(&self, peer_id: PeerId)
fn remove_reserved_peer(&self, peer_id: PeerId)
Removes a PeerId
from the list of reserved peers for a sync protocol (default peer set).
Sourcefn set_reserved_peers(
&self,
protocol: ProtocolName,
peers: HashSet<Multiaddr>,
) -> Result<(), String>
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.
Sourcefn add_peers_to_reserved_set(
&self,
protocol: ProtocolName,
peers: HashSet<Multiaddr>,
) -> Result<(), String>
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.
Sourcefn remove_peers_from_reserved_set(
&self,
protocol: ProtocolName,
peers: Vec<PeerId>,
) -> Result<(), String>
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.
Sourcefn sync_num_connected(&self) -> usize
fn sync_num_connected(&self) -> usize
Returns the number of peers in the sync peer set we’re connected to.
Sourcefn peer_role(&self, peer_id: PeerId, handshake: Vec<u8>) -> Option<ObservedRole>
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.