#![allow(dead_code)]
use crate::quic::cid::CidPair;
use crate::quic::congestion::NewReno;
use crate::quic::crypto::LevelKeys;
use crate::quic::crypto_buf::CryptoBuf;
use crate::quic::loss::LossState;
use crate::quic::pn::PnSpace;
use crate::tls::quic_hooks::Level;
pub(crate) struct CryptoState {
pub(crate) levels: [LevelKeys; 4],
pub(crate) one_rtt_phase: u8,
}
impl CryptoState {
pub(crate) fn empty() -> Self {
Self {
levels: [
LevelKeys::empty(),
LevelKeys::empty(),
LevelKeys::empty(),
LevelKeys::empty(),
],
one_rtt_phase: 0,
}
}
#[inline]
pub(crate) fn at(&self, l: Level) -> &LevelKeys {
&self.levels[l as usize]
}
#[inline]
pub(crate) fn at_mut(&mut self, l: Level) -> &mut LevelKeys {
&mut self.levels[l as usize]
}
}
pub(crate) struct LevelBufs {
pub(crate) bufs: [CryptoBuf; 4],
}
impl LevelBufs {
pub(crate) fn new() -> Self {
Self {
bufs: [
CryptoBuf::new(),
CryptoBuf::new(),
CryptoBuf::new(),
CryptoBuf::new(),
],
}
}
#[inline]
pub(crate) fn at(&self, l: Level) -> &CryptoBuf {
&self.bufs[l as usize]
}
#[inline]
pub(crate) fn at_mut(&mut self, l: Level) -> &mut CryptoBuf {
&mut self.bufs[l as usize]
}
}
pub(crate) struct PnSpaces {
pub(crate) initial: PnSpace,
pub(crate) handshake: PnSpace,
pub(crate) application: PnSpace,
}
impl PnSpaces {
pub(crate) fn new() -> Self {
Self {
initial: PnSpace::default(),
handshake: PnSpace::default(),
application: PnSpace::default(),
}
}
pub(crate) fn for_level(&mut self, l: Level) -> &mut PnSpace {
match l {
Level::Initial => &mut self.initial,
Level::Handshake => &mut self.handshake,
Level::EarlyData | Level::OneRtt => &mut self.application,
}
}
}
pub(crate) struct Endpoint {
pub(crate) crypto: CryptoState,
pub(crate) bufs: LevelBufs,
pub(crate) pn: PnSpaces,
pub(crate) loss: LossState,
pub(crate) cc: NewReno,
pub(crate) cids: CidPair,
pub(crate) sent_first_datagram: bool,
pub(crate) handshake_complete: bool,
}
impl Endpoint {
pub(crate) fn new(cids: CidPair) -> Self {
Self {
crypto: CryptoState::empty(),
bufs: LevelBufs::new(),
pn: PnSpaces::new(),
loss: LossState::new(),
cc: NewReno::new(),
cids,
sent_first_datagram: false,
handshake_complete: false,
}
}
}