Skip to content

Commit

Permalink
proto: Factor out NewToken frame struct
Browse files Browse the repository at this point in the history
  • Loading branch information
gretchenfrage committed Jan 26, 2025
1 parent 2125b36 commit 273f7c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::{
coding::BufMutExt,
config::{ServerConfig, TransportConfig},
crypto::{self, KeyPair, Keys, PacketKey},
frame::{self, Close, Datagram, FrameStruct},
frame::{self, Close, Datagram, FrameStruct, NewToken},
packet::{
FixedLengthConnectionIdParser, Header, InitialHeader, InitialPacket, LongType, Packet,
PacketNumber, PartialDecode, SpaceId,
Expand Down Expand Up @@ -2849,7 +2849,7 @@ impl Connection {
self.update_rem_cid();
}
}
Frame::NewToken { token } => {
Frame::NewToken(NewToken { token }) => {
if self.side.is_server() {
return Err(TransportError::PROTOCOL_VIOLATION("client sent NEW_TOKEN"));
}
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/connection/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl FrameStats {
Frame::StopSending(_) => self.stop_sending += 1,
Frame::Crypto(_) => self.crypto += 1,
Frame::Datagram(_) => self.datagram += 1,
Frame::NewToken { .. } => self.new_token += 1,
Frame::NewToken(_) => self.new_token += 1,
Frame::MaxData(_) => self.max_data += 1,
Frame::MaxStreamData { .. } => self.max_stream_data += 1,
Frame::MaxStreams { dir, .. } => {
Expand Down
13 changes: 9 additions & 4 deletions quinn-proto/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub(crate) enum Frame {
ResetStream(ResetStream),
StopSending(StopSending),
Crypto(Crypto),
NewToken { token: Bytes },
NewToken(NewToken),
Stream(Stream),
MaxData(VarInt),
MaxStreamData { id: StreamId, offset: u64 },
Expand Down Expand Up @@ -200,7 +200,7 @@ impl Frame {
PathResponse(_) => FrameType::PATH_RESPONSE,
NewConnectionId { .. } => FrameType::NEW_CONNECTION_ID,
Crypto(_) => FrameType::CRYPTO,
NewToken { .. } => FrameType::NEW_TOKEN,
NewToken(_) => FrameType::NEW_TOKEN,
Datagram(_) => FrameType(*DATAGRAM_TYS.start()),
AckFrequency(_) => FrameType::ACK_FREQUENCY,
ImmediateAck => FrameType::IMMEDIATE_ACK,
Expand Down Expand Up @@ -525,6 +525,11 @@ impl Crypto {
}
}

#[derive(Debug, Clone)]
pub(crate) struct NewToken {
pub(crate) token: Bytes,
}

pub(crate) struct Iter {
bytes: Bytes,
last_ty: Option<FrameType>,
Expand Down Expand Up @@ -671,9 +676,9 @@ impl Iter {
offset: self.bytes.get_var()?,
data: self.take_len()?,
}),
FrameType::NEW_TOKEN => Frame::NewToken {
FrameType::NEW_TOKEN => Frame::NewToken(NewToken {
token: self.take_len()?,
},
}),
FrameType::HANDSHAKE_DONE => Frame::HandshakeDone,
FrameType::ACK_FREQUENCY => Frame::AckFrequency(AckFrequency {
sequence: self.bytes.get()?,
Expand Down

0 comments on commit 273f7c2

Please sign in to comment.