From fbc80843c7935e7e4fa7e43bbec7d7258916b275 Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 10 Jul 2025 02:56:45 +0300 Subject: [PATCH] implement `listen` option, rename `enable_upnp_port_forwarding` to `listen_upnp` --- README.md | 10 ++++++---- src/config.rs | 8 ++++++-- src/main.rs | 15 +++++++++++++-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 150bbc4..2241ae5 100644 --- a/README.md +++ b/README.md @@ -55,12 +55,11 @@ aquatic-crawler --infohash /path/to/info-hash-ipv4.bin\ ### Options ``` bash - -d, --debug + -d, --debug Print debug output --infohash 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)) --tracker @@ -95,8 +94,11 @@ aquatic-crawler --infohash /path/to/info-hash-ipv4.bin\ --enable-tcp Enable TCP connection - --enable-upnp-port-forwarding - Enable UPnP + --listen + Bind listener on specified `host:port` (`[host]:port` for IPv6) + + --listen-upnp + Enable UPnP forwarding --enable-upload Enable upload (share bytes received with BitTorrent network) diff --git a/src/config.rs b/src/config.rs index 63cc2c6..12c9f7a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -53,9 +53,13 @@ pub struct Config { #[arg(long, default_value_t = false)] pub enable_tcp: bool, - /// Enable UPnP + /// Bind listener on specified `host:port` (`[host]:port` for IPv6) + #[arg(long)] + pub listen: Option, + + /// Enable UPnP forwarding #[arg(long, default_value_t = false)] - pub enable_upnp_port_forwarding: bool, + pub listen_upnp: bool, /// Enable upload (share bytes received with BitTorrent network) #[arg(long, default_value_t = false)] diff --git a/src/main.rs b/src/main.rs index 0ff1375..95a8015 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,11 +13,11 @@ use config::Config; use index::Index; use librqbit::{ AddTorrent, AddTorrentOptions, AddTorrentResponse, ByteBufOwned, ConnectionOptions, - PeerConnectionOptions, SessionOptions, TorrentMetaV1Info, + ListenerOptions, PeerConnectionOptions, SessionOptions, TorrentMetaV1Info, }; use peers::Peers; use rss::Rss; -use std::{collections::HashSet, num::NonZero, path::PathBuf, time::Duration}; +use std::{collections::HashSet, num::NonZero, path::PathBuf, str::FromStr, time::Duration}; use torrent::Torrent; use trackers::Trackers; use url::Url; @@ -51,6 +51,17 @@ async fn main() -> Result<()> { None => PathBuf::new(), }, SessionOptions { + listen: Some(match config.listen { + Some(l) => ListenerOptions { + listen_addr: std::net::SocketAddr::from_str(&l).unwrap(), + enable_upnp_port_forwarding: config.listen_upnp, + ..ListenerOptions::default() + }, + None => ListenerOptions { + enable_upnp_port_forwarding: config.listen_upnp, + ..ListenerOptions::default() + }, + }), connect: Some(ConnectionOptions { enable_tcp: config.enable_tcp, proxy_url: config.proxy_url,