diff options
author | robot-contrib <[email protected]> | 2025-05-01 08:17:53 +0300 |
---|---|---|
committer | robot-contrib <[email protected]> | 2025-05-01 08:57:12 +0300 |
commit | 0d5861bb6d9b5e7f39cbdc17456909efab426bd9 (patch) | |
tree | 9414709cf2454ae612ed7a34c34a8047436d6932 | |
parent | a24e6ced72db4dbcfba43e2f8c630986b2c9c38b (diff) |
Update contrib/libs/nghttp3 to 1.9.0
commit_hash:404c76a4ce7d29b42f27d1a0cd72424faad00313
-rw-r--r-- | contrib/libs/nghttp3/.yandex_meta/licenses.list.txt | 1 | ||||
-rw-r--r-- | contrib/libs/nghttp3/.yandex_meta/override.nix | 4 | ||||
-rw-r--r-- | contrib/libs/nghttp3/AUTHORS | 1 | ||||
-rw-r--r-- | contrib/libs/nghttp3/lib/includes/nghttp3/version.h | 4 | ||||
-rw-r--r-- | contrib/libs/nghttp3/lib/nghttp3_buf.c | 12 | ||||
-rw-r--r-- | contrib/libs/nghttp3/lib/nghttp3_buf.h | 13 | ||||
-rw-r--r-- | contrib/libs/nghttp3/lib/nghttp3_conn.c | 12 | ||||
-rw-r--r-- | contrib/libs/nghttp3/lib/nghttp3_conv.c | 2 | ||||
-rw-r--r-- | contrib/libs/nghttp3/lib/nghttp3_conv.h | 6 | ||||
-rw-r--r-- | contrib/libs/nghttp3/lib/nghttp3_http.c | 13 | ||||
-rw-r--r-- | contrib/libs/nghttp3/lib/nghttp3_pq.c | 16 | ||||
-rw-r--r-- | contrib/libs/nghttp3/lib/nghttp3_pq.h | 11 | ||||
-rw-r--r-- | contrib/libs/nghttp3/lib/nghttp3_ringbuf.c | 5 | ||||
-rw-r--r-- | contrib/libs/nghttp3/lib/nghttp3_stream.c | 188 | ||||
-rw-r--r-- | contrib/libs/nghttp3/lib/nghttp3_stream.h | 3 | ||||
-rw-r--r-- | contrib/libs/nghttp3/ya.make | 4 |
16 files changed, 123 insertions, 172 deletions
diff --git a/contrib/libs/nghttp3/.yandex_meta/licenses.list.txt b/contrib/libs/nghttp3/.yandex_meta/licenses.list.txt index 104d3c77e92..4d518d5a5f5 100644 --- a/contrib/libs/nghttp3/.yandex_meta/licenses.list.txt +++ b/contrib/libs/nghttp3/.yandex_meta/licenses.list.txt @@ -92,6 +92,7 @@ Deel Dimitris Apostolou Don Don Olmstead +Dusk_NM02 Force Charlie James M Snell Javier Blazquez diff --git a/contrib/libs/nghttp3/.yandex_meta/override.nix b/contrib/libs/nghttp3/.yandex_meta/override.nix index d6430760a17..8b0b32c4e75 100644 --- a/contrib/libs/nghttp3/.yandex_meta/override.nix +++ b/contrib/libs/nghttp3/.yandex_meta/override.nix @@ -1,6 +1,6 @@ pkgs: attrs: with pkgs; with attrs; rec { pname = "nghttp3"; - version = "1.8.0"; + version = "1.9.0"; nativeBuildInputs = [ cmake pkg-config autoconf libtool automake @@ -10,6 +10,6 @@ pkgs: attrs: with pkgs; with attrs; rec { src = fetchurl { url = "https://github.com/ngtcp2/nghttp3/releases/download/v${version}/nghttp3-${version}.tar.xz"; - hash = "sha256-qd0olwl35oAqPq8s+urm0PrmDI0sDyxM5gADanmY7po="; + hash = "sha256-sbUxz2rlyTZqvqLTMZ5KyTL9ZMByyKr9ac9ilXM84So="; }; } diff --git a/contrib/libs/nghttp3/AUTHORS b/contrib/libs/nghttp3/AUTHORS index e6bbb8b9293..1993a2aa4bc 100644 --- a/contrib/libs/nghttp3/AUTHORS +++ b/contrib/libs/nghttp3/AUTHORS @@ -9,6 +9,7 @@ Deel Dimitris Apostolou Don Don Olmstead +Dusk_NM02 Force Charlie James M Snell Javier Blazquez diff --git a/contrib/libs/nghttp3/lib/includes/nghttp3/version.h b/contrib/libs/nghttp3/lib/includes/nghttp3/version.h index 32290b4f35b..4ebb92cf0d9 100644 --- a/contrib/libs/nghttp3/lib/includes/nghttp3/version.h +++ b/contrib/libs/nghttp3/lib/includes/nghttp3/version.h @@ -31,7 +31,7 @@ * * Version number of the nghttp3 library release. */ -#define NGHTTP3_VERSION "1.8.0" +#define NGHTTP3_VERSION "1.9.0" /** * @macro @@ -41,6 +41,6 @@ * number, 8 bits for minor and 8 bits for patch. Version 1.2.3 * becomes 0x010203. */ -#define NGHTTP3_VERSION_NUM 0x010800 +#define NGHTTP3_VERSION_NUM 0x010900 #endif /* !defined(NGHTTP3_VERSION_H) */ diff --git a/contrib/libs/nghttp3/lib/nghttp3_buf.c b/contrib/libs/nghttp3/lib/nghttp3_buf.c index aae075a73cc..57cf744680e 100644 --- a/contrib/libs/nghttp3/lib/nghttp3_buf.c +++ b/contrib/libs/nghttp3/lib/nghttp3_buf.c @@ -50,6 +50,10 @@ size_t nghttp3_buf_cap(const nghttp3_buf *buf) { return (size_t)(buf->end - buf->begin); } +size_t nghttp3_buf_offset(const nghttp3_buf *buf) { + return (size_t)(buf->pos - buf->begin); +} + void nghttp3_buf_reset(nghttp3_buf *buf) { buf->pos = buf->last = buf->begin; } int nghttp3_buf_reserve(nghttp3_buf *buf, size_t size, const nghttp3_mem *mem) { @@ -87,4 +91,12 @@ void nghttp3_typed_buf_init(nghttp3_typed_buf *tbuf, const nghttp3_buf *buf, nghttp3_buf_type type) { tbuf->buf = *buf; tbuf->type = type; + tbuf->buf.begin = tbuf->buf.pos; +} + +void nghttp3_typed_buf_shared_init(nghttp3_typed_buf *tbuf, + const nghttp3_buf *chunk) { + tbuf->buf = *chunk; + tbuf->type = NGHTTP3_BUF_TYPE_SHARED; + tbuf->buf.begin = tbuf->buf.pos = tbuf->buf.last; } diff --git a/contrib/libs/nghttp3/lib/nghttp3_buf.h b/contrib/libs/nghttp3/lib/nghttp3_buf.h index 9fa067de91b..c7abd0d3af7 100644 --- a/contrib/libs/nghttp3/lib/nghttp3_buf.h +++ b/contrib/libs/nghttp3/lib/nghttp3_buf.h @@ -42,6 +42,12 @@ void nghttp3_buf_wrap_init(nghttp3_buf *buf, uint8_t *src, size_t len); */ size_t nghttp3_buf_cap(const nghttp3_buf *buf); +/* + * nghttp3_buf_offset returns the distance from tbuf->begin to + * tbuf->pos. In other words, it returns buf->pos - buf->begin. + */ +size_t nghttp3_buf_offset(const nghttp3_buf *buf); + int nghttp3_buf_reserve(nghttp3_buf *buf, size_t size, const nghttp3_mem *mem); /* @@ -69,6 +75,13 @@ typedef struct nghttp3_typed_buf { void nghttp3_typed_buf_init(nghttp3_typed_buf *tbuf, const nghttp3_buf *buf, nghttp3_buf_type type); +/* + * nghttp3_typed_buf_shared_init initializes |tbuf| of type + * NGHTTP3_BUF_TYPE_SHARED. + */ +void nghttp3_typed_buf_shared_init(nghttp3_typed_buf *tbuf, + const nghttp3_buf *chunk); + void nghttp3_typed_buf_free(nghttp3_typed_buf *tbuf); #endif /* !defined(NGHTTP3_BUF_H) */ diff --git a/contrib/libs/nghttp3/lib/nghttp3_conn.c b/contrib/libs/nghttp3/lib/nghttp3_conn.c index 66b403fad78..04ffc9a0886 100644 --- a/contrib/libs/nghttp3/lib/nghttp3_conn.c +++ b/contrib/libs/nghttp3/lib/nghttp3_conn.c @@ -460,14 +460,8 @@ nghttp3_ssize nghttp3_conn_read_stream(nghttp3_conn *conn, int64_t stream_id, return NGHTTP3_ERR_H3_STREAM_CREATION_ERROR; } } else if (conn->server) { - if (nghttp3_client_stream_bidi(stream_id)) { - if (stream->rx.hstate == NGHTTP3_HTTP_STATE_NONE) { - stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL; - stream->tx.hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL; - } - } else { - assert(nghttp3_client_stream_uni(stream_id)); - } + assert(nghttp3_client_stream_bidi(stream_id) || + nghttp3_client_stream_uni(stream_id)); } else { assert(nghttp3_client_stream_bidi(stream_id) || nghttp3_server_stream_uni(stream_id)); @@ -1794,6 +1788,8 @@ conn_on_priority_update_stream(nghttp3_conn *conn, stream->node.pri = fr->pri; stream->flags |= NGHTTP3_STREAM_FLAG_PRIORITY_UPDATE_RECVED; + stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL; + stream->tx.hstate = NGHTTP3_HTTP_STATE_REQ_INITIAL; return 0; } diff --git a/contrib/libs/nghttp3/lib/nghttp3_conv.c b/contrib/libs/nghttp3/lib/nghttp3_conv.c index 6439a6d7829..9b32ca3f405 100644 --- a/contrib/libs/nghttp3/lib/nghttp3_conv.c +++ b/contrib/libs/nghttp3/lib/nghttp3_conv.c @@ -66,8 +66,6 @@ const uint8_t *nghttp3_get_varint(int64_t *dest, const uint8_t *p) { } } -int64_t nghttp3_get_varint_fb(const uint8_t *p) { return *p & 0x3f; } - size_t nghttp3_get_varintlen(const uint8_t *p) { return (size_t)(1u << (*p >> 6)); } diff --git a/contrib/libs/nghttp3/lib/nghttp3_conv.h b/contrib/libs/nghttp3/lib/nghttp3_conv.h index 40f5d4de782..f70802ce600 100644 --- a/contrib/libs/nghttp3/lib/nghttp3_conv.h +++ b/contrib/libs/nghttp3/lib/nghttp3_conv.h @@ -136,12 +136,6 @@ STIN uint16_t ntohs(uint16_t netshort) { const uint8_t *nghttp3_get_varint(int64_t *dest, const uint8_t *p); /* - * nghttp3_get_varint_fb reads first byte of encoded variable-length - * integer from |p|. - */ -int64_t nghttp3_get_varint_fb(const uint8_t *p); - -/* * nghttp3_get_varintlen returns the required number of bytes to read * variable-length integer starting at |p|. */ diff --git a/contrib/libs/nghttp3/lib/nghttp3_http.c b/contrib/libs/nghttp3/lib/nghttp3_http.c index be3dadfb453..9a8f06ea11d 100644 --- a/contrib/libs/nghttp3/lib/nghttp3_http.c +++ b/contrib/libs/nghttp3/lib/nghttp3_http.c @@ -69,11 +69,11 @@ static int64_t parse_uint(const uint8_t *s, size_t len) { } for (i = 0; i < len; ++i) { if ('0' <= s[i] && s[i] <= '9') { - if (n > INT64_MAX / 10) { + if (n > (int64_t)NGHTTP3_MAX_VARINT / 10) { return -1; } n *= 10; - if (n > INT64_MAX - (s[i] - '0')) { + if (n > (int64_t)NGHTTP3_MAX_VARINT - (s[i] - '0')) { return -1; } n += s[i] - '0'; @@ -549,6 +549,9 @@ static int http_request_on_header(nghttp3_http_state *http, break; case NGHTTP3_QPACK_TOKEN_PRIORITY: if (!nghttp3_check_header_value(nv->value->base, nv->value->len)) { + http->flags &= ~NGHTTP3_HTTP_FLAG_PRIORITY; + http->flags |= NGHTTP3_HTTP_FLAG_BAD_PRIORITY; + return NGHTTP3_ERR_REMOVE_HTTP_HEADER; } @@ -992,7 +995,11 @@ int nghttp3_check_header_value(const uint8_t *value, size_t len) { case 0: return 1; case 1: - return !is_ws(*value); + if (is_ws(*value)) { + return 0; + } + + break; default: if (is_ws(*value) || is_ws(*(value + len - 1))) { return 0; diff --git a/contrib/libs/nghttp3/lib/nghttp3_pq.c b/contrib/libs/nghttp3/lib/nghttp3_pq.c index feefcd6fc71..e35bcac4e43 100644 --- a/contrib/libs/nghttp3/lib/nghttp3_pq.c +++ b/contrib/libs/nghttp3/lib/nghttp3_pq.c @@ -164,20 +164,4 @@ int nghttp3_pq_empty(const nghttp3_pq *pq) { return pq->length == 0; } size_t nghttp3_pq_size(const nghttp3_pq *pq) { return pq->length; } -int nghttp3_pq_each(const nghttp3_pq *pq, nghttp3_pq_item_cb fun, void *arg) { - size_t i; - - if (pq->length == 0) { - return 0; - } - - for (i = 0; i < pq->length; ++i) { - if ((*fun)(pq->q[i], arg)) { - return 1; - } - } - - return 0; -} - void nghttp3_pq_clear(nghttp3_pq *pq) { pq->length = 0; } diff --git a/contrib/libs/nghttp3/lib/nghttp3_pq.h b/contrib/libs/nghttp3/lib/nghttp3_pq.h index 3813b529473..c4e47b16708 100644 --- a/contrib/libs/nghttp3/lib/nghttp3_pq.h +++ b/contrib/libs/nghttp3/lib/nghttp3_pq.h @@ -112,17 +112,6 @@ int nghttp3_pq_empty(const nghttp3_pq *pq); */ size_t nghttp3_pq_size(const nghttp3_pq *pq); -typedef int (*nghttp3_pq_item_cb)(nghttp3_pq_entry *item, void *arg); - -/* - * nghttp3_pq_each applies |fun| to each item in |pq|. The |arg| is - * passed as arg parameter to callback function. This function must - * not change the ordering key. If the return value from callback is - * nonzero, this function returns 1 immediately without iterating - * remaining items. Otherwise this function returns 0. - */ -int nghttp3_pq_each(const nghttp3_pq *pq, nghttp3_pq_item_cb fun, void *arg); - /* * nghttp3_pq_remove removes |item| from |pq|. |pq| must contain * |item| otherwise the behavior is undefined. diff --git a/contrib/libs/nghttp3/lib/nghttp3_ringbuf.c b/contrib/libs/nghttp3/lib/nghttp3_ringbuf.c index 85c2e03f877..ccd1d3e99ab 100644 --- a/contrib/libs/nghttp3/lib/nghttp3_ringbuf.c +++ b/contrib/libs/nghttp3/lib/nghttp3_ringbuf.c @@ -35,8 +35,9 @@ #ifndef NDEBUG static int ispow2(size_t n) { -# if defined(_MSC_VER) && !defined(__clang__) && \ - (defined(_M_ARM) || (defined(_M_ARM64) && _MSC_VER < 1941)) +# if defined(DISABLE_POPCNT) || \ + (defined(_MSC_VER) && !defined(__clang__) && \ + (defined(_M_ARM) || (defined(_M_ARM64) && _MSC_VER < 1941))) return n && !(n & (n - 1)); # elif defined(WIN32) return 1 == __popcnt((unsigned int)n); diff --git a/contrib/libs/nghttp3/lib/nghttp3_stream.c b/contrib/libs/nghttp3/lib/nghttp3_stream.c index f34c63575e1..9ae9d4850d0 100644 --- a/contrib/libs/nghttp3/lib/nghttp3_stream.c +++ b/contrib/libs/nghttp3/lib/nghttp3_stream.c @@ -181,42 +181,45 @@ void nghttp3_stream_read_state_reset(nghttp3_stream_read_state *rstate) { nghttp3_ssize nghttp3_read_varint(nghttp3_varint_read_state *rvint, const uint8_t *begin, const uint8_t *end, int fin) { - const uint8_t *orig_begin = begin; - size_t len; + size_t len, vlen; + uint8_t *p; assert(begin != end); if (rvint->left == 0) { assert(rvint->acc == 0); - len = nghttp3_get_varintlen(begin); - if (len <= (size_t)(end - begin)) { + vlen = nghttp3_get_varintlen(begin); + len = nghttp3_min_size(vlen, (size_t)(end - begin)); + if (vlen <= len) { nghttp3_get_varint(&rvint->acc, begin); - return (nghttp3_ssize)len; + return (nghttp3_ssize)vlen; } if (fin) { return NGHTTP3_ERR_INVALID_ARGUMENT; } - rvint->acc = nghttp3_get_varint_fb(begin++); - rvint->left = len - 1; - } + p = (uint8_t *)&rvint->acc + (sizeof(rvint->acc) - vlen); + memcpy(p, begin, len); + *p &= 0x3f; + rvint->left = vlen - len; - len = nghttp3_min_size(rvint->left, (size_t)(end - begin)); - end = begin + len; - - for (; begin != end;) { - rvint->acc = (rvint->acc << 8) + *begin++; + return (nghttp3_ssize)len; } + len = nghttp3_min_size(rvint->left, (size_t)(end - begin)); + p = (uint8_t *)&rvint->acc + (sizeof(rvint->acc) - rvint->left); + memcpy(p, begin, len); rvint->left -= len; - if (fin && rvint->left) { + if (rvint->left == 0) { + rvint->acc = (int64_t)nghttp3_ntohl64((uint64_t)rvint->acc); + } else if (fin) { return NGHTTP3_ERR_INVALID_ARGUMENT; } - return (nghttp3_ssize)(begin - orig_begin); + return (nghttp3_ssize)len; } int nghttp3_stream_frq_add(nghttp3_stream *stream, @@ -301,12 +304,6 @@ int nghttp3_stream_fill_outq(nghttp3_stream *stream) { return 0; } -static void typed_buf_shared_init(nghttp3_typed_buf *tbuf, - const nghttp3_buf *chunk) { - nghttp3_typed_buf_init(tbuf, chunk, NGHTTP3_BUF_TYPE_SHARED); - tbuf->buf.pos = tbuf->buf.last; -} - int nghttp3_stream_write_stream_type(nghttp3_stream *stream) { size_t len = nghttp3_put_varintlen((int64_t)stream->type); nghttp3_buf *chunk; @@ -319,7 +316,7 @@ int nghttp3_stream_write_stream_type(nghttp3_stream *stream) { } chunk = nghttp3_stream_get_chunk(stream); - typed_buf_shared_init(&tbuf, chunk); + nghttp3_typed_buf_shared_init(&tbuf, chunk); chunk->last = nghttp3_put_varint(chunk->last, (int64_t)stream->type); tbuf.buf.last = chunk->last; @@ -380,7 +377,7 @@ int nghttp3_stream_write_settings(nghttp3_stream *stream, } chunk = nghttp3_stream_get_chunk(stream); - typed_buf_shared_init(&tbuf, chunk); + nghttp3_typed_buf_shared_init(&tbuf, chunk); chunk->last = nghttp3_frame_write_settings(chunk->last, &fr.settings); @@ -405,7 +402,7 @@ int nghttp3_stream_write_goaway(nghttp3_stream *stream, } chunk = nghttp3_stream_get_chunk(stream); - typed_buf_shared_init(&tbuf, chunk); + nghttp3_typed_buf_shared_init(&tbuf, chunk); chunk->last = nghttp3_frame_write_goaway(chunk->last, fr); @@ -430,7 +427,7 @@ int nghttp3_stream_write_priority_update(nghttp3_stream *stream, } chunk = nghttp3_stream_get_chunk(stream); - typed_buf_shared_init(&tbuf, chunk); + nghttp3_typed_buf_shared_init(&tbuf, chunk); chunk->last = nghttp3_frame_write_priority_update(chunk->last, fr); @@ -471,7 +468,7 @@ int nghttp3_stream_write_header_block(nghttp3_stream *stream, rv = nghttp3_qpack_encoder_encode(qenc, &pbuf, rbuf, ebuf, stream->node.id, nva, nvlen); if (rv != 0) { - goto fail; + return rv; } pbuflen = nghttp3_buf_len(&pbuf); @@ -489,11 +486,11 @@ int nghttp3_stream_write_header_block(nghttp3_stream *stream, rv = nghttp3_stream_ensure_chunk(stream, len); if (rv != 0) { - goto fail; + return rv; } chunk = nghttp3_stream_get_chunk(stream); - typed_buf_shared_init(&tbuf, chunk); + nghttp3_typed_buf_shared_init(&tbuf, chunk); chunk->last = nghttp3_frame_write_hd(chunk->last, &hd); @@ -505,13 +502,13 @@ int nghttp3_stream_write_header_block(nghttp3_stream *stream, rv = nghttp3_stream_outq_add(stream, &tbuf); if (rv != 0) { - goto fail; + return rv; } nghttp3_typed_buf_init(&tbuf, rbuf, NGHTTP3_BUF_TYPE_PRIVATE); rv = nghttp3_stream_outq_add(stream, &tbuf); if (rv != 0) { - goto fail; + return rv; } nghttp3_buf_init(rbuf); } else if (rbuflen) { @@ -520,7 +517,7 @@ int nghttp3_stream_write_header_block(nghttp3_stream *stream, rv = nghttp3_stream_outq_add(stream, &tbuf); if (rv != 0) { - goto fail; + return rv; } nghttp3_buf_reset(rbuf); } @@ -539,18 +536,18 @@ int nghttp3_stream_write_header_block(nghttp3_stream *stream, rv = nghttp3_stream_ensure_chunk(qenc_stream, ebuflen); if (rv != 0) { - goto fail; + return rv; } chunk = nghttp3_stream_get_chunk(qenc_stream); - typed_buf_shared_init(&tbuf, chunk); + nghttp3_typed_buf_shared_init(&tbuf, chunk); chunk->last = nghttp3_cpymem(chunk->last, ebuf->pos, ebuflen); tbuf.buf.last = chunk->last; rv = nghttp3_stream_outq_add(qenc_stream, &tbuf); if (rv != 0) { - goto fail; + return rv; } nghttp3_buf_reset(ebuf); } @@ -560,10 +557,6 @@ int nghttp3_stream_write_header_block(nghttp3_stream *stream, assert(0 == nghttp3_buf_len(ebuf)); return 0; - -fail: - - return rv; } int nghttp3_stream_write_data(nghttp3_stream *stream, int *peof, @@ -642,7 +635,7 @@ int nghttp3_stream_write_data(nghttp3_stream *stream, int *peof, } chunk = nghttp3_stream_get_chunk(stream); - typed_buf_shared_init(&tbuf, chunk); + nghttp3_typed_buf_shared_init(&tbuf, chunk); chunk->last = nghttp3_frame_write_hd(chunk->last, &hd); @@ -697,7 +690,7 @@ int nghttp3_stream_write_qpack_decoder_stream(nghttp3_stream *stream) { } chunk = nghttp3_stream_get_chunk(stream); - typed_buf_shared_init(&tbuf, chunk); + nghttp3_typed_buf_shared_init(&tbuf, chunk); nghttp3_qpack_decoder_write_decoder(qdec, chunk); @@ -724,17 +717,16 @@ int nghttp3_stream_outq_add(nghttp3_stream *stream, if (len) { dest = nghttp3_ringbuf_get(outq, len - 1); if (dest->type == tbuf->type && dest->type == NGHTTP3_BUF_TYPE_SHARED && - dest->buf.begin == tbuf->buf.begin && dest->buf.last == tbuf->buf.pos) { + dest->buf.end == tbuf->buf.end && dest->buf.last == tbuf->buf.pos) { /* If we have already written last entry, adjust outq_idx and offset so that this entry is eligible to send. */ if (len == stream->outq_idx) { --stream->outq_idx; - stream->outq_offset = nghttp3_buf_len(&dest->buf); } dest->buf.last = tbuf->buf.last; - /* TODO Is this required? */ - dest->buf.end = tbuf->buf.end; + + assert(dest->buf.end == tbuf->buf.end); return 0; } @@ -824,34 +816,24 @@ size_t nghttp3_stream_writev(nghttp3_stream *stream, int *pfin, nghttp3_ringbuf *outq = &stream->outq; size_t len = nghttp3_ringbuf_len(outq); size_t i = stream->outq_idx; - uint64_t offset = stream->outq_offset; size_t buflen; nghttp3_vec *vbegin = vec, *vend = vec + veccnt; nghttp3_typed_buf *tbuf; assert(veccnt > 0); - if (i < len) { + for (; i < len && vec != vend; ++i) { tbuf = nghttp3_ringbuf_get(outq, i); buflen = nghttp3_buf_len(&tbuf->buf); - if (offset < buflen) { - vec->base = tbuf->buf.pos + offset; - vec->len = (size_t)(buflen - offset); - ++vec; - } else { - /* This is the only case that satisfies offset >= buflen */ - assert(0 == offset); - assert(0 == buflen); + if (buflen == 0) { + continue; } - ++i; + vec->base = tbuf->buf.pos; + vec->len = buflen; - for (; i < len && vec != vend; ++i, ++vec) { - tbuf = nghttp3_ringbuf_get(outq, i); - vec->base = tbuf->buf.pos; - vec->len = nghttp3_buf_len(&tbuf->buf); - } + ++vec; } /* TODO Rework this if we have finished implementing HTTP @@ -866,26 +848,27 @@ void nghttp3_stream_add_outq_offset(nghttp3_stream *stream, size_t n) { nghttp3_ringbuf *outq = &stream->outq; size_t i; size_t len = nghttp3_ringbuf_len(outq); - uint64_t offset = stream->outq_offset + n; size_t buflen; nghttp3_typed_buf *tbuf; + stream->unsent_bytes -= n; + for (i = stream->outq_idx; i < len; ++i) { tbuf = nghttp3_ringbuf_get(outq, i); buflen = nghttp3_buf_len(&tbuf->buf); - if (offset >= buflen) { - offset -= buflen; - continue; + if (n < buflen) { + tbuf->buf.pos += n; + + break; } - break; + tbuf->buf.pos = tbuf->buf.last; + n -= buflen; } - assert(i < len || offset == 0); + assert(i < len || n == 0); - stream->unsent_bytes -= n; stream->outq_idx = i; - stream->outq_offset = offset; } int nghttp3_stream_outq_write_done(nghttp3_stream *stream) { @@ -911,7 +894,6 @@ static void stream_pop_outq_entry(nghttp3_stream *stream, chunk = nghttp3_ringbuf_get(chunks, 0); - assert(chunk->begin == tbuf->buf.begin); assert(chunk->end == tbuf->buf.end); if (chunk->last == tbuf->buf.last) { @@ -934,14 +916,13 @@ static void stream_pop_outq_entry(nghttp3_stream *stream, int nghttp3_stream_update_ack_offset(nghttp3_stream *stream, uint64_t offset) { nghttp3_ringbuf *outq = &stream->outq; size_t buflen; - size_t npopped = 0; uint64_t nack; nghttp3_typed_buf *tbuf; int rv; for (; nghttp3_ringbuf_len(outq);) { tbuf = nghttp3_ringbuf_get(outq, 0); - buflen = nghttp3_buf_len(&tbuf->buf); + buflen = (size_t)(tbuf->buf.last - tbuf->buf.begin); /* For NGHTTP3_BUF_TYPE_ALIEN, we never add 0 length buffer. */ if (tbuf->type == NGHTTP3_BUF_TYPE_ALIEN && stream->ack_offset < offset && @@ -956,17 +937,13 @@ int nghttp3_stream_update_ack_offset(nghttp3_stream *stream, uint64_t offset) { } } - if (offset >= stream->ack_base + buflen) { + if (stream->outq_idx > 0 && offset >= stream->ack_base + buflen) { stream_pop_outq_entry(stream, tbuf); stream->ack_base += buflen; stream->ack_offset = stream->ack_base; - ++npopped; - if (stream->outq_idx + 1 == npopped) { - stream->outq_offset = 0; - break; - } + --stream->outq_idx; continue; } @@ -974,13 +951,6 @@ int nghttp3_stream_update_ack_offset(nghttp3_stream *stream, uint64_t offset) { break; } - assert(stream->outq_idx + 1 >= npopped); - if (stream->outq_idx >= npopped) { - stream->outq_idx -= npopped; - } else { - stream->outq_idx = 0; - } - stream->ack_offset = offset; return 0; @@ -1052,19 +1022,17 @@ int nghttp3_stream_transit_rx_http_state(nghttp3_stream *stream, switch (stream->rx.hstate) { case NGHTTP3_HTTP_STATE_NONE: - return NGHTTP3_ERR_H3_INTERNAL_ERROR; + nghttp3_unreachable(); case NGHTTP3_HTTP_STATE_REQ_INITIAL: - switch (event) { - case NGHTTP3_HTTP_EVENT_HEADERS_BEGIN: - stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_HEADERS_BEGIN; - return 0; - default: + if (event != NGHTTP3_HTTP_EVENT_HEADERS_BEGIN) { return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; } + + stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_HEADERS_BEGIN; + + return 0; case NGHTTP3_HTTP_STATE_REQ_HEADERS_BEGIN: - if (event != NGHTTP3_HTTP_EVENT_HEADERS_END) { - return NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING; - } + assert(NGHTTP3_HTTP_EVENT_HEADERS_END == event); stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_HEADERS_END; return 0; case NGHTTP3_HTTP_STATE_REQ_HEADERS_END: @@ -1087,12 +1055,10 @@ int nghttp3_stream_transit_rx_http_state(nghttp3_stream *stream, stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_END; return 0; default: - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; + nghttp3_unreachable(); } case NGHTTP3_HTTP_STATE_REQ_DATA_BEGIN: - if (event != NGHTTP3_HTTP_EVENT_DATA_END) { - return NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING; - } + assert(NGHTTP3_HTTP_EVENT_DATA_END == event); stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_DATA_END; return 0; case NGHTTP3_HTTP_STATE_REQ_DATA_END: @@ -1115,12 +1081,10 @@ int nghttp3_stream_transit_rx_http_state(nghttp3_stream *stream, stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_END; return 0; default: - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; + nghttp3_unreachable(); } case NGHTTP3_HTTP_STATE_REQ_TRAILERS_BEGIN: - if (event != NGHTTP3_HTTP_EVENT_HEADERS_END) { - return NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING; - } + assert(NGHTTP3_HTTP_EVENT_HEADERS_END == event); stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_TRAILERS_END; return 0; case NGHTTP3_HTTP_STATE_REQ_TRAILERS_END: @@ -1136,7 +1100,7 @@ int nghttp3_stream_transit_rx_http_state(nghttp3_stream *stream, stream->rx.hstate = NGHTTP3_HTTP_STATE_REQ_END; return 0; case NGHTTP3_HTTP_STATE_REQ_END: - return NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING; + return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; case NGHTTP3_HTTP_STATE_RESP_INITIAL: if (event != NGHTTP3_HTTP_EVENT_HEADERS_BEGIN) { return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; @@ -1144,9 +1108,7 @@ int nghttp3_stream_transit_rx_http_state(nghttp3_stream *stream, stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_HEADERS_BEGIN; return 0; case NGHTTP3_HTTP_STATE_RESP_HEADERS_BEGIN: - if (event != NGHTTP3_HTTP_EVENT_HEADERS_END) { - return NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING; - } + assert(NGHTTP3_HTTP_EVENT_HEADERS_END == event); stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_HEADERS_END; return 0; case NGHTTP3_HTTP_STATE_RESP_HEADERS_END: @@ -1176,12 +1138,10 @@ int nghttp3_stream_transit_rx_http_state(nghttp3_stream *stream, stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_END; return 0; default: - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; + nghttp3_unreachable(); } case NGHTTP3_HTTP_STATE_RESP_DATA_BEGIN: - if (event != NGHTTP3_HTTP_EVENT_DATA_END) { - return NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING; - } + assert(NGHTTP3_HTTP_EVENT_DATA_END == event); stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_DATA_END; return 0; case NGHTTP3_HTTP_STATE_RESP_DATA_END: @@ -1204,17 +1164,15 @@ int nghttp3_stream_transit_rx_http_state(nghttp3_stream *stream, stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_END; return 0; default: - return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; + nghttp3_unreachable(); } case NGHTTP3_HTTP_STATE_RESP_TRAILERS_BEGIN: - if (event != NGHTTP3_HTTP_EVENT_HEADERS_END) { - return NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING; - } + assert(NGHTTP3_HTTP_EVENT_HEADERS_END == event); stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_TRAILERS_END; return 0; case NGHTTP3_HTTP_STATE_RESP_TRAILERS_END: if (event != NGHTTP3_HTTP_EVENT_MSG_END) { - return NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING; + return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; } rv = nghttp3_http_on_remote_end_stream(stream); if (rv != 0) { @@ -1223,7 +1181,7 @@ int nghttp3_stream_transit_rx_http_state(nghttp3_stream *stream, stream->rx.hstate = NGHTTP3_HTTP_STATE_RESP_END; return 0; case NGHTTP3_HTTP_STATE_RESP_END: - return NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING; + return NGHTTP3_ERR_H3_FRAME_UNEXPECTED; default: nghttp3_unreachable(); } diff --git a/contrib/libs/nghttp3/lib/nghttp3_stream.h b/contrib/libs/nghttp3/lib/nghttp3_stream.h index 9c0a18c5c00..d24cae04470 100644 --- a/contrib/libs/nghttp3/lib/nghttp3_stream.h +++ b/contrib/libs/nghttp3/lib/nghttp3_stream.h @@ -223,9 +223,6 @@ struct nghttp3_stream { uint64_t unsent_bytes; /* outq_idx is an index into outq where next write is made. */ size_t outq_idx; - /* outq_offset is write offset relative to the element at outq_idx - in outq. */ - uint64_t outq_offset; /* ack_base is the number of bytes acknowledged by a remote endpoint where the first element in outq is positioned at. */ uint64_t ack_base; diff --git a/contrib/libs/nghttp3/ya.make b/contrib/libs/nghttp3/ya.make index 635661681cc..0f451c0fb0b 100644 --- a/contrib/libs/nghttp3/ya.make +++ b/contrib/libs/nghttp3/ya.make @@ -2,9 +2,9 @@ LIBRARY() -VERSION(1.8.0) +VERSION(1.9.0) -ORIGINAL_SOURCE(https://github.com/ngtcp2/nghttp3/releases/download/v1.8.0/nghttp3-1.8.0.tar.xz) +ORIGINAL_SOURCE(https://github.com/ngtcp2/nghttp3/releases/download/v1.9.0/nghttp3-1.9.0.tar.xz) LICENSE( FSFAP AND |