Loading src/quic.cpp +45 −3 Changes for src/quic.cpp: 45 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -1592,6 +1592,49 @@ void quic::sendRetryPacket(const std::vector<uint8_t>& client_dcid, client_dcid.size(), retry_scid.size(), packet.size()); } void quic::sendVersionNegotiation(const std::vector<uint8_t>& client_dcid, const std::vector<uint8_t>& client_scid, sockaddr_storage peer_addr, socklen_t peer_len) { std::vector<uint8_t> packet; // First byte: Header Form bit (long header) MUST be 1; the remaining 7 // bits are unused and MAY be set to any value (RFC 9000 §17.2.1) — using // random bits here so clients can't assume a fixed pattern. uint8_t first_byte; fillRandomBytes(&first_byte, 1); packet.push_back(first_byte | 0x80); // Version = 0x00000000 is what marks this as a Version Negotiation // packet rather than a regular long-header one. packet.push_back(0); packet.push_back(0); packet.push_back(0); packet.push_back(0); // DCID/SCID are the triggering packet's SCID/DCID, swapped (RFC 9000 // §17.2.1) — same convention sendRetryPacket uses above. packet.push_back(static_cast<uint8_t>(client_scid.size())); packet.insert(packet.end(), client_scid.begin(), client_scid.end()); packet.push_back(static_cast<uint8_t>(client_dcid.size())); packet.insert(packet.end(), client_dcid.begin(), client_dcid.end()); // Supported Version list, plus a reserved/greased version (RFC 9000 // §6.3 SHOULD) so clients exercise their unknown-version handling. auto pushVersion = [&packet](uint32_t v) { packet.push_back(static_cast<uint8_t>(v >> 24)); packet.push_back(static_cast<uint8_t>(v >> 16)); packet.push_back(static_cast<uint8_t>(v >> 8)); packet.push_back(static_cast<uint8_t>(v)); }; pushVersion(QUIC_VERSION_1); pushVersion(QUIC_VERSION_2); pushVersion(0x1a2a3a4a); // reserved version pattern, RFC 9000 §15.3 sendBatch({{packet.data(), packet.size()}}, &peer_addr, peer_len); QUIC_DBG("sendVersionNegotiation: client_dcid_len=%zu client_scid_len=%zu packet_len=%zu", client_dcid.size(), client_scid.size(), packet.size()); } // ============================================================================ // Socket Interface: accept (Server-side connection acceptance) // ============================================================================ Loading Loading @@ -1884,9 +1927,8 @@ void quic::accept(std::unique_ptr<socket>& csock, bool nonblock) { // Verify supported version if (version != QUIC_VERSION_1 && version != QUIC_VERSION_2) { QUIC_DBG("accept: UNSUPPORTED version 0x%08x, dropping", version); // Send Version Negotiation packet // TODO: Implement version negotiation QUIC_DBG("accept: UNSUPPORTED version 0x%08x, sending Version Negotiation", version); sendVersionNegotiation(dcid, scid, peer_addr, peer_len); continue; } QUIC_DBG("accept: version OK, dcid_len=%u scid_len=%u pkt_type=%u", Loading src/socket.h +10 −0 Changes for src/socket.h: 10 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -847,6 +847,16 @@ namespace netplus { const std::vector<uint8_t>& client_scid, sockaddr_storage peer_addr, socklen_t peer_len); // Server-side: build and send a Version Negotiation packet (RFC 9000 // §6, §17.2.1) in response to a long-header packet whose version this // server doesn't speak. `client_dcid`/`client_scid` are that packet's // own DCID/SCID fields (echoed back, swapped — see RFC 9000 §17.2.1). // No child connection exists yet — sent directly on the listening // socket to `peer_addr`. void sendVersionNegotiation(const std::vector<uint8_t>& client_dcid, const std::vector<uint8_t>& client_scid, sockaddr_storage peer_addr, socklen_t peer_len); // Frame building std::vector<uint8_t> buildCryptoFrame(const std::vector<uint8_t>& data, uint64_t offset); std::vector<uint8_t> buildStreamFrame(uint64_t stream_id, const std::vector<uint8_t>& data, Loading Loading
src/quic.cpp +45 −3 Changes for src/quic.cpp: 45 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -1592,6 +1592,49 @@ void quic::sendRetryPacket(const std::vector<uint8_t>& client_dcid, client_dcid.size(), retry_scid.size(), packet.size()); } void quic::sendVersionNegotiation(const std::vector<uint8_t>& client_dcid, const std::vector<uint8_t>& client_scid, sockaddr_storage peer_addr, socklen_t peer_len) { std::vector<uint8_t> packet; // First byte: Header Form bit (long header) MUST be 1; the remaining 7 // bits are unused and MAY be set to any value (RFC 9000 §17.2.1) — using // random bits here so clients can't assume a fixed pattern. uint8_t first_byte; fillRandomBytes(&first_byte, 1); packet.push_back(first_byte | 0x80); // Version = 0x00000000 is what marks this as a Version Negotiation // packet rather than a regular long-header one. packet.push_back(0); packet.push_back(0); packet.push_back(0); packet.push_back(0); // DCID/SCID are the triggering packet's SCID/DCID, swapped (RFC 9000 // §17.2.1) — same convention sendRetryPacket uses above. packet.push_back(static_cast<uint8_t>(client_scid.size())); packet.insert(packet.end(), client_scid.begin(), client_scid.end()); packet.push_back(static_cast<uint8_t>(client_dcid.size())); packet.insert(packet.end(), client_dcid.begin(), client_dcid.end()); // Supported Version list, plus a reserved/greased version (RFC 9000 // §6.3 SHOULD) so clients exercise their unknown-version handling. auto pushVersion = [&packet](uint32_t v) { packet.push_back(static_cast<uint8_t>(v >> 24)); packet.push_back(static_cast<uint8_t>(v >> 16)); packet.push_back(static_cast<uint8_t>(v >> 8)); packet.push_back(static_cast<uint8_t>(v)); }; pushVersion(QUIC_VERSION_1); pushVersion(QUIC_VERSION_2); pushVersion(0x1a2a3a4a); // reserved version pattern, RFC 9000 §15.3 sendBatch({{packet.data(), packet.size()}}, &peer_addr, peer_len); QUIC_DBG("sendVersionNegotiation: client_dcid_len=%zu client_scid_len=%zu packet_len=%zu", client_dcid.size(), client_scid.size(), packet.size()); } // ============================================================================ // Socket Interface: accept (Server-side connection acceptance) // ============================================================================ Loading Loading @@ -1884,9 +1927,8 @@ void quic::accept(std::unique_ptr<socket>& csock, bool nonblock) { // Verify supported version if (version != QUIC_VERSION_1 && version != QUIC_VERSION_2) { QUIC_DBG("accept: UNSUPPORTED version 0x%08x, dropping", version); // Send Version Negotiation packet // TODO: Implement version negotiation QUIC_DBG("accept: UNSUPPORTED version 0x%08x, sending Version Negotiation", version); sendVersionNegotiation(dcid, scid, peer_addr, peer_len); continue; } QUIC_DBG("accept: version OK, dcid_len=%u scid_len=%u pkt_type=%u", Loading
src/socket.h +10 −0 Changes for src/socket.h: 10 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -847,6 +847,16 @@ namespace netplus { const std::vector<uint8_t>& client_scid, sockaddr_storage peer_addr, socklen_t peer_len); // Server-side: build and send a Version Negotiation packet (RFC 9000 // §6, §17.2.1) in response to a long-header packet whose version this // server doesn't speak. `client_dcid`/`client_scid` are that packet's // own DCID/SCID fields (echoed back, swapped — see RFC 9000 §17.2.1). // No child connection exists yet — sent directly on the listening // socket to `peer_addr`. void sendVersionNegotiation(const std::vector<uint8_t>& client_dcid, const std::vector<uint8_t>& client_scid, sockaddr_storage peer_addr, socklen_t peer_len); // Frame building std::vector<uint8_t> buildCryptoFrame(const std::vector<uint8_t>& data, uint64_t offset); std::vector<uint8_t> buildStreamFrame(uint64_t stream_id, const std::vector<uint8_t>& data, Loading