QUIC: application init() callback.
It's called after handshake completion or prior to the first early data stream creation. The callback should initialize application-level data before creating streams. HTTP/3 callback implementation sets keepalive timer and sends SETTINGS. Also, this allows to limit max handshake time in ngx_http_v3_init_stream().
This commit is contained in:
parent
2fb971a6b9
commit
aa58c6457a
|
@ -28,6 +28,7 @@
|
|||
#define NGX_QUIC_STREAM_UNIDIRECTIONAL 0x02
|
||||
|
||||
|
||||
typedef ngx_int_t (*ngx_quic_init_pt)(ngx_connection_t *c);
|
||||
typedef void (*ngx_quic_shutdown_pt)(ngx_connection_t *c);
|
||||
|
||||
|
||||
|
@ -77,6 +78,7 @@ typedef struct {
|
|||
ngx_int_t stream_reject_code_uni;
|
||||
ngx_int_t stream_reject_code_bidi;
|
||||
|
||||
ngx_quic_init_pt init;
|
||||
ngx_quic_shutdown_pt shutdown;
|
||||
|
||||
u_char av_token_key[NGX_QUIC_AV_KEY_LEN];
|
||||
|
|
|
@ -21,6 +21,7 @@ static ngx_quic_stream_t *ngx_quic_get_stream(ngx_connection_t *c, uint64_t id);
|
|||
static ngx_int_t ngx_quic_reject_stream(ngx_connection_t *c, uint64_t id);
|
||||
static void ngx_quic_init_stream_handler(ngx_event_t *ev);
|
||||
static void ngx_quic_init_streams_handler(ngx_connection_t *c);
|
||||
static ngx_int_t ngx_quic_do_init_streams(ngx_connection_t *c);
|
||||
static ngx_quic_stream_t *ngx_quic_create_stream(ngx_connection_t *c,
|
||||
uint64_t id);
|
||||
static void ngx_quic_empty_handler(ngx_event_t *ev);
|
||||
|
@ -555,14 +556,21 @@ ngx_quic_init_streams(ngx_connection_t *c)
|
|||
return NGX_OK;
|
||||
}
|
||||
|
||||
ngx_quic_init_streams_handler(c);
|
||||
|
||||
return NGX_OK;
|
||||
return ngx_quic_do_init_streams(c);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
ngx_quic_init_streams_handler(ngx_connection_t *c)
|
||||
{
|
||||
if (ngx_quic_do_init_streams(c) != NGX_OK) {
|
||||
ngx_quic_close_connection(c, NGX_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static ngx_int_t
|
||||
ngx_quic_do_init_streams(ngx_connection_t *c)
|
||||
{
|
||||
ngx_queue_t *q;
|
||||
ngx_quic_stream_t *qs;
|
||||
|
@ -572,6 +580,12 @@ ngx_quic_init_streams_handler(ngx_connection_t *c)
|
|||
|
||||
qc = ngx_quic_get_connection(c);
|
||||
|
||||
if (qc->conf->init) {
|
||||
if (qc->conf->init(c) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
for (q = ngx_queue_head(&qc->streams.uninitialized);
|
||||
q != ngx_queue_sentinel(&qc->streams.uninitialized);
|
||||
q = ngx_queue_next(q))
|
||||
|
@ -581,6 +595,8 @@ ngx_quic_init_streams_handler(ngx_connection_t *c)
|
|||
}
|
||||
|
||||
qc->streams.initialized = 1;
|
||||
|
||||
return NGX_OK;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ static void ngx_http_v3_cleanup_session(void *data);
|
|||
ngx_int_t
|
||||
ngx_http_v3_init_session(ngx_connection_t *c)
|
||||
{
|
||||
ngx_connection_t *pc;
|
||||
ngx_pool_cleanup_t *cln;
|
||||
ngx_http_connection_t *hc;
|
||||
ngx_http_v3_session_t *h3c;
|
||||
|
@ -25,16 +24,11 @@ ngx_http_v3_init_session(ngx_connection_t *c)
|
|||
ngx_http_v3_srv_conf_t *h3scf;
|
||||
#endif
|
||||
|
||||
pc = c->quic->parent;
|
||||
hc = pc->data;
|
||||
|
||||
if (hc->v3_session) {
|
||||
return NGX_OK;
|
||||
}
|
||||
hc = c->data;
|
||||
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init session");
|
||||
|
||||
h3c = ngx_pcalloc(pc->pool, sizeof(ngx_http_v3_session_t));
|
||||
h3c = ngx_pcalloc(c->pool, sizeof(ngx_http_v3_session_t));
|
||||
if (h3c == NULL) {
|
||||
goto failed;
|
||||
}
|
||||
|
@ -52,15 +46,15 @@ ngx_http_v3_init_session(ngx_connection_t *c)
|
|||
ngx_queue_init(&h3c->blocked);
|
||||
ngx_queue_init(&h3c->pushing);
|
||||
|
||||
h3c->keepalive.log = pc->log;
|
||||
h3c->keepalive.data = pc;
|
||||
h3c->keepalive.log = c->log;
|
||||
h3c->keepalive.data = c;
|
||||
h3c->keepalive.handler = ngx_http_v3_keepalive_handler;
|
||||
|
||||
h3c->table.send_insert_count.log = pc->log;
|
||||
h3c->table.send_insert_count.data = pc;
|
||||
h3c->table.send_insert_count.log = c->log;
|
||||
h3c->table.send_insert_count.data = c;
|
||||
h3c->table.send_insert_count.handler = ngx_http_v3_inc_insert_count_handler;
|
||||
|
||||
cln = ngx_pool_cleanup_add(pc->pool, 0);
|
||||
cln = ngx_pool_cleanup_add(c->pool, 0);
|
||||
if (cln == NULL) {
|
||||
goto failed;
|
||||
}
|
||||
|
@ -70,13 +64,7 @@ ngx_http_v3_init_session(ngx_connection_t *c)
|
|||
|
||||
hc->v3_session = h3c;
|
||||
|
||||
#if (NGX_HTTP_V3_HQ)
|
||||
if (h3c->hq) {
|
||||
return NGX_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ngx_http_v3_send_settings(c);
|
||||
return NGX_OK;
|
||||
|
||||
failed:
|
||||
|
||||
|
|
|
@ -159,6 +159,7 @@ void ngx_http_v3_init_stream(ngx_connection_t *c);
|
|||
void ngx_http_v3_reset_stream(ngx_connection_t *c);
|
||||
ngx_int_t ngx_http_v3_init_session(ngx_connection_t *c);
|
||||
ngx_int_t ngx_http_v3_check_flood(ngx_connection_t *c);
|
||||
ngx_int_t ngx_http_v3_init(ngx_connection_t *c);
|
||||
void ngx_http_v3_shutdown(ngx_connection_t *c);
|
||||
|
||||
ngx_int_t ngx_http_v3_read_request_body(ngx_http_request_t *r);
|
||||
|
|
|
@ -249,6 +249,7 @@ ngx_http_v3_create_srv_conf(ngx_conf_t *cf)
|
|||
h3scf->quic.stream_reject_code_bidi = NGX_HTTP_V3_ERR_REQUEST_REJECTED;
|
||||
h3scf->quic.active_connection_id_limit = NGX_CONF_UNSET_UINT;
|
||||
|
||||
h3scf->quic.init = ngx_http_v3_init;
|
||||
h3scf->quic.shutdown = ngx_http_v3_shutdown;
|
||||
|
||||
return h3scf;
|
||||
|
|
|
@ -57,18 +57,29 @@ static const struct {
|
|||
void
|
||||
ngx_http_v3_init_stream(ngx_connection_t *c)
|
||||
{
|
||||
ngx_http_v3_session_t *h3c;
|
||||
ngx_http_connection_t *hc, *phc;
|
||||
ngx_http_v3_srv_conf_t *h3scf;
|
||||
ngx_http_core_loc_conf_t *clcf;
|
||||
ngx_http_core_srv_conf_t *cscf;
|
||||
|
||||
hc = c->data;
|
||||
|
||||
hc->ssl = 1;
|
||||
|
||||
clcf = ngx_http_get_module_loc_conf(hc->conf_ctx, ngx_http_core_module);
|
||||
cscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_core_module);
|
||||
h3scf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_v3_module);
|
||||
|
||||
if (c->quic == NULL) {
|
||||
if (ngx_http_v3_init_session(c) != NGX_OK) {
|
||||
ngx_http_close_connection(c);
|
||||
return;
|
||||
}
|
||||
|
||||
h3c = hc->v3_session;
|
||||
ngx_add_timer(&h3c->keepalive, cscf->client_header_timeout);
|
||||
|
||||
h3scf->quic.timeout = clcf->keepalive_timeout;
|
||||
ngx_quic_run(c, &h3scf->quic);
|
||||
return;
|
||||
|
@ -86,11 +97,6 @@ ngx_http_v3_init_stream(ngx_connection_t *c)
|
|||
ngx_set_connection_log(c, clcf->error_log);
|
||||
}
|
||||
|
||||
if (ngx_http_v3_init_session(c) != NGX_OK) {
|
||||
ngx_http_close_connection(c);
|
||||
return;
|
||||
}
|
||||
|
||||
if (c->quic->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) {
|
||||
ngx_http_v3_init_uni_stream(c);
|
||||
|
||||
|
@ -100,6 +106,28 @@ ngx_http_v3_init_stream(ngx_connection_t *c)
|
|||
}
|
||||
|
||||
|
||||
ngx_int_t
|
||||
ngx_http_v3_init(ngx_connection_t *c)
|
||||
{
|
||||
ngx_http_v3_session_t *h3c;
|
||||
ngx_http_core_loc_conf_t *clcf;
|
||||
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init");
|
||||
|
||||
h3c = ngx_http_v3_get_session(c);
|
||||
clcf = ngx_http_v3_get_module_loc_conf(c, ngx_http_core_module);
|
||||
ngx_add_timer(&h3c->keepalive, clcf->keepalive_timeout);
|
||||
|
||||
#if (NGX_HTTP_V3_HQ)
|
||||
if (h3c->hq) {
|
||||
return NGX_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ngx_http_v3_send_settings(c);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ngx_http_v3_shutdown(ngx_connection_t *c)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue