PeerPoolHandling

Trait PeerPoolHandling 

Source
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§

Source

const OWNER: &str

Source

const MAXIMUM_POOL_SIZE: usize

The maximum number of peers permitted to be stored in the peer pool.

Source

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§

Source

fn peer_pool(&self) -> &RwLock<HashMap<SocketAddr, Peer<N>>>

Source

fn resolver(&self) -> &RwLock<Resolver<N>>

Source

fn is_dev(&self) -> bool

Returns true if the owning node is in development mode.

Provided Methods§

Source

fn local_ip(&self) -> SocketAddr

Returns the listener address of this node.

Source

fn is_local_ip(&self, addr: SocketAddr) -> bool

Returns true if the given IP is this node.

Source

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.

Source

fn max_connected_peers(&self) -> usize

Returns the maximum number of connected peers.

Source

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

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.

Source

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.

Source

fn downgrade_peer_to_candidate(&self, listener_addr: SocketAddr)

Downgrades a connected peer to candidate status.

Source

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.

Source

fn remove_peer(&self, listener_addr: SocketAddr)

Completely removes an entry from the peer pool.

Source

fn resolve_to_ambiguous(&self, listener_addr: SocketAddr) -> Option<SocketAddr>

Returns the connected peer address from the listener IP address.

Source

fn resolve_to_aleo_addr(&self, listener_addr: SocketAddr) -> Option<Address<N>>

Returns the connected peer aleo address from the listener IP address.

Source

fn is_connecting(&self, listener_addr: SocketAddr) -> bool

Returns true if the node is connecting to the given peer’s listener address.

Source

fn is_connected(&self, listener_addr: SocketAddr) -> bool

Returns true if the node is connected to the given peer listener address.

Source

fn is_trusted(&self, listener_addr: SocketAddr) -> bool

Returns true if the given listener address is trusted.

Source

fn number_of_peers(&self) -> usize

Returns the number of all peers.

Source

fn number_of_connected_peers(&self) -> usize

Returns the number of connected peers.

Source

fn number_of_connecting_peers(&self) -> usize

Returns the number of connecting peers.

Source

fn number_of_candidate_peers(&self) -> usize

Returns the number of candidate peers.

Source

fn get_connected_peer( &self, listener_addr: SocketAddr, ) -> Option<ConnectedPeer<N>>

Returns the connected peer given the peer IP, if it exists.

Source

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.

Source

fn get_peers(&self) -> Vec<Peer<N>>

Returns the list of all peers (connected, connecting, and candidate).

Source

fn get_connected_peers(&self) -> Vec<ConnectedPeer<N>>

Returns all connected peers.

Source

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

Source

fn filter_connected_peers<P: FnMut(&ConnectedPeer<N>) -> bool>( &self, predicate: P, ) -> Vec<ConnectedPeer<N>>

Returns all connected peers that satisify the given predicate.

Source

fn connected_peers(&self) -> Vec<SocketAddr>

Returns the list of connected peers.

Source

fn trusted_peers(&self) -> Vec<SocketAddr>

Returns the list of trusted peers.

Source

fn get_candidate_peers(&self) -> Vec<CandidatePeer>

Returns the list of candidate peers.

Source

fn unconnected_trusted_peers(&self) -> HashSet<SocketAddr>

Returns the list of unconnected trusted peers.

Source

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.

Source

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.

Source

fn add_connecting_peer(&self, listener_addr: SocketAddr) -> bool

Source

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.

Source

fn is_ip_banned(&self, ip: IpAddr) -> bool

Check whether the given IP address is currently banned.

Source

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.

Implementors§

Source§

impl<N: Network> PeerPoolHandling<N> for Router<N>

Source§

const MAXIMUM_POOL_SIZE: usize = 10_000usize

Source§

const OWNER: &str = "[Router]"

Source§

const PEER_SLASHING_COUNT: usize = 200usize