From ce2660943a6ad7f49dc3a8789f66dc411966b0b3 Mon Sep 17 00:00:00 2001 From: Toshit Chawda Date: Sat, 27 Apr 2024 17:44:00 -0700 Subject: [PATCH] decrease max ws message size, increase flow control buffer --- server/src/main.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/server/src/main.rs b/server/src/main.rs index 68b3da9..6e5803e 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -306,27 +306,34 @@ async fn accept_ws( addr: String, mux_options: MuxOptions, ) -> Result<(), Box> { - let (rx, tx) = ws.await?.split(tokio::io::split); + let mut ws = ws.await?; + // to prevent memory ""leaks"" because users are sending in packets way too fast the message + // size is set to 1M + ws.set_max_message_size(1024 * 1024); + let (rx, tx) = ws.split(tokio::io::split); let rx = FragmentCollectorRead::new(rx); println!("{:?}: connected", addr); // to prevent memory ""leaks"" because users are sending in packets way too fast the buffer - // size is set to 128 + // size is set to 512 let (mux, fut) = if mux_options.enforce_auth { - ServerMux::create(rx, tx, 128, Some(mux_options.auth.as_slice())) + ServerMux::create(rx, tx, 512, Some(mux_options.auth.as_slice())) + .await? + .with_required_extensions(&[PasswordProtocolExtension::ID]) .await? - .with_required_extensions(&[PasswordProtocolExtension::ID]).await? } else { ServerMux::create( rx, tx, - 128, + 512, Some(&[Box::new(UdpProtocolExtensionBuilder())]), ) .await? .with_no_required_extensions() }; + // this results in one stream ""leaking"" a maximum of ~512M + println!( "{:?}: downgraded: {} extensions supported: {:?}", addr, mux.downgraded, mux.supported_extension_ids