trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From masa...@apache.org
Subject [trafficserver] branch quic-latest updated: Cleanup QUICTransportParameterValue
Date Wed, 23 Aug 2017 01:38:12 GMT
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 a86fca0  Cleanup QUICTransportParameterValue
a86fca0 is described below

commit a86fca03b73533a4bcdfc2f58e9bd17413791a9f
Author: Masaori Koshiba <masaori@apache.org>
AuthorDate: Wed Aug 23 10:37:54 2017 +0900

    Cleanup QUICTransportParameterValue
---
 iocore/net/QUICNetVConnection.cc                   | 29 ++++---------
 iocore/net/quic/QUICTransportParameters.cc         | 49 +++++++++++++++++++---
 iocore/net/quic/QUICTransportParameters.h          | 21 ++++++----
 .../net/quic/test/test_QUICTransportParameters.cc  | 44 ++++++++-----------
 4 files changed, 81 insertions(+), 62 deletions(-)

diff --git a/iocore/net/QUICNetVConnection.cc b/iocore/net/QUICNetVConnection.cc
index d841232..3fc88e0 100644
--- a/iocore/net/QUICNetVConnection.cc
+++ b/iocore/net/QUICNetVConnection.cc
@@ -110,34 +110,19 @@ QUICNetVConnection::start(SSL_CTX *ssl_ctx)
   // MUSTs
   QUICTransportParametersInEncryptedExtensions *tp = new QUICTransportParametersInEncryptedExtensions();
 
-  size_t max_stream_data_buf_len     = 4;
-  ats_unique_buf max_stream_data_buf = ats_unique_malloc(max_stream_data_buf_len);
-  QUICTypeUtil::write_uint_as_nbytes(params->initial_max_stream_data(), max_stream_data_buf_len,
max_stream_data_buf.get(),
-                                     &max_stream_data_buf_len);
   tp->add(QUICTransportParameterId::INITIAL_MAX_STREAM_DATA,
           std::unique_ptr<QUICTransportParameterValue>(
-            new QUICTransportParameterValue(std::move(max_stream_data_buf), max_stream_data_buf_len)));
-
-  size_t max_data_buf_len     = 4;
-  ats_unique_buf max_data_buf = ats_unique_malloc(max_data_buf_len);
-  QUICTypeUtil::write_uint_as_nbytes(params->initial_max_data(), max_data_buf_len, max_data_buf.get(),
&max_data_buf_len);
-  tp->add(QUICTransportParameterId::INITIAL_MAX_DATA,
-          std::unique_ptr<QUICTransportParameterValue>(new QUICTransportParameterValue(std::move(max_data_buf),
max_data_buf_len)));
-
-  size_t max_stream_id_buf_len     = 4;
-  ats_unique_buf max_stream_id_buf = ats_unique_malloc(max_stream_id_buf_len);
-  QUICTypeUtil::write_uint_as_nbytes(params->initial_max_stream_id(), max_stream_id_buf_len,
max_stream_id_buf.get(),
-                                     &max_stream_id_buf_len);
+            new QUICTransportParameterValue(params->initial_max_stream_data(), sizeof(params->initial_max_stream_data()))));
+
+  tp->add(QUICTransportParameterId::INITIAL_MAX_DATA, std::unique_ptr<QUICTransportParameterValue>(new
QUICTransportParameterValue(
+                                                        params->initial_max_data(), sizeof(params->initial_max_data()))));
+
   tp->add(QUICTransportParameterId::INITIAL_MAX_STREAM_ID,
           std::unique_ptr<QUICTransportParameterValue>(
-            new QUICTransportParameterValue(std::move(max_stream_id_buf), max_stream_id_buf_len)));
+            new QUICTransportParameterValue(params->initial_max_stream_id(), sizeof(params->initial_max_stream_id()))));
 
-  size_t idle_timeout_buf_len     = 2;
-  ats_unique_buf idle_timeout_buf = ats_unique_malloc(idle_timeout_buf_len);
-  QUICTypeUtil::write_uint_as_nbytes(params->no_activity_timeout_in(), idle_timeout_buf_len,
idle_timeout_buf.get(),
-                                     &idle_timeout_buf_len);
   tp->add(QUICTransportParameterId::IDLE_TIMEOUT, std::unique_ptr<QUICTransportParameterValue>(new
QUICTransportParameterValue(
-                                                    std::move(idle_timeout_buf), idle_timeout_buf_len)));
+                                                    params->no_activity_timeout_in(),
sizeof(uint16_t))));
 
   tp->add_version(QUIC_SUPPORTED_VERSIONS[0]);
   // MAYs
diff --git a/iocore/net/quic/QUICTransportParameters.cc b/iocore/net/quic/QUICTransportParameters.cc
index c8638c4..7365084 100644
--- a/iocore/net/quic/QUICTransportParameters.cc
+++ b/iocore/net/quic/QUICTransportParameters.cc
@@ -29,6 +29,35 @@
 
 const static int TRANSPORT_PARAMETERS_MAXIMUM_SIZE = 65535;
 
+//
+// QUICTransportParameterValue
+//
+QUICTransportParameterValue::QUICTransportParameterValue(ats_unique_buf d, uint16_t l) :
_data(std::move(d)), _len(l){};
+
+QUICTransportParameterValue::QUICTransportParameterValue(uint64_t raw_data, uint16_t l)
+{
+  this->_data = ats_unique_malloc(l);
+  size_t len  = 0;
+  QUICTypeUtil::write_uint_as_nbytes(raw_data, l, this->_data.get(), &len);
+  this->_len = len;
+};
+
+const uint8_t *
+QUICTransportParameterValue::data() const
+{
+  return this->_data.get();
+}
+
+uint16_t
+QUICTransportParameterValue::len() const
+{
+  return this->_len;
+}
+
+//
+// QUICTransportParameters
+//
+
 QUICTransportParameters::QUICTransportParameters(const uint8_t *buf, size_t len)
 {
   this->_buf = ats_unique_malloc(len);
@@ -57,8 +86,8 @@ QUICTransportParameters::get(QUICTransportParameterId tpid, uint16_t &len)
const
   } else {
     auto p = this->_parameters.find(QUICTransportParameterId::INITIAL_MAX_STREAM_DATA);
     if (p != this->_parameters.end()) {
-      len = p->second->len;
-      return p->second->data.get();
+      len = p->second->len();
+      return p->second->data();
     }
   }
 
@@ -109,11 +138,11 @@ QUICTransportParameters::store(uint8_t *buf, uint16_t *len) const
     p[1] = it.first & 0xff;
     p += 2;
     const QUICTransportParameterValue *value = it.second.get();
-    p[0]                                     = (value->len & 0xff00) >> 8;
-    p[1]                                     = value->len & 0xff;
+    p[0]                                     = (value->len() & 0xff00) >> 8;
+    p[1]                                     = value->len() & 0xff;
     p += 2;
-    memcpy(p, value->data.get(), value->len);
-    p += value->len;
+    memcpy(p, value->data(), value->len());
+    p += value->len();
   }
 
   ptrdiff_t n = p - parameters_size - sizeof(uint16_t);
@@ -124,6 +153,10 @@ QUICTransportParameters::store(uint8_t *buf, uint16_t *len) const
   *len = (p - buf);
 }
 
+//
+// QUICTransportParametersInClientHello
+//
+
 void
 QUICTransportParametersInClientHello::_store(uint8_t *buf, uint16_t *len) const
 {
@@ -154,6 +187,10 @@ QUICTransportParametersInClientHello::initial_version() const
   return QUICTypeUtil::read_QUICVersion(this->_buf.get() + sizeof(QUICVersion));
 }
 
+//
+// QUICTransportParametersInEncryptedExtensions
+//
+
 void
 QUICTransportParametersInEncryptedExtensions::_store(uint8_t *buf, uint16_t *len) const
 {
diff --git a/iocore/net/quic/QUICTransportParameters.h b/iocore/net/quic/QUICTransportParameters.h
index 57814de..a32261f 100644
--- a/iocore/net/quic/QUICTransportParameters.h
+++ b/iocore/net/quic/QUICTransportParameters.h
@@ -65,14 +65,19 @@ private:
   uint16_t _id = 0;
 };
 
-typedef struct _QUICTransportParameterValue {
-  _QUICTransportParameterValue(){};
-  _QUICTransportParameterValue(ats_unique_buf str)
-    : data(std::move(str)), len(str ? strlen(reinterpret_cast<const char *>(str.get()))
: 0){};
-  _QUICTransportParameterValue(ats_unique_buf _data, uint16_t _len) : data(std::move(_data)),
len(_len){};
-  ats_unique_buf data = {nullptr, [](void *p) { ats_free(p); }};
-  uint16_t len        = 0;
-} QUICTransportParameterValue;
+class QUICTransportParameterValue
+{
+public:
+  QUICTransportParameterValue(ats_unique_buf d, uint16_t l);
+  QUICTransportParameterValue(uint64_t raw_data, uint16_t l);
+
+  const uint8_t *data() const;
+  uint16_t len() const;
+
+private:
+  ats_unique_buf _data = {nullptr, [](void *p) { ats_free(p); }};
+  uint16_t _len        = 0;
+};
 
 class QUICTransportParameters
 {
diff --git a/iocore/net/quic/test/test_QUICTransportParameters.cc b/iocore/net/quic/test/test_QUICTransportParameters.cc
index 4977db2..adf3daf 100644
--- a/iocore/net/quic/test/test_QUICTransportParameters.cc
+++ b/iocore/net/quic/test/test_QUICTransportParameters.cc
@@ -92,19 +92,15 @@ TEST_CASE("QUICTransportParametersInClientHello_write", "[quic]")
 
   QUICTransportParametersInClientHello params_in_ch(0x01020304, 0x05060708);
 
-  size_t max_stream_data_buf_len     = 4;
-  ats_unique_buf max_stream_data_buf = ats_unique_malloc(max_stream_data_buf_len);
-  memcpy(max_stream_data_buf.get(), "\x11\x22\x33\x44", max_stream_data_buf_len);
-  params_in_ch.add(QUICTransportParameterId::INITIAL_MAX_STREAM_DATA,
-                   std::unique_ptr<QUICTransportParameterValue>(
-                     new QUICTransportParameterValue(std::move(max_stream_data_buf), max_stream_data_buf_len)));
-
-  uint16_t max_packet_size_buf_len   = 2;
-  ats_unique_buf max_packet_size_buf = ats_unique_malloc(max_packet_size_buf_len);
-  memcpy(max_packet_size_buf.get(), "\xab\xcd", max_packet_size_buf_len);
-  params_in_ch.add(QUICTransportParameterId::MAX_PACKET_SIZE,
-                   std::unique_ptr<QUICTransportParameterValue>(
-                     new QUICTransportParameterValue(std::move(max_packet_size_buf), max_packet_size_buf_len)));
+  uint32_t max_stream_data = 0x11223344;
+  params_in_ch.add(
+    QUICTransportParameterId::INITIAL_MAX_STREAM_DATA,
+    std::unique_ptr<QUICTransportParameterValue>(new QUICTransportParameterValue(max_stream_data,
sizeof(max_stream_data))));
+
+  uint16_t max_packet_size = 0xabcd;
+  params_in_ch.add(
+    QUICTransportParameterId::MAX_PACKET_SIZE,
+    std::unique_ptr<QUICTransportParameterValue>(new QUICTransportParameterValue(max_packet_size,
sizeof(max_packet_size))));
 
   params_in_ch.store(buf, &len);
   CHECK(len == 24);
@@ -182,19 +178,15 @@ TEST_CASE("QUICTransportParametersEncryptedExtensions_write", "[quic]")
 
   QUICTransportParametersInEncryptedExtensions params_in_ee;
 
-  size_t max_stream_data_buf_len     = 4;
-  ats_unique_buf max_stream_data_buf = ats_unique_malloc(max_stream_data_buf_len);
-  memcpy(max_stream_data_buf.get(), "\x11\x22\x33\x44", max_stream_data_buf_len);
-  params_in_ee.add(QUICTransportParameterId::INITIAL_MAX_STREAM_DATA,
-                   std::unique_ptr<QUICTransportParameterValue>(
-                     new QUICTransportParameterValue(std::move(max_stream_data_buf), max_stream_data_buf_len)));
-
-  uint16_t max_packet_size_buf_len   = 2;
-  ats_unique_buf max_packet_size_buf = ats_unique_malloc(max_packet_size_buf_len);
-  memcpy(max_packet_size_buf.get(), "\xab\xcd", max_packet_size_buf_len);
-  params_in_ee.add(QUICTransportParameterId::MAX_PACKET_SIZE,
-                   std::unique_ptr<QUICTransportParameterValue>(
-                     new QUICTransportParameterValue(std::move(max_packet_size_buf), max_packet_size_buf_len)));
+  uint32_t max_stream_data = 0x11223344;
+  params_in_ee.add(
+    QUICTransportParameterId::INITIAL_MAX_STREAM_DATA,
+    std::unique_ptr<QUICTransportParameterValue>(new QUICTransportParameterValue(max_stream_data,
sizeof(max_stream_data))));
+
+  uint16_t max_packet_size = 0xabcd;
+  params_in_ee.add(
+    QUICTransportParameterId::MAX_PACKET_SIZE,
+    std::unique_ptr<QUICTransportParameterValue>(new QUICTransportParameterValue(max_packet_size,
sizeof(max_packet_size))));
 
   params_in_ee.add_version(0x01020304);
   params_in_ee.add_version(0x05060708);

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

Mime
View raw message