diff --git a/crates/lanspread-peer/src/config.rs b/crates/lanspread-peer/src/config.rs index e20ff5c..b8473f1 100644 --- a/crates/lanspread-peer/src/config.rs +++ b/crates/lanspread-peer/src/config.rs @@ -35,6 +35,9 @@ pub const QUIC_MAX_SEND_BUFFER_SIZE: u32 = 32 * 1024 * 1024; /// Initial congestion window for LAN-oriented BBR transfers (1 MiB). pub const QUIC_INITIAL_CONGESTION_WINDOW: u32 = 1024 * 1024; +/// Requested OS UDP send and receive buffer size for QUIC sockets (4 MiB). +pub const QUIC_SOCKET_BUFFER_SIZE: usize = 4 * 1024 * 1024; + /// Fallback interval for reconciling missed filesystem watcher events (seconds). pub const LOCAL_GAME_FALLBACK_SCAN_SECS: u64 = 300; diff --git a/crates/lanspread-peer/src/network.rs b/crates/lanspread-peer/src/network.rs index c96b066..7609902 100644 --- a/crates/lanspread-peer/src/network.rs +++ b/crates/lanspread-peer/src/network.rs @@ -14,7 +14,11 @@ use s2n_quic::{ Client as QuicClient, Connection, client::Connect, - provider::{congestion_controller, limits::Limits}, + provider::{ + congestion_controller, + io::tokio::{Builder as QuicIoBuilder, Provider as QuicIoProvider}, + limits::Limits, + }, }; use tokio_util::codec::{FramedRead, FramedWrite, LengthDelimitedCodec}; @@ -23,6 +27,7 @@ use crate::config::{ QUIC_CONNECTION_DATA_WINDOW, QUIC_INITIAL_CONGESTION_WINDOW, QUIC_MAX_SEND_BUFFER_SIZE, + QUIC_SOCKET_BUFFER_SIZE, QUIC_STREAM_DATA_WINDOW, }; @@ -41,13 +46,21 @@ pub(crate) fn quic_congestion_controller() -> congestion_controller::Bbr { .build() } +pub(crate) fn quic_io(addr: SocketAddr) -> eyre::Result { + Ok(QuicIoBuilder::default() + .with_receive_address(addr)? + .with_send_buffer_size(QUIC_SOCKET_BUFFER_SIZE)? + .with_recv_buffer_size(QUIC_SOCKET_BUFFER_SIZE)? + .build()?) +} + /// Establishes a QUIC connection to a peer. pub async fn connect_to_peer(addr: SocketAddr) -> eyre::Result { let limits = quic_limits()?.with_max_handshake_duration(Duration::from_secs(3))?; let client = QuicClient::builder() .with_tls(CERT_PEM)? - .with_io("0.0.0.0:0")? + .with_io(quic_io(SocketAddr::from(([0, 0, 0, 0], 0)))?)? .with_limits(limits)? .with_congestion_controller(quic_congestion_controller())? .start()?; diff --git a/crates/lanspread-peer/src/services/server.rs b/crates/lanspread-peer/src/services/server.rs index c9e636d..4a37d68 100644 --- a/crates/lanspread-peer/src/services/server.rs +++ b/crates/lanspread-peer/src/services/server.rs @@ -10,7 +10,7 @@ use crate::{ config::{CERT_PEM, KEY_PEM}, context::PeerCtx, events, - network::{quic_congestion_controller, quic_limits}, + network::{quic_congestion_controller, quic_io, quic_limits}, services::{ advertise::{monitor_mdns_events, start_mdns_advertiser}, stream::handle_peer_stream, @@ -29,7 +29,7 @@ pub async fn run_server_component( let mut server = Server::builder() .with_tls((CERT_PEM, KEY_PEM))? - .with_io(addr)? + .with_io(quic_io(addr)?)? .with_limits(limits)? .with_congestion_controller(quic_congestion_controller())? .start()?;