To simplify code dealing with stream states when both client and server are supported, instead of 8 named fields, use two structures split into uni/bidi and client/server.
src/event/quic/ngx_event_quic.c | 8 ++-- src/event/quic/ngx_event_quic_ack.c | 4 +- src/event/quic/ngx_event_quic_connection.h | 23 +++++++---- src/event/quic/ngx_event_quic_streams.c | 60 +++++++++++++++--------------- 4 files changed, 50 insertions(+), 45 deletions(-)
# HG changeset patch # User Vladimir Khomutov <[email protected]> # Date 1697113160 -10800 # Thu Oct 12 15:19:20 2023 +0300 # Node ID f54423e057f909b1d644cc0af316d67b91cd408f # Parent f30bd37ac6b6b2f051883d0173942794ea73d8fb QUIC: added a structure for stream limits/counters. To simplify code dealing with stream states when both client and server are supported, instead of 8 named fields, use two structures split into uni/bidi and client/server. diff --git a/src/event/quic/ngx_event_quic.c b/src/event/quic/ngx_event_quic.c --- a/src/event/quic/ngx_event_quic.c +++ b/src/event/quic/ngx_event_quic.c @@ -185,8 +185,8 @@ ngx_quic_apply_transport_params(ngx_conn qc->tp.max_idle_timeout = peer_tp->max_idle_timeout; } - qc->streams.server_max_streams_bidi = peer_tp->initial_max_streams_bidi; - qc->streams.server_max_streams_uni = peer_tp->initial_max_streams_uni; + qc->streams.server.bidi.max = peer_tp->initial_max_streams_bidi; + qc->streams.server.uni.max = peer_tp->initial_max_streams_uni; ngx_memcpy(&qc->peer_tp, peer_tp, sizeof(ngx_quic_tp_t)); @@ -303,8 +303,8 @@ ngx_quic_new_connection(ngx_connection_t qc->streams.recv_max_data = qc->tp.initial_max_data; qc->streams.recv_window = qc->streams.recv_max_data; - qc->streams.client_max_streams_uni = qc->tp.initial_max_streams_uni; - qc->streams.client_max_streams_bidi = qc->tp.initial_max_streams_bidi; + qc->streams.client.uni.max = qc->tp.initial_max_streams_uni; + qc->streams.client.bidi.max = qc->tp.initial_max_streams_bidi; qc->congestion.window = ngx_min(10 * qc->tp.max_udp_payload_size, ngx_max(2 * qc->tp.max_udp_payload_size, diff --git a/src/event/quic/ngx_event_quic_ack.c b/src/event/quic/ngx_event_quic_ack.c --- a/src/event/quic/ngx_event_quic_ack.c +++ b/src/event/quic/ngx_event_quic_ack.c @@ -614,8 +614,8 @@ ngx_quic_resend_frames(ngx_connection_t case NGX_QUIC_FT_MAX_STREAMS: case NGX_QUIC_FT_MAX_STREAMS2: f->u.max_streams.limit = f->u.max_streams.bidi - ? qc->streams.client_max_streams_bidi - : qc->streams.client_max_streams_uni; + ? qc->streams.client.bidi.max + : qc->streams.client.uni.max; ngx_quic_queue_frame(qc, f); break; diff --git a/src/event/quic/ngx_event_quic_connection.h b/src/event/quic/ngx_event_quic_connection.h --- a/src/event/quic/ngx_event_quic_connection.h +++ b/src/event/quic/ngx_event_quic_connection.h @@ -136,6 +136,18 @@ struct ngx_quic_socket_s { typedef struct { + uint64_t max; + uint64_t count; +} ngx_quic_stream_ctl_t; + + +typedef struct { + ngx_quic_stream_ctl_t uni; + ngx_quic_stream_ctl_t bidi; +} ngx_quic_stream_peer_t; + + +typedef struct { ngx_rbtree_t tree; ngx_rbtree_node_t sentinel; @@ -150,15 +162,8 @@ typedef struct { uint64_t send_offset; uint64_t send_max_data; - uint64_t server_max_streams_uni; - uint64_t server_max_streams_bidi; - uint64_t server_streams_uni; - uint64_t server_streams_bidi; - - uint64_t client_max_streams_uni; - uint64_t client_max_streams_bidi; - uint64_t client_streams_uni; - uint64_t client_streams_bidi; + ngx_quic_stream_peer_t server; + ngx_quic_stream_peer_t client; ngx_uint_t initialized; /* unsigned initialized:1; */ diff --git a/src/event/quic/ngx_event_quic_streams.c b/src/event/quic/ngx_event_quic_streams.c --- a/src/event/quic/ngx_event_quic_streams.c +++ b/src/event/quic/ngx_event_quic_streams.c @@ -59,47 +59,47 @@ ngx_quic_open_stream(ngx_connection_t *c } if (bidi) { - if (qc->streams.server_streams_bidi - >= qc->streams.server_max_streams_bidi) + if (qc->streams.server.bidi.count + >= qc->streams.server.bidi.max) { ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic too many server bidi streams:%uL", - qc->streams.server_streams_bidi); + qc->streams.server.bidi.count); return NULL; } - id = (qc->streams.server_streams_bidi << 2) + id = (qc->streams.server.bidi.count << 2) | NGX_QUIC_STREAM_SERVER_INITIATED; ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic creating server bidi stream" " streams:%uL max:%uL id:0x%xL", - qc->streams.server_streams_bidi, - qc->streams.server_max_streams_bidi, id); + qc->streams.server.bidi.count, + qc->streams.server.bidi.max, id); - qc->streams.server_streams_bidi++; + qc->streams.server.bidi.count++; } else { - if (qc->streams.server_streams_uni - >= qc->streams.server_max_streams_uni) + if (qc->streams.server.uni.count + >= qc->streams.server.uni.max) { ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic too many server uni streams:%uL", - qc->streams.server_streams_uni); + qc->streams.server.uni.count); return NULL; } - id = (qc->streams.server_streams_uni << 2) + id = (qc->streams.server.uni.count << 2) | NGX_QUIC_STREAM_SERVER_INITIATED | NGX_QUIC_STREAM_UNIDIRECTIONAL; ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic creating server uni stream" " streams:%uL max:%uL id:0x%xL", - qc->streams.server_streams_uni, - qc->streams.server_max_streams_uni, id); + qc->streams.server.uni.count, + qc->streams.server.uni.max, id); - qc->streams.server_streams_uni++; + qc->streams.server.uni.count++; } qs = ngx_quic_create_stream(pc, id); @@ -397,7 +397,7 @@ ngx_quic_get_stream(ngx_connection_t *c, if (id & NGX_QUIC_STREAM_UNIDIRECTIONAL) { if (id & NGX_QUIC_STREAM_SERVER_INITIATED) { - if ((id >> 2) < qc->streams.server_streams_uni) { + if ((id >> 2) < qc->streams.server.uni.count) { return NGX_QUIC_STREAM_GONE; } @@ -405,23 +405,23 @@ ngx_quic_get_stream(ngx_connection_t *c, return NULL; } - if ((id >> 2) < qc->streams.client_streams_uni) { + if ((id >> 2) < qc->streams.client.uni.count) { return NGX_QUIC_STREAM_GONE; } - if ((id >> 2) >= qc->streams.client_max_streams_uni) { + if ((id >> 2) >= qc->streams.client.uni.max) { qc->error = NGX_QUIC_ERR_STREAM_LIMIT_ERROR; return NULL; } - min_id = (qc->streams.client_streams_uni << 2) + min_id = (qc->streams.client.uni.count << 2) | NGX_QUIC_STREAM_UNIDIRECTIONAL; - qc->streams.client_streams_uni = (id >> 2) + 1; + qc->streams.client.uni.count = (id >> 2) + 1; } else { if (id & NGX_QUIC_STREAM_SERVER_INITIATED) { - if ((id >> 2) < qc->streams.server_streams_bidi) { + if ((id >> 2) < qc->streams.server.bidi.count) { return NGX_QUIC_STREAM_GONE; } @@ -429,17 +429,17 @@ ngx_quic_get_stream(ngx_connection_t *c, return NULL; } - if ((id >> 2) < qc->streams.client_streams_bidi) { + if ((id >> 2) < qc->streams.client.bidi.count) { return NGX_QUIC_STREAM_GONE; } - if ((id >> 2) >= qc->streams.client_max_streams_bidi) { + if ((id >> 2) >= qc->streams.client.bidi.max) { qc->error = NGX_QUIC_ERR_STREAM_LIMIT_ERROR; return NULL; } - min_id = (qc->streams.client_streams_bidi << 2); - qc->streams.client_streams_bidi = (id >> 2) + 1; + min_id = (qc->streams.client.bidi.count << 2); + qc->streams.client.bidi.count = (id >> 2) + 1; } /* @@ -1176,11 +1176,11 @@ ngx_quic_close_stream(ngx_quic_stream_t frame->type = NGX_QUIC_FT_MAX_STREAMS; if (qs->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) { - frame->u.max_streams.limit = ++qc->streams.client_max_streams_uni; + frame->u.max_streams.limit = ++qc->streams.client.uni.max; frame->u.max_streams.bidi = 0; } else { - frame->u.max_streams.limit = ++qc->streams.client_max_streams_bidi; + frame->u.max_streams.limit = ++qc->streams.client.bidi.max; frame->u.max_streams.bidi = 1; } @@ -1559,16 +1559,16 @@ ngx_quic_handle_max_streams_frame(ngx_co qc = ngx_quic_get_connection(c); if (f->bidi) { - if (qc->streams.server_max_streams_bidi < f->limit) { - qc->streams.server_max_streams_bidi = f->limit; + if (qc->streams.server.bidi.max < f->limit) { + qc->streams.server.bidi.max = f->limit; ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic max_streams_bidi:%uL", f->limit); } } else { - if (qc->streams.server_max_streams_uni < f->limit) { - qc->streams.server_max_streams_uni = f->limit; + if (qc->streams.server.uni.max < f->limit) { + qc->streams.server.uni.max = f->limit; ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic max_streams_uni:%uL", f->limit);
_______________________________________________ nginx-devel mailing list [email protected] https://mailman.nginx.org/mailman/listinfo/nginx-devel
