snarkos_node_bft

Struct Gateway

Source
pub struct Gateway<N: Network> { /* private fields */ }

Implementations§

Source§

impl<N: Network> Gateway<N>

Source

pub fn new( account: Account<N>, storage: Storage<N>, ledger: Arc<dyn LedgerService<N>>, ip: Option<SocketAddr>, trusted_validators: &[SocketAddr], dev: Option<u16>, ) -> Result<Self>

Initializes a new gateway.

Source

pub async fn run( &self, primary_sender: PrimarySender<N>, worker_senders: IndexMap<u8, WorkerSender<N>>, sync_sender: Option<SyncSender<N>>, )

Run the gateway.

Source§

impl<N: Network> Gateway<N>

Source

pub const fn account(&self) -> &Account<N>

Returns the account of the node.

Source

pub const fn dev(&self) -> Option<u16>

Returns the dev identifier of the node.

Source

pub fn local_ip(&self) -> SocketAddr

Returns the IP address of this node.

Source

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

Returns true if the given IP is this node.

Source

pub 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

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

Returns the resolver.

Source

pub fn primary_sender(&self) -> &PrimarySender<N>

Returns the primary sender.

Source

pub fn num_workers(&self) -> u8

Returns the number of workers.

Source

pub fn get_worker_sender(&self, worker_id: u8) -> Option<&WorkerSender<N>>

Returns the worker sender for the given worker ID.

Source

pub fn is_connected_address(&self, address: Address<N>) -> bool

Returns true if the node is connected to the given Aleo address.

Source

pub fn is_connected_ip(&self, ip: SocketAddr) -> bool

Returns true if the node is connected to the given peer IP.

Source

pub fn is_connecting_ip(&self, ip: SocketAddr) -> bool

Returns true if the node is connecting to the given peer IP.

Source

pub fn is_authorized_validator_ip(&self, ip: SocketAddr) -> bool

Returns true if the given peer IP is an authorized validator.

Source

pub fn is_authorized_validator_address( &self, validator_address: Address<N>, ) -> bool

Returns true if the given address is an authorized validator.

Source

pub fn max_connected_peers(&self) -> usize

Returns the maximum number of connected peers.

Source

pub fn number_of_connected_peers(&self) -> usize

Returns the number of connected peers.

Source

pub fn connected_addresses(&self) -> HashSet<Address<N>>

Returns the list of connected addresses.

Source

pub fn connected_peers(&self) -> &RwLock<IndexSet<SocketAddr>>

Returns the list of connected peers.

Source

pub fn connect(&self, peer_ip: SocketAddr) -> Option<JoinHandle<()>>

Attempts to connect to the given peer IP.

Source

pub fn disconnect(&self, peer_ip: SocketAddr) -> JoinHandle<()>

Disconnects from the given peer IP, if the peer is connected.

Source

pub async fn shut_down(&self)

Shuts down the gateway.

Trait Implementations§

Source§

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

Source§

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

Returns a copy 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> CommunicationService for Gateway<N>

Source§

type Message = Event<N>

The message type.

Source§

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,

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> Disconnect for Gateway<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 Gateway<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 protocol.

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 Gateway<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 Gateway<N>

Source§

fn tcp(&self) -> &Tcp

Returns a reference to the TCP instance.

Source§

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

Source§

const MESSAGE_QUEUE_DEPTH: usize

The maximum queue depth of incoming messages for a single peer.

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 = EventCodec<N>

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

type Message = Event<N>

The final (deserialized) type of inbound messages.
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> Transport<N> for Gateway<N>

Source§

fn send<'life0, 'async_trait>( &'life0 self, peer_ip: SocketAddr, event: Event<N>, ) -> Pin<Box<dyn Future<Output = Option<Receiver<Result<()>>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Sends the given event to specified peer.

This method is rate limited to prevent spamming the peer.

This function returns as soon as the event 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 event has been delivered.

Source§

fn broadcast(&self, event: Event<N>)

Broadcasts the given event to all connected peers.

Source§

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

Source§

const MESSAGE_QUEUE_DEPTH: usize

The maximum queue depth of outgoing messages for a single peer.

Source§

fn codec(&self, _peer_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 = EventCodec<N>

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

type Message = Event<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 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
Source§

fn broadcast(&self, message: Self::Message) -> Result<(), Error>
where Self::Message: Clone,

Broadcasts the provided message to all connected peers. Returns as soon as the message is queued to be sent to all the peers, without waiting for the actual delivery. This method doesn’t provide the means to check when and if the messages actually get delivered; you can achieve that by calling Writing::unicast for each address returned by [Tcp::connected_addrs]. Read more

Auto Trait Implementations§

§

impl<N> Freeze for Gateway<N>

§

impl<N> !RefUnwindSafe for Gateway<N>

§

impl<N> Send for Gateway<N>

§

impl<N> Sync for Gateway<N>

§

impl<N> Unpin for Gateway<N>

§

impl<N> !UnwindSafe for Gateway<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, dst: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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