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>,
storage: Storage<N>,
ledger: Arc<dyn LedgerService<N>>,
ip: Option<SocketAddr>,
trusted_validators: &[SocketAddr],
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], 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 is_valid_peer_ip(&self, ip: SocketAddr) -> bool
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.
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)
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> Reading for Gateway<N>
impl<N: Network> Reading for Gateway<N>
Source§const MESSAGE_QUEUE_DEPTH: usize
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
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 = 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
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
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>
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>where
<N as Environment>::Field: Freeze,
<N as Environment>::Scalar: Freeze,
<N as Environment>::Projective: Freeze,
impl<N> !RefUnwindSafe for Gateway<N>
impl<N> Send for Gateway<N>
impl<N> Sync for Gateway<N>
impl<N> Unpin for Gateway<N>where
<N as Environment>::Field: Unpin,
<N as Environment>::Scalar: Unpin,
<N as Environment>::Projective: Unpin,
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