diff --git a/tuic-client/README.md b/tuic-client/README.md index 1b69c74..ddb7629 100644 --- a/tuic-client/README.md +++ b/tuic-client/README.md @@ -87,6 +87,16 @@ tuic-client -c PATH/TO/CONFIG // Default: false "disable_native_certs": false, + // Optional. Maximum number of bytes to transmit to a peer without acknowledgment + // Should be set to at least the expected connection latency multiplied by the maximum desired throughput + // Default: 16MiB * 2 + "send_window": 33554432, + + // Optional. Maximum number of bytes the peer may transmit without acknowledgement on any one stream before becoming blocked + // Should be set to at least the expected connection latency multiplied by the maximum desired throughput + // Default: 16MiB + "receive_window": 16777216, + // Optional. Interval between UDP packet fragment garbage collection // Default: 3s "gc_interval": "3s", diff --git a/tuic-client/src/config.rs b/tuic-client/src/config.rs index 98879a1..81f38d5 100644 --- a/tuic-client/src/config.rs +++ b/tuic-client/src/config.rs @@ -88,6 +88,12 @@ pub struct Relay { #[serde(default = "default::relay::disable_native_certs")] pub disable_native_certs: bool, + #[serde(default = "default::relay::send_window")] + pub send_window: u64, + + #[serde(default = "default::relay::receive_window")] + pub receive_window: u32, + #[serde( default = "default::relay::gc_interval", deserialize_with = "deserialize_duration" @@ -190,6 +196,14 @@ mod default { false } + pub fn send_window() -> u64 { + 2u64.pow(24) * 2 + } + + pub fn receive_window() -> u32 { + 2u32.pow(24) + } + pub fn gc_interval() -> Duration { Duration::from_secs(3) } diff --git a/tuic-client/src/connection.rs b/tuic-client/src/connection.rs index 5307cc2..de19db5 100644 --- a/tuic-client/src/connection.rs +++ b/tuic-client/src/connection.rs @@ -72,6 +72,8 @@ impl Endpoint { tp_cfg .max_concurrent_bidi_streams(VarInt::from(DEFAULT_CONCURRENT_STREAMS as u32)) .max_concurrent_uni_streams(VarInt::from(DEFAULT_CONCURRENT_STREAMS as u32)) + .send_window(cfg.send_window) + .stream_receive_window(VarInt::from_u32(cfg.receive_window)) .max_idle_timeout(None); match cfg.congestion_control { diff --git a/tuic-server/README.md b/tuic-server/README.md index 2e25ddf..2da0a2f 100644 --- a/tuic-server/README.md +++ b/tuic-server/README.md @@ -54,7 +54,7 @@ tuic-server -c PATH/TO/CONFIG "udp_relay_ipv6": true, // Optional. Enable 0-RTT QUIC connection handshake on the server side - // This is not impacting much on the performance, as the protocol is fully multiplexed + // This is not impacting much on the performance, as the protocol is fully multiplexed // WARNING: Disabling this is highly recommended, as it is vulnerable to replay attacks. See https://blog.cloudflare.com/even-faster-connection-establishment-with-quic-0-rtt-resumption/#attack-of-the-clones // Default: false "zero_rtt_handshake": false, @@ -79,6 +79,16 @@ tuic-server -c PATH/TO/CONFIG // Default: 1500 "max_external_packet_size": 1500, + // Optional. Maximum number of bytes to transmit to a peer without acknowledgment + // Should be set to at least the expected connection latency multiplied by the maximum desired throughput + // Default: 16MiB * 2 + "send_window": 33554432, + + // Optional. Maximum number of bytes the peer may transmit without acknowledgement on any one stream before becoming blocked + // Should be set to at least the expected connection latency multiplied by the maximum desired throughput + // Default: 16MiB + "receive_window": 16777216, + // Optional. Interval between UDP packet fragment garbage collection // Default: 3s "gc_interval": "3s", diff --git a/tuic-server/src/config.rs b/tuic-server/src/config.rs index 4ad7d13..eceee6b 100644 --- a/tuic-server/src/config.rs +++ b/tuic-server/src/config.rs @@ -70,6 +70,12 @@ pub struct Config { #[serde(default = "default::max_external_packet_size")] pub max_external_packet_size: usize, + #[serde(default = "default::send_window")] + pub send_window: u64, + + #[serde(default = "default::receive_window")] + pub receive_window: u32, + #[serde( default = "default::gc_interval", deserialize_with = "deserialize_duration" @@ -154,6 +160,14 @@ mod default { 1500 } + pub fn send_window() -> u64 { + 2u64.pow(24) * 2 + } + + pub fn receive_window() -> u32 { + 2u32.pow(24) + } + pub fn gc_interval() -> Duration { Duration::from_secs(3) } diff --git a/tuic-server/src/server.rs b/tuic-server/src/server.rs index 686a76a..486359a 100644 --- a/tuic-server/src/server.rs +++ b/tuic-server/src/server.rs @@ -78,6 +78,8 @@ impl Server { tp_cfg .max_concurrent_bidi_streams(VarInt::from(DEFAULT_CONCURRENT_STREAMS as u32)) .max_concurrent_uni_streams(VarInt::from(DEFAULT_CONCURRENT_STREAMS as u32)) + .send_window(cfg.send_window) + .stream_receive_window(VarInt::from_u32(cfg.receive_window)) .max_idle_timeout(Some( IdleTimeout::try_from(cfg.max_idle_time).map_err(|_| Error::InvalidMaxIdleTime)?, ));