comparison src/event/ngx_event_quic.c @ 8382:b7704303a7e5 quic

Server CID change refactored.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 13 May 2020 18:34:34 +0300
parents 6e100d8c138a
children 7ea34e13937f
comparison
equal deleted inserted replaced
8381:6e100d8c138a 8382:b7704303a7e5
151 151
152 152
153 static ngx_int_t ngx_quic_new_connection(ngx_connection_t *c, ngx_ssl_t *ssl, 153 static ngx_int_t ngx_quic_new_connection(ngx_connection_t *c, ngx_ssl_t *ssl,
154 ngx_quic_tp_t *tp, ngx_quic_header_t *pkt, 154 ngx_quic_tp_t *tp, ngx_quic_header_t *pkt,
155 ngx_connection_handler_pt handler); 155 ngx_connection_handler_pt handler);
156 static ngx_int_t ngx_quic_new_cid(ngx_pool_t *pool, ngx_str_t *sid); 156 static ngx_int_t ngx_quic_new_dcid(ngx_connection_t *c, ngx_str_t *odcid);
157 static ngx_int_t ngx_quic_init_connection(ngx_connection_t *c); 157 static ngx_int_t ngx_quic_init_connection(ngx_connection_t *c);
158 static void ngx_quic_input_handler(ngx_event_t *rev); 158 static void ngx_quic_input_handler(ngx_event_t *rev);
159 159
160 static void ngx_quic_close_connection(ngx_connection_t *c, ngx_int_t rc); 160 static void ngx_quic_close_connection(ngx_connection_t *c, ngx_int_t rc);
161 static ngx_int_t ngx_quic_close_quic(ngx_connection_t *c, ngx_int_t rc); 161 static ngx_int_t ngx_quic_close_quic(ngx_connection_t *c, ngx_int_t rc);
612 qc->congestion.window = ngx_min(10 * qc->tp.max_packet_size, 612 qc->congestion.window = ngx_min(10 * qc->tp.max_packet_size,
613 ngx_max(2 * qc->tp.max_packet_size, 14720)); 613 ngx_max(2 * qc->tp.max_packet_size, 14720));
614 qc->congestion.ssthresh = NGX_MAX_SIZE_T_VALUE; 614 qc->congestion.ssthresh = NGX_MAX_SIZE_T_VALUE;
615 qc->congestion.recovery_start = ngx_current_msec; 615 qc->congestion.recovery_start = ngx_current_msec;
616 616
617 if (ngx_quic_new_cid(c->pool, &qc->dcid) != NGX_OK) { 617 if (ngx_quic_new_dcid(c, &pkt->dcid) != NGX_OK) {
618 return NGX_ERROR; 618 return NGX_ERROR;
619 } 619 }
620
621 #ifdef NGX_QUIC_DEBUG_PACKETS
622 ngx_quic_hexdump(c->log, "quic server CID", qc->dcid.data, qc->dcid.len);
623 #endif
624
625 qc->odcid.len = pkt->dcid.len;
626 qc->odcid.data = ngx_pnalloc(c->pool, qc->odcid.len);
627 if (qc->odcid.data == NULL) {
628 return NGX_ERROR;
629 }
630 ngx_memcpy(qc->odcid.data, pkt->dcid.data, qc->odcid.len);
631 620
632 qc->scid.len = pkt->scid.len; 621 qc->scid.len = pkt->scid.len;
633 qc->scid.data = ngx_pnalloc(c->pool, qc->scid.len); 622 qc->scid.data = ngx_pnalloc(c->pool, qc->scid.len);
634 if (qc->scid.data == NULL) { 623 if (qc->scid.data == NULL) {
635 return NGX_ERROR; 624 return NGX_ERROR;
678 return ngx_quic_input(c, pkt->raw); 667 return ngx_quic_input(c, pkt->raw);
679 } 668 }
680 669
681 670
682 static ngx_int_t 671 static ngx_int_t
683 ngx_quic_new_cid(ngx_pool_t *pool, ngx_str_t *cid) 672 ngx_quic_new_dcid(ngx_connection_t *c, ngx_str_t *odcid)
684 { 673 {
685 uint8_t len; 674 uint8_t len;
675 ngx_quic_connection_t *qc;
676
677 qc = c->quic;
686 678
687 if (RAND_bytes(&len, sizeof(len)) != 1) { 679 if (RAND_bytes(&len, sizeof(len)) != 1) {
688 return NGX_ERROR; 680 return NGX_ERROR;
689 } 681 }
690 682
691 len = len % 10 + 10; 683 len = len % 10 + 10;
692 684
693 cid->len = len; 685 qc->dcid.len = len;
694 cid->data = ngx_pnalloc(pool, len); 686 qc->dcid.data = ngx_pnalloc(c->pool, len);
695 if (cid->data == NULL) { 687 if (qc->dcid.data == NULL) {
696 return NGX_ERROR; 688 return NGX_ERROR;
697 } 689 }
698 690
699 if (RAND_bytes(cid->data, len) != 1) { 691 if (RAND_bytes(qc->dcid.data, len) != 1) {
692 return NGX_ERROR;
693 }
694
695 #ifdef NGX_QUIC_DEBUG_PACKETS
696 ngx_quic_hexdump(c->log, "quic server CID", qc->dcid.data, qc->dcid.len);
697 #endif
698
699 qc->odcid.len = odcid->len;
700 qc->odcid.data = ngx_pstrdup(c->pool, odcid);
701 if (qc->odcid.data == NULL) {
700 return NGX_ERROR; 702 return NGX_ERROR;
701 } 703 }
702 704
703 return NGX_OK; 705 return NGX_OK;
704 } 706 }