pub struct Router<N: Network>(/* private fields */);Expand description
The router keeps track of connected and connecting peers. The actual network communication happens in Inbound/Outbound, which is implemented by Validator, Prover, and Client.
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>,
restrictions_id: Field<N>,
) -> Result<Option<ChallengeRequest<N>>>
pub async fn handshake<'a>( &'a self, peer_addr: SocketAddr, stream: &'a mut TcpStream, peer_side: ConnectionSide, genesis_header: Header<N>, restrictions_id: Field<N>, ) -> Result<Option<ChallengeRequest<N>>>
Executes the handshake protocol.
Source§impl<N: Network> Router<N>
impl<N: Network> Router<N>
Sourcepub fn send_ping(
&self,
peer_ip: SocketAddr,
block_locators: Option<BlockLocators<N>>,
) -> bool
pub fn send_ping( &self, peer_ip: SocketAddr, block_locators: Option<BlockLocators<N>>, ) -> bool
Sends a “Ping” message to the given peer.
Returns false if the peer does not exist or disconnected.
Sourcepub fn send(
&self,
peer_ip: SocketAddr,
message: Message<N>,
) -> Option<Receiver<Result<()>>>
pub fn send( &self, peer_ip: SocketAddr, message: Message<N>, ) -> Option<Receiver<Result<()>>>
Sends the given message to specified peer.
This function returns as soon as the message is queued to be sent,
without waiting for the actual delivery; instead, the caller is provided with a oneshot::Receiver
which can be used to determine when and whether the message has been delivered.
This returns None, if the peer does not exist or disconnected.
Source§impl<N: Network> Router<N>
impl<N: Network> Router<N>
Sourcepub async fn new(
node_ip: SocketAddr,
node_type: NodeType,
account: Account<N>,
ledger: Arc<dyn LedgerService<N>>,
trusted_peers: &[SocketAddr],
max_peers: u16,
rotate_external_peers: bool,
allow_external_peers: bool,
storage_mode: StorageMode,
is_dev: bool,
) -> Result<Self>
pub async fn new( node_ip: SocketAddr, node_type: NodeType, account: Account<N>, ledger: Arc<dyn LedgerService<N>>, trusted_peers: &[SocketAddr], max_peers: u16, rotate_external_peers: bool, allow_external_peers: bool, storage_mode: StorageMode, is_dev: bool, ) -> Result<Self>
Initializes a new Router instance.
Source§impl<N: Network> Router<N>
impl<N: Network> Router<N>
Sourcepub fn is_valid_message_version(&self, message_version: u32) -> bool
pub fn is_valid_message_version(&self, message_version: u32) -> bool
Returns true if the message version is valid.
Sourcepub fn private_key(&self) -> &PrivateKey<N>
pub fn private_key(&self) -> &PrivateKey<N>
Returns the account private key of the node.
Sourcepub fn rotate_external_peers(&self) -> bool
pub fn rotate_external_peers(&self) -> bool
Returns true if the node is periodically evicting more external peers.
Sourcepub fn allow_external_peers(&self) -> bool
pub fn allow_external_peers(&self) -> bool
Returns true if the node is engaging in P2P gossip to request more peers.
Sourcepub fn resolve_to_listener(
&self,
connected_addr: SocketAddr,
) -> Option<SocketAddr>
pub fn resolve_to_listener( &self, connected_addr: SocketAddr, ) -> Option<SocketAddr>
Returns the listener IP address from the (ambiguous) peer address.
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.
pub fn update_last_seen_for_connected_peer(&self, peer_ip: SocketAddr)
Trait Implementations§
Source§impl<N: Network> CommunicationService for Router<N>
impl<N: Network> CommunicationService for Router<N>
Source§fn prepare_block_request(start_height: u32, end_height: u32) -> Self::Message
fn prepare_block_request(start_height: u32, end_height: u32) -> Self::Message
Prepares a block request to be sent.
Source§fn send<'life0, 'async_trait>(
&'life0 self,
peer_ip: SocketAddr,
message: Self::Message,
) -> Pin<Box<dyn Future<Output = Option<Receiver<Result<()>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn send<'life0, 'async_trait>(
&'life0 self,
peer_ip: SocketAddr,
message: Self::Message,
) -> Pin<Box<dyn Future<Output = Option<Receiver<Result<()>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Sends the given message to specified peer.
This function returns as soon as the message is queued to be sent,
without waiting for the actual delivery; instead, the caller is provided with a [oneshot::Receiver]
which can be used to determine when and whether the message has been delivered.
Source§impl<N: Network> PeerPoolHandling<N> for Router<N>
impl<N: Network> PeerPoolHandling<N> for Router<N>
Source§const MAXIMUM_POOL_SIZE: usize = 10_000usize
const MAXIMUM_POOL_SIZE: usize = 10_000usize
const OWNER: &str = "[Router]"
Source§const PEER_SLASHING_COUNT: usize = 200usize
const PEER_SLASHING_COUNT: usize = 200usize
MAXIMUM_POOL_SIZE is reached.
It must be lower than MAXIMUM_POOL_SIZE.fn peer_pool(&self) -> &RwLock<HashMap<SocketAddr, Peer<N>>>
fn resolver(&self) -> &RwLock<Resolver<N>>
Source§fn local_ip(&self) -> SocketAddr
fn local_ip(&self) -> SocketAddr
Source§fn is_local_ip(&self, addr: SocketAddr) -> bool
fn is_local_ip(&self, addr: SocketAddr) -> bool
true if the given IP is this node.Source§fn is_valid_peer_ip(&self, ip: SocketAddr) -> bool
fn is_valid_peer_ip(&self, ip: SocketAddr) -> bool
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
fn max_connected_peers(&self) -> usize
Source§fn check_connection_attempt(&self, listener_addr: SocketAddr) -> Result<bool>
fn check_connection_attempt(&self, listener_addr: SocketAddr) -> Result<bool>
Source§fn connect(&self, listener_addr: SocketAddr) -> Option<JoinHandle<bool>>
fn connect(&self, listener_addr: SocketAddr) -> Option<JoinHandle<bool>>
Source§fn disconnect(&self, listener_addr: SocketAddr) -> JoinHandle<bool>
fn disconnect(&self, listener_addr: SocketAddr) -> JoinHandle<bool>
Source§fn downgrade_peer_to_candidate(&self, listener_addr: SocketAddr)
fn downgrade_peer_to_candidate(&self, listener_addr: SocketAddr)
Source§fn insert_candidate_peers(&self, listener_addrs: Vec<(SocketAddr, Option<u32>)>)
fn insert_candidate_peers(&self, listener_addrs: Vec<(SocketAddr, Option<u32>)>)
Source§fn remove_peer(&self, listener_addr: SocketAddr)
fn remove_peer(&self, listener_addr: SocketAddr)
Source§fn resolve_to_ambiguous(&self, listener_addr: SocketAddr) -> Option<SocketAddr>
fn resolve_to_ambiguous(&self, listener_addr: SocketAddr) -> Option<SocketAddr>
Source§fn resolve_to_aleo_addr(&self, listener_addr: SocketAddr) -> Option<Address<N>>
fn resolve_to_aleo_addr(&self, listener_addr: SocketAddr) -> Option<Address<N>>
Source§fn is_connecting(&self, listener_addr: SocketAddr) -> bool
fn is_connecting(&self, listener_addr: SocketAddr) -> bool
true if the node is connecting to the given peer’s listener address.Source§fn is_connected(&self, listener_addr: SocketAddr) -> bool
fn is_connected(&self, listener_addr: SocketAddr) -> bool
true if the node is connected to the given peer listener address.Source§fn is_trusted(&self, listener_addr: SocketAddr) -> bool
fn is_trusted(&self, listener_addr: SocketAddr) -> bool
true if the given listener address is trusted.Source§fn number_of_peers(&self) -> usize
fn number_of_peers(&self) -> usize
Source§fn number_of_connected_peers(&self) -> usize
fn number_of_connected_peers(&self) -> usize
Source§fn number_of_connecting_peers(&self) -> usize
fn number_of_connecting_peers(&self) -> usize
Source§fn number_of_candidate_peers(&self) -> usize
fn number_of_candidate_peers(&self) -> usize
Source§fn get_connected_peer(
&self,
listener_addr: SocketAddr,
) -> Option<ConnectedPeer<N>>
fn get_connected_peer( &self, listener_addr: SocketAddr, ) -> Option<ConnectedPeer<N>>
Source§fn 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
Source§fn get_peers(&self) -> Vec<Peer<N>>
fn get_peers(&self) -> Vec<Peer<N>>
Source§fn get_connected_peers(&self) -> Vec<ConnectedPeer<N>>
fn get_connected_peers(&self) -> Vec<ConnectedPeer<N>>
Source§fn 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>>
Source§fn 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>>
Source§fn connected_peers(&self) -> Vec<SocketAddr>
fn connected_peers(&self) -> Vec<SocketAddr>
Source§fn trusted_peers(&self) -> Vec<SocketAddr>
fn trusted_peers(&self) -> Vec<SocketAddr>
Source§fn get_candidate_peers(&self) -> Vec<CandidatePeer>
fn get_candidate_peers(&self) -> Vec<CandidatePeer>
Source§fn unconnected_trusted_peers(&self) -> HashSet<SocketAddr>
fn unconnected_trusted_peers(&self) -> HashSet<SocketAddr>
Source§fn load_cached_peers(
storage_mode: &StorageMode,
filename: &str,
) -> Result<Vec<SocketAddr>>
fn load_cached_peers( storage_mode: &StorageMode, filename: &str, ) -> Result<Vec<SocketAddr>>
Source§fn 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<()>
fn add_connecting_peer(&self, listener_addr: SocketAddr) -> bool
Source§fn ip_ban_peer(&self, listener_addr: SocketAddr, reason: Option<&str>)
fn ip_ban_peer(&self, listener_addr: SocketAddr, reason: Option<&str>)
Source§fn is_ip_banned(&self, ip: IpAddr) -> bool
fn is_ip_banned(&self, ip: IpAddr) -> bool
Source§fn update_ip_ban(&self, ip: IpAddr)
fn update_ip_ban(&self, ip: IpAddr)
Source§impl<N: Network> Writing for Router<N>
impl<N: Network> Writing for Router<N>
Source§fn codec(&self, _addr: SocketAddr, _side: ConnectionSide) -> Self::Codec
fn codec(&self, _addr: SocketAddr, _side: ConnectionSide) -> Self::Codec
Creates an [Encoder] used to write the outbound messages to the target stream.
The side parameter indicates the connection side from the node’s perspective.
Source§type Codec = MessageCodec<N>
type Codec = MessageCodec<N>
Encoder used to write outbound messages to the target stream.Source§type Message = Message<N>
type Message = Message<N>
Self::Codec.Source§fn message_queue_depth(&self) -> usize
fn message_queue_depth(&self) -> usize
Source§fn enable_writing<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: Sync + 'async_trait,
fn enable_writing<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: Sync + 'async_trait,
Source§fn unicast(
&self,
addr: SocketAddr,
message: Self::Message,
) -> Result<Receiver<Result<(), Error>>, Error>
fn unicast( &self, addr: SocketAddr, message: Self::Message, ) -> Result<Receiver<Result<(), Error>>, Error>
SocketAddr. Returns as soon as the message is queued to
be sent, without waiting for the actual delivery; instead, the caller is provided with a oneshot::Receiver
which can be used to determine when and whether the message has been delivered. Read moreSource§fn broadcast(&self, message: Self::Message) -> Result<(), Error>
fn broadcast(&self, message: Self::Message) -> Result<(), Error>
Writing::unicast for each address returned by [Tcp::connected_addrs]. Read moreAuto Trait Implementations§
impl<N> Freeze for Router<N>
impl<N> !RefUnwindSafe for Router<N>
impl<N> Send for Router<N>
impl<N> Sync for Router<N>
impl<N> Unpin for Router<N>
impl<N> !UnwindSafe for Router<N>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more