use crate::proto::packet_processor::includes::Instant;
use crate::proto::peer::channel::UdpChannel;
use crate::proto::remote::Ticket;
use citadel_crypt::ratchets::Ratchet;
use citadel_io::tokio::sync::oneshot::{channel, Receiver, Sender};
use citadel_wire::hypernode_type::NodeType;
pub struct PreConnectState<R: Ratchet> {
pub(crate) last_stage: u8,
#[allow(dead_code)]
pub(crate) adjacent_node_type: Option<NodeType>,
pub(crate) constructor: Option<R::Constructor>,
pub(crate) ticket: Option<Ticket>,
pub(crate) last_packet_time: Option<Instant>,
pub(crate) udp_channel_oneshot_tx: UdpChannelSender<R>,
pub(crate) success: bool,
pub(crate) generated_ratchet: Option<R>,
}
impl<R: Ratchet> PreConnectState<R> {
pub fn on_packet_received(&mut self) {
self.last_packet_time = Some(Instant::now());
}
}
impl<R: Ratchet> Default for PreConnectState<R> {
fn default() -> Self {
Self {
generated_ratchet: None,
udp_channel_oneshot_tx: UdpChannelSender::empty(),
constructor: None,
last_packet_time: None,
last_stage: 0,
adjacent_node_type: None,
success: false,
ticket: None,
}
}
}
pub struct UdpChannelSender<R: Ratchet> {
pub tx: Option<Sender<UdpChannel<R>>>,
pub rx: Option<Receiver<UdpChannel<R>>>,
}
impl<R: Ratchet> UdpChannelSender<R> {
pub(crate) fn empty() -> Self {
Self { tx: None, rx: None }
}
}
impl<R: Ratchet> Default for UdpChannelSender<R> {
fn default() -> Self {
let (tx, rx) = channel();
Self {
tx: Some(tx),
rx: Some(rx),
}
}
}