This is an automated email from the ASF dual-hosted git repository. maskit pushed a commit to branch quic-latest in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 32d43b09212e1de4f2b4f699bf6f0f2c02bb00e6 Author: Masakazu Kitajo <[email protected]> AuthorDate: Thu Jun 21 11:04:09 2018 +0900 Change payload length field to length field (apart of draft 13) --- iocore/net/quic/QUICPacket.cc | 37 ++++++++++++++++++------------- iocore/net/quic/QUICPacket.h | 2 +- iocore/net/quic/QUICPacketReceiveQueue.cc | 19 ++++++++-------- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/iocore/net/quic/QUICPacket.cc b/iocore/net/quic/QUICPacket.cc index ca3bc45..d9cb9d0 100644 --- a/iocore/net/quic/QUICPacket.cc +++ b/iocore/net/quic/QUICPacket.cc @@ -53,8 +53,8 @@ QUICPacketHeader::buf() return this->_buf.get(); } else { // TODO Reuse serialzied data if nothing has changed - size_t dummy; - this->store(this->_serialized, &dummy); + this->store(this->_serialized, &this->_buf_len); + this->_buf_len += this->_payload_length; return this->_serialized; } } @@ -148,15 +148,14 @@ QUICPacketLongHeader::QUICPacketLongHeader(const IpEndpoint from, ats_unique_buf if (this->type() == QUICPacketType::VERSION_NEGOTIATION) { this->_payload_offset = offset; - this->_payload_length = len - offset; } else { - this->_payload_length = QUICIntUtil::read_QUICVariableInt(raw_buf + offset); offset += QUICVariableInt::size(raw_buf + offset); int pn_len = QUICTypeUtil::read_QUICPacketNumberLen(raw_buf + offset); QUICPacket::decode_packet_number(this->_packet_number, QUICTypeUtil::read_QUICPacketNumber(raw_buf + offset), pn_len, this->_base_packet_number); this->_payload_offset = offset + pn_len; } + this->_payload_length = len - this->_payload_offset; } QUICPacketLongHeader::QUICPacketLongHeader(QUICPacketType type, QUICConnectionId destination_cid, QUICConnectionId source_cid, @@ -177,8 +176,7 @@ QUICPacketLongHeader::QUICPacketLongHeader(QUICPacketType type, QUICConnectionId this->_buf_len = LONG_HDR_OFFSET_CONNECTION_ID + this->_destination_cid.length() + this->_source_cid.length() + this->_payload_length; } else { - this->_buf_len = LONG_HDR_OFFSET_CONNECTION_ID + this->_destination_cid.length() + this->_source_cid.length() + - QUICVariableInt::size(this->_payload_length + aead_tag_len) + 4 + this->_payload_length; + // this->_buf_len will be updated when buf() is called } } @@ -245,17 +243,17 @@ QUICPacketLongHeader::scil(uint8_t &scil, const uint8_t *packet, size_t packet_l } bool -QUICPacketLongHeader::payload_length(size_t &length, uint8_t *field_len, const uint8_t *packet, size_t packet_len) +QUICPacketLongHeader::length(size_t &length, uint8_t *field_len, const uint8_t *packet, size_t packet_len) { uint8_t dcil, scil; QUICPacketLongHeader::dcil(dcil, packet, packet_len); QUICPacketLongHeader::scil(scil, packet, packet_len); - size_t payload_len_offset = LONG_HDR_OFFSET_CONNECTION_ID + dcil + scil; - length = QUICIntUtil::read_QUICVariableInt(packet + payload_len_offset); + size_t length_offset = LONG_HDR_OFFSET_CONNECTION_ID + dcil + scil; + length = QUICIntUtil::read_QUICVariableInt(packet + length_offset); if (field_len) { - *field_len = QUICVariableInt::size(packet + payload_len_offset); + *field_len = QUICVariableInt::size(packet + length_offset); } return true; } @@ -373,13 +371,22 @@ QUICPacketLongHeader::store(uint8_t *buf, size_t *len) const *len += n; if (this->_type != QUICPacketType::VERSION_NEGOTIATION) { - QUICIntUtil::write_QUICVariableInt(this->_payload_length + aead_tag_len, buf + *len, &n); + QUICPacketNumber pn = 0; + size_t pn_len = 4; + QUICPacket::encode_packet_number(pn, this->_packet_number, pn_len); + + if (pn < 0x100) { + pn_len = 1; + } else if (pn < 0x4000) { + pn_len = 2; + } else { + pn_len = 4; + } + + QUICIntUtil::write_QUICVariableInt(QUICVariableInt::size(pn_len) + this->_payload_length + aead_tag_len, buf + *len, &n); *len += n; - QUICPacketNumber dst = 0; - size_t dst_len = 4; - QUICPacket::encode_packet_number(dst, this->_packet_number, dst_len); - QUICTypeUtil::write_QUICPacketNumber(dst, dst_len, buf + *len, &n); + QUICTypeUtil::write_QUICPacketNumber(pn, pn_len, buf + *len, &n); *len += n; } } diff --git a/iocore/net/quic/QUICPacket.h b/iocore/net/quic/QUICPacket.h index bf6cfb7..3ce9bc8 100644 --- a/iocore/net/quic/QUICPacket.h +++ b/iocore/net/quic/QUICPacket.h @@ -200,7 +200,7 @@ public: * Unlike QUICInvariants::scil(), this returns actual connection id length */ static bool scil(uint8_t &scil, const uint8_t *packet, size_t packet_len); - static bool payload_length(size_t &payload_length, uint8_t *field_len, const uint8_t *packet, size_t packet_len); + static bool length(size_t &length, uint8_t *field_len, const uint8_t *packet, size_t packet_len); private: QUICPacketNumber _packet_number; diff --git a/iocore/net/quic/QUICPacketReceiveQueue.cc b/iocore/net/quic/QUICPacketReceiveQueue.cc index 4fd2ad3..bfd6c5f 100644 --- a/iocore/net/quic/QUICPacketReceiveQueue.cc +++ b/iocore/net/quic/QUICPacketReceiveQueue.cc @@ -36,18 +36,19 @@ is_vn(QUICVersion v) } static size_t -long_hdr_pkt_len(uint8_t *buf) +long_hdr_pkt_len(uint8_t *buf, size_t len) { uint8_t dcil, scil; - QUICPacketLongHeader::dcil(dcil, buf, 6); - QUICPacketLongHeader::scil(scil, buf, 6); + QUICPacketLongHeader::dcil(dcil, buf, len); + QUICPacketLongHeader::scil(scil, buf, len); - size_t payload_len_offset = LONG_HDR_OFFSET_CONNECTION_ID + dcil + scil; + size_t length_offset = LONG_HDR_OFFSET_CONNECTION_ID + dcil + scil; - size_t payload_len; - uint8_t payload_len_field_len; - QUICPacketLongHeader::payload_length(payload_len, &payload_len_field_len, buf, payload_len_offset + 4); - return payload_len_offset + payload_len_field_len + QUICTypeUtil::read_QUICPacketNumberLen(buf) + payload_len; + size_t length; + uint8_t length_field_len; + QUICPacketLongHeader::length(length, &length_field_len, buf, len); + + return length_offset + length_field_len + length; } QUICPacketReceiveQueue::QUICPacketReceiveQueue(QUICPacketFactory &packet_factory, QUICPacketNumberProtector &pn_protector) @@ -105,7 +106,7 @@ QUICPacketReceiveQueue::dequeue(QUICPacketCreationResult &result) result = QUICPacketCreationResult::UNSUPPORTED; pkt_len = remaining_len; } else { - pkt_len = long_hdr_pkt_len(this->_payload.get() + this->_offset); + pkt_len = long_hdr_pkt_len(this->_payload.get() + this->_offset, remaining_len); } } else { pkt_len = remaining_len;
