mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 18:25:30 +00:00
aquatic_udp: move some config vars to new substruct, ProtocolConfig
This commit is contained in:
parent
5af9ae4ede
commit
840f67fc8d
4 changed files with 32 additions and 14 deletions
|
|
@ -94,11 +94,13 @@ request_workers = 1
|
||||||
|
|
||||||
[network]
|
[network]
|
||||||
address = '0.0.0.0:3000'
|
address = '0.0.0.0:3000'
|
||||||
|
socket_recv_buffer_size = 524288
|
||||||
|
poll_event_capacity = 4096
|
||||||
|
|
||||||
|
[protocol]
|
||||||
max_scrape_torrents = 255
|
max_scrape_torrents = 255
|
||||||
max_response_peers = 255
|
max_response_peers = 255
|
||||||
peer_announce_interval = 900
|
peer_announce_interval = 900
|
||||||
socket_recv_buffer_size = 524288
|
|
||||||
poll_event_capacity = 4096
|
|
||||||
|
|
||||||
[handlers]
|
[handlers]
|
||||||
max_requests_per_iter = 10000
|
max_requests_per_iter = 10000
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ pub struct Config {
|
||||||
/// generate responses and send them back to the socket workers.
|
/// generate responses and send them back to the socket workers.
|
||||||
pub request_workers: usize,
|
pub request_workers: usize,
|
||||||
pub network: NetworkConfig,
|
pub network: NetworkConfig,
|
||||||
|
pub protocol: ProtocolConfig,
|
||||||
pub handlers: HandlerConfig,
|
pub handlers: HandlerConfig,
|
||||||
pub statistics: StatisticsConfig,
|
pub statistics: StatisticsConfig,
|
||||||
pub cleaning: CleaningConfig,
|
pub cleaning: CleaningConfig,
|
||||||
|
|
@ -26,12 +27,6 @@ pub struct Config {
|
||||||
pub struct NetworkConfig {
|
pub struct NetworkConfig {
|
||||||
/// Bind to this address
|
/// Bind to this address
|
||||||
pub address: SocketAddr,
|
pub address: SocketAddr,
|
||||||
/// Maximum number of torrents to accept in scrape request
|
|
||||||
pub max_scrape_torrents: u8,
|
|
||||||
/// Maximum number of peers to return in announce response
|
|
||||||
pub max_response_peers: usize,
|
|
||||||
/// Ask peers to announce this often (seconds)
|
|
||||||
pub peer_announce_interval: i32,
|
|
||||||
/// Size of socket recv buffer. Use 0 for OS default.
|
/// Size of socket recv buffer. Use 0 for OS default.
|
||||||
///
|
///
|
||||||
/// This setting can have a big impact on dropped packages. It might
|
/// This setting can have a big impact on dropped packages. It might
|
||||||
|
|
@ -51,6 +46,18 @@ pub struct NetworkConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
|
#[serde(default)]
|
||||||
|
pub struct ProtocolConfig {
|
||||||
|
/// Maximum number of torrents to accept in scrape request
|
||||||
|
pub max_scrape_torrents: u8,
|
||||||
|
/// Maximum number of peers to return in announce response
|
||||||
|
pub max_response_peers: usize,
|
||||||
|
/// Ask peers to announce this often (seconds)
|
||||||
|
pub peer_announce_interval: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct HandlerConfig {
|
pub struct HandlerConfig {
|
||||||
|
|
@ -99,6 +106,7 @@ impl Default for Config {
|
||||||
socket_workers: 1,
|
socket_workers: 1,
|
||||||
request_workers: 1,
|
request_workers: 1,
|
||||||
network: NetworkConfig::default(),
|
network: NetworkConfig::default(),
|
||||||
|
protocol: ProtocolConfig::default(),
|
||||||
handlers: HandlerConfig::default(),
|
handlers: HandlerConfig::default(),
|
||||||
statistics: StatisticsConfig::default(),
|
statistics: StatisticsConfig::default(),
|
||||||
cleaning: CleaningConfig::default(),
|
cleaning: CleaningConfig::default(),
|
||||||
|
|
@ -112,11 +120,19 @@ impl Default for NetworkConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
address: SocketAddr::from(([0, 0, 0, 0], 3000)),
|
address: SocketAddr::from(([0, 0, 0, 0], 3000)),
|
||||||
|
poll_event_capacity: 4096,
|
||||||
|
socket_recv_buffer_size: 4096 * 128,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl Default for ProtocolConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
max_scrape_torrents: 255,
|
max_scrape_torrents: 255,
|
||||||
max_response_peers: 255,
|
max_response_peers: 255,
|
||||||
peer_announce_interval: 60 * 15,
|
peer_announce_interval: 60 * 15,
|
||||||
poll_event_capacity: 4096,
|
|
||||||
socket_recv_buffer_size: 4096 * 128,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -260,7 +260,7 @@ pub fn handle_announce_requests(
|
||||||
|
|
||||||
let response = Response::Announce(AnnounceResponse {
|
let response = Response::Announce(AnnounceResponse {
|
||||||
transaction_id: request.transaction_id,
|
transaction_id: request.transaction_id,
|
||||||
announce_interval: AnnounceInterval(config.network.peer_announce_interval),
|
announce_interval: AnnounceInterval(config.protocol.peer_announce_interval),
|
||||||
leechers: NumberOfPeers(torrent_data.num_leechers as i32),
|
leechers: NumberOfPeers(torrent_data.num_leechers as i32),
|
||||||
seeders: NumberOfPeers(torrent_data.num_seeders as i32),
|
seeders: NumberOfPeers(torrent_data.num_seeders as i32),
|
||||||
peers: response_peers
|
peers: response_peers
|
||||||
|
|
@ -311,10 +311,10 @@ fn calc_max_num_peers_to_take(
|
||||||
peers_wanted: i32,
|
peers_wanted: i32,
|
||||||
) -> usize {
|
) -> usize {
|
||||||
if peers_wanted <= 0 {
|
if peers_wanted <= 0 {
|
||||||
config.network.max_response_peers as usize
|
config.protocol.max_response_peers as usize
|
||||||
} else {
|
} else {
|
||||||
::std::cmp::min(
|
::std::cmp::min(
|
||||||
config.network.max_response_peers as usize,
|
config.protocol.max_response_peers as usize,
|
||||||
peers_wanted as usize
|
peers_wanted as usize
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,7 @@ fn read_requests(
|
||||||
Ok((amt, src)) => {
|
Ok((amt, src)) => {
|
||||||
let request = request_from_bytes(
|
let request = request_from_bytes(
|
||||||
&buffer[..amt],
|
&buffer[..amt],
|
||||||
config.network.max_scrape_torrents
|
config.protocol.max_scrape_torrents
|
||||||
);
|
);
|
||||||
|
|
||||||
bytes_received += amt;
|
bytes_received += amt;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue