From 52be6d7cef306b69ef9d7d3dcc17940aa04c4305 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Thu, 27 Feb 2025 12:55:10 +0000 Subject: [PATCH] Trackers list from outside --- crates/librqbit/Cargo.toml | 6 ++++-- crates/librqbit/src/session.rs | 4 ++++ crates/rqbit/src/main.rs | 10 +++++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/crates/librqbit/Cargo.toml b/crates/librqbit/Cargo.toml index a2a4453..1f8c4ee 100644 --- a/crates/librqbit/Cargo.toml +++ b/crates/librqbit/Cargo.toml @@ -98,7 +98,9 @@ tracing-subscriber = { version = "0.3", default-features = false, features = [ ], optional = true } uuid = { version = "1.2", features = ["v4"] } futures = "0.3" -url = { version = "=2.5.2", default-features = false } # can't upgrade yet until min version is Rust 1.81, see https://github.com/servo/rust-url/issues/992 +url = { version = "=2.5.2", default-features = false, features = [ + "serde", +] } # can't upgrade yet until min version is Rust 1.81, see https://github.com/servo/rust-url/issues/992 hex = "0.4" backoff = "0.4.0" @@ -119,7 +121,7 @@ notify = { version = "7", optional = true } walkdir = "2.5.0" arc-swap = "1.7.1" intervaltree = "0.2.7" -async-compression = {version="0.4.18", features= ["tokio", "gzip"] } +async-compression = { version = "0.4.18", features = ["tokio", "gzip"] } [build-dependencies] anyhow = "1" diff --git a/crates/librqbit/src/session.rs b/crates/librqbit/src/session.rs index f7188c7..e65eded 100644 --- a/crates/librqbit/src/session.rs +++ b/crates/librqbit/src/session.rs @@ -121,6 +121,7 @@ pub struct Session { default_storage_factory: Option, persistence: Option>, disk_write_tx: Option, + trackers: HashSet, // Limits and throttling pub(crate) concurrent_initialize_semaphore: Arc, @@ -647,6 +648,7 @@ impl Session { opts.concurrent_init_limit.unwrap_or(3), )), ratelimits: Limits::new(opts.ratelimits), + trackers: opts.trackers, #[cfg(feature = "disable-upload")] _disable_upload: opts.disable_upload, blocklist, @@ -1337,6 +1339,8 @@ impl Session { if is_private && trackers.len() > 1 { warn!("private trackers are not fully implemented, so using only the first tracker"); trackers.truncate(1); + } else { + trackers.extend(self.trackers.iter().cloned()); } let tracker_rx_stats = PeerRxTorrentInfo { diff --git a/crates/rqbit/src/main.rs b/crates/rqbit/src/main.rs index 01cb2ac..dde6707 100644 --- a/crates/rqbit/src/main.rs +++ b/crates/rqbit/src/main.rs @@ -440,7 +440,7 @@ async fn parse_trackers_file(filename: &str) -> anyhow::Result let content = tokio::fs::read_to_string(filename) .await .with_context(|| format!("error opening {filename}"))?; - Ok(content + let trackers = content .lines() .filter_map(|s| { let s = s.trim(); @@ -449,7 +449,9 @@ async fn parse_trackers_file(filename: &str) -> anyhow::Result } url::Url::parse(s).ok() }) - .collect()) + .collect::>(); + info!(filename, count = trackers.len(), "parsed trackers"); + Ok(trackers) } async fn async_main(opts: Opts, cancel: CancellationToken) -> anyhow::Result<()> { @@ -471,7 +473,9 @@ async fn async_main(opts: Opts, cancel: CancellationToken) -> anyhow::Result<()> }; let trackers = if let Some(f) = opts.trackers_filename { - parse_trackers_file(&f).await? + parse_trackers_file(&f) + .await + .context("error reading trackers file")? } else { Default::default() };