comparison src/http/v3/ngx_http_v3_tables.c @ 8768:40d710a66aef quic

HTTP/3: ngx_http_v3_get_session() macro. It's used instead of accessing c->quic->parent->data directly. Apart from being simpler, it allows to change the way session is stored in the future by changing the macro.
author Roman Arutyunyan <arut@nginx.com>
date Fri, 30 Apr 2021 19:10:11 +0300
parents 33ec97749b5f
children 9ec3e71f8a61
comparison
equal deleted inserted replaced
8767:33ec97749b5f 8768:40d710a66aef
196 196
197 if (ngx_http_v3_evict(c, size) != NGX_OK) { 197 if (ngx_http_v3_evict(c, size) != NGX_OK) {
198 return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR; 198 return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR;
199 } 199 }
200 200
201 h3c = c->quic->parent->data; 201 h3c = ngx_http_v3_get_session(c);
202 dt = &h3c->table; 202 dt = &h3c->table;
203 203
204 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, c->log, 0, 204 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, c->log, 0,
205 "http3 insert [%ui] \"%V\":\"%V\", size:%uz", 205 "http3 insert [%ui] \"%V\":\"%V\", size:%uz",
206 dt->base + dt->nelts, name, value, size); 206 dt->base + dt->nelts, name, value, size);
248 ngx_http_v3_dynamic_table_t *dt; 248 ngx_http_v3_dynamic_table_t *dt;
249 249
250 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, 250 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
251 "http3 set capacity %ui", capacity); 251 "http3 set capacity %ui", capacity);
252 252
253 pc = c->quic->parent; 253 h3c = ngx_http_v3_get_session(c);
254 h3c = pc->data;
255 h3scf = ngx_http_get_module_srv_conf(h3c->hc.conf_ctx, ngx_http_v3_module); 254 h3scf = ngx_http_get_module_srv_conf(h3c->hc.conf_ctx, ngx_http_v3_module);
256 255
257 if (capacity > h3scf->max_table_capacity) { 256 if (capacity > h3scf->max_table_capacity) {
258 ngx_log_error(NGX_LOG_INFO, c->log, 0, 257 ngx_log_error(NGX_LOG_INFO, c->log, 0,
259 "client exceeded http3_max_table_capacity limit"); 258 "client exceeded http3_max_table_capacity limit");
276 if (elts == NULL) { 275 if (elts == NULL) {
277 return NGX_ERROR; 276 return NGX_ERROR;
278 } 277 }
279 278
280 if (dt->elts == NULL) { 279 if (dt->elts == NULL) {
280 pc = c->quic->parent;
281
281 cln = ngx_pool_cleanup_add(pc->pool, 0); 282 cln = ngx_pool_cleanup_add(pc->pool, 0);
282 if (cln == NULL) { 283 if (cln == NULL) {
283 return NGX_ERROR; 284 return NGX_ERROR;
284 } 285 }
285 286
322 ngx_uint_t n; 323 ngx_uint_t n;
323 ngx_http_v3_header_t *h; 324 ngx_http_v3_header_t *h;
324 ngx_http_v3_connection_t *h3c; 325 ngx_http_v3_connection_t *h3c;
325 ngx_http_v3_dynamic_table_t *dt; 326 ngx_http_v3_dynamic_table_t *dt;
326 327
327 h3c = c->quic->parent->data; 328 h3c = ngx_http_v3_get_session(c);
328 dt = &h3c->table; 329 dt = &h3c->table;
329 330
330 if (need > dt->capacity) { 331 if (need > dt->capacity) {
331 ngx_log_error(NGX_LOG_ERR, c->log, 0, 332 ngx_log_error(NGX_LOG_ERR, c->log, 0,
332 "not enough dynamic table capacity"); 333 "not enough dynamic table capacity");
365 ngx_http_v3_connection_t *h3c; 366 ngx_http_v3_connection_t *h3c;
366 ngx_http_v3_dynamic_table_t *dt; 367 ngx_http_v3_dynamic_table_t *dt;
367 368
368 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 duplicate %ui", index); 369 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 duplicate %ui", index);
369 370
370 h3c = c->quic->parent->data; 371 h3c = ngx_http_v3_get_session(c);
371 dt = &h3c->table; 372 dt = &h3c->table;
372 373
373 if (dt->base + dt->nelts <= index) { 374 if (dt->base + dt->nelts <= index) {
374 return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR; 375 return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR;
375 } 376 }
449 { 450 {
450 ngx_http_v3_header_t *h; 451 ngx_http_v3_header_t *h;
451 ngx_http_v3_connection_t *h3c; 452 ngx_http_v3_connection_t *h3c;
452 ngx_http_v3_dynamic_table_t *dt; 453 ngx_http_v3_dynamic_table_t *dt;
453 454
454 h3c = c->quic->parent->data; 455 h3c = ngx_http_v3_get_session(c);
455 dt = &h3c->table; 456 dt = &h3c->table;
456 457
457 if (index < dt->base || index - dt->base >= dt->nelts) { 458 if (index < dt->base || index - dt->base >= dt->nelts) {
458 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, 459 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
459 "http3 dynamic[%ui] lookup out of bounds: [%ui,%ui]", 460 "http3 dynamic[%ui] lookup out of bounds: [%ui,%ui]",
492 493
493 if (*insert_count == 0) { 494 if (*insert_count == 0) {
494 return NGX_OK; 495 return NGX_OK;
495 } 496 }
496 497
497 h3c = c->quic->parent->data; 498 h3c = ngx_http_v3_get_session(c);
498 dt = &h3c->table; 499 dt = &h3c->table;
499 500
500 h3scf = ngx_http_get_module_srv_conf(h3c->hc.conf_ctx, ngx_http_v3_module); 501 h3scf = ngx_http_get_module_srv_conf(h3c->hc.conf_ctx, ngx_http_v3_module);
501 502
502 max_entries = h3scf->max_table_capacity / 32; 503 max_entries = h3scf->max_table_capacity / 32;
534 535
535 ngx_int_t 536 ngx_int_t
536 ngx_http_v3_check_insert_count(ngx_connection_t *c, ngx_uint_t insert_count) 537 ngx_http_v3_check_insert_count(ngx_connection_t *c, ngx_uint_t insert_count)
537 { 538 {
538 size_t n; 539 size_t n;
539 ngx_connection_t *pc;
540 ngx_pool_cleanup_t *cln; 540 ngx_pool_cleanup_t *cln;
541 ngx_http_v3_block_t *block; 541 ngx_http_v3_block_t *block;
542 ngx_http_v3_srv_conf_t *h3scf; 542 ngx_http_v3_srv_conf_t *h3scf;
543 ngx_http_v3_connection_t *h3c; 543 ngx_http_v3_connection_t *h3c;
544 ngx_http_v3_dynamic_table_t *dt; 544 ngx_http_v3_dynamic_table_t *dt;
545 545
546 pc = c->quic->parent; 546 h3c = ngx_http_v3_get_session(c);
547 h3c = pc->data;
548 dt = &h3c->table; 547 dt = &h3c->table;
549 548
550 n = dt->base + dt->nelts; 549 n = dt->base + dt->nelts;
551 550
552 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, 551 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
622 ngx_queue_t *q; 621 ngx_queue_t *q;
623 ngx_connection_t *bc; 622 ngx_connection_t *bc;
624 ngx_http_v3_block_t *block; 623 ngx_http_v3_block_t *block;
625 ngx_http_v3_connection_t *h3c; 624 ngx_http_v3_connection_t *h3c;
626 625
627 h3c = c->quic->parent->data; 626 h3c = ngx_http_v3_get_session(c);
628 627
629 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, 628 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
630 "http3 new dynamic header, blocked:%ui", h3c->nblocked); 629 "http3 new dynamic header, blocked:%ui", h3c->nblocked);
631 630
632 while (!ngx_queue_empty(&h3c->blocked)) { 631 while (!ngx_queue_empty(&h3c->blocked)) {