everscale_network/dht/
mod.rs1use std::sync::Arc;
6
7use anyhow::Result;
8use frunk_core::hlist::{HCons, HList, IntoTuple2, Selector};
9use frunk_core::indices::There;
10
11pub use entry::Entry;
12pub use node::{Node, NodeMetrics, NodeOptions};
13
14use crate::adnl;
15use crate::util::{DeferredInitialization, NetworkBuilder};
16
17mod buckets;
18mod entry;
19mod node;
20mod peers_iter;
21mod storage;
22
23pub mod futures;
25pub mod streams;
27
28pub(crate) type Deferred = Result<(Arc<adnl::Node>, usize, NodeOptions)>;
29
30impl DeferredInitialization for Deferred {
31 type Initialized = Arc<Node>;
32
33 fn initialize(self) -> Result<Self::Initialized> {
34 let (adnl, key_tag, options) = self?;
35 Node::new(adnl, key_tag, options)
36 }
37}
38
39impl<L, A, R> NetworkBuilder<L, (A, R)>
40where
41 L: HList + Selector<adnl::Deferred, A>,
42 HCons<Deferred, L>: IntoTuple2,
43{
44 #[allow(clippy::type_complexity)]
71 pub fn with_dht(
72 self,
73 key_tag: usize,
74 options: NodeOptions,
75 ) -> NetworkBuilder<HCons<Deferred, L>, (There<A>, There<R>)> {
76 let deferred = match self.0.get() {
77 Ok(adnl) => Ok((adnl.clone(), key_tag, options)),
78 Err(_) => Err(anyhow::anyhow!("ADNL was not initialized")),
79 };
80 NetworkBuilder(self.0.prepend(deferred), Default::default())
81 }
82}
83
84pub const KEY_ADDRESS: &str = "address";
86
87pub const KEY_NODES: &str = "nodes";
89
90pub const MAX_DHT_PEERS: u32 = 65536;