mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-02 10:45:30 +00:00
aquatic: move some fields from Config into new NetworkConfig
This commit is contained in:
parent
fa60eddcc4
commit
ca9d15c7a9
2 changed files with 26 additions and 12 deletions
|
|
@ -3,17 +3,22 @@ use std::net::SocketAddr;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub address: SocketAddr,
|
|
||||||
pub num_threads: usize,
|
pub num_threads: usize,
|
||||||
pub recv_buffer_size: usize,
|
|
||||||
pub poll_event_capacity: usize,
|
|
||||||
pub max_scrape_torrents: u8,
|
pub max_scrape_torrents: u8,
|
||||||
pub max_response_peers: usize,
|
pub max_response_peers: usize,
|
||||||
|
pub network: NetworkConfig,
|
||||||
pub statistics: StatisticsConfig,
|
pub statistics: StatisticsConfig,
|
||||||
pub cleaning: CleaningConfig,
|
pub cleaning: CleaningConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct NetworkConfig {
|
||||||
|
pub address: SocketAddr,
|
||||||
|
pub recv_buffer_size: usize,
|
||||||
|
pub poll_event_capacity: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct StatisticsConfig {
|
pub struct StatisticsConfig {
|
||||||
|
|
@ -32,12 +37,10 @@ pub struct CleaningConfig {
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
address: SocketAddr::from(([127, 0, 0, 1], 3000)),
|
|
||||||
num_threads: 4,
|
num_threads: 4,
|
||||||
poll_event_capacity: 4096,
|
|
||||||
recv_buffer_size: 4096 * 128,
|
|
||||||
max_scrape_torrents: 255,
|
max_scrape_torrents: 255,
|
||||||
max_response_peers: 255,
|
max_response_peers: 255,
|
||||||
|
network: NetworkConfig::default(),
|
||||||
statistics: StatisticsConfig::default(),
|
statistics: StatisticsConfig::default(),
|
||||||
cleaning: CleaningConfig::default(),
|
cleaning: CleaningConfig::default(),
|
||||||
}
|
}
|
||||||
|
|
@ -45,6 +48,17 @@ impl Default for Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl Default for NetworkConfig {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
address: SocketAddr::from(([127, 0, 0, 1], 3000)),
|
||||||
|
poll_event_capacity: 4096,
|
||||||
|
recv_buffer_size: 4096 * 128,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Default for StatisticsConfig {
|
impl Default for StatisticsConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ pub fn run_event_loop(
|
||||||
.register(&mut socket, Token(token_num), interests)
|
.register(&mut socket, Token(token_num), interests)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let mut events = Events::with_capacity(config.poll_event_capacity);
|
let mut events = Events::with_capacity(config.network.poll_event_capacity);
|
||||||
|
|
||||||
let mut connect_requests: Vec<(ConnectRequest, SocketAddr)> = Vec::with_capacity(1024);
|
let mut connect_requests: Vec<(ConnectRequest, SocketAddr)> = Vec::with_capacity(1024);
|
||||||
let mut announce_requests: Vec<(AnnounceRequest, SocketAddr)> = Vec::with_capacity(1024);
|
let mut announce_requests: Vec<(AnnounceRequest, SocketAddr)> = Vec::with_capacity(1024);
|
||||||
|
|
@ -72,7 +72,7 @@ pub fn run_event_loop(
|
||||||
|
|
||||||
fn create_socket(config: &Config) -> ::std::net::UdpSocket {
|
fn create_socket(config: &Config) -> ::std::net::UdpSocket {
|
||||||
let mut builder = &{
|
let mut builder = &{
|
||||||
if config.address.is_ipv4(){
|
if config.network.address.is_ipv4(){
|
||||||
UdpBuilder::new_v4().expect("socket: build")
|
UdpBuilder::new_v4().expect("socket: build")
|
||||||
} else {
|
} else {
|
||||||
UdpBuilder::new_v6().expect("socket: build")
|
UdpBuilder::new_v6().expect("socket: build")
|
||||||
|
|
@ -82,16 +82,16 @@ fn create_socket(config: &Config) -> ::std::net::UdpSocket {
|
||||||
builder = builder.reuse_port(true)
|
builder = builder.reuse_port(true)
|
||||||
.expect("socket: set reuse port");
|
.expect("socket: set reuse port");
|
||||||
|
|
||||||
let socket = builder.bind(&config.address)
|
let socket = builder.bind(&config.network.address)
|
||||||
.expect(&format!("socket: bind to {}", &config.address));
|
.expect(&format!("socket: bind to {}", &config.network.address));
|
||||||
|
|
||||||
socket.set_nonblocking(true)
|
socket.set_nonblocking(true)
|
||||||
.expect("socket: set nonblocking");
|
.expect("socket: set nonblocking");
|
||||||
|
|
||||||
if let Err(err) = socket.set_recv_buffer_size(config.recv_buffer_size){
|
if let Err(err) = socket.set_recv_buffer_size(config.network.recv_buffer_size){
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"socket: failed setting recv buffer to {}: {:?}",
|
"socket: failed setting recv buffer to {}: {:?}",
|
||||||
config.recv_buffer_size,
|
config.network.recv_buffer_size,
|
||||||
err
|
err
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue