mirror of
https://github.com/greatest-ape/aquatic.git
synced 2026-10-23 17:52:27 +00:00
Add inline markers; simplify ip address conversion in request_from_bytes
This commit is contained in:
1 parent
4721fa3109
commit
a865f4a1ae
6 files changed
+15
-6
No files matched your search
@@ -36,6 +36,7 @@ impl PeerStatus {
|
||||
/// Determine peer status from announce event and number of bytes left.
|
||||
///
|
||||
/// Likely, the last branch will be taken most of the time.
|
||||
#[inline]
|
||||
pub fn from_event_and_bytes_left(
|
||||
event: AnnounceEvent,
|
||||
bytes_left: NumberOfBytes
|
||||
@@ -62,12 +63,14 @@ pub struct Peer {
|
||||
|
||||
|
||||
impl Peer {
|
||||
#[inline(always)]
|
||||
pub fn to_response_peer(&self) -> ResponsePeer {
|
||||
ResponsePeer {
|
||||
ip_address: self.ip_address,
|
||||
port: self.port
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn from_announce_and_ip(
|
||||
announce_request: &AnnounceRequest,
|
||||
ip_address: IpAddr
|
||||
|
||||
@@ -214,6 +214,7 @@ pub fn extract_response_peers(
|
||||
}
|
||||
|
||||
|
||||
#[inline(always)]
|
||||
pub fn create_torrent_scrape_statistics(
|
||||
seeders: i32,
|
||||
leechers: i32
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
//! ```
|
||||
//! ## Average results over 50 rounds
|
||||
//!
|
||||
//! Connect handler: 2 514 978 requests/second, 397.87 ns/request
|
||||
//! Announce handler: 246 744 requests/second, 4054.58 ns/request
|
||||
//! Scrape handler: 499 385 requests/second, 2007.23 ns/request
|
||||
//! Connect handler: 2 519 969 requests/second, 397.36 ns/request
|
||||
//! Announce handler: 270 880 requests/second, 3691.91 ns/request
|
||||
//! Scrape handler: 510 028 requests/second, 1961.18 ns/request
|
||||
//! ```
|
||||
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user