Skip to content

Commit 037ed4f

Browse files
committed
deps: update nghttp2 to 1.57.0
1 parent 78a1570 commit 037ed4f

15 files changed

+335
-11
lines changed

deps/nghttp2/lib/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ set(NGHTTP2_SOURCES
2424
nghttp2_http.c
2525
nghttp2_rcbuf.c
2626
nghttp2_extpri.c
27+
nghttp2_ratelim.c
28+
nghttp2_time.c
2729
nghttp2_debug.c
2830
sfparse.c
2931
)

deps/nghttp2/lib/Makefile.am

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ OBJECTS = nghttp2_pq.c nghttp2_map.c nghttp2_queue.c \
5151
nghttp2_http.c \
5252
nghttp2_rcbuf.c \
5353
nghttp2_extpri.c \
54+
nghttp2_ratelim.c \
55+
nghttp2_time.c \
5456
nghttp2_debug.c \
5557
sfparse.c
5658

@@ -69,6 +71,8 @@ HFILES = nghttp2_pq.h nghttp2_int.h nghttp2_map.h nghttp2_queue.h \
6971
nghttp2_http.h \
7072
nghttp2_rcbuf.h \
7173
nghttp2_extpri.h \
74+
nghttp2_ratelim.h \
75+
nghttp2_time.h \
7276
nghttp2_debug.h \
7377
sfparse.h
7478

deps/nghttp2/lib/Makefile.in

+16-4
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ am__objects_2 = nghttp2_pq.lo nghttp2_map.lo nghttp2_queue.lo \
157157
nghttp2_hd_huffman.lo nghttp2_hd_huffman_data.lo \
158158
nghttp2_version.lo nghttp2_priority_spec.lo nghttp2_option.lo \
159159
nghttp2_callbacks.lo nghttp2_mem.lo nghttp2_http.lo \
160-
nghttp2_rcbuf.lo nghttp2_extpri.lo nghttp2_debug.lo sfparse.lo
160+
nghttp2_rcbuf.lo nghttp2_extpri.lo nghttp2_ratelim.lo \
161+
nghttp2_time.lo nghttp2_debug.lo sfparse.lo
161162
am_libnghttp2_la_OBJECTS = $(am__objects_1) $(am__objects_2)
162163
libnghttp2_la_OBJECTS = $(am_libnghttp2_la_OBJECTS)
163164
AM_V_lt = $(am__v_lt_@AM_V@)
@@ -194,9 +195,10 @@ am__depfiles_remade = ./$(DEPDIR)/nghttp2_buf.Plo \
194195
./$(DEPDIR)/nghttp2_outbound_item.Plo \
195196
./$(DEPDIR)/nghttp2_pq.Plo \
196197
./$(DEPDIR)/nghttp2_priority_spec.Plo \
197-
./$(DEPDIR)/nghttp2_queue.Plo ./$(DEPDIR)/nghttp2_rcbuf.Plo \
198-
./$(DEPDIR)/nghttp2_session.Plo ./$(DEPDIR)/nghttp2_stream.Plo \
199-
./$(DEPDIR)/nghttp2_submit.Plo ./$(DEPDIR)/nghttp2_version.Plo \
198+
./$(DEPDIR)/nghttp2_queue.Plo ./$(DEPDIR)/nghttp2_ratelim.Plo \
199+
./$(DEPDIR)/nghttp2_rcbuf.Plo ./$(DEPDIR)/nghttp2_session.Plo \
200+
./$(DEPDIR)/nghttp2_stream.Plo ./$(DEPDIR)/nghttp2_submit.Plo \
201+
./$(DEPDIR)/nghttp2_time.Plo ./$(DEPDIR)/nghttp2_version.Plo \
200202
./$(DEPDIR)/sfparse.Plo
201203
am__mv = mv -f
202204
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
@@ -510,6 +512,8 @@ OBJECTS = nghttp2_pq.c nghttp2_map.c nghttp2_queue.c \
510512
nghttp2_http.c \
511513
nghttp2_rcbuf.c \
512514
nghttp2_extpri.c \
515+
nghttp2_ratelim.c \
516+
nghttp2_time.c \
513517
nghttp2_debug.c \
514518
sfparse.c
515519

@@ -528,6 +532,8 @@ HFILES = nghttp2_pq.h nghttp2_int.h nghttp2_map.h nghttp2_queue.h \
528532
nghttp2_http.h \
529533
nghttp2_rcbuf.h \
530534
nghttp2_extpri.h \
535+
nghttp2_ratelim.h \
536+
nghttp2_time.h \
531537
nghttp2_debug.h \
532538
sfparse.h
533539

@@ -633,10 +639,12 @@ distclean-compile:
633639
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_pq.Plo@am__quote@ # am--include-marker
634640
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_priority_spec.Plo@am__quote@ # am--include-marker
635641
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_queue.Plo@am__quote@ # am--include-marker
642+
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_ratelim.Plo@am__quote@ # am--include-marker
636643
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_rcbuf.Plo@am__quote@ # am--include-marker
637644
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_session.Plo@am__quote@ # am--include-marker
638645
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_stream.Plo@am__quote@ # am--include-marker
639646
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_submit.Plo@am__quote@ # am--include-marker
647+
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_time.Plo@am__quote@ # am--include-marker
640648
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nghttp2_version.Plo@am__quote@ # am--include-marker
641649
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sfparse.Plo@am__quote@ # am--include-marker
642650

@@ -916,10 +924,12 @@ distclean: distclean-recursive
916924
-rm -f ./$(DEPDIR)/nghttp2_pq.Plo
917925
-rm -f ./$(DEPDIR)/nghttp2_priority_spec.Plo
918926
-rm -f ./$(DEPDIR)/nghttp2_queue.Plo
927+
-rm -f ./$(DEPDIR)/nghttp2_ratelim.Plo
919928
-rm -f ./$(DEPDIR)/nghttp2_rcbuf.Plo
920929
-rm -f ./$(DEPDIR)/nghttp2_session.Plo
921930
-rm -f ./$(DEPDIR)/nghttp2_stream.Plo
922931
-rm -f ./$(DEPDIR)/nghttp2_submit.Plo
932+
-rm -f ./$(DEPDIR)/nghttp2_time.Plo
923933
-rm -f ./$(DEPDIR)/nghttp2_version.Plo
924934
-rm -f ./$(DEPDIR)/sfparse.Plo
925935
-rm -f Makefile
@@ -985,10 +995,12 @@ maintainer-clean: maintainer-clean-recursive
985995
-rm -f ./$(DEPDIR)/nghttp2_pq.Plo
986996
-rm -f ./$(DEPDIR)/nghttp2_priority_spec.Plo
987997
-rm -f ./$(DEPDIR)/nghttp2_queue.Plo
998+
-rm -f ./$(DEPDIR)/nghttp2_ratelim.Plo
988999
-rm -f ./$(DEPDIR)/nghttp2_rcbuf.Plo
9891000
-rm -f ./$(DEPDIR)/nghttp2_session.Plo
9901001
-rm -f ./$(DEPDIR)/nghttp2_stream.Plo
9911002
-rm -f ./$(DEPDIR)/nghttp2_submit.Plo
1003+
-rm -f ./$(DEPDIR)/nghttp2_time.Plo
9921004
-rm -f ./$(DEPDIR)/nghttp2_version.Plo
9931005
-rm -f ./$(DEPDIR)/sfparse.Plo
9941006
-rm -f Makefile

deps/nghttp2/lib/includes/nghttp2/nghttp2.h

+17
Original file line numberDiff line numberDiff line change
@@ -2756,6 +2756,23 @@ NGHTTP2_EXTERN void
27562756
nghttp2_option_set_no_rfc9113_leading_and_trailing_ws_validation(
27572757
nghttp2_option *option, int val);
27582758

2759+
/**
2760+
* @function
2761+
*
2762+
* This function sets the rate limit for the incoming stream reset
2763+
* (RST_STREAM frame). It is server use only. It is a token-bucket
2764+
* based rate limiter. |burst| specifies the number of tokens that is
2765+
* initially available. The maximum number of tokens is capped to
2766+
* this value. |rate| specifies the number of tokens that are
2767+
* regenerated per second. An incoming RST_STREAM consumes one token.
2768+
* If there is no token available, GOAWAY is sent to tear down the
2769+
* connection. |burst| and |rate| default to 1000 and 33
2770+
* respectively.
2771+
*/
2772+
NGHTTP2_EXTERN void
2773+
nghttp2_option_set_stream_reset_rate_limit(nghttp2_option *option,
2774+
uint64_t burst, uint64_t rate);
2775+
27592776
/**
27602777
* @function
27612778
*

deps/nghttp2/lib/includes/nghttp2/nghttp2ver.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@
2929
* @macro
3030
* Version number of the nghttp2 library release
3131
*/
32-
#define NGHTTP2_VERSION "1.56.0"
32+
#define NGHTTP2_VERSION "1.57.0"
3333

3434
/**
3535
* @macro
3636
* Numerical representation of the version number of the nghttp2 library
3737
* release. This is a 24 bit number with 8 bits for major number, 8 bits
3838
* for minor and 8 bits for patch. Version 1.2.3 becomes 0x010203.
3939
*/
40-
#define NGHTTP2_VERSION_NUM 0x013800
40+
#define NGHTTP2_VERSION_NUM 0x013900
4141

4242
#endif /* NGHTTP2VER_H */

deps/nghttp2/lib/nghttp2_option.c

+7
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,10 @@ void nghttp2_option_set_no_rfc9113_leading_and_trailing_ws_validation(
143143
NGHTTP2_OPT_NO_RFC9113_LEADING_AND_TRAILING_WS_VALIDATION;
144144
option->no_rfc9113_leading_and_trailing_ws_validation = val;
145145
}
146+
147+
void nghttp2_option_set_stream_reset_rate_limit(nghttp2_option *option,
148+
uint64_t burst, uint64_t rate) {
149+
option->opt_set_mask |= NGHTTP2_OPT_STREAM_RESET_RATE_LIMIT;
150+
option->stream_reset_burst = burst;
151+
option->stream_reset_rate = rate;
152+
}

deps/nghttp2/lib/nghttp2_option.h

+6
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,18 @@ typedef enum {
7070
NGHTTP2_OPT_MAX_SETTINGS = 1 << 12,
7171
NGHTTP2_OPT_SERVER_FALLBACK_RFC7540_PRIORITIES = 1 << 13,
7272
NGHTTP2_OPT_NO_RFC9113_LEADING_AND_TRAILING_WS_VALIDATION = 1 << 14,
73+
NGHTTP2_OPT_STREAM_RESET_RATE_LIMIT = 1 << 15,
7374
} nghttp2_option_flag;
7475

7576
/**
7677
* Struct to store option values for nghttp2_session.
7778
*/
7879
struct nghttp2_option {
80+
/**
81+
* NGHTTP2_OPT_STREAM_RESET_RATE_LIMIT
82+
*/
83+
uint64_t stream_reset_burst;
84+
uint64_t stream_reset_rate;
7985
/**
8086
* NGHTTP2_OPT_MAX_SEND_HEADER_BLOCK_LENGTH
8187
*/

deps/nghttp2/lib/nghttp2_ratelim.c

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* nghttp2 - HTTP/2 C Library
3+
*
4+
* Copyright (c) 2023 nghttp2 contributors
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining
7+
* a copy of this software and associated documentation files (the
8+
* "Software"), to deal in the Software without restriction, including
9+
* without limitation the rights to use, copy, modify, merge, publish,
10+
* distribute, sublicense, and/or sell copies of the Software, and to
11+
* permit persons to whom the Software is furnished to do so, subject to
12+
* the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be
15+
* included in all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
#include "nghttp2_ratelim.h"
26+
#include "nghttp2_helper.h"
27+
28+
void nghttp2_ratelim_init(nghttp2_ratelim *rl, uint64_t burst, uint64_t rate) {
29+
rl->val = rl->burst = burst;
30+
rl->rate = rate;
31+
rl->tstamp = 0;
32+
}
33+
34+
void nghttp2_ratelim_update(nghttp2_ratelim *rl, uint64_t tstamp) {
35+
uint64_t d, gain;
36+
37+
if (tstamp == rl->tstamp) {
38+
return;
39+
}
40+
41+
if (tstamp > rl->tstamp) {
42+
d = tstamp - rl->tstamp;
43+
} else {
44+
d = 1;
45+
}
46+
47+
rl->tstamp = tstamp;
48+
49+
if (UINT64_MAX / d < rl->rate) {
50+
rl->val = rl->burst;
51+
52+
return;
53+
}
54+
55+
gain = rl->rate * d;
56+
57+
if (UINT64_MAX - gain < rl->val) {
58+
rl->val = rl->burst;
59+
60+
return;
61+
}
62+
63+
rl->val += gain;
64+
rl->val = nghttp2_min(rl->val, rl->burst);
65+
}
66+
67+
int nghttp2_ratelim_drain(nghttp2_ratelim *rl, uint64_t n) {
68+
if (rl->val < n) {
69+
return -1;
70+
}
71+
72+
rl->val -= n;
73+
74+
return 0;
75+
}

deps/nghttp2/lib/nghttp2_ratelim.h

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* nghttp2 - HTTP/2 C Library
3+
*
4+
* Copyright (c) 2023 nghttp2 contributors
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining
7+
* a copy of this software and associated documentation files (the
8+
* "Software"), to deal in the Software without restriction, including
9+
* without limitation the rights to use, copy, modify, merge, publish,
10+
* distribute, sublicense, and/or sell copies of the Software, and to
11+
* permit persons to whom the Software is furnished to do so, subject to
12+
* the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be
15+
* included in all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
#ifndef NGHTTP2_RATELIM_H
26+
#define NGHTTP2_RATELIM_H
27+
28+
#ifdef HAVE_CONFIG_H
29+
# include <config.h>
30+
#endif /* HAVE_CONFIG_H */
31+
32+
#include <nghttp2/nghttp2.h>
33+
34+
typedef struct nghttp2_ratelim {
35+
/* burst is the maximum value of val. */
36+
uint64_t burst;
37+
/* rate is the amount of value that is regenerated per 1 tstamp. */
38+
uint64_t rate;
39+
/* val is the amount of value available to drain. */
40+
uint64_t val;
41+
/* tstamp is the last timestamp in second resolution that is known
42+
to this object. */
43+
uint64_t tstamp;
44+
} nghttp2_ratelim;
45+
46+
/* nghttp2_ratelim_init initializes |rl| with the given parameters. */
47+
void nghttp2_ratelim_init(nghttp2_ratelim *rl, uint64_t burst, uint64_t rate);
48+
49+
/* nghttp2_ratelim_update updates rl->val with the current |tstamp|
50+
given in second resolution. */
51+
void nghttp2_ratelim_update(nghttp2_ratelim *rl, uint64_t tstamp);
52+
53+
/* nghttp2_ratelim_drain drains |n| from rl->val. It returns 0 if it
54+
succeeds, or -1. */
55+
int nghttp2_ratelim_drain(nghttp2_ratelim *rl, uint64_t n);
56+
57+
#endif /* NGHTTP2_RATELIM_H */

deps/nghttp2/lib/nghttp2_session.c

+33-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "nghttp2_http.h"
3838
#include "nghttp2_pq.h"
3939
#include "nghttp2_extpri.h"
40+
#include "nghttp2_time.h"
4041
#include "nghttp2_debug.h"
4142

4243
/*
@@ -475,6 +476,10 @@ static int session_new(nghttp2_session **session_ptr,
475476
(*session_ptr)->pending_enable_push = 1;
476477
(*session_ptr)->pending_no_rfc7540_priorities = UINT8_MAX;
477478

479+
nghttp2_ratelim_init(&(*session_ptr)->stream_reset_ratelim,
480+
NGHTTP2_DEFAULT_STREAM_RESET_BURST,
481+
NGHTTP2_DEFAULT_STREAM_RESET_RATE);
482+
478483
if (server) {
479484
(*session_ptr)->server = 1;
480485
}
@@ -573,6 +578,12 @@ static int session_new(nghttp2_session **session_ptr,
573578
(*session_ptr)->opt_flags |=
574579
NGHTTP2_OPTMASK_NO_RFC9113_LEADING_AND_TRAILING_WS_VALIDATION;
575580
}
581+
582+
if (option->opt_set_mask & NGHTTP2_OPT_STREAM_RESET_RATE_LIMIT) {
583+
nghttp2_ratelim_init(&(*session_ptr)->stream_reset_ratelim,
584+
option->stream_reset_burst,
585+
option->stream_reset_rate);
586+
}
576587
}
577588

578589
rv = nghttp2_hd_deflate_init2(&(*session_ptr)->hd_deflater,
@@ -4449,6 +4460,23 @@ static int session_process_priority_frame(nghttp2_session *session) {
44494460
return nghttp2_session_on_priority_received(session, frame);
44504461
}
44514462

4463+
static int session_update_stream_reset_ratelim(nghttp2_session *session) {
4464+
if (!session->server || (session->goaway_flags & NGHTTP2_GOAWAY_SUBMITTED)) {
4465+
return 0;
4466+
}
4467+
4468+
nghttp2_ratelim_update(&session->stream_reset_ratelim,
4469+
nghttp2_time_now_sec());
4470+
4471+
if (nghttp2_ratelim_drain(&session->stream_reset_ratelim, 1) == 0) {
4472+
return 0;
4473+
}
4474+
4475+
return nghttp2_session_add_goaway(session, session->last_recv_stream_id,
4476+
NGHTTP2_INTERNAL_ERROR, NULL, 0,
4477+
NGHTTP2_GOAWAY_AUX_NONE);
4478+
}
4479+
44524480
int nghttp2_session_on_rst_stream_received(nghttp2_session *session,
44534481
nghttp2_frame *frame) {
44544482
int rv;
@@ -4478,7 +4506,8 @@ int nghttp2_session_on_rst_stream_received(nghttp2_session *session,
44784506
if (nghttp2_is_fatal(rv)) {
44794507
return rv;
44804508
}
4481-
return 0;
4509+
4510+
return session_update_stream_reset_ratelim(session);
44824511
}
44834512

44844513
static int session_process_rst_stream_frame(nghttp2_session *session) {
@@ -7434,6 +7463,9 @@ int nghttp2_session_add_goaway(nghttp2_session *session, int32_t last_stream_id,
74347463
nghttp2_mem_free(mem, item);
74357464
return rv;
74367465
}
7466+
7467+
session->goaway_flags |= NGHTTP2_GOAWAY_SUBMITTED;
7468+
74377469
return 0;
74387470
}
74397471

0 commit comments

Comments
 (0)