Skip to content

Commit

Permalink
feat: marshal path frames in data space without recording
Browse files Browse the repository at this point in the history
  • Loading branch information
huster-zhangpeng committed Nov 27, 2024
1 parent f11e1d0 commit fe1ff31
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
6 changes: 3 additions & 3 deletions qbase/src/cid/local_cid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,15 @@ where
/// of [RFC9000](https://datatracker.ietf.org/doc/html/rfc9000) for more details.
///
/// It means that the initial source connection ID is the only one that can be used
/// to send the Initial, 0Rtt and handshake packets.
/// Changing the scid is like issuing a new connection ID to the other party,
/// to send the Initial, 0Rtt and Handshake packets.
/// Changing the scid is like issuing a new connection ID to the peer,
/// without specifying a sequence number or Stateless Reset Token.
/// Changing the scid during the Handshake phase is meaningless and harmful.
///
/// For the server, even though the server provides the preferred address
/// as the first connection ID, and even though the server can use this
/// connection ID as the scid in the Handshake packet, it is not necessary.
/// The client does not eliminate the zero connection ID.
/// The client could not eliminate the zero connection ID before entering 1RTT.
/// When the client actually eliminates the zero connection ID,
/// it means that 1RTT packets have already started to be transmitted,
/// and all subsequent transmissions should be through 1RTT packets.
Expand Down
9 changes: 8 additions & 1 deletion qbase/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl Iterator for PacketReader {
}
}

/// 在形成一个数据包的过程中,编排各种合适的帧到数据包中
/// During the formation of a packet, various frames are arranged into the packet.
pub trait MarshalFrame<F> {
fn dump_frame(&mut self, frame: F) -> Option<F>;
}
Expand All @@ -156,6 +156,13 @@ pub trait MarshalDataFrame<F, D> {
fn dump_frame_with_data(&mut self, frame: F, data: D) -> Option<F>;
}

/// Mainly customized for PathChallengeFrame and PathResponseFrame.
/// These frames are sent in the data space but do not need to be
/// reliably guaranteed in the data space.
pub trait MarshalPathFrame<F> {
fn dump_path_frame(&mut self, frame: F);
}

pub struct PacketWriter<'b> {
buffer: &'b mut [u8],
hdr_len: usize,
Expand Down
9 changes: 5 additions & 4 deletions qconnection/src/path/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bytes::BufMut;
use futures::StreamExt;
use qbase::{
frame::{io::WriteFrame, BeFrame},
packet::{MarshalFrame, PacketWriter},
packet::MarshalPathFrame,
util::ArcAsyncDeque,
};

Expand Down Expand Up @@ -53,14 +53,15 @@ where
0
}

pub fn try_load_frames_into(&self, packet: &mut PacketWriter<'_>)
pub fn try_load_frames_into<B, P>(&self, packet: &mut P)
where
for<'b> PacketWriter<'b>: MarshalFrame<F>,
B: BufMut,
P: Deref<Target = B> + MarshalPathFrame<F>,
{
let mut guard = self.0.lock().unwrap();
if let Some(frame) = guard.deref() {
if packet.remaining_mut() >= frame.encoding_size() {
packet.dump_frame(guard.take().unwrap());
packet.dump_path_frame(guard.take().unwrap());
}
}
}
Expand Down
22 changes: 21 additions & 1 deletion qconnection/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use qbase::{
packet::{
header::{io::WriteHeader, EncodeHeader},
signal::SpinBit,
AssembledPacket, MarshalDataFrame, MarshalFrame, PacketWriter,
AssembledPacket, MarshalDataFrame, MarshalFrame, MarshalPathFrame, PacketWriter,
},
util::{DescribeData, WriteData},
Epoch,
Expand Down Expand Up @@ -94,6 +94,26 @@ where
}
}

impl<'b> MarshalPathFrame<PathChallengeFrame> for PacketMemory<'b, '_, GuaranteedFrame>
where
PacketWriter<'b>: WriteFrame<PathChallengeFrame>,
{
fn dump_path_frame(&mut self, frame: PathChallengeFrame) {
self.writer.dump_frame(frame);
self.guard.record_trivial();
}
}

impl<'b> MarshalPathFrame<PathResponseFrame> for PacketMemory<'b, '_, GuaranteedFrame>
where
PacketWriter<'b>: WriteFrame<PathResponseFrame>,
{
fn dump_path_frame(&mut self, frame: PathResponseFrame) {
self.writer.dump_frame(frame);
self.guard.record_trivial();
}
}

impl<'b, F> MarshalFrame<F> for PacketMemory<'b, '_, GuaranteedFrame>
where
F: BeFrame + Into<ReliableFrame>,
Expand Down
2 changes: 1 addition & 1 deletion qrecovery/src/recv/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl<TX> Drop for Reader<TX> {
debug_assert!(
!(matches!(receiving_state, Recver::Recv(state) if !state.is_stopped())
|| matches!(receiving_state, Recver::SizeKnown(state) if !state.is_stopped())),
"RecvStream must tell peer to stop sending or be done before dropped!"
"The receiving stream must be stopped with error before dropped!"
);
}
}
Expand Down

0 comments on commit fe1ff31

Please sign in to comment.