You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by ma...@apache.org on 2017/12/05 01:58:07 UTC
[trafficserver] 02/02: Fix a bug that QUICPacket doesn't return
packet size correctly
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 d7cce37efb9cb68361793bf62e965fba263c2fe3
Author: Masakazu Kitajo <ma...@apache.org>
AuthorDate: Tue Dec 5 10:57:33 2017 +0900
Fix a bug that QUICPacket doesn't return packet size correctly
---
iocore/net/quic/QUICPacket.cc | 6 +++-
iocore/net/quic/test/test_QUICPacket.cc | 51 +++++++++++++++++++++++++++++++--
2 files changed, 54 insertions(+), 3 deletions(-)
diff --git a/iocore/net/quic/QUICPacket.cc b/iocore/net/quic/QUICPacket.cc
index 9bc6f51..bb8c08a 100644
--- a/iocore/net/quic/QUICPacket.cc
+++ b/iocore/net/quic/QUICPacket.cc
@@ -534,7 +534,11 @@ uint16_t
QUICPacket::size() const
{
// This includes not only header size and payload size but also AEAD tag length
- return this->_header->packet_size();
+ uint16_t size = this->_header->packet_size();
+ if (size == 0) {
+ size = this->header_size() + this->payload_size();
+ }
+ return size;
}
uint16_t
diff --git a/iocore/net/quic/test/test_QUICPacket.cc b/iocore/net/quic/test/test_QUICPacket.cc
index e2d7863..8a39c57 100644
--- a/iocore/net/quic/test/test_QUICPacket.cc
+++ b/iocore/net/quic/test/test_QUICPacket.cc
@@ -27,7 +27,7 @@
TEST_CASE("QUICPacketHeader", "[quic]")
{
- SECTION("Long Header")
+ SECTION("Long Header (load)")
{
const uint8_t input[] = {
0x81, // Long header, Type
@@ -41,12 +41,35 @@ TEST_CASE("QUICPacketHeader", "[quic]")
CHECK(header->size() == 17);
CHECK(header->packet_size() == 19);
CHECK(header->type() == QUICPacketType::VERSION_NEGOTIATION);
+ CHECK(header->has_connection_id() == true);
CHECK(header->connection_id() == 0x0102030405060708);
CHECK(header->packet_number() == 0x12345678);
+ CHECK(header->has_version() == true);
CHECK(header->version() == 0x11223344);
+ CHECK(header->has_key_phase() == false);
}
- SECTION("Short Header")
+ SECTION("Long Header (build)")
+ {
+ const uint8_t expected[] = {0x11, 0x22, 0x33, 0x44, 0x55};
+ ats_unique_buf payload = ats_unique_malloc(sizeof(expected));
+ memcpy(payload.get(), expected, sizeof(expected));
+
+ QUICPacketHeader *header = QUICPacketHeader::build(QUICPacketType::CLIENT_INITIAL, 0x0102030405060708, 0x12345678, 0,
+ 0xa0a0a0a0, std::move(payload), 32);
+
+ CHECK(header->size() == 17);
+ CHECK(header->has_key_phase() == false);
+ CHECK(header->packet_size() == 0);
+ CHECK(header->type() == QUICPacketType::CLIENT_INITIAL);
+ CHECK(header->has_connection_id() == true);
+ CHECK(header->connection_id() == 0x0102030405060708);
+ CHECK(header->packet_number() == 0x12345678);
+ CHECK(header->has_version() == true);
+ CHECK(header->version() == 0xa0a0a0a0);
+ }
+
+ SECTION("Short Header (load)")
{
const uint8_t input[] = {
0x43, // Short header, with Connection ID, KeyPhse 0, Type
@@ -58,8 +81,32 @@ TEST_CASE("QUICPacketHeader", "[quic]")
QUICPacketHeader *header = QUICPacketHeader::load(input, sizeof(input), 0);
CHECK(header->size() == 13);
CHECK(header->packet_size() == 15);
+ CHECK(header->has_key_phase() == true);
+ CHECK(header->key_phase() == QUICKeyPhase::PHASE_0);
+ CHECK(header->has_connection_id() == true);
+ CHECK(header->connection_id() == 0x0102030405060708);
+ CHECK(header->packet_number() == 0x12345678);
+ CHECK(header->has_version() == false);
+ }
+
+ SECTION("Short Header (build)")
+ {
+ const uint8_t expected[] = {0x11, 0x22, 0x33, 0x44, 0x55};
+ ats_unique_buf payload = ats_unique_malloc(sizeof(expected));
+ memcpy(payload.get(), expected, sizeof(expected));
+
+ QUICPacketHeader *header = QUICPacketHeader::build(QUICPacketType::PROTECTED, QUICKeyPhase::PHASE_0, 0x0102030405060708,
+ 0x12345678, 0, std::move(payload), 32);
+
+ CHECK(header->size() == 13);
+ CHECK(header->packet_size() == 0);
+ CHECK(header->has_key_phase() == true);
+ CHECK(header->key_phase() == QUICKeyPhase::PHASE_0);
+ CHECK(header->type() == QUICPacketType::PROTECTED);
+ CHECK(header->has_connection_id() == true);
CHECK(header->connection_id() == 0x0102030405060708);
CHECK(header->packet_number() == 0x12345678);
+ CHECK(header->has_version() == false);
}
}
--
To stop receiving notification emails like this one, please contact
"commits@trafficserver.apache.org" <co...@trafficserver.apache.org>.