pub struct Node { /* private fields */ }
Expand description
Unreliable UDP transport layer
Implementations§
Source§impl Node
impl Node
Sourcepub fn new(
socket_addr: SocketAddrV4,
keystore: Keystore,
options: NodeOptions,
peer_filter: Option<Arc<dyn PeerFilter>>,
) -> Result<Arc<Self>>
pub fn new( socket_addr: SocketAddrV4, keystore: Keystore, options: NodeOptions, peer_filter: Option<Arc<dyn PeerFilter>>, ) -> Result<Arc<Self>>
Create new ADNL node on the specified address
Sourcepub fn options(&self) -> &NodeOptions
pub fn options(&self) -> &NodeOptions
ADNL node options
Sourcepub fn metrics(&self) -> NodeMetrics
pub fn metrics(&self) -> NodeMetrics
Instant metrics
Sourcepub fn add_message_subscriber(
&self,
message_subscriber: Arc<dyn MessageSubscriber>,
) -> Result<()>
pub fn add_message_subscriber( &self, message_subscriber: Arc<dyn MessageSubscriber>, ) -> Result<()>
Adds a new message subscriber brefore the node was started
Sourcepub fn add_query_subscriber(
&self,
query_subscriber: Arc<dyn QuerySubscriber>,
) -> Result<()>
pub fn add_query_subscriber( &self, query_subscriber: Arc<dyn QuerySubscriber>, ) -> Result<()>
Adds a new query subscriber brefore the node was started
Sourcepub fn compute_query_timeout(&self, roundtrip: Option<u64>) -> u64
pub fn compute_query_timeout(&self, roundtrip: Option<u64>) -> u64
Computes ADNL query timeout, based on the roundtrip and the configured options
Sourcepub fn socket_addr(&self) -> SocketAddrV4
pub fn socket_addr(&self) -> SocketAddrV4
Socket address of the node
Sourcepub fn start_time(&self) -> u32
pub fn start_time(&self) -> u32
Node start timestamp
Sourcepub fn build_address_list(&self) -> AddressList
pub fn build_address_list(&self) -> AddressList
Builds a new address list for the current ADNL node with no expiration date
Sourcepub fn key_by_id(&self, id: &NodeIdShort) -> Result<&Arc<Key>, KeystoreError>
pub fn key_by_id(&self, id: &NodeIdShort) -> Result<&Arc<Key>, KeystoreError>
Searches for the stored ADNL key by it’s short id
See Node::key_by_tag
Sourcepub fn key_by_tag(&self, tag: usize) -> Result<&Arc<Key>, KeystoreError>
pub fn key_by_tag(&self, tag: usize) -> Result<&Arc<Key>, KeystoreError>
Searches for the stored ADNL key by it’s tag
See Node::key_by_id
Sourcepub fn add_peer(
&self,
ctx: NewPeerContext,
local_id: &NodeIdShort,
peer_id: &NodeIdShort,
addr: SocketAddrV4,
peer_id_full: NodeIdFull,
) -> Result<bool>
pub fn add_peer( &self, ctx: NewPeerContext, local_id: &NodeIdShort, peer_id: &NodeIdShort, addr: SocketAddrV4, peer_id_full: NodeIdFull, ) -> Result<bool>
Adds new remote peer. Returns whether the peer was added
Sourcepub fn remove_peer(
&self,
local_id: &NodeIdShort,
peer_id: &NodeIdShort,
) -> Result<bool>
pub fn remove_peer( &self, local_id: &NodeIdShort, peer_id: &NodeIdShort, ) -> Result<bool>
Removes remote peer.
NOTE: This method will return an error if there is no peers table for the specified local id.
See Node::add_peer
Sourcepub fn get_peer_address(
&self,
local_id: &NodeIdShort,
peer_id: &NodeIdShort,
) -> Option<SocketAddrV4>
pub fn get_peer_address( &self, local_id: &NodeIdShort, peer_id: &NodeIdShort, ) -> Option<SocketAddrV4>
Searches for remote peer socket address in the known peers
Sourcepub fn match_peer_addresses<T>(
&self,
local_id: &NodeIdShort,
entries: HashMap<SocketAddrV4, T, RandomState>,
) -> Option<HashMap<T, NodeIdShort, RandomState>>
pub fn match_peer_addresses<T>( &self, local_id: &NodeIdShort, entries: HashMap<SocketAddrV4, T, RandomState>, ) -> Option<HashMap<T, NodeIdShort, RandomState>>
Matches entries with peer id by socket address
NOTE: It is a quite expensive method that iterates over all peers and may block new peers from being added during the execution time. Use it with caution.
Sourcepub async fn query<Q, A>(
&self,
local_id: &NodeIdShort,
peer_id: &NodeIdShort,
query: Q,
timeout: Option<u64>,
) -> Result<Option<A>>
pub async fn query<Q, A>( &self, local_id: &NodeIdShort, peer_id: &NodeIdShort, query: Q, timeout: Option<u64>, ) -> Result<Option<A>>
ADNL query without prefix to the remote peer.
NOTE: In case of timeout returns Ok(None)
Sourcepub async fn query_with_prefix<Q, A>(
&self,
local_id: &NodeIdShort,
peer_id: &NodeIdShort,
prefix: &[u8],
query: Q,
timeout: Option<u64>,
) -> Result<Option<A>>
pub async fn query_with_prefix<Q, A>( &self, local_id: &NodeIdShort, peer_id: &NodeIdShort, prefix: &[u8], query: Q, timeout: Option<u64>, ) -> Result<Option<A>>
ADNL query with prefix to the remote peer
NOTE: In case of timeout returns Ok(None)
Sourcepub async fn query_raw(
&self,
local_id: &NodeIdShort,
peer_id: &NodeIdShort,
query: Bytes,
timeout: Option<u64>,
) -> Result<Option<Vec<u8>>>
pub async fn query_raw( &self, local_id: &NodeIdShort, peer_id: &NodeIdShort, query: Bytes, timeout: Option<u64>, ) -> Result<Option<Vec<u8>>>
ADNL query to the remote peer
NOTE: In case of timeout returns Ok(None)
Sourcepub fn send_custom_message(
&self,
local_id: &NodeIdShort,
peer_id: &NodeIdShort,
data: &[u8],
) -> Result<()>
pub fn send_custom_message( &self, local_id: &NodeIdShort, peer_id: &NodeIdShort, data: &[u8], ) -> Result<()>
Sends a one-way ADNL message