diff --git a/client/src/stream_provider.rs b/client/src/stream_provider.rs index abc7131..aefb4eb 100644 --- a/client/src/stream_provider.rs +++ b/client/src/stream_provider.rs @@ -17,7 +17,7 @@ use webpki_roots::TLS_SERVER_ROOTS; use wisp_mux::{ extensions::{udp::UdpProtocolExtensionBuilder, AnyProtocolExtensionBuilder}, ws::{WebSocketRead, WebSocketWrite}, - ClientMux, MuxStreamAsyncRW, MuxStreamIo, StreamType, WispV2Extensions, + ClientMux, MuxStreamAsyncRW, MuxStreamIo, StreamType, WispV2Handshake, }; use crate::{ @@ -119,7 +119,7 @@ impl StreamProvider { UdpProtocolExtensionBuilder, )]; let extensions = if self.wisp_v2 { - Some(WispV2Extensions::new(extensions_vec)) + Some(WispV2Handshake::new(extensions_vec)) } else { None }; diff --git a/server/src/config.rs b/server/src/config.rs index 50c705f..de6e02b 100644 --- a/server/src/config.rs +++ b/server/src/config.rs @@ -14,7 +14,7 @@ use wisp_mux::{ udp::UdpProtocolExtensionBuilder, AnyProtocolExtensionBuilder, }, - WispV2Extensions, + WispV2Handshake, }; use crate::{handle::wisp::utils::get_certificates_from_paths, CLI, CONFIG, RESOLVER}; @@ -346,7 +346,7 @@ impl Default for WispConfig { } impl WispConfig { - pub async fn to_opts(&self) -> anyhow::Result<(Option, Vec, u32)> { + pub async fn to_opts(&self) -> anyhow::Result<(Option, Vec, u32)> { if self.wisp_v2 { let mut extensions: Vec = Vec::new(); let mut required_extensions: Vec = Vec::new(); @@ -391,7 +391,7 @@ impl WispConfig { } Ok(( - Some(WispV2Extensions::new(extensions)), + Some(WispV2Handshake::new(extensions)), required_extensions, self.buffer_size, )) diff --git a/simple-wisp-client/src/main.rs b/simple-wisp-client/src/main.rs index 8d52f74..c03f86f 100644 --- a/simple-wisp-client/src/main.rs +++ b/simple-wisp-client/src/main.rs @@ -38,7 +38,7 @@ use wisp_mux::{ udp::{UdpProtocolExtension, UdpProtocolExtensionBuilder}, AnyProtocolExtensionBuilder, }, - ClientMux, StreamType, WispError, WispV2Extensions, + ClientMux, StreamType, WispError, WispV2Handshake, }; #[derive(Debug)] @@ -198,7 +198,7 @@ async fn main() -> Result<(), Box> { .await? .with_no_required_extensions() } else { - ClientMux::create(rx, tx, Some(WispV2Extensions::new(extensions))) + ClientMux::create(rx, tx, Some(WispV2Handshake::new(extensions))) .await? .with_required_extensions(extension_ids.as_slice()) .await? diff --git a/wisp/src/extensions/motd.rs b/wisp/src/extensions/motd.rs index 2c1c17a..d93349c 100644 --- a/wisp/src/extensions/motd.rs +++ b/wisp/src/extensions/motd.rs @@ -76,6 +76,18 @@ pub enum MotdProtocolExtensionBuilder { Client, } +impl MotdProtocolExtensionBuilder { + /// Create a new server variant of the MOTD protocol extension builder. + pub fn new_server(motd: String) -> Self { + Self::Server(motd) + } + + /// Create a new client variant of the MOTD protocol extension builder. + pub fn new_client() -> Self { + Self::Client + } +} + impl ProtocolExtensionBuilder for MotdProtocolExtensionBuilder { fn get_id(&self) -> u8 { MotdProtocolExtension::ID diff --git a/wisp/src/mux/client.rs b/wisp/src/mux/client.rs index e2f44b0..5b44766 100644 --- a/wisp/src/mux/client.rs +++ b/wisp/src/mux/client.rs @@ -20,15 +20,15 @@ use crate::{ use super::{ get_supported_extensions, validate_continue_packet, Multiplexor, MuxResult, - WispHandshakeResult, WispHandshakeResultKind, WispV2Extensions, + WispHandshakeResult, WispHandshakeResultKind, WispV2Handshake, }; async fn handshake( rx: &mut R, tx: &LockedWebSocketWrite, - v2_info: Option, + v2_info: Option, ) -> Result<(WispHandshakeResult, u32), WispError> { - if let Some(WispV2Extensions { + if let Some(WispV2Handshake { mut builders, closure, }) = v2_info @@ -100,7 +100,7 @@ impl ClientMux { pub async fn create( mut rx: R, tx: W, - wisp_v2: Option, + wisp_v2: Option, ) -> Result> + Send>, WispError> where R: WebSocketRead + Send, diff --git a/wisp/src/mux/mod.rs b/wisp/src/mux/mod.rs index 9166a89..18624f0 100644 --- a/wisp/src/mux/mod.rs +++ b/wisp/src/mux/mod.rs @@ -123,14 +123,19 @@ where } } -type WispV2ClosureResult = Pin> + Sync + Send>>; /// Wisp V2 handshake and protocol extension settings wrapper struct. -pub struct WispV2Extensions { +pub struct WispV2Handshake { builders: Vec, - closure: Box) -> WispV2ClosureResult + Send>, + #[expect(clippy::type_complexity)] + closure: Box< + dyn Fn( + &mut Vec, + ) -> Pin> + Sync + Send>> + + Send, + >, } -impl WispV2Extensions { +impl WispV2Handshake { /// Create a Wisp V2 settings struct with no middleware. pub fn new(builders: Vec) -> Self { Self { @@ -142,7 +147,11 @@ impl WispV2Extensions { /// Create a Wisp V2 settings struct with some middleware. pub fn new_with_middleware(builders: Vec, closure: C) -> Self where - C: Fn(&mut Vec) -> WispV2ClosureResult + Send + 'static, + C: Fn( + &mut Vec, + ) -> Pin> + Sync + Send>> + + Send + + 'static, { Self { builders, diff --git a/wisp/src/mux/server.rs b/wisp/src/mux/server.rs index a60f409..edca6a4 100644 --- a/wisp/src/mux/server.rs +++ b/wisp/src/mux/server.rs @@ -19,16 +19,16 @@ use crate::{ use super::{ get_supported_extensions, send_info_packet, Multiplexor, MuxResult, WispHandshakeResult, - WispHandshakeResultKind, WispV2Extensions, + WispHandshakeResultKind, WispV2Handshake, }; async fn handshake( rx: &mut R, tx: &LockedWebSocketWrite, buffer_size: u32, - v2_info: Option, + v2_info: Option, ) -> Result { - if let Some(WispV2Extensions { + if let Some(WispV2Handshake { mut builders, closure, }) = v2_info @@ -95,7 +95,7 @@ impl ServerMux { mut rx: R, tx: W, buffer_size: u32, - wisp_v2: Option, + wisp_v2: Option, ) -> Result> + Send>, WispError> where R: WebSocketRead + Send,