mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
aquatic_http: clean up / move around code; update TODO
This commit is contained in:
parent
c8de9857f8
commit
6fc4b693cd
4 changed files with 29 additions and 33 deletions
3
TODO.md
3
TODO.md
|
|
@ -14,7 +14,8 @@
|
|||
* compact peer representation in announce response: is implementation correct?
|
||||
* scrape info hash parsing: multiple ought to be accepted
|
||||
* move stuff to common crate with ws: what about Request/InMessage etc?
|
||||
* info hashes, peer ids: verify that they are 20 bytes
|
||||
* info hashes, peer ids: check that whole deserialization and url decoding
|
||||
works as it should. There are suspicously many `\u{fffd}`
|
||||
* AnnounceRequest.compact: parse int to bool
|
||||
|
||||
## aquatic_ws
|
||||
|
|
|
|||
|
|
@ -184,13 +184,6 @@ pub fn run_handshake_and_read_requests<'a>(
|
|||
|
||||
debug!("read request, sending to handler");
|
||||
|
||||
if let Request::Announce(ref request) = request {
|
||||
for (i, c) in request.info_hash.0.chars().enumerate() {
|
||||
debug!("{}: {}", i, c.escape_unicode());
|
||||
}
|
||||
debug!("request info hash char count: {}", request.info_hash.0.chars().count());
|
||||
}
|
||||
|
||||
if let Err(err) = request_channel_sender
|
||||
.send((meta, request))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,30 +9,6 @@ mod serde_helpers;
|
|||
use serde_helpers::*;
|
||||
|
||||
|
||||
pub fn serialize_response_peers_compact<S>(
|
||||
response_peers: &Vec<ResponsePeer>,
|
||||
serializer: S
|
||||
) -> Result<S::Ok, S::Error> where S: Serializer {
|
||||
let mut bytes = Vec::with_capacity(response_peers.len() * 6);
|
||||
|
||||
for peer in response_peers {
|
||||
match peer.ip_address {
|
||||
IpAddr::V4(ip) => {
|
||||
bytes.extend_from_slice(&u32::from(ip).to_be_bytes());
|
||||
bytes.extend_from_slice(&peer.port.to_be_bytes())
|
||||
},
|
||||
IpAddr::V6(_) => {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let text: String = bytes.into_iter().map(|byte| byte as char).collect();
|
||||
|
||||
serializer.serialize_str(&text)
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct PeerId(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
use std::net::IpAddr;
|
||||
|
||||
use serde::{Serializer, Deserializer, de::{Visitor, SeqAccess}};
|
||||
|
||||
use super::InfoHash;
|
||||
use super::{InfoHash, ResponsePeer};
|
||||
|
||||
|
||||
struct TwentyCharStringVisitor;
|
||||
|
|
@ -91,3 +93,27 @@ pub fn deserialize_info_hashes<'de, D>(
|
|||
{
|
||||
Ok(deserializer.deserialize_any(InfoHashVecVisitor).unwrap_or_default())
|
||||
}
|
||||
|
||||
|
||||
pub fn serialize_response_peers_compact<S>(
|
||||
response_peers: &Vec<ResponsePeer>,
|
||||
serializer: S
|
||||
) -> Result<S::Ok, S::Error> where S: Serializer {
|
||||
let mut bytes = Vec::with_capacity(response_peers.len() * 6);
|
||||
|
||||
for peer in response_peers {
|
||||
match peer.ip_address {
|
||||
IpAddr::V4(ip) => {
|
||||
bytes.extend_from_slice(&u32::from(ip).to_be_bytes());
|
||||
bytes.extend_from_slice(&peer.port.to_be_bytes())
|
||||
},
|
||||
IpAddr::V6(_) => {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let text: String = bytes.into_iter().map(|byte| byte as char).collect();
|
||||
|
||||
serializer.serialize_str(&text)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue