feat(client): protocol v2 wire layer, screen sharing, channel webhooks and secure voice

Verified against the real gateway via tests/gateway_interop.rs.
This commit is contained in:
Loki 2026-10-24 16:51:15 +02:00
parent 8460fb28fd
commit 3d7dd5413b
Signed by: boba
GPG key ID: 253067914055423B
65 changed files with 6048 additions and 1156 deletions

View file

@ -1,11 +1,11 @@
use anyhow::{Result, anyhow};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpStream;
use super::payloads::{HDR_SIZE, MAX_PAYLOAD};
pub struct RawPacket {
pub packet_id: u16,
pub sequence: u32,
pub payload: Vec<u8>,
}
@ -37,29 +37,45 @@ pub fn decode_frame(bytes: &[u8]) -> Result<RawPacket> {
return Err(anyhow!("frame too short"));
}
let hdr: [u8; HDR_SIZE] = bytes[..HDR_SIZE].try_into().expect("header length");
let (packet_id, _, _, payload_length) = parse_header(&hdr)?;
let (packet_id, flags, sequence, payload_length) = parse_header(&hdr)?;
if flags != 0 {
return Err(anyhow!("unexpected handshake flags"));
}
let end = HDR_SIZE + payload_length as usize;
if bytes.len() < end {
return Err(anyhow!("truncated frame"));
}
Ok(RawPacket {
packet_id,
sequence,
payload: bytes[HDR_SIZE..end].to_vec(),
})
}
pub async fn read(stream: &mut TcpStream) -> Result<RawPacket> {
pub async fn read(stream: &mut (impl tokio::io::AsyncRead + Unpin)) -> Result<RawPacket> {
let mut buf = [0u8; HDR_SIZE];
stream.read_exact(&mut buf).await?;
let (packet_id, _, _, payload_length) = parse_header(&buf)?;
let (packet_id, flags, sequence, payload_length) = parse_header(&buf)?;
if flags != 0 {
return Err(anyhow!("unexpected handshake flags"));
}
let mut payload = vec![0u8; payload_length as usize];
if !payload.is_empty() {
stream.read_exact(&mut payload).await?;
}
Ok(RawPacket { packet_id, payload })
Ok(RawPacket {
packet_id,
sequence,
payload,
})
}
pub async fn write(stream: &mut TcpStream, id: u16, seq: &mut u32, payload: &[u8]) -> Result<()> {
pub async fn write(
stream: &mut (impl tokio::io::AsyncWrite + Unpin),
id: u16,
seq: &mut u32,
payload: &[u8],
) -> Result<()> {
let frame = encode_frame(id, seq, payload);
stream.write_all(&frame).await?;
Ok(())