pub struct Overlay { /* private fields */ }
Expand description
P2P messages distribution layer
Implementations§
Source§impl Overlay
impl Overlay
Sourcepub fn options(&self) -> &OverlayOptions
pub fn options(&self) -> &OverlayOptions
Configuration
Sourcepub fn metrics(&self) -> OverlayMetrics
pub fn metrics(&self) -> OverlayMetrics
Instant metrics
Sourcepub fn overlay_key(&self) -> &Arc<Key>
pub fn overlay_key(&self) -> &Arc<Key>
Returns local ADNL key for public overlay
Sourcepub fn add_public_peer(
&self,
adnl: &Node,
addr: SocketAddrV4,
node: Node<'_>,
) -> Result<Option<NodeIdShort>>
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.
Sourcepub fn add_public_peers<'a, I>(
&self,
adnl: &Node,
nodes: I,
) -> Result<Vec<NodeIdShort>>
pub fn add_public_peers<'a, I>( &self, adnl: &Node, nodes: I, ) -> Result<Vec<NodeIdShort>>
Verifies and adds new peers to the overlay. Returns a list of successfully added peers.
See Overlay::add_public_peer
for single peer.
Sourcepub fn remove_public_peer(&self, peer_id: &NodeIdShort) -> bool
pub fn remove_public_peer(&self, peer_id: &NodeIdShort) -> bool
Removes peer from random peers and adds it to ignored peers
Sourcepub fn is_known_peer(&self, peer_id: &NodeIdShort) -> bool
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
Sourcepub fn is_active_public_peer(&self, peer_id: &NodeIdShort) -> bool
pub fn is_active_public_peer(&self, peer_id: &NodeIdShort) -> bool
Checks whether the specified peer is in the current public overlay
Sourcepub fn write_cached_peers(&self, amount: u32, dst: &PeersSet)
pub fn write_cached_peers(&self, amount: u32, dst: &PeersSet)
Fill dst
with amount
peers from known peers
Sourcepub fn query_prefix(&self) -> &[u8] ⓘ
pub fn query_prefix(&self) -> &[u8] ⓘ
Serialized proto::rpc::OverlayQuery
with own overlay id
Sourcepub fn message_prefix(&self) -> &[u8] ⓘ
pub fn message_prefix(&self) -> &[u8] ⓘ
Serialized proto::overlay::Message
with own overlay id
Sourcepub fn send_message(
&self,
adnl: &Node,
peer_id: &NodeIdShort,
data: &[u8],
) -> Result<()>
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
Sourcepub async fn adnl_query<Q>(
&self,
adnl: &Node,
peer_id: &NodeIdShort,
query: Q,
timeout: Option<u64>,
) -> Result<Option<Vec<u8>>>where
Q: TlWrite,
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
Sourcepub async fn rldp_query<Q>(
&self,
rldp: &Node,
peer_id: &NodeIdShort,
query: Q,
roundtrip: Option<u64>,
) -> Result<(Option<Vec<u8>>, u64)>where
Q: TlWrite,
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
Sourcepub fn broadcast(
self: &Arc<Self>,
adnl: &Arc<Node>,
data: Vec<u8>,
source: Option<&Arc<Key>>,
target: BroadcastTarget,
) -> OutgoingBroadcastInfo
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
Sourcepub async fn wait_for_broadcast(&self) -> IncomingBroadcastInfo
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.
Sourcepub fn take_new_peers(&self) -> ReceivedPeersMap
pub fn take_new_peers(&self) -> ReceivedPeersMap
Take received peers map
Sourcepub fn sign_local_node(&self) -> NodeOwned
pub fn sign_local_node(&self) -> NodeOwned
Returns raw signed overlay node
Sourcepub async fn exchange_random_peers(
&self,
adnl: &Node,
peer_id: &NodeIdShort,
timeout: Option<u64>,
) -> Result<Option<Vec<NodeIdShort>>>
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.
Sourcepub async fn exchange_random_peers_ext(
&self,
adnl: &Node,
peer_id: &NodeIdShort,
timeout: Option<u64>,
existing_peers: &dyn ExistingPeersFilter,
) -> Result<Option<Vec<NodeIdShort>>>
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.