aquatic: put max_scrape_torrents, max_response_peers in NetworkConfig

This commit is contained in:
Joakim Frostegård 2020-04-08 21:32:05 +02:00
parent 7239e9c047
commit 31c8864658
3 changed files with 6 additions and 6 deletions

View file

@ -4,8 +4,6 @@ use std::net::SocketAddr;
#[derive(Clone)] #[derive(Clone)]
pub struct Config { pub struct Config {
pub num_threads: usize, pub num_threads: usize,
pub max_scrape_torrents: u8,
pub max_response_peers: usize,
pub network: NetworkConfig, pub network: NetworkConfig,
pub statistics: StatisticsConfig, pub statistics: StatisticsConfig,
pub cleaning: CleaningConfig, pub cleaning: CleaningConfig,
@ -15,6 +13,8 @@ pub struct Config {
#[derive(Clone)] #[derive(Clone)]
pub struct NetworkConfig { pub struct NetworkConfig {
pub address: SocketAddr, pub address: SocketAddr,
pub max_scrape_torrents: u8,
pub max_response_peers: usize,
pub peer_announce_interval: i32, pub peer_announce_interval: i32,
pub recv_buffer_size: usize, pub recv_buffer_size: usize,
pub poll_event_capacity: usize, pub poll_event_capacity: usize,
@ -39,8 +39,6 @@ impl Default for Config {
fn default() -> Self { fn default() -> Self {
Self { Self {
num_threads: 4, num_threads: 4,
max_scrape_torrents: 255,
max_response_peers: 255,
network: NetworkConfig::default(), network: NetworkConfig::default(),
statistics: StatisticsConfig::default(), statistics: StatisticsConfig::default(),
cleaning: CleaningConfig::default(), cleaning: CleaningConfig::default(),
@ -53,6 +51,8 @@ impl Default for NetworkConfig {
fn default() -> Self { fn default() -> Self {
Self { Self {
address: SocketAddr::from(([127, 0, 0, 1], 3000)), address: SocketAddr::from(([127, 0, 0, 1], 3000)),
max_scrape_torrents: 255,
max_response_peers: 255,
peer_announce_interval: 60 * 15, peer_announce_interval: 60 * 15,
poll_event_capacity: 4096, poll_event_capacity: 4096,
recv_buffer_size: 4096 * 128, recv_buffer_size: 4096 * 128,

View file

@ -82,7 +82,7 @@ pub fn handle_announce_requests(
}; };
let max_num_peers_to_take = (request.peers_wanted.0.max(0) as usize) let max_num_peers_to_take = (request.peers_wanted.0.max(0) as usize)
.min(config.max_response_peers); .min(config.network.max_response_peers);
// Since there is a miniscule risk of the torrent having been removed // Since there is a miniscule risk of the torrent having been removed
// by now, don't unwrap the result. // by now, don't unwrap the result.

View file

@ -121,7 +121,7 @@ fn handle_readable_socket(
Ok((amt, src)) => { Ok((amt, src)) => {
let request = request_from_bytes( let request = request_from_bytes(
&buffer[..amt], &buffer[..amt],
config.max_scrape_torrents config.network.max_scrape_torrents
); );
bytes_received += amt; bytes_received += amt;