mirror of
https://github.com/MercuryWorkshop/epoxy-tls.git
synced 2025-05-13 14:30:02 -04:00
serverside done except it deadlocks
This commit is contained in:
parent
1f23c26db6
commit
24d145cc66
8 changed files with 176 additions and 24 deletions
40
wisp/src/fastwebsockets.rs
Normal file
40
wisp/src/fastwebsockets.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
use bytes::Bytes;
|
||||
use fastwebsockets::{Payload, Frame, OpCode};
|
||||
|
||||
impl TryFrom<OpCode> for crate::ws::OpCode {
|
||||
type Error = crate::WispError;
|
||||
fn try_from(opcode: OpCode) -> Result<Self, Self::Error> {
|
||||
use OpCode::*;
|
||||
match opcode {
|
||||
Continuation => Err(Self::Error::WsImplNotSupported),
|
||||
Text => Ok(Self::Text),
|
||||
Binary => Ok(Self::Binary),
|
||||
Close => Ok(Self::Close),
|
||||
Ping => Err(Self::Error::WsImplNotSupported),
|
||||
Pong => Err(Self::Error::WsImplNotSupported),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Frame<'_>> for crate::ws::Frame {
|
||||
type Error = crate::WispError;
|
||||
fn try_from(mut frame: Frame) -> Result<Self, Self::Error> {
|
||||
let opcode = frame.opcode.try_into()?;
|
||||
Ok(Self {
|
||||
finished: frame.fin,
|
||||
opcode,
|
||||
payload: Bytes::copy_from_slice(frame.payload.to_mut()),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crate::ws::Frame> for Frame<'_> {
|
||||
fn from(frame: crate::ws::Frame) -> Self {
|
||||
use crate::ws::OpCode::*;
|
||||
match frame.opcode {
|
||||
Text => Self::text(Payload::Owned(frame.payload.to_vec())),
|
||||
Binary => Self::binary(Payload::Owned(frame.payload.to_vec())),
|
||||
Close => Self::close_raw(Payload::Owned(frame.payload.to_vec()))
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
#[cfg(feature = "fastwebsockets")]
|
||||
mod fastwebsockets;
|
||||
mod packet;
|
||||
pub mod ws;
|
||||
|
||||
|
@ -9,12 +11,14 @@ pub enum Role {
|
|||
Server,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum WispError {
|
||||
PacketTooSmall,
|
||||
InvalidPacketType,
|
||||
WsFrameInvalidType,
|
||||
WsFrameNotFinished,
|
||||
WsImplError(Box<dyn std::error::Error>),
|
||||
WsImplNotSupported,
|
||||
Utf8Error(std::str::Utf8Error),
|
||||
}
|
||||
|
||||
|
@ -23,3 +27,20 @@ impl From<std::str::Utf8Error> for WispError {
|
|||
WispError::Utf8Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for WispError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
use WispError::*;
|
||||
match self {
|
||||
PacketTooSmall => write!(f, "Packet too small"),
|
||||
InvalidPacketType => write!(f, "Invalid packet type"),
|
||||
WsFrameInvalidType => write!(f, "Invalid websocket frame type"),
|
||||
WsFrameNotFinished => write!(f, "Unfinished websocket frame"),
|
||||
WsImplError(err) => write!(f, "Websocket implementation error: {:?}", err),
|
||||
WsImplNotSupported => write!(f, "Websocket implementation error: unsupported feature"),
|
||||
Utf8Error(err) => write!(f, "UTF-8 error: {:?}", err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for WispError {}
|
||||
|
|
|
@ -4,9 +4,9 @@ use bytes::{Buf, BufMut, Bytes};
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct ConnectPacket {
|
||||
stream_type: u8,
|
||||
destination_port: u16,
|
||||
destination_hostname: String,
|
||||
pub stream_type: u8,
|
||||
pub destination_port: u16,
|
||||
pub destination_hostname: String,
|
||||
}
|
||||
|
||||
impl ConnectPacket {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue