Parsing tracker list
This commit is contained in:
parent
8ea5dfae87
commit
3eb1558451
4 changed files with 33 additions and 0 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -4436,6 +4436,7 @@ dependencies = [
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
"tracing",
|
"tracing",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
|
"url",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
||||||
|
|
@ -422,6 +422,9 @@ pub struct SessionOptions {
|
||||||
|
|
||||||
pub blocklist_url: Option<String>,
|
pub blocklist_url: Option<String>,
|
||||||
|
|
||||||
|
// The list of tracker URLs to always use for each torrent.
|
||||||
|
pub trackers: HashSet<url::Url>,
|
||||||
|
|
||||||
#[cfg(feature = "disable-upload")]
|
#[cfg(feature = "disable-upload")]
|
||||||
pub disable_upload: bool,
|
pub disable_upload: bool,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ libc = "0.2.158"
|
||||||
signal-hook = "0.3.17"
|
signal-hook = "0.3.17"
|
||||||
tokio-util = "0.7.11"
|
tokio-util = "0.7.11"
|
||||||
gethostname = "0.5.0"
|
gethostname = "0.5.0"
|
||||||
|
url = "2"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
futures = { version = "0.3" }
|
futures = { version = "0.3" }
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use std::{
|
use std::{
|
||||||
|
collections::HashSet,
|
||||||
io,
|
io,
|
||||||
net::SocketAddr,
|
net::SocketAddr,
|
||||||
num::NonZeroU32,
|
num::NonZeroU32,
|
||||||
|
|
@ -232,6 +233,10 @@ struct Opts {
|
||||||
/// Downloads a p2p blocklist from this url and blocks peers from it
|
/// Downloads a p2p blocklist from this url and blocks peers from it
|
||||||
#[arg(long, env = "RQBIT_BLOCKLIST_URL")]
|
#[arg(long, env = "RQBIT_BLOCKLIST_URL")]
|
||||||
blocklist_url: Option<String>,
|
blocklist_url: Option<String>,
|
||||||
|
|
||||||
|
/// The filename with tracker URLs to always use for each torrent.
|
||||||
|
#[arg(long, env = "RQBIT_TRACKERS_FILENAME")]
|
||||||
|
trackers_filename: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
|
@ -431,6 +436,22 @@ fn main() -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn parse_trackers_file(filename: &str) -> anyhow::Result<HashSet<url::Url>> {
|
||||||
|
let content = tokio::fs::read_to_string(filename)
|
||||||
|
.await
|
||||||
|
.with_context(|| format!("error opening {filename}"))?;
|
||||||
|
Ok(content
|
||||||
|
.lines()
|
||||||
|
.filter_map(|s| {
|
||||||
|
let s = s.trim();
|
||||||
|
if s.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
url::Url::parse(s).ok()
|
||||||
|
})
|
||||||
|
.collect())
|
||||||
|
}
|
||||||
|
|
||||||
async fn async_main(opts: Opts, cancel: CancellationToken) -> anyhow::Result<()> {
|
async fn async_main(opts: Opts, cancel: CancellationToken) -> anyhow::Result<()> {
|
||||||
let log_config = init_logging(InitLoggingOptions {
|
let log_config = init_logging(InitLoggingOptions {
|
||||||
default_rust_log_value: Some(match opts.log_level.unwrap_or(LogLevel::Info) {
|
default_rust_log_value: Some(match opts.log_level.unwrap_or(LogLevel::Info) {
|
||||||
|
|
@ -449,6 +470,12 @@ async fn async_main(opts: Opts, cancel: CancellationToken) -> anyhow::Result<()>
|
||||||
Err(e) => warn!("failed increasing open file limit: {:#}", e),
|
Err(e) => warn!("failed increasing open file limit: {:#}", e),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let trackers = if let Some(f) = opts.trackers_filename {
|
||||||
|
parse_trackers_file(&f).await?
|
||||||
|
} else {
|
||||||
|
Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
let mut sopts = SessionOptions {
|
let mut sopts = SessionOptions {
|
||||||
disable_dht: opts.disable_dht,
|
disable_dht: opts.disable_dht,
|
||||||
disable_dht_persistence: opts.disable_dht_persistence,
|
disable_dht_persistence: opts.disable_dht_persistence,
|
||||||
|
|
@ -499,6 +526,7 @@ async fn async_main(opts: Opts, cancel: CancellationToken) -> anyhow::Result<()>
|
||||||
download_bps: opts.ratelimit_download_bps,
|
download_bps: opts.ratelimit_download_bps,
|
||||||
},
|
},
|
||||||
blocklist_url: opts.blocklist_url,
|
blocklist_url: opts.blocklist_url,
|
||||||
|
trackers,
|
||||||
};
|
};
|
||||||
|
|
||||||
let http_api_basic_auth = if let Ok(up) = std::env::var("RQBIT_HTTP_BASIC_AUTH_USERPASS") {
|
let http_api_basic_auth = if let Ok(up) = std::env::var("RQBIT_HTTP_BASIC_AUTH_USERPASS") {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue