1use std::iter::Empty;
2
3use quik_util::*;
4
5use crate::crypto::Crypto;
6use crate::frame::Frame;
7use crate::packet::{Packet, RemainingBuf};
8use crate::server::Handler;
9
10pub trait Io {
11 fn send(&self, data: &[u8]) -> impl Future<Output = Result<()>>;
12 fn recv(&self, data: &mut [u8]) -> impl Future<Output = Result<()>>;
13 fn close(self) -> impl Future<Output = ()>;
14}
15
16pub struct Connection<C: Crypto, I: Io, H: Handler> {
17 crypto: C,
18 io: I,
19 handler: H,
20}
21
22impl<C: Crypto, I: Io, H: Handler> Connection<C, I, H> {
23 pub fn send(&self, data: &[u8]) {
24 }
26
27 pub async fn recv(&self, data: &[u8]) -> Result<()> {
28 let (packet, remainder) = Packet::parse(&self.crypto, data).await?;
29 match remainder {
30 RemainingBuf::Decrypted(data) => {
31 self.handler
32 .handle(packet, Frame::parse_multiple(&data))
33 .await?;
34 }
35 RemainingBuf::None => {
36 self.handler.handle(packet, Empty::default()).await?;
37 }
38 }
39 Ok(())
40 }
41
42 pub fn close(self) {
43 }
45}