add wisp v1 flag

This commit is contained in:
Toshit Chawda 2024-05-27 17:08:21 -07:00
parent 50bfa47bc2
commit 273063ec28
No known key found for this signature in database
GPG key ID: 91480ED99E2B3D9D

View file

@ -68,6 +68,9 @@ struct Cli {
/// `user` cannot contain `:`. Whitespace will be trimmed. /// `user` cannot contain `:`. Whitespace will be trimmed.
#[arg(long)] #[arg(long)]
auth: Option<PathBuf>, auth: Option<PathBuf>,
/// Use Wisp V1.
#[arg(long)]
wisp_v1: bool,
} }
#[derive(Clone)] #[derive(Clone)]
@ -77,6 +80,7 @@ struct MuxOptions {
pub block_non_http: bool, pub block_non_http: bool,
pub enforce_auth: bool, pub enforce_auth: bool,
pub auth: Arc<Vec<Box<(dyn ProtocolExtensionBuilder + Send + Sync)>>>, pub auth: Arc<Vec<Box<(dyn ProtocolExtensionBuilder + Send + Sync)>>>,
pub wisp_v1: bool,
} }
#[cfg(not(unix))] #[cfg(not(unix))]
@ -191,6 +195,7 @@ async fn main() -> Result<(), Error> {
Box::new(pw_ext), Box::new(pw_ext),
]), ]),
enforce_auth, enforce_auth,
wisp_v1: opt.wisp_v1,
}; };
println!("listening on `{}` with prefix `{}`", addr, prefix); println!("listening on `{}` with prefix `{}`", addr, prefix);
@ -316,7 +321,11 @@ async fn accept_ws(
println!("{:?}: connected", addr); println!("{:?}: connected", addr);
// to prevent memory ""leaks"" because users are sending in packets way too fast the buffer // to prevent memory ""leaks"" because users are sending in packets way too fast the buffer
// size is set to 512 // size is set to 512
let (mux, fut) = if mux_options.enforce_auth { let (mux, fut) = if mux_options.wisp_v1 {
ServerMux::create(rx, tx, 512, None)
.await?
.with_no_required_extensions()
} else if mux_options.enforce_auth {
ServerMux::create(rx, tx, 512, Some(mux_options.auth.as_slice())) ServerMux::create(rx, tx, 512, Some(mux_options.auth.as_slice()))
.await? .await?
.with_required_extensions(&[PasswordProtocolExtension::ID]) .with_required_extensions(&[PasswordProtocolExtension::ID])