From 1b94c86b961d902510658cbc6b286a1d7b414e5a Mon Sep 17 00:00:00 2001
From: Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>
Date: Wed, 27 May 2020 08:32:46 +0900
Subject: [PATCH] Change ngtcp2_conn_submit_new_token signature

---
 examples/server.cc           | 11 +++++------
 lib/includes/ngtcp2/ngtcp2.h |  9 +++++----
 lib/ngtcp2_conn.c            | 13 +++++++------
 3 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/examples/server.cc b/examples/server.cc
index 0d5d0d76..70aa4dae 100644
--- a/examples/server.cc
+++ b/examples/server.cc
@@ -822,10 +822,10 @@ int Handler::handshake_completed() {
     }
   }
 
-  std::array<uint8_t, MAX_TOKENLEN> tokenbuf;
-  size_t tokenlen = tokenbuf.size();
+  std::array<uint8_t, MAX_TOKENLEN> token;
+  size_t tokenlen = token.size();
 
-  if (server_->generate_token(tokenbuf.data(), tokenlen, &remote_addr_.su.sa,
+  if (server_->generate_token(token.data(), tokenlen, &remote_addr_.su.sa,
                               remote_addr_.len) != 0) {
     if (!config.quiet) {
       std::cerr << "Unable to generate token" << std::endl;
@@ -833,9 +833,8 @@ int Handler::handshake_completed() {
     return 0;
   }
 
-  ngtcp2_vec token{tokenbuf.data(), tokenlen};
-
-  if (auto rv = ngtcp2_conn_submit_new_token(conn_, &token); rv != 0) {
+  if (auto rv = ngtcp2_conn_submit_new_token(conn_, token.data(), tokenlen);
+      rv != 0) {
     if (!config.quiet) {
       std::cerr << "ngtcp2_conn_submit_new_token: " << ngtcp2_strerror(rv)
                 << std::endl;
diff --git a/lib/includes/ngtcp2/ngtcp2.h b/lib/includes/ngtcp2/ngtcp2.h
index c205a50e..5e5c2703 100644
--- a/lib/includes/ngtcp2/ngtcp2.h
+++ b/lib/includes/ngtcp2/ngtcp2.h
@@ -2786,10 +2786,10 @@ ngtcp2_conn_submit_crypto_data(ngtcp2_conn *conn,
  *
  * `ngtcp2_conn_submit_new_token` submits address validation token.
  * It is sent in NEW_TOKEN frame.  Only server can call this function.
- * |token| must not be empty.
+ * |tokenlen| must not be 0.
  *
- * This function makes a copy of the buffer pointed by |token|->base
- * of length |token|->len.
+ * This function makes a copy of the buffer pointed by |token| of
+ * length |tokenlen|.
  *
  * This function returns 0 if it succeeds, or one of the following
  * negative error codes:
@@ -2798,7 +2798,8 @@ ngtcp2_conn_submit_crypto_data(ngtcp2_conn *conn,
  *     Out of memory.
  */
 NGTCP2_EXTERN int ngtcp2_conn_submit_new_token(ngtcp2_conn *conn,
-                                               const ngtcp2_vec *token);
+                                               const uint8_t *token,
+                                               size_t tokenlen);
 
 /**
  * @function
diff --git a/lib/ngtcp2_conn.c b/lib/ngtcp2_conn.c
index 7289eddc..4e85cffd 100644
--- a/lib/ngtcp2_conn.c
+++ b/lib/ngtcp2_conn.c
@@ -9251,16 +9251,17 @@ int ngtcp2_conn_submit_crypto_data(ngtcp2_conn *conn,
   return 0;
 }
 
-int ngtcp2_conn_submit_new_token(ngtcp2_conn *conn, const ngtcp2_vec *token) {
+int ngtcp2_conn_submit_new_token(ngtcp2_conn *conn, const uint8_t *token,
+                                 size_t tokenlen) {
   int rv;
   ngtcp2_frame_chain *nfrc;
   uint8_t *p;
 
   assert(conn->server);
-  assert(token->base);
-  assert(token->len);
+  assert(token);
+  assert(tokenlen);
 
-  rv = ngtcp2_frame_chain_extralen_new(&nfrc, token->len, conn->mem);
+  rv = ngtcp2_frame_chain_extralen_new(&nfrc, tokenlen, conn->mem);
   if (rv != 0) {
     return rv;
   }
@@ -9268,9 +9269,9 @@ int ngtcp2_conn_submit_new_token(ngtcp2_conn *conn, const ngtcp2_vec *token) {
   nfrc->fr.type = NGTCP2_FRAME_NEW_TOKEN;
 
   p = (uint8_t *)nfrc + sizeof(*nfrc);
-  memcpy(p, token->base, token->len);
+  memcpy(p, token, tokenlen);
 
-  ngtcp2_vec_init(&nfrc->fr.new_token.token, p, token->len);
+  ngtcp2_vec_init(&nfrc->fr.new_token.token, p, tokenlen);
 
   nfrc->next = conn->pktns.tx.frq;
   conn->pktns.tx.frq = nfrc;
-- 
GitLab