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

fix

parent 74732f50
Loading
Loading
Loading
Loading
+47 −5
Changes for src/quic.cpp: 47 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -4757,8 +4757,8 @@ void quic::pumpIncoming() {
    std::lock_guard<std::recursive_mutex> lock(quic_mtx());

    static constexpr int MAX_PUMP = 64;
    for (int i = 0; i < MAX_PUMP; ++i) {
    std::vector<uint8_t> dgram(65535);
    for (int i = 0; i < MAX_PUMP; ++i) {
        sockaddr_storage peer_addr{};
        socklen_t peer_len = sizeof(peer_addr);

@@ -4769,26 +4769,68 @@ void quic::pumpIncoming() {
                                       reinterpret_cast<sockaddr*>(&peer_addr),
                                       &peer_len);
        if (recv_len <= 0) break;
        dgram.resize(static_cast<size_t>(recv_len));

        // Short header packets — route via DCID for server (child connections),
        // or process directly for client connections (no _child_connections).
        if (!(dgram[0] & 0x80)) {
            if (!_parent && parent->_child_connections.empty()) {
                // Client-side: process packet directly on this connection
                processIncomingPacket(dgram.data(), dgram.size());
                processIncomingPacket(dgram.data(), static_cast<size_t>(recv_len));
            } else {
                static constexpr size_t CID_LEN = 8;
                if (dgram.size() < 1 + CID_LEN) continue;
                if (static_cast<size_t>(recv_len) < 1 + CID_LEN) continue;
                std::vector<uint8_t> dcid(dgram.begin() + 1,
                                           dgram.begin() + 1 + CID_LEN);
                auto it = parent->_child_connections.find(dcid);
                if (it != parent->_child_connections.end() && it->second) {
                    it->second->processIncomingPacket(dgram.data(), dgram.size());
                    it->second->processIncomingPacket(dgram.data(), static_cast<size_t>(recv_len));

                    // Flush child's pending flow control frames
                    if (it->second->_handshake_complete &&
                        it->second->_conn_state.load() == ConnectionState::Connected) {
                        for (auto& [sid, limit] : it->second->_pending_max_stream_data) {
                            it->second->sendMaxStreamData(sid, limit);
                        }
                        it->second->_pending_max_stream_data.clear();
                        if (it->second->_pending_max_data) {
                            it->second->sendMaxData(it->second->_pending_max_data_value);
                            it->second->_pending_max_data = false;
                        }
                    }
                }
            }
        } else {
            // Long header packet (Initial, Handshake, etc.) — route to
            // existing child connection if possible.  Must not silently
            // drop these, as they may carry handshake continuations.
            if (static_cast<size_t>(recv_len) >= 7) {
                size_t dcid_len = static_cast<size_t>(dgram[5]);
                if (6 + dcid_len <= static_cast<size_t>(recv_len)) {
                    std::vector<uint8_t> dcid(dgram.begin() + 6,
                                               dgram.begin() + 6 + dcid_len);
                    auto it = parent->_child_connections.find(dcid);
                    if (it != parent->_child_connections.end() && it->second) {
                        it->second->processIncomingPacket(dgram.data(), static_cast<size_t>(recv_len));
                    }
                    // If no match, the datagram is for a NEW connection
                    // and will be picked up by the next accept() call.
                    // We cannot create connections here, so buffer it.
                }
            }
        }
    }

    // Flush own pending flow control frames
    if (_handshake_complete && _conn_state.load() == ConnectionState::Connected) {
        for (auto& [sid, limit] : _pending_max_stream_data) {
            sendMaxStreamData(sid, limit);
        }
        _pending_max_stream_data.clear();
        if (_pending_max_data) {
            sendMaxData(_pending_max_data_value);
            _pending_max_data = false;
        }
    }

    // After processing incoming packets (which may contain ACKs),
    // check for lost packets and retransmit.