Struct Overlay

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

P2P messages distribution layer

Implementations§

Source§

impl Overlay

Source

pub fn options(&self) -> &OverlayOptions

Configuration

Source

pub fn metrics(&self) -> OverlayMetrics

Instant metrics

Source

pub fn id(&self) -> &IdShort

Short overlay id

Source

pub fn overlay_key(&self) -> &Arc<Key>

Returns local ADNL key for public overlay

Source

pub fn add_public_peer( &self, adnl: &Node, addr: SocketAddrV4, node: Node<'_>, ) -> Result<Option<NodeIdShort>>

Verifies and adds new peer to the overlay. Returns Some short peer id if new peer was successfully added and None if peer already existed.

See Overlay::add_public_peers for multiple peers.

Source

pub fn add_public_peers<'a, I>( &self, adnl: &Node, nodes: I, ) -> Result<Vec<NodeIdShort>>
where I: IntoIterator<Item = (SocketAddrV4, Node<'a>)>,

Verifies and adds new peers to the overlay. Returns a list of successfully added peers.

See Overlay::add_public_peer for single peer.

Source

pub fn remove_public_peer(&self, peer_id: &NodeIdShort) -> bool

Removes peer from random peers and adds it to ignored peers

Source

pub fn is_known_peer(&self, peer_id: &NodeIdShort) -> bool

Checks whether the specified peer has ever been in this public overlay

NOTE: Peer might have been excluded. If you need to check whether the specified peer is still in this overlay use Overlay::is_active_public_peer

Source

pub fn is_active_public_peer(&self, peer_id: &NodeIdShort) -> bool

Checks whether the specified peer is in the current public overlay

Source

pub fn write_cached_peers(&self, amount: u32, dst: &PeersSet)

Fill dst with amount peers from known peers

Source

pub fn query_prefix(&self) -> &[u8]

Serialized proto::rpc::OverlayQuery with own overlay id

Source

pub fn message_prefix(&self) -> &[u8]

Serialized proto::overlay::Message with own overlay id

Source

pub fn send_message( &self, adnl: &Node, peer_id: &NodeIdShort, data: &[u8], ) -> Result<()>

Sends direct ADNL message (proto::adnl::Message::Custom) to the given peer.

NOTE: Local id (Overlay::overlay_key) will be used as sender

Source

pub async fn adnl_query<Q>( &self, adnl: &Node, peer_id: &NodeIdShort, query: Q, timeout: Option<u64>, ) -> Result<Option<Vec<u8>>>
where Q: TlWrite,

Sends ADNL query directly to the given peer. In case of timeout returns Ok(None)

NOTE: Local id (Overlay::overlay_key) will be used as sender

Source

pub async fn rldp_query<Q>( &self, rldp: &Node, peer_id: &NodeIdShort, query: Q, roundtrip: Option<u64>, ) -> Result<(Option<Vec<u8>>, u64)>
where Q: TlWrite,

Sends RLDP query directly to the given peer. In case of timeout returns Ok((None, max_timeout))

NOTE: Local id (Overlay::overlay_key) will be used as sender

Source

pub fn broadcast( self: &Arc<Self>, adnl: &Arc<Node>, data: Vec<u8>, source: Option<&Arc<Key>>, target: BroadcastTarget, ) -> OutgoingBroadcastInfo

Distributes provided message to the neighbours subset.

See broadcast_target_count in OverlayOptions

NOTE: If data len is greater than

Source

pub async fn wait_for_broadcast(&self) -> IncomingBroadcastInfo

Waits until the next received broadcast.

NOTE: It is important to keep polling this method because otherwise received broadcasts queue will consume all the memory.

Source

pub fn take_new_peers(&self) -> ReceivedPeersMap

Take received peers map

Source

pub fn sign_local_node(&self) -> NodeOwned

Returns raw signed overlay node

Source

pub async fn exchange_random_peers( &self, adnl: &Node, peer_id: &NodeIdShort, timeout: Option<u64>, ) -> Result<Option<Vec<NodeIdShort>>>

Exchanges random peers with the specified peer. Returns Ok(None) in case of timeout. Uses the default existing peers filter.

Source

pub async fn exchange_random_peers_ext( &self, adnl: &Node, peer_id: &NodeIdShort, timeout: Option<u64>, existing_peers: &dyn ExistingPeersFilter, ) -> Result<Option<Vec<NodeIdShort>>>

Exchanges random peers with the specified peer. Returns Ok(None) in case of timeout. Uses the specified existing peers filter.

Auto Trait Implementations§

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