diff --git a/crates/librqbit/src/session.rs b/crates/librqbit/src/session.rs index 1bfd586..4508e9c 100644 --- a/crates/librqbit/src/session.rs +++ b/crates/librqbit/src/session.rs @@ -43,7 +43,7 @@ use crate::{ torrent_state::{ ManagedTorrentBuilder, ManagedTorrentHandle, ManagedTorrentState, TorrentStateLive, }, - tracker_comms::{TorrentStatsForTrackerDummy, TrackerComms}, + tracker_comms::{self, TorrentStatsForTrackerDummy, TrackerComms}, type_aliases::PeerStream, }; @@ -768,7 +768,7 @@ impl Session { self.tcp_listen_port }; - let (info_hash, info, peer_rx, initial_peers) = match add { + let (info_hash, info, trackers, peer_rx, initial_peers) = match add { AddTorrent::Url(magnet) if magnet.starts_with("magnet:") => { let magnet = Magnet::parse(&magnet).context("provided path is not a valid magnet URL")?; @@ -785,7 +785,7 @@ impl Session { let tracker_peer_rx = TrackerComms::start( info_hash, self.peer_id, - magnet.trackers, + magnet.trackers.clone(), Box::new(TorrentStatsForTrackerDummy {}), opts.force_tracker_interval, self.cancellation_token().clone(), @@ -816,6 +816,7 @@ impl Session { ( info_hash, info, + magnet.trackers, if opts.paused || opts.list_only { None } else { @@ -856,7 +857,7 @@ impl Session { Ok(url) => Some(url.to_owned()), Err(_) => { warn!("cannot parse tracker url as utf-8, ignoring"); - return None; + None } }) .collect::>(); @@ -864,7 +865,7 @@ impl Session { let tracker_peer_rx = TrackerComms::start( torrent.info_hash, self.peer_id, - trackers, + trackers.clone(), Box::new(TorrentStatsForTrackerDummy {}), opts.force_tracker_interval, self.cancellation_token().clone(), @@ -876,6 +877,7 @@ impl Session { ( torrent.info_hash, torrent.info, + trackers, peer_rx, opts.initial_peers .clone() @@ -889,6 +891,7 @@ impl Session { self.main_torrent_info( info_hash, info, + trackers, peer_rx, initial_peers.into_iter().collect(), opts, @@ -901,6 +904,7 @@ impl Session { &self, info_hash: Id20, info: TorrentMetaV1Info, + trackers: Vec, peer_rx: Option, initial_peers: Vec, opts: AddTorrentOptions, @@ -988,6 +992,7 @@ impl Session { .overwrite(opts.overwrite) .spawner(self.spawner) .cancellation_token(self.cancellation_token.child_token()) + .trackers(trackers) .peer_id(self.peer_id); if let Some(only_files) = only_files { @@ -1074,13 +1079,22 @@ impl Session { } pub fn unpause(&self, handle: &ManagedTorrentHandle) -> anyhow::Result<()> { - let peer_rx = self + let dht_rx = self .dht .as_ref() .map(|dht| dht.get_peers(handle.info_hash(), self.tcp_listen_port)) .transpose()?; - todo!(); - let peer_rx = None; + let trackers = handle.info().trackers.clone(); + let peer_rx = TrackerComms::start( + handle.info.info_hash, + handle.info.peer_id, + trackers.into_iter().collect(), + Box::new(tracker_comms::TorrentStatsForTrackerDummy {}), + None, + self.cancellation_token.clone(), + self.tcp_listen_port, + ); + let peer_rx = merge_peer_rx(dht_rx, peer_rx); handle.start(Default::default(), peer_rx, false)?; Ok(()) } diff --git a/crates/librqbit/src/torrent_state/mod.rs b/crates/librqbit/src/torrent_state/mod.rs index da80053..0899750 100644 --- a/crates/librqbit/src/torrent_state/mod.rs +++ b/crates/librqbit/src/torrent_state/mod.rs @@ -84,7 +84,7 @@ pub struct ManagedTorrentInfo { pub info_hash: Id20, pub out_dir: PathBuf, pub(crate) spawner: BlockingSpawner, - pub trackers: HashSet, + pub trackers: HashSet, pub peer_id: Id20, pub lengths: Lengths, pub span: tracing::Span, @@ -422,7 +422,7 @@ pub struct ManagedTorrentBuilder { peer_connect_timeout: Option, peer_read_write_timeout: Option, only_files: Option>, - trackers: Vec, + trackers: Vec, peer_id: Option, overwrite: bool, spawner: Option, @@ -461,7 +461,7 @@ impl ManagedTorrentBuilder { self } - pub fn trackers(&mut self, trackers: Vec) -> &mut Self { + pub fn trackers(&mut self, trackers: Vec) -> &mut Self { self.trackers = trackers; self }