mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-13 06:20:02 -04:00
WispV2Extensions -> WispV2Handshake and motd helpers
This commit is contained in:
parent
36fddc8943
commit
41f2139eb1
7 changed files with 41 additions and 20 deletions
|
@ -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
|
||||
|
|
|
@ -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<R: WebSocketRead>(
|
||||
rx: &mut R,
|
||||
tx: &LockedWebSocketWrite,
|
||||
v2_info: Option<WispV2Extensions>,
|
||||
v2_info: Option<WispV2Handshake>,
|
||||
) -> 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<R, W>(
|
||||
mut rx: R,
|
||||
tx: W,
|
||||
wisp_v2: Option<WispV2Extensions>,
|
||||
wisp_v2: Option<WispV2Handshake>,
|
||||
) -> Result<MuxResult<ClientMux, impl Future<Output = Result<(), WispError>> + Send>, WispError>
|
||||
where
|
||||
R: WebSocketRead + Send,
|
||||
|
|
|
@ -123,14 +123,19 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
type WispV2ClosureResult = Pin<Box<dyn Future<Output = Result<(), WispError>> + Sync + Send>>;
|
||||
/// Wisp V2 handshake and protocol extension settings wrapper struct.
|
||||
pub struct WispV2Extensions {
|
||||
pub struct WispV2Handshake {
|
||||
builders: Vec<AnyProtocolExtensionBuilder>,
|
||||
closure: Box<dyn Fn(&mut Vec<AnyProtocolExtensionBuilder>) -> WispV2ClosureResult + Send>,
|
||||
#[expect(clippy::type_complexity)]
|
||||
closure: Box<
|
||||
dyn Fn(
|
||||
&mut Vec<AnyProtocolExtensionBuilder>,
|
||||
) -> Pin<Box<dyn Future<Output = Result<(), WispError>> + Sync + Send>>
|
||||
+ Send,
|
||||
>,
|
||||
}
|
||||
|
||||
impl WispV2Extensions {
|
||||
impl WispV2Handshake {
|
||||
/// Create a Wisp V2 settings struct with no middleware.
|
||||
pub fn new(builders: Vec<AnyProtocolExtensionBuilder>) -> Self {
|
||||
Self {
|
||||
|
@ -142,7 +147,11 @@ impl WispV2Extensions {
|
|||
/// Create a Wisp V2 settings struct with some middleware.
|
||||
pub fn new_with_middleware<C>(builders: Vec<AnyProtocolExtensionBuilder>, closure: C) -> Self
|
||||
where
|
||||
C: Fn(&mut Vec<AnyProtocolExtensionBuilder>) -> WispV2ClosureResult + Send + 'static,
|
||||
C: Fn(
|
||||
&mut Vec<AnyProtocolExtensionBuilder>,
|
||||
) -> Pin<Box<dyn Future<Output = Result<(), WispError>> + Sync + Send>>
|
||||
+ Send
|
||||
+ 'static,
|
||||
{
|
||||
Self {
|
||||
builders,
|
||||
|
|
|
@ -19,16 +19,16 @@ use crate::{
|
|||
|
||||
use super::{
|
||||
get_supported_extensions, send_info_packet, Multiplexor, MuxResult, WispHandshakeResult,
|
||||
WispHandshakeResultKind, WispV2Extensions,
|
||||
WispHandshakeResultKind, WispV2Handshake,
|
||||
};
|
||||
|
||||
async fn handshake<R: WebSocketRead>(
|
||||
rx: &mut R,
|
||||
tx: &LockedWebSocketWrite,
|
||||
buffer_size: u32,
|
||||
v2_info: Option<WispV2Extensions>,
|
||||
v2_info: Option<WispV2Handshake>,
|
||||
) -> Result<WispHandshakeResult, WispError> {
|
||||
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<WispV2Extensions>,
|
||||
wisp_v2: Option<WispV2Handshake>,
|
||||
) -> Result<MuxResult<ServerMux, impl Future<Output = Result<(), WispError>> + Send>, WispError>
|
||||
where
|
||||
R: WebSocketRead + Send,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue