diff --git a/crates/librqbit/src/dht/inforead.rs b/crates/librqbit/src/dht/inforead.rs index 9841003..4a13997 100644 --- a/crates/librqbit/src/dht/inforead.rs +++ b/crates/librqbit/src/dht/inforead.rs @@ -1,7 +1,7 @@ use std::net::SocketAddr; use futures::{stream::FuturesUnordered, StreamExt}; -use log::warn; +use log::debug; use tokio::sync::mpsc::UnboundedReceiver; use crate::{buffers::ByteString, peer_info_reader, torrent_metainfo::TorrentMetaV1Info}; @@ -50,7 +50,7 @@ pub async fn read_metainfo_from_peer_receiver( match done { Some(Ok(info)) => return ReadMetainfoResult::Found { info, seen, rx: addrs }, Some(Err(e)) => { - warn!("error in peer_info_reader::read_metainfo_from_peer: {}", e); + debug!("error in peer_info_reader::read_metainfo_from_peer: {}", e); }, None => unreachable!() } diff --git a/crates/librqbit/src/magnet.rs b/crates/librqbit/src/magnet.rs index d298326..be46172 100644 --- a/crates/librqbit/src/magnet.rs +++ b/crates/librqbit/src/magnet.rs @@ -27,12 +27,10 @@ impl Magnet { } } match info_hash { - Some(info_hash) => { - return Ok(Magnet { - info_hash, - trackers, - }) - } + Some(info_hash) => Ok(Magnet { + info_hash, + trackers, + }), None => { anyhow::bail!("did not find infohash") } diff --git a/crates/librqbit/src/torrent_manager.rs b/crates/librqbit/src/torrent_manager.rs index 5a63aec..f86336c 100644 --- a/crates/librqbit/src/torrent_manager.rs +++ b/crates/librqbit/src/torrent_manager.rs @@ -37,6 +37,7 @@ pub struct TorrentManagerBuilder { overwrite: bool, output_folder: PathBuf, only_files: Option>, + peer_id: Option<[u8; 20]>, force_tracker_interval: Option, spawner: Option, } @@ -53,6 +54,7 @@ impl TorrentManagerBuilder { overwrite: false, output_folder: output_folder.as_ref().into(), only_files: None, + peer_id: None, force_tracker_interval: None, spawner: None, } @@ -78,6 +80,11 @@ impl TorrentManagerBuilder { self } + pub fn peer_id(&mut self, peer_id: [u8; 20]) -> &mut Self { + self.peer_id = Some(peer_id); + self + } + pub fn start_manager(self) -> anyhow::Result { TorrentManager::start( self.info, @@ -86,6 +93,7 @@ impl TorrentManagerBuilder { self.overwrite, self.only_files, self.force_tracker_interval, + self.peer_id, self.spawner.unwrap_or_else(|| BlockingSpawner::new(true)), ) } @@ -123,6 +131,7 @@ impl TorrentManagerHandle { struct TorrentManager { state: Arc, + #[allow(dead_code)] speed_estimator: Arc, trackers: Mutex>, force_tracker_interval: Option, @@ -136,13 +145,15 @@ fn make_lengths>( } impl TorrentManager { - pub fn start>( + #[allow(clippy::too_many_arguments)] + fn start>( info: TorrentMetaV1Info, info_hash: [u8; 20], out: P, overwrite: bool, only_files: Option>, force_tracker_interval: Option, + peer_id: Option<[u8; 20]>, spawner: BlockingSpawner, ) -> anyhow::Result { let files = { @@ -180,7 +191,7 @@ impl TorrentManager { files }; - let peer_id = generate_peer_id(); + let peer_id = peer_id.unwrap_or_else(generate_peer_id); let lengths = make_lengths(&info).context("unable to compute Lengths from torrent")?; debug!("computed lengths: {:?}", &lengths); diff --git a/crates/librqbit/src/torrent_state.rs b/crates/librqbit/src/torrent_state.rs index bbc3fa5..45cc894 100644 --- a/crates/librqbit/src/torrent_state.rs +++ b/crates/librqbit/src/torrent_state.rs @@ -27,7 +27,7 @@ use crate::{ peer_connection::{PeerConnection, PeerConnectionHandler, WriterRequest}, peer_state::{InflightRequest, LivePeerState, PeerState}, spawn_utils::{spawn, BlockingSpawner}, - torrent_metainfo::{TorrentMetaV1Info, TorrentMetaV1Owned}, + torrent_metainfo::TorrentMetaV1Info, type_aliases::{PeerHandle, Sha1, BF}, }; diff --git a/src/main.rs b/src/main.rs index 897eca5..150fcb0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -57,7 +57,7 @@ enum LogLevel { #[derive(Clap)] #[clap(version = "1.0", author = "Igor Katson ")] struct Opts { - /// The filename or URL of the .torrent file. + /// The filename or URL of the torrent. If URL, http/https/magnet are supported. torrent_path: String, /// The filename of the .torrent file. @@ -182,7 +182,7 @@ async fn async_main(opts: Opts, spawner: BlockingSpawner) -> anyhow::Result<()> librqbit::dht::inforead::ReadMetainfoResult::Found { info, rx, seen } => { (info, rx, seen) } - librqbit::dht::inforead::ReadMetainfoResult::ChannelClosed { seen } => { + librqbit::dht::inforead::ReadMetainfoResult::ChannelClosed { .. } => { anyhow::bail!("DHT died, no way to discover torrent metainfo") } }; @@ -198,7 +198,7 @@ async fn async_main(opts: Opts, spawner: BlockingSpawner) -> anyhow::Result<()> .filter_map(|url| match reqwest::Url::parse(&url) { Ok(url) => Some(url), Err(e) => { - warn!("error parsing tracker {} as url", url); + warn!("error parsing tracker {} as url: {}", url, e); None } }) @@ -269,7 +269,10 @@ async fn main_info( None }; let mut builder = TorrentManagerBuilder::new(info, info_hash, opts.output_folder); - builder.overwrite(opts.overwrite).spawner(spawner); + builder + .overwrite(opts.overwrite) + .spawner(spawner) + .peer_id(peer_id); if let Some(only_files) = only_files { builder.only_files(only_files); } @@ -283,7 +286,7 @@ async fn main_info( for peer in initial_peers { handle.add_peer(peer); } - spawn("peer adder", { + spawn("DHT peer adder", { let handle = handle.clone(); async move { while let Some(peer) = dht_peer_rx.recv().await {