Commit 65f83dcd authored by jan.koester's avatar jan.koester
Browse files

bugfix

parent 883d5530
Loading
Loading
Loading
Loading
+17 −3
Changes for src/quic.cpp: 17 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -43,7 +43,12 @@
#include <cstdio>
#include <cmath>

#define QUIC_DBG(fmt, ...) do { } while(0)
#define QUIC_DBG(fmt, ...) do { \
    if (getenv("QUIC_TRACE")) { \
        fprintf(stderr, "[%.6f] " fmt "\n", \
                std::chrono::duration<double>(std::chrono::steady_clock::now().time_since_epoch()).count(), ##__VA_ARGS__); \
    } \
} while(0)

namespace netplus {

@@ -1572,7 +1577,9 @@ void quic::sendRetryPacket(const std::vector<uint8_t>& client_dcid,
    auto tag = computeRetryIntegrityTag(client_dcid, packet.data(), packet.size());
    packet.insert(packet.end(), tag.begin(), tag.end());

    sendBatch({{packet.data(), packet.size()}}, &peer_addr, peer_len);
    ssize_t sent = sendBatch({{packet.data(), packet.size()}}, &peer_addr, peer_len);
    QUIC_DBG("sendRetryPacket: client_dcid_len=%zu retry_scid_len=%zu packet_len=%zu sent=%zd",
             client_dcid.size(), retry_scid.size(), packet.size(), sent);
}

// ============================================================================
@@ -1904,6 +1911,9 @@ void quic::accept(std::unique_ptr<socket>& csock, bool nonblock) {
    if (!token.empty()) {
        parsed_token = validateToken(token, peer_addr, peer_len);
    }
    QUIC_DBG("accept: token.size()=%zu valid=%d is_retry=%d dcid_len=%zu scid_len=%zu",
             token.size(), (int)parsed_token.valid, (int)parsed_token.is_retry,
             dcid.size(), scid.size());
    if (!parsed_token.valid) {
        sendRetryPacket(dcid, scid, peer_addr, peer_len);
        continue;
@@ -2229,6 +2239,8 @@ void quic::processLongHeaderPacket(const uint8_t* data, size_t len) {
}

void quic::processRetryPacket(const uint8_t* data, size_t len) {
    QUIC_DBG("processRetryPacket: ENTER len=%zu is_server=%d retry_received=%d handshake_complete=%d state=%d",
             len, (int)_is_server, (int)_retry_received, (int)_handshake_complete, (int)_conn_state.load());
    // Only clients act on a Retry (a server never legitimately receives
    // one), and at most once per connection (RFC 9000 §17.2.5.2) — a
    // second Retry is discarded, not reprocessed.
@@ -2265,7 +2277,9 @@ void quic::processRetryPacket(const uint8_t* data, size_t len) {

    // Verify the Integrity Tag before trusting anything in this packet.
    auto expected_tag = computeRetryIntegrityTag(_original_dcid, data, len - 16);
    if (!std::equal(expected_tag.begin(), expected_tag.end(), data + len - 16)) {
    bool tag_ok = std::equal(expected_tag.begin(), expected_tag.end(), data + len - 16);
    QUIC_DBG("processRetryPacket: scid_len=%zu token_len=%zu tag_ok=%d", scid.size(), token_len, (int)tag_ok);
    if (!tag_ok) {
        return; // drop silently — off-path noise or corruption, not fatal
    }