aquatic_ws: add setting Config.ipv6_only

This commit is contained in:
Joakim Frostegård 2020-05-23 15:40:56 +02:00
parent 416d61a2b2
commit d4bcc14c82
4 changed files with 15 additions and 4 deletions

View file

@ -143,6 +143,7 @@ socket_workers = 1
[network]
address = '0.0.0.0:3000'
ipv6_only = false
use_tls = false
tls_pkcs12_path = ''
tls_pkcs12_password = ''
@ -151,6 +152,8 @@ max_offers = 10
peer_announce_interval = 120
poll_event_capacity = 4096
poll_timeout_milliseconds = 50
websocket_max_message_size = 65536
websocket_max_frame_size = 16384
[handlers]
max_requests_per_iter = 10000

View file

@ -3,7 +3,7 @@
## aquatic_ws
* network
* send/recv buffer size config
* ipv6_only setting
* tcp backlog setting
* is it even necessary to check if event is readable in poll, since that
is all we're listening for?
* panic/error in workers: print error, exit program with non-zero exit code

View file

@ -22,6 +22,7 @@ pub struct Config {
pub struct NetworkConfig {
/// Bind to this address
pub address: SocketAddr,
pub ipv6_only: bool,
pub use_tls: bool,
pub tls_pkcs12_path: String,
pub tls_pkcs12_password: String,
@ -90,6 +91,7 @@ impl Default for NetworkConfig {
fn default() -> Self {
Self {
address: SocketAddr::from(([0, 0, 0, 0], 3000)),
ipv6_only: false,
use_tls: false,
tls_pkcs12_path: "".into(),
tls_pkcs12_password: "".into(),

View file

@ -1,5 +1,6 @@
use std::time::Instant;
use anyhow::Context;
use mio::Token;
use net2::{TcpBuilder, unix::UnixTcpBuilderExt};
@ -11,14 +12,19 @@ use super::connection::*;
pub fn create_listener(
config: &Config
) -> ::anyhow::Result<::std::net::TcpListener> {
let builder = if config.network.address.is_ipv4(){
let mut builder = &if config.network.address.is_ipv4(){
TcpBuilder::new_v4()
} else {
TcpBuilder::new_v6()
}?;
let builder = builder.reuse_port(true)?;
let builder = builder.bind(&config.network.address)?;
if config.network.ipv6_only {
builder = builder.only_v6(true)
.context("Failed setting ipv6_only to true")?
}
builder = builder.reuse_port(true)?;
builder = builder.bind(&config.network.address)?;
let listener = builder.listen(128)?;