This commit is contained in:
Antoine Langlois 2024-04-02 21:26:42 +02:00
parent 2272395a3e
commit 61fb0934d1
Signed by: DataHearth
GPG Key ID: 946E2D0C410C7B3D
3 changed files with 20 additions and 3075 deletions

3059
cli/out

File diff suppressed because it is too large Load Diff

View File

@ -1,10 +1,13 @@
use std::fs;
use brs::torrent::v1;
pub(crate) fn metadata(v1: bool, _v2: bool, path: String) {
if v1 {
let torrent = v1::Torrent::parse(path);
let bytes = fs::read(path).unwrap();
let torrent = v1::Torrent::parse_bytes(&bytes);
if let Err(e) = &torrent {
println!("Failed to parse torrent: {e}");
eprintln!("{e}");
}
println!("{}", torrent.unwrap())
} else {

View File

@ -1,38 +1,39 @@
use std::fs;
use brs::{
torrent::v1,
tracker::{Tracker, TrackerRequest, Announce},
tracker::{Tracker, TrackerRequest},
};
use rand::distributions::Alphanumeric;
use rand::Rng;
pub(crate) async fn check(path: String) {
let torrent = v1::Torrent::parse(path);
let bytes = fs::read(path).unwrap();
let torrent = v1::Torrent::parse_bytes(&bytes);
if let Err(e) = &torrent {
eprintln!("Failed to parse torrent: {e}")
}
let torrent = torrent.unwrap();
let mut tracker = Tracker {
url: torrent.announce,
peers: None,
interval: None,
};
let peer_id: String = rand::thread_rng()
.sample_iter(&Alphanumeric)
.take(12)
.map(char::from)
.collect();
let info_hash = match torrent.calc_hash() {
Ok(v) => v,
Err(e) => return eprintln!("Failed to calculate info hash: {e}"),
};
let mut tracker = Tracker::new(torrent.announce.clone());
let rsp = tracker
.announce(TrackerRequest {
ip: None,
port: None,
peer_id: format!("-BRS010-{peer_id}"),
downloaded: "".to_string(),
left: "".to_string(),
uploaded: "".to_string(),
event: None,
info_hash: "".to_string(),
downloaded: "0".to_string(),
left: torrent.calc_download_lenght().to_string(),
uploaded: "0".to_string(),
info_hash,
compact: true,
..Default::default()
})
.await;