Mercurial > hg > nginx-quic
annotate src/http/v3/ngx_http_v3_streams.c @ 8608:cbbe901c199d quic
QUIC: removed Firefox workaround for trailing zeroes in datagrams.
This became unnecessary after discarding invalid packets since a6784cf32c13.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Thu, 09 Sep 2021 19:12:27 +0300 |
parents | d6e191a583cc |
children | 531075860fe2 |
rev | line source |
---|---|
7681 | 1 |
2 /* | |
3 * Copyright (C) Roman Arutyunyan | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_http.h> | |
11 | |
12 | |
13 typedef struct { | |
8432
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
14 ngx_http_v3_parse_uni_t parse; |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
15 ngx_int_t index; |
7681 | 16 } ngx_http_v3_uni_stream_t; |
17 | |
18 | |
8015 | 19 typedef struct { |
20 ngx_queue_t queue; | |
21 uint64_t id; | |
22 ngx_connection_t *connection; | |
23 ngx_uint_t *npushing; | |
24 } ngx_http_v3_push_t; | |
25 | |
26 | |
7681 | 27 static void ngx_http_v3_close_uni_stream(ngx_connection_t *c); |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7681
diff
changeset
|
28 static void ngx_http_v3_uni_read_handler(ngx_event_t *rev); |
7747
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
29 static void ngx_http_v3_dummy_write_handler(ngx_event_t *wev); |
8015 | 30 static void ngx_http_v3_push_cleanup(void *data); |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
31 static ngx_connection_t *ngx_http_v3_get_uni_stream(ngx_connection_t *c, |
7681 | 32 ngx_uint_t type); |
8360
98c4020f1c9a
HTTP/3: keepalive timeout.
Roman Arutyunyan <arut@nginx.com>
parents:
8359
diff
changeset
|
33 |
98c4020f1c9a
HTTP/3: keepalive timeout.
Roman Arutyunyan <arut@nginx.com>
parents:
8359
diff
changeset
|
34 |
8272
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8200
diff
changeset
|
35 void |
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8200
diff
changeset
|
36 ngx_http_v3_init_uni_stream(ngx_connection_t *c) |
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8200
diff
changeset
|
37 { |
8549
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8546
diff
changeset
|
38 uint64_t n; |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8546
diff
changeset
|
39 ngx_http_v3_srv_conf_t *h3scf; |
8272
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8200
diff
changeset
|
40 ngx_http_v3_uni_stream_t *us; |
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8200
diff
changeset
|
41 |
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8200
diff
changeset
|
42 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init uni stream"); |
7681 | 43 |
8549
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8546
diff
changeset
|
44 h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module); |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8546
diff
changeset
|
45 |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8546
diff
changeset
|
46 n = c->quic->id >> 2; |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8546
diff
changeset
|
47 |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8546
diff
changeset
|
48 if (n >= h3scf->max_uni_streams) { |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8546
diff
changeset
|
49 ngx_http_v3_finalize_connection(c, |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8546
diff
changeset
|
50 NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR, |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8546
diff
changeset
|
51 "reached maximum number of uni streams"); |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8546
diff
changeset
|
52 ngx_http_close_connection(c); |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8546
diff
changeset
|
53 return; |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8546
diff
changeset
|
54 } |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8546
diff
changeset
|
55 |
8359
fc64ab301bad
QUIC: connection shutdown.
Roman Arutyunyan <arut@nginx.com>
parents:
8358
diff
changeset
|
56 c->quic->cancelable = 1; |
fc64ab301bad
QUIC: connection shutdown.
Roman Arutyunyan <arut@nginx.com>
parents:
8358
diff
changeset
|
57 |
7681 | 58 us = ngx_pcalloc(c->pool, sizeof(ngx_http_v3_uni_stream_t)); |
59 if (us == NULL) { | |
8272
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8200
diff
changeset
|
60 ngx_http_close_connection(c); |
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8200
diff
changeset
|
61 return; |
7681 | 62 } |
63 | |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
64 us->index = -1; |
7681 | 65 |
66 c->data = us; | |
67 | |
8432
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
68 c->read->handler = ngx_http_v3_uni_read_handler; |
7747
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
69 c->write->handler = ngx_http_v3_dummy_write_handler; |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
70 |
8432
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
71 ngx_http_v3_uni_read_handler(c->read); |
7681 | 72 } |
73 | |
74 | |
75 static void | |
76 ngx_http_v3_close_uni_stream(ngx_connection_t *c) | |
77 { | |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
78 ngx_pool_t *pool; |
8430
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8429
diff
changeset
|
79 ngx_http_v3_session_t *h3c; |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
80 ngx_http_v3_uni_stream_t *us; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
81 |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
82 us = c->data; |
8428
40d710a66aef
HTTP/3: ngx_http_v3_get_session() macro.
Roman Arutyunyan <arut@nginx.com>
parents:
8427
diff
changeset
|
83 h3c = ngx_http_v3_get_session(c); |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
84 |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
85 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 close stream"); |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
86 |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
87 if (us->index >= 0) { |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
88 h3c->known_streams[us->index] = NULL; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
89 } |
7681 | 90 |
91 c->destroyed = 1; | |
92 | |
93 pool = c->pool; | |
94 | |
95 ngx_close_connection(c); | |
96 | |
97 ngx_destroy_pool(pool); | |
98 } | |
99 | |
100 | |
8432
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
101 ngx_int_t |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
102 ngx_http_v3_register_uni_stream(ngx_connection_t *c, uint64_t type) |
7681 | 103 { |
8432
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
104 ngx_int_t index; |
8430
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8429
diff
changeset
|
105 ngx_http_v3_session_t *h3c; |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
106 ngx_http_v3_uni_stream_t *us; |
7681 | 107 |
8546
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8508
diff
changeset
|
108 h3c = ngx_http_v3_get_session(c); |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8508
diff
changeset
|
109 |
8432
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
110 switch (type) { |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
111 |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
112 case NGX_HTTP_V3_STREAM_ENCODER: |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
113 |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
114 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
115 "http3 encoder stream"); |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
116 index = NGX_HTTP_V3_STREAM_CLIENT_ENCODER; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
117 break; |
7681 | 118 |
8432
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
119 case NGX_HTTP_V3_STREAM_DECODER: |
7681 | 120 |
8432
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
121 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
122 "http3 decoder stream"); |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
123 index = NGX_HTTP_V3_STREAM_CLIENT_DECODER; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
124 break; |
7681 | 125 |
8432
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
126 case NGX_HTTP_V3_STREAM_CONTROL: |
7681 | 127 |
8432
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
128 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
129 "http3 control stream"); |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
130 index = NGX_HTTP_V3_STREAM_CLIENT_CONTROL; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
131 |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
132 break; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
133 |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
134 default: |
7955
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
135 |
8432
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
136 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
137 "http3 stream 0x%02xL", type); |
8546
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8508
diff
changeset
|
138 |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8508
diff
changeset
|
139 if (h3c->known_streams[NGX_HTTP_V3_STREAM_CLIENT_ENCODER] == NULL |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8508
diff
changeset
|
140 || h3c->known_streams[NGX_HTTP_V3_STREAM_CLIENT_DECODER] == NULL |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8508
diff
changeset
|
141 || h3c->known_streams[NGX_HTTP_V3_STREAM_CLIENT_CONTROL] == NULL) |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8508
diff
changeset
|
142 { |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8508
diff
changeset
|
143 ngx_log_error(NGX_LOG_INFO, c->log, 0, "missing mandatory stream"); |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8508
diff
changeset
|
144 return NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR; |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8508
diff
changeset
|
145 } |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8508
diff
changeset
|
146 |
8432
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
147 index = -1; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
148 } |
7681 | 149 |
8432
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
150 if (index >= 0) { |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
151 if (h3c->known_streams[index]) { |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
152 ngx_log_error(NGX_LOG_INFO, c->log, 0, "stream exists"); |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
153 return NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR; |
7681 | 154 } |
155 | |
8432
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
156 h3c->known_streams[index] = c; |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7681
diff
changeset
|
157 |
8432
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
158 us = c->data; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
159 us->index = index; |
7681 | 160 } |
161 | |
8432
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8431
diff
changeset
|
162 return NGX_OK; |
7681 | 163 } |
164 | |
165 | |
166 static void | |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7681
diff
changeset
|
167 ngx_http_v3_uni_read_handler(ngx_event_t *rev) |
7681 | 168 { |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7681
diff
changeset
|
169 u_char buf[128]; |
7681 | 170 ssize_t n; |
8563
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
171 ngx_buf_t b; |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
172 ngx_int_t rc; |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7681
diff
changeset
|
173 ngx_connection_t *c; |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
174 ngx_http_v3_uni_stream_t *us; |
7681 | 175 |
176 c = rev->data; | |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
177 us = c->data; |
7681 | 178 |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7681
diff
changeset
|
179 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 read handler"); |
7681 | 180 |
8563
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
181 ngx_memzero(&b, sizeof(ngx_buf_t)); |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
182 |
7681 | 183 while (rev->ready) { |
184 | |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7681
diff
changeset
|
185 n = c->recv(c, buf, sizeof(buf)); |
7681 | 186 |
7955
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
187 if (n == NGX_ERROR) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
188 rc = NGX_HTTP_V3_ERR_INTERNAL_ERROR; |
7681 | 189 goto failed; |
190 } | |
191 | |
7955
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
192 if (n == 0) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
193 if (us->index >= 0) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
194 rc = NGX_HTTP_V3_ERR_CLOSED_CRITICAL_STREAM; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
195 goto failed; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
196 } |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
197 |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
198 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 read eof"); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
199 ngx_http_v3_close_uni_stream(c); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
200 return; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
201 } |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
202 |
7692
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
7681
diff
changeset
|
203 if (n == NGX_AGAIN) { |
7681 | 204 break; |
205 } | |
206 | |
8563
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
207 b.pos = buf; |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
208 b.last = buf + n; |
7681 | 209 |
8563
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
210 rc = ngx_http_v3_parse_uni(c, &us->parse, &b); |
7681 | 211 |
8563
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
212 if (rc == NGX_DONE) { |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
213 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
214 "http3 read done"); |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
215 ngx_http_v3_close_uni_stream(c); |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
216 return; |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
217 } |
7955
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
218 |
8563
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
219 if (rc > 0) { |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
220 goto failed; |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
221 } |
7681 | 222 |
8563
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
223 if (rc != NGX_AGAIN) { |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
224 rc = NGX_HTTP_V3_ERR_GENERAL_PROTOCOL_ERROR; |
d6e191a583cc
HTTP/3: bulk parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
225 goto failed; |
7681 | 226 } |
227 } | |
228 | |
229 if (ngx_handle_read_event(rev, 0) != NGX_OK) { | |
7955
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
230 rc = NGX_HTTP_V3_ERR_INTERNAL_ERROR; |
7681 | 231 goto failed; |
232 } | |
233 | |
234 return; | |
235 | |
236 failed: | |
237 | |
7955
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
238 ngx_http_v3_finalize_connection(c, rc, "stream error"); |
7681 | 239 ngx_http_v3_close_uni_stream(c); |
240 } | |
241 | |
242 | |
7747
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
243 static void |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
244 ngx_http_v3_dummy_write_handler(ngx_event_t *wev) |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
245 { |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
246 ngx_connection_t *c; |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
247 |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
248 c = wev->data; |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
249 |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
250 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 dummy write handler"); |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
251 |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
252 if (ngx_handle_write_event(wev, 0) != NGX_OK) { |
7955
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
253 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_INTERNAL_ERROR, |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
7951
diff
changeset
|
254 NULL); |
7747
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
255 ngx_http_v3_close_uni_stream(c); |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
256 } |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
257 } |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
258 |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
259 |
7681 | 260 /* XXX async & buffered stream writes */ |
261 | |
8015 | 262 ngx_connection_t * |
263 ngx_http_v3_create_push_stream(ngx_connection_t *c, uint64_t push_id) | |
264 { | |
8430
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8429
diff
changeset
|
265 u_char *p, buf[NGX_HTTP_V3_VARLEN_INT_LEN * 2]; |
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8429
diff
changeset
|
266 size_t n; |
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8429
diff
changeset
|
267 ngx_connection_t *sc; |
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8429
diff
changeset
|
268 ngx_pool_cleanup_t *cln; |
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8429
diff
changeset
|
269 ngx_http_v3_push_t *push; |
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8429
diff
changeset
|
270 ngx_http_v3_session_t *h3c; |
8015 | 271 |
272 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
273 "http3 create push stream id:%uL", push_id); | |
274 | |
275 sc = ngx_quic_open_stream(c, 0); | |
276 if (sc == NULL) { | |
277 return NULL; | |
278 } | |
279 | |
280 p = buf; | |
281 p = (u_char *) ngx_http_v3_encode_varlen_int(p, NGX_HTTP_V3_STREAM_PUSH); | |
282 p = (u_char *) ngx_http_v3_encode_varlen_int(p, push_id); | |
283 n = p - buf; | |
284 | |
285 if (sc->send(sc, buf, n) != (ssize_t) n) { | |
286 goto failed; | |
287 } | |
288 | |
289 cln = ngx_pool_cleanup_add(sc->pool, sizeof(ngx_http_v3_push_t)); | |
290 if (cln == NULL) { | |
291 goto failed; | |
292 } | |
293 | |
8428
40d710a66aef
HTTP/3: ngx_http_v3_get_session() macro.
Roman Arutyunyan <arut@nginx.com>
parents:
8427
diff
changeset
|
294 h3c = ngx_http_v3_get_session(c); |
8015 | 295 h3c->npushing++; |
296 | |
297 cln->handler = ngx_http_v3_push_cleanup; | |
298 | |
299 push = cln->data; | |
300 push->id = push_id; | |
301 push->connection = sc; | |
302 push->npushing = &h3c->npushing; | |
303 | |
304 ngx_queue_insert_tail(&h3c->pushing, &push->queue); | |
305 | |
306 return sc; | |
307 | |
308 failed: | |
309 | |
310 ngx_http_v3_close_uni_stream(sc); | |
311 | |
312 return NULL; | |
313 } | |
314 | |
315 | |
316 static void | |
317 ngx_http_v3_push_cleanup(void *data) | |
318 { | |
319 ngx_http_v3_push_t *push = data; | |
320 | |
321 ngx_queue_remove(&push->queue); | |
322 (*push->npushing)--; | |
323 } | |
324 | |
325 | |
7681 | 326 static ngx_connection_t * |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
327 ngx_http_v3_get_uni_stream(ngx_connection_t *c, ngx_uint_t type) |
7681 | 328 { |
329 u_char buf[NGX_HTTP_V3_VARLEN_INT_LEN]; | |
330 size_t n; | |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
331 ngx_int_t index; |
7681 | 332 ngx_connection_t *sc; |
8430
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8429
diff
changeset
|
333 ngx_http_v3_session_t *h3c; |
7681 | 334 ngx_http_v3_uni_stream_t *us; |
335 | |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
336 switch (type) { |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
337 case NGX_HTTP_V3_STREAM_ENCODER: |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
338 index = NGX_HTTP_V3_STREAM_SERVER_ENCODER; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
339 break; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
340 case NGX_HTTP_V3_STREAM_DECODER: |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
341 index = NGX_HTTP_V3_STREAM_SERVER_DECODER; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
342 break; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
343 case NGX_HTTP_V3_STREAM_CONTROL: |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
344 index = NGX_HTTP_V3_STREAM_SERVER_CONTROL; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
345 break; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
346 default: |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
347 index = -1; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
348 } |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
349 |
8428
40d710a66aef
HTTP/3: ngx_http_v3_get_session() macro.
Roman Arutyunyan <arut@nginx.com>
parents:
8427
diff
changeset
|
350 h3c = ngx_http_v3_get_session(c); |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
351 |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
352 if (index >= 0) { |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
353 if (h3c->known_streams[index]) { |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
354 return h3c->known_streams[index]; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
355 } |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
356 } |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
357 |
8013
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8010
diff
changeset
|
358 sc = ngx_quic_open_stream(c, 0); |
7681 | 359 if (sc == NULL) { |
360 return NULL; | |
361 } | |
362 | |
8359
fc64ab301bad
QUIC: connection shutdown.
Roman Arutyunyan <arut@nginx.com>
parents:
8358
diff
changeset
|
363 sc->quic->cancelable = 1; |
fc64ab301bad
QUIC: connection shutdown.
Roman Arutyunyan <arut@nginx.com>
parents:
8358
diff
changeset
|
364 |
7681 | 365 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
366 "http3 create uni stream, type:%ui", type); | |
367 | |
368 us = ngx_pcalloc(sc->pool, sizeof(ngx_http_v3_uni_stream_t)); | |
369 if (us == NULL) { | |
370 goto failed; | |
371 } | |
372 | |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
373 us->index = index; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
374 |
7681 | 375 sc->data = us; |
376 | |
7747
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
377 sc->read->handler = ngx_http_v3_uni_read_handler; |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
378 sc->write->handler = ngx_http_v3_dummy_write_handler; |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
7694
diff
changeset
|
379 |
7880
c101438c69a4
HTTP/3: prevent array access by negative index for unknown streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7839
diff
changeset
|
380 if (index >= 0) { |
c101438c69a4
HTTP/3: prevent array access by negative index for unknown streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7839
diff
changeset
|
381 h3c->known_streams[index] = sc; |
c101438c69a4
HTTP/3: prevent array access by negative index for unknown streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7839
diff
changeset
|
382 } |
7681 | 383 |
384 n = (u_char *) ngx_http_v3_encode_varlen_int(buf, type) - buf; | |
385 | |
386 if (sc->send(sc, buf, n) != (ssize_t) n) { | |
387 goto failed; | |
388 } | |
389 | |
390 return sc; | |
391 | |
392 failed: | |
393 | |
394 ngx_http_v3_close_uni_stream(sc); | |
395 | |
396 return NULL; | |
397 } | |
398 | |
399 | |
8434
f4d3f5d93a82
HTTP/3: moved session initialization to a separate file.
Roman Arutyunyan <arut@nginx.com>
parents:
8432
diff
changeset
|
400 ngx_int_t |
7951
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
401 ngx_http_v3_send_settings(ngx_connection_t *c) |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
402 { |
8429
9ec3e71f8a61
HTTP/3: reference h3c directly from ngx_http_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8428
diff
changeset
|
403 u_char *p, buf[NGX_HTTP_V3_VARLEN_INT_LEN * 6]; |
9ec3e71f8a61
HTTP/3: reference h3c directly from ngx_http_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8428
diff
changeset
|
404 size_t n; |
9ec3e71f8a61
HTTP/3: reference h3c directly from ngx_http_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8428
diff
changeset
|
405 ngx_connection_t *cc; |
9ec3e71f8a61
HTTP/3: reference h3c directly from ngx_http_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8428
diff
changeset
|
406 ngx_http_v3_srv_conf_t *h3scf; |
8013
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8010
diff
changeset
|
407 |
7951
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
408 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 send settings"); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
409 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
410 cc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_CONTROL); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
411 if (cc == NULL) { |
8013
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8010
diff
changeset
|
412 return NGX_DECLINED; |
7951
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
413 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
414 |
8429
9ec3e71f8a61
HTTP/3: reference h3c directly from ngx_http_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8428
diff
changeset
|
415 h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module); |
7951
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
416 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
417 n = ngx_http_v3_encode_varlen_int(NULL, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
418 NGX_HTTP_V3_PARAM_MAX_TABLE_CAPACITY); |
8010
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
419 n += ngx_http_v3_encode_varlen_int(NULL, h3scf->max_table_capacity); |
7951
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
420 n += ngx_http_v3_encode_varlen_int(NULL, NGX_HTTP_V3_PARAM_BLOCKED_STREAMS); |
8010
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
421 n += ngx_http_v3_encode_varlen_int(NULL, h3scf->max_blocked_streams); |
7951
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
422 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
423 p = (u_char *) ngx_http_v3_encode_varlen_int(buf, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
424 NGX_HTTP_V3_FRAME_SETTINGS); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
425 p = (u_char *) ngx_http_v3_encode_varlen_int(p, n); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
426 p = (u_char *) ngx_http_v3_encode_varlen_int(p, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
427 NGX_HTTP_V3_PARAM_MAX_TABLE_CAPACITY); |
8010
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
428 p = (u_char *) ngx_http_v3_encode_varlen_int(p, h3scf->max_table_capacity); |
7951
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
429 p = (u_char *) ngx_http_v3_encode_varlen_int(p, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
430 NGX_HTTP_V3_PARAM_BLOCKED_STREAMS); |
8010
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
431 p = (u_char *) ngx_http_v3_encode_varlen_int(p, h3scf->max_blocked_streams); |
7951
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
432 n = p - buf; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
433 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
434 if (cc->send(cc, buf, n) != (ssize_t) n) { |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
435 goto failed; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
436 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
437 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
438 return NGX_OK; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
439 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
440 failed: |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
441 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
442 ngx_http_v3_close_uni_stream(cc); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
443 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
444 return NGX_ERROR; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
445 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
446 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
447 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7880
diff
changeset
|
448 ngx_int_t |
8358
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
449 ngx_http_v3_send_goaway(ngx_connection_t *c, uint64_t id) |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
450 { |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
451 u_char *p, buf[NGX_HTTP_V3_VARLEN_INT_LEN * 3]; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
452 size_t n; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
453 ngx_connection_t *cc; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
454 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
455 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 send goaway %uL", id); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
456 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
457 cc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_CONTROL); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
458 if (cc == NULL) { |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
459 return NGX_DECLINED; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
460 } |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
461 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
462 n = ngx_http_v3_encode_varlen_int(NULL, id); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
463 p = (u_char *) ngx_http_v3_encode_varlen_int(buf, NGX_HTTP_V3_FRAME_GOAWAY); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
464 p = (u_char *) ngx_http_v3_encode_varlen_int(p, n); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
465 p = (u_char *) ngx_http_v3_encode_varlen_int(p, id); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
466 n = p - buf; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
467 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
468 if (cc->send(cc, buf, n) != (ssize_t) n) { |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
469 goto failed; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
470 } |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
471 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
472 return NGX_OK; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
473 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
474 failed: |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
475 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
476 ngx_http_v3_close_uni_stream(cc); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
477 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
478 return NGX_ERROR; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
479 } |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
480 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
481 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8354
diff
changeset
|
482 ngx_int_t |
8431
0981329169ea
HTTP/3: renamed ngx_http_v3_client_XXX() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8430
diff
changeset
|
483 ngx_http_v3_send_ref_insert(ngx_connection_t *c, ngx_uint_t dynamic, |
7681 | 484 ngx_uint_t index, ngx_str_t *value) |
485 { | |
486 u_char *p, buf[NGX_HTTP_V3_PREFIX_INT_LEN * 2]; | |
487 size_t n; | |
488 ngx_connection_t *ec; | |
489 | |
490 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
491 "http3 client ref insert, %s[%ui] \"%V\"", | |
492 dynamic ? "dynamic" : "static", index, value); | |
493 | |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
494 ec = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_ENCODER); |
7681 | 495 if (ec == NULL) { |
496 return NGX_ERROR; | |
497 } | |
498 | |
499 p = buf; | |
500 | |
501 *p = (dynamic ? 0x80 : 0xc0); | |
502 p = (u_char *) ngx_http_v3_encode_prefix_int(p, index, 6); | |
503 | |
504 /* XXX option for huffman? */ | |
505 *p = 0; | |
506 p = (u_char *) ngx_http_v3_encode_prefix_int(p, value->len, 7); | |
507 | |
508 n = p - buf; | |
509 | |
510 if (ec->send(ec, buf, n) != (ssize_t) n) { | |
511 goto failed; | |
512 } | |
513 | |
514 if (ec->send(ec, value->data, value->len) != (ssize_t) value->len) { | |
515 goto failed; | |
516 } | |
517 | |
518 return NGX_OK; | |
519 | |
520 failed: | |
521 | |
522 ngx_http_v3_close_uni_stream(ec); | |
523 | |
524 return NGX_ERROR; | |
525 } | |
526 | |
527 | |
528 ngx_int_t | |
8431
0981329169ea
HTTP/3: renamed ngx_http_v3_client_XXX() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8430
diff
changeset
|
529 ngx_http_v3_send_insert(ngx_connection_t *c, ngx_str_t *name, ngx_str_t *value) |
7681 | 530 { |
531 u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN]; | |
532 size_t n; | |
533 ngx_connection_t *ec; | |
534 | |
535 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
536 "http3 client insert \"%V\":\"%V\"", name, value); | |
537 | |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
538 ec = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_ENCODER); |
7681 | 539 if (ec == NULL) { |
540 return NGX_ERROR; | |
541 } | |
542 | |
543 /* XXX option for huffman? */ | |
544 buf[0] = 0x40; | |
545 n = (u_char *) ngx_http_v3_encode_prefix_int(buf, name->len, 5) - buf; | |
546 | |
547 if (ec->send(ec, buf, n) != (ssize_t) n) { | |
548 goto failed; | |
549 } | |
550 | |
551 if (ec->send(ec, name->data, name->len) != (ssize_t) name->len) { | |
552 goto failed; | |
553 } | |
554 | |
555 /* XXX option for huffman? */ | |
556 buf[0] = 0; | |
557 n = (u_char *) ngx_http_v3_encode_prefix_int(buf, value->len, 7) - buf; | |
558 | |
559 if (ec->send(ec, buf, n) != (ssize_t) n) { | |
560 goto failed; | |
561 } | |
562 | |
563 if (ec->send(ec, value->data, value->len) != (ssize_t) value->len) { | |
564 goto failed; | |
565 } | |
566 | |
567 return NGX_OK; | |
568 | |
569 failed: | |
570 | |
571 ngx_http_v3_close_uni_stream(ec); | |
572 | |
573 return NGX_ERROR; | |
574 } | |
575 | |
576 | |
577 ngx_int_t | |
8431
0981329169ea
HTTP/3: renamed ngx_http_v3_client_XXX() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8430
diff
changeset
|
578 ngx_http_v3_send_set_capacity(ngx_connection_t *c, ngx_uint_t capacity) |
7681 | 579 { |
580 u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN]; | |
581 size_t n; | |
582 ngx_connection_t *ec; | |
583 | |
584 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
585 "http3 client set capacity %ui", capacity); | |
586 | |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
587 ec = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_ENCODER); |
7681 | 588 if (ec == NULL) { |
589 return NGX_ERROR; | |
590 } | |
591 | |
592 buf[0] = 0x20; | |
593 n = (u_char *) ngx_http_v3_encode_prefix_int(buf, capacity, 5) - buf; | |
594 | |
595 if (ec->send(ec, buf, n) != (ssize_t) n) { | |
596 ngx_http_v3_close_uni_stream(ec); | |
597 return NGX_ERROR; | |
598 } | |
599 | |
600 return NGX_OK; | |
601 } | |
602 | |
603 | |
604 ngx_int_t | |
8431
0981329169ea
HTTP/3: renamed ngx_http_v3_client_XXX() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8430
diff
changeset
|
605 ngx_http_v3_send_duplicate(ngx_connection_t *c, ngx_uint_t index) |
7681 | 606 { |
607 u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN]; | |
608 size_t n; | |
609 ngx_connection_t *ec; | |
610 | |
611 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
612 "http3 client duplicate %ui", index); | |
613 | |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
614 ec = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_ENCODER); |
7681 | 615 if (ec == NULL) { |
616 return NGX_ERROR; | |
617 } | |
618 | |
619 buf[0] = 0; | |
620 n = (u_char *) ngx_http_v3_encode_prefix_int(buf, index, 5) - buf; | |
621 | |
622 if (ec->send(ec, buf, n) != (ssize_t) n) { | |
623 ngx_http_v3_close_uni_stream(ec); | |
624 return NGX_ERROR; | |
625 } | |
626 | |
627 return NGX_OK; | |
628 } | |
629 | |
630 | |
631 ngx_int_t | |
8508
0ac25efb2da3
HTTP/3: quic-qpack term updates.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8497
diff
changeset
|
632 ngx_http_v3_send_ack_section(ngx_connection_t *c, ngx_uint_t stream_id) |
7681 | 633 { |
634 u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN]; | |
635 size_t n; | |
636 ngx_connection_t *dc; | |
637 | |
638 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
8508
0ac25efb2da3
HTTP/3: quic-qpack term updates.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8497
diff
changeset
|
639 "http3 client ack section %ui", stream_id); |
7681 | 640 |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
641 dc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_DECODER); |
7681 | 642 if (dc == NULL) { |
643 return NGX_ERROR; | |
644 } | |
645 | |
646 buf[0] = 0x80; | |
647 n = (u_char *) ngx_http_v3_encode_prefix_int(buf, stream_id, 7) - buf; | |
648 | |
649 if (dc->send(dc, buf, n) != (ssize_t) n) { | |
650 ngx_http_v3_close_uni_stream(dc); | |
651 return NGX_ERROR; | |
652 } | |
653 | |
654 return NGX_OK; | |
655 } | |
656 | |
657 | |
658 ngx_int_t | |
8431
0981329169ea
HTTP/3: renamed ngx_http_v3_client_XXX() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8430
diff
changeset
|
659 ngx_http_v3_send_cancel_stream(ngx_connection_t *c, ngx_uint_t stream_id) |
7681 | 660 { |
661 u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN]; | |
662 size_t n; | |
663 ngx_connection_t *dc; | |
664 | |
665 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
666 "http3 client cancel stream %ui", stream_id); | |
667 | |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
668 dc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_DECODER); |
7681 | 669 if (dc == NULL) { |
670 return NGX_ERROR; | |
671 } | |
672 | |
673 buf[0] = 0x40; | |
674 n = (u_char *) ngx_http_v3_encode_prefix_int(buf, stream_id, 6) - buf; | |
675 | |
676 if (dc->send(dc, buf, n) != (ssize_t) n) { | |
677 ngx_http_v3_close_uni_stream(dc); | |
678 return NGX_ERROR; | |
679 } | |
680 | |
681 return NGX_OK; | |
682 } | |
683 | |
684 | |
685 ngx_int_t | |
8431
0981329169ea
HTTP/3: renamed ngx_http_v3_client_XXX() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8430
diff
changeset
|
686 ngx_http_v3_send_inc_insert_count(ngx_connection_t *c, ngx_uint_t inc) |
7681 | 687 { |
688 u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN]; | |
689 size_t n; | |
690 ngx_connection_t *dc; | |
691 | |
692 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
693 "http3 client increment insert count %ui", inc); | |
694 | |
7749
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
7747
diff
changeset
|
695 dc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_DECODER); |
7681 | 696 if (dc == NULL) { |
697 return NGX_ERROR; | |
698 } | |
699 | |
700 buf[0] = 0; | |
701 n = (u_char *) ngx_http_v3_encode_prefix_int(buf, inc, 6) - buf; | |
702 | |
703 if (dc->send(dc, buf, n) != (ssize_t) n) { | |
704 ngx_http_v3_close_uni_stream(dc); | |
705 return NGX_ERROR; | |
706 } | |
707 | |
708 return NGX_OK; | |
709 } | |
8015 | 710 |
711 | |
712 ngx_int_t | |
713 ngx_http_v3_set_max_push_id(ngx_connection_t *c, uint64_t max_push_id) | |
714 { | |
8430
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8429
diff
changeset
|
715 ngx_http_v3_session_t *h3c; |
8015 | 716 |
8428
40d710a66aef
HTTP/3: ngx_http_v3_get_session() macro.
Roman Arutyunyan <arut@nginx.com>
parents:
8427
diff
changeset
|
717 h3c = ngx_http_v3_get_session(c); |
8015 | 718 |
719 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
720 "http3 MAX_PUSH_ID:%uL", max_push_id); | |
721 | |
8354
5cb5b568282b
HTTP/3: do not push until a MAX_PUSH_ID frame is received.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8272
diff
changeset
|
722 if (h3c->max_push_id != (uint64_t) -1 && max_push_id < h3c->max_push_id) { |
8015 | 723 return NGX_HTTP_V3_ERR_ID_ERROR; |
724 } | |
725 | |
726 h3c->max_push_id = max_push_id; | |
727 | |
728 return NGX_OK; | |
729 } | |
730 | |
731 | |
732 ngx_int_t | |
8497
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8434
diff
changeset
|
733 ngx_http_v3_goaway(ngx_connection_t *c, uint64_t push_id) |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8434
diff
changeset
|
734 { |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8434
diff
changeset
|
735 ngx_http_v3_session_t *h3c; |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8434
diff
changeset
|
736 |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8434
diff
changeset
|
737 h3c = ngx_http_v3_get_session(c); |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8434
diff
changeset
|
738 |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8434
diff
changeset
|
739 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 GOAWAY:%uL", push_id); |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8434
diff
changeset
|
740 |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8434
diff
changeset
|
741 h3c->goaway_push_id = push_id; |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8434
diff
changeset
|
742 |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8434
diff
changeset
|
743 return NGX_OK; |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8434
diff
changeset
|
744 } |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8434
diff
changeset
|
745 |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8434
diff
changeset
|
746 |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8434
diff
changeset
|
747 ngx_int_t |
8015 | 748 ngx_http_v3_cancel_push(ngx_connection_t *c, uint64_t push_id) |
749 { | |
8430
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8429
diff
changeset
|
750 ngx_queue_t *q; |
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8429
diff
changeset
|
751 ngx_http_request_t *r; |
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8429
diff
changeset
|
752 ngx_http_v3_push_t *push; |
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8429
diff
changeset
|
753 ngx_http_v3_session_t *h3c; |
8015 | 754 |
8428
40d710a66aef
HTTP/3: ngx_http_v3_get_session() macro.
Roman Arutyunyan <arut@nginx.com>
parents:
8427
diff
changeset
|
755 h3c = ngx_http_v3_get_session(c); |
8015 | 756 |
757 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
758 "http3 CANCEL_PUSH:%uL", push_id); | |
759 | |
760 if (push_id >= h3c->next_push_id) { | |
761 return NGX_HTTP_V3_ERR_ID_ERROR; | |
762 } | |
763 | |
764 for (q = ngx_queue_head(&h3c->pushing); | |
765 q != ngx_queue_sentinel(&h3c->pushing); | |
766 q = ngx_queue_next(&h3c->pushing)) | |
767 { | |
768 push = (ngx_http_v3_push_t *) q; | |
769 | |
770 if (push->id != push_id) { | |
771 continue; | |
772 } | |
773 | |
774 r = push->connection->data; | |
775 | |
776 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
777 "http3 cancel push"); | |
778 | |
779 ngx_http_finalize_request(r, NGX_HTTP_CLOSE); | |
780 | |
781 break; | |
782 } | |
783 | |
784 return NGX_OK; | |
785 } | |
8427
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8360
diff
changeset
|
786 |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8360
diff
changeset
|
787 |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8360
diff
changeset
|
788 ngx_int_t |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8360
diff
changeset
|
789 ngx_http_v3_cancel_stream(ngx_connection_t *c, ngx_uint_t stream_id) |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8360
diff
changeset
|
790 { |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8360
diff
changeset
|
791 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8360
diff
changeset
|
792 "http3 cancel stream %ui", stream_id); |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8360
diff
changeset
|
793 |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8360
diff
changeset
|
794 /* we do not use dynamic tables */ |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8360
diff
changeset
|
795 |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8360
diff
changeset
|
796 return NGX_OK; |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8360
diff
changeset
|
797 } |