pub struct Gateway<N: Network>(/* private fields */);Expand description
The gateway maintains connections to other validators. For connections with clients and provers, the Router logic is used.
Implementations§
Source§impl<N: Network> Gateway<N>
impl<N: Network> Gateway<N>
Sourcepub fn new(
account: Account<N>,
storage: Storage<N>,
ledger: Arc<dyn LedgerService<N>>,
ip: Option<SocketAddr>,
trusted_validators: &[SocketAddr],
trusted_peers_only: bool,
node_data_dir: NodeDataDir,
dev: Option<u16>,
) -> Result<Self>
pub fn new( account: Account<N>, storage: Storage<N>, ledger: Arc<dyn LedgerService<N>>, ip: Option<SocketAddr>, trusted_validators: &[SocketAddr], trusted_peers_only: bool, node_data_dir: NodeDataDir, 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 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 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.
Returns true if the given peer IP is an authorized validator.
Returns true if the given address is an authorized validator.
Sourcepub fn connected_addresses(&self) -> HashSet<Address<N>>
pub fn connected_addresses(&self) -> HashSet<Address<N>>
Returns the list of connected addresses.
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_000
const TIMEOUT_MS: u64 = 3_000
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)
fn return_stream<T>(&self, conn: &mut Connection, stream: T)
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> PeerPoolHandling<N> for Gateway<N>
impl<N: Network> PeerPoolHandling<N> for Gateway<N>
Source§const MAXIMUM_POOL_SIZE: usize = 200
const MAXIMUM_POOL_SIZE: usize = 200
const OWNER: &str = CONTEXT
Source§const PEER_SLASHING_COUNT: usize = 20
const PEER_SLASHING_COUNT: usize = 20
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 trusted_peers_only(&self) -> bool
fn trusted_peers_only(&self) -> bool
true if the node is in trusted peers only mode.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, Error>
fn check_connection_attempt( &self, listener_addr: SocketAddr, ) -> Result<bool, Error>
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) -> bool
fn downgrade_peer_to_candidate(&self, listener_addr: SocketAddr) -> bool
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_connected_address(&self, aleo_address: Address<N>) -> bool
fn is_connected_address(&self, aleo_address: Address<N>) -> bool
true if the node is connected to the given Aleo 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>(
&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>),
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>(&self, predicate: P) -> Vec<ConnectedPeer<N>>
fn filter_connected_peers<P>(&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(path: &Path) -> Result<Vec<SocketAddr>, Error>
fn load_cached_peers(path: &Path) -> Result<Vec<SocketAddr>, Error>
Source§fn save_best_peers(
&self,
path: &Path,
max_entries: Option<usize>,
store_ports: bool,
) -> Result<(), Error>
fn save_best_peers( &self, path: &Path, max_entries: Option<usize>, store_ports: bool, ) -> Result<(), Error>
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> Reading for Gateway<N>
impl<N: Network> Reading for Gateway<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§fn message_queue_depth(&self) -> usize
fn message_queue_depth(&self) -> usize
Computes the depth of per-connection queues used to process inbound messages, sufficient to process the maximum expected load at any givent moment. The greater it is, the more inbound messages the node can enqueue, but a too large value can make the node more susceptible to DoS attacks.
Source§type Codec = EventCodec<N>
type Codec = EventCodec<N>
Decoder used to interpret inbound messages.Source§const INITIAL_BUFFER_SIZE: usize = _
const INITIAL_BUFFER_SIZE: usize = _
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§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.
Source§fn message_queue_depth(&self) -> usize
fn message_queue_depth(&self) -> usize
Computes the depth of per-connection queues used to send outbound messages, sufficient to process the maximum expected load at any givent moment. The greater it is, the more outbound messages the node can enqueue. A too large value large value might obscure potential issues with your implementation (like slow serialization) or network.
Source§type Codec = EventCodec<N>
type Codec = EventCodec<N>
Encoder used to write outbound messages to the target stream.Source§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 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 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> UnsafeUnpin for Gateway<N>
impl<N> !UnwindSafe for Gateway<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