diff --git a/src/format.rs b/src/format.rs index aedd356..5f5b440 100644 --- a/src/format.rs +++ b/src/format.rs @@ -20,7 +20,7 @@ pub fn magnet(info_hash: &str, trackers: Option<&Vec>) -> String { let mut b = if info_hash.len() == 40 { format!("magnet:?xt=urn:btih:{info_hash}") } else { - todo!("info-hash v2 yet not supported") + todo!("info-hash v2 yet not supported") // librqbit_core::hash_id::Id }; if let Some(t) = trackers { for tracker in t { diff --git a/src/main.rs b/src/main.rs index 64f7bb3..d6f442d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -73,7 +73,7 @@ fn index( .map(|t| t.format(&meta.format_time).to_string()), indexed: torrent.time.format(&meta.format_time).to_string(), magnet: format::magnet(&torrent.info_hash, meta.trackers.as_ref()), - scrape: scraper.scrape(torrent.info_hash.as_bytes()), + scrape: scraper.scrape(&torrent.info_hash), size: format::bytes(torrent.size), files: torrent.files.as_ref().map_or("1 file".into(), |f| { let l = f.len(); diff --git a/src/scraper.rs b/src/scraper.rs index d9860e6..1c46383 100644 --- a/src/scraper.rs +++ b/src/scraper.rs @@ -1,7 +1,7 @@ mod udp; use rocket::serde::Serialize; -use std::net::SocketAddr; +use std::{net::SocketAddr, str::FromStr}; use udp::Udp; #[derive(Serialize, Default)] @@ -24,14 +24,13 @@ impl Scraper { } } - pub fn scrape(&self, info_hash: &[u8]) -> Option { + pub fn scrape(&self, info_hash: &str) -> Option { self.udp.as_ref()?; - if info_hash.len() != 40 { - todo!("info-hash v2 yet not supported") - } let mut t = Scrape::default(); if let Some(ref u) = self.udp { - let r = u.scrape(info_hash).ok()?; // @TODO handle + let r = u + .scrape(librqbit_core::Id20::from_str(info_hash).ok()?) + .ok()?; // @TODO handle t.leechers += r.leechers; t.peers += r.peers; t.seeders += r.seeders; diff --git a/src/scraper/udp.rs b/src/scraper/udp.rs index c6031a8..6e80080 100644 --- a/src/scraper/udp.rs +++ b/src/scraper/udp.rs @@ -1,4 +1,5 @@ use super::Scrape; +use librqbit_core::hash_id::Id20; use rand::Rng; use std::{ io::Error, @@ -36,7 +37,7 @@ impl Udp { ) } - pub fn scrape(&self, info_hash: &[u8]) -> Result { + pub fn scrape(&self, info_hash: Id20) -> Result { let mut t = Scrape::default(); for route in &self.0 { for remote in &route.remote { @@ -50,7 +51,7 @@ impl Udp { &scrape_request( u64::from_be_bytes(b[8..16].try_into().unwrap()), rand::rng().random::(), - &[info_hash.to_vec()], + &[info_hash], ), remote, )?; @@ -76,7 +77,7 @@ fn connection_request() -> Vec { b } -fn scrape_request(connection_id: u64, transaction_id: u32, info_hashes: &[Vec]) -> Vec { +fn scrape_request(connection_id: u64, transaction_id: u32, info_hashes: &[Id20]) -> Vec { let mut b = Vec::new(); b.extend_from_slice(&connection_id.to_be_bytes()); b.extend_from_slice(&2u32.to_be_bytes()); @@ -87,7 +88,7 @@ fn scrape_request(connection_id: u64, transaction_id: u32, info_hashes: &[Vec