diff --git a/README.md b/README.md index e03cdc2..71bb750 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/TODO.md b/TODO.md index 3c65a71..20f05d6 100644 --- a/TODO.md +++ b/TODO.md @@ -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 diff --git a/aquatic_ws/src/lib/config.rs b/aquatic_ws/src/lib/config.rs index 153832e..6f7f6e1 100644 --- a/aquatic_ws/src/lib/config.rs +++ b/aquatic_ws/src/lib/config.rs @@ -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(), diff --git a/aquatic_ws/src/lib/network/utils.rs b/aquatic_ws/src/lib/network/utils.rs index 45ca98e..7783bdf 100644 --- a/aquatic_ws/src/lib/network/utils.rs +++ b/aquatic_ws/src/lib/network/utils.rs @@ -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)?;