Struct Node

Source
pub struct Node { /* private fields */ }
Expand description

Unreliable UDP transport layer

Implementations§

Source§

impl Node

Source

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

Source

pub fn options(&self) -> &NodeOptions

ADNL node options

Source

pub fn metrics(&self) -> NodeMetrics

Instant metrics

Source

pub fn add_message_subscriber( &self, message_subscriber: Arc<dyn MessageSubscriber>, ) -> Result<()>

Adds a new message subscriber brefore the node was started

Source

pub fn add_query_subscriber( &self, query_subscriber: Arc<dyn QuerySubscriber>, ) -> Result<()>

Adds a new query subscriber brefore the node was started

Source

pub fn start(self: &Arc<Self>) -> Result<()>

Starts listening for incoming packets

Source

pub fn shutdown(&self)

Stops all spawned listeners

Source

pub fn compute_query_timeout(&self, roundtrip: Option<u64>) -> u64

Computes ADNL query timeout, based on the roundtrip and the configured options

Source

pub fn socket_addr(&self) -> SocketAddrV4

Socket address of the node

Source

pub fn start_time(&self) -> u32

Node start timestamp

Source

pub fn build_address_list(&self) -> AddressList

Builds a new address list for the current ADNL node with no expiration date

Source

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

Source

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

Source

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

See Node::remove_peer

Source

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

Source

pub fn get_peer_address( &self, local_id: &NodeIdShort, peer_id: &NodeIdShort, ) -> Option<SocketAddrV4>

Searches for remote peer socket address in the known peers

Source

pub fn match_peer_addresses<T>( &self, local_id: &NodeIdShort, entries: HashMap<SocketAddrV4, T, RandomState>, ) -> Option<HashMap<T, NodeIdShort, RandomState>>
where T: Hash + Eq,

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.

Source

pub async fn query<Q, A>( &self, local_id: &NodeIdShort, peer_id: &NodeIdShort, query: Q, timeout: Option<u64>, ) -> Result<Option<A>>
where Q: TlWrite, for<'a> A: TlRead<'a, Repr = Boxed> + 'static,

ADNL query without prefix to the remote peer.

NOTE: In case of timeout returns Ok(None)

Source

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>>
where Q: TlWrite, for<'a> A: TlRead<'a, Repr = Boxed> + 'static,

ADNL query with prefix to the remote peer

NOTE: In case of timeout returns Ok(None)

Source

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)

Source

pub fn send_custom_message( &self, local_id: &NodeIdShort, peer_id: &NodeIdShort, data: &[u8], ) -> Result<()>

Sends a one-way ADNL message

Trait Implementations§

Source§

impl Drop for Node

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl !Freeze for Node

§

impl !RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl !UnwindSafe for Node

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<Choices> CoproductSubsetter<CNil, HNil> for Choices

Source§

type Remainder = Choices

Source§

fn subset( self, ) -> Result<CNil, <Choices as CoproductSubsetter<CNil, HNil>>::Remainder>

Extract a subset of the possible types in a coproduct (or get the remaining possibilities) 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, U, I> LiftInto<U, I> for T
where U: LiftFrom<T, I>,

Source§

fn lift_into(self) -> U

Performs the indexed conversion.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<Source> Sculptor<HNil, HNil> for Source

Source§

type Remainder = Source

Source§

fn sculpt(self) -> (HNil, <Source as Sculptor<HNil, HNil>>::Remainder)

Consumes the current HList and returns an HList with the requested shape. 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