tycho_network/dht/
config.rs

1use std::time::Duration;
2
3use bytesize::ByteSize;
4use serde::{Deserialize, Serialize};
5use tycho_util::serde_helpers;
6
7// TODO: add max storage item size
8#[derive(Debug, Clone, Serialize, Deserialize)]
9#[serde(default)]
10pub struct DhtConfig {
11    /// DHT K parameter.
12    ///
13    /// Default: 6.
14    pub max_k: usize,
15
16    /// Maximum time to live for peer info.
17    ///
18    /// Default: 1 hour.
19    #[serde(with = "serde_helpers::humantime")]
20    pub max_peer_info_ttl: Duration,
21
22    /// Maximum time to live for stored values.
23    ///
24    /// Default: 1 hour.
25    #[serde(with = "serde_helpers::humantime")]
26    pub max_stored_value_ttl: Duration,
27
28    /// Maximum storage capacity (number of entries).
29    ///
30    /// Default: 16 MiB.
31    pub max_storage_capacity: ByteSize,
32
33    /// Time until a stored item is considered idle and can be removed.
34    ///
35    /// Default: unlimited.
36    #[serde(with = "serde_helpers::humantime")]
37    pub storage_item_time_to_idle: Option<Duration>,
38
39    /// A period of refreshing the local peer info.
40    ///
41    /// Default: 1 minute.
42    #[serde(with = "serde_helpers::humantime")]
43    pub local_info_refresh_period: Duration,
44
45    /// A period of storing the local peer info into the DHT.
46    ///
47    /// Default: 10 minutes.
48    #[serde(with = "serde_helpers::humantime")]
49    pub local_info_announce_period: Duration,
50
51    /// A maximum value of a random jitter for the peer announce period.
52    ///
53    /// Default: 1 minute.
54    #[serde(with = "serde_helpers::humantime")]
55    pub local_info_announce_period_max_jitter: Duration,
56
57    /// A period of updating and populating the routing table.
58    ///
59    /// Default: 10 minutes.
60    #[serde(with = "serde_helpers::humantime")]
61    pub routing_table_refresh_period: Duration,
62
63    /// A maximum value of a random jitter for the routing table refresh period.
64    ///
65    /// Default: 1 minutes.
66    #[serde(with = "serde_helpers::humantime")]
67    pub routing_table_refresh_period_max_jitter: Duration,
68
69    /// The capacity of the announced peers channel.
70    ///
71    /// Default: 10.
72    pub announced_peers_channel_capacity: usize,
73}
74
75impl Default for DhtConfig {
76    fn default() -> Self {
77        Self {
78            max_k: 6,
79            max_peer_info_ttl: Duration::from_secs(3600),
80            max_stored_value_ttl: Duration::from_secs(3600),
81            max_storage_capacity: ByteSize::mib(16),
82            storage_item_time_to_idle: None,
83            local_info_refresh_period: Duration::from_secs(60),
84            local_info_announce_period: Duration::from_secs(600),
85            local_info_announce_period_max_jitter: Duration::from_secs(60),
86            routing_table_refresh_period: Duration::from_secs(600),
87            routing_table_refresh_period_max_jitter: Duration::from_secs(60),
88            announced_peers_channel_capacity: 10,
89        }
90    }
91}