Commit a03f3614 authored by jan.koester's avatar jan.koester
Browse files

pmtu added

parent 85c05f88
Loading
Loading
Loading
Loading
+12 −0
Changes for src/quic.cpp: 12 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -3121,6 +3121,18 @@ void quic::pumpNetwork(int flags) {
            checkLossAndRetransmit();
        }
    }

    // Path MTU Discovery: drive the probe state machine unconditionally
    // (not just when datagrams just arrived above) so a lost probe's
    // timeout is still detected on a caller that polls pumpNetwork() in a
    // tight loop without new data ever showing up. handshake_after_accept()
    // carries the equivalent tick for event-loop-driven connections; this
    // is the one that matters for callers (including these tests) that
    // poll a bare, non-event-loop quic object directly.
    if (_handshake_complete && _conn_state.load() == ConnectionState::Connected) {
        std::lock_guard<std::recursive_mutex> lock(quic_mtx());
        pmtudTick();
    }
}

// ============================================================================
+59 −0
Changes for test/quic_rfc9000_test.cpp: 59 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -95,6 +95,11 @@ public:
static void runServer(std::map<std::string, ssl::CertificateBundle>& certs) {
    try {
        quic serverSock(certs, "127.0.0.1", 18443, 1024, -1);
        // Raised so test_pmtu_discovery()'s client can search past the
        // 1472 baseline; clients that never raise their own ceiling still
        // clamp their search to 1472 regardless (see setPmtuCeiling()), so
        // this has no effect on the other tests in this file.
        serverSock.setPmtuCeiling(9000);
        serverSock.setStreamCallback([](netplus::socket* sock, uint64_t stream_id,
                                        const std::vector<uint8_t>& data, bool fin) {
            quic* q = dynamic_cast<quic*>(sock);
@@ -563,6 +568,59 @@ static void test_idle_survival() {
    }
}

// ============================================================================
// RFC 9000 §14.3-14.4 / RFC 8899: Path MTU Discovery
// ============================================================================

static void test_pmtu_discovery() {
    std::cout << "\n=== RFC 9000 §14.3-14.4: Path MTU Discovery ===" << std::endl;

    // Default ceiling (1472) must be a no-op: discovery never raises the
    // confirmed send size past today's fixed baseline unless asked to.
    {
        quic client;
        connectClient(client);
        auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(2);
        while (std::chrono::steady_clock::now() < deadline) {
            client.pumpNetwork(MSG_DONTWAIT);
            std::this_thread::sleep_for(std::chrono::microseconds(200));
        }
        check(client.getMaxUdpPayload() == 1472,
              "Default ceiling: confirmed size stays at the 1472 baseline");
    }

    // Raising the ceiling should let the client discover a larger usable
    // size over the loopback path (server's ceiling raised in runServer()).
    {
        quic client;
        client.setPmtuCeiling(9000);
        connectClient(client);

        auto deadline = std::chrono::steady_clock::now() + std::chrono::seconds(5);
        while (std::chrono::steady_clock::now() < deadline) {
            client.pumpNetwork(MSG_DONTWAIT);
            std::this_thread::sleep_for(std::chrono::microseconds(200));
        }

        uint64_t discovered = client.getMaxUdpPayload();
        std::cout << "    Discovered max_udp_payload: " << discovered << std::endl;
        check(discovered > 1472, "Raised ceiling: confirmed size grows past the 1472 baseline");

        // Stream sends must still round-trip correctly once chunked at
        // the larger discovered datagram size.
        uint64_t sid = client.openStream(true);
        std::vector<uint8_t> payload(16384);
        fillPattern(payload, 0x33);
        client.sendStreamData(sid, payload, true);

        std::vector<uint8_t> recv_buf(payload.size() + 4096);
        size_t total = drainStream(client, sid, recv_buf, 10);
        check(total == payload.size(), "Post-discovery echo: correct size returned");
        check(std::memcmp(payload.data(), recv_buf.data(), payload.size()) == 0,
              "Post-discovery echo: data integrity at larger datagram size");
    }
}

// ============================================================================
// Main
// ============================================================================
@@ -608,6 +666,7 @@ int main() {
    test_concurrent_streams();
    test_rapid_stream_creation();
    test_idle_survival();
    test_pmtu_discovery();

    // Summary
    std::cout << "\n======================================" << std::endl;