Skip to content

Commit

Permalink
opt packet/recover
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyuanbing committed Dec 18, 2023
1 parent dc1424e commit 2b81c89
Show file tree
Hide file tree
Showing 23 changed files with 195 additions and 209 deletions.
5 changes: 3 additions & 2 deletions quiche/quic/core/frames/quic_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
#include "quiche/quic/core/frames/quic_window_update_frame.h"
#include "quiche/quic/core/quic_types.h"
#include "quiche/quic/platform/api/quic_export.h"
#include "quiche/common/small_vector.hpp"

#ifndef QUIC_FRAME_DEBUG
#if !defined(NDEBUG) || defined(ADDRESS_SANITIZER)
#define QUIC_FRAME_DEBUG 1
#define QUIC_FRAME_DEBUG 0
#else // !defined(NDEBUG) || defined(ADDRESS_SANITIZER)
#define QUIC_FRAME_DEBUG 0
#endif // !defined(NDEBUG) || defined(ADDRESS_SANITIZER)
Expand Down Expand Up @@ -129,7 +130,7 @@ static_assert(offsetof(QuicStreamFrame, type) == offsetof(QuicFrame, type),

// A inline size of 1 is chosen to optimize the typical use case of
// 1-stream-frame in QuicTransmissionInfo.retransmittable_frames.
#if 1
#ifndef _DEBUG
using QuicFrames = absl::InlinedVector<QuicFrame, 2>;
//using QuicFrames = sfl::small_vector<QuicFrame, 2>;
#else
Expand Down
121 changes: 63 additions & 58 deletions quiche/quic/core/quic_connection.cc

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions quiche/quic/core/quic_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -2274,6 +2274,9 @@ class QUIC_EXPORT_PRIVATE QuicConnection final
bool should_proactively_validate_peer_address_on_path_challenge_ = false;

// Enable this via reloadable flag once this feature is complete.
#if !QUIC_TLS_SESSION
constexpr static
#endif
bool connection_migration_use_new_cid_ = false;

// If true, send connection close packet on INVALID_VERSION.
Expand Down
2 changes: 1 addition & 1 deletion quiche/quic/core/quic_control_frame_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class QUIC_EXPORT_PRIVATE QuicControlFrameManager {
// frame.
void WriteOrBufferQuicFrame(QuicFrame frame);

absl::InlinedVector<QuicFrame, 3> control_frames_;
absl::InlinedVector<QuicFrame, 2> control_frames_;

// Id of latest saved control frame. 0 if no control frame has been saved.
QuicControlFrameId last_control_frame_id_;
Expand Down
2 changes: 1 addition & 1 deletion quiche/quic/core/quic_flow_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ void QuicFlowController::EnsureWindowAtLeast(QuicByteCount window_size) {
UpdateReceiveWindowOffsetAndSendWindowUpdate(available_window);
}

bool QuicFlowController::IsBlocked() const { return bytes_sent_ > send_window_offset_; }
bool QuicFlowController::IsBlocked() const { return bytes_sent_ >= send_window_offset_; }

uint64_t QuicFlowController::SendWindowSize() const {
if (bytes_sent_ > send_window_offset_) {
Expand Down
17 changes: 7 additions & 10 deletions quiche/quic/core/quic_framer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -968,10 +968,8 @@ size_t QuicFramer::BuildDataPacket(const QuicPacketHeader& header,
}
break;
case WINDOW_UPDATE_FRAME:
if (!AppendWindowUpdateFrame(frame.window_update_frame, &writer)) {
QUIC_BUG(quic_bug_10850_25) << "AppendWindowUpdateFrame failed";
return 0;
}
AppendWindowUpdateFrame(frame.window_update_frame, &writer);

break;
case BLOCKED_FRAME:
if (!AppendBlockedFrame(frame.blocked_frame, &writer)) {
Expand Down Expand Up @@ -2212,9 +2210,8 @@ bool QuicFramer::AppendPacketHeader(const QuicPacketHeader& header,
if (header.nonce != nullptr)
writer->WriteBytes(header.nonce, kDiversificationNonceSize);

AppendPacketNumber(header.packet_number_length, header.packet_number,
return AppendPacketNumber(header.packet_number_length, header.packet_number,
writer);
return true;
}

bool QuicFramer::AppendIetfHeaderTypeByte(const QuicPacketHeader& header,
Expand Down Expand Up @@ -2444,8 +2441,8 @@ bool QuicFramer::ProcessPublicHeader(QuicDataReader* reader,
// A nonce should only be present in packets from the server to the client,
// which are neither version negotiation nor public reset packets.
if (public_flags & PACKET_PUBLIC_FLAGS_NONCE &&
!(public_flags & (PACKET_PUBLIC_FLAGS_VERSION | PACKET_PUBLIC_FLAGS_RST)) &&
// !(public_flags & PACKET_PUBLIC_FLAGS_RST) &&
!(public_flags & PACKET_PUBLIC_FLAGS_VERSION) &&
!(public_flags & PACKET_PUBLIC_FLAGS_RST) &&
// The nonce flag from a client is ignored and is assumed to be an older
// client indicating an eight-byte connection ID.
perspective_ == Perspective::IS_CLIENT) {
Expand Down Expand Up @@ -2891,8 +2888,8 @@ bool QuicFramer::ProcessFrameData(QuicDataReader* reader,
}
QUIC_DVLOG(2) << ENDPOINT << "Processing packet with header " << header;
while (!reader->IsDoneReading()) {
uint8_t frame_type = NUM_FRAME_TYPES + 2;
if (!reader->ReadUInt8(&frame_type)) {
uint8_t frame_type;
if (!reader->ReadBytes(&frame_type, 1)) {
set_detailed_error("Unable to read frame type.");
return RaiseError(QUIC_INVALID_FRAME_DATA);
}
Expand Down
2 changes: 0 additions & 2 deletions quiche/quic/core/quic_framer.h
Original file line number Diff line number Diff line change
Expand Up @@ -744,8 +744,6 @@ class QUIC_EXPORT_PRIVATE QuicFramer {
private:
friend class test::QuicFramerPeer;

using NackRangeMap = std::map<QuicPacketNumber, uint8_t>;

// AckTimestampRange is a data structure derived from a QuicAckFrame. It is
// used to serialize timestamps in a IETF_ACK_RECEIVE_TIMESTAMPS frame.
struct QUIC_EXPORT_PRIVATE AckTimestampRange {
Expand Down
13 changes: 6 additions & 7 deletions quiche/quic/core/quic_idle_network_detector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ void QuicIdleNetworkDetector::OnPacketSent(QuicTime now,
MaybeSetAlarmOnSentPacket(pto_delay);
return;
}
// if (!alarm_->IsSet())
// if (!alarm_->IsSet()) //hybchanged
// SetAlarm();
}

void QuicIdleNetworkDetector::OnPacketReceived(QuicTime now) {
QUICHE_DCHECK(time_of_last_received_packet_ <= now);
time_of_last_received_packet_ = now;
MaybeSetAlarmOnSentPacket(kAlarmGranularity * 1000);
//SetAlarm(); //TODO hybchanged
//MaybeSetAlarmOnSentPacket(kAlarmGranularity * 1000);
SetAlarm(); //TODO hybchanged
}

void QuicIdleNetworkDetector::SetAlarm() {
Expand Down Expand Up @@ -147,19 +147,18 @@ void QuicIdleNetworkDetector::SetAlarm() {

void QuicIdleNetworkDetector::MaybeSetAlarmOnSentPacket(
QuicTime::Delta pto_delay) {
if (!handshake_timeout_.IsInfinite() /* || !alarm_->IsSet()***/) {
QUICHE_DCHECK(shorter_idle_timeout_on_sent_packet_);
if (!handshake_timeout_.IsInfinite() || !alarm_->IsSet()) {
SetAlarm();
return;
}

// Make sure connection will be alive for another PTO.
const QuicTime deadline = alarm_->deadline();
const QuicTime min_deadline = last_network_activity_time() + pto_delay;
if (deadline > min_deadline) {
return;
}
SetAlarm();
//alarm_->Update(min_deadline, kAlarmGranularity);
alarm_->Update(min_deadline, kAlarmGranularity);
}

QuicTime QuicIdleNetworkDetector::GetIdleNetworkDeadline() const {
Expand Down
23 changes: 10 additions & 13 deletions quiche/quic/core/quic_network_blackhole_detector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ QuicNetworkBlackholeDetector::QuicNetworkBlackholeDetector(

void QuicNetworkBlackholeDetector::OnAlarm() {
QuicTime next_deadline = GetEarliestDeadline();
if (false && !next_deadline.IsInitialized()) {
if (!next_deadline.IsInitialized()) {
QUIC_BUG(quic_bug_10328_1) << "BlackholeDetector alarm fired unexpectedly";
return;
}
Expand All @@ -59,7 +59,7 @@ void QuicNetworkBlackholeDetector::OnAlarm() {
if (blackhole_deadline_ == next_deadline) {
blackhole_deadline_ = QuicTime::Zero();
delegate_->OnBlackholeDetected();
}
} else

UpdateAlarm();
}
Expand Down Expand Up @@ -90,16 +90,15 @@ void QuicNetworkBlackholeDetector::RestartDetection(
}

QuicTime QuicNetworkBlackholeDetector::GetEarliestDeadline() const {
QuicTime result = path_mtu_reduction_deadline_;
for (QuicTime t : {path_degrading_deadline_, blackhole_deadline_}) {
if (!t.IsInitialized()) {
continue;
}

if (!result.IsInitialized() || t < result) {
QuicTime result = std::min(path_degrading_deadline_, blackhole_deadline_);
#if 0
if (!result.IsInitialized())
QUICHE_DCHECK(!std::max(path_degrading_deadline_, blackhole_deadline_).IsInitialized);
//result = std::max(path_degrading_deadline_, blackhole_deadline_);
if (QuicTime t = path_mtu_reduction_deadline_; !result.IsInitialized() || (t.IsInitialized() && t < result)) {
result = t;
}
}
#endif

return result;
}
Expand All @@ -112,10 +111,8 @@ QuicTime QuicNetworkBlackholeDetector::GetLastDeadline() const {
void QuicNetworkBlackholeDetector::UpdateAlarm() const {
// If called after OnBlackholeDetected(), the alarm may have been permanently
// cancelled and is not safe to be armed again.
//QUICHE_DCHECK(!alarm_->IsPermanentlyCancelled());
if (false && alarm_->IsPermanentlyCancelled()) {
QUIC_DVLOG(2) << "Updating alarm. next_deadline:" << blackhole_deadline_;
//return;
return;
}

QuicTime next_deadline = GetEarliestDeadline();
Expand Down
Loading

0 comments on commit 2b81c89

Please sign in to comment.