Skip to content

Commit 28c0c78

Browse files
jasnellrichardlau
authored andcommitted
deps: update ngtcp2 and nghttp3
PR-URL: #51291 Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Jiawen Geng <[email protected]>
1 parent 8fd5a35 commit 28c0c78

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+10428
-8655
lines changed

deps/ngtcp2/nghttp3/lib/includes/nghttp3/nghttp3.h

Lines changed: 530 additions & 265 deletions
Large diffs are not rendered by default.

deps/ngtcp2/nghttp3/lib/nghttp3_conn.c

Lines changed: 193 additions & 112 deletions
Large diffs are not rendered by default.

deps/ngtcp2/nghttp3/lib/nghttp3_conn.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
/* NGHTTP3_CONN_FLAG_QPACK_DECODER_OPENED is set when a QPACK decoder
6363
stream has opened. */
6464
#define NGHTTP3_CONN_FLAG_QPACK_DECODER_OPENED 0x0008u
65+
/* NGHTTP3_CONN_FLAG_SHUTDOWN_COMMENCED is set when graceful shutdown
66+
has started. */
67+
#define NGHTTP3_CONN_FLAG_SHUTDOWN_COMMENCED 0x0010u
6568
/* NGHTTP3_CONN_FLAG_GOAWAY_RECVED indicates that GOAWAY frame has
6669
received. */
6770
#define NGHTTP3_CONN_FLAG_GOAWAY_RECVED 0x0020u
@@ -73,7 +76,7 @@ typedef struct nghttp3_chunk {
7376
nghttp3_opl_entry oplent;
7477
} nghttp3_chunk;
7578

76-
nghttp3_objalloc_def(chunk, nghttp3_chunk, oplent);
79+
nghttp3_objalloc_decl(chunk, nghttp3_chunk, oplent);
7780

7881
struct nghttp3_conn {
7982
nghttp3_objalloc out_chunk_objalloc;
@@ -90,7 +93,6 @@ struct nghttp3_conn {
9093
void *user_data;
9194
int server;
9295
uint16_t flags;
93-
uint64_t next_seq;
9496

9597
struct {
9698
nghttp3_settings settings;
@@ -109,6 +111,10 @@ struct nghttp3_conn {
109111
initiated bidirectional stream ID the remote endpoint can
110112
issue. This field is used on server side only. */
111113
uint64_t max_client_streams;
114+
/* num_streams is the number of client initiated bidirectional
115+
streams that are currently open. This field is for server
116+
use only. */
117+
size_t num_streams;
112118
} bidi;
113119
nghttp3_settings settings;
114120
} remote;

deps/ngtcp2/nghttp3/lib/nghttp3_conv.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <assert.h>
3030

3131
#include "nghttp3_str.h"
32+
#include "nghttp3_unreachable.h"
3233

3334
int64_t nghttp3_get_varint(size_t *plen, const uint8_t *p) {
3435
union {
@@ -38,7 +39,7 @@ int64_t nghttp3_get_varint(size_t *plen, const uint8_t *p) {
3839
uint64_t n64;
3940
} n;
4041

41-
*plen = 1u << (*p >> 6);
42+
*plen = (size_t)(1u << (*p >> 6));
4243

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

60-
assert(0);
61-
abort();
61+
nghttp3_unreachable();
6262
}
6363

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

66-
size_t nghttp3_get_varint_len(const uint8_t *p) { return 1u << (*p >> 6); }
66+
size_t nghttp3_get_varintlen(const uint8_t *p) {
67+
return (size_t)(1u << (*p >> 6));
68+
}
6769

6870
uint8_t *nghttp3_put_uint64be(uint8_t *p, uint64_t n) {
6971
n = nghttp3_htonl64(n);
7072
return nghttp3_cpymem(p, (const uint8_t *)&n, sizeof(n));
7173
}
7274

73-
uint8_t *nghttp3_put_uint48be(uint8_t *p, uint64_t n) {
74-
n = nghttp3_htonl64(n);
75-
return nghttp3_cpymem(p, ((const uint8_t *)&n) + 2, 6);
76-
}
77-
7875
uint8_t *nghttp3_put_uint32be(uint8_t *p, uint32_t n) {
7976
n = htonl(n);
8077
return nghttp3_cpymem(p, (const uint8_t *)&n, sizeof(n));
8178
}
8279

83-
uint8_t *nghttp3_put_uint24be(uint8_t *p, uint32_t n) {
84-
n = htonl(n);
85-
return nghttp3_cpymem(p, ((const uint8_t *)&n) + 1, 3);
86-
}
87-
8880
uint8_t *nghttp3_put_uint16be(uint8_t *p, uint16_t n) {
8981
n = htons(n);
9082
return nghttp3_cpymem(p, (const uint8_t *)&n, sizeof(n));
@@ -112,7 +104,7 @@ uint8_t *nghttp3_put_varint(uint8_t *p, int64_t n) {
112104
return rv;
113105
}
114106

115-
size_t nghttp3_put_varint_len(int64_t n) {
107+
size_t nghttp3_put_varintlen(int64_t n) {
116108
if (n < 64) {
117109
return 1;
118110
}
@@ -129,7 +121,3 @@ size_t nghttp3_put_varint_len(int64_t n) {
129121
uint64_t nghttp3_ord_stream_id(int64_t stream_id) {
130122
return (uint64_t)(stream_id >> 2) + 1;
131123
}
132-
133-
uint8_t nghttp3_pri_to_uint8(const nghttp3_pri *pri) {
134-
return (uint8_t)((uint32_t)pri->inc << 7 | pri->urgency);
135-
}

deps/ngtcp2/nghttp3/lib/nghttp3_conv.h

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,11 @@
5050
# include <sys/endian.h>
5151
#endif /* HAVE_SYS_ENDIAN_H */
5252

53-
#include <nghttp3/nghttp3.h>
53+
#if defined(__APPLE__)
54+
# include <libkern/OSByteOrder.h>
55+
#endif // __APPLE__
5456

55-
#if defined(HAVE_BSWAP_64) || \
56-
(defined(HAVE_DECL_BSWAP_64) && HAVE_DECL_BSWAP_64 > 0)
57-
# define nghttp3_bswap64 bswap_64
58-
#else /* !HAVE_BSWAP_64 */
59-
# define nghttp3_bswap64(N) \
60-
((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32)))
61-
#endif /* !HAVE_BSWAP_64 */
57+
#include <nghttp3/nghttp3.h>
6258

6359
#if defined(HAVE_BE64TOH) || \
6460
(defined(HAVE_DECL_BE64TOH) && HAVE_DECL_BE64TOH > 0)
@@ -69,6 +65,17 @@
6965
# define nghttp3_ntohl64(N) (N)
7066
# define nghttp3_htonl64(N) (N)
7167
# else /* !WORDS_BIGENDIAN */
68+
# if defined(HAVE_BSWAP_64) || \
69+
(defined(HAVE_DECL_BSWAP_64) && HAVE_DECL_BSWAP_64 > 0)
70+
# define nghttp3_bswap64 bswap_64
71+
# elif defined(WIN32)
72+
# define nghttp3_bswap64 _byteswap_uint64
73+
# elif defined(__APPLE__)
74+
# define nghttp3_bswap64 OSSwapInt64
75+
# else /* !HAVE_BSWAP_64 && !WIN32 && !__APPLE__ */
76+
# define nghttp3_bswap64(N) \
77+
((uint64_t)(ntohl((uint32_t)(N))) << 32 | ntohl((uint32_t)((N) >> 32)))
78+
# endif /* !HAVE_BSWAP_64 && !WIN32 && !__APPLE__ */
7279
# define nghttp3_ntohl64(N) nghttp3_bswap64(N)
7380
# define nghttp3_htonl64(N) nghttp3_bswap64(N)
7481
# endif /* !WORDS_BIGENDIAN */
@@ -106,17 +113,17 @@ STIN uint16_t htons(uint16_t hostshort) {
106113
STIN uint32_t ntohl(uint32_t netlong) {
107114
uint32_t res;
108115
unsigned char *p = (unsigned char *)&netlong;
109-
res = *p++ << 24;
110-
res += *p++ << 16;
111-
res += *p++ << 8;
116+
res = (uint32_t)(*p++ << 24);
117+
res += (uint32_t)(*p++ << 16);
118+
res += (uint32_t)(*p++ << 8);
112119
res += *p;
113120
return res;
114121
}
115122

116123
STIN uint16_t ntohs(uint16_t netshort) {
117124
uint16_t res;
118125
unsigned char *p = (unsigned char *)&netshort;
119-
res = *p++ << 8;
126+
res = (uint16_t)(*p++ << 8);
120127
res += *p;
121128
return res;
122129
}
@@ -137,10 +144,10 @@ int64_t nghttp3_get_varint(size_t *plen, const uint8_t *p);
137144
int64_t nghttp3_get_varint_fb(const uint8_t *p);
138145

139146
/*
140-
* nghttp3_get_varint_len returns the required number of bytes to read
147+
* nghttp3_get_varintlen returns the required number of bytes to read
141148
* variable-length integer starting at |p|.
142149
*/
143-
size_t nghttp3_get_varint_len(const uint8_t *p);
150+
size_t nghttp3_get_varintlen(const uint8_t *p);
144151

145152
/*
146153
* nghttp3_put_uint64be writes |n| in host byte order in |p| in
@@ -149,27 +156,13 @@ size_t nghttp3_get_varint_len(const uint8_t *p);
149156
*/
150157
uint8_t *nghttp3_put_uint64be(uint8_t *p, uint64_t n);
151158

152-
/*
153-
* nghttp3_put_uint48be writes |n| in host byte order in |p| in
154-
* network byte order. It writes only least significant 48 bits. It
155-
* returns the one beyond of the last written position.
156-
*/
157-
uint8_t *nghttp3_put_uint48be(uint8_t *p, uint64_t n);
158-
159159
/*
160160
* nghttp3_put_uint32be writes |n| in host byte order in |p| in
161161
* network byte order. It returns the one beyond of the last written
162162
* position.
163163
*/
164164
uint8_t *nghttp3_put_uint32be(uint8_t *p, uint32_t n);
165165

166-
/*
167-
* nghttp3_put_uint24be writes |n| in host byte order in |p| in
168-
* network byte order. It writes only least significant 24 bits. It
169-
* returns the one beyond of the last written position.
170-
*/
171-
uint8_t *nghttp3_put_uint24be(uint8_t *p, uint32_t n);
172-
173166
/*
174167
* nghttp3_put_uint16be writes |n| in host byte order in |p| in
175168
* network byte order. It returns the one beyond of the last written
@@ -184,10 +177,10 @@ uint8_t *nghttp3_put_uint16be(uint8_t *p, uint16_t n);
184177
uint8_t *nghttp3_put_varint(uint8_t *p, int64_t n);
185178

186179
/*
187-
* nghttp3_put_varint_len returns the required number of bytes to
180+
* nghttp3_put_varintlen returns the required number of bytes to
188181
* encode |n|.
189182
*/
190-
size_t nghttp3_put_varint_len(int64_t n);
183+
size_t nghttp3_put_varintlen(int64_t n);
191184

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

203-
/*
204-
* nghttp3_pri_to_uint8 encodes |pri| into uint8_t variable.
205-
*/
206-
uint8_t nghttp3_pri_to_uint8(const nghttp3_pri *pri);
207-
208-
/*
209-
* nghttp3_pri_uint8_urgency extracts urgency from |PRI| which is
210-
* supposed to be constructed by nghttp3_pri_to_uint8.
211-
*/
212-
#define nghttp3_pri_uint8_urgency(PRI) \
213-
((uint32_t)((PRI) & ~NGHTTP3_PRI_INC_MASK))
214-
215-
/*
216-
* nghttp3_pri_uint8_inc extracts inc from |PRI| which is supposed to
217-
* be constructed by nghttp3_pri_to_uint8.
218-
*/
219-
#define nghttp3_pri_uint8_inc(PRI) (((PRI)&NGHTTP3_PRI_INC_MASK) != 0)
220-
221196
#endif /* NGHTTP3_CONV_H */

deps/ngtcp2/nghttp3/lib/nghttp3_err.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ const char *nghttp3_strerror(int liberr) {
2828
switch (liberr) {
2929
case NGHTTP3_ERR_INVALID_ARGUMENT:
3030
return "ERR_INVALID_ARGUMENT";
31-
case NGHTTP3_ERR_NOBUF:
32-
return "ERR_NOBUF";
3331
case NGHTTP3_ERR_INVALID_STATE:
3432
return "ERR_INVALID_STATE";
3533
case NGHTTP3_ERR_WOULDBLOCK:
@@ -104,6 +102,9 @@ uint64_t nghttp3_err_infer_quic_app_error_code(int liberr) {
104102
case NGHTTP3_ERR_H3_INTERNAL_ERROR:
105103
case NGHTTP3_ERR_NOMEM:
106104
case NGHTTP3_ERR_CALLBACK_FAILURE:
105+
case NGHTTP3_ERR_QPACK_FATAL:
106+
case NGHTTP3_ERR_QPACK_HEADER_TOO_LARGE:
107+
case NGHTTP3_ERR_STREAM_DATA_OVERFLOW:
107108
return NGHTTP3_H3_INTERNAL_ERROR;
108109
case NGHTTP3_ERR_H3_CLOSED_CRITICAL_STREAM:
109110
return NGHTTP3_H3_CLOSED_CRITICAL_STREAM;

deps/ngtcp2/nghttp3/lib/nghttp3_frame.c

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ uint8_t *nghttp3_frame_write_hd(uint8_t *p, const nghttp3_frame_hd *hd) {
3838
}
3939

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

4444
uint8_t *nghttp3_frame_write_settings(uint8_t *p,
@@ -61,14 +61,14 @@ size_t nghttp3_frame_write_settings_len(int64_t *ppayloadlen,
6161
size_t i;
6262

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

6868
*ppayloadlen = (int64_t)payloadlen;
6969

70-
return nghttp3_put_varint_len(NGHTTP3_FRAME_SETTINGS) +
71-
nghttp3_put_varint_len((int64_t)payloadlen) + payloadlen;
70+
return nghttp3_put_varintlen(NGHTTP3_FRAME_SETTINGS) +
71+
nghttp3_put_varintlen((int64_t)payloadlen) + payloadlen;
7272
}
7373

7474
uint8_t *nghttp3_frame_write_goaway(uint8_t *p,
@@ -81,44 +81,34 @@ uint8_t *nghttp3_frame_write_goaway(uint8_t *p,
8181

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

8686
*ppayloadlen = (int64_t)payloadlen;
8787

88-
return nghttp3_put_varint_len(NGHTTP3_FRAME_GOAWAY) +
89-
nghttp3_put_varint_len((int64_t)payloadlen) + payloadlen;
88+
return nghttp3_put_varintlen(NGHTTP3_FRAME_GOAWAY) +
89+
nghttp3_put_varintlen((int64_t)payloadlen) + payloadlen;
9090
}
9191

9292
uint8_t *
9393
nghttp3_frame_write_priority_update(uint8_t *p,
9494
const nghttp3_frame_priority_update *fr) {
9595
p = nghttp3_frame_write_hd(p, &fr->hd);
9696
p = nghttp3_put_varint(p, fr->pri_elem_id);
97-
98-
assert(fr->pri.urgency <= NGHTTP3_URGENCY_LOW);
99-
100-
*p++ = 'u';
101-
*p++ = '=';
102-
*p++ = (uint8_t)('0' + fr->pri.urgency);
103-
104-
if (fr->pri.inc) {
105-
#define NGHTTP3_PRIORITY_INCREMENTAL ", i"
106-
p = nghttp3_cpymem(p, (const uint8_t *)NGHTTP3_PRIORITY_INCREMENTAL,
107-
sizeof(NGHTTP3_PRIORITY_INCREMENTAL) - 1);
97+
if (fr->datalen) {
98+
p = nghttp3_cpymem(p, fr->data, fr->datalen);
10899
}
109100

110101
return p;
111102
}
112103

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

118108
*ppayloadlen = (int64_t)payloadlen;
119109

120-
return nghttp3_put_varint_len(fr->hd.type) +
121-
nghttp3_put_varint_len((int64_t)payloadlen) + payloadlen;
110+
return nghttp3_put_varintlen(fr->hd.type) +
111+
nghttp3_put_varintlen((int64_t)payloadlen) + payloadlen;
122112
}
123113

124114
int nghttp3_nva_copy(nghttp3_nv **pnva, const nghttp3_nv *nva, size_t nvlen,
@@ -164,11 +154,11 @@ int nghttp3_nva_copy(nghttp3_nv **pnva, const nghttp3_nv *nva, size_t nvlen,
164154
} else {
165155
if (nva[i].namelen) {
166156
memcpy(data, nva[i].name, nva[i].namelen);
157+
nghttp3_downcase(data, nva[i].namelen);
167158
}
168159
p->name = data;
169160
p->namelen = nva[i].namelen;
170161
data[p->namelen] = '\0';
171-
nghttp3_downcase(p->name, p->namelen);
172162
data += nva[i].namelen + 1;
173163
}
174164

@@ -202,3 +192,12 @@ void nghttp3_frame_headers_free(nghttp3_frame_headers *fr,
202192

203193
nghttp3_nva_del(fr->nva, mem);
204194
}
195+
196+
void nghttp3_frame_priority_update_free(nghttp3_frame_priority_update *fr,
197+
const nghttp3_mem *mem) {
198+
if (fr == NULL) {
199+
return;
200+
}
201+
202+
nghttp3_mem_free(mem, fr->data);
203+
}

0 commit comments

Comments
 (0)