From 5430e561f561ad2d767a63b47311b3cacaae2ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Sun, 12 Apr 2020 13:26:44 +0200 Subject: [PATCH] aquatic: Config: add fields for max handler request, channel timeout --- TODO.md | 4 +--- aquatic/src/lib/config.rs | 19 +++++++++++++++++++ aquatic/src/lib/handlers.rs | 6 ++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/TODO.md b/TODO.md index ff18748..c48ac22 100644 --- a/TODO.md +++ b/TODO.md @@ -1,12 +1,10 @@ # TODO ## aquatic -* thread 'main' panicked at 'overflow when subtracting duration from instant', src/libstd/time.rs:374:9 +* `thread 'main' panicked at 'overflow when subtracting duration from instant', src/libstd/time.rs:374:9` * Put connections and torrent in a struct behind a commong lock. Add functionality for checking if mutex is unlocked before quitting to collect requests from channel (try_recv) up to a limit. -* Add config variable like "handler_max_requests" (default 1024?) -* Shorter timeout on handler channel collector (1ms?) * Handle Ipv4 and Ipv6 peers. Probably split state. Ipv4 peers can't make use of Ipv6 ones. Ipv6 ones may or may note be able to make use of Ipv4 ones, have to check. diff --git a/aquatic/src/lib/config.rs b/aquatic/src/lib/config.rs index e4f7b97..a3152f5 100644 --- a/aquatic/src/lib/config.rs +++ b/aquatic/src/lib/config.rs @@ -9,6 +9,7 @@ pub struct Config { pub socket_workers: usize, pub response_workers: usize, pub network: NetworkConfig, + pub handlers: HandlerConfig, pub statistics: StatisticsConfig, pub cleaning: CleaningConfig, } @@ -30,6 +31,13 @@ pub struct NetworkConfig { } +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct HandlerConfig { + pub max_requests_per_iter: usize, + pub channel_recv_timeout_ms: u64, +} + + #[derive(Clone, Debug, Serialize, Deserialize)] pub struct StatisticsConfig { /// Print statistics this often (seconds). Don't print when set to zero. @@ -54,6 +62,7 @@ impl Default for Config { socket_workers: 1, response_workers: 1, network: NetworkConfig::default(), + handlers: HandlerConfig::default(), statistics: StatisticsConfig::default(), cleaning: CleaningConfig::default(), } @@ -75,6 +84,16 @@ impl Default for NetworkConfig { } +impl Default for HandlerConfig { + fn default() -> Self { + Self { + max_requests_per_iter: 2048, + channel_recv_timeout_ms: 1, + } + } +} + + impl Default for StatisticsConfig { fn default() -> Self { Self { diff --git a/aquatic/src/lib/handlers.rs b/aquatic/src/lib/handlers.rs index 702a931..1cb86b2 100644 --- a/aquatic/src/lib/handlers.rs +++ b/aquatic/src/lib/handlers.rs @@ -26,10 +26,12 @@ pub fn handle( let mut std_rng = StdRng::from_entropy(); let mut small_rng = SmallRng::from_rng(&mut std_rng).unwrap(); - let timeout = Duration::from_millis(10); + let timeout = Duration::from_millis( + config.handlers.channel_recv_timeout_ms + ); loop { - for i in 0..1000 { + for i in 0..config.handlers.max_requests_per_iter { let (request, src): (Request, SocketAddr) = if i == 0 { match request_receiver.recv(){ Ok(r) => r,