mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-03-31 17:55:36 +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]
|
||||
address = '0.0.0.0:3000'
|
||||
socket_recv_buffer_size = 524288
|
||||
poll_event_capacity = 4096
|
||||
|
||||
[protocol]
|
||||
max_scrape_torrents = 255
|
||||
max_response_peers = 255
|
||||
peer_announce_interval = 900
|
||||
socket_recv_buffer_size = 524288
|
||||
poll_event_capacity = 4096
|
||||
|
||||
[handlers]
|
||||
max_requests_per_iter = 10000
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ pub struct Config {
|
|||
/// generate responses and send them back to the socket workers.
|
||||
pub request_workers: usize,
|
||||
pub network: NetworkConfig,
|
||||
pub protocol: ProtocolConfig,
|
||||
pub handlers: HandlerConfig,
|
||||
pub statistics: StatisticsConfig,
|
||||
pub cleaning: CleaningConfig,
|
||||
|
|
@ -26,12 +27,6 @@ pub struct Config {
|
|||
pub struct NetworkConfig {
|
||||
/// Bind to this address
|
||||
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.
|
||||
///
|
||||
/// 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)]
|
||||
#[serde(default)]
|
||||
pub struct HandlerConfig {
|
||||
|
|
@ -99,6 +106,7 @@ impl Default for Config {
|
|||
socket_workers: 1,
|
||||
request_workers: 1,
|
||||
network: NetworkConfig::default(),
|
||||
protocol: ProtocolConfig::default(),
|
||||
handlers: HandlerConfig::default(),
|
||||
statistics: StatisticsConfig::default(),
|
||||
cleaning: CleaningConfig::default(),
|
||||
|
|
@ -112,11 +120,19 @@ impl Default for NetworkConfig {
|
|||
fn default() -> Self {
|
||||
Self {
|
||||
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_response_peers: 255,
|
||||
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 {
|
||||
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),
|
||||
seeders: NumberOfPeers(torrent_data.num_seeders as i32),
|
||||
peers: response_peers
|
||||
|
|
@ -311,10 +311,10 @@ fn calc_max_num_peers_to_take(
|
|||
peers_wanted: i32,
|
||||
) -> usize {
|
||||
if peers_wanted <= 0 {
|
||||
config.network.max_response_peers as usize
|
||||
config.protocol.max_response_peers as usize
|
||||
} else {
|
||||
::std::cmp::min(
|
||||
config.network.max_response_peers as usize,
|
||||
config.protocol.max_response_peers as usize,
|
||||
peers_wanted as usize
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ fn read_requests(
|
|||
Ok((amt, src)) => {
|
||||
let request = request_from_bytes(
|
||||
&buffer[..amt],
|
||||
config.network.max_scrape_torrents
|
||||
config.protocol.max_scrape_torrents
|
||||
);
|
||||
|
||||
bytes_received += amt;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue