mirror of
https://github.com/YGGverse/btracker.git
synced 2026-03-31 17:15:31 +00:00
fix scrape response, parse inline
This commit is contained in:
parent
a3e3cb0897
commit
ff0c0aae36
1 changed files with 6 additions and 15 deletions
|
|
@ -58,11 +58,13 @@ impl Udp {
|
||||||
|
|
||||||
let mut b = [0u8; 1024];
|
let mut b = [0u8; 1024];
|
||||||
let l = route.socket.recv(&mut b)?;
|
let l = route.socket.recv(&mut b)?;
|
||||||
let r = scrape_response(&b[..l]);
|
if l < 20 {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
|
||||||
t.leechers += r.leechers;
|
t.seeders += u32::from_be_bytes(b[8..12].try_into().unwrap());
|
||||||
t.peers += r.peers;
|
t.leechers += u32::from_be_bytes(b[12..16].try_into().unwrap());
|
||||||
t.seeders += r.seeders;
|
t.peers += u32::from_be_bytes(b[16..20].try_into().unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(t)
|
Ok(t)
|
||||||
|
|
@ -92,14 +94,3 @@ fn scrape_request(connection_id: u64, transaction_id: u32, info_hashes: &[Id20])
|
||||||
}
|
}
|
||||||
b
|
b
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scrape_response(response: &[u8]) -> Scrape {
|
|
||||||
if response.len() < 20 {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
Scrape {
|
|
||||||
leechers: u32::from_be_bytes(response[12..16].try_into().unwrap()),
|
|
||||||
seeders: u32::from_be_bytes(response[16..20].try_into().unwrap()),
|
|
||||||
peers: 0, // @TODO
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue