-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Extend
Frame::Padding
with length (#1762)
* feat: Extend `Frame::Padding` with a `length` field This is preparation of qlog supporting the logging of runs of padding frames via `payload_length`, instead of each one individually. * Use `dv` more * Fix test * Address code review * Add TODO
- Loading branch information
1 parent
e2f9369
commit 56f53bb
Showing
6 changed files
with
219 additions
and
222 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -20,7 +20,7 @@ use crate::{ | |
#[allow(clippy::module_name_repetitions)] | ||
pub type FrameType = u64; | ||
|
||
const FRAME_TYPE_PADDING: FrameType = 0x0; | ||
pub const FRAME_TYPE_PADDING: FrameType = 0x0; | ||
pub const FRAME_TYPE_PING: FrameType = 0x1; | ||
pub const FRAME_TYPE_ACK: FrameType = 0x2; | ||
const FRAME_TYPE_ACK_ECN: FrameType = 0x3; | ||
|
@@ -103,7 +103,7 @@ pub struct AckRange { | |
|
||
#[derive(PartialEq, Eq, Debug, Clone)] | ||
pub enum Frame<'a> { | ||
Padding, | ||
Padding(u16), | ||
Ping, | ||
Ack { | ||
largest_acknowledged: u64, | ||
|
@@ -215,7 +215,7 @@ impl<'a> Frame<'a> { | |
|
||
pub fn get_type(&self) -> FrameType { | ||
match self { | ||
Self::Padding => FRAME_TYPE_PADDING, | ||
Self::Padding { .. } => FRAME_TYPE_PADDING, | ||
Self::Ping => FRAME_TYPE_PING, | ||
Self::Ack { .. } => FRAME_TYPE_ACK, // We don't do ACK ECN. | ||
Self::ResetStream { .. } => FRAME_TYPE_RESET_STREAM, | ||
|
@@ -288,7 +288,7 @@ impl<'a> Frame<'a> { | |
pub fn ack_eliciting(&self) -> bool { | ||
!matches!( | ||
self, | ||
Self::Ack { .. } | Self::Padding | Self::ConnectionClose { .. } | ||
Self::Ack { .. } | Self::Padding { .. } | Self::ConnectionClose { .. } | ||
) | ||
} | ||
|
||
|
@@ -297,7 +297,7 @@ impl<'a> Frame<'a> { | |
pub fn path_probing(&self) -> bool { | ||
matches!( | ||
self, | ||
Self::Padding | ||
Self::Padding { .. } | ||
| Self::NewConnectionId { .. } | ||
| Self::PathChallenge { .. } | ||
| Self::PathResponse { .. } | ||
|
@@ -347,36 +347,34 @@ impl<'a> Frame<'a> { | |
Ok(acked_ranges) | ||
} | ||
|
||
pub fn dump(&self) -> Option<String> { | ||
pub fn dump(&self) -> String { | ||
match self { | ||
Self::Crypto { offset, data } => Some(format!( | ||
"Crypto {{ offset: {}, len: {} }}", | ||
offset, | ||
data.len() | ||
)), | ||
Self::Crypto { offset, data } => { | ||
format!("Crypto {{ offset: {}, len: {} }}", offset, data.len()) | ||
} | ||
Self::Stream { | ||
stream_id, | ||
offset, | ||
fill, | ||
data, | ||
fin, | ||
} => Some(format!( | ||
} => format!( | ||
"Stream {{ stream_id: {}, offset: {}, len: {}{}, fin: {} }}", | ||
stream_id.as_u64(), | ||
offset, | ||
if *fill { ">>" } else { "" }, | ||
data.len(), | ||
fin, | ||
)), | ||
Self::Padding => None, | ||
Self::Datagram { data, .. } => Some(format!("Datagram {{ len: {} }}", data.len())), | ||
_ => Some(format!("{self:?}")), | ||
), | ||
Self::Padding(length) => format!("Padding {{ len: {length} }}"), | ||
Self::Datagram { data, .. } => format!("Datagram {{ len: {} }}", data.len()), | ||
_ => format!("{self:?}"), | ||
} | ||
} | ||
|
||
pub fn is_allowed(&self, pt: PacketType) -> bool { | ||
match self { | ||
Self::Padding | Self::Ping => true, | ||
Self::Padding { .. } | Self::Ping => true, | ||
Self::Crypto { .. } | ||
| Self::Ack { .. } | ||
| Self::ConnectionClose { | ||
|
@@ -409,13 +407,23 @@ impl<'a> Frame<'a> { | |
} | ||
|
||
// TODO([email protected]): check for minimal encoding | ||
let t = d(dec.decode_varint())?; | ||
let t = dv(dec)?; | ||
match t { | ||
FRAME_TYPE_PADDING => Ok(Self::Padding), | ||
FRAME_TYPE_PADDING => { | ||
let mut length: u16 = 1; | ||
while let Some(b) = dec.peek_byte() { | ||
if u64::from(b) != FRAME_TYPE_PADDING { | ||
break; | ||
} | ||
length += 1; | ||
dec.skip(1); | ||
} | ||
Ok(Self::Padding(length)) | ||
} | ||
FRAME_TYPE_PING => Ok(Self::Ping), | ||
FRAME_TYPE_RESET_STREAM => Ok(Self::ResetStream { | ||
stream_id: StreamId::from(dv(dec)?), | ||
application_error_code: d(dec.decode_varint())?, | ||
application_error_code: dv(dec)?, | ||
final_size: match dec.decode_varint() { | ||
Some(v) => v, | ||
_ => return Err(Error::NoMoreData), | ||
|
@@ -457,7 +465,7 @@ impl<'a> Frame<'a> { | |
} | ||
FRAME_TYPE_STOP_SENDING => Ok(Self::StopSending { | ||
stream_id: StreamId::from(dv(dec)?), | ||
application_error_code: d(dec.decode_varint())?, | ||
application_error_code: dv(dec)?, | ||
}), | ||
FRAME_TYPE_CRYPTO => { | ||
let offset = dv(dec)?; | ||
|
@@ -563,7 +571,7 @@ impl<'a> Frame<'a> { | |
Ok(Self::PathResponse { data: datav }) | ||
} | ||
FRAME_TYPE_CONNECTION_CLOSE_TRANSPORT | FRAME_TYPE_CONNECTION_CLOSE_APPLICATION => { | ||
let error_code = CloseError::from_type_bit(t, d(dec.decode_varint())?); | ||
let error_code = CloseError::from_type_bit(t, dv(dec)?); | ||
let frame_type = if t == FRAME_TYPE_CONNECTION_CLOSE_TRANSPORT { | ||
dv(dec)? | ||
} else { | ||
|
@@ -631,8 +639,10 @@ mod tests { | |
|
||
#[test] | ||
fn padding() { | ||
let f = Frame::Padding; | ||
let f = Frame::Padding(1); | ||
just_dec(&f, "00"); | ||
let f = Frame::Padding(2); | ||
just_dec(&f, "0000"); | ||
} | ||
|
||
#[test] | ||
|
@@ -888,8 +898,8 @@ mod tests { | |
|
||
#[test] | ||
fn test_compare() { | ||
let f1 = Frame::Padding; | ||
let f2 = Frame::Padding; | ||
let f1 = Frame::Padding(1); | ||
let f2 = Frame::Padding(1); | ||
let f3 = Frame::Crypto { | ||
offset: 0, | ||
data: &[1, 2, 3], | ||
|
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.