mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 10:15:31 +00:00
Add inline markers; simplify ip address conversion in request_from_bytes
This commit is contained in:
parent
4721fa3109
commit
a865f4a1ae
6 changed files with 15 additions and 6 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use crate::types;
|
||||
|
||||
|
||||
#[inline]
|
||||
pub fn event_from_i32(i: i32) -> types::AnnounceEvent {
|
||||
match i {
|
||||
1 => types::AnnounceEvent::Completed,
|
||||
|
|
@ -11,6 +12,7 @@ pub fn event_from_i32(i: i32) -> types::AnnounceEvent {
|
|||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
pub fn event_to_i32(event: types::AnnounceEvent) -> i32 {
|
||||
match event {
|
||||
types::AnnounceEvent::None => 0,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ use super::common::*;
|
|||
const MAGIC_NUMBER: i64 = 4_497_486_125_440;
|
||||
|
||||
|
||||
#[inline]
|
||||
pub fn request_to_bytes(
|
||||
bytes: &mut impl Write,
|
||||
request: types::Request
|
||||
|
|
@ -60,6 +61,7 @@ pub fn request_to_bytes(
|
|||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
pub fn request_from_bytes(
|
||||
bytes: &[u8],
|
||||
max_scrape_torrents: u8,
|
||||
|
|
@ -110,9 +112,8 @@ pub fn request_from_bytes(
|
|||
|
||||
let opt_ip = if ip == [0; 4] {
|
||||
None
|
||||
}
|
||||
else {
|
||||
Some(Ipv4Addr::new(ip[0], ip[1], ip[2], ip[3]))
|
||||
} else {
|
||||
Some(Ipv4Addr::from(ip))
|
||||
};
|
||||
|
||||
Ok(types::Request::Announce(types::AnnounceRequest {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use std::net::{IpAddr, Ipv6Addr, Ipv4Addr};
|
|||
use crate::types;
|
||||
|
||||
|
||||
#[inline]
|
||||
pub fn response_to_bytes(
|
||||
bytes: &mut impl Write,
|
||||
response: types::Response,
|
||||
|
|
@ -78,6 +79,7 @@ pub fn response_to_bytes(
|
|||
}
|
||||
|
||||
|
||||
#[inline]
|
||||
pub fn response_from_bytes(
|
||||
bytes: &[u8],
|
||||
ip_version: types::IpVersion,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue