pub struct Node { /* private fields */ }
Expand description
Kademlia-like DHT node
Implementations§
Source§impl Node
impl Node
Sourcepub fn new(
adnl: Arc<Node>,
key_tag: usize,
options: NodeOptions,
) -> Result<Arc<Self>>
pub fn new( adnl: Arc<Node>, key_tag: usize, options: NodeOptions, ) -> Result<Arc<Self>>
Create new DHT node on top of ADNL node
Sourcepub fn options(&self) -> &NodeOptions
pub fn options(&self) -> &NodeOptions
Configuration
Sourcepub fn metrics(&self) -> NodeMetrics
pub fn metrics(&self) -> NodeMetrics
Instant metrics
pub fn key(&self) -> &Arc<Key>
pub fn iter_known_peers(&self) -> impl Iterator<Item = &NodeIdShort>
Sourcepub fn add_dht_peer(&self, peer: NodeOwned) -> Result<Option<NodeIdShort>>
pub fn add_dht_peer(&self, peer: NodeOwned) -> Result<Option<NodeIdShort>>
Adds new peer to DHT or explicitly marks existing as good. Returns new peer short id
Sourcepub fn is_bad_peer(&self, peer: &NodeIdShort) -> bool
pub fn is_bad_peer(&self, peer: &NodeIdShort) -> bool
Checks whether the specified peer was marked as bad
Sourcepub async fn ping(&self, peer_id: &NodeIdShort) -> Result<bool>
pub async fn ping(&self, peer_id: &NodeIdShort) -> Result<bool>
Sends ping query to the given peer
Sourcepub fn entry<'a, T>(self: &'a Arc<Self>, id: &'a T, name: &'a str) -> Entry<'a>
pub fn entry<'a, T>(self: &'a Arc<Self>, id: &'a T, name: &'a str) -> Entry<'a>
Returns an entry interface for manipulating DHT values
Sourcepub async fn query_dht_nodes(
&self,
peer_id: &NodeIdShort,
k: u32,
store_self: bool,
) -> Result<Vec<NodeOwned>>
pub async fn query_dht_nodes( &self, peer_id: &NodeIdShort, k: u32, store_self: bool, ) -> Result<Vec<NodeOwned>>
Queries given peer for at most k
DHT nodes with
the same affinity as local_id <-> peer_id
Sourcepub async fn find_more_dht_nodes(&self) -> Result<usize>
pub async fn find_more_dht_nodes(&self) -> Result<usize>
Asks each known DHT node for other nodes, extending current nodes set
Sourcepub async fn find_overlay_nodes(
self: &Arc<Self>,
overlay_id: &IdShort,
) -> Result<Vec<(SocketAddrV4, NodeOwned)>>
pub async fn find_overlay_nodes( self: &Arc<Self>, overlay_id: &IdShort, ) -> Result<Vec<(SocketAddrV4, NodeOwned)>>
Searches overlay nodes and their ip addresses.
NOTE: For the sake of speed it uses only a subset of nodes, so results may vary between calls.
Sourcepub async fn find_address(
self: &Arc<Self>,
peer_id: &NodeIdShort,
) -> Result<(SocketAddrV4, NodeIdFull)>
pub async fn find_address( self: &Arc<Self>, peer_id: &NodeIdShort, ) -> Result<(SocketAddrV4, NodeIdFull)>
Searches for the first stored IP address for the given peer id
Sourcepub fn store_value(self: &Arc<Self>, value: Value<'_>) -> Result<StoreValue>
pub fn store_value(self: &Arc<Self>, value: Value<'_>) -> Result<StoreValue>
Returns a future which stores value into multiple DHT nodes.
See Node::entry
for more convenient API
Sourcepub async fn store_overlay_node(
self: &Arc<Self>,
overlay_id_full: &IdFull,
node: Node<'_>,
) -> Result<bool>
pub async fn store_overlay_node( self: &Arc<Self>, overlay_id_full: &IdFull, node: Node<'_>, ) -> Result<bool>
Stores given overlay node into multiple DHT nodes
Returns and error if stored value is incorrect
Sourcepub async fn store_address(
self: &Arc<Self>,
key: &Key,
addr: SocketAddrV4,
) -> Result<bool>
pub async fn store_address( self: &Arc<Self>, key: &Key, addr: SocketAddrV4, ) -> Result<bool>
Stores given socket address into multiple DHT nodes