This is an automated email from the ASF dual-hosted git repository.

masaori pushed a commit to branch quic-latest
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/quic-latest by this push:
     new b5f3490  draft-08: Support new frame format of NEW_CONNECTION_ID and 
STOP_SENDING
b5f3490 is described below

commit b5f3490db7566330f36c49991ded136841593994
Author: Masaori Koshiba <masa...@apache.org>
AuthorDate: Thu Dec 14 15:37:05 2017 +0900

    draft-08: Support new frame format of NEW_CONNECTION_ID and STOP_SENDING
---
 iocore/net/quic/QUICFrame.cc           | 56 +++++++++++++++++++++++++---------
 iocore/net/quic/QUICFrame.h            | 19 +++++++++---
 iocore/net/quic/test/test_QUICFrame.cc | 21 +++++++------
 3 files changed, 68 insertions(+), 28 deletions(-)

diff --git a/iocore/net/quic/QUICFrame.cc b/iocore/net/quic/QUICFrame.cc
index 6127485..fd237ad 100644
--- a/iocore/net/quic/QUICFrame.cc
+++ b/iocore/net/quic/QUICFrame.cc
@@ -1355,12 +1355,6 @@ QUICStreamIdBlockedFrame::_get_stream_id_field_length() 
const
 // NEW_CONNECTION_ID frame
 //
 
-QUICNewConnectionIdFrame::QUICNewConnectionIdFrame(uint16_t sequence, 
QUICConnectionId connection_i,
-                                                   QUICStatelessResetToken 
stateless_reset_token)
-  : _sequence(sequence), _connection_id(connection_i), 
_stateless_reset_token(stateless_reset_token)
-{
-}
-
 QUICFrameType
 QUICNewConnectionIdFrame::type() const
 {
@@ -1370,7 +1364,7 @@ QUICNewConnectionIdFrame::type() const
 size_t
 QUICNewConnectionIdFrame::size() const
 {
-  return 11;
+  return sizeof(QUICFrameType) + this->_get_sequence_field_length() + 
sizeof(QUICConnectionId) + 16;
 }
 
 void
@@ -1380,7 +1374,7 @@ QUICNewConnectionIdFrame::store(uint8_t *buf, size_t 
*len) const
   uint8_t *p = buf;
   *p         = static_cast<uint8_t>(QUICFrameType::NEW_CONNECTION_ID);
   ++p;
-  QUICTypeUtil::write_uint_as_nbytes(this->_sequence, 2, p, &n);
+  QUICTypeUtil::write_QUICVariableInt(this->_sequence, p, &n);
   p += n;
   QUICTypeUtil::write_QUICConnectionId(this->_connection_id, 8, p, &n);
   p += n;
@@ -1390,11 +1384,11 @@ QUICNewConnectionIdFrame::store(uint8_t *buf, size_t 
*len) const
   *len = p - buf;
 }
 
-uint16_t
+uint64_t
 QUICNewConnectionIdFrame::sequence() const
 {
   if (this->_buf) {
-    return QUICTypeUtil::read_nbytes_as_uint(this->_buf + 1, 2);
+    return QUICTypeUtil::read_QUICVariableInt(this->_buf + 
sizeof(QUICFrameType));
   } else {
     return this->_sequence;
   }
@@ -1404,7 +1398,7 @@ QUICConnectionId
 QUICNewConnectionIdFrame::connection_id() const
 {
   if (this->_buf) {
-    return QUICTypeUtil::read_QUICConnectionId(this->_buf + 3, 8);
+    return QUICTypeUtil::read_QUICConnectionId(this->_buf + 
this->_get_connection_id_field_offset(), 8);
   } else {
     return this->_connection_id;
   }
@@ -1414,12 +1408,28 @@ QUICStatelessResetToken
 QUICNewConnectionIdFrame::stateless_reset_token() const
 {
   if (this->_buf) {
-    return QUICStatelessResetToken(this->_buf + 11);
+    return QUICStatelessResetToken(this->_buf + 
this->_get_connection_id_field_offset() + sizeof(QUICConnectionId));
   } else {
     return this->_stateless_reset_token;
   }
 }
 
+size_t
+QUICNewConnectionIdFrame::_get_sequence_field_length() const
+{
+  if (this->_buf) {
+    return QUICVariableInt::size(this->_buf + sizeof(QUICFrameType));
+  } else {
+    return QUICVariableInt::size(this->_sequence);
+  }
+}
+
+size_t
+QUICNewConnectionIdFrame::_get_connection_id_field_offset() const
+{
+  return sizeof(QUICFrameType) + this->_get_sequence_field_length();
+}
+
 //
 // STOP_SENDING frame
 //
@@ -1438,7 +1448,7 @@ QUICStopSendingFrame::type() const
 size_t
 QUICStopSendingFrame::size() const
 {
-  return 7;
+  return sizeof(QUICFrameType) + this->_get_stream_id_field_length() + 
sizeof(QUICAppErrorCode);
 }
 
 void
@@ -1460,7 +1470,7 @@ QUICAppErrorCode
 QUICStopSendingFrame::error_code() const
 {
   if (this->_buf) {
-    return QUICTypeUtil::read_QUICAppErrorCode(this->_buf + 5);
+    return QUICTypeUtil::read_QUICAppErrorCode(this->_buf + 
this->_get_error_code_field_offset());
   } else {
     return this->_error_code;
   }
@@ -1470,12 +1480,28 @@ QUICStreamId
 QUICStopSendingFrame::stream_id() const
 {
   if (this->_buf) {
-    return QUICTypeUtil::read_QUICStreamId(this->_buf + 1);
+    return QUICTypeUtil::read_QUICStreamId(this->_buf + sizeof(QUICFrameType));
   } else {
     return this->_stream_id;
   }
 }
 
+size_t
+QUICStopSendingFrame::_get_stream_id_field_length() const
+{
+  if (this->_buf) {
+    return QUICVariableInt::size(this->_buf + sizeof(QUICFrameType));
+  } else {
+    return QUICVariableInt::size(this->_stream_id);
+  }
+}
+
+size_t
+QUICStopSendingFrame::_get_error_code_field_offset() const
+{
+  return sizeof(QUICFrameType) + this->_get_stream_id_field_length();
+}
+
 //
 // QUICRetransmissionFrame
 //
diff --git a/iocore/net/quic/QUICFrame.h b/iocore/net/quic/QUICFrame.h
index 319e64c..151d317 100644
--- a/iocore/net/quic/QUICFrame.h
+++ b/iocore/net/quic/QUICFrame.h
@@ -462,16 +462,22 @@ class QUICNewConnectionIdFrame : public QUICFrame
 public:
   QUICNewConnectionIdFrame() : QUICFrame() {}
   QUICNewConnectionIdFrame(const uint8_t *buf, size_t len) : QUICFrame(buf, 
len) {}
-  QUICNewConnectionIdFrame(uint16_t sequence, QUICConnectionId connection_id, 
QUICStatelessResetToken stateless_reset_token);
+  QUICNewConnectionIdFrame(uint64_t seq, QUICConnectionId id, 
QUICStatelessResetToken token)
+      : _sequence(seq), _connection_id(id), _stateless_reset_token(token) {};
+
   virtual QUICFrameType type() const override;
   virtual size_t size() const override;
   virtual void store(uint8_t *buf, size_t *len) const override;
-  uint16_t sequence() const;
+
+  uint64_t sequence() const;
   QUICConnectionId connection_id() const;
   QUICStatelessResetToken stateless_reset_token() const;
 
 private:
-  uint16_t _sequence              = 0;
+  size_t _get_sequence_field_length() const;
+  size_t _get_connection_id_field_offset() const;
+
+  uint64_t _sequence              = 0;
   QUICConnectionId _connection_id = 0;
   QUICStatelessResetToken _stateless_reset_token;
 };
@@ -486,15 +492,20 @@ public:
   QUICStopSendingFrame() : QUICFrame() {}
   QUICStopSendingFrame(const uint8_t *buf, size_t len) : QUICFrame(buf, len) {}
   QUICStopSendingFrame(QUICStreamId stream_id, QUICAppErrorCode error_code);
+
   virtual QUICFrameType type() const override;
   virtual size_t size() const override;
   virtual void store(uint8_t *buf, size_t *len) const override;
+
   QUICStreamId stream_id() const;
   QUICAppErrorCode error_code() const;
 
 private:
+  size_t _get_stream_id_field_length() const;
+  size_t _get_error_code_field_offset() const;
+
   QUICStreamId _stream_id = 0;
-  QUICAppErrorCode _error_code;
+  QUICAppErrorCode _error_code = 0;
 };
 
 using QUICFrameDeleterFunc = void (*)(QUICFrame *p);
diff --git a/iocore/net/quic/test/test_QUICFrame.cc 
b/iocore/net/quic/test/test_QUICFrame.cc
index 6ae828f..280aae4 100644
--- a/iocore/net/quic/test/test_QUICFrame.cc
+++ b/iocore/net/quic/test/test_QUICFrame.cc
@@ -757,14 +757,14 @@ TEST_CASE("Load NewConnectionId Frame", "[quic]")
 {
   uint8_t buf1[] = {
     0x0b,                                           // Type
-    0x01, 0x02,                                     // Sequence
+    0x41, 0x02,                                     // Sequence
     0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, // Connection ID
     0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, // Stateless Reset Token
     0x80, 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0,
   };
   std::shared_ptr<const QUICFrame> frame1 = QUICFrameFactory::create(buf1, 
sizeof(buf1));
   CHECK(frame1->type() == QUICFrameType::NEW_CONNECTION_ID);
-  CHECK(frame1->size() == 11);
+  CHECK(frame1->size() == 27);
   std::shared_ptr<const QUICNewConnectionIdFrame> newConnectionIdFrame1 =
     std::dynamic_pointer_cast<const QUICNewConnectionIdFrame>(frame1);
   CHECK(newConnectionIdFrame1 != nullptr);
@@ -775,13 +775,16 @@ TEST_CASE("Load NewConnectionId Frame", "[quic]")
 
 TEST_CASE("Store NewConnectionId Frame", "[quic]")
 {
-  uint8_t buf[65535];
+  uint8_t buf[32];
   size_t len;
 
-  uint8_t expected[] = {0x0b,                                           // Type
-                        0x01, 0x02,                                     // 
Sequence
-                        0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, // 
Connection ID
-                        0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 
0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
+  uint8_t expected[] = {
+    0x0b,                                           // Type
+    0x41, 0x02,                                     // Sequence
+    0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, // Connection ID
+    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, // Stateless Reset Token
+    0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+  };
   QUICNewConnectionIdFrame newConnectionIdFrame(0x0102, 0x1122334455667788ULL, 
{expected + 11});
   newConnectionIdFrame.store(buf, &len);
   CHECK(len == 27);
@@ -792,7 +795,7 @@ TEST_CASE("Load STOP_SENDING Frame", "[quic]")
 {
   uint8_t buf[] = {
     0x0c,                   // Type
-    0x12, 0x34, 0x56, 0x78, // Stream ID
+    0x92, 0x34, 0x56, 0x78, // Stream ID
     0x00, 0x01,             // Error Code
   };
   std::shared_ptr<const QUICFrame> frame = QUICFrameFactory::create(buf, 
sizeof(buf));
@@ -812,7 +815,7 @@ TEST_CASE("Store STOP_SENDING Frame", "[quic]")
 
   uint8_t expected[] = {
     0x0c,                   // Type
-    0x12, 0x34, 0x56, 0x78, // Stream ID
+    0x92, 0x34, 0x56, 0x78, // Stream ID
     0x00, 0x01,             // Error Code
   };
   QUICStopSendingFrame stop_sending_frame(0x12345678, 
static_cast<QUICAppErrorCode>(0x01));

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>'].

Reply via email to