comparison src/event/quic/ngx_event_quic_streams.c @ 9058:b0c2234aaa9f quic

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().
author Roman Arutyunyan <arut@nginx.com>
date Wed, 30 Nov 2022 12:51:15 +0400
parents 740d7d6e8ff0
children e3760b9b7c8e
comparison
equal deleted inserted replaced
9057:7b83da3bdf9f 9058:b0c2234aaa9f
19 static ngx_int_t ngx_quic_shutdown_stream_recv(ngx_connection_t *c); 19 static ngx_int_t ngx_quic_shutdown_stream_recv(ngx_connection_t *c);
20 static ngx_quic_stream_t *ngx_quic_get_stream(ngx_connection_t *c, uint64_t id); 20 static ngx_quic_stream_t *ngx_quic_get_stream(ngx_connection_t *c, uint64_t id);
21 static ngx_int_t ngx_quic_reject_stream(ngx_connection_t *c, uint64_t id); 21 static ngx_int_t ngx_quic_reject_stream(ngx_connection_t *c, uint64_t id);
22 static void ngx_quic_init_stream_handler(ngx_event_t *ev); 22 static void ngx_quic_init_stream_handler(ngx_event_t *ev);
23 static void ngx_quic_init_streams_handler(ngx_connection_t *c); 23 static void ngx_quic_init_streams_handler(ngx_connection_t *c);
24 static ngx_int_t ngx_quic_do_init_streams(ngx_connection_t *c);
24 static ngx_quic_stream_t *ngx_quic_create_stream(ngx_connection_t *c, 25 static ngx_quic_stream_t *ngx_quic_create_stream(ngx_connection_t *c,
25 uint64_t id); 26 uint64_t id);
26 static void ngx_quic_empty_handler(ngx_event_t *ev); 27 static void ngx_quic_empty_handler(ngx_event_t *ev);
27 static ssize_t ngx_quic_stream_recv(ngx_connection_t *c, u_char *buf, 28 static ssize_t ngx_quic_stream_recv(ngx_connection_t *c, u_char *buf,
28 size_t size); 29 size_t size);
553 if (rc == NGX_AGAIN) { 554 if (rc == NGX_AGAIN) {
554 c->ssl->handler = ngx_quic_init_streams_handler; 555 c->ssl->handler = ngx_quic_init_streams_handler;
555 return NGX_OK; 556 return NGX_OK;
556 } 557 }
557 558
558 ngx_quic_init_streams_handler(c); 559 return ngx_quic_do_init_streams(c);
559
560 return NGX_OK;
561 } 560 }
562 561
563 562
564 static void 563 static void
565 ngx_quic_init_streams_handler(ngx_connection_t *c) 564 ngx_quic_init_streams_handler(ngx_connection_t *c)
566 { 565 {
566 if (ngx_quic_do_init_streams(c) != NGX_OK) {
567 ngx_quic_close_connection(c, NGX_ERROR);
568 }
569 }
570
571
572 static ngx_int_t
573 ngx_quic_do_init_streams(ngx_connection_t *c)
574 {
567 ngx_queue_t *q; 575 ngx_queue_t *q;
568 ngx_quic_stream_t *qs; 576 ngx_quic_stream_t *qs;
569 ngx_quic_connection_t *qc; 577 ngx_quic_connection_t *qc;
570 578
571 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic init streams"); 579 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic init streams");
572 580
573 qc = ngx_quic_get_connection(c); 581 qc = ngx_quic_get_connection(c);
582
583 if (qc->conf->init) {
584 if (qc->conf->init(c) != NGX_OK) {
585 return NGX_ERROR;
586 }
587 }
574 588
575 for (q = ngx_queue_head(&qc->streams.uninitialized); 589 for (q = ngx_queue_head(&qc->streams.uninitialized);
576 q != ngx_queue_sentinel(&qc->streams.uninitialized); 590 q != ngx_queue_sentinel(&qc->streams.uninitialized);
577 q = ngx_queue_next(q)) 591 q = ngx_queue_next(q))
578 { 592 {
579 qs = ngx_queue_data(q, ngx_quic_stream_t, queue); 593 qs = ngx_queue_data(q, ngx_quic_stream_t, queue);
580 ngx_post_event(qs->connection->read, &ngx_posted_events); 594 ngx_post_event(qs->connection->read, &ngx_posted_events);
581 } 595 }
582 596
583 qc->streams.initialized = 1; 597 qc->streams.initialized = 1;
598
599 return NGX_OK;
584 } 600 }
585 601
586 602
587 static ngx_quic_stream_t * 603 static ngx_quic_stream_t *
588 ngx_quic_create_stream(ngx_connection_t *c, uint64_t id) 604 ngx_quic_create_stream(ngx_connection_t *c, uint64_t id)