From 9a2f184a19fa238f5e6d03700fd4d37cb00704e9 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 13 Aug 2025 16:53:09 +0300 Subject: [PATCH] separate ban timeout config option, update ban handlers --- src/config.rs | 14 +++++++++----- src/main.rs | 16 +++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/config.rs b/src/config.rs index 03bd399..3ba56f4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -94,18 +94,22 @@ pub struct Config { #[arg(long, default_value_t = 1000)] pub index_capacity: usize, - /// Max time to handle each torrent + /// Max time in seconds to add new torrent #[arg(long, default_value_t = 60)] pub add_torrent_timeout: u64, + /// Ban time in seconds on torrent add failure + #[arg(long, default_value_t = 3600)] + pub add_torrent_ban: u64, + + /// Ban time in seconds on torrent resolve failure + #[arg(long, default_value_t = 3600)] + pub resolve_torrent_ban: u64, + /// Crawl loop delay in seconds #[arg(long, default_value_t = 60)] pub sleep: u64, - /// Ban unresolvable info-hashes for `n` seconds - #[arg(long, default_value_t = 3600)] - pub ban: u64, - /// Limit download speed (b/s) #[arg(long)] pub download_limit: Option, // * reminder: upload feature is not planed by the crawler impl diff --git a/src/main.rs b/src/main.rs index 1851fb9..7f6f1af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -71,7 +71,7 @@ async fn main() -> Result<()> { let time_queue = Local::now(); log::debug!("queue crawl begin at {time_queue}..."); ban.retain(|i, &mut t| { - let is_expired = t > time_queue - Duration::from_secs(config.ban); + let is_expired = t >= time_queue; if is_expired { log::debug!( "remove ban for `{}` by the timeout expiration ({t})", @@ -221,19 +221,17 @@ async fn main() -> Result<()> { } Ok(_) => panic!(), Err(e) => { - log::debug!( - "failed to resolve torrent `{h}`: `{e}`, ban for {} seconds.", - config.ban - ); - assert!(ban.insert(i, Local::now()).is_none()); + let t = Local::now() + Duration::from_secs(config.add_torrent_ban); + log::debug!("failed to resolve torrent `{h}`: `{e}`, ban until {t}."); + assert!(ban.insert(i, t).is_none()); } }, Err(e) => { + let t = Local::now() + Duration::from_secs(config.add_torrent_ban); log::debug!( - "skip awaiting the completion of adding torrent `{h}` data (`{e}`), ban for {} seconds.", - config.ban + "skip awaiting the completion of adding torrent `{h}` data (`{e}`), ban until {t}." ); - assert!(ban.insert(i, Local::now()).is_none()); + assert!(ban.insert(i, t).is_none()); } } }