From 491f7ef3c42c5ac353c168f7f34c7c3baff97c42 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 7 Jun 2025 16:40:46 +0300 Subject: [PATCH] add `initial_peers` argument --- README.md | 59 ++++++++++++++++++++++++++----------------------- src/argument.rs | 4 ++++ src/main.rs | 11 +++++++++ 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 945c294..003b37b 100644 --- a/README.md +++ b/README.md @@ -44,47 +44,50 @@ aquatic-crawler --infohash-source /path/to/info-hash-ipv4.json\ ### Options ``` bash - -d, --debug - Debug level +-d, --debug + Debug level - * `e` - error * `i` - info + * `e` - error * `i` - info - [default: ei] + [default: ei] - -c, --clear - Clear previous index collected on crawl session start +-c, --clear + Clear previous index collected on crawl session start - -i, --infohash-source - Filepath(s) to the Aquatic tracker info-hash JSON/API +-i, --infohash-source + Filepath(s) to the Aquatic tracker info-hash JSON/API - * PR#233 feature + * PR#233 feature - --torrents-path - Directory path to store the `.torrent` files +--torrents-path + Directory path to store the `.torrent` files - --torrent-tracker - Define custom tracker(s) to preload the `.torrent` files info +--torrent-tracker + Define custom tracker(s) to preload the `.torrent` files info - --enable_dht-dht - Enable DHT +--initial-peers + Define initial peer(s) to preload the `.torrent` files info - --enable-upnp-port-forwarding - Enable UPnP +--enable-dht + Enable DHT resolver - --enable-upload - Enable upload +--enable-upnp-port-forwarding + Enable UPnP - --socks-proxy-url - Use `socks5://[username:password@]host:port` +--enable-upload + Enable upload - -s - Crawl loop delay in seconds +--socks-proxy-url + Use `socks5://[username:password@]host:port` - [default: 300] +-s + Crawl loop delay in seconds - -h, --help - Print help (see a summary with '-h') + [default: 300] - -V, --version - Print version +-h, --help + Print help (see a summary with '-h') + +-V, --version + Print version ``` \ No newline at end of file diff --git a/src/argument.rs b/src/argument.rs index 0043f45..004bfb5 100644 --- a/src/argument.rs +++ b/src/argument.rs @@ -28,6 +28,10 @@ pub struct Argument { #[arg(long)] pub torrent_tracker: Vec, + /// Define initial peer(s) to preload the `.torrent` files info + #[arg(long)] + pub initial_peers: Vec, + /// Enable DHT resolver #[arg(long, default_value_t = false)] pub enable_dht: bool, diff --git a/src/main.rs b/src/main.rs index 64e7afe..81aa64d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,6 +31,11 @@ async fn main() -> anyhow::Result<()> { trackers.insert(url::Url::from_str(&tracker)?); } + let mut peers = Vec::with_capacity(argument.initial_peers.len()); + for peer in argument.initial_peers { + peers.push(std::net::SocketAddr::from_str(&peer)?); + } + // begin if is_debug_i { debug::info(String::from("Crawler started")); @@ -72,6 +77,12 @@ async fn main() -> anyhow::Result<()> { "magnet:?xt=urn:btih:{i}" )), Some(librqbit::AddTorrentOptions { + disable_trackers: trackers.is_empty(), + initial_peers: if peers.is_empty() { + None + } else { + Some(peers.clone()) + }, list_only: true, ..Default::default() }),