diff --git a/examples/server.cc b/examples/server.cc index 0d5d0d7691ad1037dc61011d9b34797491555c9d..70aa4daeb4aa92905f3546df5651dc3b98a19240 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 c205a50efd61ddb8112741acf562aab02f175e5f..5e5c27038ec8dfa2e07d761c1199395101f6febc 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 7289eddc1024338ccf76e74b77b7d5ef49ab7adc..4e85cffdac106d25ad3b8399c093e6e8f2b8c366 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;