mirror of
https://github.com/n0-computer/noq.git
synced 2026-09-24 12:13:05 +00:00
Yield protocol violation for packets without frames
This commit is contained in:
@@ -2192,7 +2192,7 @@ impl Connection {
|
||||
return Ok(());
|
||||
}
|
||||
State::Closed(_) => {
|
||||
for result in frame::Iter::new(packet.payload.freeze()) {
|
||||
for result in frame::Iter::new(packet.payload.freeze())? {
|
||||
let frame = match result {
|
||||
Ok(frame) => frame,
|
||||
Err(err) => {
|
||||
@@ -2441,7 +2441,7 @@ impl Connection {
|
||||
debug_assert_ne!(packet.header.space(), SpaceId::Data);
|
||||
let payload_len = packet.payload.len();
|
||||
let mut ack_eliciting = false;
|
||||
for result in frame::Iter::new(packet.payload.freeze()) {
|
||||
for result in frame::Iter::new(packet.payload.freeze())? {
|
||||
let frame = result?;
|
||||
let span = match frame {
|
||||
Frame::Padding => continue,
|
||||
@@ -2499,7 +2499,7 @@ impl Connection {
|
||||
let mut close = None;
|
||||
let payload_len = payload.len();
|
||||
let mut ack_eliciting = false;
|
||||
for result in frame::Iter::new(payload) {
|
||||
for result in frame::Iter::new(payload)? {
|
||||
let frame = result?;
|
||||
let span = match frame {
|
||||
Frame::Padding => continue,
|
||||
|
||||
@@ -550,11 +550,20 @@ impl From<UnexpectedEnd> for IterErr {
|
||||
}
|
||||
|
||||
impl Iter {
|
||||
pub(crate) fn new(payload: Bytes) -> Self {
|
||||
Self {
|
||||
pub(crate) fn new(payload: Bytes) -> Result<Self, TransportError> {
|
||||
if payload.is_empty() {
|
||||
// "An endpoint MUST treat receipt of a packet containing no frames as a
|
||||
// connection error of type PROTOCOL_VIOLATION."
|
||||
// https://www.rfc-editor.org/rfc/rfc9000.html#name-frames-and-frame-types
|
||||
return Err(TransportError::PROTOCOL_VIOLATION(
|
||||
"packet payload is empty",
|
||||
));
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
bytes: io::Cursor::new(payload),
|
||||
last_ty: None,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn take_len(&mut self) -> Result<Bytes, UnexpectedEnd> {
|
||||
@@ -923,6 +932,7 @@ mod test {
|
||||
|
||||
fn frames(buf: Vec<u8>) -> Vec<Frame> {
|
||||
Iter::new(Bytes::from(buf))
|
||||
.unwrap()
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
@@ -2257,6 +2257,7 @@ fn single_ack_eliciting_packet_triggers_ack_after_delay() {
|
||||
// The ACK delay is properly calculated
|
||||
assert_eq!(pair.client.captured_packets.len(), 1);
|
||||
let mut frames = frame::Iter::new(pair.client.captured_packets.remove(0).into())
|
||||
.unwrap()
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.unwrap();
|
||||
assert_eq!(frames.len(), 1);
|
||||
|
||||
Reference in New Issue
Block a user