From 3dd61f8ec3990928ee5f2606353d2b291f771aab Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Mon, 25 Mar 2024 18:46:03 +0900 Subject: [PATCH] Remove RFC 7540 priorities Summary of the behavioral changes in public API functions: - nghttp2_session_change_stream_priority: This function is noop. It always returns 0. - nghttp2_session_create_idle_stream: This function is noop. It always returns 0. - nghttp2_submit_request: pri_spec is ignored. - nghttp2_submit_request2: pri_spec is ignored. - nghttp2_submit_headers: pri_spec is ignored. - nghttp2_submit_priority: This function is noop. It always returns 0. - nghttp2_stream_get_parent: This function always returns NULL. - nghttp2_stream_get_next_sibling: This function always returns NULL. - nghttp2_stream_get_previous_sibling: This function always returns NULL. - nghttp2_stream_get_first_child: This function always returns NULL. - nghttp2_stream_get_weight: This function always returns NGHTTP2_DEFAULT_WEIGHT. - nghttp2_stream_get_sum_dependency_weight: This function always returns 0. --- lib/includes/nghttp2/nghttp2.h | 216 +-- lib/nghttp2_http.c | 1 - lib/nghttp2_session.c | 689 +-------- lib/nghttp2_session.h | 116 +- lib/nghttp2_stream.c | 849 +---------- lib/nghttp2_stream.h | 157 +- lib/nghttp2_submit.c | 155 +- tests/nghttp2_session_test.c | 2545 +------------------------------- tests/nghttp2_session_test.h | 24 - tests/nghttp2_test_helper.c | 126 +- tests/nghttp2_test_helper.h | 32 - 11 files changed, 163 insertions(+), 4747 deletions(-) diff --git a/lib/includes/nghttp2/nghttp2.h b/lib/includes/nghttp2/nghttp2.h index 2ef49b8d..c520e8c1 100644 --- a/lib/includes/nghttp2/nghttp2.h +++ b/lib/includes/nghttp2/nghttp2.h @@ -4179,39 +4179,9 @@ NGHTTP2_EXTERN int nghttp2_session_consume_stream(nghttp2_session *session, * * Deprecated. :rfc:`7540` priorities are deprecated by * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible - * prioritization scheme. In the future release after the end of - * 2024, this function will always return 0 without doing anything. + * prioritization scheme. * - * Changes priority of existing stream denoted by |stream_id|. The - * new priority specification is |pri_spec|. - * - * The priority is changed silently and instantly, and no PRIORITY - * frame will be sent to notify the peer of this change. This - * function may be useful for server to change the priority of pushed - * stream. - * - * If |session| is initialized as server, and ``pri_spec->stream_id`` - * points to the idle stream, the idle stream is created if it does - * not exist. The created idle stream will depend on root stream - * (stream 0) with weight 16. - * - * Otherwise, if stream denoted by ``pri_spec->stream_id`` is not - * found, we use default priority instead of given |pri_spec|. That - * is make stream depend on root stream with weight 16. - * - * If - * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` - * of value of 1 is submitted via `nghttp2_submit_settings()`, this - * function does nothing and returns 0. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` - * Attempted to depend on itself; or no stream exist for the given - * |stream_id|; or |stream_id| is 0 + * This function is noop. It always returns 0. */ NGHTTP2_EXTERN int nghttp2_session_change_stream_priority(nghttp2_session *session, @@ -4225,51 +4195,9 @@ nghttp2_session_change_stream_priority(nghttp2_session *session, * * Deprecated. :rfc:`7540` priorities are deprecated by * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible - * prioritization scheme. In the future release after the end of - * 2024, this function will always return 0 without doing anything. + * prioritization scheme. * - * Creates idle stream with the given |stream_id|, and priority - * |pri_spec|. - * - * The stream creation is done without sending PRIORITY frame, which - * means that peer does not know about the existence of this idle - * stream in the local endpoint. - * - * RFC 7540 does not disallow the use of creation of idle stream with - * odd or even stream ID regardless of client or server. So this - * function can create odd or even stream ID regardless of client or - * server. But probably it is a bit safer to use the stream ID the - * local endpoint can initiate (in other words, use odd stream ID for - * client, and even stream ID for server), to avoid potential - * collision from peer's instruction. Also we can use - * `nghttp2_session_set_next_stream_id()` to avoid to open created - * idle streams accidentally if we follow this recommendation. - * - * If |session| is initialized as server, and ``pri_spec->stream_id`` - * points to the idle stream, the idle stream is created if it does - * not exist. The created idle stream will depend on root stream - * (stream 0) with weight 16. - * - * Otherwise, if stream denoted by ``pri_spec->stream_id`` is not - * found, we use default priority instead of given |pri_spec|. That - * is make stream depend on root stream with weight 16. - * - * If - * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` - * of value of 1 is submitted via `nghttp2_submit_settings()`, this - * function does nothing and returns 0. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` - * Attempted to depend on itself; or stream denoted by |stream_id| - * already exists; or |stream_id| cannot be used to create idle - * stream (in other words, local endpoint has already opened - * stream ID greater than or equal to the given stream ID; or - * |stream_id| is 0 + * This function is noop. It always returns 0. */ NGHTTP2_EXTERN int nghttp2_session_create_idle_stream(nghttp2_session *session, int32_t stream_id, @@ -4505,23 +4433,7 @@ nghttp2_priority_spec_check_default(const nghttp2_priority_spec *pri_spec); * * Submits HEADERS frame and optionally one or more DATA frames. * - * The |pri_spec| is a deprecated priority specification of this - * request. ``NULL`` means the default priority (see - * `nghttp2_priority_spec_default_init()`). To specify the priority, - * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``, - * this function will copy its data members. - * - * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`, - * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` - * is strictly less than :macro:`NGHTTP2_MIN_WEIGHT`, it becomes - * :macro:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than - * :macro:`NGHTTP2_MAX_WEIGHT`, it becomes - * :macro:`NGHTTP2_MAX_WEIGHT`. - * - * If - * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` - * of value of 1 is received by a remote endpoint, |pri_spec| is - * ignored, and treated as if ``NULL`` is specified. + * The |pri_spec| is ignored. * * The |nva| is an array of name/value pair :type:`nghttp2_nv` with * |nvlen| elements. The application is responsible to include @@ -4564,9 +4476,6 @@ nghttp2_priority_spec_check_default(const nghttp2_priority_spec *pri_spec); * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE` * No stream ID is available because maximum stream ID was * reached. - * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` - * Trying to depend on itself (new stream ID equals - * ``pri_spec->stream_id``). * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` * The |session| is server session. * @@ -4594,25 +4503,7 @@ NGHTTP2_EXTERN int32_t nghttp2_submit_request( * * Submits HEADERS frame and optionally one or more DATA frames. * - * The |pri_spec| is a deprecated priority specification of this - * request. ``NULL`` means the default priority (see - * `nghttp2_priority_spec_default_init()`). To specify the priority, - * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``, - * this function will copy its data members. In the future release - * after the end of 2024, this function will ignore |pri_spec| and - * behave as if ``NULL`` is given. - * - * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`, - * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` - * is strictly less than :macro:`NGHTTP2_MIN_WEIGHT`, it becomes - * :macro:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than - * :macro:`NGHTTP2_MAX_WEIGHT`, it becomes - * :macro:`NGHTTP2_MAX_WEIGHT`. - * - * If - * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` - * of value of 1 is received by a remote endpoint, |pri_spec| is - * ignored, and treated as if ``NULL`` is specified. + * The |pri_spec| is ignored. * * The |nva| is an array of name/value pair :type:`nghttp2_nv` with * |nvlen| elements. The application is responsible to include @@ -4655,9 +4546,6 @@ NGHTTP2_EXTERN int32_t nghttp2_submit_request( * :enum:`nghttp2_error.NGHTTP2_ERR_STREAM_ID_NOT_AVAILABLE` * No stream ID is available because maximum stream ID was * reached. - * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` - * Trying to depend on itself (new stream ID equals - * ``pri_spec->stream_id``). * :enum:`nghttp2_error.NGHTTP2_ERR_PROTO` * The |session| is server session. * @@ -4899,24 +4787,7 @@ NGHTTP2_EXTERN int nghttp2_submit_trailer(nghttp2_session *session, * assigned stream ID will be returned. Otherwise, specify stream ID * in |stream_id|. * - * The |pri_spec| is a deprecated priority specification of this - * request. ``NULL`` means the default priority (see - * `nghttp2_priority_spec_default_init()`). To specify the priority, - * use `nghttp2_priority_spec_init()`. If |pri_spec| is not ``NULL``, - * this function will copy its data members. In the future release - * after the end of 2024, this function will ignore |pri_spec| and - * behave as if ``NULL`` is given. - * - * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`, - * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` - * is strictly less than :macro:`NGHTTP2_MIN_WEIGHT`, it becomes - * :macro:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than - * :macro:`NGHTTP2_MAX_WEIGHT`, it becomes :macro:`NGHTTP2_MAX_WEIGHT`. - * - * If - * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` - * of value of 1 is received by a remote endpoint, |pri_spec| is - * ignored, and treated as if ``NULL`` is specified. + * The |pri_spec| is ignored. * * The |nva| is an array of name/value pair :type:`nghttp2_nv` with * |nvlen| elements. The application is responsible to include @@ -4956,8 +4827,7 @@ NGHTTP2_EXTERN int nghttp2_submit_trailer(nghttp2_session *session, * No stream ID is available because maximum stream ID was * reached. * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` - * The |stream_id| is 0; or trying to depend on itself (stream ID - * equals ``pri_spec->stream_id``). + * The |stream_id| is 0. * :enum:`nghttp2_error.NGHTTP2_ERR_DATA_EXIST` * DATA or HEADERS has been already submitted and not fully * processed yet. This happens if stream denoted by |stream_id| @@ -5083,40 +4953,9 @@ NGHTTP2_EXTERN int nghttp2_submit_data2(nghttp2_session *session, uint8_t flags, * * Deprecated. :rfc:`7540` priorities are deprecated by * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible - * prioritization scheme. In the future release after the end of - * 2024, this function will always return 0 without doing anything. + * prioritization scheme. * - * Submits PRIORITY frame to change the priority of stream |stream_id| - * to the priority specification |pri_spec|. - * - * The |flags| is currently ignored and should be - * :enum:`nghttp2_flag.NGHTTP2_FLAG_NONE`. - * - * The |pri_spec| is a deprecated priority specification of this - * request. ``NULL`` is not allowed for this function. To specify the - * priority, use `nghttp2_priority_spec_init()`. This function will - * copy its data members. - * - * The ``pri_spec->weight`` must be in [:macro:`NGHTTP2_MIN_WEIGHT`, - * :macro:`NGHTTP2_MAX_WEIGHT`], inclusive. If ``pri_spec->weight`` - * is strictly less than :macro:`NGHTTP2_MIN_WEIGHT`, it becomes - * :macro:`NGHTTP2_MIN_WEIGHT`. If it is strictly greater than - * :macro:`NGHTTP2_MAX_WEIGHT`, it becomes - * :macro:`NGHTTP2_MAX_WEIGHT`. - * - * If - * :enum:`nghttp2_settings_id.NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES` - * of value of 1 is received by a remote endpoint, this function does - * nothing and returns 0. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * :enum:`nghttp2_error.NGHTTP2_ERR_NOMEM` - * Out of memory. - * :enum:`nghttp2_error.NGHTTP2_ERR_INVALID_ARGUMENT` - * The |stream_id| is 0; or the |pri_spec| is NULL; or trying to - * depend on itself. + * This function is noop. It always returns 0. */ NGHTTP2_EXTERN int nghttp2_submit_priority(nghttp2_session *session, uint8_t flags, @@ -6885,11 +6724,9 @@ nghttp2_session_get_root_stream(nghttp2_session *session); * * Deprecated. :rfc:`7540` priorities are deprecated by * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible - * prioritization scheme. In the future release after the end of - * 2024, this function will always return NULL. + * prioritization scheme. * - * Returns the parent stream of |stream| in dependency tree. Returns - * NULL if there is no such stream. + * This function always returns NULL. */ NGHTTP2_EXTERN nghttp2_stream * nghttp2_stream_get_parent(nghttp2_stream *stream); @@ -6903,11 +6740,9 @@ NGHTTP2_EXTERN int32_t nghttp2_stream_get_stream_id(nghttp2_stream *stream); * * Deprecated. :rfc:`7540` priorities are deprecated by * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible - * prioritization scheme. In the future release after the end of - * 2024, this function will always return NULL. + * prioritization scheme. * - * Returns the next sibling stream of |stream| in dependency tree. - * Returns NULL if there is no such stream. + * This function always returns NULL. */ NGHTTP2_EXTERN nghttp2_stream * nghttp2_stream_get_next_sibling(nghttp2_stream *stream); @@ -6919,11 +6754,9 @@ nghttp2_stream_get_next_sibling(nghttp2_stream *stream); * * Deprecated. :rfc:`7540` priorities are deprecated by * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible - * prioritization scheme. In the future release after the end of - * 2024, this function will always return NULL. + * prioritization scheme. * - * Returns the previous sibling stream of |stream| in dependency tree. - * Returns NULL if there is no such stream. + * This function always returns NULL. */ NGHTTP2_EXTERN nghttp2_stream * nghttp2_stream_get_previous_sibling(nghttp2_stream *stream); @@ -6935,11 +6768,9 @@ nghttp2_stream_get_previous_sibling(nghttp2_stream *stream); * * Deprecated. :rfc:`7540` priorities are deprecated by * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible - * prioritization scheme. In the future release after the end of - * 2024, this function will always return NULL. + * prioritization scheme. * - * Returns the first child stream of |stream| in dependency tree. - * Returns NULL if there is no such stream. + * This function always returns NULL. */ NGHTTP2_EXTERN nghttp2_stream * nghttp2_stream_get_first_child(nghttp2_stream *stream); @@ -6951,11 +6782,9 @@ nghttp2_stream_get_first_child(nghttp2_stream *stream); * * Deprecated. :rfc:`7540` priorities are deprecated by * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible - * prioritization scheme. In the future release after the end of - * 2024, this function will always return - * :macro:`NGHTTP2_DEFAULT_WEIGHT`. + * prioritization scheme. * - * Returns dependency weight to the parent stream of |stream|. + * This function always returns :macro:`NGHTTP2_DEFAULT_WEIGHT`. */ NGHTTP2_EXTERN int32_t nghttp2_stream_get_weight(nghttp2_stream *stream); @@ -6966,10 +6795,9 @@ NGHTTP2_EXTERN int32_t nghttp2_stream_get_weight(nghttp2_stream *stream); * * Deprecated. :rfc:`7540` priorities are deprecated by * :rfc:`9113`. Consider migrating to :rfc:`9218` extensible - * prioritization scheme. In the future release after the end of - * 2024, this function will always return 0. + * prioritization scheme. * - * Returns the sum of the weight for |stream|'s children. + * This function always returns 0. */ NGHTTP2_EXTERN int32_t nghttp2_stream_get_sum_dependency_weight(nghttp2_stream *stream); diff --git a/lib/nghttp2_http.c b/lib/nghttp2_http.c index 076dd70c..60a0b01e 100644 --- a/lib/nghttp2_http.c +++ b/lib/nghttp2_http.c @@ -207,7 +207,6 @@ static int http_request_on_header(nghttp2_stream *stream, nghttp2_hd_nv *nv, if (!trailer && /* Do not parse the header field in PUSH_PROMISE. */ (stream->stream_id & 1) && - (stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES) && !(stream->http_flags & NGHTTP2_HTTP_FLAG_BAD_PRIORITY)) { nghttp2_extpri_from_uint8(&extpri, stream->http_extpri); if (nghttp2_http_parse_priority(&extpri, nv->value->base, diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index df33a89e..39f0aecb 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -41,6 +41,8 @@ #include "nghttp2_debug.h" #include "nghttp2_submit.h" +nghttp2_stream root; + /* * Returns non-zero if the number of outgoing opened streams is larger * than or equal to @@ -146,11 +148,6 @@ static int session_detect_idle_stream(nghttp2_session *session, return 0; } -static int session_no_rfc7540_pri_no_fallback(nghttp2_session *session) { - return session->pending_no_rfc7540_priorities == 1 && - !session->fallback_rfc7540_priorities; -} - static int check_ext_type_set(const uint8_t *ext_types, uint8_t type) { return (ext_types[type / 8] & (1 << (type & 0x7))) > 0; } @@ -458,10 +455,6 @@ static int session_new(nghttp2_session **session_ptr, /* next_stream_id is initialized in either nghttp2_session_client_new2 or nghttp2_session_server_new2 */ - nghttp2_stream_init(&(*session_ptr)->root, 0, NGHTTP2_STREAM_FLAG_NONE, - NGHTTP2_STREAM_IDLE, NGHTTP2_DEFAULT_WEIGHT, 0, 0, NULL, - mem); - (*session_ptr)->remote_window_size = NGHTTP2_INITIAL_CONNECTION_WINDOW_SIZE; (*session_ptr)->recv_window_size = 0; (*session_ptr)->consumed_size = 0; @@ -810,7 +803,6 @@ void nghttp2_session_del(nghttp2_session *session) { for (i = 0; i < NGHTTP2_EXTPRI_URGENCY_LEVELS; ++i) { nghttp2_pq_free(&session->sched[i].ob_data); } - nghttp2_stream_free(&session->root); /* Have to free streams first, so that we can check stream->item->queued */ @@ -829,82 +821,6 @@ void nghttp2_session_del(nghttp2_session *session) { nghttp2_mem_free(mem, session); } -int nghttp2_session_reprioritize_stream( - nghttp2_session *session, nghttp2_stream *stream, - const nghttp2_priority_spec *pri_spec_in) { - int rv; - nghttp2_stream *dep_stream = NULL; - nghttp2_priority_spec pri_spec_default; - const nghttp2_priority_spec *pri_spec = pri_spec_in; - - assert((!session->server && session->pending_no_rfc7540_priorities != 1) || - (session->server && !session_no_rfc7540_pri_no_fallback(session))); - assert(pri_spec->stream_id != stream->stream_id); - - if (!nghttp2_stream_in_dep_tree(stream)) { - return 0; - } - - if (pri_spec->stream_id != 0) { - dep_stream = nghttp2_session_get_stream_raw(session, pri_spec->stream_id); - - if (!dep_stream && - session_detect_idle_stream(session, pri_spec->stream_id)) { - nghttp2_priority_spec_default_init(&pri_spec_default); - - dep_stream = nghttp2_session_open_stream( - session, pri_spec->stream_id, NGHTTP2_FLAG_NONE, &pri_spec_default, - NGHTTP2_STREAM_IDLE, NULL); - - if (dep_stream == NULL) { - return NGHTTP2_ERR_NOMEM; - } - } else if (!dep_stream || !nghttp2_stream_in_dep_tree(dep_stream)) { - nghttp2_priority_spec_default_init(&pri_spec_default); - pri_spec = &pri_spec_default; - } - } - - if (pri_spec->stream_id == 0) { - dep_stream = &session->root; - } else if (nghttp2_stream_dep_find_ancestor(dep_stream, stream)) { - DEBUGF("stream: cycle detected, dep_stream(%p)=%d stream(%p)=%d\n", - dep_stream, dep_stream->stream_id, stream, stream->stream_id); - - nghttp2_stream_dep_remove_subtree(dep_stream); - rv = nghttp2_stream_dep_add_subtree(stream->dep_prev, dep_stream); - if (rv != 0) { - return rv; - } - } - - assert(dep_stream); - - if (dep_stream == stream->dep_prev && !pri_spec->exclusive) { - /* This is minor optimization when just weight is changed. */ - nghttp2_stream_change_weight(stream, pri_spec->weight); - - return 0; - } - - nghttp2_stream_dep_remove_subtree(stream); - - /* We have to update weight after removing stream from tree */ - stream->weight = pri_spec->weight; - - if (pri_spec->exclusive) { - rv = nghttp2_stream_dep_insert_subtree(dep_stream, stream); - } else { - rv = nghttp2_stream_dep_add_subtree(dep_stream, stream); - } - - if (rv != 0) { - return rv; - } - - return 0; -} - static uint64_t pq_get_first_cycle(nghttp2_pq *pq) { nghttp2_stream *stream; @@ -923,7 +839,6 @@ static int session_ob_data_push(nghttp2_session *session, int inc; nghttp2_pq *pq; - assert(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES); assert(stream->queued == 0); urgency = nghttp2_extpri_uint8_urgency(stream->extpri); @@ -952,7 +867,6 @@ static void session_ob_data_remove(nghttp2_session *session, nghttp2_stream *stream) { uint32_t urgency; - assert(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES); assert(stream->queued == 1); urgency = nghttp2_extpri_uint8_urgency(stream->extpri); @@ -969,14 +883,7 @@ static int session_attach_stream_item(nghttp2_session *session, nghttp2_outbound_item *item) { int rv; - rv = nghttp2_stream_attach_item(stream, item); - if (rv != 0) { - return rv; - } - - if (!(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES)) { - return 0; - } + nghttp2_stream_attach_item(stream, item); rv = session_ob_data_push(session, stream); if (rv != 0) { @@ -992,8 +899,7 @@ static void session_detach_stream_item(nghttp2_session *session, nghttp2_stream *stream) { nghttp2_stream_detach_item(stream); - if (!(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES) || - !stream->queued) { + if (!stream->queued) { return; } @@ -1004,8 +910,7 @@ static void session_defer_stream_item(nghttp2_session *session, nghttp2_stream *stream, uint8_t flags) { nghttp2_stream_defer_item(stream, flags); - if (!(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES) || - !stream->queued) { + if (!stream->queued) { return; } @@ -1015,15 +920,9 @@ static void session_defer_stream_item(nghttp2_session *session, static int session_resume_deferred_stream_item(nghttp2_session *session, nghttp2_stream *stream, uint8_t flags) { - int rv; + nghttp2_stream_resume_deferred_item(stream, flags); - rv = nghttp2_stream_resume_deferred_item(stream, flags); - if (rv != 0) { - return rv; - } - - if (!(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES) || - (stream->flags & NGHTTP2_STREAM_FLAG_DEFERRED_ALL)) { + if (stream->flags & NGHTTP2_STREAM_FLAG_DEFERRED_ALL) { return 0; } @@ -1168,7 +1067,6 @@ int nghttp2_session_add_item(nghttp2_session *session, return 0; case NGHTTP2_PUSH_PROMISE: { nghttp2_headers_aux_data *aux_data; - nghttp2_priority_spec pri_spec; aux_data = &item->aux_data.headers; @@ -1176,20 +1074,13 @@ int nghttp2_session_add_item(nghttp2_session *session, return NGHTTP2_ERR_STREAM_CLOSED; } - nghttp2_priority_spec_init(&pri_spec, stream->stream_id, - NGHTTP2_DEFAULT_WEIGHT, 0); - if (!nghttp2_session_open_stream( session, frame->push_promise.promised_stream_id, - NGHTTP2_STREAM_FLAG_NONE, &pri_spec, NGHTTP2_STREAM_RESERVED, + NGHTTP2_STREAM_FLAG_NONE, NGHTTP2_STREAM_RESERVED, aux_data->stream_user_data)) { return NGHTTP2_ERR_NOMEM; } - /* We don't have to call nghttp2_session_adjust_closed_stream() - here, since stream->stream_id is local stream_id, and it does - not affect closed stream count. */ - nghttp2_outbound_queue_push(&session->ob_reg, item); item->queued = 1; @@ -1290,15 +1181,11 @@ int nghttp2_session_add_rst_stream(nghttp2_session *session, int32_t stream_id, nghttp2_stream *nghttp2_session_open_stream(nghttp2_session *session, int32_t stream_id, uint8_t flags, - nghttp2_priority_spec *pri_spec_in, nghttp2_stream_state initial_state, void *stream_user_data) { int rv; nghttp2_stream *stream; - nghttp2_stream *dep_stream = NULL; int stream_alloc = 0; - nghttp2_priority_spec pri_spec_default; - nghttp2_priority_spec *pri_spec = pri_spec_in; nghttp2_mem *mem; mem = &session->mem; @@ -1311,23 +1198,9 @@ nghttp2_stream *nghttp2_session_open_stream(nghttp2_session *session, if (stream) { assert(stream->state == NGHTTP2_STREAM_IDLE); - assert((stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES) || - nghttp2_stream_in_dep_tree(stream)); + assert(initial_state != NGHTTP2_STREAM_IDLE); - nghttp2_session_detach_idle_stream(session, stream); - - if (nghttp2_stream_in_dep_tree(stream)) { - assert(!(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES)); - - rv = nghttp2_stream_dep_remove(stream); - if (rv != 0) { - return NULL; - } - - if (session_no_rfc7540_pri_no_fallback(session)) { - stream->flags |= NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES; - } - } + --session->num_idle_streams; } else { stream = nghttp2_mem_malloc(mem, sizeof(nghttp2_stream)); if (stream == NULL) { @@ -1337,69 +1210,16 @@ nghttp2_stream *nghttp2_session_open_stream(nghttp2_session *session, stream_alloc = 1; } - if (session_no_rfc7540_pri_no_fallback(session) || - session->remote_settings.no_rfc7540_priorities == 1) { - /* For client which has not received server - SETTINGS_NO_RFC7540_PRIORITIES = 1, send a priority signal - opportunistically. */ - if (session->server || - session->remote_settings.no_rfc7540_priorities == 1) { - nghttp2_priority_spec_default_init(&pri_spec_default); - pri_spec = &pri_spec_default; - } - - if (session->pending_no_rfc7540_priorities == 1) { - flags |= NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES; - } - } else if (pri_spec->stream_id != 0) { - dep_stream = nghttp2_session_get_stream_raw(session, pri_spec->stream_id); - - if (!dep_stream && - session_detect_idle_stream(session, pri_spec->stream_id)) { - /* Depends on idle stream, which does not exist in memory. - Assign default priority for it. */ - nghttp2_priority_spec_default_init(&pri_spec_default); - - dep_stream = nghttp2_session_open_stream( - session, pri_spec->stream_id, NGHTTP2_FLAG_NONE, &pri_spec_default, - NGHTTP2_STREAM_IDLE, NULL); - - if (dep_stream == NULL) { - if (stream_alloc) { - nghttp2_mem_free(mem, stream); - } - - return NULL; - } - } else if (!dep_stream || !nghttp2_stream_in_dep_tree(dep_stream)) { - /* If dep_stream is not part of dependency tree, stream will get - default priority. This handles the case when - pri_spec->stream_id == stream_id. This happens because we - don't check pri_spec->stream_id against new stream ID in - nghttp2_submit_request. This also handles the case when idle - stream created by PRIORITY frame was opened. Somehow we - first remove the idle stream from dependency tree. This is - done to simplify code base, but ideally we should retain old - dependency. But I'm not sure this adds values. */ - nghttp2_priority_spec_default_init(&pri_spec_default); - pri_spec = &pri_spec_default; - } - } - if (initial_state == NGHTTP2_STREAM_RESERVED) { flags |= NGHTTP2_STREAM_FLAG_PUSH; } if (stream_alloc) { nghttp2_stream_init(stream, stream_id, flags, initial_state, - pri_spec->weight, (int32_t)session->remote_settings.initial_window_size, (int32_t)session->local_settings.initial_window_size, - stream_user_data, mem); - - if (session_no_rfc7540_pri_no_fallback(session)) { - stream->seq = session->stream_seq++; - } + stream_user_data); + stream->seq = session->stream_seq++; rv = nghttp2_map_insert(&session->streams, stream_id, stream); if (rv != 0) { @@ -1410,7 +1230,6 @@ nghttp2_stream *nghttp2_session_open_stream(nghttp2_session *session, } else { stream->flags = flags; stream->state = initial_state; - stream->weight = pri_spec->weight; stream->stream_user_data = stream_user_data; } @@ -1428,9 +1247,7 @@ nghttp2_stream *nghttp2_session_open_stream(nghttp2_session *session, limit. That is one of the DOS vector. */ break; case NGHTTP2_STREAM_IDLE: - /* Idle stream does not count toward the concurrent streams limit. - This is used as anchor node in dependency tree. */ - nghttp2_session_keep_idle_stream(session, stream); + ++session->num_idle_streams; break; default: if (nghttp2_session_is_my_stream_id(session, stream_id)) { @@ -1440,31 +1257,11 @@ nghttp2_stream *nghttp2_session_open_stream(nghttp2_session *session, } } - if (stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES) { - return stream; - } - - if (pri_spec->stream_id == 0) { - dep_stream = &session->root; - } - - assert(dep_stream); - - if (pri_spec->exclusive) { - rv = nghttp2_stream_dep_insert(dep_stream, stream); - if (rv != 0) { - return NULL; - } - } else { - nghttp2_stream_dep_add(dep_stream, stream); - } - return stream; } int nghttp2_session_close_stream(nghttp2_session *session, int32_t stream_id, uint32_t error_code) { - int rv; nghttp2_stream *stream; nghttp2_mem *mem; int is_my_stream_id; @@ -1528,207 +1325,26 @@ int nghttp2_session_close_stream(nghttp2_session *session, int32_t stream_id, /* Closes both directions just in case they are not closed yet */ stream->flags |= NGHTTP2_STREAM_FLAG_CLOSED; - if (session->pending_no_rfc7540_priorities == 1) { - return nghttp2_session_destroy_stream(session, stream); - } - - if ((session->opt_flags & NGHTTP2_OPTMASK_NO_CLOSED_STREAMS) == 0 && - session->server && !is_my_stream_id && - nghttp2_stream_in_dep_tree(stream)) { - /* On server side, retain stream at most MAX_CONCURRENT_STREAMS - combined with the current active incoming streams to make - dependency tree work better. */ - nghttp2_session_keep_closed_stream(session, stream); - } else { - rv = nghttp2_session_destroy_stream(session, stream); - if (rv != 0) { - return rv; - } - } + nghttp2_session_destroy_stream(session, stream); return 0; } -int nghttp2_session_destroy_stream(nghttp2_session *session, - nghttp2_stream *stream) { +void nghttp2_session_destroy_stream(nghttp2_session *session, + nghttp2_stream *stream) { nghttp2_mem *mem; - int rv; DEBUGF("stream: destroy closed stream(%p)=%d\n", stream, stream->stream_id); mem = &session->mem; - if (nghttp2_stream_in_dep_tree(stream)) { - rv = nghttp2_stream_dep_remove(stream); - if (rv != 0) { - return rv; - } - } - - if (stream->queued && - (stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES)) { + if (stream->queued) { session_ob_data_remove(session, stream); } nghttp2_map_remove(&session->streams, stream->stream_id); nghttp2_stream_free(stream); nghttp2_mem_free(mem, stream); - - return 0; -} - -void nghttp2_session_keep_closed_stream(nghttp2_session *session, - nghttp2_stream *stream) { - DEBUGF("stream: keep closed stream(%p)=%d, state=%d\n", stream, - stream->stream_id, stream->state); - - if (session->closed_stream_tail) { - session->closed_stream_tail->closed_next = stream; - stream->closed_prev = session->closed_stream_tail; - } else { - session->closed_stream_head = stream; - } - session->closed_stream_tail = stream; - - ++session->num_closed_streams; -} - -void nghttp2_session_keep_idle_stream(nghttp2_session *session, - nghttp2_stream *stream) { - DEBUGF("stream: keep idle stream(%p)=%d, state=%d\n", stream, - stream->stream_id, stream->state); - - if (session->idle_stream_tail) { - session->idle_stream_tail->closed_next = stream; - stream->closed_prev = session->idle_stream_tail; - } else { - session->idle_stream_head = stream; - } - session->idle_stream_tail = stream; - - ++session->num_idle_streams; -} - -void nghttp2_session_detach_idle_stream(nghttp2_session *session, - nghttp2_stream *stream) { - nghttp2_stream *prev_stream, *next_stream; - - DEBUGF("stream: detach idle stream(%p)=%d, state=%d\n", stream, - stream->stream_id, stream->state); - - prev_stream = stream->closed_prev; - next_stream = stream->closed_next; - - if (prev_stream) { - prev_stream->closed_next = next_stream; - } else { - session->idle_stream_head = next_stream; - } - - if (next_stream) { - next_stream->closed_prev = prev_stream; - } else { - session->idle_stream_tail = prev_stream; - } - - stream->closed_prev = NULL; - stream->closed_next = NULL; - - --session->num_idle_streams; -} - -int nghttp2_session_adjust_closed_stream(nghttp2_session *session) { - size_t num_stream_max; - int rv; - - if (session->local_settings.max_concurrent_streams == - NGHTTP2_DEFAULT_MAX_CONCURRENT_STREAMS) { - num_stream_max = session->pending_local_max_concurrent_stream; - } else { - num_stream_max = session->local_settings.max_concurrent_streams; - } - - DEBUGF("stream: adjusting kept closed streams num_closed_streams=%zu, " - "num_incoming_streams=%zu, max_concurrent_streams=%zu\n", - session->num_closed_streams, session->num_incoming_streams, - num_stream_max); - - while (session->num_closed_streams > 0 && - session->num_closed_streams + session->num_incoming_streams > - num_stream_max) { - nghttp2_stream *head_stream; - nghttp2_stream *next; - - head_stream = session->closed_stream_head; - - assert(head_stream); - - next = head_stream->closed_next; - - rv = nghttp2_session_destroy_stream(session, head_stream); - if (rv != 0) { - return rv; - } - - /* head_stream is now freed */ - - session->closed_stream_head = next; - - if (session->closed_stream_head) { - session->closed_stream_head->closed_prev = NULL; - } else { - session->closed_stream_tail = NULL; - } - - --session->num_closed_streams; - } - - return 0; -} - -int nghttp2_session_adjust_idle_stream(nghttp2_session *session) { - size_t max; - int rv; - - /* Make minimum number of idle streams 16, and maximum 100, which - are arbitrary chosen numbers. */ - max = nghttp2_min_uint32( - 100, - nghttp2_max_uint32( - 16, nghttp2_min_uint32(session->local_settings.max_concurrent_streams, - session->pending_local_max_concurrent_stream))); - - DEBUGF("stream: adjusting kept idle streams num_idle_streams=%zu, max=%zu\n", - session->num_idle_streams, max); - - while (session->num_idle_streams > max) { - nghttp2_stream *head; - nghttp2_stream *next; - - head = session->idle_stream_head; - assert(head); - - next = head->closed_next; - - rv = nghttp2_session_destroy_stream(session, head); - if (rv != 0) { - return rv; - } - - /* head is now destroyed */ - - session->idle_stream_head = next; - - if (session->idle_stream_head) { - session->idle_stream_head->closed_prev = NULL; - } else { - session->idle_stream_tail = NULL; - } - - --session->num_idle_streams; - } - - return 0; } /* @@ -2411,16 +2027,12 @@ static int session_prep_frame(nghttp2_session *session, stream = nghttp2_session_open_stream( session, frame->hd.stream_id, NGHTTP2_STREAM_FLAG_NONE, - &frame->headers.pri_spec, NGHTTP2_STREAM_INITIAL, - aux_data->stream_user_data); + NGHTTP2_STREAM_INITIAL, aux_data->stream_user_data); if (stream == NULL) { return NGHTTP2_ERR_NOMEM; } - /* We don't call nghttp2_session_adjust_closed_stream() here, - since we don't keep closed stream in client side */ - rv = session_predicate_request_headers_send(session, item); if (rv != 0) { return rv; @@ -2662,8 +2274,6 @@ static int session_prep_frame(nghttp2_session *session, nghttp2_outbound_item * nghttp2_session_get_next_ob_item(nghttp2_session *session) { - nghttp2_outbound_item *item; - if (nghttp2_outbound_queue_top(&session->ob_urgent)) { return nghttp2_outbound_queue_top(&session->ob_urgent); } @@ -2679,11 +2289,6 @@ nghttp2_session_get_next_ob_item(nghttp2_session *session) { } if (session->remote_window_size > 0) { - item = nghttp2_stream_next_outbound_item(&session->root); - if (item) { - return item; - } - return session_sched_get_next_outbound_item(session); } @@ -2718,11 +2323,6 @@ nghttp2_session_pop_next_ob_item(nghttp2_session *session) { } if (session->remote_window_size > 0) { - item = nghttp2_stream_next_outbound_item(&session->root); - if (item) { - return item; - } - return session_sched_get_next_outbound_item(session); } @@ -2781,7 +2381,6 @@ static int find_stream_on_goaway_func(void *entry, void *ptr) { nghttp2_session_close_stream() inside nghttp2_map_each(). Reuse closed_next member.. bad choice? */ assert(stream->closed_next == NULL); - assert(stream->closed_prev == NULL); if (arg->head) { stream->closed_next = arg->head; @@ -2837,11 +2436,6 @@ static void session_reschedule_stream(nghttp2_session *session, nghttp2_stream *stream) { stream->last_writelen = stream->item->frame.hd.length; - if (!(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES)) { - nghttp2_stream_reschedule(stream); - return; - } - if (!session->server) { return; } @@ -3020,37 +2614,6 @@ static int session_after_frame_sent1(nghttp2_session *session) { } } case NGHTTP2_PRIORITY: - if (session->server || session->pending_no_rfc7540_priorities == 1) { - return 0; - } - - stream = nghttp2_session_get_stream_raw(session, frame->hd.stream_id); - - if (!stream) { - if (!session_detect_idle_stream(session, frame->hd.stream_id)) { - return 0; - } - - stream = nghttp2_session_open_stream( - session, frame->hd.stream_id, NGHTTP2_FLAG_NONE, - &frame->priority.pri_spec, NGHTTP2_STREAM_IDLE, NULL); - if (!stream) { - return NGHTTP2_ERR_NOMEM; - } - } else { - rv = nghttp2_session_reprioritize_stream(session, stream, - &frame->priority.pri_spec); - if (nghttp2_is_fatal(rv)) { - return rv; - } - } - - rv = nghttp2_session_adjust_idle_stream(session); - - if (nghttp2_is_fatal(rv)) { - return rv; - } - return 0; case NGHTTP2_RST_STREAM: rv = nghttp2_session_close_stream(session, frame->hd.stream_id, @@ -3239,14 +2802,6 @@ static nghttp2_ssize nghttp2_session_mem_send_internal(nghttp2_session *session, aob = &session->aob; framebufs = &aob->framebufs; - /* We may have idle streams more than we expect (e.g., - nghttp2_session_change_stream_priority() or - nghttp2_session_create_idle_stream()). Adjust them here. */ - rv = nghttp2_session_adjust_idle_stream(session); - if (nghttp2_is_fatal(rv)) { - return rv; - } - for (;;) { switch (aob->state) { case NGHTTP2_OB_POP_ITEM: { @@ -4064,7 +3619,6 @@ static int session_end_stream_headers_received(nghttp2_session *session, if (session->server && session_enforce_http_messaging(session) && frame->headers.cat == NGHTTP2_HCAT_REQUEST && - (stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES) && !(stream->flags & NGHTTP2_STREAM_FLAG_IGNORE_CLIENT_PRIORITIES) && (stream->http_flags & NGHTTP2_HTTP_FLAG_PRIORITY)) { rv = session_update_stream_priority(session, stream, stream->http_extpri); @@ -4253,18 +3807,13 @@ int nghttp2_session_on_request_headers_received(nghttp2_session *session, NGHTTP2_ERR_REFUSED_STREAM); } - stream = nghttp2_session_open_stream( - session, frame->hd.stream_id, NGHTTP2_STREAM_FLAG_NONE, - &frame->headers.pri_spec, NGHTTP2_STREAM_OPENING, NULL); + stream = nghttp2_session_open_stream(session, frame->hd.stream_id, + NGHTTP2_STREAM_FLAG_NONE, + NGHTTP2_STREAM_OPENING, NULL); if (!stream) { return NGHTTP2_ERR_NOMEM; } - rv = nghttp2_session_adjust_closed_stream(session); - if (nghttp2_is_fatal(rv)) { - return rv; - } - session->last_proc_stream_id = session->last_recv_stream_id; rv = session_call_on_begin_headers(session, frame); @@ -4425,77 +3974,6 @@ static int session_process_headers_frame(nghttp2_session *session) { return nghttp2_session_on_headers_received(session, frame, stream); } -int nghttp2_session_on_priority_received(nghttp2_session *session, - nghttp2_frame *frame) { - int rv; - nghttp2_stream *stream; - - assert(!session_no_rfc7540_pri_no_fallback(session)); - - if (frame->hd.stream_id == 0) { - return session_handle_invalid_connection(session, frame, NGHTTP2_ERR_PROTO, - "PRIORITY: stream_id == 0"); - } - - if (frame->priority.pri_spec.stream_id == frame->hd.stream_id) { - return nghttp2_session_terminate_session_with_reason( - session, NGHTTP2_PROTOCOL_ERROR, "depend on itself"); - } - - if (!session->server) { - /* Re-prioritization works only in server */ - return session_call_on_frame_received(session, frame); - } - - stream = nghttp2_session_get_stream_raw(session, frame->hd.stream_id); - - if (!stream) { - /* PRIORITY against idle stream can create anchor node in - dependency tree. */ - if (!session_detect_idle_stream(session, frame->hd.stream_id)) { - return 0; - } - - stream = nghttp2_session_open_stream( - session, frame->hd.stream_id, NGHTTP2_STREAM_FLAG_NONE, - &frame->priority.pri_spec, NGHTTP2_STREAM_IDLE, NULL); - - if (stream == NULL) { - return NGHTTP2_ERR_NOMEM; - } - - rv = nghttp2_session_adjust_idle_stream(session); - if (nghttp2_is_fatal(rv)) { - return rv; - } - } else { - rv = nghttp2_session_reprioritize_stream(session, stream, - &frame->priority.pri_spec); - - if (nghttp2_is_fatal(rv)) { - return rv; - } - - rv = nghttp2_session_adjust_idle_stream(session); - if (nghttp2_is_fatal(rv)) { - return rv; - } - } - - return session_call_on_frame_received(session, frame); -} - -static int session_process_priority_frame(nghttp2_session *session) { - nghttp2_inbound_frame *iframe = &session->iframe; - nghttp2_frame *frame = &iframe->frame; - - assert(!session_no_rfc7540_pri_no_fallback(session)); - - nghttp2_frame_unpack_priority_payload(&frame->priority, iframe->sbuf.pos); - - return nghttp2_session_on_priority_received(session, frame); -} - static int session_update_stream_reset_ratelim(nghttp2_session *session) { if (!session->server || (session->goaway_flags & NGHTTP2_GOAWAY_SUBMITTED)) { return 0; @@ -5000,7 +4478,6 @@ int nghttp2_session_on_push_promise_received(nghttp2_session *session, int rv; nghttp2_stream *stream; nghttp2_stream *promised_stream; - nghttp2_priority_spec pri_spec; if (frame->hd.stream_id == 0) { return session_inflate_handle_invalid_connection( @@ -5058,20 +4535,14 @@ int nghttp2_session_on_push_promise_received(nghttp2_session *session, session, frame, NGHTTP2_ERR_STREAM_CLOSED, "PUSH_PROMISE: stream closed"); } - nghttp2_priority_spec_init(&pri_spec, stream->stream_id, - NGHTTP2_DEFAULT_WEIGHT, 0); - promised_stream = nghttp2_session_open_stream( session, frame->push_promise.promised_stream_id, NGHTTP2_STREAM_FLAG_NONE, - &pri_spec, NGHTTP2_STREAM_RESERVED, NULL); + NGHTTP2_STREAM_RESERVED, NULL); if (!promised_stream) { return NGHTTP2_ERR_NOMEM; } - /* We don't call nghttp2_session_adjust_closed_stream(), since we - don't keep closed stream in client side */ - session->last_proc_stream_id = session->last_recv_stream_id; rv = session_call_on_begin_headers(session, frame); if (rv != 0) { @@ -5292,7 +4763,6 @@ int nghttp2_session_on_priority_update_received(nghttp2_session *session, nghttp2_frame *frame) { nghttp2_ext_priority_update *priority_update; nghttp2_stream *stream; - nghttp2_priority_spec pri_spec; nghttp2_extpri extpri; int rv; @@ -5330,10 +4800,9 @@ int nghttp2_session_on_priority_update_received(nghttp2_session *session, "PRIORITY_UPDATE: max concurrent streams exceeded"); } - nghttp2_priority_spec_default_init(&pri_spec); - stream = nghttp2_session_open_stream(session, priority_update->stream_id, - NGHTTP2_FLAG_NONE, &pri_spec, - NGHTTP2_STREAM_IDLE, NULL); + stream = + nghttp2_session_open_stream(session, priority_update->stream_id, + NGHTTP2_FLAG_NONE, NGHTTP2_STREAM_IDLE, NULL); if (!stream) { return NGHTTP2_ERR_NOMEM; } @@ -5869,14 +5338,6 @@ nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, mem = &session->mem; - /* We may have idle streams more than we expect (e.g., - nghttp2_session_change_stream_priority() or - nghttp2_session_create_idle_stream()). Adjust them here. */ - rv = nghttp2_session_adjust_idle_stream(session); - if (nghttp2_is_fatal(rv)) { - return rv; - } - if (!nghttp2_session_want_read(session)) { return (nghttp2_ssize)inlen; } @@ -6392,8 +5853,7 @@ nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, break; } - if (!session_no_rfc7540_pri_no_fallback(session) || - iframe->payloadleft > sizeof(iframe->raw_sbuf)) { + if (iframe->payloadleft > sizeof(iframe->raw_sbuf)) { busy = 1; iframe->state = NGHTTP2_IB_IGN_PAYLOAD; break; @@ -6510,18 +5970,6 @@ nghttp2_ssize nghttp2_session_mem_recv2(nghttp2_session *session, break; case NGHTTP2_PRIORITY: - if (!session_no_rfc7540_pri_no_fallback(session) && - session->remote_settings.no_rfc7540_priorities != 1) { - rv = session_process_priority_frame(session); - if (nghttp2_is_fatal(rv)) { - return rv; - } - - if (iframe->state == NGHTTP2_IB_IGN_ALL) { - return (nghttp2_ssize)inlen; - } - } - session_inbound_frame_reset(session); break; @@ -7404,9 +6852,7 @@ int nghttp2_session_want_write(nghttp2_session *session) { */ return session->aob.item || nghttp2_outbound_queue_top(&session->ob_urgent) || nghttp2_outbound_queue_top(&session->ob_reg) || - ((!nghttp2_pq_empty(&session->root.obq) || - !session_sched_empty(session)) && - session->remote_window_size > 0) || + (!session_sched_empty(session) && session->remote_window_size > 0) || (nghttp2_outbound_queue_top(&session->ob_syn) && !session_is_outgoing_concurrent_streams_max(session)); } @@ -8046,7 +7492,6 @@ static int nghttp2_session_upgrade_internal(nghttp2_session *session, nghttp2_settings_entry *iv; size_t niv; int rv; - nghttp2_priority_spec pri_spec; nghttp2_mem *mem; mem = &session->mem; @@ -8083,18 +7528,13 @@ static int nghttp2_session_upgrade_internal(nghttp2_session *session, return rv; } - nghttp2_priority_spec_default_init(&pri_spec); - stream = nghttp2_session_open_stream( - session, 1, NGHTTP2_STREAM_FLAG_NONE, &pri_spec, NGHTTP2_STREAM_OPENING, + session, 1, NGHTTP2_STREAM_FLAG_NONE, NGHTTP2_STREAM_OPENING, session->server ? NULL : stream_user_data); if (stream == NULL) { return NGHTTP2_ERR_NOMEM; } - /* We don't call nghttp2_session_adjust_closed_stream(), since this - should be the first stream open. */ - if (session->server) { nghttp2_stream_shutdown(stream, NGHTTP2_SHUT_RD); session->last_recv_stream_id = 1; @@ -8293,14 +7733,16 @@ int32_t nghttp2_session_get_last_proc_stream_id(nghttp2_session *session) { nghttp2_stream *nghttp2_session_find_stream(nghttp2_session *session, int32_t stream_id) { if (stream_id == 0) { - return &session->root; + return &root; } return nghttp2_session_get_stream_raw(session, stream_id); } nghttp2_stream *nghttp2_session_get_root_stream(nghttp2_session *session) { - return &session->root; + (void)session; + + return &root; } int nghttp2_session_check_server_session(nghttp2_session *session) { @@ -8310,75 +7752,20 @@ int nghttp2_session_check_server_session(nghttp2_session *session) { int nghttp2_session_change_stream_priority( nghttp2_session *session, int32_t stream_id, const nghttp2_priority_spec *pri_spec) { - int rv; - nghttp2_stream *stream; - nghttp2_priority_spec pri_spec_copy; + (void)session; + (void)stream_id; + (void)pri_spec; - if (session->pending_no_rfc7540_priorities == 1) { - return 0; - } - - if (stream_id == 0 || stream_id == pri_spec->stream_id) { - return NGHTTP2_ERR_INVALID_ARGUMENT; - } - - stream = nghttp2_session_get_stream_raw(session, stream_id); - if (!stream) { - return NGHTTP2_ERR_INVALID_ARGUMENT; - } - - pri_spec_copy = *pri_spec; - nghttp2_priority_spec_normalize_weight(&pri_spec_copy); - - rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec_copy); - - if (nghttp2_is_fatal(rv)) { - return rv; - } - - /* We don't intentionally call nghttp2_session_adjust_idle_stream() - so that idle stream created by this function, and existing ones - are kept for application. We will adjust number of idle stream - in nghttp2_session_mem_send2 or nghttp2_session_mem_recv2 is - called. */ return 0; } int nghttp2_session_create_idle_stream(nghttp2_session *session, int32_t stream_id, const nghttp2_priority_spec *pri_spec) { - nghttp2_stream *stream; - nghttp2_priority_spec pri_spec_copy; + (void)session; + (void)stream_id; + (void)pri_spec; - if (session->pending_no_rfc7540_priorities == 1) { - return 0; - } - - if (stream_id == 0 || stream_id == pri_spec->stream_id || - !session_detect_idle_stream(session, stream_id)) { - return NGHTTP2_ERR_INVALID_ARGUMENT; - } - - stream = nghttp2_session_get_stream_raw(session, stream_id); - if (stream) { - return NGHTTP2_ERR_INVALID_ARGUMENT; - } - - pri_spec_copy = *pri_spec; - nghttp2_priority_spec_normalize_weight(&pri_spec_copy); - - stream = - nghttp2_session_open_stream(session, stream_id, NGHTTP2_STREAM_FLAG_NONE, - &pri_spec_copy, NGHTTP2_STREAM_IDLE, NULL); - if (!stream) { - return NGHTTP2_ERR_NOMEM; - } - - /* We don't intentionally call nghttp2_session_adjust_idle_stream() - so that idle stream created by this function, and existing ones - are kept for application. We will adjust number of idle stream - in nghttp2_session_mem_send2 or nghttp2_session_mem_recv2 is - called. */ return 0; } diff --git a/lib/nghttp2_session.h b/lib/nghttp2_session.h index ef8f7b27..7946d714 100644 --- a/lib/nghttp2_session.h +++ b/lib/nghttp2_session.h @@ -45,6 +45,8 @@ preface handling. */ extern int nghttp2_enable_strict_preface; +extern nghttp2_stream root; + /* * Option flags. */ @@ -89,10 +91,6 @@ typedef struct { /* The default maximum number of incoming reserved streams */ #define NGHTTP2_MAX_INCOMING_RESERVED_STREAMS 200 -/* Even if we have less SETTINGS_MAX_CONCURRENT_STREAMS than this - number, we keep NGHTTP2_MIN_IDLE_STREAMS streams in idle state */ -#define NGHTTP2_MIN_IDLE_STREAMS 16 - /* The maximum number of items in outbound queue, which is considered as flooding caused by peer. All frames are not considered here. We only consider PING + ACK and SETTINGS + ACK. This is because @@ -205,8 +203,6 @@ typedef struct nghttp2_inflight_settings nghttp2_inflight_settings; struct nghttp2_session { nghttp2_map /* */ streams; - /* root of dependency tree*/ - nghttp2_stream root; /* Queue for outbound urgent frames (PING and SETTINGS) */ nghttp2_outbound_queue ob_urgent; /* Queue for non-DATA frames */ @@ -229,20 +225,6 @@ struct nghttp2_session { /* Memory allocator */ nghttp2_mem mem; void *user_data; - /* Points to the latest incoming closed stream. NULL if there is no - closed stream. Only used when session is initialized as - server. */ - nghttp2_stream *closed_stream_head; - /* Points to the oldest incoming closed stream. NULL if there is no - closed stream. Only used when session is initialized as - server. */ - nghttp2_stream *closed_stream_tail; - /* Points to the latest idle stream. NULL if there is no idle - stream. Only used when session is initialized as server .*/ - nghttp2_stream *idle_stream_head; - /* Points to the oldest idle stream. NULL if there is no idle - stream. Only used when session is initialized as erver. */ - nghttp2_stream *idle_stream_tail; /* Queue of In-flight SETTINGS values. SETTINGS bearing ACK is not considered as in-flight. */ nghttp2_inflight_settings *inflight_settings_head; @@ -276,10 +258,9 @@ struct nghttp2_session { |closed_stream_head|. The current implementation only keeps incoming streams and session is initialized as server. */ size_t num_closed_streams; - /* The number of idle streams kept in |streams| hash. The idle - streams can be accessed through doubly linked list - |idle_stream_head|. The current implementation only keeps idle - streams if session is initialized as server. */ + /* The number of idle streams kept in |streams| hash. The current + implementation only keeps idle streams if session is initialized + as server. */ size_t num_idle_streams; /* The number of bytes allocated for nvbuf */ size_t nvbuflen; @@ -527,15 +508,9 @@ int nghttp2_session_add_settings(nghttp2_session *session, uint8_t flags, * * This function returns a pointer to created new stream object, or * NULL. - * - * This function adjusts neither the number of closed streams or idle - * streams. The caller should manually call - * nghttp2_session_adjust_closed_stream() or - * nghttp2_session_adjust_idle_stream() respectively. */ nghttp2_stream *nghttp2_session_open_stream(nghttp2_session *session, int32_t stream_id, uint8_t flags, - nghttp2_priority_spec *pri_spec, nghttp2_stream_state initial_state, void *stream_user_data); @@ -544,11 +519,6 @@ nghttp2_stream *nghttp2_session_open_stream(nghttp2_session *session, * is indicated by the |error_code|. When closing the stream, * on_stream_close_callback will be called. * - * If the session is initialized as server and |stream| is incoming - * stream, stream is just marked closed and this function calls - * nghttp2_session_keep_closed_stream() with |stream|. Otherwise, - * |stream| will be deleted from memory. - * * This function returns 0 if it succeeds, or one the following * negative error codes: * @@ -565,63 +535,9 @@ int nghttp2_session_close_stream(nghttp2_session *session, int32_t stream_id, /* * Deletes |stream| from memory. After this function returns, stream * cannot be accessed. - * - * This function returns 0 if it succeeds, or one the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory */ -int nghttp2_session_destroy_stream(nghttp2_session *session, - nghttp2_stream *stream); - -/* - * Tries to keep incoming closed stream |stream|. Due to the - * limitation of maximum number of streams in memory, |stream| is not - * closed and just deleted from memory (see - * nghttp2_session_destroy_stream). - */ -void nghttp2_session_keep_closed_stream(nghttp2_session *session, - nghttp2_stream *stream); - -/* - * Appends |stream| to linked list |session->idle_stream_head|. We - * apply fixed limit for list size. To fit into that limit, one or - * more oldest streams are removed from list as necessary. - */ -void nghttp2_session_keep_idle_stream(nghttp2_session *session, - nghttp2_stream *stream); - -/* - * Detaches |stream| from idle streams linked list. - */ -void nghttp2_session_detach_idle_stream(nghttp2_session *session, - nghttp2_stream *stream); - -/* - * Deletes closed stream to ensure that number of incoming streams - * including active and closed is in the maximum number of allowed - * stream. - * - * This function returns 0 if it succeeds, or one the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_session_adjust_closed_stream(nghttp2_session *session); - -/* - * Deletes idle stream to ensure that number of idle streams is in - * certain limit. - * - * This function returns 0 if it succeeds, or one the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_session_adjust_idle_stream(nghttp2_session *session); +void nghttp2_session_destroy_stream(nghttp2_session *session, + nghttp2_stream *stream); /* * If further receptions and transmissions over the stream |stream_id| @@ -915,24 +831,6 @@ int nghttp2_session_update_local_settings(nghttp2_session *session, nghttp2_settings_entry *iv, size_t niv); -/* - * Re-prioritize |stream|. The new priority specification is - * |pri_spec|. Caller must ensure that stream->hd.stream_id != - * pri_spec->stream_id. - * - * This function does not adjust the number of idle streams. The - * caller should call nghttp2_session_adjust_idle_stream() later. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_session_reprioritize_stream(nghttp2_session *session, - nghttp2_stream *stream, - const nghttp2_priority_spec *pri_spec); - /* * Terminates current |session| with the |error_code|. The |reason| * is NULL-terminated debug string. diff --git a/lib/nghttp2_stream.c b/lib/nghttp2_stream.c index f2362447..afbd7c2d 100644 --- a/lib/nghttp2_stream.c +++ b/lib/nghttp2_stream.c @@ -25,45 +25,17 @@ #include "nghttp2_stream.h" #include -#include #include "nghttp2_session.h" #include "nghttp2_helper.h" #include "nghttp2_debug.h" #include "nghttp2_frame.h" -/* Maximum distance between any two stream's cycle in the same - priority queue. Imagine stream A's cycle is A, and stream B's - cycle is B, and A < B. The cycle is unsigned 32 bit integer, it - may get overflow. Because of how we calculate the next cycle - value, if B - A is less than or equals to - NGHTTP2_MAX_CYCLE_DISTANCE, A and B are in the same scale, in other - words, B is really greater than or equal to A. Otherwise, A is a - result of overflow, and it is actually A > B if we consider that - fact. */ -#define NGHTTP2_MAX_CYCLE_DISTANCE \ - ((uint64_t)NGHTTP2_MAX_FRAME_SIZE_MAX * 256 + 255) - -static int stream_less(const void *lhsx, const void *rhsx) { - const nghttp2_stream *lhs, *rhs; - - lhs = nghttp2_struct_of(lhsx, nghttp2_stream, pq_entry); - rhs = nghttp2_struct_of(rhsx, nghttp2_stream, pq_entry); - - if (lhs->cycle == rhs->cycle) { - return lhs->seq < rhs->seq; - } - - return rhs->cycle - lhs->cycle <= NGHTTP2_MAX_CYCLE_DISTANCE; -} - void nghttp2_stream_init(nghttp2_stream *stream, int32_t stream_id, uint8_t flags, nghttp2_stream_state initial_state, - int32_t weight, int32_t remote_initial_window_size, + int32_t remote_initial_window_size, int32_t local_initial_window_size, - void *stream_user_data, nghttp2_mem *mem) { - nghttp2_pq_init(&stream->obq, stream_less, mem); - + void *stream_user_data) { stream->stream_id = stream_id; stream->flags = flags; stream->state = initial_state; @@ -77,428 +49,36 @@ void nghttp2_stream_init(nghttp2_stream *stream, int32_t stream_id, stream->recv_reduction = 0; stream->window_update_queued = 0; - stream->dep_prev = NULL; - stream->dep_next = NULL; - stream->sib_prev = NULL; - stream->sib_next = NULL; - - stream->closed_prev = NULL; stream->closed_next = NULL; - stream->weight = weight; - stream->sum_dep_weight = 0; - stream->http_flags = NGHTTP2_HTTP_FLAG_NONE; stream->content_length = -1; stream->recv_content_length = 0; stream->status_code = -1; stream->queued = 0; - stream->descendant_last_cycle = 0; stream->cycle = 0; stream->pending_penalty = 0; - stream->descendant_next_seq = 0; stream->seq = 0; stream->last_writelen = 0; stream->extpri = stream->http_extpri = NGHTTP2_EXTPRI_DEFAULT_URGENCY; } -void nghttp2_stream_free(nghttp2_stream *stream) { - nghttp2_pq_free(&stream->obq); - /* We don't free stream->item. If it is assigned to aob, then - active_outbound_item_reset() will delete it. Otherwise, - nghttp2_stream_close() or session_del() will delete it. */ -} +void nghttp2_stream_free(nghttp2_stream *stream) { (void)stream; } void nghttp2_stream_shutdown(nghttp2_stream *stream, nghttp2_shut_flag flag) { stream->shut_flags = (uint8_t)(stream->shut_flags | flag); } -/* - * Returns nonzero if |stream| is active. This function does not take - * into account its descendants. - */ -static int stream_active(nghttp2_stream *stream) { - return stream->item && - (stream->flags & NGHTTP2_STREAM_FLAG_DEFERRED_ALL) == 0; -} - -/* - * Returns nonzero if |stream| or one of its descendants is active - */ -static int stream_subtree_active(nghttp2_stream *stream) { - return stream_active(stream) || !nghttp2_pq_empty(&stream->obq); -} - -/* - * Returns next cycle for |stream|. - */ -static void stream_next_cycle(nghttp2_stream *stream, uint64_t last_cycle) { - uint64_t penalty; - - penalty = (uint64_t)stream->last_writelen * NGHTTP2_MAX_WEIGHT + - stream->pending_penalty; - - stream->cycle = last_cycle + penalty / (uint32_t)stream->weight; - stream->pending_penalty = (uint32_t)(penalty % (uint32_t)stream->weight); -} - -static int stream_obq_push(nghttp2_stream *dep_stream, nghttp2_stream *stream) { - int rv; - - for (; dep_stream && !stream->queued; - stream = dep_stream, dep_stream = dep_stream->dep_prev) { - stream_next_cycle(stream, dep_stream->descendant_last_cycle); - stream->seq = dep_stream->descendant_next_seq++; - - DEBUGF("stream: stream=%d obq push cycle=%lu\n", stream->stream_id, - stream->cycle); - - DEBUGF("stream: push stream %d to stream %d\n", stream->stream_id, - dep_stream->stream_id); - - rv = nghttp2_pq_push(&dep_stream->obq, &stream->pq_entry); - if (rv != 0) { - return rv; - } - stream->queued = 1; - } - - return 0; -} - -/* - * Removes |stream| from parent's obq. If removal of |stream| makes - * parent's obq empty, and parent is not active, then parent is also - * removed. This process is repeated recursively. - */ -static void stream_obq_remove(nghttp2_stream *stream) { - nghttp2_stream *dep_stream; - - dep_stream = stream->dep_prev; - - if (!stream->queued) { - return; - } - - for (; dep_stream; stream = dep_stream, dep_stream = dep_stream->dep_prev) { - DEBUGF("stream: remove stream %d from stream %d\n", stream->stream_id, - dep_stream->stream_id); - - nghttp2_pq_remove(&dep_stream->obq, &stream->pq_entry); - - assert(stream->queued); - - stream->queued = 0; - stream->cycle = 0; - stream->pending_penalty = 0; - stream->descendant_last_cycle = 0; - stream->last_writelen = 0; - - if (stream_subtree_active(dep_stream)) { - return; - } - } -} - -/* - * Moves |stream| from |src|'s obq to |dest|'s obq. Removal from - * |src|'s obq is just done calling nghttp2_pq_remove(), so it does - * not recursively remove |src| and ancestors, like - * stream_obq_remove(). - */ -static int stream_obq_move(nghttp2_stream *dest, nghttp2_stream *src, - nghttp2_stream *stream) { - if (!stream->queued) { - return 0; - } - - DEBUGF("stream: remove stream %d from stream %d (move)\n", stream->stream_id, - src->stream_id); - - nghttp2_pq_remove(&src->obq, &stream->pq_entry); - stream->queued = 0; - - return stream_obq_push(dest, stream); -} - -void nghttp2_stream_reschedule(nghttp2_stream *stream) { - nghttp2_stream *dep_stream; - - assert(stream->queued); - - dep_stream = stream->dep_prev; - - for (; dep_stream; stream = dep_stream, dep_stream = dep_stream->dep_prev) { - nghttp2_pq_remove(&dep_stream->obq, &stream->pq_entry); - - stream_next_cycle(stream, dep_stream->descendant_last_cycle); - stream->seq = dep_stream->descendant_next_seq++; - - nghttp2_pq_push(&dep_stream->obq, &stream->pq_entry); - - DEBUGF("stream: stream=%d obq resched cycle=%lu\n", stream->stream_id, - stream->cycle); - - dep_stream->last_writelen = stream->last_writelen; - } -} - -void nghttp2_stream_change_weight(nghttp2_stream *stream, int32_t weight) { - nghttp2_stream *dep_stream; - uint64_t last_cycle; - int32_t old_weight; - uint64_t wlen_penalty; - - if (stream->weight == weight) { - return; - } - - old_weight = stream->weight; - stream->weight = weight; - - dep_stream = stream->dep_prev; - - if (!dep_stream) { - return; - } - - dep_stream->sum_dep_weight += weight - old_weight; - - if (!stream->queued) { - return; - } - - nghttp2_pq_remove(&dep_stream->obq, &stream->pq_entry); - - wlen_penalty = (uint64_t)stream->last_writelen * NGHTTP2_MAX_WEIGHT; - - /* Compute old stream->pending_penalty we used to calculate - stream->cycle */ - stream->pending_penalty = - (uint32_t)((stream->pending_penalty + (uint32_t)old_weight - - (wlen_penalty % (uint32_t)old_weight)) % - (uint32_t)old_weight); - - last_cycle = stream->cycle - - (wlen_penalty + stream->pending_penalty) / (uint32_t)old_weight; - - /* Now we have old stream->pending_penalty and new stream->weight in - place */ - stream_next_cycle(stream, last_cycle); - - if (dep_stream->descendant_last_cycle - stream->cycle <= - NGHTTP2_MAX_CYCLE_DISTANCE) { - stream->cycle = dep_stream->descendant_last_cycle; - } - - /* Continue to use same stream->seq */ - - nghttp2_pq_push(&dep_stream->obq, &stream->pq_entry); - - DEBUGF("stream: stream=%d obq resched cycle=%lu\n", stream->stream_id, - stream->cycle); -} - -static nghttp2_stream *stream_last_sib(nghttp2_stream *stream) { - for (; stream->sib_next; stream = stream->sib_next) - ; - - return stream; -} - -int32_t nghttp2_stream_dep_distributed_weight(nghttp2_stream *stream, - int32_t weight) { - weight = stream->weight * weight / stream->sum_dep_weight; - - return nghttp2_max_int32(1, weight); -} - -#ifdef STREAM_DEP_DEBUG - -static void ensure_inactive(nghttp2_stream *stream) { - nghttp2_stream *si; - - if (stream->queued) { - fprintf(stderr, "stream(%p)=%d, stream->queued = 1; want 0\n", stream, - stream->stream_id); - assert(0); - } - - if (stream_active(stream)) { - fprintf(stderr, "stream(%p)=%d, stream_active(stream) = 1; want 0\n", - stream, stream->stream_id); - assert(0); - } - - if (!nghttp2_pq_empty(&stream->obq)) { - fprintf(stderr, "stream(%p)=%d, nghttp2_pq_size() = %zu; want 0\n", stream, - stream->stream_id, nghttp2_pq_size(&stream->obq)); - assert(0); - } - - for (si = stream->dep_next; si; si = si->sib_next) { - ensure_inactive(si); - } -} - -static void check_queued(nghttp2_stream *stream) { - nghttp2_stream *si; - int queued; - - if (stream->queued) { - if (!stream_subtree_active(stream)) { - fprintf(stderr, - "stream(%p)=%d, stream->queued == 1, but " - "stream_active() == %d and nghttp2_pq_size(&stream->obq) = %zu\n", - stream, stream->stream_id, stream_active(stream), - nghttp2_pq_size(&stream->obq)); - assert(0); - } - if (!stream_active(stream)) { - queued = 0; - for (si = stream->dep_next; si; si = si->sib_next) { - if (si->queued) { - ++queued; - } - } - if (queued == 0) { - fprintf(stderr, - "stream(%p)=%d, stream->queued == 1, and " - "!stream_active(), but no descendants is queued\n", - stream, stream->stream_id); - assert(0); - } - } - - for (si = stream->dep_next; si; si = si->sib_next) { - check_queued(si); - } - } else { - if (stream_active(stream) || !nghttp2_pq_empty(&stream->obq)) { - fprintf(stderr, - "stream(%p) = %d, stream->queued == 0, but " - "stream_active(stream) == %d and " - "nghttp2_pq_size(&stream->obq) = %zu\n", - stream, stream->stream_id, stream_active(stream), - nghttp2_pq_size(&stream->obq)); - assert(0); - } - for (si = stream->dep_next; si; si = si->sib_next) { - ensure_inactive(si); - } - } -} - -static void check_sum_dep(nghttp2_stream *stream) { - nghttp2_stream *si; - int32_t n = 0; - for (si = stream->dep_next; si; si = si->sib_next) { - n += si->weight; - } - if (n != stream->sum_dep_weight) { - fprintf(stderr, "stream(%p)=%d, sum_dep_weight = %d; want %d\n", stream, - stream->stream_id, n, stream->sum_dep_weight); - assert(0); - } - for (si = stream->dep_next; si; si = si->sib_next) { - check_sum_dep(si); - } -} - -static void check_dep_prev(nghttp2_stream *stream) { - nghttp2_stream *si; - for (si = stream->dep_next; si; si = si->sib_next) { - if (si->dep_prev != stream) { - fprintf(stderr, "si->dep_prev = %p; want %p\n", si->dep_prev, stream); - assert(0); - } - check_dep_prev(si); - } -} - -#endif /* STREAM_DEP_DEBUG */ - -#ifdef STREAM_DEP_DEBUG -static void validate_tree(nghttp2_stream *stream) { - nghttp2_stream *si; - - if (!stream) { - return; - } - - for (; stream->dep_prev; stream = stream->dep_prev) - ; - - assert(stream->stream_id == 0); - assert(!stream->queued); - - fprintf(stderr, "checking...\n"); - if (nghttp2_pq_empty(&stream->obq)) { - fprintf(stderr, "root obq empty\n"); - for (si = stream->dep_next; si; si = si->sib_next) { - ensure_inactive(si); - } - } else { - for (si = stream->dep_next; si; si = si->sib_next) { - check_queued(si); - } - } - - check_sum_dep(stream); - check_dep_prev(stream); -} -#else /* !STREAM_DEP_DEBUG */ -static void validate_tree(nghttp2_stream *stream) { (void)stream; } -#endif /* !STREAM_DEP_DEBUG*/ - -static int stream_update_dep_on_attach_item(nghttp2_stream *stream) { - int rv; - - rv = stream_obq_push(stream->dep_prev, stream); - if (rv != 0) { - return rv; - } - - validate_tree(stream); - return 0; -} - -static void stream_update_dep_on_detach_item(nghttp2_stream *stream) { - if (nghttp2_pq_empty(&stream->obq)) { - stream_obq_remove(stream); - } - - validate_tree(stream); -} - -int nghttp2_stream_attach_item(nghttp2_stream *stream, - nghttp2_outbound_item *item) { - int rv; - +void nghttp2_stream_attach_item(nghttp2_stream *stream, + nghttp2_outbound_item *item) { assert((stream->flags & NGHTTP2_STREAM_FLAG_DEFERRED_ALL) == 0); assert(stream->item == NULL); DEBUGF("stream: stream=%d attach item=%p\n", stream->stream_id, item); stream->item = item; - - if (stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES) { - return 0; - } - - rv = stream_update_dep_on_attach_item(stream); - if (rv != 0) { - /* This may relave stream->queued == 1, but stream->item == NULL. - But only consequence of this error is fatal one, and session - destruction. In that execution path, these inconsistency does - not matter. */ - stream->item = NULL; - return rv; - } - - return 0; } void nghttp2_stream_detach_item(nghttp2_stream *stream) { @@ -506,12 +86,6 @@ void nghttp2_stream_detach_item(nghttp2_stream *stream) { stream->item = NULL; stream->flags = (uint8_t)(stream->flags & ~NGHTTP2_STREAM_FLAG_DEFERRED_ALL); - - if (stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES) { - return; - } - - stream_update_dep_on_detach_item(stream); } void nghttp2_stream_defer_item(nghttp2_stream *stream, uint8_t flags) { @@ -521,31 +95,16 @@ void nghttp2_stream_defer_item(nghttp2_stream *stream, uint8_t flags) { stream->item, flags); stream->flags |= flags; - - if (stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES) { - return; - } - - stream_update_dep_on_detach_item(stream); } -int nghttp2_stream_resume_deferred_item(nghttp2_stream *stream, uint8_t flags) { +void nghttp2_stream_resume_deferred_item(nghttp2_stream *stream, + uint8_t flags) { assert(stream->item); DEBUGF("stream: stream=%d resume item=%p flags=%02x\n", stream->stream_id, stream->item, flags); stream->flags = (uint8_t)(stream->flags & ~flags); - - if (stream->flags & NGHTTP2_STREAM_FLAG_DEFERRED_ALL) { - return 0; - } - - if (stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES) { - return 0; - } - - return stream_update_dep_on_attach_item(stream); } int nghttp2_stream_check_deferred_item(nghttp2_stream *stream) { @@ -591,373 +150,11 @@ void nghttp2_stream_promise_fulfilled(nghttp2_stream *stream) { stream->flags = (uint8_t)(stream->flags & ~NGHTTP2_STREAM_FLAG_PUSH); } -int nghttp2_stream_dep_find_ancestor(nghttp2_stream *stream, - nghttp2_stream *target) { - for (; stream; stream = stream->dep_prev) { - if (stream == target) { - return 1; - } - } - return 0; -} - -int nghttp2_stream_dep_insert(nghttp2_stream *dep_stream, - nghttp2_stream *stream) { - nghttp2_stream *si; - int rv; - - DEBUGF("stream: dep_insert dep_stream(%p)=%d, stream(%p)=%d\n", dep_stream, - dep_stream->stream_id, stream, stream->stream_id); - - stream->sum_dep_weight = dep_stream->sum_dep_weight; - dep_stream->sum_dep_weight = stream->weight; - - if (dep_stream->dep_next) { - for (si = dep_stream->dep_next; si; si = si->sib_next) { - si->dep_prev = stream; - if (si->queued) { - rv = stream_obq_move(stream, dep_stream, si); - if (rv != 0) { - return rv; - } - } - } - - if (stream_subtree_active(stream)) { - rv = stream_obq_push(dep_stream, stream); - if (rv != 0) { - return rv; - } - } - - stream->dep_next = dep_stream->dep_next; - } - - dep_stream->dep_next = stream; - stream->dep_prev = dep_stream; - - validate_tree(stream); - - return 0; -} - -static void set_dep_prev(nghttp2_stream *stream, nghttp2_stream *dep) { - for (; stream; stream = stream->sib_next) { - stream->dep_prev = dep; - } -} - -static void link_dep(nghttp2_stream *dep_stream, nghttp2_stream *stream) { - dep_stream->dep_next = stream; - if (stream) { - stream->dep_prev = dep_stream; - } -} - -static void link_sib(nghttp2_stream *a, nghttp2_stream *b) { - a->sib_next = b; - if (b) { - b->sib_prev = a; - } -} - -static void insert_link_dep(nghttp2_stream *dep_stream, - nghttp2_stream *stream) { - nghttp2_stream *sib_next; - - assert(stream->sib_prev == NULL); - - sib_next = dep_stream->dep_next; - - link_sib(stream, sib_next); - - link_dep(dep_stream, stream); -} - -static void unlink_sib(nghttp2_stream *stream) { - nghttp2_stream *prev, *next, *dep_next; - - prev = stream->sib_prev; - dep_next = stream->dep_next; - - assert(prev); - - if (dep_next) { - /* - * prev--stream(--sib_next--...) - * | - * dep_next - */ - - link_sib(prev, dep_next); - - set_dep_prev(dep_next, stream->dep_prev); - - if (stream->sib_next) { - link_sib(stream_last_sib(dep_next), stream->sib_next); - } - } else { - /* - * prev--stream(--sib_next--...) - */ - next = stream->sib_next; - - prev->sib_next = next; - - if (next) { - next->sib_prev = prev; - } - } -} - -static void unlink_dep(nghttp2_stream *stream) { - nghttp2_stream *prev, *next, *dep_next; - - prev = stream->dep_prev; - dep_next = stream->dep_next; - - assert(prev); - - if (dep_next) { - /* - * prev - * | - * stream(--sib_next--...) - * | - * dep_next - */ - link_dep(prev, dep_next); - - set_dep_prev(dep_next, stream->dep_prev); - - if (stream->sib_next) { - link_sib(stream_last_sib(dep_next), stream->sib_next); - } - - } else if (stream->sib_next) { - /* - * prev - * | - * stream--sib_next - */ - next = stream->sib_next; - - next->sib_prev = NULL; - - link_dep(prev, next); - } else { - prev->dep_next = NULL; - } -} - -void nghttp2_stream_dep_add(nghttp2_stream *dep_stream, - nghttp2_stream *stream) { - DEBUGF("stream: dep_add dep_stream(%p)=%d, stream(%p)=%d\n", dep_stream, - dep_stream->stream_id, stream, stream->stream_id); - - dep_stream->sum_dep_weight += stream->weight; - - if (dep_stream->dep_next == NULL) { - link_dep(dep_stream, stream); - } else { - insert_link_dep(dep_stream, stream); - } - - validate_tree(stream); -} - -int nghttp2_stream_dep_remove(nghttp2_stream *stream) { - nghttp2_stream *dep_prev, *si; - int32_t sum_dep_weight_delta; - int rv; - - DEBUGF("stream: dep_remove stream(%p)=%d\n", stream, stream->stream_id); - - /* Distribute weight of |stream| to direct descendants */ - sum_dep_weight_delta = -stream->weight; - - for (si = stream->dep_next; si; si = si->sib_next) { - si->weight = nghttp2_stream_dep_distributed_weight(stream, si->weight); - - sum_dep_weight_delta += si->weight; - - if (si->queued) { - rv = stream_obq_move(stream->dep_prev, stream, si); - if (rv != 0) { - return rv; - } - } - } - - assert(stream->dep_prev); - - dep_prev = stream->dep_prev; - - dep_prev->sum_dep_weight += sum_dep_weight_delta; - - if (stream->queued) { - stream_obq_remove(stream); - } - - if (stream->sib_prev) { - unlink_sib(stream); - } else { - unlink_dep(stream); - } - - stream->sum_dep_weight = 0; - - stream->dep_prev = NULL; - stream->dep_next = NULL; - stream->sib_prev = NULL; - stream->sib_next = NULL; - - validate_tree(dep_prev); - - return 0; -} - -int nghttp2_stream_dep_insert_subtree(nghttp2_stream *dep_stream, - nghttp2_stream *stream) { - nghttp2_stream *last_sib; - nghttp2_stream *dep_next; - nghttp2_stream *si; - int rv; - - DEBUGF("stream: dep_insert_subtree dep_stream(%p)=%d stream(%p)=%d\n", - dep_stream, dep_stream->stream_id, stream, stream->stream_id); - - stream->sum_dep_weight += dep_stream->sum_dep_weight; - dep_stream->sum_dep_weight = stream->weight; - - if (dep_stream->dep_next) { - dep_next = dep_stream->dep_next; - - link_dep(dep_stream, stream); - - if (stream->dep_next) { - last_sib = stream_last_sib(stream->dep_next); - - link_sib(last_sib, dep_next); - } else { - link_dep(stream, dep_next); - } - - for (si = dep_next; si; si = si->sib_next) { - si->dep_prev = stream; - if (si->queued) { - rv = stream_obq_move(stream, dep_stream, si); - if (rv != 0) { - return rv; - } - } - } - } else { - link_dep(dep_stream, stream); - } - - if (stream_subtree_active(stream)) { - rv = stream_obq_push(dep_stream, stream); - if (rv != 0) { - return rv; - } - } - - validate_tree(dep_stream); - - return 0; -} - -int nghttp2_stream_dep_add_subtree(nghttp2_stream *dep_stream, - nghttp2_stream *stream) { - int rv; - - DEBUGF("stream: dep_add_subtree dep_stream(%p)=%d stream(%p)=%d\n", - dep_stream, dep_stream->stream_id, stream, stream->stream_id); - - dep_stream->sum_dep_weight += stream->weight; - - if (dep_stream->dep_next) { - insert_link_dep(dep_stream, stream); - } else { - link_dep(dep_stream, stream); - } - - if (stream_subtree_active(stream)) { - rv = stream_obq_push(dep_stream, stream); - if (rv != 0) { - return rv; - } - } - - validate_tree(dep_stream); - - return 0; -} - -void nghttp2_stream_dep_remove_subtree(nghttp2_stream *stream) { - nghttp2_stream *next, *dep_prev; - - DEBUGF("stream: dep_remove_subtree stream(%p)=%d\n", stream, - stream->stream_id); - - assert(stream->dep_prev); - - dep_prev = stream->dep_prev; - - if (stream->sib_prev) { - link_sib(stream->sib_prev, stream->sib_next); - } else { - next = stream->sib_next; - - link_dep(dep_prev, next); - - if (next) { - next->sib_prev = NULL; - } - } - - dep_prev->sum_dep_weight -= stream->weight; - - if (stream->queued) { - stream_obq_remove(stream); - } - - validate_tree(dep_prev); - - stream->sib_prev = NULL; - stream->sib_next = NULL; - stream->dep_prev = NULL; -} - -int nghttp2_stream_in_dep_tree(nghttp2_stream *stream) { - return stream->dep_prev || stream->dep_next || stream->sib_prev || - stream->sib_next; -} - -nghttp2_outbound_item * -nghttp2_stream_next_outbound_item(nghttp2_stream *stream) { - nghttp2_pq_entry *ent; - nghttp2_stream *si; - - for (;;) { - if (stream_active(stream)) { - /* Update ascendant's descendant_last_cycle here, so that we can - assure that new stream is scheduled based on it. */ - for (si = stream; si->dep_prev; si = si->dep_prev) { - si->dep_prev->descendant_last_cycle = si->cycle; - } - return stream->item; - } - ent = nghttp2_pq_top(&stream->obq); - if (!ent) { - return NULL; - } - stream = nghttp2_struct_of(ent, nghttp2_stream, pq_entry); - } -} - nghttp2_stream_proto_state nghttp2_stream_get_state(nghttp2_stream *stream) { + if (stream == &root) { + return NGHTTP2_STREAM_STATE_IDLE; + } + if (stream->flags & NGHTTP2_STREAM_FLAG_CLOSED) { return NGHTTP2_STREAM_STATE_CLOSED; } @@ -988,27 +185,39 @@ nghttp2_stream_proto_state nghttp2_stream_get_state(nghttp2_stream *stream) { } nghttp2_stream *nghttp2_stream_get_parent(nghttp2_stream *stream) { - return stream->dep_prev; + (void)stream; + + return NULL; } nghttp2_stream *nghttp2_stream_get_next_sibling(nghttp2_stream *stream) { - return stream->sib_next; + (void)stream; + + return NULL; } nghttp2_stream *nghttp2_stream_get_previous_sibling(nghttp2_stream *stream) { - return stream->sib_prev; + (void)stream; + + return NULL; } nghttp2_stream *nghttp2_stream_get_first_child(nghttp2_stream *stream) { - return stream->dep_next; + (void)stream; + + return NULL; } int32_t nghttp2_stream_get_weight(nghttp2_stream *stream) { - return stream->weight; + (void)stream; + + return NGHTTP2_DEFAULT_WEIGHT; } int32_t nghttp2_stream_get_sum_dependency_weight(nghttp2_stream *stream) { - return stream->sum_dep_weight; + (void)stream; + + return 0; } int32_t nghttp2_stream_get_stream_id(nghttp2_stream *stream) { diff --git a/lib/nghttp2_stream.h b/lib/nghttp2_stream.h index 28add165..e73cd283 100644 --- a/lib/nghttp2_stream.h +++ b/lib/nghttp2_stream.h @@ -91,9 +91,6 @@ typedef enum { /* bitwise OR of NGHTTP2_STREAM_FLAG_DEFERRED_FLOW_CONTROL and NGHTTP2_STREAM_FLAG_DEFERRED_USER. */ NGHTTP2_STREAM_FLAG_DEFERRED_ALL = 0x0c, - /* Indicates that this stream is not subject to RFC7540 - priorities scheme. */ - NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES = 0x10, /* Ignore client RFC 9218 priority signal. */ NGHTTP2_STREAM_FLAG_IGNORE_CLIENT_PRIORITIES = 0x20, /* Indicates that RFC 9113 leading and trailing white spaces @@ -146,39 +143,18 @@ typedef enum { } nghttp2_http_flag; struct nghttp2_stream { - /* Entry for dep_prev->obq */ + nghttp2_stream_state state; nghttp2_pq_entry pq_entry; - /* Priority Queue storing direct descendant (nghttp2_stream). Only - streams which itself has some data to send, or has a descendant - which has some data to sent. */ - nghttp2_pq obq; /* Content-Length of request/response body. -1 if unknown. */ int64_t content_length; /* Received body so far */ int64_t recv_content_length; - /* Base last_cycle for direct descendent streams. */ - uint64_t descendant_last_cycle; /* Next scheduled time to sent item */ uint64_t cycle; - /* Next seq used for direct descendant streams */ - uint64_t descendant_next_seq; /* Secondary key for prioritization to break a tie for cycle. This value is monotonically increased for single parent stream. */ uint64_t seq; - /* pointers to form dependency tree. If multiple streams depend on - a stream, only one stream (left most) has non-NULL dep_prev which - points to the stream it depends on. The remaining streams are - linked using sib_prev and sib_next. The stream which has - non-NULL dep_prev always NULL sib_prev. The right most stream - has NULL sib_next. If this stream is a root of dependency tree, - dep_prev and sib_prev are NULL. */ - nghttp2_stream *dep_prev, *dep_next; - nghttp2_stream *sib_prev, *sib_next; - /* When stream is kept after closure, it may be kept in doubly - linked list pointed by nghttp2_session closed_stream_head. - closed_next points to the next stream object if it is the element - of the list. */ - nghttp2_stream *closed_prev, *closed_next; + nghttp2_stream *closed_next; /* The arbitrary data provided by user for this stream. */ void *stream_user_data; /* Item to send */ @@ -205,13 +181,8 @@ struct nghttp2_stream { NGHTTP2_INITIAL_WINDOW_SIZE and could be increased/decreased by submitting WINDOW_UPDATE. See nghttp2_submit_window_update(). */ int32_t local_window_size; - /* weight of this stream */ - int32_t weight; /* This is unpaid penalty (offset) when calculating cycle. */ uint32_t pending_penalty; - /* sum of weight of direct descendants */ - int32_t sum_dep_weight; - nghttp2_stream_state state; /* status code from remote server */ int16_t status_code; /* Bitwise OR of zero or more nghttp2_http_flag values */ @@ -239,9 +210,9 @@ struct nghttp2_stream { void nghttp2_stream_init(nghttp2_stream *stream, int32_t stream_id, uint8_t flags, nghttp2_stream_state initial_state, - int32_t weight, int32_t remote_initial_window_size, + int32_t remote_initial_window_size, int32_t local_initial_window_size, - void *stream_user_data, nghttp2_mem *mem); + void *stream_user_data); void nghttp2_stream_free(nghttp2_stream *stream); @@ -267,14 +238,8 @@ void nghttp2_stream_defer_item(nghttp2_stream *stream, uint8_t flags); * NGHTTP2_STREAM_FLAG_DEFERRED_FLOW_CONTROL and given masks are * cleared if they are set. So even if this function is called, if * one of flag is still set, data does not become active. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory */ -int nghttp2_stream_resume_deferred_item(nghttp2_stream *stream, uint8_t flags); +void nghttp2_stream_resume_deferred_item(nghttp2_stream *stream, uint8_t flags); /* * Returns nonzero if item is deferred by whatever reason. @@ -317,57 +282,11 @@ int nghttp2_stream_update_local_initial_window_size( */ void nghttp2_stream_promise_fulfilled(nghttp2_stream *stream); -/* - * Returns nonzero if |target| is an ancestor of |stream|. - */ -int nghttp2_stream_dep_find_ancestor(nghttp2_stream *stream, - nghttp2_stream *target); - -/* - * Computes distributed weight of a stream of the |weight| under the - * |stream| if |stream| is removed from a dependency tree. - */ -int32_t nghttp2_stream_dep_distributed_weight(nghttp2_stream *stream, - int32_t weight); - -/* - * Makes the |stream| depend on the |dep_stream|. This dependency is - * exclusive. All existing direct descendants of |dep_stream| become - * the descendants of the |stream|. This function assumes - * |stream->item| is NULL. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_stream_dep_insert(nghttp2_stream *dep_stream, - nghttp2_stream *stream); - -/* - * Makes the |stream| depend on the |dep_stream|. This dependency is - * not exclusive. This function assumes |stream->item| is NULL. - */ -void nghttp2_stream_dep_add(nghttp2_stream *dep_stream, nghttp2_stream *stream); - -/* - * Removes the |stream| from the current dependency tree. This - * function assumes |stream->item| is NULL. - */ -int nghttp2_stream_dep_remove(nghttp2_stream *stream); - /* * Attaches |item| to |stream|. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory */ -int nghttp2_stream_attach_item(nghttp2_stream *stream, - nghttp2_outbound_item *item); +void nghttp2_stream_attach_item(nghttp2_stream *stream, + nghttp2_outbound_item *item); /* * Detaches |stream->item|. This function does not free @@ -375,66 +294,4 @@ int nghttp2_stream_attach_item(nghttp2_stream *stream, */ void nghttp2_stream_detach_item(nghttp2_stream *stream); -/* - * Makes the |stream| depend on the |dep_stream|. This dependency is - * exclusive. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_stream_dep_insert_subtree(nghttp2_stream *dep_stream, - nghttp2_stream *stream); - -/* - * Makes the |stream| depend on the |dep_stream|. This dependency is - * not exclusive. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -int nghttp2_stream_dep_add_subtree(nghttp2_stream *dep_stream, - nghttp2_stream *stream); - -/* - * Removes subtree whose root stream is |stream|. The - * effective_weight of streams in removed subtree is not updated. - * - * This function returns 0 if it succeeds, or one of the following - * negative error codes: - * - * NGHTTP2_ERR_NOMEM - * Out of memory - */ -void nghttp2_stream_dep_remove_subtree(nghttp2_stream *stream); - -/* - * Returns nonzero if |stream| is in any dependency tree. - */ -int nghttp2_stream_in_dep_tree(nghttp2_stream *stream); - -/* - * Schedules transmission of |stream|'s item, assuming stream->item is - * attached, and stream->last_writelen was updated. - */ -void nghttp2_stream_reschedule(nghttp2_stream *stream); - -/* - * Changes |stream|'s weight to |weight|. If |stream| is queued, it - * will be rescheduled based on new weight. - */ -void nghttp2_stream_change_weight(nghttp2_stream *stream, int32_t weight); - -/* - * Returns a stream which has highest priority, updating - * descendant_last_cycle of selected stream's ancestors. - */ -nghttp2_outbound_item * -nghttp2_stream_next_outbound_item(nghttp2_stream *stream); - #endif /* NGHTTP2_STREAM */ diff --git a/lib/nghttp2_submit.c b/lib/nghttp2_submit.c index 81c1ab70..d481aebd 100644 --- a/lib/nghttp2_submit.c +++ b/lib/nghttp2_submit.c @@ -32,42 +32,12 @@ #include "nghttp2_helper.h" #include "nghttp2_priority_spec.h" -/* - * Detects the dependency error, that is stream attempted to depend on - * itself. If |stream_id| is -1, we use session->next_stream_id as - * stream ID. - * - * This function returns 0 if it succeeds, or one of the following - * error codes: - * - * NGHTTP2_ERR_INVALID_ARGUMENT - * Stream attempted to depend on itself. - */ -static int detect_self_dependency(nghttp2_session *session, int32_t stream_id, - const nghttp2_priority_spec *pri_spec) { - assert(pri_spec); - - if (stream_id == -1) { - if ((int32_t)session->next_stream_id == pri_spec->stream_id) { - return NGHTTP2_ERR_INVALID_ARGUMENT; - } - return 0; - } - - if (stream_id == pri_spec->stream_id) { - return NGHTTP2_ERR_INVALID_ARGUMENT; - } - - return 0; -} - /* This function takes ownership of |nva_copy|. Regardless of the return value, the caller must not free |nva_copy| after this function returns. */ static int32_t submit_headers_shared(nghttp2_session *session, uint8_t flags, - int32_t stream_id, - const nghttp2_priority_spec *pri_spec, - nghttp2_nv *nva_copy, size_t nvlen, + int32_t stream_id, nghttp2_nv *nva_copy, + size_t nvlen, const nghttp2_data_provider_wrap *dpw, void *stream_user_data) { int rv; @@ -114,8 +84,8 @@ static int32_t submit_headers_shared(nghttp2_session *session, uint8_t flags, frame = &item->frame; - nghttp2_frame_headers_init(&frame->headers, flags_copy, stream_id, hcat, - pri_spec, nva_copy, nvlen); + nghttp2_frame_headers_init(&frame->headers, flags_copy, stream_id, hcat, NULL, + nva_copy, nvlen); rv = nghttp2_session_add_item(session, item); @@ -141,31 +111,22 @@ fail2: static int32_t submit_headers_shared_nva(nghttp2_session *session, uint8_t flags, int32_t stream_id, - const nghttp2_priority_spec *pri_spec, const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider_wrap *dpw, void *stream_user_data) { int rv; nghttp2_nv *nva_copy; - nghttp2_priority_spec copy_pri_spec; nghttp2_mem *mem; mem = &session->mem; - if (pri_spec) { - copy_pri_spec = *pri_spec; - nghttp2_priority_spec_normalize_weight(©_pri_spec); - } else { - nghttp2_priority_spec_default_init(©_pri_spec); - } - rv = nghttp2_nv_array_copy(&nva_copy, nva, nvlen, mem); if (rv < 0) { return rv; } - return submit_headers_shared(session, flags, stream_id, ©_pri_spec, - nva_copy, nvlen, dpw, stream_user_data); + return submit_headers_shared(session, flags, stream_id, nva_copy, nvlen, dpw, + stream_user_data); } int nghttp2_submit_trailer(nghttp2_session *session, int32_t stream_id, @@ -174,8 +135,8 @@ int nghttp2_submit_trailer(nghttp2_session *session, int32_t stream_id, return NGHTTP2_ERR_INVALID_ARGUMENT; } - return (int)submit_headers_shared_nva( - session, NGHTTP2_FLAG_END_STREAM, stream_id, NULL, nva, nvlen, NULL, NULL); + return (int)submit_headers_shared_nva(session, NGHTTP2_FLAG_END_STREAM, + stream_id, nva, nvlen, NULL, NULL); } int32_t nghttp2_submit_headers(nghttp2_session *session, uint8_t flags, @@ -183,7 +144,7 @@ int32_t nghttp2_submit_headers(nghttp2_session *session, uint8_t flags, const nghttp2_priority_spec *pri_spec, const nghttp2_nv *nva, size_t nvlen, void *stream_user_data) { - int rv; + (void)pri_spec; if (stream_id == -1) { if (session->server) { @@ -195,20 +156,8 @@ int32_t nghttp2_submit_headers(nghttp2_session *session, uint8_t flags, flags &= NGHTTP2_FLAG_END_STREAM; - if (pri_spec && !nghttp2_priority_spec_check_default(pri_spec) && - session->remote_settings.no_rfc7540_priorities != 1) { - rv = detect_self_dependency(session, stream_id, pri_spec); - if (rv != 0) { - return rv; - } - - flags |= NGHTTP2_FLAG_PRIORITY; - } else { - pri_spec = NULL; - } - - return submit_headers_shared_nva(session, flags, stream_id, pri_spec, nva, - nvlen, NULL, stream_user_data); + return submit_headers_shared_nva(session, flags, stream_id, nva, nvlen, NULL, + stream_user_data); } int nghttp2_submit_ping(nghttp2_session *session, uint8_t flags, @@ -220,51 +169,10 @@ int nghttp2_submit_ping(nghttp2_session *session, uint8_t flags, int nghttp2_submit_priority(nghttp2_session *session, uint8_t flags, int32_t stream_id, const nghttp2_priority_spec *pri_spec) { - int rv; - nghttp2_outbound_item *item; - nghttp2_frame *frame; - nghttp2_priority_spec copy_pri_spec; - nghttp2_mem *mem; + (void)session; (void)flags; - - mem = &session->mem; - - if (session->remote_settings.no_rfc7540_priorities == 1) { - return 0; - } - - if (stream_id == 0 || pri_spec == NULL) { - return NGHTTP2_ERR_INVALID_ARGUMENT; - } - - if (stream_id == pri_spec->stream_id) { - return NGHTTP2_ERR_INVALID_ARGUMENT; - } - - copy_pri_spec = *pri_spec; - - nghttp2_priority_spec_normalize_weight(©_pri_spec); - - item = nghttp2_mem_malloc(mem, sizeof(nghttp2_outbound_item)); - - if (item == NULL) { - return NGHTTP2_ERR_NOMEM; - } - - nghttp2_outbound_item_init(item); - - frame = &item->frame; - - nghttp2_frame_priority_init(&frame->priority, stream_id, ©_pri_spec); - - rv = nghttp2_session_add_item(session, item); - - if (rv != 0) { - nghttp2_frame_priority_free(&frame->priority); - nghttp2_mem_free(mem, item); - - return rv; - } + (void)stream_id; + (void)pri_spec; return 0; } @@ -738,46 +646,29 @@ fail_item_malloc: return rv; } -static uint8_t set_request_flags(const nghttp2_priority_spec *pri_spec, - const nghttp2_data_provider_wrap *dpw) { +static uint8_t set_request_flags(const nghttp2_data_provider_wrap *dpw) { uint8_t flags = NGHTTP2_FLAG_NONE; if (dpw == NULL || dpw->data_prd.read_callback == NULL) { flags |= NGHTTP2_FLAG_END_STREAM; } - if (pri_spec) { - flags |= NGHTTP2_FLAG_PRIORITY; - } - return flags; } static int32_t submit_request_shared(nghttp2_session *session, - const nghttp2_priority_spec *pri_spec, const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider_wrap *dpw, void *stream_user_data) { uint8_t flags; - int rv; if (session->server) { return NGHTTP2_ERR_PROTO; } - if (pri_spec && !nghttp2_priority_spec_check_default(pri_spec) && - session->remote_settings.no_rfc7540_priorities != 1) { - rv = detect_self_dependency(session, -1, pri_spec); - if (rv != 0) { - return rv; - } - } else { - pri_spec = NULL; - } + flags = set_request_flags(dpw); - flags = set_request_flags(pri_spec, dpw); - - return submit_headers_shared_nva(session, flags, -1, pri_spec, nva, nvlen, - dpw, stream_user_data); + return submit_headers_shared_nva(session, flags, -1, nva, nvlen, dpw, + stream_user_data); } int32_t nghttp2_submit_request(nghttp2_session *session, @@ -786,8 +677,9 @@ int32_t nghttp2_submit_request(nghttp2_session *session, const nghttp2_data_provider *data_prd, void *stream_user_data) { nghttp2_data_provider_wrap dpw; + (void)pri_spec; - return submit_request_shared(session, pri_spec, nva, nvlen, + return submit_request_shared(session, nva, nvlen, nghttp2_data_provider_wrap_v1(&dpw, data_prd), stream_user_data); } @@ -798,8 +690,9 @@ int32_t nghttp2_submit_request2(nghttp2_session *session, const nghttp2_data_provider2 *data_prd, void *stream_user_data) { nghttp2_data_provider_wrap dpw; + (void)pri_spec; - return submit_request_shared(session, pri_spec, nva, nvlen, + return submit_request_shared(session, nva, nvlen, nghttp2_data_provider_wrap_v2(&dpw, data_prd), stream_user_data); } @@ -826,8 +719,8 @@ static int submit_response_shared(nghttp2_session *session, int32_t stream_id, } flags = set_response_flags(dpw); - return submit_headers_shared_nva(session, flags, stream_id, NULL, nva, nvlen, - dpw, NULL); + return submit_headers_shared_nva(session, flags, stream_id, nva, nvlen, dpw, + NULL); } int nghttp2_submit_response(nghttp2_session *session, int32_t stream_id, diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index 3cb8f243..528fe026 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -67,7 +67,6 @@ static const MunitTest tests[] = { munit_void_test(test_nghttp2_session_on_response_headers_received), munit_void_test(test_nghttp2_session_on_headers_received), munit_void_test(test_nghttp2_session_on_push_response_headers_received), - munit_void_test(test_nghttp2_session_on_priority_received), munit_void_test(test_nghttp2_session_on_rst_stream_received), munit_void_test(test_nghttp2_session_on_settings_received), munit_void_test(test_nghttp2_session_on_push_promise_received), @@ -85,9 +84,6 @@ static const MunitTest tests[] = { munit_void_test(test_nghttp2_session_send_push_promise), munit_void_test(test_nghttp2_session_is_my_stream_id), munit_void_test(test_nghttp2_session_upgrade2), - munit_void_test(test_nghttp2_session_reprioritize_stream), - munit_void_test( - test_nghttp2_session_reprioritize_stream_with_idle_stream_dep), munit_void_test(test_nghttp2_submit_data), munit_void_test(test_nghttp2_submit_data_read_length_too_large), munit_void_test(test_nghttp2_submit_data_read_length_smallest), @@ -104,7 +100,6 @@ static const MunitTest tests[] = { munit_void_test(test_nghttp2_submit_headers), munit_void_test(test_nghttp2_submit_headers_continuation), munit_void_test(test_nghttp2_submit_headers_continuation_extra_large), - munit_void_test(test_nghttp2_submit_priority), munit_void_test(test_nghttp2_submit_settings), munit_void_test(test_nghttp2_submit_settings_update_local_window_size), munit_void_test(test_nghttp2_submit_settings_multiple_times), @@ -119,7 +114,6 @@ static const MunitTest tests[] = { munit_void_test(test_nghttp2_submit_priority_update), munit_void_test(test_nghttp2_submit_rst_stream), munit_void_test(test_nghttp2_session_open_stream), - munit_void_test(test_nghttp2_session_open_stream_with_idle_stream_dep), munit_void_test(test_nghttp2_session_get_next_ob_item), munit_void_test(test_nghttp2_session_pop_next_ob_item), munit_void_test(test_nghttp2_session_reply_fail), @@ -139,21 +133,8 @@ static const MunitTest tests[] = { munit_void_test(test_nghttp2_session_pack_data_with_padding), munit_void_test(test_nghttp2_session_pack_headers_with_padding), munit_void_test(test_nghttp2_pack_settings_payload), - munit_void_test(test_nghttp2_session_stream_dep_add), - munit_void_test(test_nghttp2_session_stream_dep_remove), - munit_void_test(test_nghttp2_session_stream_dep_add_subtree), - munit_void_test(test_nghttp2_session_stream_dep_remove_subtree), - munit_void_test( - test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us), - munit_void_test(test_nghttp2_session_stream_attach_item), - munit_void_test(test_nghttp2_session_stream_attach_item_subtree), munit_void_test(test_nghttp2_session_stream_get_state), - munit_void_test(test_nghttp2_session_stream_get_something), munit_void_test(test_nghttp2_session_find_stream), - munit_void_test(test_nghttp2_session_keep_closed_stream), - munit_void_test(test_nghttp2_session_keep_idle_stream), - munit_void_test(test_nghttp2_session_detach_idle_stream), - munit_void_test(test_nghttp2_session_large_dep_tree), munit_void_test(test_nghttp2_session_graceful_shutdown), munit_void_test(test_nghttp2_session_on_header_temporal_failure), munit_void_test(test_nghttp2_session_recv_client_magic), @@ -166,11 +147,7 @@ static const MunitTest tests[] = { munit_void_test(test_nghttp2_session_defer_then_close), munit_void_test(test_nghttp2_session_detach_item_from_closed_stream), munit_void_test(test_nghttp2_session_flooding), - munit_void_test(test_nghttp2_session_change_stream_priority), munit_void_test(test_nghttp2_session_change_extpri_stream_priority), - munit_void_test(test_nghttp2_session_create_idle_stream), - munit_void_test(test_nghttp2_session_repeated_priority_change), - munit_void_test(test_nghttp2_session_repeated_priority_submission), munit_void_test(test_nghttp2_session_set_local_window_size), munit_void_test(test_nghttp2_session_cancel_from_before_frame_send), munit_void_test(test_nghttp2_session_too_many_settings), @@ -179,7 +156,6 @@ static const MunitTest tests[] = { munit_void_test(test_nghttp2_session_no_closed_streams), munit_void_test(test_nghttp2_session_set_stream_user_data), munit_void_test(test_nghttp2_session_no_rfc7540_priorities), - munit_void_test(test_nghttp2_session_server_fallback_rfc7540_priorities), munit_void_test(test_nghttp2_session_stream_reset_ratelim), munit_void_test(test_nghttp2_http_mandatory_headers), munit_void_test(test_nghttp2_http_content_length), @@ -906,7 +882,7 @@ void test_nghttp2_session_recv(void) { user_data.begin_frame_cb_called = 0; assert_int(0, ==, nghttp2_session_recv(session)); - assert_int(1, ==, user_data.frame_recv_cb_called); + assert_int(0, ==, user_data.frame_recv_cb_called); assert_int(1, ==, user_data.begin_frame_cb_called); nghttp2_bufs_reset(&bufs); @@ -1652,8 +1628,7 @@ void test_nghttp2_session_recv_headers_with_priority(void) { stream = nghttp2_session_get_stream(session, 3); - assert_int32(99, ==, stream->weight); - assert_int32(1, ==, stream->dep_prev->stream_id); + assert_not_null(stream); nghttp2_bufs_reset(&bufs); @@ -1908,7 +1883,7 @@ void test_nghttp2_session_recv_headers_early_response(void) { stream = nghttp2_session_get_stream_raw(session, 1); - assert_true(stream->flags & NGHTTP2_STREAM_FLAG_CLOSED); + assert_null(stream); nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -2203,7 +2178,7 @@ void test_nghttp2_session_recv_premature_headers(void) { nghttp2_session_client_new(&session, &callbacks, &ud); nghttp2_hd_deflate_init(&deflater, mem); - open_sent_stream3(session, 1, NGHTTP2_STREAM_FLAG_NONE, &pri_spec_default, + open_sent_stream3(session, 1, NGHTTP2_STREAM_FLAG_NONE, NGHTTP2_STREAM_OPENING, NULL); rv = pack_push_promise(&bufs, &deflater, 1, NGHTTP2_FLAG_END_HEADERS, 2, @@ -3418,7 +3393,6 @@ void test_nghttp2_session_on_request_headers_received(void) { assert_int(1, ==, user_data.begin_headers_cb_called); stream = nghttp2_session_get_stream(session, stream_id); assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); - assert_int32(255, ==, stream->weight); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3577,7 +3551,6 @@ void test_nghttp2_session_on_request_headers_received(void) { assert_int(NGHTTP2_ERR_IGN_HEADER_BLOCK, ==, nghttp2_session_on_request_headers_received(session, &frame)); - assert_true(session->goaway_flags & NGHTTP2_GOAWAY_TERM_ON_SEND); nghttp2_frame_headers_free(&frame.headers, mem); @@ -3756,90 +3729,6 @@ void test_nghttp2_session_on_push_response_headers_received(void) { nghttp2_session_del(session); } -void test_nghttp2_session_on_priority_received(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - my_user_data user_data; - nghttp2_frame frame; - nghttp2_stream *stream, *dep_stream; - nghttp2_priority_spec pri_spec; - nghttp2_outbound_item *item; - - memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.on_frame_recv_callback = on_frame_recv_callback; - callbacks.on_invalid_frame_recv_callback = on_invalid_frame_recv_callback; - - nghttp2_session_server_new(&session, &callbacks, &user_data); - stream = open_recv_stream(session, 1); - - nghttp2_priority_spec_init(&pri_spec, 0, 2, 0); - - nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - - /* depend on stream 0 */ - assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); - - assert_int32(2, ==, stream->weight); - - stream = open_sent_stream(session, 2); - dep_stream = open_recv_stream(session, 3); - - frame.hd.stream_id = 2; - - /* using dependency stream */ - nghttp2_priority_spec_init(&frame.priority.pri_spec, 3, 1, 0); - - assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); - assert_ptr_equal(dep_stream, stream->dep_prev); - - /* PRIORITY against idle stream */ - - frame.hd.stream_id = 100; - - assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); - - stream = nghttp2_session_get_stream_raw(session, frame.hd.stream_id); - - assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, stream->state); - assert_ptr_equal(dep_stream, stream->dep_prev); - - nghttp2_frame_priority_free(&frame.priority); - nghttp2_session_del(session); - - /* Check dep_stream_id == stream_id case */ - nghttp2_session_server_new(&session, &callbacks, &user_data); - open_recv_stream(session, 1); - - nghttp2_priority_spec_init(&pri_spec, 1, 0, 0); - - nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - - assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); - - item = nghttp2_session_get_next_ob_item(session); - - assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); - - nghttp2_frame_priority_free(&frame.priority); - nghttp2_session_del(session); - - /* Check again dep_stream_id == stream_id, and stream_id is idle */ - nghttp2_session_server_new(&session, &callbacks, &user_data); - - nghttp2_priority_spec_init(&pri_spec, 1, 16, 0); - - nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - - assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); - - item = nghttp2_session_get_next_ob_item(session); - - assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); - - nghttp2_frame_priority_free(&frame.priority); - nghttp2_session_del(session); -} - void test_nghttp2_session_on_rst_stream_received(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; @@ -4577,7 +4466,7 @@ void test_nghttp2_session_on_window_update_received(void) { data_item = create_data_ob_item(mem); - assert_int(0, ==, nghttp2_stream_attach_item(stream, data_item)); + nghttp2_stream_attach_item(stream, data_item); nghttp2_frame_window_update_init(&frame.window_update, NGHTTP2_FLAG_NONE, 1, 16 * 1024); @@ -4717,8 +4606,7 @@ void test_nghttp2_session_on_data_received_fail_fast(void) { item = nghttp2_session_get_next_ob_item(session); - assert_not_null(item); - assert_uint8(NGHTTP2_GOAWAY, ==, item->frame.hd.type); + assert_null(item); nghttp2_session_del(session); } @@ -5236,183 +5124,6 @@ void test_nghttp2_session_upgrade2(void) { nghttp2_bufs_free(&bufs); } -void test_nghttp2_session_reprioritize_stream(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - nghttp2_stream *stream; - nghttp2_stream *dep_stream; - nghttp2_priority_spec pri_spec; - int rv; - - memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback2 = block_count_send_callback; - - nghttp2_session_server_new(&session, &callbacks, NULL); - - stream = open_recv_stream(session, 1); - - nghttp2_priority_spec_init(&pri_spec, 0, 10, 0); - - rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - - assert_int(0, ==, rv); - assert_int32(10, ==, stream->weight); - assert_ptr_equal(&session->root, stream->dep_prev); - - /* If dependency to idle stream which is not in dependency tree yet */ - - nghttp2_priority_spec_init(&pri_spec, 3, 99, 0); - - rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - - assert_int(0, ==, rv); - assert_int32(99, ==, stream->weight); - assert_int32(3, ==, stream->dep_prev->stream_id); - - dep_stream = nghttp2_session_get_stream_raw(session, 3); - - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, dep_stream->weight); - - dep_stream = open_recv_stream(session, 3); - - /* Change weight */ - pri_spec.weight = 128; - - rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - - assert_int(0, ==, rv); - assert_int32(128, ==, stream->weight); - assert_ptr_equal(dep_stream, stream->dep_prev); - - /* Change weight again to test short-path case */ - pri_spec.weight = 100; - - rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - - assert_int(0, ==, rv); - assert_int32(100, ==, stream->weight); - assert_ptr_equal(dep_stream, stream->dep_prev); - assert_int32(100, ==, dep_stream->sum_dep_weight); - - /* Test circular dependency; stream 1 is first removed and becomes - root. Then stream 3 depends on it. */ - nghttp2_priority_spec_init(&pri_spec, 1, 1, 0); - - rv = nghttp2_session_reprioritize_stream(session, dep_stream, &pri_spec); - - assert_int(0, ==, rv); - assert_int32(1, ==, dep_stream->weight); - assert_ptr_equal(stream, dep_stream->dep_prev); - - /* Making priority to closed stream will result in default - priority */ - session->last_recv_stream_id = 9; - - nghttp2_priority_spec_init(&pri_spec, 5, 5, 0); - - rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - - assert_int(0, ==, rv); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); - - nghttp2_session_del(session); - - nghttp2_session_server_new(&session, &callbacks, NULL); - - /* circular dependency; in case of stream which is not a direct - descendant of root. Use exclusive dependency. */ - stream = open_recv_stream(session, 1); - stream = open_recv_stream_with_dep(session, 3, stream); - stream = open_recv_stream_with_dep(session, 5, stream); - stream = open_recv_stream_with_dep(session, 7, stream); - open_recv_stream_with_dep(session, 9, stream); - - nghttp2_priority_spec_init(&pri_spec, 7, 1, 1); - - stream = nghttp2_session_get_stream(session, 3); - rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - - assert_int(0, ==, rv); - assert_int32(7, ==, stream->dep_prev->stream_id); - - stream = nghttp2_session_get_stream(session, 7); - - assert_int32(1, ==, stream->dep_prev->stream_id); - - stream = nghttp2_session_get_stream(session, 9); - - assert_int32(3, ==, stream->dep_prev->stream_id); - - stream = nghttp2_session_get_stream(session, 5); - - assert_int32(3, ==, stream->dep_prev->stream_id); - - nghttp2_session_del(session); - - nghttp2_session_server_new(&session, &callbacks, NULL); - - /* circular dependency; in case of stream which is not a direct - descendant of root. Without exclusive dependency. */ - stream = open_recv_stream(session, 1); - stream = open_recv_stream_with_dep(session, 3, stream); - stream = open_recv_stream_with_dep(session, 5, stream); - stream = open_recv_stream_with_dep(session, 7, stream); - open_recv_stream_with_dep(session, 9, stream); - - nghttp2_priority_spec_init(&pri_spec, 7, 1, 0); - - stream = nghttp2_session_get_stream(session, 3); - rv = nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - - assert_int(0, ==, rv); - assert_int32(7, ==, stream->dep_prev->stream_id); - - stream = nghttp2_session_get_stream(session, 7); - - assert_int32(1, ==, stream->dep_prev->stream_id); - - stream = nghttp2_session_get_stream(session, 9); - - assert_int32(7, ==, stream->dep_prev->stream_id); - - stream = nghttp2_session_get_stream(session, 5); - - assert_int32(3, ==, stream->dep_prev->stream_id); - - nghttp2_session_del(session); -} - -void test_nghttp2_session_reprioritize_stream_with_idle_stream_dep(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - nghttp2_stream *stream; - nghttp2_priority_spec pri_spec; - - memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback2 = block_count_send_callback; - - nghttp2_session_server_new(&session, &callbacks, NULL); - - stream = open_recv_stream(session, 1); - - session->pending_local_max_concurrent_stream = 1; - - nghttp2_priority_spec_init(&pri_spec, 101, 10, 0); - - nghttp2_session_reprioritize_stream(session, stream, &pri_spec); - - /* idle stream is not counteed to max concurrent streams */ - - assert_int32(10, ==, stream->weight); - assert_int32(101, ==, stream->dep_prev->stream_id); - - stream = nghttp2_session_get_stream_raw(session, 101); - - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); - - nghttp2_session_del(session); -} - void test_nghttp2_submit_data(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; @@ -5693,7 +5404,6 @@ void test_nghttp2_submit_request_without_data(void) { nva_out out; nghttp2_bufs bufs; nghttp2_mem *mem; - nghttp2_priority_spec pri_spec; mem = nghttp2_mem_default(); frame_pack_bufs_init(&bufs); @@ -5729,14 +5439,6 @@ void test_nghttp2_submit_request_without_data(void) { nghttp2_bufs_free(&bufs); nghttp2_hd_inflate_free(&inflater); - /* Try to depend on itself is error */ - nghttp2_priority_spec_init(&pri_spec, (int32_t)session->next_stream_id, 16, - 0); - - assert_int32(NGHTTP2_ERR_INVALID_ARGUMENT, ==, - nghttp2_submit_request2(session, &pri_spec, reqnv, ARRLEN(reqnv), - NULL, NULL)); - nghttp2_session_del(session); } @@ -6053,7 +5755,6 @@ void test_nghttp2_submit_headers(void) { nva_out out; nghttp2_bufs bufs; nghttp2_mem *mem; - nghttp2_priority_spec pri_spec; mem = nghttp2_mem_default(); frame_pack_bufs_init(&bufs); @@ -6109,20 +5810,6 @@ void test_nghttp2_submit_headers(void) { nghttp2_hd_inflate_free(&inflater); - /* Try to depend on itself */ - nghttp2_priority_spec_init(&pri_spec, 3, 16, 0); - - assert_int32(NGHTTP2_ERR_INVALID_ARGUMENT, ==, - nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, 3, &pri_spec, - reqnv, ARRLEN(reqnv), NULL)); - - session->next_stream_id = 5; - nghttp2_priority_spec_init(&pri_spec, 5, 16, 0); - - assert_int32(NGHTTP2_ERR_INVALID_ARGUMENT, ==, - nghttp2_submit_headers(session, NGHTTP2_FLAG_NONE, -1, &pri_spec, - reqnv, ARRLEN(reqnv), NULL)); - nghttp2_session_del(session); /* Error cases with invalid stream ID */ @@ -6228,39 +5915,6 @@ void test_nghttp2_submit_headers_continuation_extra_large(void) { nghttp2_option_del(opt); } -void test_nghttp2_submit_priority(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - nghttp2_stream *stream; - my_user_data ud; - nghttp2_priority_spec pri_spec; - - memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback2 = null_send_callback; - callbacks.on_frame_send_callback = on_frame_send_callback; - - nghttp2_session_client_new(&session, &callbacks, &ud); - stream = open_sent_stream(session, 1); - - nghttp2_priority_spec_init(&pri_spec, 0, 3, 0); - - /* depends on stream 0 */ - assert_int(0, ==, - nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); - assert_int(0, ==, nghttp2_session_send(session)); - assert_int32(3, ==, stream->weight); - - /* submit against idle stream */ - assert_int(0, ==, - nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 3, &pri_spec)); - - ud.frame_send_cb_called = 0; - assert_int(0, ==, nghttp2_session_send(session)); - assert_int(1, ==, ud.frame_send_cb_called); - - nghttp2_session_del(session); -} - void test_nghttp2_submit_settings(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; @@ -7284,126 +6938,54 @@ void test_nghttp2_session_open_stream(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; nghttp2_stream *stream; - nghttp2_priority_spec pri_spec; memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); nghttp2_session_server_new(&session, &callbacks, NULL); - nghttp2_priority_spec_init(&pri_spec, 0, 245, 0); - stream = nghttp2_session_open_stream(session, 1, NGHTTP2_STREAM_FLAG_NONE, - &pri_spec, NGHTTP2_STREAM_OPENED, NULL); + NGHTTP2_STREAM_OPENED, NULL); assert_size(1, ==, session->num_incoming_streams); assert_size(0, ==, session->num_outgoing_streams); assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENED, ==, stream->state); - assert_int32(245, ==, stream->weight); - assert_ptr_equal(&session->root, stream->dep_prev); assert_uint8(NGHTTP2_SHUT_NONE, ==, stream->shut_flags); stream = nghttp2_session_open_stream(session, 2, NGHTTP2_STREAM_FLAG_NONE, - &pri_spec_default, NGHTTP2_STREAM_OPENING, NULL); assert_size(1, ==, session->num_incoming_streams); assert_size(1, ==, session->num_outgoing_streams); - assert_ptr_equal(&session->root, stream->dep_prev); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); assert_uint8(NGHTTP2_SHUT_NONE, ==, stream->shut_flags); stream = nghttp2_session_open_stream(session, 4, NGHTTP2_STREAM_FLAG_NONE, - &pri_spec_default, NGHTTP2_STREAM_RESERVED, NULL); assert_size(1, ==, session->num_incoming_streams); assert_size(1, ==, session->num_outgoing_streams); - assert_ptr_equal(&session->root, stream->dep_prev); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); assert_uint8(NGHTTP2_SHUT_RD, ==, stream->shut_flags); - nghttp2_priority_spec_init(&pri_spec, 1, 17, 1); - stream = nghttp2_session_open_stream(session, 3, NGHTTP2_STREAM_FLAG_NONE, - &pri_spec, NGHTTP2_STREAM_OPENED, NULL); - assert_int32(17, ==, stream->weight); - assert_int32(1, ==, stream->dep_prev->stream_id); + NGHTTP2_STREAM_OPENED, NULL); /* Dependency to idle stream */ - nghttp2_priority_spec_init(&pri_spec, 1000000007, 240, 1); - stream = nghttp2_session_open_stream(session, 5, NGHTTP2_STREAM_FLAG_NONE, - &pri_spec, NGHTTP2_STREAM_OPENED, NULL); - assert_int32(240, ==, stream->weight); - assert_int32(1000000007, ==, stream->dep_prev->stream_id); - - stream = nghttp2_session_get_stream_raw(session, 1000000007); - - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); - assert_ptr_equal(&session->root, stream->dep_prev); + NGHTTP2_STREAM_OPENED, NULL); /* Dependency to closed stream which is not in dependency tree */ session->last_recv_stream_id = 7; - nghttp2_priority_spec_init(&pri_spec, 7, 10, 0); - - stream = nghttp2_session_open_stream(session, 9, NGHTTP2_FLAG_NONE, &pri_spec, + stream = nghttp2_session_open_stream(session, 9, NGHTTP2_FLAG_NONE, NGHTTP2_STREAM_OPENED, NULL); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); - assert_ptr_equal(&session->root, stream->dep_prev); - nghttp2_session_del(session); nghttp2_session_client_new(&session, &callbacks, NULL); stream = nghttp2_session_open_stream(session, 4, NGHTTP2_STREAM_FLAG_NONE, - &pri_spec_default, NGHTTP2_STREAM_RESERVED, NULL); assert_size(0, ==, session->num_incoming_streams); assert_size(0, ==, session->num_outgoing_streams); - assert_ptr_equal(&session->root, stream->dep_prev); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); assert_uint8(NGHTTP2_SHUT_WR, ==, stream->shut_flags); nghttp2_session_del(session); } -void test_nghttp2_session_open_stream_with_idle_stream_dep(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - nghttp2_stream *stream; - nghttp2_priority_spec pri_spec; - - memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - nghttp2_session_server_new(&session, &callbacks, NULL); - - /* Dependency to idle stream */ - nghttp2_priority_spec_init(&pri_spec, 101, 245, 0); - - stream = nghttp2_session_open_stream(session, 1, NGHTTP2_STREAM_FLAG_NONE, - &pri_spec, NGHTTP2_STREAM_OPENED, NULL); - - assert_int32(245, ==, stream->weight); - assert_int32(101, ==, stream->dep_prev->stream_id); - - stream = nghttp2_session_get_stream_raw(session, 101); - - assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, stream->state); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); - - nghttp2_priority_spec_init(&pri_spec, 211, 1, 0); - - /* stream 101 was already created as idle. */ - stream = nghttp2_session_open_stream(session, 101, NGHTTP2_STREAM_FLAG_NONE, - &pri_spec, NGHTTP2_STREAM_OPENED, NULL); - - assert_int32(1, ==, stream->weight); - assert_int32(211, ==, stream->dep_prev->stream_id); - - stream = nghttp2_session_get_stream_raw(session, 211); - - assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, stream->state); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream->weight); - - nghttp2_session_del(session); -} - void test_nghttp2_session_get_next_ob_item(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; @@ -8046,9 +7628,8 @@ void test_nghttp2_session_on_stream_close(void) { user_data.stream_close_cb_called = 0; nghttp2_session_client_new(&session, &callbacks, &user_data); - stream = - open_sent_stream3(session, 1, NGHTTP2_STREAM_FLAG_NONE, &pri_spec_default, - NGHTTP2_STREAM_OPENED, &user_data); + stream = open_sent_stream3(session, 1, NGHTTP2_STREAM_FLAG_NONE, + NGHTTP2_STREAM_OPENED, &user_data); assert_not_null(stream); assert_int(0, ==, nghttp2_session_close_stream(session, 1, NGHTTP2_NO_ERROR)); assert_int(1, ==, user_data.stream_close_cb_called); @@ -8069,9 +7650,8 @@ void test_nghttp2_session_on_ctrl_not_send(void) { user_data.not_sent_error = 0; nghttp2_session_server_new(&session, &callbacks, &user_data); - stream = - open_recv_stream3(session, 1, NGHTTP2_STREAM_FLAG_NONE, &pri_spec_default, - NGHTTP2_STREAM_OPENING, &user_data); + stream = open_recv_stream3(session, 1, NGHTTP2_STREAM_FLAG_NONE, + NGHTTP2_STREAM_OPENING, &user_data); /* Check response HEADERS */ /* Send bogus stream ID */ @@ -8509,1263 +8089,6 @@ void test_nghttp2_pack_settings_payload(void) { assert_ptrdiff(NGHTTP2_ERR_INSUFF_BUFSIZE, ==, len); } -#define check_stream_dep_sib(STREAM, DEP_PREV, DEP_NEXT, SIB_PREV, SIB_NEXT) \ - do { \ - assert_ptr_equal(DEP_PREV, STREAM->dep_prev); \ - assert_ptr_equal(DEP_NEXT, STREAM->dep_next); \ - assert_ptr_equal(SIB_PREV, STREAM->sib_prev); \ - assert_ptr_equal(SIB_NEXT, STREAM->sib_next); \ - } while (0) - -/* nghttp2_stream_dep_add() and its families functions should be - tested in nghttp2_stream_test.c, but it is easier to use - nghttp2_session_open_stream(). Therefore, we test them here. */ -void test_nghttp2_session_stream_dep_add(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - nghttp2_stream *a, *b, *c, *d, *e, *root; - - memset(&callbacks, 0, sizeof(callbacks)); - - nghttp2_session_server_new(&session, &callbacks, NULL); - - root = &session->root; - - a = open_stream(session, 1); - - c = open_stream_with_dep(session, 5, a); - b = open_stream_with_dep(session, 3, a); - d = open_stream_with_dep(session, 7, c); - - /* a - * | - * b--c - * | - * d - */ - - assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, a->sum_dep_weight); - assert_int32(0, ==, b->sum_dep_weight); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); - assert_int32(0, ==, d->sum_dep_weight); - - check_stream_dep_sib(a, root, b, NULL, NULL); - check_stream_dep_sib(b, a, NULL, NULL, c); - check_stream_dep_sib(c, a, d, b, NULL); - check_stream_dep_sib(d, c, NULL, NULL, NULL); - - assert_ptr_equal(a, session->root.dep_next); - - e = open_stream_with_dep_excl(session, 9, a); - - /* a - * | - * e - * | - * b--c - * | - * d - */ - - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); - assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, e->sum_dep_weight); - assert_int32(0, ==, b->sum_dep_weight); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); - assert_int32(0, ==, d->sum_dep_weight); - - check_stream_dep_sib(a, root, e, NULL, NULL); - check_stream_dep_sib(e, a, b, NULL, NULL); - check_stream_dep_sib(b, e, NULL, NULL, c); - check_stream_dep_sib(c, e, d, b, NULL); - check_stream_dep_sib(d, c, NULL, NULL, NULL); - - assert_ptr_equal(a, session->root.dep_next); - - nghttp2_session_del(session); -} - -void test_nghttp2_session_stream_dep_remove(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - nghttp2_stream *a, *b, *c, *d, *e, *f, *root; - - memset(&callbacks, 0, sizeof(callbacks)); - - /* Remove root */ - nghttp2_session_server_new(&session, &callbacks, NULL); - - root = &session->root; - - a = open_stream(session, 1); - b = open_stream_with_dep(session, 3, a); - c = open_stream_with_dep(session, 5, a); - d = open_stream_with_dep(session, 7, c); - - /* a - * | - * c--b - * | - * d - */ - - nghttp2_stream_dep_remove(a); - - /* becomes: - * c b - * | - * d - */ - - assert_int32(0, ==, a->sum_dep_weight); - assert_int32(0, ==, b->sum_dep_weight); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); - assert_int32(0, ==, d->sum_dep_weight); - - check_stream_dep_sib(a, NULL, NULL, NULL, NULL); - check_stream_dep_sib(b, root, NULL, c, NULL); - check_stream_dep_sib(c, root, d, NULL, b); - check_stream_dep_sib(d, c, NULL, NULL, NULL); - - assert_ptr_equal(c, session->root.dep_next); - - nghttp2_session_del(session); - - /* Remove right most stream */ - nghttp2_session_server_new(&session, &callbacks, NULL); - - root = &session->root; - - a = open_stream(session, 1); - b = open_stream_with_dep(session, 3, a); - c = open_stream_with_dep(session, 5, a); - d = open_stream_with_dep(session, 7, c); - - /* a - * | - * c--b - * | - * d - */ - - nghttp2_stream_dep_remove(b); - - /* becomes: - * a - * | - * c - * | - * d - */ - - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); - assert_int32(0, ==, d->sum_dep_weight); - assert_int32(0, ==, b->sum_dep_weight); - - check_stream_dep_sib(a, root, c, NULL, NULL); - check_stream_dep_sib(b, NULL, NULL, NULL, NULL); - check_stream_dep_sib(c, a, d, NULL, NULL); - check_stream_dep_sib(d, c, NULL, NULL, NULL); - - assert_ptr_equal(a, session->root.dep_next); - - nghttp2_session_del(session); - - /* Remove left most stream */ - nghttp2_session_server_new(&session, &callbacks, NULL); - - root = &session->root; - - a = open_stream(session, 1); - b = open_stream_with_dep(session, 3, a); - c = open_stream_with_dep(session, 5, a); - d = open_stream_with_dep(session, 7, c); - e = open_stream_with_dep(session, 9, c); - - /* a - * | - * c--b - * | - * e--d - */ - - nghttp2_stream_dep_remove(c); - - /* becomes: - * a - * | - * e--d--b - */ - - assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, a->sum_dep_weight); - assert_int32(0, ==, b->sum_dep_weight); - assert_int32(0, ==, d->sum_dep_weight); - assert_int32(0, ==, c->sum_dep_weight); - assert_int32(0, ==, e->sum_dep_weight); - - check_stream_dep_sib(a, root, e, NULL, NULL); - check_stream_dep_sib(b, a, NULL, d, NULL); - check_stream_dep_sib(c, NULL, NULL, NULL, NULL); - check_stream_dep_sib(d, a, NULL, e, b); - check_stream_dep_sib(e, a, NULL, NULL, d); - - nghttp2_session_del(session); - - /* Remove middle stream */ - nghttp2_session_server_new(&session, &callbacks, NULL); - - root = &session->root; - - a = open_stream(session, 1); - b = open_stream_with_dep(session, 3, a); - c = open_stream_with_dep(session, 5, a); - d = open_stream_with_dep(session, 7, a); - e = open_stream_with_dep(session, 9, c); - f = open_stream_with_dep(session, 11, c); - - /* a - * | - * d--c--b - * | - * f--e - */ - - assert_int32(NGHTTP2_DEFAULT_WEIGHT * 3, ==, a->sum_dep_weight); - assert_int32(0, ==, b->sum_dep_weight); - assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, c->sum_dep_weight); - assert_int32(0, ==, d->sum_dep_weight); - assert_int32(0, ==, e->sum_dep_weight); - assert_int32(0, ==, f->sum_dep_weight); - - nghttp2_stream_dep_remove(c); - - /* becomes: - * a - * | - * d--f--e--b - */ - - /* c's weight 16 is distributed evenly to e and f. Each weight of e - and f becomes 8. */ - assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2 + 8 * 2, ==, a->sum_dep_weight); - assert_int32(0, ==, b->sum_dep_weight); - assert_int32(0, ==, c->sum_dep_weight); - assert_int32(0, ==, d->sum_dep_weight); - assert_int32(0, ==, e->sum_dep_weight); - assert_int32(0, ==, f->sum_dep_weight); - - check_stream_dep_sib(a, root, d, NULL, NULL); - check_stream_dep_sib(b, a, NULL, e, NULL); - check_stream_dep_sib(c, NULL, NULL, NULL, NULL); - check_stream_dep_sib(e, a, NULL, f, b); - check_stream_dep_sib(f, a, NULL, d, e); - check_stream_dep_sib(d, a, NULL, NULL, f); - - nghttp2_session_del(session); -} - -void test_nghttp2_session_stream_dep_add_subtree(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - nghttp2_stream *a, *b, *c, *d, *e, *f, *root; - - memset(&callbacks, 0, sizeof(callbacks)); - - /* dep_stream has dep_next */ - nghttp2_session_server_new(&session, &callbacks, NULL); - - root = &session->root; - - a = open_stream(session, 1); - b = open_stream_with_dep(session, 3, a); - c = open_stream_with_dep(session, 5, a); - d = open_stream_with_dep(session, 7, c); - - e = open_stream(session, 9); - f = open_stream_with_dep(session, 11, e); - - /* a e - * | | - * c--b f - * | - * d - */ - - nghttp2_stream_dep_remove_subtree(e); - nghttp2_stream_dep_add_subtree(a, e); - - /* becomes - * a - * | - * e--c--b - * | | - * f d - */ - - assert_int32(NGHTTP2_DEFAULT_WEIGHT * 3, ==, a->sum_dep_weight); - assert_int32(0, ==, b->sum_dep_weight); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); - assert_int32(0, ==, d->sum_dep_weight); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, e->sum_dep_weight); - assert_int32(0, ==, f->sum_dep_weight); - - check_stream_dep_sib(a, root, e, NULL, NULL); - check_stream_dep_sib(b, a, NULL, c, NULL); - check_stream_dep_sib(c, a, d, e, b); - check_stream_dep_sib(d, c, NULL, NULL, NULL); - check_stream_dep_sib(e, a, f, NULL, c); - check_stream_dep_sib(f, e, NULL, NULL, NULL); - - nghttp2_session_del(session); - - /* dep_stream has dep_next and now we insert subtree */ - nghttp2_session_server_new(&session, &callbacks, NULL); - - root = &session->root; - - a = open_stream(session, 1); - b = open_stream_with_dep(session, 3, a); - c = open_stream_with_dep(session, 5, a); - d = open_stream_with_dep(session, 7, c); - - e = open_stream(session, 9); - f = open_stream_with_dep(session, 11, e); - - /* a e - * | | - * c--b f - * | - * d - */ - - nghttp2_stream_dep_remove_subtree(e); - nghttp2_stream_dep_insert_subtree(a, e); - - /* becomes - * a - * | - * e - * | - * f--c--b - * | - * d - */ - - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); - assert_int32(0, ==, b->sum_dep_weight); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); - assert_int32(0, ==, d->sum_dep_weight); - assert_int32(NGHTTP2_DEFAULT_WEIGHT * 3, ==, e->sum_dep_weight); - assert_int32(0, ==, f->sum_dep_weight); - - check_stream_dep_sib(a, root, e, NULL, NULL); - check_stream_dep_sib(e, a, f, NULL, NULL); - check_stream_dep_sib(f, e, NULL, NULL, c); - check_stream_dep_sib(b, e, NULL, c, NULL); - check_stream_dep_sib(c, e, d, f, b); - check_stream_dep_sib(d, c, NULL, NULL, NULL); - - nghttp2_session_del(session); -} - -void test_nghttp2_session_stream_dep_remove_subtree(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - nghttp2_stream *a, *b, *c, *d, *e, *root; - - memset(&callbacks, 0, sizeof(callbacks)); - - /* Remove left most stream */ - nghttp2_session_server_new(&session, &callbacks, NULL); - - root = &session->root; - - a = open_stream(session, 1); - b = open_stream_with_dep(session, 3, a); - c = open_stream_with_dep(session, 5, a); - d = open_stream_with_dep(session, 7, c); - - /* a - * | - * c--b - * | - * d - */ - - nghttp2_stream_dep_remove_subtree(c); - - /* becomes - * a c - * | | - * b d - */ - - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); - assert_int32(0, ==, b->sum_dep_weight); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); - assert_int32(0, ==, d->sum_dep_weight); - - check_stream_dep_sib(a, root, b, NULL, NULL); - check_stream_dep_sib(b, a, NULL, NULL, NULL); - check_stream_dep_sib(c, NULL, d, NULL, NULL); - check_stream_dep_sib(d, c, NULL, NULL, NULL); - - nghttp2_session_del(session); - - /* Remove right most stream */ - nghttp2_session_server_new(&session, &callbacks, NULL); - - root = &session->root; - - a = open_stream(session, 1); - b = open_stream_with_dep(session, 3, a); - c = open_stream_with_dep(session, 5, a); - d = open_stream_with_dep(session, 7, c); - - /* a - * | - * c--b - * | - * d - */ - - nghttp2_stream_dep_remove_subtree(b); - - /* becomes - * a b - * | - * c - * | - * d - */ - - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); - assert_int32(0, ==, b->sum_dep_weight); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); - assert_int32(0, ==, d->sum_dep_weight); - - check_stream_dep_sib(a, root, c, NULL, NULL); - check_stream_dep_sib(c, a, d, NULL, NULL); - check_stream_dep_sib(d, c, NULL, NULL, NULL); - check_stream_dep_sib(b, NULL, NULL, NULL, NULL); - - nghttp2_session_del(session); - - /* Remove middle stream */ - nghttp2_session_server_new(&session, &callbacks, NULL); - - root = &session->root; - - a = open_stream(session, 1); - e = open_stream_with_dep(session, 9, a); - c = open_stream_with_dep(session, 5, a); - b = open_stream_with_dep(session, 3, a); - d = open_stream_with_dep(session, 7, c); - - /* a - * | - * b--c--e - * | - * d - */ - - nghttp2_stream_dep_remove_subtree(c); - - /* becomes - * a c - * | | - * b--e d - */ - - assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, a->sum_dep_weight); - assert_int32(0, ==, b->sum_dep_weight); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); - assert_int32(0, ==, d->sum_dep_weight); - assert_int32(0, ==, e->sum_dep_weight); - - check_stream_dep_sib(a, root, b, NULL, NULL); - check_stream_dep_sib(b, a, NULL, NULL, e); - check_stream_dep_sib(e, a, NULL, b, NULL); - check_stream_dep_sib(c, NULL, d, NULL, NULL); - check_stream_dep_sib(d, c, NULL, NULL, NULL); - - nghttp2_session_del(session); -} - -void test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - nghttp2_stream *a, *b, *c, *d, *root; - nghttp2_outbound_item *db, *dc; - nghttp2_mem *mem; - - mem = nghttp2_mem_default(); - - memset(&callbacks, 0, sizeof(callbacks)); - - nghttp2_session_server_new(&session, &callbacks, NULL); - - root = &session->root; - - a = open_stream(session, 1); - b = open_stream_with_dep(session, 3, a); - - c = open_stream(session, 5); - - /* a c - * | - * b - */ - - nghttp2_stream_dep_remove_subtree(c); - assert_int(0, ==, nghttp2_stream_dep_insert_subtree(&session->root, c)); - - /* - * c - * | - * a - * | - * b - */ - - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, c->sum_dep_weight); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); - assert_int32(0, ==, b->sum_dep_weight); - - assert_true(nghttp2_pq_empty(&a->obq)); - assert_true(nghttp2_pq_empty(&b->obq)); - assert_true(nghttp2_pq_empty(&c->obq)); - - check_stream_dep_sib(c, root, a, NULL, NULL); - check_stream_dep_sib(a, c, b, NULL, NULL); - check_stream_dep_sib(b, a, NULL, NULL, NULL); - - nghttp2_session_del(session); - - nghttp2_session_server_new(&session, &callbacks, NULL); - - root = &session->root; - - a = open_stream(session, 1); - b = open_stream(session, 3); - c = open_stream(session, 5); - - /* - * a b c - */ - - nghttp2_stream_dep_remove_subtree(c); - assert_int(0, ==, nghttp2_stream_dep_insert_subtree(&session->root, c)); - - /* - * c - * | - * b--a - */ - - assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, c->sum_dep_weight); - assert_int32(0, ==, b->sum_dep_weight); - assert_int32(0, ==, a->sum_dep_weight); - - assert_true(nghttp2_pq_empty(&a->obq)); - assert_true(nghttp2_pq_empty(&b->obq)); - assert_true(nghttp2_pq_empty(&c->obq)); - - check_stream_dep_sib(c, root, b, NULL, NULL); - check_stream_dep_sib(b, c, NULL, NULL, a); - check_stream_dep_sib(a, c, NULL, b, NULL); - - nghttp2_session_del(session); - - nghttp2_session_server_new(&session, &callbacks, NULL); - - root = &session->root; - - a = open_stream(session, 1); - b = open_stream_with_dep(session, 3, a); - - c = open_stream(session, 5); - d = open_stream_with_dep(session, 7, c); - - /* a c - * | | - * b d - */ - - nghttp2_stream_dep_remove_subtree(c); - assert_int(0, ==, nghttp2_stream_dep_insert_subtree(&session->root, c)); - - /* - * c - * | - * d--a - * | - * b - */ - - assert_int32(NGHTTP2_DEFAULT_WEIGHT * 2, ==, c->sum_dep_weight); - assert_int32(0, ==, d->sum_dep_weight); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, a->sum_dep_weight); - assert_int32(0, ==, b->sum_dep_weight); - - assert_true(nghttp2_pq_empty(&a->obq)); - assert_true(nghttp2_pq_empty(&b->obq)); - assert_true(nghttp2_pq_empty(&c->obq)); - assert_true(nghttp2_pq_empty(&d->obq)); - - check_stream_dep_sib(c, root, d, NULL, NULL); - check_stream_dep_sib(d, c, NULL, NULL, a); - check_stream_dep_sib(a, c, b, d, NULL); - check_stream_dep_sib(b, a, NULL, NULL, NULL); - - nghttp2_session_del(session); - - nghttp2_session_server_new(&session, &callbacks, NULL); - - root = &session->root; - - a = open_stream(session, 1); - b = open_stream_with_dep(session, 3, a); - - c = open_stream(session, 5); - d = open_stream_with_dep(session, 7, c); - - /* a c - * | | - * b d - */ - - db = create_data_ob_item(mem); - - nghttp2_stream_attach_item(b, db); - - nghttp2_stream_dep_remove_subtree(c); - assert_int(0, ==, nghttp2_stream_dep_insert_subtree(&session->root, c)); - - /* - * c - * | - * d--a - * | - * b - */ - - assert_true(c->queued); - assert_true(a->queued); - assert_true(b->queued); - assert_true(!d->queued); - - assert_size(1, ==, nghttp2_pq_size(&a->obq)); - assert_size(1, ==, nghttp2_pq_size(&c->obq)); - assert_true(nghttp2_pq_empty(&d->obq)); - - check_stream_dep_sib(c, root, d, NULL, NULL); - check_stream_dep_sib(d, c, NULL, NULL, a); - check_stream_dep_sib(a, c, b, d, NULL); - check_stream_dep_sib(b, a, NULL, NULL, NULL); - - nghttp2_session_del(session); - - nghttp2_session_server_new(&session, &callbacks, NULL); - - root = &session->root; - - a = open_stream(session, 1); - b = open_stream_with_dep(session, 3, a); - - c = open_stream(session, 5); - d = open_stream_with_dep(session, 7, c); - - /* a c - * | | - * b d - */ - - db = create_data_ob_item(mem); - dc = create_data_ob_item(mem); - - nghttp2_stream_attach_item(b, db); - nghttp2_stream_attach_item(c, dc); - - nghttp2_stream_dep_remove_subtree(c); - assert_int(0, ==, nghttp2_stream_dep_insert_subtree(&session->root, c)); - - /* - * c - * | - * d--a - * | - * b - */ - - assert_true(c->queued); - assert_true(a->queued); - assert_true(b->queued); - assert_true(!d->queued); - - check_stream_dep_sib(c, root, d, NULL, NULL); - check_stream_dep_sib(d, c, NULL, NULL, a); - check_stream_dep_sib(a, c, b, d, NULL); - check_stream_dep_sib(b, a, NULL, NULL, NULL); - - nghttp2_session_del(session); -} - -void test_nghttp2_session_stream_attach_item(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - nghttp2_stream *a, *b, *c, *d, *e; - nghttp2_outbound_item *da, *db, *dc, *dd; - nghttp2_mem *mem; - - mem = nghttp2_mem_default(); - - memset(&callbacks, 0, sizeof(callbacks)); - - nghttp2_session_server_new(&session, &callbacks, NULL); - - a = open_stream(session, 1); - b = open_stream_with_dep(session, 3, a); - c = open_stream_with_dep(session, 5, a); - d = open_stream_with_dep(session, 7, c); - - /* a - * | - * c--b - * | - * d - */ - - db = create_data_ob_item(mem); - - nghttp2_stream_attach_item(b, db); - - assert_true(a->queued); - assert_true(b->queued); - assert_true(!c->queued); - assert_true(!d->queued); - - assert_size(1, ==, nghttp2_pq_size(&a->obq)); - - /* Attach item to c */ - dc = create_data_ob_item(mem); - - nghttp2_stream_attach_item(c, dc); - - assert_true(a->queued); - assert_true(b->queued); - assert_true(c->queued); - assert_true(!d->queued); - - assert_size(2, ==, nghttp2_pq_size(&a->obq)); - - /* Attach item to a */ - da = create_data_ob_item(mem); - - nghttp2_stream_attach_item(a, da); - - assert_true(a->queued); - assert_true(b->queued); - assert_true(c->queued); - assert_true(!d->queued); - - assert_size(2, ==, nghttp2_pq_size(&a->obq)); - - /* Detach item from a */ - nghttp2_stream_detach_item(a); - - assert_true(a->queued); - assert_true(b->queued); - assert_true(c->queued); - assert_true(!d->queued); - - assert_size(2, ==, nghttp2_pq_size(&a->obq)); - - /* Attach item to d */ - dd = create_data_ob_item(mem); - - nghttp2_stream_attach_item(d, dd); - - assert_true(a->queued); - assert_true(b->queued); - assert_true(c->queued); - assert_true(d->queued); - - assert_size(2, ==, nghttp2_pq_size(&a->obq)); - assert_size(1, ==, nghttp2_pq_size(&c->obq)); - - /* Detach item from c */ - nghttp2_stream_detach_item(c); - - assert_true(a->queued); - assert_true(b->queued); - assert_true(c->queued); - assert_true(d->queued); - - assert_size(2, ==, nghttp2_pq_size(&a->obq)); - assert_size(1, ==, nghttp2_pq_size(&c->obq)); - - /* Detach item from b */ - nghttp2_stream_detach_item(b); - - assert_true(a->queued); - assert_true(!b->queued); - assert_true(c->queued); - assert_true(d->queued); - - assert_size(1, ==, nghttp2_pq_size(&a->obq)); - - /* exercises insertion */ - e = open_stream_with_dep_excl(session, 9, a); - - /* a - * | - * e - * | - * c--b - * | - * d - */ - - assert_true(a->queued); - assert_true(e->queued); - assert_true(!b->queued); - assert_true(c->queued); - assert_true(d->queued); - - assert_size(1, ==, nghttp2_pq_size(&a->obq)); - assert_size(1, ==, nghttp2_pq_size(&e->obq)); - assert_true(nghttp2_pq_empty(&b->obq)); - assert_size(1, ==, nghttp2_pq_size(&c->obq)); - assert_true(nghttp2_pq_empty(&d->obq)); - - /* exercises deletion */ - nghttp2_stream_dep_remove(e); - - /* a - * | - * c--b - * | - * d - */ - - assert_true(a->queued); - assert_true(!b->queued); - assert_true(c->queued); - assert_true(d->queued); - - assert_size(1, ==, nghttp2_pq_size(&a->obq)); - assert_true(nghttp2_pq_empty(&b->obq)); - assert_size(1, ==, nghttp2_pq_size(&c->obq)); - assert_true(nghttp2_pq_empty(&d->obq)); - - /* e's weight 16 is distributed equally among c and b, both now have - weight 8 each. */ - assert_int32(8, ==, b->weight); - assert_int32(8, ==, c->weight); - - /* da, db, dc have been detached */ - nghttp2_outbound_item_free(da, mem); - nghttp2_outbound_item_free(db, mem); - nghttp2_outbound_item_free(dc, mem); - free(da); - free(db); - free(dc); - - nghttp2_session_del(session); - - nghttp2_session_server_new(&session, &callbacks, NULL); - - a = open_stream(session, 1); - b = open_stream_with_dep(session, 3, a); - c = open_stream_with_dep(session, 5, a); - d = open_stream_with_dep(session, 7, c); - - /* a - * | - * c--b - * | - * d - */ - - da = create_data_ob_item(mem); - db = create_data_ob_item(mem); - dc = create_data_ob_item(mem); - - nghttp2_stream_attach_item(a, da); - nghttp2_stream_attach_item(b, db); - nghttp2_stream_attach_item(c, dc); - - assert_true(a->queued); - assert_true(b->queued); - assert_true(c->queued); - assert_true(!d->queued); - - assert_size(2, ==, nghttp2_pq_size(&a->obq)); - assert_true(nghttp2_pq_empty(&b->obq)); - assert_true(nghttp2_pq_empty(&c->obq)); - assert_true(nghttp2_pq_empty(&d->obq)); - - /* Detach item from a */ - nghttp2_stream_detach_item(a); - - assert_true(a->queued); - assert_true(b->queued); - assert_true(c->queued); - assert_true(!d->queued); - - assert_size(2, ==, nghttp2_pq_size(&a->obq)); - assert_true(nghttp2_pq_empty(&b->obq)); - assert_true(nghttp2_pq_empty(&c->obq)); - assert_true(nghttp2_pq_empty(&d->obq)); - - /* da has been detached */ - nghttp2_outbound_item_free(da, mem); - free(da); - - nghttp2_session_del(session); -} - -void test_nghttp2_session_stream_attach_item_subtree(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - nghttp2_stream *a, *b, *c, *d, *e, *f; - nghttp2_outbound_item *da, *db, *dd, *de; - nghttp2_mem *mem; - - mem = nghttp2_mem_default(); - - memset(&callbacks, 0, sizeof(callbacks)); - - nghttp2_session_server_new(&session, &callbacks, NULL); - - a = open_stream(session, 1); - b = open_stream_with_dep(session, 3, a); - c = open_stream_with_dep(session, 5, a); - d = open_stream_with_dep(session, 7, c); - - e = open_stream_with_dep_weight(session, 9, 32, &session->root); - f = open_stream_with_dep(session, 11, e); - - /* - * a e - * | | - * c--b f - * | - * d - */ - - de = create_data_ob_item(mem); - - nghttp2_stream_attach_item(e, de); - - db = create_data_ob_item(mem); - - nghttp2_stream_attach_item(b, db); - - assert_true(a->queued); - assert_true(b->queued); - assert_true(!c->queued); - assert_true(!d->queued); - assert_true(e->queued); - assert_true(!f->queued); - - assert_size(1, ==, nghttp2_pq_size(&a->obq)); - assert_true(nghttp2_pq_empty(&b->obq)); - assert_true(nghttp2_pq_empty(&c->obq)); - assert_true(nghttp2_pq_empty(&d->obq)); - assert_true(nghttp2_pq_empty(&e->obq)); - assert_true(nghttp2_pq_empty(&f->obq)); - - /* Insert subtree e under a */ - - nghttp2_stream_dep_remove_subtree(e); - nghttp2_stream_dep_insert_subtree(a, e); - - /* - * a - * | - * e - * | - * f--c--b - * | - * d - */ - - assert_true(a->queued); - assert_true(b->queued); - assert_true(!c->queued); - assert_true(!d->queued); - assert_true(e->queued); - assert_true(!f->queued); - - assert_size(1, ==, nghttp2_pq_size(&a->obq)); - assert_true(nghttp2_pq_empty(&b->obq)); - assert_true(nghttp2_pq_empty(&c->obq)); - assert_true(nghttp2_pq_empty(&d->obq)); - assert_size(1, ==, nghttp2_pq_size(&e->obq)); - assert_true(nghttp2_pq_empty(&f->obq)); - - /* Remove subtree b */ - - nghttp2_stream_dep_remove_subtree(b); - - assert_int(0, ==, nghttp2_stream_dep_add_subtree(&session->root, b)); - - /* - * a b - * | - * e - * | - * f--c - * | - * d - */ - - assert_true(a->queued); - assert_true(b->queued); - assert_true(!c->queued); - assert_true(!d->queued); - assert_true(e->queued); - assert_true(!f->queued); - - assert_size(1, ==, nghttp2_pq_size(&a->obq)); - assert_true(nghttp2_pq_empty(&b->obq)); - assert_true(nghttp2_pq_empty(&c->obq)); - assert_true(nghttp2_pq_empty(&d->obq)); - assert_true(nghttp2_pq_empty(&e->obq)); - assert_true(nghttp2_pq_empty(&f->obq)); - - /* Remove subtree a, and add it to root again */ - - nghttp2_stream_dep_remove_subtree(a); - - assert_int(0, ==, nghttp2_stream_dep_add_subtree(&session->root, a)); - - assert_true(a->queued); - assert_true(b->queued); - assert_true(!c->queued); - assert_true(!d->queued); - assert_true(e->queued); - assert_true(!f->queued); - - assert_size(1, ==, nghttp2_pq_size(&a->obq)); - assert_true(nghttp2_pq_empty(&b->obq)); - assert_true(nghttp2_pq_empty(&c->obq)); - assert_true(nghttp2_pq_empty(&d->obq)); - assert_true(nghttp2_pq_empty(&e->obq)); - assert_true(nghttp2_pq_empty(&f->obq)); - - /* Remove subtree c */ - - nghttp2_stream_dep_remove_subtree(c); - - assert_int(0, ==, nghttp2_stream_dep_add_subtree(&session->root, c)); - - /* - * a b c - * | | - * e d - * | - * f - */ - - assert_true(a->queued); - assert_true(b->queued); - assert_true(!c->queued); - assert_true(!d->queued); - assert_true(e->queued); - assert_true(!f->queued); - - assert_size(1, ==, nghttp2_pq_size(&a->obq)); - assert_true(nghttp2_pq_empty(&b->obq)); - assert_true(nghttp2_pq_empty(&c->obq)); - assert_true(nghttp2_pq_empty(&d->obq)); - assert_true(nghttp2_pq_empty(&e->obq)); - assert_true(nghttp2_pq_empty(&f->obq)); - - dd = create_data_ob_item(mem); - - nghttp2_stream_attach_item(d, dd); - - /* Add subtree c to a */ - - nghttp2_stream_dep_remove_subtree(c); - nghttp2_stream_dep_add_subtree(a, c); - - /* - * a b - * | - * c--e - * | | - * d f - */ - - assert_true(a->queued); - assert_true(b->queued); - assert_true(c->queued); - assert_true(d->queued); - assert_true(e->queued); - assert_true(!f->queued); - - assert_size(2, ==, nghttp2_pq_size(&a->obq)); - assert_true(nghttp2_pq_empty(&b->obq)); - assert_size(1, ==, nghttp2_pq_size(&c->obq)); - assert_true(nghttp2_pq_empty(&d->obq)); - assert_true(nghttp2_pq_empty(&e->obq)); - assert_true(nghttp2_pq_empty(&f->obq)); - - /* Insert b under a */ - - nghttp2_stream_dep_remove_subtree(b); - nghttp2_stream_dep_insert_subtree(a, b); - - /* - * a - * | - * b - * | - * c--e - * | | - * d f - */ - - assert_true(a->queued); - assert_true(b->queued); - assert_true(c->queued); - assert_true(d->queued); - assert_true(e->queued); - assert_true(!f->queued); - - assert_size(1, ==, nghttp2_pq_size(&a->obq)); - assert_size(2, ==, nghttp2_pq_size(&b->obq)); - assert_size(1, ==, nghttp2_pq_size(&c->obq)); - assert_true(nghttp2_pq_empty(&d->obq)); - assert_true(nghttp2_pq_empty(&e->obq)); - assert_true(nghttp2_pq_empty(&f->obq)); - - /* Remove subtree b */ - - nghttp2_stream_dep_remove_subtree(b); - assert_int(0, ==, nghttp2_stream_dep_add_subtree(&session->root, b)); - - /* - * b a - * | - * e--c - * | | - * f d - */ - - assert_true(!a->queued); - assert_true(b->queued); - assert_true(c->queued); - assert_true(d->queued); - assert_true(e->queued); - assert_true(!f->queued); - - assert_true(nghttp2_pq_empty(&a->obq)); - assert_size(2, ==, nghttp2_pq_size(&b->obq)); - assert_size(1, ==, nghttp2_pq_size(&c->obq)); - assert_true(nghttp2_pq_empty(&d->obq)); - assert_true(nghttp2_pq_empty(&e->obq)); - assert_true(nghttp2_pq_empty(&f->obq)); - - /* Remove subtree c, and detach item from b, and then re-add - subtree c under b */ - - nghttp2_stream_dep_remove_subtree(c); - nghttp2_stream_detach_item(b); - nghttp2_stream_dep_add_subtree(b, c); - - /* - * b a - * | - * e--c - * | | - * f d - */ - - assert_true(!a->queued); - assert_true(b->queued); - assert_true(c->queued); - assert_true(d->queued); - assert_true(e->queued); - assert_true(!f->queued); - - assert_true(nghttp2_pq_empty(&a->obq)); - assert_size(2, ==, nghttp2_pq_size(&b->obq)); - assert_size(1, ==, nghttp2_pq_size(&c->obq)); - assert_true(nghttp2_pq_empty(&d->obq)); - assert_true(nghttp2_pq_empty(&e->obq)); - assert_true(nghttp2_pq_empty(&f->obq)); - - /* Attach data to a, and add subtree a under b */ - - da = create_data_ob_item(mem); - nghttp2_stream_attach_item(a, da); - nghttp2_stream_dep_remove_subtree(a); - nghttp2_stream_dep_add_subtree(b, a); - - /* - * b - * | - * a--e--c - * | | - * f d - */ - - assert_true(a->queued); - assert_true(b->queued); - assert_true(c->queued); - assert_true(d->queued); - assert_true(e->queued); - assert_true(!f->queued); - - assert_true(nghttp2_pq_empty(&a->obq)); - assert_size(3, ==, nghttp2_pq_size(&b->obq)); - assert_size(1, ==, nghttp2_pq_size(&c->obq)); - assert_true(nghttp2_pq_empty(&d->obq)); - assert_true(nghttp2_pq_empty(&e->obq)); - assert_true(nghttp2_pq_empty(&f->obq)); - - /* Remove subtree c, and add under f */ - nghttp2_stream_dep_remove_subtree(c); - nghttp2_stream_dep_insert_subtree(f, c); - - /* - * b - * | - * a--e - * | - * f - * | - * c - * | - * d - */ - - assert_true(a->queued); - assert_true(b->queued); - assert_true(c->queued); - assert_true(d->queued); - assert_true(e->queued); - assert_true(f->queued); - - assert_true(nghttp2_pq_empty(&a->obq)); - assert_size(2, ==, nghttp2_pq_size(&b->obq)); - assert_size(1, ==, nghttp2_pq_size(&c->obq)); - assert_true(nghttp2_pq_empty(&d->obq)); - assert_size(1, ==, nghttp2_pq_size(&e->obq)); - assert_size(1, ==, nghttp2_pq_size(&f->obq)); - - /* db has been detached */ - nghttp2_outbound_item_free(db, mem); - free(db); - - nghttp2_session_del(session); -} - void test_nghttp2_session_stream_get_state(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; @@ -9776,7 +8099,6 @@ void test_nghttp2_session_stream_get_state(void) { nghttp2_stream *stream; nghttp2_ssize rv; nghttp2_data_provider2 data_prd; - nghttp2_frame frame; mem = nghttp2_mem_default(); frame_pack_bufs_init(&bufs); @@ -9852,8 +8174,7 @@ void test_nghttp2_session_stream_get_state(void) { stream = nghttp2_session_find_stream(session, 3); - assert_enum(nghttp2_stream_proto_state, NGHTTP2_STREAM_STATE_CLOSED, ==, - nghttp2_stream_get_state(stream)); + assert_null(stream); /* stream 5 HEADERS; with END_STREAM flag set */ pack_headers(&bufs, &deflater, 5, @@ -9924,25 +8245,6 @@ void test_nghttp2_session_stream_get_state(void) { NGHTTP2_STREAM_STATE_HALF_CLOSED_REMOTE, ==, nghttp2_stream_get_state(stream)); - /* Create idle stream by PRIORITY frame */ - nghttp2_frame_priority_init(&frame.priority, 7, &pri_spec_default); - - nghttp2_frame_pack_priority(&bufs, &frame.priority); - - nghttp2_frame_priority_free(&frame.priority); - - buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - - assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); - - stream = nghttp2_session_find_stream(session, 7); - - assert_enum(nghttp2_stream_proto_state, NGHTTP2_STREAM_STATE_IDLE, ==, - nghttp2_stream_get_state(stream)); - - nghttp2_bufs_reset(&bufs); - nghttp2_hd_deflate_free(&deflater); nghttp2_session_del(session); @@ -9996,43 +8298,6 @@ void test_nghttp2_session_stream_get_state(void) { nghttp2_bufs_free(&bufs); } -void test_nghttp2_session_stream_get_something(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - nghttp2_stream *a, *b, *c; - - memset(&callbacks, 0, sizeof(callbacks)); - - nghttp2_session_server_new(&session, &callbacks, NULL); - - a = open_stream(session, 1); - - assert_ptr_equal(nghttp2_session_get_root_stream(session), - nghttp2_stream_get_parent(a)); - assert_null(nghttp2_stream_get_previous_sibling(a)); - assert_null(nghttp2_stream_get_next_sibling(a)); - assert_null(nghttp2_stream_get_first_child(a)); - - b = open_stream_with_dep(session, 3, a); - c = open_stream_with_dep_weight(session, 5, 11, a); - - assert_ptr_equal(a, nghttp2_stream_get_parent(c)); - assert_ptr_equal(a, nghttp2_stream_get_parent(b)); - - assert_ptr_equal(c, nghttp2_stream_get_first_child(a)); - - assert_ptr_equal(b, nghttp2_stream_get_next_sibling(c)); - assert_ptr_equal(c, nghttp2_stream_get_previous_sibling(b)); - - assert_int32(27, ==, nghttp2_stream_get_sum_dependency_weight(a)); - - assert_int32(11, ==, nghttp2_stream_get_weight(c)); - assert_int32(5, ==, nghttp2_stream_get_stream_id(c)); - assert_int32(0, ==, nghttp2_stream_get_stream_id(&session->root)); - - nghttp2_session_del(session); -} - void test_nghttp2_session_find_stream(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; @@ -10051,7 +8316,7 @@ void test_nghttp2_session_find_stream(void) { stream = nghttp2_session_find_stream(session, 0); - assert_ptr_equal(&session->root, stream); + assert_not_null(stream); assert_int32(0, ==, stream->stream_id); stream = nghttp2_session_find_stream(session, 2); @@ -10061,232 +8326,6 @@ void test_nghttp2_session_find_stream(void) { nghttp2_session_del(session); } -void test_nghttp2_session_keep_closed_stream(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - const size_t max_concurrent_streams = 5; - nghttp2_settings_entry iv = {NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, - (uint32_t)max_concurrent_streams}; - size_t i; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback2 = null_send_callback; - - nghttp2_session_server_new(&session, &callbacks, NULL); - - nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1); - - for (i = 0; i < max_concurrent_streams; ++i) { - open_recv_stream(session, (int32_t)i * 2 + 1); - } - - assert_size(0, ==, session->num_closed_streams); - - nghttp2_session_close_stream(session, 1, NGHTTP2_NO_ERROR); - - assert_size(1, ==, session->num_closed_streams); - assert_int32(1, ==, session->closed_stream_tail->stream_id); - assert_ptr_equal(session->closed_stream_tail, session->closed_stream_head); - - nghttp2_session_close_stream(session, 5, NGHTTP2_NO_ERROR); - - assert_size(2, ==, session->num_closed_streams); - assert_int32(5, ==, session->closed_stream_tail->stream_id); - assert_int32(1, ==, session->closed_stream_head->stream_id); - assert_ptr_equal(session->closed_stream_head, - session->closed_stream_tail->closed_prev); - assert_null(session->closed_stream_tail->closed_next); - assert_ptr_equal(session->closed_stream_tail, - session->closed_stream_head->closed_next); - assert_null(session->closed_stream_head->closed_prev); - - open_recv_stream(session, 11); - nghttp2_session_adjust_closed_stream(session); - - assert_size(1, ==, session->num_closed_streams); - assert_int32(5, ==, session->closed_stream_tail->stream_id); - assert_ptr_equal(session->closed_stream_tail, session->closed_stream_head); - assert_null(session->closed_stream_head->closed_prev); - assert_null(session->closed_stream_head->closed_next); - - open_recv_stream(session, 13); - nghttp2_session_adjust_closed_stream(session); - - assert_size(0, ==, session->num_closed_streams); - assert_null(session->closed_stream_tail); - assert_null(session->closed_stream_head); - - nghttp2_session_close_stream(session, 3, NGHTTP2_NO_ERROR); - - assert_size(1, ==, session->num_closed_streams); - assert_int32(3, ==, session->closed_stream_head->stream_id); - - /* server initiated stream is not counted to max concurrent limit */ - open_sent_stream(session, 2); - nghttp2_session_adjust_closed_stream(session); - - assert_size(1, ==, session->num_closed_streams); - assert_int32(3, ==, session->closed_stream_head->stream_id); - - nghttp2_session_close_stream(session, 2, NGHTTP2_NO_ERROR); - - assert_size(1, ==, session->num_closed_streams); - assert_int32(3, ==, session->closed_stream_head->stream_id); - - nghttp2_session_del(session); -} - -void test_nghttp2_session_keep_idle_stream(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - const size_t max_concurrent_streams = 1; - nghttp2_settings_entry iv = {NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, - (uint32_t)max_concurrent_streams}; - int i; - int32_t stream_id; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback2 = null_send_callback; - - nghttp2_session_server_new(&session, &callbacks, NULL); - - nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1); - - /* We at least allow NGHTTP2_MIN_IDLE_STREAM idle streams even if - max concurrent streams is very low. */ - for (i = 0; i < NGHTTP2_MIN_IDLE_STREAMS; ++i) { - open_recv_stream2(session, i * 2 + 1, NGHTTP2_STREAM_IDLE); - nghttp2_session_adjust_idle_stream(session); - } - - assert_size(NGHTTP2_MIN_IDLE_STREAMS, ==, session->num_idle_streams); - - stream_id = (NGHTTP2_MIN_IDLE_STREAMS - 1) * 2 + 1; - assert_int32(1, ==, session->idle_stream_head->stream_id); - assert_int32(stream_id, ==, session->idle_stream_tail->stream_id); - - stream_id += 2; - - open_recv_stream2(session, stream_id, NGHTTP2_STREAM_IDLE); - nghttp2_session_adjust_idle_stream(session); - - assert_size(NGHTTP2_MIN_IDLE_STREAMS, ==, session->num_idle_streams); - assert_int32(3, ==, session->idle_stream_head->stream_id); - assert_int32(stream_id, ==, session->idle_stream_tail->stream_id); - - nghttp2_session_del(session); -} - -void test_nghttp2_session_detach_idle_stream(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - int i; - nghttp2_stream *stream; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback2 = null_send_callback; - - nghttp2_session_server_new(&session, &callbacks, NULL); - - for (i = 1; i <= 3; ++i) { - nghttp2_session_open_stream(session, i, NGHTTP2_STREAM_FLAG_NONE, - &pri_spec_default, NGHTTP2_STREAM_IDLE, NULL); - } - - assert_size(3, ==, session->num_idle_streams); - - /* Detach middle stream */ - stream = nghttp2_session_get_stream_raw(session, 2); - - assert_ptr_equal(session->idle_stream_head, stream->closed_prev); - assert_ptr_equal(session->idle_stream_tail, stream->closed_next); - assert_ptr_equal(stream, session->idle_stream_head->closed_next); - assert_ptr_equal(stream, session->idle_stream_tail->closed_prev); - - nghttp2_session_detach_idle_stream(session, stream); - - assert_size(2, ==, session->num_idle_streams); - - assert_null(stream->closed_prev); - assert_null(stream->closed_next); - - assert_ptr_equal(session->idle_stream_head, - session->idle_stream_tail->closed_prev); - assert_ptr_equal(session->idle_stream_tail, - session->idle_stream_head->closed_next); - - /* Detach head stream */ - stream = session->idle_stream_head; - - nghttp2_session_detach_idle_stream(session, stream); - - assert_size(1, ==, session->num_idle_streams); - - assert_ptr_equal(session->idle_stream_head, session->idle_stream_tail); - assert_null(session->idle_stream_head->closed_prev); - assert_null(session->idle_stream_head->closed_next); - - /* Detach last stream */ - - stream = session->idle_stream_head; - - nghttp2_session_detach_idle_stream(session, stream); - - assert_size(0, ==, session->num_idle_streams); - - assert_null(session->idle_stream_head); - assert_null(session->idle_stream_tail); - - for (i = 4; i <= 5; ++i) { - nghttp2_session_open_stream(session, i, NGHTTP2_STREAM_FLAG_NONE, - &pri_spec_default, NGHTTP2_STREAM_IDLE, NULL); - } - - assert_size(2, ==, session->num_idle_streams); - - /* Detach tail stream */ - - stream = session->idle_stream_tail; - - nghttp2_session_detach_idle_stream(session, stream); - - assert_size(1, ==, session->num_idle_streams); - - assert_ptr_equal(session->idle_stream_head, session->idle_stream_tail); - assert_null(session->idle_stream_head->closed_prev); - assert_null(session->idle_stream_head->closed_next); - - nghttp2_session_del(session); -} - -void test_nghttp2_session_large_dep_tree(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - size_t i; - nghttp2_stream *dep_stream = NULL; - nghttp2_stream *stream; - int32_t stream_id; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback2 = null_send_callback; - - nghttp2_session_server_new(&session, &callbacks, NULL); - - stream_id = 1; - for (i = 0; i < 250; ++i, stream_id += 2) { - dep_stream = open_stream_with_dep(session, stream_id, dep_stream); - } - - stream_id = 1; - for (i = 0; i < 250; ++i, stream_id += 2) { - stream = nghttp2_session_get_stream(session, stream_id); - assert_true(nghttp2_stream_dep_find_ancestor(stream, &session->root)); - assert_true(nghttp2_stream_in_dep_tree(stream)); - } - - nghttp2_session_del(session); -} - void test_nghttp2_session_graceful_shutdown(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; @@ -10503,15 +8542,14 @@ void test_nghttp2_session_recv_client_magic(void) { void test_nghttp2_session_delete_data_item(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; - nghttp2_stream *a; nghttp2_data_provider2 prd; memset(&callbacks, 0, sizeof(callbacks)); nghttp2_session_server_new(&session, &callbacks, NULL); - a = open_recv_stream(session, 1); - open_recv_stream_with_dep(session, 3, a); + open_recv_stream(session, 1); + open_recv_stream(session, 3); /* We don't care about these members, since we won't send data */ prd.source.ptr = NULL; @@ -10528,7 +8566,6 @@ void test_nghttp2_session_open_idle_stream(void) { nghttp2_session_callbacks callbacks; nghttp2_stream *stream; nghttp2_stream *opened_stream; - nghttp2_priority_spec pri_spec; nghttp2_frame frame; nghttp2_ext_priority_update priority_update; @@ -10536,28 +8573,25 @@ void test_nghttp2_session_open_idle_stream(void) { nghttp2_session_server_new(&session, &callbacks, NULL); - nghttp2_priority_spec_init(&pri_spec, 0, 3, 0); + frame.ext.payload = &priority_update; - nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); + nghttp2_frame_priority_update_init(&frame.ext, 1, (uint8_t *)"u=3", + strlen("u=3")); - assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); + assert_int(0, ==, + nghttp2_session_on_priority_update_received(session, &frame)); stream = nghttp2_session_get_stream_raw(session, 1); assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, stream->state); - assert_null(stream->closed_prev); assert_null(stream->closed_next); assert_size(1, ==, session->num_idle_streams); - assert_ptr_equal(session->idle_stream_head, stream); - assert_ptr_equal(session->idle_stream_tail, stream); opened_stream = open_recv_stream2(session, 1, NGHTTP2_STREAM_OPENING); assert_ptr_equal(stream, opened_stream); assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); assert_size(0, ==, session->num_idle_streams); - assert_null(session->idle_stream_head); - assert_null(session->idle_stream_tail); nghttp2_frame_priority_free(&frame.priority); @@ -11005,80 +9039,6 @@ void test_nghttp2_session_flooding(void) { nghttp2_bufs_free(&bufs); } -void test_nghttp2_session_change_stream_priority(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - nghttp2_stream *stream1, *stream2, *stream3, *stream5; - nghttp2_priority_spec pri_spec; - int rv; - - memset(&callbacks, 0, sizeof(callbacks)); - - nghttp2_session_server_new(&session, &callbacks, NULL); - - stream1 = open_recv_stream(session, 1); - stream3 = open_recv_stream_with_dep_weight(session, 3, 199, stream1); - stream2 = open_sent_stream_with_dep_weight(session, 2, 101, stream3); - - nghttp2_priority_spec_init(&pri_spec, 1, 256, 0); - - rv = nghttp2_session_change_stream_priority(session, 2, &pri_spec); - - assert_int(0, ==, rv); - - assert_ptr_equal(stream1, stream2->dep_prev); - assert_int32(256, ==, stream2->weight); - - /* Cannot change stream which does not exist */ - rv = nghttp2_session_change_stream_priority(session, 5, &pri_spec); - assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); - - /* It is an error to depend on itself */ - rv = nghttp2_session_change_stream_priority(session, 1, &pri_spec); - assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); - - /* It is an error to change priority of root stream (0) */ - rv = nghttp2_session_change_stream_priority(session, 0, &pri_spec); - assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); - - /* Depends on the non-existing idle stream. This creates that idle - stream. */ - nghttp2_priority_spec_init(&pri_spec, 5, 9, 1); - - rv = nghttp2_session_change_stream_priority(session, 2, &pri_spec); - - assert_int(0, ==, rv); - - stream5 = nghttp2_session_get_stream_raw(session, 5); - - assert_not_null(stream5); - assert_ptr_equal(&session->root, stream5->dep_prev); - assert_ptr_equal(stream5, stream2->dep_prev); - assert_int32(9, ==, stream2->weight); - - nghttp2_session_del(session); - - /* Check that this works in client session too */ - nghttp2_session_client_new(&session, &callbacks, NULL); - - stream1 = open_sent_stream(session, 1); - - nghttp2_priority_spec_init(&pri_spec, 5, 9, 1); - - rv = nghttp2_session_change_stream_priority(session, 1, &pri_spec); - - assert_int(0, ==, rv); - - stream5 = nghttp2_session_get_stream_raw(session, 5); - - assert_not_null(stream5); - assert_ptr_equal(&session->root, stream5->dep_prev); - assert_ptr_equal(stream5, stream1->dep_prev); - assert_int32(9, ==, stream1->weight); - - nghttp2_session_del(session); -} - void test_nghttp2_session_change_extpri_stream_priority(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; @@ -11163,243 +9123,6 @@ void test_nghttp2_session_change_extpri_stream_priority(void) { nghttp2_bufs_free(&bufs); } -void test_nghttp2_session_create_idle_stream(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - nghttp2_stream *stream2, *stream4, *stream8, *stream10; - nghttp2_priority_spec pri_spec; - int rv; - int i; - - memset(&callbacks, 0, sizeof(callbacks)); - callbacks.send_callback2 = null_send_callback; - - nghttp2_session_server_new(&session, &callbacks, NULL); - - stream2 = open_sent_stream(session, 2); - - nghttp2_priority_spec_init(&pri_spec, 2, 111, 1); - - rv = nghttp2_session_create_idle_stream(session, 4, &pri_spec); - - assert_int(0, ==, rv); - - stream4 = nghttp2_session_get_stream_raw(session, 4); - - assert_int32(4, ==, stream4->stream_id); - assert_int32(111, ==, stream4->weight); - assert_ptr_equal(stream2, stream4->dep_prev); - assert_ptr_equal(stream4, stream2->dep_next); - - /* If pri_spec->stream_id does not exist, and it is idle stream, it - is created too */ - nghttp2_priority_spec_init(&pri_spec, 10, 109, 0); - - rv = nghttp2_session_create_idle_stream(session, 8, &pri_spec); - - assert_int(0, ==, rv); - - stream8 = nghttp2_session_get_stream_raw(session, 8); - stream10 = nghttp2_session_get_stream_raw(session, 10); - - assert_int32(8, ==, stream8->stream_id); - assert_int32(109, ==, stream8->weight); - assert_int32(10, ==, stream10->stream_id); - assert_int32(16, ==, stream10->weight); - assert_ptr_equal(stream10, stream8->dep_prev); - assert_ptr_equal(&session->root, stream10->dep_prev); - - /* It is an error to attempt to create already existing idle - stream */ - rv = nghttp2_session_create_idle_stream(session, 4, &pri_spec); - - assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); - - /* It is an error to depend on itself */ - pri_spec.stream_id = 6; - - rv = nghttp2_session_create_idle_stream(session, 6, &pri_spec); - assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); - - /* It is an error to create root stream (0) as idle stream */ - rv = nghttp2_session_create_idle_stream(session, 0, &pri_spec); - assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); - - /* It is an error to create non-idle stream */ - session->last_sent_stream_id = 20; - pri_spec.stream_id = 2; - - rv = nghttp2_session_create_idle_stream(session, 18, &pri_spec); - - assert_int(NGHTTP2_ERR_INVALID_ARGUMENT, ==, rv); - - nghttp2_session_del(session); - - /* Check that this works in client session too */ - nghttp2_session_client_new(&session, &callbacks, NULL); - - nghttp2_priority_spec_init(&pri_spec, 4, 99, 1); - - rv = nghttp2_session_create_idle_stream(session, 2, &pri_spec); - - assert_int(0, ==, rv); - - stream4 = nghttp2_session_get_stream_raw(session, 4); - stream2 = nghttp2_session_get_stream_raw(session, 2); - - assert_not_null(stream4); - assert_not_null(stream2); - assert_ptr_equal(&session->root, stream4->dep_prev); - assert_int32(NGHTTP2_DEFAULT_WEIGHT, ==, stream4->weight); - assert_ptr_equal(stream4, stream2->dep_prev); - assert_int32(99, ==, stream2->weight); - - nghttp2_session_del(session); - - /* Check that idle stream is reduced when nghttp2_session_send() is - called. */ - nghttp2_session_server_new(&session, &callbacks, NULL); - - session->local_settings.max_concurrent_streams = 30; - - nghttp2_priority_spec_init(&pri_spec, 0, 16, 0); - for (i = 0; i < 100; ++i) { - rv = nghttp2_session_create_idle_stream(session, i * 2 + 1, &pri_spec); - - assert_int(0, ==, rv); - - nghttp2_priority_spec_init(&pri_spec, i * 2 + 1, 16, 0); - } - - assert_size(100, ==, session->num_idle_streams); - assert_int(0, ==, nghttp2_session_send(session)); - assert_size(30, ==, session->num_idle_streams); - assert_int32(141, ==, session->idle_stream_head->stream_id); - - nghttp2_session_del(session); - - /* Check that idle stream is reduced when nghttp2_session_mem_recv2() is - called. */ - nghttp2_session_client_new(&session, &callbacks, NULL); - - session->local_settings.max_concurrent_streams = 30; - - nghttp2_priority_spec_init(&pri_spec, 0, 16, 0); - for (i = 0; i < 100; ++i) { - rv = nghttp2_session_create_idle_stream(session, i * 2 + 1, &pri_spec); - - assert_int(0, ==, rv); - - nghttp2_priority_spec_init(&pri_spec, i * 2 + 1, 16, 0); - } - - assert_size(100, ==, session->num_idle_streams); - assert_ptrdiff(0, ==, nghttp2_session_mem_recv2(session, NULL, 0)); - assert_size(30, ==, session->num_idle_streams); - assert_int32(141, ==, session->idle_stream_head->stream_id); - - nghttp2_session_del(session); -} - -void test_nghttp2_session_repeated_priority_change(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - nghttp2_frame frame; - nghttp2_priority_spec pri_spec; - int32_t stream_id, last_stream_id; - int32_t max_streams = 20; - - memset(&callbacks, 0, sizeof(callbacks)); - - nghttp2_session_server_new(&session, &callbacks, NULL); - - session->local_settings.max_concurrent_streams = (uint32_t)max_streams; - - /* 1 -> 0 */ - nghttp2_priority_spec_init(&pri_spec, 0, 16, 0); - nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - - assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); - - nghttp2_frame_priority_free(&frame.priority); - - last_stream_id = max_streams * 2 + 1; - - for (stream_id = 3; stream_id < last_stream_id; stream_id += 2) { - /* 1 -> stream_id */ - nghttp2_priority_spec_init(&pri_spec, stream_id, 16, 0); - nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - - assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); - - nghttp2_frame_priority_free(&frame.priority); - } - - assert_size(20, ==, session->num_idle_streams); - assert_int32(1, ==, session->idle_stream_head->stream_id); - - /* 1 -> last_stream_id */ - nghttp2_priority_spec_init(&pri_spec, last_stream_id, 16, 0); - nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - - assert_int(0, ==, nghttp2_session_on_priority_received(session, &frame)); - - nghttp2_frame_priority_free(&frame.priority); - - assert_size(20, ==, session->num_idle_streams); - assert_int32(3, ==, session->idle_stream_head->stream_id); - - nghttp2_session_del(session); -} - -void test_nghttp2_session_repeated_priority_submission(void) { - nghttp2_session *session; - nghttp2_session_callbacks callbacks; - nghttp2_priority_spec pri_spec; - int32_t stream_id, last_stream_id; - uint32_t max_streams = NGHTTP2_MIN_IDLE_STREAMS; - - memset(&callbacks, 0, sizeof(callbacks)); - - callbacks.send_callback2 = null_send_callback; - - nghttp2_session_client_new(&session, &callbacks, NULL); - - session->local_settings.max_concurrent_streams = max_streams; - - /* 1 -> 0 */ - nghttp2_priority_spec_init(&pri_spec, 0, 16, 0); - - assert_int(0, ==, - nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); - - last_stream_id = (int32_t)(max_streams * 2 + 1); - - for (stream_id = 3; stream_id < last_stream_id; stream_id += 2) { - /* 1 -> stream_id */ - nghttp2_priority_spec_init(&pri_spec, stream_id, 16, 0); - - assert_int( - 0, ==, nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); - } - - assert_int(0, ==, nghttp2_session_send(session)); - assert_size(max_streams, ==, session->num_idle_streams); - assert_int32(1, ==, session->idle_stream_head->stream_id); - - /* 1 -> last_stream_id */ - nghttp2_priority_spec_init(&pri_spec, last_stream_id, 16, 0); - - assert_int(0, ==, - nghttp2_submit_priority(session, NGHTTP2_FLAG_NONE, 1, &pri_spec)); - - assert_int(0, ==, nghttp2_session_send(session)); - assert_size(max_streams, ==, session->num_idle_streams); - assert_int32(3, ==, session->idle_stream_head->stream_id); - - nghttp2_session_del(session); -} - void test_nghttp2_session_set_local_window_size(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; @@ -12063,40 +9786,10 @@ void test_nghttp2_session_no_rfc7540_priorities(void) { assert_size( 1, ==, nghttp2_pq_size(&session->sched[NGHTTP2_EXTPRI_DEFAULT_URGENCY].ob_data)); - assert_true(nghttp2_pq_empty(&session->root.obq)); nghttp2_session_del(session); - /* Priorities are sent as is before client receives - SETTINGS_NO_RFC7540_PRIORITIES = 1 from server. */ - assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, NULL)); - - iv.settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; - iv.value = 1; - - assert_int(0, ==, - nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1)); - - pri_spec.stream_id = 5; - pri_spec.weight = 111; - pri_spec.exclusive = 1; - - assert_int32(1, ==, - nghttp2_submit_request2(session, &pri_spec, reqnv, ARRLEN(reqnv), - NULL, NULL)); - - item = nghttp2_outbound_queue_top(&session->ob_syn); - - assert_not_null(item); - assert_uint8(NGHTTP2_HEADERS, ==, item->frame.hd.type); - assert_int32(pri_spec.stream_id, ==, item->frame.headers.pri_spec.stream_id); - assert_int32(pri_spec.weight, ==, item->frame.headers.pri_spec.weight); - assert_uint8(pri_spec.exclusive, ==, item->frame.headers.pri_spec.exclusive); - - nghttp2_session_del(session); - - /* Priorities are defaulted if client received - SETTINGS_NO_RFC7540_PRIORITIES = 1 from server. */ + /* Priorities are defaulted */ assert_int(0, ==, nghttp2_session_client_new(&session, &callbacks, NULL)); iv.settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; @@ -12125,196 +9818,6 @@ void test_nghttp2_session_no_rfc7540_priorities(void) { nghttp2_session_del(session); } -void test_nghttp2_session_server_fallback_rfc7540_priorities(void) { - nghttp2_session *session; - nghttp2_option *option; - nghttp2_session_callbacks callbacks; - nghttp2_frame frame; - nghttp2_bufs bufs; - nghttp2_buf *buf; - nghttp2_ssize rv; - nghttp2_settings_entry iv; - nghttp2_mem *mem; - nghttp2_hd_deflater deflater; - nghttp2_nv *nva; - size_t nvlen; - nghttp2_priority_spec pri_spec; - nghttp2_stream *anchor_stream, *stream; - my_user_data ud; - nghttp2_ext_priority_update priority_update; - static const uint8_t field_value[] = "u=0"; - - mem = nghttp2_mem_default(); - frame_pack_bufs_init(&bufs); - - memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); - callbacks.send_callback2 = null_send_callback; - callbacks.on_frame_recv_callback = on_frame_recv_callback; - - nghttp2_option_new(&option); - nghttp2_option_set_server_fallback_rfc7540_priorities(option, 1); - - iv.settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; - iv.value = 1; - - /* Server falls back to RFC 7540 priorities. */ - nghttp2_session_server_new2(&session, &callbacks, &ud, option); - - rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1); - - assert_ptrdiff(0, ==, rv); - - rv = nghttp2_session_send(session); - - assert_ptrdiff(0, ==, rv); - - nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, NULL, 0); - rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - - assert_ptrdiff(0, ==, rv); - - nghttp2_frame_settings_free(&frame.settings, mem); - - buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - - assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); - assert_true(session->fallback_rfc7540_priorities); - - nghttp2_hd_deflate_init(&deflater, mem); - - nvlen = ARRLEN(reqnv); - nghttp2_nv_array_copy(&nva, reqnv, nvlen, mem); - nghttp2_priority_spec_init(&pri_spec, 3, 111, 1); - nghttp2_frame_headers_init(&frame.headers, - NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_PRIORITY, - 1, NGHTTP2_HCAT_HEADERS, &pri_spec, nva, nvlen); - nghttp2_bufs_reset(&bufs); - rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - - assert_ptrdiff(0, ==, rv); - - nghttp2_frame_headers_free(&frame.headers, mem); - - buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - - assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); - - anchor_stream = nghttp2_session_get_stream_raw(session, 3); - - assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, - anchor_stream->state); - assert_false(anchor_stream->flags & - NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES); - assert_ptr_equal(&session->root, anchor_stream->dep_prev); - - stream = nghttp2_session_get_stream(session, 1); - - assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); - assert_false(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES); - assert_ptr_equal(anchor_stream, stream->dep_prev); - - /* Make sure that PRIORITY frame updates stream priority. */ - nghttp2_priority_spec_init(&pri_spec, 5, 1, 0); - nghttp2_frame_priority_init(&frame.priority, 1, &pri_spec); - nghttp2_bufs_reset(&bufs); - nghttp2_frame_pack_priority(&bufs, &frame.priority); - - nghttp2_frame_priority_free(&frame.priority); - - buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - - assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); - - anchor_stream = nghttp2_session_get_stream_raw(session, 5); - - assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_IDLE, ==, - anchor_stream->state); - assert_ptr_equal(&session->root, anchor_stream->dep_prev); - assert_ptr_equal(anchor_stream, stream->dep_prev); - - /* Make sure that PRIORITY_UPDATE frame is ignored. */ - frame.ext.payload = &priority_update; - nghttp2_frame_priority_update_init(&frame.ext, 1, (uint8_t *)field_value, - sizeof(field_value) - 1); - nghttp2_bufs_reset(&bufs); - nghttp2_frame_pack_priority_update(&bufs, &frame.ext); - - ud.frame_recv_cb_called = 0; - buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - - assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); - assert_int(0, ==, ud.frame_recv_cb_called); - assert_uint32(NGHTTP2_EXTPRI_DEFAULT_URGENCY, ==, stream->extpri); - - nghttp2_hd_deflate_free(&deflater); - nghttp2_session_del(session); - - /* Server does not fallback to RFC 7540 priorities. */ - nghttp2_session_server_new2(&session, &callbacks, &ud, option); - - rv = nghttp2_submit_settings(session, NGHTTP2_FLAG_NONE, &iv, 1); - - assert_ptrdiff(0, ==, rv); - - rv = nghttp2_session_send(session); - - assert_ptrdiff(0, ==, rv); - - iv.settings_id = NGHTTP2_SETTINGS_NO_RFC7540_PRIORITIES; - iv.value = 0; - - nghttp2_frame_settings_init(&frame.settings, NGHTTP2_FLAG_NONE, - dup_iv(&iv, 1), 1); - nghttp2_bufs_reset(&bufs); - rv = nghttp2_frame_pack_settings(&bufs, &frame.settings); - - assert_ptrdiff(0, ==, rv); - - nghttp2_frame_settings_free(&frame.settings, mem); - - buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - - assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); - assert_false(session->fallback_rfc7540_priorities); - - nghttp2_hd_deflate_init(&deflater, mem); - - nvlen = ARRLEN(reqnv); - nghttp2_nv_array_copy(&nva, reqnv, nvlen, mem); - nghttp2_priority_spec_init(&pri_spec, 3, 111, 1); - nghttp2_frame_headers_init(&frame.headers, - NGHTTP2_FLAG_END_HEADERS | NGHTTP2_FLAG_PRIORITY, - 1, NGHTTP2_HCAT_HEADERS, &pri_spec, nva, nvlen); - nghttp2_bufs_reset(&bufs); - rv = nghttp2_frame_pack_headers(&bufs, &frame.headers, &deflater); - - assert_ptrdiff(0, ==, rv); - - nghttp2_frame_headers_free(&frame.headers, mem); - - buf = &bufs.head->buf; - rv = nghttp2_session_mem_recv2(session, buf->pos, nghttp2_buf_len(buf)); - - assert_ptrdiff((nghttp2_ssize)nghttp2_buf_len(buf), ==, rv); - assert_null(nghttp2_session_get_stream_raw(session, 3)); - - stream = nghttp2_session_get_stream(session, 1); - - assert_enum(nghttp2_stream_state, NGHTTP2_STREAM_OPENING, ==, stream->state); - assert_true(stream->flags & NGHTTP2_STREAM_FLAG_NO_RFC7540_PRIORITIES); - - nghttp2_hd_deflate_free(&deflater); - nghttp2_session_del(session); - - nghttp2_option_del(option); - nghttp2_bufs_free(&bufs); -} - void test_nghttp2_session_stream_reset_ratelim(void) { nghttp2_session *session; nghttp2_session_callbacks callbacks; diff --git a/tests/nghttp2_session_test.h b/tests/nghttp2_session_test.h index 89e85753..50061978 100644 --- a/tests/nghttp2_session_test.h +++ b/tests/nghttp2_session_test.h @@ -63,7 +63,6 @@ munit_void_test_decl(test_nghttp2_session_on_request_headers_received) munit_void_test_decl(test_nghttp2_session_on_response_headers_received) munit_void_test_decl(test_nghttp2_session_on_headers_received) munit_void_test_decl(test_nghttp2_session_on_push_response_headers_received) -munit_void_test_decl(test_nghttp2_session_on_priority_received) munit_void_test_decl(test_nghttp2_session_on_rst_stream_received) munit_void_test_decl(test_nghttp2_session_on_settings_received) munit_void_test_decl(test_nghttp2_session_on_push_promise_received) @@ -81,9 +80,6 @@ munit_void_test_decl(test_nghttp2_session_send_rst_stream) munit_void_test_decl(test_nghttp2_session_send_push_promise) munit_void_test_decl(test_nghttp2_session_is_my_stream_id) munit_void_test_decl(test_nghttp2_session_upgrade2) -munit_void_test_decl(test_nghttp2_session_reprioritize_stream) -munit_void_test_decl( - test_nghttp2_session_reprioritize_stream_with_idle_stream_dep) munit_void_test_decl(test_nghttp2_submit_data) munit_void_test_decl(test_nghttp2_submit_data_read_length_too_large) munit_void_test_decl(test_nghttp2_submit_data_read_length_smallest) @@ -100,7 +96,6 @@ munit_void_test_decl(test_nghttp2_submit_headers_push_reply) munit_void_test_decl(test_nghttp2_submit_headers) munit_void_test_decl(test_nghttp2_submit_headers_continuation) munit_void_test_decl(test_nghttp2_submit_headers_continuation_extra_large) -munit_void_test_decl(test_nghttp2_submit_priority) munit_void_test_decl(test_nghttp2_submit_settings) munit_void_test_decl(test_nghttp2_submit_settings_update_local_window_size) munit_void_test_decl(test_nghttp2_submit_settings_multiple_times) @@ -115,7 +110,6 @@ munit_void_test_decl(test_nghttp2_submit_origin) munit_void_test_decl(test_nghttp2_submit_priority_update) munit_void_test_decl(test_nghttp2_submit_rst_stream) munit_void_test_decl(test_nghttp2_session_open_stream) -munit_void_test_decl(test_nghttp2_session_open_stream_with_idle_stream_dep) munit_void_test_decl(test_nghttp2_session_get_next_ob_item) munit_void_test_decl(test_nghttp2_session_pop_next_ob_item) munit_void_test_decl(test_nghttp2_session_reply_fail) @@ -135,21 +129,8 @@ munit_void_test_decl(test_nghttp2_session_data_backoff_by_high_pri_frame) munit_void_test_decl(test_nghttp2_session_pack_data_with_padding) munit_void_test_decl(test_nghttp2_session_pack_headers_with_padding) munit_void_test_decl(test_nghttp2_pack_settings_payload) -munit_void_test_decl(test_nghttp2_session_stream_dep_add) -munit_void_test_decl(test_nghttp2_session_stream_dep_remove) -munit_void_test_decl(test_nghttp2_session_stream_dep_add_subtree) -munit_void_test_decl(test_nghttp2_session_stream_dep_remove_subtree) -munit_void_test_decl( - test_nghttp2_session_stream_dep_all_your_stream_are_belong_to_us) -munit_void_test_decl(test_nghttp2_session_stream_attach_item) -munit_void_test_decl(test_nghttp2_session_stream_attach_item_subtree) munit_void_test_decl(test_nghttp2_session_stream_get_state) -munit_void_test_decl(test_nghttp2_session_stream_get_something) munit_void_test_decl(test_nghttp2_session_find_stream) -munit_void_test_decl(test_nghttp2_session_keep_closed_stream) -munit_void_test_decl(test_nghttp2_session_keep_idle_stream) -munit_void_test_decl(test_nghttp2_session_detach_idle_stream) -munit_void_test_decl(test_nghttp2_session_large_dep_tree) munit_void_test_decl(test_nghttp2_session_graceful_shutdown) munit_void_test_decl(test_nghttp2_session_on_header_temporal_failure) munit_void_test_decl(test_nghttp2_session_recv_client_magic) @@ -162,11 +143,7 @@ munit_void_test_decl(test_nghttp2_session_on_begin_headers_temporal_failure) munit_void_test_decl(test_nghttp2_session_defer_then_close) munit_void_test_decl(test_nghttp2_session_detach_item_from_closed_stream) munit_void_test_decl(test_nghttp2_session_flooding) -munit_void_test_decl(test_nghttp2_session_change_stream_priority) munit_void_test_decl(test_nghttp2_session_change_extpri_stream_priority) -munit_void_test_decl(test_nghttp2_session_create_idle_stream) -munit_void_test_decl(test_nghttp2_session_repeated_priority_change) -munit_void_test_decl(test_nghttp2_session_repeated_priority_submission) munit_void_test_decl(test_nghttp2_session_set_local_window_size) munit_void_test_decl(test_nghttp2_session_cancel_from_before_frame_send) munit_void_test_decl(test_nghttp2_session_too_many_settings) @@ -175,7 +152,6 @@ munit_void_test_decl(test_nghttp2_session_pause_data) munit_void_test_decl(test_nghttp2_session_no_closed_streams) munit_void_test_decl(test_nghttp2_session_set_stream_user_data) munit_void_test_decl(test_nghttp2_session_no_rfc7540_priorities) -munit_void_test_decl(test_nghttp2_session_server_fallback_rfc7540_priorities) munit_void_test_decl(test_nghttp2_session_stream_reset_ratelim) munit_void_test_decl(test_nghttp2_http_mandatory_headers) munit_void_test_decl(test_nghttp2_http_content_length) diff --git a/tests/nghttp2_test_helper.c b/tests/nghttp2_test_helper.c index 54acd294..ed9861ad 100644 --- a/tests/nghttp2_test_helper.c +++ b/tests/nghttp2_test_helper.c @@ -260,49 +260,9 @@ void bufs_large_init(nghttp2_bufs *bufs, size_t chunk_size) { nghttp2_mem_default()); } -static nghttp2_stream *open_stream_with_all(nghttp2_session *session, - int32_t stream_id, int32_t weight, - uint8_t exclusive, - nghttp2_stream *dep_stream) { - nghttp2_priority_spec pri_spec; - int32_t dep_stream_id; - - if (dep_stream) { - dep_stream_id = dep_stream->stream_id; - } else { - dep_stream_id = 0; - } - - nghttp2_priority_spec_init(&pri_spec, dep_stream_id, weight, exclusive); - - return nghttp2_session_open_stream(session, stream_id, - NGHTTP2_STREAM_FLAG_NONE, &pri_spec, - NGHTTP2_STREAM_OPENED, NULL); -} - nghttp2_stream *open_stream(nghttp2_session *session, int32_t stream_id) { - return open_stream_with_all(session, stream_id, NGHTTP2_DEFAULT_WEIGHT, 0, - NULL); -} - -nghttp2_stream *open_stream_with_dep(nghttp2_session *session, - int32_t stream_id, - nghttp2_stream *dep_stream) { - return open_stream_with_all(session, stream_id, NGHTTP2_DEFAULT_WEIGHT, 0, - dep_stream); -} - -nghttp2_stream *open_stream_with_dep_weight(nghttp2_session *session, - int32_t stream_id, int32_t weight, - nghttp2_stream *dep_stream) { - return open_stream_with_all(session, stream_id, weight, 0, dep_stream); -} - -nghttp2_stream *open_stream_with_dep_excl(nghttp2_session *session, - int32_t stream_id, - nghttp2_stream *dep_stream) { - return open_stream_with_all(session, stream_id, NGHTTP2_DEFAULT_WEIGHT, 1, - dep_stream); + return nghttp2_session_open_stream( + session, stream_id, NGHTTP2_STREAM_FLAG_NONE, NGHTTP2_STREAM_OPENED, NULL); } nghttp2_outbound_item *create_data_ob_item(nghttp2_mem *mem) { @@ -315,58 +275,26 @@ nghttp2_outbound_item *create_data_ob_item(nghttp2_mem *mem) { } nghttp2_stream *open_sent_stream(nghttp2_session *session, int32_t stream_id) { - nghttp2_priority_spec pri_spec; - - nghttp2_priority_spec_init(&pri_spec, 0, NGHTTP2_DEFAULT_WEIGHT, 0); - return open_sent_stream3(session, stream_id, NGHTTP2_FLAG_NONE, &pri_spec, + return open_sent_stream3(session, stream_id, NGHTTP2_FLAG_NONE, NGHTTP2_STREAM_OPENED, NULL); } nghttp2_stream *open_sent_stream2(nghttp2_session *session, int32_t stream_id, nghttp2_stream_state initial_state) { - nghttp2_priority_spec pri_spec; - - nghttp2_priority_spec_init(&pri_spec, 0, NGHTTP2_DEFAULT_WEIGHT, 0); - return open_sent_stream3(session, stream_id, NGHTTP2_FLAG_NONE, &pri_spec, - initial_state, NULL); + return open_sent_stream3(session, stream_id, NGHTTP2_FLAG_NONE, initial_state, + NULL); } nghttp2_stream *open_sent_stream3(nghttp2_session *session, int32_t stream_id, uint8_t flags, - nghttp2_priority_spec *pri_spec_in, nghttp2_stream_state initial_state, void *stream_user_data) { nghttp2_stream *stream; assert(nghttp2_session_is_my_stream_id(session, stream_id)); - stream = nghttp2_session_open_stream(session, stream_id, flags, pri_spec_in, - initial_state, stream_user_data); - session->last_sent_stream_id = - nghttp2_max_int32(session->last_sent_stream_id, stream_id); - session->next_stream_id = - nghttp2_max_uint32(session->next_stream_id, (uint32_t)stream_id + 2); - - return stream; -} - -nghttp2_stream *open_sent_stream_with_dep(nghttp2_session *session, - int32_t stream_id, - nghttp2_stream *dep_stream) { - return open_sent_stream_with_dep_weight(session, stream_id, - NGHTTP2_DEFAULT_WEIGHT, dep_stream); -} - -nghttp2_stream *open_sent_stream_with_dep_weight(nghttp2_session *session, - int32_t stream_id, - int32_t weight, - nghttp2_stream *dep_stream) { - nghttp2_stream *stream; - - assert(nghttp2_session_is_my_stream_id(session, stream_id)); - - stream = open_stream_with_all(session, stream_id, weight, 0, dep_stream); - + stream = nghttp2_session_open_stream(session, stream_id, flags, initial_state, + stream_user_data); session->last_sent_stream_id = nghttp2_max_int32(session->last_sent_stream_id, stream_id); session->next_stream_id = @@ -376,56 +304,26 @@ nghttp2_stream *open_sent_stream_with_dep_weight(nghttp2_session *session, } nghttp2_stream *open_recv_stream(nghttp2_session *session, int32_t stream_id) { - nghttp2_priority_spec pri_spec; - - nghttp2_priority_spec_init(&pri_spec, 0, NGHTTP2_DEFAULT_WEIGHT, 0); - return open_recv_stream3(session, stream_id, NGHTTP2_FLAG_NONE, &pri_spec, + return open_recv_stream3(session, stream_id, NGHTTP2_FLAG_NONE, NGHTTP2_STREAM_OPENED, NULL); } nghttp2_stream *open_recv_stream2(nghttp2_session *session, int32_t stream_id, nghttp2_stream_state initial_state) { - nghttp2_priority_spec pri_spec; - - nghttp2_priority_spec_init(&pri_spec, 0, NGHTTP2_DEFAULT_WEIGHT, 0); - return open_recv_stream3(session, stream_id, NGHTTP2_FLAG_NONE, &pri_spec, - initial_state, NULL); + return open_recv_stream3(session, stream_id, NGHTTP2_FLAG_NONE, initial_state, + NULL); } nghttp2_stream *open_recv_stream3(nghttp2_session *session, int32_t stream_id, uint8_t flags, - nghttp2_priority_spec *pri_spec_in, nghttp2_stream_state initial_state, void *stream_user_data) { nghttp2_stream *stream; assert(!nghttp2_session_is_my_stream_id(session, stream_id)); - stream = nghttp2_session_open_stream(session, stream_id, flags, pri_spec_in, - initial_state, stream_user_data); - session->last_recv_stream_id = - nghttp2_max_int32(session->last_recv_stream_id, stream_id); - - return stream; -} - -nghttp2_stream *open_recv_stream_with_dep(nghttp2_session *session, - int32_t stream_id, - nghttp2_stream *dep_stream) { - return open_recv_stream_with_dep_weight(session, stream_id, - NGHTTP2_DEFAULT_WEIGHT, dep_stream); -} - -nghttp2_stream *open_recv_stream_with_dep_weight(nghttp2_session *session, - int32_t stream_id, - int32_t weight, - nghttp2_stream *dep_stream) { - nghttp2_stream *stream; - - assert(!nghttp2_session_is_my_stream_id(session, stream_id)); - - stream = open_stream_with_all(session, stream_id, weight, 0, dep_stream); - + stream = nghttp2_session_open_stream(session, stream_id, flags, initial_state, + stream_user_data); session->last_recv_stream_id = nghttp2_max_int32(session->last_recv_stream_id, stream_id); diff --git a/tests/nghttp2_test_helper.h b/tests/nghttp2_test_helper.h index 5ef0c8aa..e5e87899 100644 --- a/tests/nghttp2_test_helper.h +++ b/tests/nghttp2_test_helper.h @@ -78,18 +78,6 @@ void bufs_large_init(nghttp2_bufs *bufs, size_t chunk_size); nghttp2_stream *open_stream(nghttp2_session *session, int32_t stream_id); -nghttp2_stream *open_stream_with_dep(nghttp2_session *session, - int32_t stream_id, - nghttp2_stream *dep_stream); - -nghttp2_stream *open_stream_with_dep_weight(nghttp2_session *session, - int32_t stream_id, int32_t weight, - nghttp2_stream *dep_stream); - -nghttp2_stream *open_stream_with_dep_excl(nghttp2_session *session, - int32_t stream_id, - nghttp2_stream *dep_stream); - nghttp2_outbound_item *create_data_ob_item(nghttp2_mem *mem); /* Opens stream. This stream is assumed to be sent from |session|, @@ -102,19 +90,9 @@ nghttp2_stream *open_sent_stream2(nghttp2_session *session, int32_t stream_id, nghttp2_stream *open_sent_stream3(nghttp2_session *session, int32_t stream_id, uint8_t flags, - nghttp2_priority_spec *pri_spec_in, nghttp2_stream_state initial_state, void *stream_user_data); -nghttp2_stream *open_sent_stream_with_dep(nghttp2_session *session, - int32_t stream_id, - nghttp2_stream *dep_stream); - -nghttp2_stream *open_sent_stream_with_dep_weight(nghttp2_session *session, - int32_t stream_id, - int32_t weight, - nghttp2_stream *dep_stream); - /* Opens stream. This stream is assumed to be received by |session|, and session->last_recv_stream_id will be adjusted accordingly. */ nghttp2_stream *open_recv_stream(nghttp2_session *session, int32_t stream_id); @@ -124,17 +102,7 @@ nghttp2_stream *open_recv_stream2(nghttp2_session *session, int32_t stream_id, nghttp2_stream *open_recv_stream3(nghttp2_session *session, int32_t stream_id, uint8_t flags, - nghttp2_priority_spec *pri_spec_in, nghttp2_stream_state initial_state, void *stream_user_data); -nghttp2_stream *open_recv_stream_with_dep(nghttp2_session *session, - int32_t stream_id, - nghttp2_stream *dep_stream); - -nghttp2_stream *open_recv_stream_with_dep_weight(nghttp2_session *session, - int32_t stream_id, - int32_t weight, - nghttp2_stream *dep_stream); - #endif /* NGHTTP2_TEST_HELPER_H */