mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 10:45:30 +00:00
Run rustfmt, clean up aquatic_http_protocol/Cargo.toml
This commit is contained in:
parent
0cc312a78d
commit
d0e716f80b
65 changed files with 1754 additions and 2590 deletions
|
|
@ -1,24 +1,22 @@
|
|||
use std::net::SocketAddr;
|
||||
use std::sync::{Arc, atomic::AtomicUsize};
|
||||
use std::sync::{atomic::AtomicUsize, Arc};
|
||||
|
||||
use hashbrown::HashMap;
|
||||
use parking_lot::Mutex;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use aquatic_udp_protocol::*;
|
||||
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)]
|
||||
pub struct ThreadId(pub u8);
|
||||
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct Config {
|
||||
/// Server address
|
||||
pub server_address: SocketAddr,
|
||||
/// Number of sockets and socket worker threads
|
||||
///
|
||||
///
|
||||
/// Sockets will bind to one port each, and with
|
||||
/// multiple_client_ips = true, additionally to one IP each.
|
||||
pub num_socket_workers: u8,
|
||||
|
|
@ -31,14 +29,13 @@ pub struct Config {
|
|||
pub handler: HandlerConfig,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct NetworkConfig {
|
||||
/// True means bind to one localhost IP per socket. On macOS, this by
|
||||
/// default causes all server responses to go to one socket worker.
|
||||
/// Default option ("true") can cause issues on macOS.
|
||||
///
|
||||
///
|
||||
/// The point of multiple IPs is to possibly cause a better distribution
|
||||
/// of requests to servers with SO_REUSEPORT option.
|
||||
pub multiple_client_ips: bool,
|
||||
|
|
@ -51,7 +48,7 @@ pub struct NetworkConfig {
|
|||
/// Socket worker polling event number
|
||||
pub poll_event_capacity: usize,
|
||||
/// Size of socket recv buffer. Use 0 for OS default.
|
||||
///
|
||||
///
|
||||
/// This setting can have a big impact on dropped packages. It might
|
||||
/// require changing system defaults. Some examples of commands to set
|
||||
/// recommended values for different operating systems:
|
||||
|
|
@ -67,7 +64,6 @@ pub struct NetworkConfig {
|
|||
pub recv_buffer: usize,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct HandlerConfig {
|
||||
|
|
@ -89,7 +85,7 @@ pub struct HandlerConfig {
|
|||
/// Handler: max microseconds to wait for single response from channel
|
||||
pub channel_timeout: u64,
|
||||
/// Pareto shape
|
||||
///
|
||||
///
|
||||
/// Fake peers choose torrents according to Pareto distribution.
|
||||
pub torrent_selection_pareto_shape: f64,
|
||||
/// Probability that a generated peer is a seeder
|
||||
|
|
@ -100,7 +96,6 @@ pub struct HandlerConfig {
|
|||
pub additional_request_factor: f64,
|
||||
}
|
||||
|
||||
|
||||
impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
|
@ -127,7 +122,6 @@ impl Default for NetworkConfig {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl Default for HandlerConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
|
@ -145,7 +139,6 @@ impl Default for HandlerConfig {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(PartialEq, Eq, Clone)]
|
||||
pub struct TorrentPeer {
|
||||
pub info_hash: InfoHash,
|
||||
|
|
@ -155,10 +148,8 @@ pub struct TorrentPeer {
|
|||
pub port: Port,
|
||||
}
|
||||
|
||||
|
||||
pub type TorrentPeerMap = HashMap<TransactionId, TorrentPeer>;
|
||||
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Statistics {
|
||||
pub requests: AtomicUsize,
|
||||
|
|
@ -169,7 +160,6 @@ pub struct Statistics {
|
|||
pub responses_error: AtomicUsize,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct LoadTestState {
|
||||
pub torrent_peers: Arc<Mutex<TorrentPeerMap>>,
|
||||
|
|
@ -177,15 +167,13 @@ pub struct LoadTestState {
|
|||
pub statistics: Arc<Statistics>,
|
||||
}
|
||||
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
pub enum RequestType {
|
||||
Announce,
|
||||
Connect,
|
||||
Scrape
|
||||
Scrape,
|
||||
}
|
||||
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct SocketWorkerLocalStatistics {
|
||||
pub requests: usize,
|
||||
|
|
@ -194,4 +182,4 @@ pub struct SocketWorkerLocalStatistics {
|
|||
pub responses_announce: usize,
|
||||
pub responses_scrape: usize,
|
||||
pub responses_error: usize,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue