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

test

parent 56910dba
Loading
Loading
Loading
Loading
+56 −30
Changes for src/quic.cpp: 56 added lines, 30 removed lines.
Original line number Diff line number Diff line
@@ -795,7 +795,8 @@ std::vector<uint8_t> quic::protectPacket(const std::vector<uint8_t>& header,
    
    // Combine header + ciphertext + tag
    std::vector<uint8_t> result;
    result.reserve(header.size() + ciphertext.size() + 16);
    const size_t total = header.size() + ciphertext.size() + 16;
    result.reserve(total);
    result.insert(result.end(), header.begin(), header.end());
    result.insert(result.end(), ciphertext.begin(), ciphertext.end());
    result.insert(result.end(), tag, tag + 16);
@@ -2849,11 +2850,6 @@ void quic::processStreamFrame(const uint8_t* data, size_t len, size_t& offset) {
    
    if (offset + stream_len > len) return;
    
    if (stream_len > 0) {
        for (size_t i = 0; i < std::min(stream_len, (uint64_t)32); ++i) {
        }
    }
    
    // Get or create stream
    auto& stream = _streams[stream_id];
    stream.stream_id = stream_id;
@@ -3043,6 +3039,7 @@ void quic::sendStreamData(uint64_t stream_id, const std::vector<uint8_t>& data,
        if (set_fin) frame_type |= 0x01;      // FIN bit

        std::vector<uint8_t> frame;
        frame.reserve(frame_hdr_max + chunk_len);
        frame.push_back(frame_type);

        // Stream ID (varint)
@@ -3695,10 +3692,19 @@ size_t quic::sendData(buffer& data, int flags) {
        }
    }
    
    // Build STREAM frame
    std::vector<uint8_t> stream_data(send_ptr, send_ptr + send_len);
    // Build STREAM frames in 1200-byte datagram chunks (QUIC MTU)
    const size_t header_overhead = 1 + _remote_cid.size() + 4 + 16;
    const size_t frame_hdr_max = 1 + 8 + 8 + 8;
    const size_t max_datagram = 1200;
    const size_t max_chunk = max_datagram - header_overhead - frame_hdr_max;

    size_t sent_total = 0;
    while (sent_total < send_len) {
        size_t chunk = std::min(send_len - sent_total, max_chunk);

        std::vector<uint8_t> chunk_data(send_ptr + sent_total, send_ptr + sent_total + chunk);
        std::vector<uint8_t> stream_frame = buildStreamFrame(
        stream_id, stream_data, stream.send_offset, false);
            stream_id, chunk_data, stream.send_offset, false);

        // Build 1-RTT packet
        std::vector<uint8_t> packet = buildShortHeaderPacket(stream_frame);
@@ -3708,17 +3714,22 @@ size_t quic::sendData(buffer& data, int flags) {
        applyHeaderProtection(packet, hp_key);

        // Send packet
    int send_flags = (flags & MSG_DONTWAIT) ? MSG_DONTWAIT : 0;
    {
        buffer send_buf(reinterpret_cast<const char*>(packet.data()), packet.size());
        udp::sendData(send_buf, send_flags);
        ssize_t ret = sendPacket(packet.data(), packet.size());
        if (ret < 0) {
            for (int retry = 0; retry < 10 && ret < 0; ++retry) {
                std::this_thread::sleep_for(
                    std::chrono::microseconds(100 * (1 << retry)));
                ret = sendPacket(packet.data(), packet.size());
            }
            if (ret < 0) break;
        }

    // Update offsets
    stream.send_offset += send_len;
    _data_sent += send_len;
        stream.send_offset += chunk;
        _data_sent += chunk;
        sent_total += chunk;
    }
    
    return send_len;
    return sent_total;
}

// ============================================================================
@@ -3756,32 +3767,46 @@ size_t quic::sendStreamData(uint64_t stream_id, const uint8_t* data, size_t len,
        return 0;
    }
    
    // Build STREAM frame
    std::vector<uint8_t> stream_data(data, data + send_len);
    // Chunk into 1200-byte QUIC datagrams for proper MTU handling
    const size_t header_overhead = 1 + _remote_cid.size() + 4 + 16;
    const size_t frame_hdr_max = 1 + 8 + 8 + 8;
    const size_t max_datagram = 1200;
    const size_t max_chunk = max_datagram - header_overhead - frame_hdr_max;

    size_t sent_total = 0;
    while (sent_total < send_len) {
        size_t chunk = std::min(send_len - sent_total, max_chunk);
        bool is_last = (sent_total + chunk >= send_len);
        bool set_fin = fin && is_last;

        std::vector<uint8_t> chunk_data(data + sent_total, data + sent_total + chunk);
        std::vector<uint8_t> stream_frame = buildStreamFrame(
        stream_id, stream_data, stream.send_offset, fin);
            stream_id, chunk_data, stream.send_offset, set_fin);

    // Build and send packet
        std::vector<uint8_t> packet = buildShortHeaderPacket(stream_frame);
        const uint8_t* hp_key = _is_server ? _app_hp_server : _app_hp_client;
        applyHeaderProtection(packet, hp_key);

    try {
        buffer send_buf(reinterpret_cast<const char*>(packet.data()), packet.size());
        udp::sendData(send_buf, 0);
    } catch (...) {
        return 0;
        ssize_t ret = sendPacket(packet.data(), packet.size());
        if (ret < 0) {
            for (int retry = 0; retry < 10 && ret < 0; ++retry) {
                std::this_thread::sleep_for(
                    std::chrono::microseconds(100 * (1 << retry)));
                ret = sendPacket(packet.data(), packet.size());
            }
            if (ret < 0) break;
        }

    // Update state
    stream.send_offset += send_len;
    _data_sent += send_len;
        stream.send_offset += chunk;
        _data_sent += chunk;
        sent_total += chunk;
    }

    if (fin) {
        stream.send_fin = true;
    }
    
    return send_len;
    return sent_total;
}

// ============================================================================
@@ -3792,6 +3817,7 @@ std::vector<uint8_t> quic::buildStreamFrame(uint64_t stream_id,
                                             const std::vector<uint8_t>& data,
                                             uint64_t offset, bool fin) {
    std::vector<uint8_t> frame;
    frame.reserve(1 + 8 + 8 + 8 + data.size());
    
    // Frame type: STREAM (0x08-0x0f)
    // Bits: OFF (0x04) | LEN (0x02) | FIN (0x01)
+221 −243

File changed.

Preview size limit exceeded, changes collapsed.