pub struct BootstrapClient<N: Network>(/* private fields */);Implementations§
Source§impl<N: Network> BootstrapClient<N>
impl<N: Network> BootstrapClient<N>
pub async fn new( listener_addr: SocketAddr, account: Account<N>, genesis_header: Header<N>, dev: Option<u16>, ) -> Result<Self>
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,
connected_addr: SocketAddr,
) -> Option<SocketAddr>
pub fn resolve_to_listener( &self, connected_addr: SocketAddr, ) -> Option<SocketAddr>
Returns the listener IP address from the connected peer address.
Sourcepub async fn get_or_update_committee(
&self,
) -> Result<Option<HashSet<Address<N>>>>
pub async fn get_or_update_committee( &self, ) -> Result<Option<HashSet<Address<N>>>>
Returns the current validator committee or updates it from the explorer, if we are capable of obtaining it from the network.
Sourcepub fn get_known_validators(&self) -> HashMap<SocketAddr, Address<N>>
pub fn get_known_validators(&self) -> HashMap<SocketAddr, Address<N>>
Returns the list of known validators connected in Gateway mode.
Trait Implementations§
Source§impl<N: Clone + Network> Clone for BootstrapClient<N>
impl<N: Clone + Network> Clone for BootstrapClient<N>
Source§fn clone(&self) -> BootstrapClient<N>
fn clone(&self) -> BootstrapClient<N>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<N: Network> Deref for BootstrapClient<N>
impl<N: Network> Deref for BootstrapClient<N>
Source§impl<N: Network> Disconnect for BootstrapClient<N>
impl<N: Network> Disconnect for BootstrapClient<N>
Source§fn handle_disconnect<'life0, 'async_trait>(
&'life0 self,
peer_addr: SocketAddr,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn handle_disconnect<'life0, 'async_trait>(
&'life0 self,
peer_addr: SocketAddr,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Any extra operations to be performed during a disconnect.
Source§fn enable_disconnect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: Sync + 'async_trait,
fn enable_disconnect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: Sync + 'async_trait,
Attaches the behavior specified in
Disconnect::handle_disconnect to every occurrence of the
node disconnecting from a peer.Source§impl<N: Network> Handshake for BootstrapClient<N>
impl<N: Network> Handshake for BootstrapClient<N>
Source§fn perform_handshake<'life0, 'async_trait>(
&'life0 self,
connection: Connection,
) -> Pin<Box<dyn Future<Output = Result<Connection>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn perform_handshake<'life0, 'async_trait>(
&'life0 self,
connection: Connection,
) -> Pin<Box<dyn Future<Output = Result<Connection>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Performs the handshake; temporarily assumes control of the
Connection and returns it if the handshake is
successful.Source§const TIMEOUT_MS: u64 = 3_000u64
const TIMEOUT_MS: u64 = 3_000u64
The maximum time allowed for a connection to perform a handshake before it is rejected. Read more
Source§fn enable_handshake<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: Sync + 'async_trait,
fn enable_handshake<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: Sync + 'async_trait,
Prepares the node to perform specified network handshakes.
Source§fn borrow_stream<'a>(&self, conn: &'a mut Connection) -> &'a mut TcpStream
fn borrow_stream<'a>(&self, conn: &'a mut Connection) -> &'a mut TcpStream
Borrows the full connection stream to be used in the implementation of
Handshake::perform_handshake.Source§fn take_stream(&self, conn: &mut Connection) -> TcpStream
fn take_stream(&self, conn: &mut Connection) -> TcpStream
Assumes full control of a connection’s stream in the implementation of
Handshake::perform_handshake, by
the end of which it must be followed by Handshake::return_stream.Source§fn return_stream<T>(&self, conn: &mut Connection, stream: T)
fn return_stream<T>(&self, conn: &mut Connection, stream: T)
This method only needs to be called if
Handshake::take_stream had been called before; it is used to
return a (potentially modified) stream back to the applicable connection.Source§impl<N: Network> OnConnect for BootstrapClient<N>
impl<N: Network> OnConnect for BootstrapClient<N>
Source§fn on_connect<'life0, 'async_trait>(
&'life0 self,
peer_addr: SocketAddr,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn on_connect<'life0, 'async_trait>(
&'life0 self,
peer_addr: SocketAddr,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Any initial actions to be executed after the handshake is concluded; in order to be able to
communicate with the peer in the usual manner (i.e. via [
Writing]), only its SocketAddr
(as opposed to the related [Connection] object) is provided as an argument.Source§fn enable_on_connect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: Sync + 'async_trait,
fn enable_on_connect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: Sync + 'async_trait,
Attaches the behavior specified in
OnConnect::on_connect right after every successful
handshake.Source§impl<N: Network> P2P for BootstrapClient<N>
impl<N: Network> P2P for BootstrapClient<N>
Source§impl<N: Network> PeerPoolHandling<N> for BootstrapClient<N>
impl<N: Network> PeerPoolHandling<N> for BootstrapClient<N>
Source§const MAXIMUM_POOL_SIZE: usize = 10_000usize
const MAXIMUM_POOL_SIZE: usize = 10_000usize
The maximum number of peers permitted to be stored in the peer pool.
const OWNER: &'static str = "[Network]"
Source§const PEER_SLASHING_COUNT: usize = 200usize
const PEER_SLASHING_COUNT: usize = 200usize
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.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
Returns the listener address of this node.
Source§fn is_local_ip(&self, addr: SocketAddr) -> bool
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
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
fn max_connected_peers(&self) -> usize
Returns the maximum number of connected peers.
Source§fn check_connection_attempt(
&self,
listener_addr: SocketAddr,
) -> Result<bool, Error>
fn check_connection_attempt( &self, listener_addr: SocketAddr, ) -> Result<bool, Error>
Ensure we are allowed to connect to the given listener address of a peer. Read more
Source§fn 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. Read more
Source§fn 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.
Source§fn downgrade_peer_to_candidate(&self, listener_addr: SocketAddr)
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>)>)
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)
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>
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>>
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
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
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
fn is_trusted(&self, listener_addr: SocketAddr) -> bool
Returns
true if the given listener address is trusted.Source§fn number_of_peers(&self) -> usize
fn number_of_peers(&self) -> usize
Returns the number of all peers.
Source§fn number_of_connected_peers(&self) -> usize
fn number_of_connected_peers(&self) -> usize
Returns the number of connected peers.
Source§fn number_of_connecting_peers(&self) -> usize
fn number_of_connecting_peers(&self) -> usize
Returns the number of connecting peers.
Source§fn number_of_candidate_peers(&self) -> usize
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>>
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>(
&self,
listener_addr: &SocketAddr,
update_fn: F,
) -> boolwhere
F: FnMut(&mut ConnectedPeer<N>),
fn update_connected_peer<F>(
&self,
listener_addr: &SocketAddr,
update_fn: F,
) -> boolwhere
F: FnMut(&mut ConnectedPeer<N>),
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>>
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>>
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>>
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>(&self, predicate: P) -> Vec<ConnectedPeer<N>>
fn filter_connected_peers<P>(&self, predicate: P) -> Vec<ConnectedPeer<N>>
Returns all connected peers that satisify the given predicate.
Source§fn connected_peers(&self) -> Vec<SocketAddr>
fn connected_peers(&self) -> Vec<SocketAddr>
Returns the list of connected peers.
Source§fn trusted_peers(&self) -> Vec<SocketAddr>
fn trusted_peers(&self) -> Vec<SocketAddr>
Returns the list of trusted peers.
Source§fn get_candidate_peers(&self) -> Vec<CandidatePeer>
fn get_candidate_peers(&self) -> Vec<CandidatePeer>
Returns the list of candidate peers.
Source§fn unconnected_trusted_peers(&self) -> HashSet<SocketAddr>
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>, Error>
fn load_cached_peers( storage_mode: &StorageMode, filename: &str, ) -> Result<Vec<SocketAddr>, Error>
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<(), Error>
fn save_best_peers( &self, storage_mode: &StorageMode, filename: &str, max_entries: Option<usize>, ) -> Result<(), Error>
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
Source§fn 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.
Source§fn is_ip_banned(&self, ip: IpAddr) -> bool
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)
fn update_ip_ban(&self, ip: IpAddr)
Insert or update a banned IP.
Source§impl<N: Network> Reading for BootstrapClient<N>
impl<N: Network> Reading for BootstrapClient<N>
Source§fn codec(&self, _peer_addr: SocketAddr, _side: ConnectionSide) -> Self::Codec
fn codec(&self, _peer_addr: SocketAddr, _side: ConnectionSide) -> Self::Codec
Creates a Decoder used to interpret messages from the network.
The side param indicates the connection side from the node’s perspective.
Source§fn process_message<'life0, 'async_trait>(
&'life0 self,
peer_addr: SocketAddr,
message: Self::Message,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn process_message<'life0, 'async_trait>(
&'life0 self,
peer_addr: SocketAddr,
message: Self::Message,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Processes a message received from the network.
Source§type Codec = BootstrapClientCodec<N>
type Codec = BootstrapClientCodec<N>
The user-supplied
Decoder used to interpret inbound messages.Source§type Message = <BootstrapClientCodec<N> as Decoder>::Item
type Message = <BootstrapClientCodec<N> as Decoder>::Item
The final (deserialized) type of inbound messages.
Source§fn message_queue_depth(&self) -> usize
fn message_queue_depth(&self) -> usize
The depth of per-connection queues used to process inbound messages; the greater it is, the more inbound
messages the node can enqueue, but setting it to a large value can make the node more susceptible to DoS
attacks. Read more
Source§const INITIAL_BUFFER_SIZE: usize = 1_048_576usize
const INITIAL_BUFFER_SIZE: usize = 1_048_576usize
The initial size of a per-connection buffer for reading inbound messages. Can be set to the maximum expected size
of the inbound message in order to only allocate it once. Read more
Source§impl<N: Network> Writing for BootstrapClient<N>
impl<N: Network> Writing for BootstrapClient<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 = BootstrapClientCodec<N>
type Codec = BootstrapClientCodec<N>
The user-supplied
Encoder used to write outbound messages to the target stream.Source§type Message = MessageOrEvent<N>
type Message = MessageOrEvent<N>
The type of the outbound messages; unless their serialization is expensive and the message
is broadcasted (in which case it would get serialized multiple times), serialization should
be done in the implementation of
Self::Codec.Source§fn message_queue_depth(&self) -> usize
fn message_queue_depth(&self) -> usize
The depth of per-connection queues used to send outbound messages; the greater it is, the more outbound
messages the node can enqueue. Setting it to a large value is not recommended, as doing it might
obscure potential issues with your implementation (like slow serialization) or network. Read more
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,
Prepares the node to send messages.
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>
Sends the provided message to the specified
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 moreAuto Trait Implementations§
impl<N> Freeze for BootstrapClient<N>
impl<N> !RefUnwindSafe for BootstrapClient<N>
impl<N> Send for BootstrapClient<N>
impl<N> Sync for BootstrapClient<N>
impl<N> Unpin for BootstrapClient<N>
impl<N> !UnwindSafe for BootstrapClient<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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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