Skip to content

Commit

Permalink
interim implementation of the traker requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ishaan26 committed Jan 1, 2025
1 parent 6b0867b commit acfe62c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
9 changes: 3 additions & 6 deletions zung_torrent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,10 @@ impl TorrentArgs {
}
TorrentCommands::Test { file } => {
let torrent = Client::new(file)?;
let list = torrent
torrent
.sources()
.tracker_requests(torrent.info_hash().as_encoded(), torrent.peer_id())
.await
.unwrap();

println!("{list:#?}");
.tracker_responses(torrent.info_hash().as_encoded(), torrent.peer_id())
.await;
}
}

Expand Down
33 changes: 33 additions & 0 deletions zung_torrent/src/sources/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
PeerID,
};

use colored::Colorize;
use futures::StreamExt;

mod http_seeders;
Expand Down Expand Up @@ -205,4 +206,36 @@ impl<'a> DownloadSources<'a> {
None
}
}

pub async fn tracker_responses(
&self,
info_hash: InfoHashEncoded,
peer_id: PeerID,
) -> Option<()> {
if let Some(list) = self.tracker_list() {
let request_futures = list.generate_requests(info_hash, peer_id).await;
request_futures
.for_each_concurrent(None, |request| async move {
println!("Connecting");
match request {
Ok(Ok(tracker_request)) => {
let _ = tokio::spawn(async move {
println!("{}", "from thread".green());
let a = tracker_request.make_request().await;
if let Ok(resp) = a {
println!("{resp}")
}
})
.await;
}
Err(e) => eprintln!("{e}"),
Ok(Err(e)) => eprintln!("{e}"),
}
})
.await;
Some(())
} else {
None
}
}
}

0 comments on commit acfe62c

Please sign in to comment.