implement Debug
for all structs
This commit is contained in:
parent
640ae7d2fd
commit
6c3e72b56a
@ -1,5 +1,6 @@
|
||||
use super::side::{self, Side};
|
||||
use crate::protocol::{Authenticate as AuthenticateHeader, Header};
|
||||
use std::fmt::{Debug, Formatter, Result as FmtResult};
|
||||
use uuid::Uuid;
|
||||
|
||||
/// The model of the `Authenticate` command
|
||||
@ -36,6 +37,15 @@ impl Authenticate<side::Tx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Authenticate<side::Tx> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
let Side::Tx(tx) = &self.inner else { unreachable!() };
|
||||
f.debug_struct("Authenticate")
|
||||
.field("header", &tx.header)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
struct Rx {
|
||||
uuid: Uuid,
|
||||
token: [u8; 32],
|
||||
@ -72,6 +82,16 @@ impl Authenticate<side::Rx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Authenticate<side::Rx> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
let Side::Rx(rx) = &self.inner else { unreachable!() };
|
||||
f.debug_struct("Authenticate")
|
||||
.field("uuid", &rx.uuid)
|
||||
.field("token", &rx.token)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
/// The trait for exporting keying material
|
||||
pub trait KeyingMaterialExporter {
|
||||
/// Exports keying material
|
||||
|
@ -1,6 +1,7 @@
|
||||
use super::side::{self, Side};
|
||||
use crate::protocol::{Address, Connect as ConnectHeader, Header};
|
||||
use register_count::Register;
|
||||
use std::fmt::{Debug, Formatter, Result as FmtResult};
|
||||
|
||||
/// The model of the `Connect` command
|
||||
pub struct Connect<M> {
|
||||
@ -31,6 +32,15 @@ impl Connect<side::Tx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Connect<side::Tx> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
let Side::Tx(tx) = &self.inner else { unreachable!() };
|
||||
f.debug_struct("Connect")
|
||||
.field("header", &tx.header)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
struct Rx {
|
||||
addr: Address,
|
||||
_task_reg: Register,
|
||||
@ -53,3 +63,10 @@ impl Connect<side::Rx> {
|
||||
&rx.addr
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Connect<side::Rx> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
let Side::Rx(rx) = &self.inner else { unreachable!() };
|
||||
f.debug_struct("Connect").field("addr", &rx.addr).finish()
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use super::side::{self, Side};
|
||||
use crate::protocol::{Dissociate as DissociateHeader, Header};
|
||||
use std::fmt::{Debug, Formatter, Result as FmtResult};
|
||||
|
||||
/// The model of the `Dissociate` command
|
||||
pub struct Dissociate<M> {
|
||||
@ -28,6 +29,15 @@ impl Dissociate<side::Tx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Dissociate<side::Tx> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
let Side::Tx(tx) = &self.inner else { unreachable!() };
|
||||
f.debug_struct("Dissociate")
|
||||
.field("header", &tx.header)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
struct Rx {
|
||||
assoc_id: u16,
|
||||
}
|
||||
@ -46,3 +56,12 @@ impl Dissociate<side::Rx> {
|
||||
rx.assoc_id
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Dissociate<side::Rx> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
let Side::Rx(rx) = &self.inner else { unreachable!() };
|
||||
f.debug_struct("Dissociate")
|
||||
.field("assoc_id", &rx.assoc_id)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
use super::side::{self, Side};
|
||||
use crate::protocol::{Header, Heartbeat as HeartbeatHeader};
|
||||
use std::fmt::{Debug, Formatter, Result as FmtResult};
|
||||
|
||||
pub struct Heartbeat<M> {
|
||||
inner: Side<Tx, Rx>,
|
||||
@ -27,6 +28,15 @@ impl Heartbeat<side::Tx> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Heartbeat<side::Tx> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
let Side::Tx(tx) = &self.inner else { unreachable!() };
|
||||
f.debug_struct("Heartbeat")
|
||||
.field("header", &tx.header)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
struct Rx;
|
||||
|
||||
impl Heartbeat<side::Rx> {
|
||||
@ -37,3 +47,9 @@ impl Heartbeat<side::Rx> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Heartbeat<side::Rx> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
f.debug_struct("Heartbeat").finish()
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ use parking_lot::Mutex;
|
||||
use register_count::{Counter, Register};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fmt::{Debug, Formatter, Result as FmtResult},
|
||||
mem,
|
||||
sync::{
|
||||
atomic::{AtomicU16, Ordering},
|
||||
@ -33,6 +34,7 @@ pub use self::{
|
||||
};
|
||||
|
||||
/// An abstraction of a TUIC connection, with packet fragmentation management and task counters. No I/O operation is involved internally
|
||||
#[derive(Clone)]
|
||||
pub struct Connection<B> {
|
||||
udp_sessions: Arc<Mutex<UdpSessions<B>>>,
|
||||
task_connect_count: Counter,
|
||||
@ -160,6 +162,19 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> Debug for Connection<B>
|
||||
where
|
||||
B: AsRef<[u8]> + Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
f.debug_struct("Connection")
|
||||
.field("udp_sessions", &self.udp_sessions)
|
||||
.field("task_connect_count", &self.task_connect_count())
|
||||
.field("task_associate_count", &self.task_associate_count())
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
/// Abstracts the side of a task
|
||||
pub mod side {
|
||||
/// The side of a task that sends data
|
||||
@ -268,6 +283,17 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> Debug for UdpSessions<B>
|
||||
where
|
||||
B: AsRef<[u8]> + Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
f.debug_struct("UdpSessions")
|
||||
.field("sessions", &self.sessions)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
struct UdpSession<B> {
|
||||
pkt_buf: HashMap<u16, PacketBuffer<B>>,
|
||||
next_pkt_id: AtomicU16,
|
||||
@ -343,6 +369,19 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> Debug for UdpSession<B>
|
||||
where
|
||||
B: AsRef<[u8]> + Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
f.debug_struct("UdpSession")
|
||||
.field("pkt_buf", &self.pkt_buf)
|
||||
.field("next_pkt_id", &self.next_pkt_id)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct PacketBuffer<B> {
|
||||
buf: Vec<Option<B>>,
|
||||
frag_total: u8,
|
||||
@ -419,6 +458,7 @@ where
|
||||
}
|
||||
|
||||
/// A complete packet that can be assembled
|
||||
#[derive(Debug)]
|
||||
pub struct Assemblable<B> {
|
||||
buf: Vec<Option<B>>,
|
||||
addr: Address,
|
||||
|
@ -4,7 +4,12 @@ use super::{
|
||||
};
|
||||
use crate::protocol::{Address, Header, Packet as PacketHeader};
|
||||
use parking_lot::Mutex;
|
||||
use std::{marker::PhantomData, slice, sync::Arc};
|
||||
use std::{
|
||||
fmt::{Debug, Formatter, Result as FmtResult},
|
||||
marker::PhantomData,
|
||||
slice,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
pub struct Packet<M, B> {
|
||||
inner: Side<Tx, Rx<B>>,
|
||||
@ -53,6 +58,18 @@ impl<B> Packet<side::Tx, B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Packet<side::Tx, ()> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
let Side::Tx(tx) = &self.inner else { unreachable!() };
|
||||
f.debug_struct("Packet")
|
||||
.field("assoc_id", &tx.assoc_id)
|
||||
.field("pkt_id", &tx.pkt_id)
|
||||
.field("addr", &tx.addr)
|
||||
.field("max_pkt_size", &tx.max_pkt_size)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
struct Rx<B> {
|
||||
sessions: Arc<Mutex<UdpSessions<B>>>,
|
||||
assoc_id: u16,
|
||||
@ -90,6 +107,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
/// Reassembles the packet. If the packet is not complete yet, `None` is returned.
|
||||
pub fn assemble(self, data: B) -> Result<Option<Assemblable<B>>, AssembleError> {
|
||||
let Side::Rx(rx) = self.inner else { unreachable!() };
|
||||
let mut sessions = rx.sessions.lock();
|
||||
@ -105,23 +123,41 @@ where
|
||||
)
|
||||
}
|
||||
|
||||
/// Returns the UDP session ID
|
||||
pub fn assoc_id(&self) -> u16 {
|
||||
let Side::Rx(rx) = &self.inner else { unreachable!() };
|
||||
rx.assoc_id
|
||||
}
|
||||
|
||||
/// Returns the address
|
||||
pub fn addr(&self) -> &Address {
|
||||
let Side::Rx(rx) = &self.inner else { unreachable!() };
|
||||
&rx.addr
|
||||
}
|
||||
|
||||
/// Returns the size of the (fragmented) packet
|
||||
pub fn size(&self) -> u16 {
|
||||
let Side::Rx(rx) = &self.inner else { unreachable!() };
|
||||
rx.size
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> Debug for Packet<side::Rx, B> {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
let Side::Rx(rx) = &self.inner else { unreachable!() };
|
||||
f.debug_struct("Packet")
|
||||
.field("assoc_id", &rx.assoc_id)
|
||||
.field("pkt_id", &rx.pkt_id)
|
||||
.field("frag_total", &rx.frag_total)
|
||||
.field("frag_id", &rx.frag_id)
|
||||
.field("size", &rx.size)
|
||||
.field("addr", &rx.addr)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
/// Iterator over fragments of a packet
|
||||
#[derive(Debug)]
|
||||
pub struct Fragments<'a, P>
|
||||
where
|
||||
P: 'a,
|
||||
|
Loading…
x
Reference in New Issue
Block a user