Respect QUIC max_idle_timeout.

This commit is contained in:
Roman Arutyunyan 2020-03-23 21:20:20 +03:00
parent 9975b088bb
commit 5ac5e51fdf
4 changed files with 27 additions and 14 deletions

View File

@ -30,7 +30,6 @@ typedef struct {
typedef struct {
ngx_rbtree_t tree;
ngx_rbtree_node_t sentinel;
ngx_msec_t timeout;
ngx_connection_handler_pt handler;
ngx_uint_t id_counter;
@ -59,6 +58,8 @@ struct ngx_quic_connection_s {
ngx_quic_streams_t streams;
ngx_uint_t max_data;
ngx_uint_t send_timer_set;
/* unsigned send_timer_set:1 */
#define SSL_ECRYPTION_LAST ((ssl_encryption_application) + 1)
uint64_t crypto_offset[SSL_ECRYPTION_LAST];
@ -255,6 +256,12 @@ ngx_quic_add_handshake_data(ngx_ssl_conn_t *ssl_conn,
return NGX_ERROR;
}
if (qc->ctp.max_idle_timeout > 0
&& qc->ctp.max_idle_timeout < qc->tp.max_idle_timeout)
{
qc->tp.max_idle_timeout = qc->ctp.max_idle_timeout;
}
qc->client_tp_done = 1;
}
}
@ -334,7 +341,7 @@ ngx_quic_send_alert(ngx_ssl_conn_t *ssl_conn, enum ssl_encryption_level_t level,
void
ngx_quic_run(ngx_connection_t *c, ngx_ssl_t *ssl, ngx_quic_tp_t *tp,
ngx_msec_t timeout, ngx_connection_handler_pt handler)
ngx_connection_handler_pt handler)
{
ngx_buf_t *b;
ngx_quic_header_t pkt;
@ -359,9 +366,8 @@ ngx_quic_run(ngx_connection_t *c, ngx_ssl_t *ssl, ngx_quic_tp_t *tp,
// we don't need stream handler for initial packet processing
c->quic->streams.handler = handler;
c->quic->streams.timeout = timeout;
ngx_add_timer(c->read, timeout);
ngx_add_timer(c->read, c->quic->tp.max_idle_timeout);
c->read->handler = ngx_quic_input_handler;
@ -524,9 +530,10 @@ ngx_quic_init_connection(ngx_connection_t *c)
static void
ngx_quic_input_handler(ngx_event_t *rev)
{
ssize_t n;
ngx_buf_t b;
ngx_connection_t *c;
ssize_t n;
ngx_buf_t b;
ngx_connection_t *c;
ngx_quic_connection_t *qc;
static u_char buf[65535];
@ -544,8 +551,6 @@ ngx_quic_input_handler(ngx_event_t *rev)
return;
}
ngx_add_timer(rev, c->quic->streams.timeout);
if (c->close) {
ngx_quic_close_connection(c);
return;
@ -569,6 +574,11 @@ ngx_quic_input_handler(ngx_event_t *rev)
ngx_quic_close_connection(c);
return;
}
qc = c->quic;
qc->send_timer_set = 0;
ngx_add_timer(rev, qc->tp.max_idle_timeout);
}
@ -1209,6 +1219,11 @@ ngx_quic_output(ngx_connection_t *c)
qc->frames = NULL;
if (!qc->send_timer_set) {
qc->send_timer_set = 1;
ngx_add_timer(c->read, qc->tp.max_idle_timeout);
}
return NGX_OK;
}

View File

@ -54,7 +54,7 @@ struct ngx_quic_stream_s {
void ngx_quic_run(ngx_connection_t *c, ngx_ssl_t *ssl, ngx_quic_tp_t *tp,
ngx_msec_t timeout, ngx_connection_handler_pt handler);
ngx_connection_handler_pt handler);
ngx_connection_t *ngx_quic_create_uni_stream(ngx_connection_t *c);

View File

@ -347,9 +347,7 @@ ngx_http_init_connection(ngx_connection_t *c)
v3cf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_v3_module);
sscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_ssl_module);
ngx_quic_run(c, &sscf->ssl, &v3cf->quic,
c->listening->post_accept_timeout,
ngx_http_quic_stream_handler);
ngx_quic_run(c, &sscf->ssl, &v3cf->quic, ngx_http_quic_stream_handler);
return;
}
#endif

View File

@ -229,7 +229,7 @@ ngx_http_v3_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_http_v3_srv_conf_t *conf = child;
ngx_conf_merge_msec_value(conf->quic.max_idle_timeout,
prev->quic.max_idle_timeout, 10000);
prev->quic.max_idle_timeout, 60000);
// > 2 ^ 14 is invalid
ngx_conf_merge_msec_value(conf->quic.max_ack_delay,