-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Factor out packet logging (#2396)
* chore: Factor out packet logging Because `output_path` and `input_path` are getting long, and there is a lot of redundancy between the calls to `dump` and `qlog`. * tos * Minimize diff * Minimize more * More * Less * Fix len and tos * clippy * TODO * Update neqo-transport/src/connection/mod.rs Co-authored-by: Martin Thomson <mt@lowentropy.net> Signed-off-by: Lars Eggert <lars@eggert.org> --------- Signed-off-by: Lars Eggert <lars@eggert.org> Co-authored-by: Martin Thomson <mt@lowentropy.net>
- Loading branch information
1 parent
379722c
commit 59ba66c
Showing
5 changed files
with
189 additions
and
156 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Enable just this file for logging to just see packets. | ||
// e.g. "RUST_LOG=neqo_transport::dump neqo-client ..." | ||
|
||
use std::fmt::Display; | ||
|
||
use neqo_common::IpTos; | ||
use qlog::events::quic::PacketHeader; | ||
|
||
use super::DecryptedPacket; | ||
use crate::{ | ||
packet::{PacketNumber, PacketType}, | ||
path::PathRef, | ||
}; | ||
|
||
#[derive(Clone, Copy)] | ||
pub enum Direction { | ||
Tx, | ||
Rx, | ||
} | ||
|
||
impl Display for Direction { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::Tx => write!(f, "TX ->"), | ||
Self::Rx => write!(f, "-> RX"), | ||
} | ||
} | ||
} | ||
|
||
pub struct MetaData<'a> { | ||
path: &'a PathRef, | ||
direction: Direction, | ||
packet_type: PacketType, | ||
packet_number: PacketNumber, | ||
tos: IpTos, | ||
len: usize, | ||
payload: &'a [u8], | ||
} | ||
|
||
impl MetaData<'_> { | ||
pub fn new_in<'a>( | ||
path: &'a PathRef, | ||
tos: IpTos, | ||
len: usize, | ||
decrypted: &'a DecryptedPacket, | ||
) -> MetaData<'a> { | ||
MetaData { | ||
path, | ||
direction: Direction::Rx, | ||
packet_type: decrypted.packet_type(), | ||
packet_number: decrypted.pn(), | ||
tos, | ||
len, | ||
payload: decrypted, | ||
} | ||
} | ||
|
||
pub fn new_out<'a>( | ||
path: &'a PathRef, | ||
packet_type: PacketType, | ||
packet_number: PacketNumber, | ||
length: usize, | ||
payload: &'a [u8], | ||
) -> MetaData<'a> { | ||
MetaData { | ||
path, | ||
direction: Direction::Tx, | ||
packet_type, | ||
packet_number, | ||
tos: path.borrow().tos(), | ||
len: length, | ||
payload, | ||
} | ||
} | ||
|
||
#[must_use] | ||
pub const fn direction(&self) -> Direction { | ||
self.direction | ||
} | ||
|
||
#[must_use] | ||
pub const fn length(&self) -> usize { | ||
self.len | ||
} | ||
|
||
#[must_use] | ||
pub const fn payload(&self) -> &[u8] { | ||
self.payload | ||
} | ||
} | ||
|
||
impl From<MetaData<'_>> for PacketHeader { | ||
fn from(val: MetaData<'_>) -> Self { | ||
Self::with_type( | ||
val.packet_type.into(), | ||
Some(val.packet_number), | ||
None, | ||
None, | ||
None, | ||
) | ||
} | ||
} | ||
|
||
impl Display for MetaData<'_> { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!( | ||
f, | ||
"pn={} type={:?} {} {:?} len {}", | ||
self.packet_number, | ||
self.packet_type, | ||
self.path.borrow(), | ||
self.tos, | ||
self.len, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.