pub mod codec;
mod discv4_handlers;
mod discv5_handlers;
pub mod lookup;
pub mod server;
pub use server::{DiscoveryServer, DiscoveryServerError, is_discv4_packet};
use std::time::Duration;
#[derive(Debug, Clone)]
pub struct DiscoveryConfig {
pub discv4_enabled: bool,
pub discv5_enabled: bool,
pub initial_lookup_interval: f64,
}
impl Default for DiscoveryConfig {
fn default() -> Self {
Self {
discv4_enabled: true,
discv5_enabled: true,
initial_lookup_interval: INITIAL_LOOKUP_INTERVAL_MS,
}
}
}
pub const INITIAL_LOOKUP_INTERVAL_MS: f64 = 100.0; pub const LOOKUP_INTERVAL_MS: f64 = 600.0;
pub fn lookup_interval_function(progress: f64, lower_limit: f64, upper_limit: f64) -> Duration {
let ease_in_out_cubic = if progress < 0.5 {
4.0 * progress.powf(3.0)
} else {
1.0 - ((-2.0 * progress + 2.0).powf(3.0)) / 2.0
};
Duration::from_micros(
(1000f64 * (ease_in_out_cubic * (upper_limit - lower_limit) + lower_limit)).round() as u64,
)
}