From ab0f2ace36a116f1e905c17e61904cc48abd76c2 Mon Sep 17 00:00:00 2001 From: gengjiawen Date: Sat, 30 Mar 2019 00:22:54 +0800 Subject: [PATCH] deps: update nghttp2 to 1.37.0 Backport-PR-URL: https://github.com/nodejs/node/pull/29123 PR-URL: https://github.com/nodejs/node/pull/26990 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Matteo Collina --- deps/nghttp2/lib/CMakeLists.txt | 25 +++++++------ deps/nghttp2/lib/includes/nghttp2/nghttp2.h | 8 ++++- .../nghttp2/lib/includes/nghttp2/nghttp2ver.h | 4 +-- deps/nghttp2/lib/nghttp2_hd.c | 2 +- deps/nghttp2/lib/nghttp2_session.h | 3 -- deps/nghttp2/lib/nghttp2_stream.c | 35 +++++++++---------- deps/nghttp2/lib/nghttp2_stream.h | 4 +-- 7 files changed, 43 insertions(+), 38 deletions(-) diff --git a/deps/nghttp2/lib/CMakeLists.txt b/deps/nghttp2/lib/CMakeLists.txt index 17e422b22db790..c27ee99bb7fa46 100644 --- a/deps/nghttp2/lib/CMakeLists.txt +++ b/deps/nghttp2/lib/CMakeLists.txt @@ -38,16 +38,23 @@ if(WIN32) endif() # Public shared library -add_library(nghttp2 SHARED ${NGHTTP2_SOURCES} ${NGHTTP2_RES}) -set_target_properties(nghttp2 PROPERTIES - COMPILE_FLAGS "${WARNCFLAGS}" - VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION} - C_VISIBILITY_PRESET hidden -) -target_include_directories(nghttp2 INTERFACE +if(ENABLE_SHARED_LIB) + add_library(nghttp2 SHARED ${NGHTTP2_SOURCES} ${NGHTTP2_RES}) + set_target_properties(nghttp2 PROPERTIES + COMPILE_FLAGS "${WARNCFLAGS}" + VERSION ${LT_VERSION} SOVERSION ${LT_SOVERSION} + C_VISIBILITY_PRESET hidden + ) + target_include_directories(nghttp2 INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/includes" "${CMAKE_CURRENT_SOURCE_DIR}/includes" - ) + ) + + install(TARGETS nghttp2 + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") +endif() if(HAVE_CUNIT OR ENABLE_STATIC_LIB) # Static library (for unittests because of symbol visibility) @@ -64,8 +71,6 @@ if(HAVE_CUNIT OR ENABLE_STATIC_LIB) endif() endif() -install(TARGETS nghttp2 - DESTINATION "${CMAKE_INSTALL_LIBDIR}") install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libnghttp2.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") diff --git a/deps/nghttp2/lib/includes/nghttp2/nghttp2.h b/deps/nghttp2/lib/includes/nghttp2/nghttp2.h index e7198b3d27314d..925a4cbcaf6d6a 100644 --- a/deps/nghttp2/lib/includes/nghttp2/nghttp2.h +++ b/deps/nghttp2/lib/includes/nghttp2/nghttp2.h @@ -31,6 +31,11 @@ # define WIN32 #endif +/* Compatibility for non-Clang compilers */ +#ifndef __has_declspec_attribute +# define __has_declspec_attribute(x) 0 +#endif + #ifdef __cplusplus extern "C" { #endif @@ -51,7 +56,8 @@ extern "C" { #ifdef NGHTTP2_STATICLIB # define NGHTTP2_EXTERN -#elif defined(WIN32) +#elif defined(WIN32) || (__has_declspec_attribute(dllexport) && \ + __has_declspec_attribute(dllimport)) # ifdef BUILDING_NGHTTP2 # define NGHTTP2_EXTERN __declspec(dllexport) # else /* !BUILDING_NGHTTP2 */ diff --git a/deps/nghttp2/lib/includes/nghttp2/nghttp2ver.h b/deps/nghttp2/lib/includes/nghttp2/nghttp2ver.h index 420adbd53dddce..2384f5278773cb 100644 --- a/deps/nghttp2/lib/includes/nghttp2/nghttp2ver.h +++ b/deps/nghttp2/lib/includes/nghttp2/nghttp2ver.h @@ -29,7 +29,7 @@ * @macro * Version number of the nghttp2 library release */ -#define NGHTTP2_VERSION "1.34.0" +#define NGHTTP2_VERSION "1.37.0" /** * @macro @@ -37,6 +37,6 @@ * release. This is a 24 bit number with 8 bits for major number, 8 bits * for minor and 8 bits for patch. Version 1.2.3 becomes 0x010203. */ -#define NGHTTP2_VERSION_NUM 0x012200 +#define NGHTTP2_VERSION_NUM 0x012500 #endif /* NGHTTP2VER_H */ diff --git a/deps/nghttp2/lib/nghttp2_hd.c b/deps/nghttp2/lib/nghttp2_hd.c index a61f0d47a6f79d..11ca3345f3c6b3 100644 --- a/deps/nghttp2/lib/nghttp2_hd.c +++ b/deps/nghttp2/lib/nghttp2_hd.c @@ -1390,7 +1390,7 @@ static int deflate_nv(nghttp2_hd_deflater *deflater, nghttp2_bufs *bufs, if (indexing_mode == NGHTTP2_HD_WITH_INDEXING) { nghttp2_hd_nv hd_nv; - if (idx != -1 && idx < (ssize_t)NGHTTP2_STATIC_TABLE_LENGTH) { + if (idx != -1) { hd_nv.name = nghttp2_hd_table_get(&deflater->ctx, (size_t)idx).name; nghttp2_rcbuf_incref(hd_nv.name); } else { diff --git a/deps/nghttp2/lib/nghttp2_session.h b/deps/nghttp2/lib/nghttp2_session.h index 40a8865a04b12f..bd7a5b35817599 100644 --- a/deps/nghttp2/lib/nghttp2_session.h +++ b/deps/nghttp2/lib/nghttp2_session.h @@ -209,9 +209,6 @@ struct nghttp2_session { nghttp2_session_callbacks callbacks; /* Memory allocator */ nghttp2_mem mem; - /* Base value when we schedule next DATA frame write. This is - updated when one frame was written. */ - uint64_t last_cycle; void *user_data; /* Points to the latest incoming closed stream. NULL if there is no closed stream. Only used when session is initialized as diff --git a/deps/nghttp2/lib/nghttp2_stream.c b/deps/nghttp2/lib/nghttp2_stream.c index eccd3174ef7bda..dc3a6b11ccbf75 100644 --- a/deps/nghttp2/lib/nghttp2_stream.c +++ b/deps/nghttp2/lib/nghttp2_stream.c @@ -30,6 +30,7 @@ #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 prirority queue. Imagine stream A's cycle is A, and stream B's @@ -40,7 +41,8 @@ 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 (16384 * 256 + 255) +#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; @@ -52,11 +54,7 @@ static int stream_less(const void *lhsx, const void *rhsx) { return lhs->seq < rhs->seq; } - if (lhs->cycle < rhs->cycle) { - return rhs->cycle - lhs->cycle <= NGHTTP2_MAX_CYCLE_DISTANCE; - } - - return lhs->cycle - rhs->cycle > NGHTTP2_MAX_CYCLE_DISTANCE; + return rhs->cycle - lhs->cycle <= NGHTTP2_MAX_CYCLE_DISTANCE; } void nghttp2_stream_init(nghttp2_stream *stream, int32_t stream_id, @@ -135,14 +133,14 @@ static int stream_subtree_active(nghttp2_stream *stream) { /* * Returns next cycle for |stream|. */ -static void stream_next_cycle(nghttp2_stream *stream, uint32_t last_cycle) { - uint32_t penalty; +static void stream_next_cycle(nghttp2_stream *stream, uint64_t last_cycle) { + uint64_t penalty; - penalty = (uint32_t)stream->last_writelen * NGHTTP2_MAX_WEIGHT + + penalty = (uint64_t)stream->last_writelen * NGHTTP2_MAX_WEIGHT + stream->pending_penalty; stream->cycle = last_cycle + penalty / (uint32_t)stream->weight; - stream->pending_penalty = 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) { @@ -153,7 +151,7 @@ static int stream_obq_push(nghttp2_stream *dep_stream, nghttp2_stream *stream) { stream_next_cycle(stream, dep_stream->descendant_last_cycle); stream->seq = dep_stream->descendant_next_seq++; - DEBUGF("stream: stream=%d obq push cycle=%d\n", stream->stream_id, + 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, @@ -239,7 +237,7 @@ void nghttp2_stream_reschedule(nghttp2_stream *stream) { nghttp2_pq_push(&dep_stream->obq, &stream->pq_entry); - DEBUGF("stream: stream=%d obq resched cycle=%d\n", stream->stream_id, + DEBUGF("stream: stream=%d obq resched cycle=%lu\n", stream->stream_id, stream->cycle); dep_stream->last_writelen = stream->last_writelen; @@ -248,9 +246,9 @@ void nghttp2_stream_reschedule(nghttp2_stream *stream) { void nghttp2_stream_change_weight(nghttp2_stream *stream, int32_t weight) { nghttp2_stream *dep_stream; - uint32_t last_cycle; + uint64_t last_cycle; int32_t old_weight; - uint32_t wlen_penalty; + uint64_t wlen_penalty; if (stream->weight == weight) { return; @@ -273,7 +271,7 @@ void nghttp2_stream_change_weight(nghttp2_stream *stream, int32_t weight) { nghttp2_pq_remove(&dep_stream->obq, &stream->pq_entry); - wlen_penalty = (uint32_t)stream->last_writelen * NGHTTP2_MAX_WEIGHT; + wlen_penalty = (uint64_t)stream->last_writelen * NGHTTP2_MAX_WEIGHT; /* Compute old stream->pending_penalty we used to calculate stream->cycle */ @@ -289,9 +287,8 @@ void nghttp2_stream_change_weight(nghttp2_stream *stream, int32_t weight) { place */ stream_next_cycle(stream, last_cycle); - if (stream->cycle < dep_stream->descendant_last_cycle && - (dep_stream->descendant_last_cycle - stream->cycle) <= - NGHTTP2_MAX_CYCLE_DISTANCE) { + if (dep_stream->descendant_last_cycle - stream->cycle <= + NGHTTP2_MAX_CYCLE_DISTANCE) { stream->cycle = dep_stream->descendant_last_cycle; } @@ -299,7 +296,7 @@ void nghttp2_stream_change_weight(nghttp2_stream *stream, int32_t weight) { nghttp2_pq_push(&dep_stream->obq, &stream->pq_entry); - DEBUGF("stream: stream=%d obq resched cycle=%d\n", stream->stream_id, + DEBUGF("stream: stream=%d obq resched cycle=%lu\n", stream->stream_id, stream->cycle); } diff --git a/deps/nghttp2/lib/nghttp2_stream.h b/deps/nghttp2/lib/nghttp2_stream.h index fb8dc14d67be6d..a1b807d295c05c 100644 --- a/deps/nghttp2/lib/nghttp2_stream.h +++ b/deps/nghttp2/lib/nghttp2_stream.h @@ -148,9 +148,9 @@ struct nghttp2_stream { /* Received body so far */ int64_t recv_content_length; /* Base last_cycle for direct descendent streams. */ - uint32_t descendant_last_cycle; + uint64_t descendant_last_cycle; /* Next scheduled time to sent item */ - uint32_t cycle; + 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