diff --git a/crates/librqbit/src/dht_utils.rs b/crates/librqbit/src/dht_utils.rs index c01b552..d97a98d 100644 --- a/crates/librqbit/src/dht_utils.rs +++ b/crates/librqbit/src/dht_utils.rs @@ -16,7 +16,7 @@ use librqbit_core::hash_id::Id20; pub enum ReadMetainfoResult { Found { info: TorrentMetaV1Info, - bytes: ByteBufOwned, + info_bytes: ByteBufOwned, rx: Rx, seen: HashSet, }, @@ -81,7 +81,7 @@ pub async fn read_metainfo_from_peer_receiver + Unp }, done = unordered.next(), if !unordered.is_empty() => { match done { - Some(Ok(info)) => return ReadMetainfoResult::Found { info: info.0, bytes: info.1, seen, rx: addrs }, + Some(Ok((info, info_bytes))) => return ReadMetainfoResult::Found { info, info_bytes, seen, rx: addrs }, Some(Err(e)) => { debug!("{:#}", e); }, diff --git a/crates/librqbit/src/peer_info_reader/mod.rs b/crates/librqbit/src/peer_info_reader/mod.rs index a2b170d..aff3e44 100644 --- a/crates/librqbit/src/peer_info_reader/mod.rs +++ b/crates/librqbit/src/peer_info_reader/mod.rs @@ -32,7 +32,7 @@ pub(crate) async fn read_metainfo_from_peer( peer_connection_options: Option, spawner: BlockingSpawner, connector: Arc, -) -> anyhow::Result { +) -> anyhow::Result { let (result_tx, result_rx) = tokio::sync::oneshot::channel::< anyhow::Result<(TorrentMetaV1Info, ByteBufOwned)>, >(); @@ -136,13 +136,13 @@ impl HandlerLocked { } } -pub type TorrentAndBytes = (TorrentMetaV1Info, ByteBufOwned); +pub type TorrentAndInfoBytes = (TorrentMetaV1Info, ByteBufOwned); struct Handler { addr: SocketAddr, info_hash: Id20, writer_tx: UnboundedSender, - result_tx: Mutex>>>, + result_tx: Mutex>>>, locked: RwLock>, } diff --git a/crates/librqbit/src/session.rs b/crates/librqbit/src/session.rs index 253ef02..4aa1b1a 100644 --- a/crates/librqbit/src/session.rs +++ b/crates/librqbit/src/session.rs @@ -502,6 +502,15 @@ async fn create_tcp_listener( bail!("no free TCP ports in range {port_range:?}"); } +fn torrent_file_from_info_and_bytes( + info: &TorrentMetaV1Info, + info_hash: &Id20, + info_bytes: &[u8], + trackers: &[String], +) -> Bytes { + todo!() +} + pub(crate) struct CheckedIncomingConnection { pub addr: SocketAddr, pub stream: tokio::net::TcpStream, @@ -986,16 +995,22 @@ impl Session { { ReadMetainfoResult::Found { info, - bytes, + info_bytes, rx, seen, } => { debug!(?info, "received result from DHT"); + let trackers = magnet.trackers.into_iter().unique().collect_vec(); InternalAddResult { info_hash, + torrent_bytes: torrent_file_from_info_and_bytes( + &info, + &info_hash, + &info_bytes, + &trackers, + ), info, - torrent_bytes: Bytes::from(bytes.0), - trackers: magnet.trackers.into_iter().unique().collect(), + trackers, peer_rx: Some(rx), initial_peers: seen.into_iter().collect(), }