aquatic-crawler/src/config.rs
2025-08-13 17:14:50 +03:00

125 lines
3.8 KiB
Rust

use clap::Parser;
use regex::Regex;
use std::{net::SocketAddr, path::PathBuf};
use url::Url;
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct Config {
/// Directory path to store preloaded data (e.g. `.torrent` files)
///
/// * it's probably the same location as `public` dir for the [btracker](https://github.com/YGGverse/btracker) frontend
#[arg(long)]
pub preload: PathBuf,
/// Absolute path(s) or URL(s) to import infohashes from the Aquatic tracker binary API
///
/// * PR#233 feature ([Wiki](https://github.com/YGGverse/aquatic-crawler/wiki/Aquatic))
#[arg(long)]
pub infohash: Vec<String>,
/// The P2P Blocklist file URL (to filter outgoing connections)
///
/// * use `--blocklist=file:///path/to/blocklist.txt` format for the local path
#[arg(long)]
pub blocklist: Option<Url>,
/// Define custom tracker(s) to preload the `.torrent` files info
#[arg(long)]
pub tracker: Vec<Url>,
/// Define initial peer(s) to preload the `.torrent` files info
#[arg(long)]
pub initial_peer: Option<Vec<SocketAddr>>,
/// Appends `--tracker` value to magnets and torrents
#[arg(long, default_value_t = false)]
pub export_trackers: bool,
/// Enable DHT resolver
#[arg(long, default_value_t = false)]
pub enable_dht: bool,
/// Enable LSD multicast
#[arg(long, default_value_t = false)]
pub enable_lsd: bool,
/// Disable TCP connection
#[arg(long, default_value_t = false)]
pub disable_tcp: bool,
/// Bind resolver session on specified device name (`tun0`, `mycelium`, etc.)
#[arg(long)]
pub bind: Option<String>,
/// Preload only files match regex pattern (list only without preload by default)
/// * see also `preload_max_filesize`, `preload_max_filecount` options
///
/// ## Example:
///
/// Filter by image ext
/// ```
/// --preload-regex '\.(png|gif|jpeg|jpg|webp|svg|log|txt)$'
/// ```
///
/// * requires `storage` argument defined
#[arg(long)]
pub preload_regex: Option<Regex>,
/// Max size sum of preloaded files per torrent (match `preload_regex`)
#[arg(long)]
pub preload_max_filesize: Option<u64>,
/// Max count of preloaded files per torrent (match `preload_regex`)
#[arg(long)]
pub preload_max_filecount: Option<usize>,
/// Use `socks5://[username:password@]host:port`
#[arg(long)]
pub proxy_url: Option<Url>,
// Tuneup the peers processor
#[arg(long)]
pub peer_connect_timeout: Option<u64>,
#[arg(long)]
pub peer_read_write_timeout: Option<u64>,
#[arg(long)]
pub peer_keep_alive_interval: Option<u64>,
/// Estimated info-hash index capacity
///
/// * use for memory optimization, depending on tracker volumes
#[arg(long, default_value_t = 1000)]
pub index_capacity: usize,
/// 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 (`add_torrent_timeout` is reached)
#[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,
/// Ban time in seconds on torrent data download is longer than `add_torrent_timeout`
#[arg(long)]
pub slow_torrent_ban: Option<u64>,
/// Crawl loop delay in seconds
#[arg(long, default_value_t = 60)]
pub sleep: u64,
/// Limit download speed (b/s)
#[arg(long)]
pub download_limit: Option<u32>, // * reminder: upload feature is not planed by the crawler impl
/// Skip long-thinking connections,
/// try to handle the other hashes in this queue after `n` seconds
#[arg(long, default_value_t = 60)]
pub wait_until_completed: u64,
}