mirror of
https://github.com/YGGverse/btracker.git
synced 2026-03-31 17:15:31 +00:00
use librqbit_core::hash_id::Id to parse info-hash from string
This commit is contained in:
parent
3e94c483d6
commit
a3e3cb0897
4 changed files with 12 additions and 12 deletions
|
|
@ -20,7 +20,7 @@ pub fn magnet(info_hash: &str, trackers: Option<&Vec<url::Url>>) -> 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 {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<Scrape> {
|
||||
pub fn scrape(&self, info_hash: &str) -> Option<Scrape> {
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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<Scrape, Error> {
|
||||
pub fn scrape(&self, info_hash: Id20) -> Result<Scrape, Error> {
|
||||
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::<u32>(),
|
||||
&[info_hash.to_vec()],
|
||||
&[info_hash],
|
||||
),
|
||||
remote,
|
||||
)?;
|
||||
|
|
@ -76,7 +77,7 @@ fn connection_request() -> Vec<u8> {
|
|||
b
|
||||
}
|
||||
|
||||
fn scrape_request(connection_id: u64, transaction_id: u32, info_hashes: &[Vec<u8>]) -> Vec<u8> {
|
||||
fn scrape_request(connection_id: u64, transaction_id: u32, info_hashes: &[Id20]) -> Vec<u8> {
|
||||
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<u8
|
|||
todo!()
|
||||
}
|
||||
for hash in info_hashes {
|
||||
b.extend_from_slice(hash);
|
||||
b.extend_from_slice(&hash.0);
|
||||
}
|
||||
b
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue