mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +00:00
refactor aquatic_udp_protocol, notably make converters trait fns
This commit is contained in:
parent
2cf161469f
commit
ea6a4c2635
19 changed files with 774 additions and 809 deletions
|
|
@ -7,7 +7,7 @@ use indexmap::IndexMap;
|
|||
use parking_lot::Mutex;
|
||||
|
||||
pub use aquatic_common::ValidUntil;
|
||||
pub use aquatic_udp_protocol::types::*;
|
||||
pub use aquatic_udp_protocol::*;
|
||||
|
||||
|
||||
pub const MAX_PACKET_SIZE: usize = 4096;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use parking_lot::MutexGuard;
|
|||
use rand::{SeedableRng, Rng, rngs::{SmallRng, StdRng}};
|
||||
|
||||
use aquatic_common::{convert_ipv4_mapped_ipv6, extract_response_peers};
|
||||
use aquatic_udp_protocol::types::*;
|
||||
use aquatic_udp_protocol::*;
|
||||
|
||||
use crate::common::*;
|
||||
use crate::config::Config;
|
||||
|
|
|
|||
|
|
@ -9,8 +9,7 @@ use mio::{Events, Poll, Interest, Token};
|
|||
use mio::net::UdpSocket;
|
||||
use socket2::{Socket, Domain, Type, Protocol};
|
||||
|
||||
use aquatic_udp_protocol::types::IpVersion;
|
||||
use aquatic_udp_protocol::converters::{response_to_bytes, request_from_bytes};
|
||||
use aquatic_udp_protocol::{Request, Response, IpVersion};
|
||||
|
||||
use crate::common::*;
|
||||
use crate::config::Config;
|
||||
|
|
@ -131,7 +130,7 @@ fn read_requests(
|
|||
loop {
|
||||
match socket.recv_from(&mut buffer[..]) {
|
||||
Ok((amt, src)) => {
|
||||
let request = request_from_bytes(
|
||||
let request = Request::from_bytes(
|
||||
&buffer[..amt],
|
||||
config.protocol.max_scrape_torrents
|
||||
);
|
||||
|
|
@ -212,7 +211,7 @@ fn send_responses(
|
|||
|
||||
let ip_version = ip_version_from_ip(src.ip());
|
||||
|
||||
response_to_bytes(&mut cursor, response, ip_version).unwrap();
|
||||
response.write(&mut cursor, ip_version).unwrap();
|
||||
|
||||
let amt = cursor.position() as usize;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue