Struct snarkos_node_router::Router
source · pub struct Router<N: Network>(/* private fields */);
Implementations§
source§impl<N: Network> Router<N>
impl<N: Network> Router<N>
sourcepub async fn handshake<'a>(
&'a self,
peer_addr: SocketAddr,
stream: &'a mut TcpStream,
peer_side: ConnectionSide,
genesis_header: Header<N>
) -> Result<(SocketAddr, Framed<&mut TcpStream, MessageCodec<N>>)>
pub async fn handshake<'a>( &'a self, peer_addr: SocketAddr, stream: &'a mut TcpStream, peer_side: ConnectionSide, genesis_header: Header<N> ) -> Result<(SocketAddr, Framed<&mut TcpStream, MessageCodec<N>>)>
Executes the handshake protocol.
source§impl<N: Network> Router<N>
impl<N: Network> Router<N>
sourcepub async fn new(
node_ip: SocketAddr,
node_type: NodeType,
account: Account<N>,
trusted_peers: &[SocketAddr],
max_peers: u16,
is_dev: bool
) -> Result<Self>
pub async fn new( node_ip: SocketAddr, node_type: NodeType, account: Account<N>, trusted_peers: &[SocketAddr], max_peers: u16, is_dev: bool ) -> Result<Self>
Initializes a new Router
instance.
source§impl<N: Network> Router<N>
impl<N: Network> Router<N>
sourcepub fn connect(&self, peer_ip: SocketAddr) -> Option<JoinHandle<bool>>
pub fn connect(&self, peer_ip: SocketAddr) -> Option<JoinHandle<bool>>
Attempts to connect to the given peer IP.
sourcepub fn disconnect(&self, peer_ip: SocketAddr) -> JoinHandle<bool>
pub fn disconnect(&self, peer_ip: SocketAddr) -> JoinHandle<bool>
Disconnects from the given peer IP, if the peer is connected.
sourcepub fn local_ip(&self) -> SocketAddr
pub fn local_ip(&self) -> SocketAddr
Returns the IP address of this node.
sourcepub fn is_local_ip(&self, ip: &SocketAddr) -> bool
pub fn is_local_ip(&self, ip: &SocketAddr) -> bool
Returns true
if the given IP is this node.
sourcepub fn private_key(&self) -> &PrivateKey<N>
pub fn private_key(&self) -> &PrivateKey<N>
Returns the account private key of the node.
sourcepub fn resolve_to_listener(&self, peer_addr: &SocketAddr) -> Option<SocketAddr>
pub fn resolve_to_listener(&self, peer_addr: &SocketAddr) -> Option<SocketAddr>
Returns the listener IP address from the (ambiguous) peer address.
sourcepub fn resolve_to_ambiguous(&self, peer_ip: &SocketAddr) -> Option<SocketAddr>
pub fn resolve_to_ambiguous(&self, peer_ip: &SocketAddr) -> Option<SocketAddr>
Returns the (ambiguous) peer address from the listener IP address.
sourcepub fn is_connected(&self, ip: &SocketAddr) -> bool
pub fn is_connected(&self, ip: &SocketAddr) -> bool
Returns true
if the node is connected to the given peer IP.
sourcepub fn is_connected_validator(&self, peer_ip: &SocketAddr) -> bool
pub fn is_connected_validator(&self, peer_ip: &SocketAddr) -> bool
Returns true
if the given peer IP is a connected validator.
sourcepub fn is_connected_prover(&self, peer_ip: &SocketAddr) -> bool
pub fn is_connected_prover(&self, peer_ip: &SocketAddr) -> bool
Returns true
if the given peer IP is a connected prover.
sourcepub fn is_connected_client(&self, peer_ip: &SocketAddr) -> bool
pub fn is_connected_client(&self, peer_ip: &SocketAddr) -> bool
Returns true
if the given peer IP is a connected client.
sourcepub fn is_connecting(&self, ip: &SocketAddr) -> bool
pub fn is_connecting(&self, ip: &SocketAddr) -> bool
Returns true
if the node is currently connecting to the given peer IP.
sourcepub fn is_restricted(&self, ip: &SocketAddr) -> bool
pub fn is_restricted(&self, ip: &SocketAddr) -> bool
Returns true
if the given IP is restricted.
sourcepub fn max_connected_peers(&self) -> usize
pub fn max_connected_peers(&self) -> usize
Returns the maximum number of connected peers.
sourcepub fn number_of_connected_peers(&self) -> usize
pub fn number_of_connected_peers(&self) -> usize
Returns the number of connected peers.
sourcepub fn number_of_connected_validators(&self) -> usize
pub fn number_of_connected_validators(&self) -> usize
Returns the number of connected validators.
sourcepub fn number_of_connected_provers(&self) -> usize
pub fn number_of_connected_provers(&self) -> usize
Returns the number of connected provers.
sourcepub fn number_of_connected_clients(&self) -> usize
pub fn number_of_connected_clients(&self) -> usize
Returns the number of connected clients.
sourcepub fn number_of_candidate_peers(&self) -> usize
pub fn number_of_candidate_peers(&self) -> usize
Returns the number of candidate peers.
sourcepub fn number_of_restricted_peers(&self) -> usize
pub fn number_of_restricted_peers(&self) -> usize
Returns the number of restricted peers.
sourcepub fn get_connected_peer(&self, ip: &SocketAddr) -> Option<Peer<N>>
pub fn get_connected_peer(&self, ip: &SocketAddr) -> Option<Peer<N>>
Returns the connected peer given the peer IP, if it exists.
sourcepub fn get_connected_peers(&self) -> Vec<Peer<N>>
pub fn get_connected_peers(&self) -> Vec<Peer<N>>
Returns the connected peers.
sourcepub fn connected_peers(&self) -> Vec<SocketAddr>
pub fn connected_peers(&self) -> Vec<SocketAddr>
Returns the list of connected peers.
sourcepub fn connected_validators(&self) -> Vec<SocketAddr>
pub fn connected_validators(&self) -> Vec<SocketAddr>
Returns the list of connected validators.
sourcepub fn connected_provers(&self) -> Vec<SocketAddr>
pub fn connected_provers(&self) -> Vec<SocketAddr>
Returns the list of connected provers.
sourcepub fn connected_clients(&self) -> Vec<SocketAddr>
pub fn connected_clients(&self) -> Vec<SocketAddr>
Returns the list of connected clients.
sourcepub fn candidate_peers(&self) -> IndexSet<SocketAddr>
pub fn candidate_peers(&self) -> IndexSet<SocketAddr>
Returns the list of candidate peers.
sourcepub fn restricted_peers(&self) -> Vec<SocketAddr>
pub fn restricted_peers(&self) -> Vec<SocketAddr>
Returns the list of restricted peers.
sourcepub fn trusted_peers(&self) -> &IndexSet<SocketAddr>
pub fn trusted_peers(&self) -> &IndexSet<SocketAddr>
Returns the list of trusted peers.
sourcepub fn bootstrap_peers(&self) -> Vec<SocketAddr>
pub fn bootstrap_peers(&self) -> Vec<SocketAddr>
Returns the list of bootstrap peers.
sourcepub fn connected_metrics(&self) -> Vec<(SocketAddr, NodeType)>
pub fn connected_metrics(&self) -> Vec<(SocketAddr, NodeType)>
Returns the list of metrics for the connected peers.
sourcepub fn insert_connected_peer(&self, peer: Peer<N>, peer_addr: SocketAddr)
pub fn insert_connected_peer(&self, peer: Peer<N>, peer_addr: SocketAddr)
Inserts the given peer into the connected peers.
sourcepub fn insert_candidate_peers(&self, peers: &[SocketAddr])
pub fn insert_candidate_peers(&self, peers: &[SocketAddr])
Inserts the given peer IPs to the set of candidate peers.
This method skips adding any given peers if the combined size exceeds the threshold, as the peer providing this list could be subverting the protocol.
sourcepub fn insert_restricted_peer(&self, peer_ip: SocketAddr)
pub fn insert_restricted_peer(&self, peer_ip: SocketAddr)
Inserts the given peer into the restricted peers.
sourcepub fn update_connected_peer<Fn: FnMut(&mut Peer<N>)>(
&self,
peer_ip: SocketAddr,
node_type: NodeType,
write_fn: Fn
) -> Result<()>
pub fn update_connected_peer<Fn: FnMut(&mut Peer<N>)>( &self, peer_ip: SocketAddr, node_type: NodeType, write_fn: Fn ) -> Result<()>
Updates the connected peer with the given function.
sourcepub fn remove_connected_peer(&self, peer_ip: SocketAddr)
pub fn remove_connected_peer(&self, peer_ip: SocketAddr)
Removes the connected peer and adds them to the candidate peers.
sourcepub fn remove_candidate_peer(&self, peer_ip: SocketAddr)
pub fn remove_candidate_peer(&self, peer_ip: SocketAddr)
Removes the given address from the candidate peers, if it exists.