Mercurial > hg > nginx-quic
comparison src/event/ngx_event_quic.c @ 7855:81a4f98a2556 quic
Cleaned up reordering code.
The ordered frame handler is always called for the existing stream, as it is
allocated from this stream. Instead of searching stream by id, pointer to the
stream node is passed.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Fri, 08 May 2020 13:08:04 +0300 |
parents | 2a94aaa70b33 |
children | aecd8ec29c8e |
comparison
equal
deleted
inserted
replaced
7854:2a94aaa70b33 | 7855:81a4f98a2556 |
---|---|
124 unsigned key_phase:1; | 124 unsigned key_phase:1; |
125 }; | 125 }; |
126 | 126 |
127 | 127 |
128 typedef ngx_int_t (*ngx_quic_frame_handler_pt)(ngx_connection_t *c, | 128 typedef ngx_int_t (*ngx_quic_frame_handler_pt)(ngx_connection_t *c, |
129 ngx_quic_frame_t *frame); | 129 ngx_quic_frame_t *frame, void *data); |
130 | 130 |
131 | 131 |
132 #if BORINGSSL_API_VERSION >= 10 | 132 #if BORINGSSL_API_VERSION >= 10 |
133 static int ngx_quic_set_read_secret(ngx_ssl_conn_t *ssl_conn, | 133 static int ngx_quic_set_read_secret(ngx_ssl_conn_t *ssl_conn, |
134 enum ssl_encryption_level_t level, const SSL_CIPHER *cipher, | 134 enum ssl_encryption_level_t level, const SSL_CIPHER *cipher, |
187 static void ngx_quic_handle_stream_ack(ngx_connection_t *c, | 187 static void ngx_quic_handle_stream_ack(ngx_connection_t *c, |
188 ngx_quic_frame_t *f); | 188 ngx_quic_frame_t *f); |
189 | 189 |
190 static ngx_int_t ngx_quic_handle_ordered_frame(ngx_connection_t *c, | 190 static ngx_int_t ngx_quic_handle_ordered_frame(ngx_connection_t *c, |
191 ngx_quic_frames_stream_t *fs, ngx_quic_frame_t *frame, | 191 ngx_quic_frames_stream_t *fs, ngx_quic_frame_t *frame, |
192 ngx_quic_frame_handler_pt handler); | 192 ngx_quic_frame_handler_pt handler, void *data); |
193 static ngx_int_t ngx_quic_adjust_frame_offset(ngx_connection_t *c, | 193 static ngx_int_t ngx_quic_adjust_frame_offset(ngx_connection_t *c, |
194 ngx_quic_frame_t *f, uint64_t offset_in); | 194 ngx_quic_frame_t *f, uint64_t offset_in); |
195 static ngx_int_t ngx_quic_buffer_frame(ngx_connection_t *c, | 195 static ngx_int_t ngx_quic_buffer_frame(ngx_connection_t *c, |
196 ngx_quic_frames_stream_t *stream, ngx_quic_frame_t *f); | 196 ngx_quic_frames_stream_t *stream, ngx_quic_frame_t *f); |
197 | 197 |
198 static ngx_int_t ngx_quic_handle_crypto_frame(ngx_connection_t *c, | 198 static ngx_int_t ngx_quic_handle_crypto_frame(ngx_connection_t *c, |
199 ngx_quic_header_t *pkt, ngx_quic_frame_t *frame); | 199 ngx_quic_header_t *pkt, ngx_quic_frame_t *frame); |
200 static ngx_int_t ngx_quic_crypto_input(ngx_connection_t *c, | 200 static ngx_int_t ngx_quic_crypto_input(ngx_connection_t *c, |
201 ngx_quic_frame_t *frame); | 201 ngx_quic_frame_t *frame, void *data); |
202 static ngx_int_t ngx_quic_handle_stream_frame(ngx_connection_t *c, | 202 static ngx_int_t ngx_quic_handle_stream_frame(ngx_connection_t *c, |
203 ngx_quic_header_t *pkt, ngx_quic_frame_t *frame); | 203 ngx_quic_header_t *pkt, ngx_quic_frame_t *frame); |
204 static ngx_int_t ngx_quic_stream_input(ngx_connection_t *c, | 204 static ngx_int_t ngx_quic_stream_input(ngx_connection_t *c, |
205 ngx_quic_frame_t *frame); | 205 ngx_quic_frame_t *frame, void *data); |
206 | 206 |
207 static ngx_int_t ngx_quic_handle_max_streams(ngx_connection_t *c); | 207 static ngx_int_t ngx_quic_handle_max_streams(ngx_connection_t *c); |
208 static ngx_int_t ngx_quic_handle_max_data_frame(ngx_connection_t *c, | 208 static ngx_int_t ngx_quic_handle_max_data_frame(ngx_connection_t *c, |
209 ngx_quic_max_data_frame_t *f); | 209 ngx_quic_max_data_frame_t *f); |
210 static ngx_int_t ngx_quic_handle_streams_blocked_frame(ngx_connection_t *c, | 210 static ngx_int_t ngx_quic_handle_streams_blocked_frame(ngx_connection_t *c, |
1778 } | 1778 } |
1779 | 1779 |
1780 | 1780 |
1781 static ngx_int_t | 1781 static ngx_int_t |
1782 ngx_quic_handle_ordered_frame(ngx_connection_t *c, ngx_quic_frames_stream_t *fs, | 1782 ngx_quic_handle_ordered_frame(ngx_connection_t *c, ngx_quic_frames_stream_t *fs, |
1783 ngx_quic_frame_t *frame, ngx_quic_frame_handler_pt handler) | 1783 ngx_quic_frame_t *frame, ngx_quic_frame_handler_pt handler, void *data) |
1784 { | 1784 { |
1785 size_t full_len; | 1785 size_t full_len; |
1786 ngx_int_t rc; | 1786 ngx_int_t rc; |
1787 ngx_queue_t *q; | 1787 ngx_queue_t *q; |
1788 ngx_quic_ordered_frame_t *f; | 1788 ngx_quic_ordered_frame_t *f; |
1809 /* intersecting data range, frame modified */ | 1809 /* intersecting data range, frame modified */ |
1810 } | 1810 } |
1811 | 1811 |
1812 /* f->offset == fs->received */ | 1812 /* f->offset == fs->received */ |
1813 | 1813 |
1814 rc = handler(c, frame); | 1814 rc = handler(c, frame, data); |
1815 if (rc == NGX_ERROR) { | 1815 if (rc == NGX_ERROR) { |
1816 return NGX_ERROR; | 1816 return NGX_ERROR; |
1817 | 1817 |
1818 } else if (rc == NGX_DONE) { | 1818 } else if (rc == NGX_DONE) { |
1819 /* handler destroyed stream, queue no longer exists */ | 1819 /* handler destroyed stream, queue no longer exists */ |
1861 /* frame was adjusted, proceed to input */ | 1861 /* frame was adjusted, proceed to input */ |
1862 } | 1862 } |
1863 | 1863 |
1864 /* f->offset == fs->received */ | 1864 /* f->offset == fs->received */ |
1865 | 1865 |
1866 rc = handler(c, frame); | 1866 rc = handler(c, frame, data); |
1867 | 1867 |
1868 if (rc == NGX_ERROR) { | 1868 if (rc == NGX_ERROR) { |
1869 return NGX_ERROR; | 1869 return NGX_ERROR; |
1870 | 1870 |
1871 } else if (rc == NGX_DONE) { | 1871 } else if (rc == NGX_DONE) { |
1998 ngx_quic_frames_stream_t *fs; | 1998 ngx_quic_frames_stream_t *fs; |
1999 | 1999 |
2000 qc = c->quic; | 2000 qc = c->quic; |
2001 fs = &qc->crypto[pkt->level]; | 2001 fs = &qc->crypto[pkt->level]; |
2002 | 2002 |
2003 return ngx_quic_handle_ordered_frame(c, fs, frame, ngx_quic_crypto_input); | 2003 return ngx_quic_handle_ordered_frame(c, fs, frame, ngx_quic_crypto_input, |
2004 NULL); | |
2004 } | 2005 } |
2005 | 2006 |
2006 | 2007 |
2007 static ngx_int_t | 2008 static ngx_int_t |
2008 ngx_quic_crypto_input(ngx_connection_t *c, ngx_quic_frame_t *frame) | 2009 ngx_quic_crypto_input(ngx_connection_t *c, ngx_quic_frame_t *frame, void *data) |
2009 { | 2010 { |
2010 int sslerr; | 2011 int sslerr; |
2011 ssize_t n; | 2012 ssize_t n; |
2012 ngx_ssl_conn_t *ssl_conn; | 2013 ngx_ssl_conn_t *ssl_conn; |
2013 ngx_quic_crypto_frame_t *f; | 2014 ngx_quic_crypto_frame_t *f; |
2089 static ngx_int_t | 2090 static ngx_int_t |
2090 ngx_quic_handle_stream_frame(ngx_connection_t *c, ngx_quic_header_t *pkt, | 2091 ngx_quic_handle_stream_frame(ngx_connection_t *c, ngx_quic_header_t *pkt, |
2091 ngx_quic_frame_t *frame) | 2092 ngx_quic_frame_t *frame) |
2092 { | 2093 { |
2093 size_t n; | 2094 size_t n; |
2094 ngx_buf_t *b; | 2095 ngx_buf_t *b; |
2095 ngx_event_t *rev; | 2096 ngx_event_t *rev; |
2096 ngx_quic_stream_t *sn; | 2097 ngx_quic_stream_t *sn; |
2097 ngx_quic_connection_t *qc; | 2098 ngx_quic_connection_t *qc; |
2098 ngx_quic_stream_frame_t *f; | 2099 ngx_quic_stream_frame_t *f; |
2099 ngx_quic_frames_stream_t *fs; | 2100 ngx_quic_frames_stream_t *fs; |
2100 | 2101 |
2168 /* out-of-order stream: proceed to buffering */ | 2169 /* out-of-order stream: proceed to buffering */ |
2169 } | 2170 } |
2170 | 2171 |
2171 fs = &sn->fs; | 2172 fs = &sn->fs; |
2172 | 2173 |
2173 return ngx_quic_handle_ordered_frame(c, fs, frame, ngx_quic_stream_input); | 2174 return ngx_quic_handle_ordered_frame(c, fs, frame, ngx_quic_stream_input, |
2175 sn); | |
2174 } | 2176 } |
2175 | 2177 |
2176 | 2178 |
2177 static ngx_int_t | 2179 static ngx_int_t |
2178 ngx_quic_stream_input(ngx_connection_t *c, ngx_quic_frame_t *frame) | 2180 ngx_quic_stream_input(ngx_connection_t *c, ngx_quic_frame_t *frame, void *data) |
2179 { | 2181 { |
2180 ngx_buf_t *b; | 2182 ngx_buf_t *b; |
2181 ngx_event_t *rev; | 2183 ngx_event_t *rev; |
2182 ngx_quic_stream_t *sn; | 2184 ngx_quic_stream_t *sn; |
2183 ngx_quic_connection_t *qc; | 2185 ngx_quic_connection_t *qc; |
2184 ngx_quic_stream_frame_t *f; | 2186 ngx_quic_stream_frame_t *f; |
2185 | 2187 |
2186 qc = c->quic; | 2188 qc = c->quic; |
2189 sn = data; | |
2187 | 2190 |
2188 f = &frame->u.stream; | 2191 f = &frame->u.stream; |
2189 | |
2190 sn = ngx_quic_find_stream(&qc->streams.tree, f->stream_id); | |
2191 if (sn == NULL) { | |
2192 // TODO: possible? | |
2193 // stream was deleted while in reordering queue ? | |
2194 return NGX_ERROR; | |
2195 } | |
2196 | 2192 |
2197 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic existing stream"); | 2193 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic existing stream"); |
2198 | 2194 |
2199 b = sn->b; | 2195 b = sn->b; |
2200 | 2196 |