add initial_peers argument

This commit is contained in:
yggverse 2025-06-07 16:40:46 +03:00
parent 2572f0d32e
commit 491f7ef3c4
3 changed files with 46 additions and 28 deletions

View file

@ -65,8 +65,11 @@ aquatic-crawler --infohash-source /path/to/info-hash-ipv4.json\
--torrent-tracker <TORRENT_TRACKER>
Define custom tracker(s) to preload the `.torrent` files info
--enable_dht-dht
Enable DHT
--initial-peers <INITIAL_PEERS>
Define initial peer(s) to preload the `.torrent` files info
--enable-dht
Enable DHT resolver
--enable-upnp-port-forwarding
Enable UPnP

View file

@ -28,6 +28,10 @@ pub struct Argument {
#[arg(long)]
pub torrent_tracker: Vec<String>,
/// Define initial peer(s) to preload the `.torrent` files info
#[arg(long)]
pub initial_peers: Vec<String>,
/// Enable DHT resolver
#[arg(long, default_value_t = false)]
pub enable_dht: bool,

View file

@ -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()
}),