]> git.kaiwu.me - nginx.git/commitdiff
HTTP/3: reference h3c directly from ngx_http_connection_t.
authorRoman Arutyunyan <arut@nginx.com>
Wed, 5 May 2021 11:53:36 +0000 (14:53 +0300)
committerRoman Arutyunyan <arut@nginx.com>
Wed, 5 May 2021 11:53:36 +0000 (14:53 +0300)
Previously, an ngx_http_v3_connection_t object was created for HTTP/3 and
then assinged to c->data instead of the generic ngx_http_connection_t object.
Now a direct reference is added to ngx_http_connection_t, which is less
confusing and does not require a flag for http3.

src/http/modules/ngx_http_quic_module.c
src/http/modules/ngx_http_quic_module.h
src/http/ngx_http.h
src/http/ngx_http_request.h
src/http/v3/ngx_http_v3.h
src/http/v3/ngx_http_v3_streams.c
src/http/v3/ngx_http_v3_tables.c

index b7661b42ce07965c184f1496a8f89eaebd0e8fac..2354dfd8bb290a641a616b270172aff83eae46b4 100644 (file)
@@ -201,7 +201,7 @@ ngx_http_quic_init(ngx_connection_t *c)
 
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http init quic stream");
 
-    phc = c->quic->parent->data;
+    phc = ngx_http_quic_get_connection(c);
 
     if (phc->ssl_servername) {
         hc->ssl_servername = phc->ssl_servername;
index 21d4a40a10c98f95e530151f7b9e89d3e283a526..8cadfbb878be07b72e12ccc8ed0973d6e3ef7813 100644 (file)
 #define NGX_HTTP_QUIC_ALPN_DRAFT_FMT  "\x05hq-%02uD"
 
 
+#define ngx_http_quic_get_connection(c)                                       \
+    ((ngx_http_connection_t *) (c)->quic->parent->data)
+
+
 ngx_int_t ngx_http_quic_init(ngx_connection_t *c);
 
 
index f5d772e65c57b7da4e207f7bfc761523b3a930ac..6f2d38d8b00392f45ecf64f7e9b083fa3d5fd14c 100644 (file)
@@ -21,6 +21,8 @@ typedef struct ngx_http_log_ctx_s     ngx_http_log_ctx_t;
 typedef struct ngx_http_chunked_s     ngx_http_chunked_t;
 typedef struct ngx_http_v2_stream_s   ngx_http_v2_stream_t;
 typedef struct ngx_http_v3_parse_s    ngx_http_v3_parse_t;
+typedef struct ngx_http_v3_connection_s
+                                      ngx_http_v3_connection_t;
 
 typedef ngx_int_t (*ngx_http_header_handler_pt)(ngx_http_request_t *r,
     ngx_table_elt_t *h, ngx_uint_t offset);
index 5231ad6f26fa1323e8fbdb4af2465a7e6794b51a..01ae716fe6f980325230771a2651466ffb856145 100644 (file)
@@ -318,6 +318,10 @@ typedef struct {
 #endif
 #endif
 
+#if (NGX_HTTP_V3 || NGX_COMPAT)
+    ngx_http_v3_connection_t         *v3_session;
+#endif
+
     ngx_chain_t                      *busy;
     ngx_int_t                         nbusy;
 
@@ -325,7 +329,6 @@ typedef struct {
 
     unsigned                          ssl:1;
     unsigned                          proxy_protocol:1;
-    unsigned                          http3:1;
 } ngx_http_connection_t;
 
 
index 9ee809fa1e94e596bb7766eb52f62c7c57e89b1c..10ea945921e7716c8e4b99a445ac15e8bb9a4ee6 100644 (file)
 #define NGX_HTTP_V3_ERR_DECODER_STREAM_ERROR       0x202
 
 
-#define ngx_http_v3_get_session(c)                                            \
-    ((ngx_http_v3_connection_t *) (c)->quic->parent->data)
+#define ngx_http_v3_get_session(c)  ngx_http_quic_get_connection(c)->v3_session
 
 #define ngx_http_v3_get_module_loc_conf(c, module)                            \
-    ngx_http_get_module_loc_conf(                                             \
-           ((ngx_http_v3_connection_t *) c->quic->parent->data)->hc.conf_ctx, \
-           module)
+    ngx_http_get_module_loc_conf(ngx_http_quic_get_connection(c)->conf_ctx,     \
+                                 module)
 
 #define ngx_http_v3_get_module_srv_conf(c, module)                            \
-    ngx_http_get_module_srv_conf(                                             \
-           ((ngx_http_v3_connection_t *) c->quic->parent->data)->hc.conf_ctx, \
-           module)
+    ngx_http_get_module_srv_conf(ngx_http_quic_get_connection(c)->conf_ctx,     \
+                                 module)
 
 #define ngx_http_v3_finalize_connection(c, code, reason)                      \
     ngx_quic_finalize_connection(c->quic->parent, code, reason)
@@ -130,9 +127,7 @@ typedef struct {
 } ngx_http_v3_dynamic_table_t;
 
 
-typedef struct {
-    /* the http connection must be first */
-    ngx_http_connection_t         hc;
+struct ngx_http_v3_connection_s {
     ngx_http_v3_dynamic_table_t   table;
 
     ngx_event_t                   keepalive;
@@ -149,7 +144,7 @@ typedef struct {
     ngx_uint_t                    goaway;  /* unsigned  goaway:1; */
 
     ngx_connection_t             *known_streams[NGX_HTTP_V3_MAX_KNOWN_STREAM];
-} ngx_http_v3_connection_t;
+};
 
 
 void ngx_http_v3_init(ngx_connection_t *c);
index 513738469ee9bd3e8735a7f07e5f41f0eb76d777..cf3204edd09babf23d7fafa42b19ea366580ad1d 100644 (file)
@@ -46,13 +46,13 @@ ngx_http_v3_init_session(ngx_connection_t *c)
 {
     ngx_connection_t          *pc;
     ngx_pool_cleanup_t        *cln;
-    ngx_http_connection_t     *phc;
+    ngx_http_connection_t     *hc;
     ngx_http_v3_connection_t  *h3c;
 
     pc = c->quic->parent;
-    phc = pc->data;
+    hc = pc->data;
 
-    if (phc->http3) {
+    if (hc->v3_session) {
         return NGX_OK;
     }
 
@@ -63,8 +63,6 @@ ngx_http_v3_init_session(ngx_connection_t *c)
         return NGX_ERROR;
     }
 
-    h3c->hc = *phc;
-    h3c->hc.http3 = 1;
     h3c->max_push_id = (uint64_t) -1;
 
     ngx_queue_init(&h3c->blocked);
@@ -83,7 +81,7 @@ ngx_http_v3_init_session(ngx_connection_t *c)
     cln->handler = ngx_http_v3_cleanup_session;
     cln->data = h3c;
 
-    pc->data = h3c;
+    hc->v3_session = h3c;
 
     return ngx_http_v3_send_settings(c);
 }
@@ -519,13 +517,10 @@ failed:
 static ngx_int_t
 ngx_http_v3_send_settings(ngx_connection_t *c)
 {
-    u_char                    *p, buf[NGX_HTTP_V3_VARLEN_INT_LEN * 6];
-    size_t                     n;
-    ngx_connection_t          *cc;
-    ngx_http_v3_srv_conf_t    *h3scf;
-    ngx_http_v3_connection_t  *h3c;
-
-    h3c = ngx_http_v3_get_session(c);
+    u_char                  *p, buf[NGX_HTTP_V3_VARLEN_INT_LEN * 6];
+    size_t                   n;
+    ngx_connection_t        *cc;
+    ngx_http_v3_srv_conf_t  *h3scf;
 
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 send settings");
 
@@ -534,7 +529,7 @@ ngx_http_v3_send_settings(ngx_connection_t *c)
         return NGX_DECLINED;
     }
 
-    h3scf = ngx_http_get_module_srv_conf(h3c->hc.conf_ctx, ngx_http_v3_module);
+    h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module);
 
     n = ngx_http_v3_encode_varlen_int(NULL,
                                       NGX_HTTP_V3_PARAM_MAX_TABLE_CAPACITY);
index c2ce1466008ce7c5c187002c66f560013d03fba8..46dcc67344591adf5437ef39aa624c939f71823d 100644 (file)
@@ -251,7 +251,7 @@ ngx_http_v3_set_capacity(ngx_connection_t *c, ngx_uint_t capacity)
                    "http3 set capacity %ui", capacity);
 
     h3c = ngx_http_v3_get_session(c);
-    h3scf = ngx_http_get_module_srv_conf(h3c->hc.conf_ctx, ngx_http_v3_module);
+    h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module);
 
     if (capacity > h3scf->max_table_capacity) {
         ngx_log_error(NGX_LOG_INFO, c->log, 0,
@@ -498,7 +498,7 @@ ngx_http_v3_decode_insert_count(ngx_connection_t *c, ngx_uint_t *insert_count)
     h3c = ngx_http_v3_get_session(c);
     dt = &h3c->table;
 
-    h3scf = ngx_http_get_module_srv_conf(h3c->hc.conf_ctx, ngx_http_v3_module);
+    h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module);
 
     max_entries = h3scf->max_table_capacity / 32;
     full_range = 2 * max_entries;
@@ -582,8 +582,7 @@ ngx_http_v3_check_insert_count(ngx_connection_t *c, ngx_uint_t insert_count)
     }
 
     if (block->queue.prev == NULL) {
-        h3scf = ngx_http_get_module_srv_conf(h3c->hc.conf_ctx,
-                                             ngx_http_v3_module);
+        h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module);
 
         if (h3c->nblocked == h3scf->max_blocked_streams) {
             ngx_log_error(NGX_LOG_INFO, c->log, 0,