Commit 41a38113 authored by jan.koester's avatar jan.koester
Browse files

test

parent ee1765b3
Loading
Loading
Loading
Loading
+30 −8
Changes for src/quic.cpp: 30 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -3691,8 +3691,10 @@ void quic::processFrame(const uint8_t* data, size_t len, size_t& offset, bool& a
            break;

        case 0x02:  // ACK
            processAckFrame(data, len, offset, false);
            break;
        case 0x03:  // ACK_ECN
            processAckFrame(data, len, offset);
            processAckFrame(data, len, offset, true);
            break;

        case 0x06:  // CRYPTO
@@ -4419,7 +4421,7 @@ void quic::processStreamFrame(const uint8_t* data, size_t len, size_t& offset) {
// Frame Processing: ACK Frame
// ============================================================================

void quic::processAckFrame(const uint8_t* data, size_t len, size_t& offset) {
void quic::processAckFrame(const uint8_t* data, size_t len, size_t& offset, bool is_ecn) {
    if (offset >= len) return;

    size_t bytes;
@@ -4474,15 +4476,18 @@ void quic::processAckFrame(const uint8_t* data, size_t len, size_t& offset) {
        return;
    }

    // Collect all ACKed ranges: [lo, hi] pairs
    // Collect all ACKed ranges: [lo, hi] pairs. Bounded by
    // MAX_ACK_RANGES_PER_FRAME (already validated above), so a fixed-size
    // stack array replaces what used to be a heap-allocated vector on this
    // hot per-ACK path.
    struct AckRange { uint64_t lo; uint64_t hi; };
    std::vector<AckRange> acked_ranges;
    acked_ranges.reserve(static_cast<size_t>(ack_range_count) + 1);
    AckRange acked_ranges[MAX_ACK_RANGES_PER_FRAME + 1];
    size_t acked_count = 0;

    // First range
    uint64_t hi = largest_ack;
    uint64_t lo = largest_ack - first_ack_range;
    acked_ranges.push_back({lo, hi});
    acked_ranges[acked_count++] = {lo, hi};

    uint64_t prev_smallest = lo;

@@ -4495,14 +4500,31 @@ void quic::processAckFrame(const uint8_t* data, size_t len, size_t& offset) {
        if (prev_smallest < gap + 2) break; // malformed
        hi = prev_smallest - gap - 2;
        lo = (hi >= ack_range) ? hi - ack_range : 0;
        acked_ranges.push_back({lo, hi});
        acked_ranges[acked_count++] = {lo, hi};
        prev_smallest = lo;
    }

    // ACK_ECN (RFC 9000 §19.3.2) carries three additional varints after the
    // ACK Ranges: ECT0 Count, ECT1 Count, ECN-CE Count. These MUST be
    // consumed here regardless of whether this endpoint reacts to ECN yet —
    // otherwise `offset` is left pointing mid-field, and the caller's frame
    // loop misinterprets the remaining bytes as an unrelated frame (typically
    // aborting the connection via the default/malformed-frame path).
    if (is_ecn) {
        uint64_t ect0, ect1, ecn_ce;
        if (!readVarInt(ect0)) return;
        if (!readVarInt(ect1)) return;
        if (!readVarInt(ecn_ce)) return;
        _peer_ect0_count = ect0;
        _peer_ect1_count = ect1;
        _peer_ecn_ce_count = ecn_ce;
    }

    auto now = std::chrono::steady_clock::now();

    // Remove acknowledged packets from _sent_packets and update RTT
    for (auto& ar : acked_ranges) {
    for (size_t ri = 0; ri < acked_count; ++ri) {
        auto& ar = acked_ranges[ri];
        for (auto it = _sent_packets.lower_bound(ar.lo);
             it != _sent_packets.end() && it->first <= ar.hi; ) {
            // Update RTT from the largest newly-acked packet
+11 −1
Changes for src/socket.h: 11 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -811,7 +811,7 @@ namespace netplus {
		void processFrame(const uint8_t* data, size_t len, size_t& offset, bool& ack_eliciting);
		void processCryptoFrame(const uint8_t* data, size_t len, size_t& offset);
		void processStreamFrame(const uint8_t* data, size_t len, size_t& offset);
		void processAckFrame(const uint8_t* data, size_t len, size_t& offset);
		void processAckFrame(const uint8_t* data, size_t len, size_t& offset, bool is_ecn);
		// Sends CONNECTION_CLOSE(error_code, reason), drains the connection,
		// and sets offset = len so the caller's frame loop terminates —
		// the response to any malformed/truncated frame data parsing hits
@@ -1058,6 +1058,16 @@ namespace netplus {
		uint32_t _app_unacked_count = 0;  // Delayed ACK counter
		bool     _app_ack_pending = false; // Deferred ACK flag

		// Latest ECN counts reported by the peer via an ACK_ECN frame (RFC
		// 9000 §19.3.2). Not yet fed into a congestion-signal decision (see
		// onPacketAckedCC()/onPacketLostCC()) — captured now so the frame is
		// parsed correctly (offset must advance past all three fields) and
		// so the values are available for a future ECN-reactive CC without
		// another wire-format change.
		uint64_t _peer_ect0_count = 0;
		uint64_t _peer_ect1_count = 0;
		uint64_t _peer_ecn_ce_count = 0;

		// Received packet-number ranges (inclusive) for proper ACK encoding
		// Each pair is [lo, hi] representing contiguous received PNs.
		std::set<std::pair<uint64_t,uint64_t>> _initial_pn_recv_ranges;