ethrex_p2p/discovery/
mod.rs1pub mod codec;
14mod discv4_handlers;
15mod discv5_handlers;
16pub mod lookup;
17pub mod server;
18
19pub use server::{DiscoveryServer, DiscoveryServerError, is_discv4_packet};
20
21use std::time::Duration;
22
23#[derive(Debug, Clone)]
25pub struct DiscoveryConfig {
26 pub discv4_enabled: bool,
27 pub discv5_enabled: bool,
28 pub initial_lookup_interval: f64,
29}
30
31impl Default for DiscoveryConfig {
32 fn default() -> Self {
33 Self {
34 discv4_enabled: true,
35 discv5_enabled: true,
36 initial_lookup_interval: INITIAL_LOOKUP_INTERVAL_MS,
37 }
38 }
39}
40
41pub 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 {
49 let ease_in_out_cubic = if progress < 0.5 {
52 4.0 * progress.powf(3.0)
53 } else {
54 1.0 - ((-2.0 * progress + 2.0).powf(3.0)) / 2.0
55 };
56 Duration::from_micros(
57 (1000f64 * (ease_in_out_cubic * (upper_limit - lower_limit) + lower_limit)).round() as u64,
58 )
59}