BootstrapClient

Struct BootstrapClient 

Source
pub struct BootstrapClient<N: Network>(/* private fields */);

Implementations§

Source§

impl<N: Network> BootstrapClient<N>

Source

pub async fn new( listener_addr: SocketAddr, account: Account<N>, genesis_header: Header<N>, dev: Option<u16>, ) -> Result<Self>

Source

pub fn address(&self) -> Address<N>

Returns the account address of the node.

Source

pub fn private_key(&self) -> &PrivateKey<N>

Returns the account private key of the node.

Source

pub fn view_key(&self) -> &ViewKey<N>

Returns the account view key of the node.

Source

pub fn resolve_to_listener( &self, connected_addr: SocketAddr, ) -> Option<SocketAddr>

Returns the listener IP address from the connected peer address.

Source

pub fn is_dev(&self) -> bool

Returns true if the node is in development mode.

Source

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.

Source

pub fn get_known_validators(&self) -> HashMap<SocketAddr, Address<N>>

Returns the list of known validators connected in Gateway mode.

Source

pub async fn shut_down(&self)

Shuts down the bootstrap client.

Trait Implementations§

Source§

impl<N: Clone + Network> Clone for BootstrapClient<N>

Source§

fn clone(&self) -> BootstrapClient<N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<N: Network> Deref for BootstrapClient<N>

Source§

type Target = Arc<InnerBootstrapClient<N>>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

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,

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,

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>

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,

Performs the handshake; temporarily assumes control of the Connection and returns it if the handshake is successful.
Source§

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,

Prepares the node to perform specified network handshakes.
Source§

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

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)
where T: AsyncRead + AsyncWrite + Send + Sync + 'static,

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>

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,

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,

Attaches the behavior specified in OnConnect::on_connect right after every successful handshake.
Source§

impl<N: Network> P2P for BootstrapClient<N>

Source§

fn tcp(&self) -> &Tcp

Returns a reference to the TCP instance.
Source§

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

Source§

const MAXIMUM_POOL_SIZE: usize = 10_000usize

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

const OWNER: &'static str = "[Network]"

Source§

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

fn is_dev(&self) -> bool

Returns true if the owning node is in development mode.
Source§

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

Source§

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

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, 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>>

Attempts to connect to the given peer’s listener address. Read more
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>( &self, listener_addr: &SocketAddr, update_fn: F, ) -> bool
where 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>>

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>(&self, predicate: P) -> Vec<ConnectedPeer<N>>
where P: FnMut(&ConnectedPeer<N>) -> bool,

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>, 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>

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

impl<N: Network> Reading for BootstrapClient<N>

Source§

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,

Processes a message received from the network.

Source§

type Codec = BootstrapClientCodec<N>

The user-supplied Decoder used to interpret inbound messages.
Source§

type Message = <BootstrapClientCodec<N> as Decoder>::Item

The final (deserialized) type of inbound messages.
Source§

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

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§

fn enable_reading<'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 receive messages.
Source§

impl<N: Network> Writing for BootstrapClient<N>

Source§

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>

The user-supplied Encoder used to write outbound messages to the target stream.
Source§

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

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,

Prepares the node to send messages.
Source§

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 more

Auto 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,