pub trait PeerPoolHandling<N: Network>: P2P {
const OWNER: &str;
const MAXIMUM_POOL_SIZE: usize;
const PEER_SLASHING_COUNT: usize;
Show 38 methods
// Required methods
fn peer_pool(&self) -> &RwLock<HashMap<SocketAddr, Peer<N>>>;
fn resolver(&self) -> &RwLock<Resolver<N>>;
fn is_dev(&self) -> bool;
// Provided methods
fn local_ip(&self) -> SocketAddr { ... }
fn is_local_ip(&self, addr: SocketAddr) -> bool { ... }
fn is_valid_peer_ip(&self, ip: SocketAddr) -> bool { ... }
fn max_connected_peers(&self) -> usize { ... }
fn check_connection_attempt(
&self,
listener_addr: SocketAddr,
) -> Result<bool> { ... }
fn connect(&self, listener_addr: SocketAddr) -> Option<JoinHandle<bool>> { ... }
fn disconnect(&self, listener_addr: SocketAddr) -> JoinHandle<bool> { ... }
fn downgrade_peer_to_candidate(&self, listener_addr: SocketAddr) { ... }
fn insert_candidate_peers(
&self,
listener_addrs: Vec<(SocketAddr, Option<u32>)>,
) { ... }
fn remove_peer(&self, listener_addr: SocketAddr) { ... }
fn resolve_to_ambiguous(
&self,
listener_addr: SocketAddr,
) -> Option<SocketAddr> { ... }
fn resolve_to_aleo_addr(
&self,
listener_addr: SocketAddr,
) -> Option<Address<N>> { ... }
fn is_connecting(&self, listener_addr: SocketAddr) -> bool { ... }
fn is_connected(&self, listener_addr: SocketAddr) -> bool { ... }
fn is_trusted(&self, listener_addr: SocketAddr) -> bool { ... }
fn number_of_peers(&self) -> usize { ... }
fn number_of_connected_peers(&self) -> usize { ... }
fn number_of_connecting_peers(&self) -> usize { ... }
fn number_of_candidate_peers(&self) -> usize { ... }
fn get_connected_peer(
&self,
listener_addr: SocketAddr,
) -> Option<ConnectedPeer<N>> { ... }
fn update_connected_peer<F: FnMut(&mut ConnectedPeer<N>)>(
&self,
listener_addr: &SocketAddr,
update_fn: F,
) -> bool { ... }
fn get_peers(&self) -> Vec<Peer<N>> { ... }
fn get_connected_peers(&self) -> Vec<ConnectedPeer<N>> { ... }
fn get_best_connected_peers(
&self,
max_entries: Option<usize>,
) -> Vec<ConnectedPeer<N>> { ... }
fn filter_connected_peers<P: FnMut(&ConnectedPeer<N>) -> bool>(
&self,
predicate: P,
) -> Vec<ConnectedPeer<N>> { ... }
fn connected_peers(&self) -> Vec<SocketAddr> { ... }
fn trusted_peers(&self) -> Vec<SocketAddr> { ... }
fn get_candidate_peers(&self) -> Vec<CandidatePeer> { ... }
fn unconnected_trusted_peers(&self) -> HashSet<SocketAddr> { ... }
fn load_cached_peers(
storage_mode: &StorageMode,
filename: &str,
) -> Result<Vec<SocketAddr>> { ... }
fn save_best_peers(
&self,
storage_mode: &StorageMode,
filename: &str,
max_entries: Option<usize>,
) -> Result<()> { ... }
fn add_connecting_peer(&self, listener_addr: SocketAddr) -> bool { ... }
fn ip_ban_peer(&self, listener_addr: SocketAddr, reason: Option<&str>) { ... }
fn is_ip_banned(&self, ip: IpAddr) -> bool { ... }
fn update_ip_ban(&self, ip: IpAddr) { ... }
}Required Associated Constants§
const OWNER: &str
Sourceconst MAXIMUM_POOL_SIZE: usize
const MAXIMUM_POOL_SIZE: usize
The maximum number of peers permitted to be stored in the peer pool.
Sourceconst PEER_SLASHING_COUNT: usize
const PEER_SLASHING_COUNT: usize
The number of candidate peers to be removed from the pool once MAXIMUM_POOL_SIZE is reached.
It must be lower than MAXIMUM_POOL_SIZE.
Required Methods§
fn peer_pool(&self) -> &RwLock<HashMap<SocketAddr, Peer<N>>>
fn resolver(&self) -> &RwLock<Resolver<N>>
Provided Methods§
Sourcefn local_ip(&self) -> SocketAddr
fn local_ip(&self) -> SocketAddr
Returns the listener address of this node.
Sourcefn is_local_ip(&self, addr: SocketAddr) -> bool
fn is_local_ip(&self, addr: SocketAddr) -> bool
Returns true if the given IP is this node.
Sourcefn is_valid_peer_ip(&self, ip: SocketAddr) -> bool
fn is_valid_peer_ip(&self, ip: SocketAddr) -> bool
Returns true if the given IP is not this node, is not a bogon address, and is not unspecified.
Sourcefn max_connected_peers(&self) -> usize
fn max_connected_peers(&self) -> usize
Returns the maximum number of connected peers.
Sourcefn check_connection_attempt(&self, listener_addr: SocketAddr) -> Result<bool>
fn check_connection_attempt(&self, listener_addr: SocketAddr) -> Result<bool>
Ensure we are allowed to connect to the given listener address of a peer.
§Return Values
Ok(true)if already connected (or connecting) to the peer.Ok(false)if not connected to the peer but allowed to.Err(err)if not allowed to connect to the peer.
Sourcefn connect(&self, listener_addr: SocketAddr) -> Option<JoinHandle<bool>>
fn connect(&self, listener_addr: SocketAddr) -> Option<JoinHandle<bool>>
Attempts to connect to the given peer’s listener address.
Returns None if we are already connected to the peer or cannot connect. Otherwise, it returns a handle to the tokio tasks that sets up the connection.
Sourcefn disconnect(&self, listener_addr: SocketAddr) -> JoinHandle<bool>
fn disconnect(&self, listener_addr: SocketAddr) -> JoinHandle<bool>
Disconnects from the given peer IP, if the peer is connected. The returned boolean indicates whether the peer was actually disconnected from, or if this was a noop.
Sourcefn downgrade_peer_to_candidate(&self, listener_addr: SocketAddr)
fn downgrade_peer_to_candidate(&self, listener_addr: SocketAddr)
Downgrades a connected peer to candidate status.
Sourcefn insert_candidate_peers(&self, listener_addrs: Vec<(SocketAddr, Option<u32>)>)
fn insert_candidate_peers(&self, listener_addrs: Vec<(SocketAddr, Option<u32>)>)
Adds new candidate peers to the peer pool, ensuring their validity and following the limit on the number of peers in the pool. The listener addresses may be paired with the last known block height of the associated peer.
Sourcefn remove_peer(&self, listener_addr: SocketAddr)
fn remove_peer(&self, listener_addr: SocketAddr)
Completely removes an entry from the peer pool.
Sourcefn resolve_to_ambiguous(&self, listener_addr: SocketAddr) -> Option<SocketAddr>
fn resolve_to_ambiguous(&self, listener_addr: SocketAddr) -> Option<SocketAddr>
Returns the connected peer address from the listener IP address.
Sourcefn resolve_to_aleo_addr(&self, listener_addr: SocketAddr) -> Option<Address<N>>
fn resolve_to_aleo_addr(&self, listener_addr: SocketAddr) -> Option<Address<N>>
Returns the connected peer aleo address from the listener IP address.
Sourcefn is_connecting(&self, listener_addr: SocketAddr) -> bool
fn is_connecting(&self, listener_addr: SocketAddr) -> bool
Returns true if the node is connecting to the given peer’s listener address.
Sourcefn is_connected(&self, listener_addr: SocketAddr) -> bool
fn is_connected(&self, listener_addr: SocketAddr) -> bool
Returns true if the node is connected to the given peer listener address.
Sourcefn is_trusted(&self, listener_addr: SocketAddr) -> bool
fn is_trusted(&self, listener_addr: SocketAddr) -> bool
Returns true if the given listener address is trusted.
Sourcefn number_of_peers(&self) -> usize
fn number_of_peers(&self) -> usize
Returns the number of all peers.
Sourcefn number_of_connected_peers(&self) -> usize
fn number_of_connected_peers(&self) -> usize
Returns the number of connected peers.
Sourcefn number_of_connecting_peers(&self) -> usize
fn number_of_connecting_peers(&self) -> usize
Returns the number of connecting peers.
Sourcefn number_of_candidate_peers(&self) -> usize
fn number_of_candidate_peers(&self) -> usize
Returns the number of candidate peers.
Sourcefn get_connected_peer(
&self,
listener_addr: SocketAddr,
) -> Option<ConnectedPeer<N>>
fn get_connected_peer( &self, listener_addr: SocketAddr, ) -> Option<ConnectedPeer<N>>
Returns the connected peer given the peer IP, if it exists.
Sourcefn update_connected_peer<F: FnMut(&mut ConnectedPeer<N>)>(
&self,
listener_addr: &SocketAddr,
update_fn: F,
) -> bool
fn update_connected_peer<F: FnMut(&mut ConnectedPeer<N>)>( &self, listener_addr: &SocketAddr, update_fn: F, ) -> bool
Updates the connected peer - if it exists - given the peer IP and a closure. The returned status indicates whether the update was successful, i.e. the peer had existed.
Sourcefn get_peers(&self) -> Vec<Peer<N>>
fn get_peers(&self) -> Vec<Peer<N>>
Returns the list of all peers (connected, connecting, and candidate).
Sourcefn get_connected_peers(&self) -> Vec<ConnectedPeer<N>>
fn get_connected_peers(&self) -> Vec<ConnectedPeer<N>>
Returns all connected peers.
Sourcefn get_best_connected_peers(
&self,
max_entries: Option<usize>,
) -> Vec<ConnectedPeer<N>>
fn get_best_connected_peers( &self, max_entries: Option<usize>, ) -> Vec<ConnectedPeer<N>>
Returns an optionally bounded list of all connected peers sorted by their block height (highest first) and failure count (lowest first).
Sourcefn filter_connected_peers<P: FnMut(&ConnectedPeer<N>) -> bool>(
&self,
predicate: P,
) -> Vec<ConnectedPeer<N>>
fn filter_connected_peers<P: FnMut(&ConnectedPeer<N>) -> bool>( &self, predicate: P, ) -> Vec<ConnectedPeer<N>>
Returns all connected peers that satisify the given predicate.
Sourcefn connected_peers(&self) -> Vec<SocketAddr>
fn connected_peers(&self) -> Vec<SocketAddr>
Returns the list of connected peers.
Sourcefn trusted_peers(&self) -> Vec<SocketAddr>
fn trusted_peers(&self) -> Vec<SocketAddr>
Returns the list of trusted peers.
Sourcefn get_candidate_peers(&self) -> Vec<CandidatePeer>
fn get_candidate_peers(&self) -> Vec<CandidatePeer>
Returns the list of candidate peers.
Sourcefn unconnected_trusted_peers(&self) -> HashSet<SocketAddr>
fn unconnected_trusted_peers(&self) -> HashSet<SocketAddr>
Returns the list of unconnected trusted peers.
Sourcefn load_cached_peers(
storage_mode: &StorageMode,
filename: &str,
) -> Result<Vec<SocketAddr>>
fn load_cached_peers( storage_mode: &StorageMode, filename: &str, ) -> Result<Vec<SocketAddr>>
Loads any previously cached peer addresses so they can be introduced as initial candidate peers to connect to.
Sourcefn save_best_peers(
&self,
storage_mode: &StorageMode,
filename: &str,
max_entries: Option<usize>,
) -> Result<()>
fn save_best_peers( &self, storage_mode: &StorageMode, filename: &str, max_entries: Option<usize>, ) -> Result<()>
Preserve the peers who have the greatest known block heights, and the lowest number of registered network failures.
fn add_connecting_peer(&self, listener_addr: SocketAddr) -> bool
Sourcefn ip_ban_peer(&self, listener_addr: SocketAddr, reason: Option<&str>)
fn ip_ban_peer(&self, listener_addr: SocketAddr, reason: Option<&str>)
Temporarily IP-ban and disconnect from the peer with the given listener address and an optional reason for the ban. This also removes the peer from the candidate pool.
Sourcefn is_ip_banned(&self, ip: IpAddr) -> bool
fn is_ip_banned(&self, ip: IpAddr) -> bool
Check whether the given IP address is currently banned.
Sourcefn update_ip_ban(&self, ip: IpAddr)
fn update_ip_ban(&self, ip: IpAddr)
Insert or update a banned IP.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.