Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: update ngtcp2 and nghttp3, update quic impls #51291

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
795 changes: 530 additions & 265 deletions deps/ngtcp2/nghttp3/lib/includes/nghttp3/nghttp3.h

Large diffs are not rendered by default.

305 changes: 193 additions & 112 deletions deps/ngtcp2/nghttp3/lib/nghttp3_conn.c

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions deps/ngtcp2/nghttp3/lib/nghttp3_conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
/* NGHTTP3_CONN_FLAG_QPACK_DECODER_OPENED is set when a QPACK decoder
stream has opened. */
#define NGHTTP3_CONN_FLAG_QPACK_DECODER_OPENED 0x0008u
/* NGHTTP3_CONN_FLAG_SHUTDOWN_COMMENCED is set when graceful shutdown
has started. */
#define NGHTTP3_CONN_FLAG_SHUTDOWN_COMMENCED 0x0010u
/* NGHTTP3_CONN_FLAG_GOAWAY_RECVED indicates that GOAWAY frame has
received. */
#define NGHTTP3_CONN_FLAG_GOAWAY_RECVED 0x0020u
Expand All @@ -73,7 +76,7 @@ typedef struct nghttp3_chunk {
nghttp3_opl_entry oplent;
} nghttp3_chunk;

nghttp3_objalloc_def(chunk, nghttp3_chunk, oplent);
nghttp3_objalloc_decl(chunk, nghttp3_chunk, oplent);

struct nghttp3_conn {
nghttp3_objalloc out_chunk_objalloc;
Expand All @@ -90,7 +93,6 @@ struct nghttp3_conn {
void *user_data;
int server;
uint16_t flags;
uint64_t next_seq;

struct {
nghttp3_settings settings;
Expand All @@ -109,6 +111,10 @@ struct nghttp3_conn {
initiated bidirectional stream ID the remote endpoint can
issue. This field is used on server side only. */
uint64_t max_client_streams;
/* num_streams is the number of client initiated bidirectional
streams that are currently open. This field is for server
use only. */
size_t num_streams;
} bidi;
nghttp3_settings settings;
} remote;
Expand Down
26 changes: 7 additions & 19 deletions deps/ngtcp2/nghttp3/lib/nghttp3_conv.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <assert.h>

#include "nghttp3_str.h"
#include "nghttp3_unreachable.h"

int64_t nghttp3_get_varint(size_t *plen, const uint8_t *p) {
union {
Expand All @@ -38,7 +39,7 @@ int64_t nghttp3_get_varint(size_t *plen, const uint8_t *p) {
uint64_t n64;
} n;

*plen = 1u << (*p >> 6);
*plen = (size_t)(1u << (*p >> 6));

switch (*plen) {
case 1:
Expand All @@ -57,34 +58,25 @@ int64_t nghttp3_get_varint(size_t *plen, const uint8_t *p) {
return (int64_t)nghttp3_ntohl64(n.n64);
}

assert(0);
abort();
nghttp3_unreachable();
}

int64_t nghttp3_get_varint_fb(const uint8_t *p) { return *p & 0x3f; }

size_t nghttp3_get_varint_len(const uint8_t *p) { return 1u << (*p >> 6); }
size_t nghttp3_get_varintlen(const uint8_t *p) {
return (size_t)(1u << (*p >> 6));
}

uint8_t *nghttp3_put_uint64be(uint8_t *p, uint64_t n) {
n = nghttp3_htonl64(n);
return nghttp3_cpymem(p, (const uint8_t *)&n, sizeof(n));
}

uint8_t *nghttp3_put_uint48be(uint8_t *p, uint64_t n) {
n = nghttp3_htonl64(n);
return nghttp3_cpymem(p, ((const uint8_t *)&n) + 2, 6);
}

uint8_t *nghttp3_put_uint32be(uint8_t *p, uint32_t n) {
n = htonl(n);
return nghttp3_cpymem(p, (const uint8_t *)&n, sizeof(n));
}

uint8_t *nghttp3_put_uint24be(uint8_t *p, uint32_t n) {
n = htonl(n);
return nghttp3_cpymem(p, ((const uint8_t *)&n) + 1, 3);
}

uint8_t *nghttp3_put_uint16be(uint8_t *p, uint16_t n) {
n = htons(n);
return nghttp3_cpymem(p, (const uint8_t *)&n, sizeof(n));
Expand Down Expand Up @@ -112,7 +104,7 @@ uint8_t *nghttp3_put_varint(uint8_t *p, int64_t n) {
return rv;
}

size_t nghttp3_put_varint_len(int64_t n) {
size_t nghttp3_put_varintlen(int64_t n) {
if (n < 64) {
return 1;
}
Expand All @@ -129,7 +121,3 @@ size_t nghttp3_put_varint_len(int64_t n) {
uint64_t nghttp3_ord_stream_id(int64_t stream_id) {
return (uint64_t)(stream_id >> 2) + 1;
}

uint8_t nghttp3_pri_to_uint8(const nghttp3_pri *pri) {
return (uint8_t)((uint32_t)pri->inc << 7 | pri->urgency);
}
71 changes: 23 additions & 48 deletions deps/ngtcp2/nghttp3/lib/nghttp3_conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,11 @@
# include <sys/endian.h>
#endif /* HAVE_SYS_ENDIAN_H */

#include <nghttp3/nghttp3.h>
#if defined(__APPLE__)
# include <libkern/OSByteOrder.h>
#endif // __APPLE__

#if defined(HAVE_BSWAP_64) || \
(defined(HAVE_DECL_BSWAP_64) && HAVE_DECL_BSWAP_64 > 0)
# define nghttp3_bswap64 bswap_64
#else /* !HAVE_BSWAP_64 */
# define nghttp3_bswap64(N) \
((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32)))
#endif /* !HAVE_BSWAP_64 */
#include <nghttp3/nghttp3.h>

#if defined(HAVE_BE64TOH) || \
(defined(HAVE_DECL_BE64TOH) && HAVE_DECL_BE64TOH > 0)
Expand All @@ -69,6 +65,17 @@
# define nghttp3_ntohl64(N) (N)
# define nghttp3_htonl64(N) (N)
# else /* !WORDS_BIGENDIAN */
# if defined(HAVE_BSWAP_64) || \
(defined(HAVE_DECL_BSWAP_64) && HAVE_DECL_BSWAP_64 > 0)
# define nghttp3_bswap64 bswap_64
# elif defined(WIN32)
# define nghttp3_bswap64 _byteswap_uint64
# elif defined(__APPLE__)
# define nghttp3_bswap64 OSSwapInt64
# else /* !HAVE_BSWAP_64 && !WIN32 && !__APPLE__ */
# define nghttp3_bswap64(N) \
((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32)))
# endif /* !HAVE_BSWAP_64 && !WIN32 && !__APPLE__ */
# define nghttp3_ntohl64(N) nghttp3_bswap64(N)
# define nghttp3_htonl64(N) nghttp3_bswap64(N)
# endif /* !WORDS_BIGENDIAN */
Expand Down Expand Up @@ -106,17 +113,17 @@ STIN uint16_t htons(uint16_t hostshort) {
STIN uint32_t ntohl(uint32_t netlong) {
uint32_t res;
unsigned char *p = (unsigned char *)&netlong;
res = *p++ << 24;
res += *p++ << 16;
res += *p++ << 8;
res = (uint32_t)(*p++ << 24);
res += (uint32_t)(*p++ << 16);
res += (uint32_t)(*p++ << 8);
res += *p;
return res;
}

STIN uint16_t ntohs(uint16_t netshort) {
uint16_t res;
unsigned char *p = (unsigned char *)&netshort;
res = *p++ << 8;
res = (uint16_t)(*p++ << 8);
res += *p;
return res;
}
Expand All @@ -137,10 +144,10 @@ int64_t nghttp3_get_varint(size_t *plen, const uint8_t *p);
int64_t nghttp3_get_varint_fb(const uint8_t *p);

/*
* nghttp3_get_varint_len returns the required number of bytes to read
* nghttp3_get_varintlen returns the required number of bytes to read
* variable-length integer starting at |p|.
*/
size_t nghttp3_get_varint_len(const uint8_t *p);
size_t nghttp3_get_varintlen(const uint8_t *p);

/*
* nghttp3_put_uint64be writes |n| in host byte order in |p| in
Expand All @@ -149,27 +156,13 @@ size_t nghttp3_get_varint_len(const uint8_t *p);
*/
uint8_t *nghttp3_put_uint64be(uint8_t *p, uint64_t n);

/*
* nghttp3_put_uint48be writes |n| in host byte order in |p| in
* network byte order. It writes only least significant 48 bits. It
* returns the one beyond of the last written position.
*/
uint8_t *nghttp3_put_uint48be(uint8_t *p, uint64_t n);

/*
* nghttp3_put_uint32be writes |n| in host byte order in |p| in
* network byte order. It returns the one beyond of the last written
* position.
*/
uint8_t *nghttp3_put_uint32be(uint8_t *p, uint32_t n);

/*
* nghttp3_put_uint24be writes |n| in host byte order in |p| in
* network byte order. It writes only least significant 24 bits. It
* returns the one beyond of the last written position.
*/
uint8_t *nghttp3_put_uint24be(uint8_t *p, uint32_t n);

/*
* nghttp3_put_uint16be writes |n| in host byte order in |p| in
* network byte order. It returns the one beyond of the last written
Expand All @@ -184,10 +177,10 @@ uint8_t *nghttp3_put_uint16be(uint8_t *p, uint16_t n);
uint8_t *nghttp3_put_varint(uint8_t *p, int64_t n);

/*
* nghttp3_put_varint_len returns the required number of bytes to
* nghttp3_put_varintlen returns the required number of bytes to
* encode |n|.
*/
size_t nghttp3_put_varint_len(int64_t n);
size_t nghttp3_put_varintlen(int64_t n);

/*
* nghttp3_ord_stream_id returns the ordinal number of |stream_id|.
Expand All @@ -200,22 +193,4 @@ uint64_t nghttp3_ord_stream_id(int64_t stream_id);
*/
#define NGHTTP3_PRI_INC_MASK (1 << 7)

/*
* nghttp3_pri_to_uint8 encodes |pri| into uint8_t variable.
*/
uint8_t nghttp3_pri_to_uint8(const nghttp3_pri *pri);

/*
* nghttp3_pri_uint8_urgency extracts urgency from |PRI| which is
* supposed to be constructed by nghttp3_pri_to_uint8.
*/
#define nghttp3_pri_uint8_urgency(PRI) \
((uint32_t)((PRI) & ~NGHTTP3_PRI_INC_MASK))

/*
* nghttp3_pri_uint8_inc extracts inc from |PRI| which is supposed to
* be constructed by nghttp3_pri_to_uint8.
*/
#define nghttp3_pri_uint8_inc(PRI) (((PRI)&NGHTTP3_PRI_INC_MASK) != 0)

#endif /* NGHTTP3_CONV_H */
5 changes: 3 additions & 2 deletions deps/ngtcp2/nghttp3/lib/nghttp3_err.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ const char *nghttp3_strerror(int liberr) {
switch (liberr) {
case NGHTTP3_ERR_INVALID_ARGUMENT:
return "ERR_INVALID_ARGUMENT";
case NGHTTP3_ERR_NOBUF:
return "ERR_NOBUF";
case NGHTTP3_ERR_INVALID_STATE:
return "ERR_INVALID_STATE";
case NGHTTP3_ERR_WOULDBLOCK:
Expand Down Expand Up @@ -104,6 +102,9 @@ uint64_t nghttp3_err_infer_quic_app_error_code(int liberr) {
case NGHTTP3_ERR_H3_INTERNAL_ERROR:
case NGHTTP3_ERR_NOMEM:
case NGHTTP3_ERR_CALLBACK_FAILURE:
case NGHTTP3_ERR_QPACK_FATAL:
case NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE:
case NGHTTP3_ERR_STREAM_DATA_OVERFLOW:
return NGHTTP3_H3_INTERNAL_ERROR;
case NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM:
return NGHTTP3_H3_CLOSED_CRITICAL_STREAM;
Expand Down
47 changes: 23 additions & 24 deletions deps/ngtcp2/nghttp3/lib/nghttp3_frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ uint8_t *nghttp3_frame_write_hd(uint8_t *p, const nghttp3_frame_hd *hd) {
}

size_t nghttp3_frame_write_hd_len(const nghttp3_frame_hd *hd) {
return nghttp3_put_varint_len(hd->type) + nghttp3_put_varint_len(hd->length);
return nghttp3_put_varintlen(hd->type) + nghttp3_put_varintlen(hd->length);
}

uint8_t *nghttp3_frame_write_settings(uint8_t *p,
Expand All @@ -61,14 +61,14 @@ size_t nghttp3_frame_write_settings_len(int64_t *ppayloadlen,
size_t i;

for (i = 0; i < fr->niv; ++i) {
payloadlen += nghttp3_put_varint_len((int64_t)fr->iv[i].id) +
nghttp3_put_varint_len((int64_t)fr->iv[i].value);
payloadlen += nghttp3_put_varintlen((int64_t)fr->iv[i].id) +
nghttp3_put_varintlen((int64_t)fr->iv[i].value);
}

*ppayloadlen = (int64_t)payloadlen;

return nghttp3_put_varint_len(NGHTTP3_FRAME_SETTINGS) +
nghttp3_put_varint_len((int64_t)payloadlen) + payloadlen;
return nghttp3_put_varintlen(NGHTTP3_FRAME_SETTINGS) +
nghttp3_put_varintlen((int64_t)payloadlen) + payloadlen;
}

uint8_t *nghttp3_frame_write_goaway(uint8_t *p,
Expand All @@ -81,44 +81,34 @@ uint8_t *nghttp3_frame_write_goaway(uint8_t *p,

size_t nghttp3_frame_write_goaway_len(int64_t *ppayloadlen,
const nghttp3_frame_goaway *fr) {
size_t payloadlen = nghttp3_put_varint_len(fr->id);
size_t payloadlen = nghttp3_put_varintlen(fr->id);

*ppayloadlen = (int64_t)payloadlen;

return nghttp3_put_varint_len(NGHTTP3_FRAME_GOAWAY) +
nghttp3_put_varint_len((int64_t)payloadlen) + payloadlen;
return nghttp3_put_varintlen(NGHTTP3_FRAME_GOAWAY) +
nghttp3_put_varintlen((int64_t)payloadlen) + payloadlen;
}

uint8_t *
nghttp3_frame_write_priority_update(uint8_t *p,
const nghttp3_frame_priority_update *fr) {
p = nghttp3_frame_write_hd(p, &fr->hd);
p = nghttp3_put_varint(p, fr->pri_elem_id);

assert(fr->pri.urgency <= NGHTTP3_URGENCY_LOW);

*p++ = 'u';
*p++ = '=';
*p++ = (uint8_t)('0' + fr->pri.urgency);

if (fr->pri.inc) {
#define NGHTTP3_PRIORITY_INCREMENTAL ", i"
p = nghttp3_cpymem(p, (const uint8_t *)NGHTTP3_PRIORITY_INCREMENTAL,
sizeof(NGHTTP3_PRIORITY_INCREMENTAL) - 1);
if (fr->datalen) {
p = nghttp3_cpymem(p, fr->data, fr->datalen);
}

return p;
}

size_t nghttp3_frame_write_priority_update_len(
int64_t *ppayloadlen, const nghttp3_frame_priority_update *fr) {
size_t payloadlen = nghttp3_put_varint_len(fr->pri_elem_id) + sizeof("u=U") -
1 + (fr->pri.inc ? sizeof(", i") - 1 : 0);
size_t payloadlen = nghttp3_put_varintlen(fr->pri_elem_id) + fr->datalen;

*ppayloadlen = (int64_t)payloadlen;

return nghttp3_put_varint_len(fr->hd.type) +
nghttp3_put_varint_len((int64_t)payloadlen) + payloadlen;
return nghttp3_put_varintlen(fr->hd.type) +
nghttp3_put_varintlen((int64_t)payloadlen) + payloadlen;
}

int nghttp3_nva_copy(nghttp3_nv **pnva, const nghttp3_nv *nva, size_t nvlen,
Expand Down Expand Up @@ -164,11 +154,11 @@ int nghttp3_nva_copy(nghttp3_nv **pnva, const nghttp3_nv *nva, size_t nvlen,
} else {
if (nva[i].namelen) {
memcpy(data, nva[i].name, nva[i].namelen);
nghttp3_downcase(data, nva[i].namelen);
}
p->name = data;
p->namelen = nva[i].namelen;
data[p->namelen] = '\0';
nghttp3_downcase(p->name, p->namelen);
data += nva[i].namelen + 1;
}

Expand Down Expand Up @@ -202,3 +192,12 @@ void nghttp3_frame_headers_free(nghttp3_frame_headers *fr,

nghttp3_nva_del(fr->nva, mem);
}

void nghttp3_frame_priority_update_free(nghttp3_frame_priority_update *fr,
const nghttp3_mem *mem) {
if (fr == NULL) {
return;
}

nghttp3_mem_free(mem, fr->data);
}
Loading