Struct snarkos_node_bft::Gateway
source · pub struct Gateway<N: Network> { /* private fields */ }Implementations§
source§impl<N: Network> Gateway<N>
impl<N: Network> Gateway<N>
sourcepub fn new(
account: Account<N>,
ledger: Arc<dyn LedgerService<N>>,
ip: Option<SocketAddr>,
trusted_validators: &[SocketAddr],
dev: Option<u16>
) -> Result<Self>
pub fn new( account: Account<N>, ledger: Arc<dyn LedgerService<N>>, ip: Option<SocketAddr>, trusted_validators: &[SocketAddr], dev: Option<u16> ) -> Result<Self>
Initializes a new gateway.
sourcepub async fn run(
&self,
primary_sender: PrimarySender<N>,
worker_senders: IndexMap<u8, WorkerSender<N>>,
sync_sender: Option<SyncSender<N>>
)
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>
impl<N: Network> Gateway<N>
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 primary_sender(&self) -> &PrimarySender<N>
pub fn primary_sender(&self) -> &PrimarySender<N>
Returns the primary sender.
sourcepub fn num_workers(&self) -> u8
pub fn num_workers(&self) -> u8
Returns the number of workers.
sourcepub fn get_worker_sender(&self, worker_id: u8) -> Option<&WorkerSender<N>>
pub fn get_worker_sender(&self, worker_id: u8) -> Option<&WorkerSender<N>>
Returns the worker sender for the given worker ID.
sourcepub fn is_connected_address(&self, address: Address<N>) -> bool
pub fn is_connected_address(&self, address: Address<N>) -> bool
Returns true if the node is connected to the given Aleo address.
sourcepub fn is_connected_ip(&self, ip: SocketAddr) -> bool
pub fn is_connected_ip(&self, ip: SocketAddr) -> bool
Returns true if the node is connected to the given peer IP.
sourcepub fn is_connecting_ip(&self, ip: SocketAddr) -> bool
pub fn is_connecting_ip(&self, ip: SocketAddr) -> bool
Returns true if the node is connecting to the given peer IP.
Returns true if the given peer IP is an authorized validator.
Returns true if the given address is an authorized validator.
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 connected_addresses(&self) -> HashSet<Address<N>>
pub fn connected_addresses(&self) -> HashSet<Address<N>>
Returns the list of connected addresses.
sourcepub fn connected_peers(&self) -> &RwLock<IndexSet<SocketAddr>>
pub fn connected_peers(&self) -> &RwLock<IndexSet<SocketAddr>>
Returns the list of connected peers.
sourcepub fn connect(&self, peer_ip: SocketAddr) -> Option<JoinHandle<()>>
pub fn connect(&self, peer_ip: SocketAddr) -> Option<JoinHandle<()>>
Attempts to connect to the given peer IP.
sourcepub fn disconnect(&self, peer_ip: SocketAddr) -> JoinHandle<()>
pub fn disconnect(&self, peer_ip: SocketAddr) -> JoinHandle<()>
Disconnects from the given peer IP, if the peer is connected.
Trait Implementations§
source§impl<N: Network> CommunicationService for Gateway<N>
impl<N: Network> CommunicationService for Gateway<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> Disconnect for Gateway<N>
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,
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,
Disconnect::handle_disconnect to every occurrence of the
node disconnecting from a peer.source§impl<N: Network> Handshake for Gateway<N>
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,
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
const TIMEOUT_MS: u64 = 3_000u64
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,
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
Handshake::perform_handshake.source§fn take_stream(&self, conn: &mut Connection) -> TcpStream
fn take_stream(&self, conn: &mut Connection) -> TcpStream
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,
fn return_stream<T>(&self, conn: &mut Connection, stream: T)where T: AsyncRead + AsyncWrite + Send + Sync + 'static,
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>
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,
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,
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,
OnConnect::on_connect right after every successful
handshake.source§impl<N: Network> Reading for Gateway<N>
impl<N: Network> Reading for Gateway<N>
source§const MESSAGE_QUEUE_DEPTH: usize = 5_000_000usize
const MESSAGE_QUEUE_DEPTH: usize = 5_000_000usize
The maximum queue depth of incoming messages for a single peer.
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.
§type Codec = EventCodec<N>
type Codec = EventCodec<N>
Decoder used to interpret inbound messages.source§const INITIAL_BUFFER_SIZE: usize = 1_048_576usize
const INITIAL_BUFFER_SIZE: usize = 1_048_576usize
source§impl<N: Network> Transport<N> for Gateway<N>
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,
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§impl<N: Network> Writing for Gateway<N>
impl<N: Network> Writing for Gateway<N>
source§const MESSAGE_QUEUE_DEPTH: usize = 5_000_000usize
const MESSAGE_QUEUE_DEPTH: usize = 5_000_000usize
The maximum queue depth of outgoing messages for a single peer.
source§fn codec(&self, _peer_addr: SocketAddr, _side: ConnectionSide) -> Self::Codec
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.
§type Codec = EventCodec<N>
type Codec = EventCodec<N>
Encoder used to write outbound messages to the target stream.§type Message = Event<N>
type Message = Event<N>
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,
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 more