use std::time::Duration;
use bytesize::ByteSize;
use serde::{Deserialize, Serialize};
use tycho_util::serde_helpers;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default)]
pub struct DhtConfig {
pub max_k: usize,
#[serde(with = "serde_helpers::humantime")]
pub max_peer_info_ttl: Duration,
#[serde(with = "serde_helpers::humantime")]
pub max_stored_value_ttl: Duration,
pub max_storage_capacity: ByteSize,
#[serde(with = "serde_helpers::humantime")]
pub storage_item_time_to_idle: Option<Duration>,
#[serde(with = "serde_helpers::humantime")]
pub local_info_refresh_period: Duration,
#[serde(with = "serde_helpers::humantime")]
pub local_info_announce_period: Duration,
#[serde(with = "serde_helpers::humantime")]
pub local_info_announce_period_max_jitter: Duration,
#[serde(with = "serde_helpers::humantime")]
pub routing_table_refresh_period: Duration,
#[serde(with = "serde_helpers::humantime")]
pub routing_table_refresh_period_max_jitter: Duration,
pub announced_peers_channel_capacity: usize,
#[serde(with = "serde_helpers::humantime")]
pub bootstrap_peers_refill_period: Option<Duration>,
#[serde(with = "serde_helpers::humantime")]
pub request_timeout: Duration,
}
impl Default for DhtConfig {
fn default() -> Self {
Self {
max_k: 6,
max_peer_info_ttl: Duration::from_secs(3600),
max_stored_value_ttl: Duration::from_secs(3600),
max_storage_capacity: ByteSize::mib(16),
storage_item_time_to_idle: None,
local_info_refresh_period: Duration::from_secs(60),
local_info_announce_period: Duration::from_secs(600),
local_info_announce_period_max_jitter: Duration::from_secs(60),
routing_table_refresh_period: Duration::from_secs(600),
routing_table_refresh_period_max_jitter: Duration::from_secs(60),
announced_peers_channel_capacity: 10,
bootstrap_peers_refill_period: Some(Duration::from_secs(60)),
request_timeout: Duration::from_millis(500),
}
}
}