gfe-relnote: In QUIC, add a utility function CopySerializedPacket. Not used yet, not protected.
Add bool has_ack_frame_copy to SerializedPacket, indicating whether the serialized packet contains a copy of ack frame.
PiperOrigin-RevId: 275908820
Change-Id: I34b156091a9fbaa542bed5951588c43b59de12bb
diff --git a/quic/core/quic_packets.cc b/quic/core/quic_packets.cc
index 216a37b..68a078e 100644
--- a/quic/core/quic_packets.cc
+++ b/quic/core/quic_packets.cc
@@ -456,7 +456,8 @@
encryption_level(ENCRYPTION_INITIAL),
has_ack(has_ack),
has_stop_waiting(has_stop_waiting),
- transmission_type(NOT_RETRANSMISSION) {}
+ transmission_type(NOT_RETRANSMISSION),
+ has_ack_frame_copy(false) {}
SerializedPacket::SerializedPacket(const SerializedPacket& other) = default;
@@ -475,20 +476,41 @@
has_stop_waiting(other.has_stop_waiting),
transmission_type(other.transmission_type),
original_packet_number(other.original_packet_number),
- largest_acked(other.largest_acked) {
+ largest_acked(other.largest_acked),
+ has_ack_frame_copy(other.has_ack_frame_copy) {
retransmittable_frames.swap(other.retransmittable_frames);
nonretransmittable_frames.swap(other.nonretransmittable_frames);
}
SerializedPacket::~SerializedPacket() {}
+SerializedPacket* CopySerializedPacket(const SerializedPacket& serialized,
+ QuicBufferAllocator* allocator,
+ bool copy_buffer) {
+ SerializedPacket* copy = new SerializedPacket(serialized);
+ if (copy_buffer) {
+ copy->encrypted_buffer = CopyBuffer(serialized);
+ }
+ // Copy underlying frames.
+ copy->retransmittable_frames =
+ CopyQuicFrames(allocator, serialized.retransmittable_frames);
+ copy->nonretransmittable_frames.clear();
+ for (const auto& frame : serialized.nonretransmittable_frames) {
+ if (frame.type == ACK_FRAME) {
+ copy->has_ack_frame_copy = true;
+ }
+ copy->nonretransmittable_frames.push_back(CopyQuicFrame(allocator, frame));
+ }
+ return copy;
+}
+
void ClearSerializedPacket(SerializedPacket* serialized_packet) {
if (!serialized_packet->retransmittable_frames.empty()) {
DeleteFrames(&serialized_packet->retransmittable_frames);
}
for (auto& frame : serialized_packet->nonretransmittable_frames) {
- if (frame.type == ACK_FRAME) {
- // Ack frame is owned by received_packet_manager.
+ if (!serialized_packet->has_ack_frame_copy && frame.type == ACK_FRAME) {
+ // Do not delete ack frame if the packet does not own a copy of it.
continue;
}
DeleteFrame(&frame);