Mercurial > hg > nginx-quic
comparison src/event/quic/ngx_event_quic.c @ 8387:76f476ce4d31 quic
QUIC: distinct files for connection migration.
The connection migration-related code from quic.c with dependencies is moved
into separate file.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Wed, 31 Mar 2021 14:57:15 +0300 |
parents | 714e9af983de |
children | fa24745b8c06 |
comparison
equal
deleted
inserted
replaced
8386:714e9af983de | 8387:76f476ce4d31 |
---|---|
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 #include <ngx_event.h> | 9 #include <ngx_event.h> |
10 #include <ngx_event_quic_transport.h> | 10 #include <ngx_event_quic_transport.h> |
11 #include <ngx_event_quic_protection.h> | 11 #include <ngx_event_quic_protection.h> |
12 #include <ngx_event_quic_connection.h> | 12 #include <ngx_event_quic_connection.h> |
13 #include <ngx_event_quic_migration.h> | |
13 #include <ngx_sha1.h> | 14 #include <ngx_sha1.h> |
14 | 15 |
15 | |
16 /* 0-RTT and 1-RTT data exist in the same packet number space, | |
17 * so we have 3 packet number spaces: | |
18 * | |
19 * 0 - Initial | |
20 * 1 - Handshake | |
21 * 2 - 0-RTT and 1-RTT | |
22 */ | |
23 #define ngx_quic_get_send_ctx(qc, level) \ | |
24 ((level) == ssl_encryption_initial) ? &((qc)->send_ctx[0]) \ | |
25 : (((level) == ssl_encryption_handshake) ? &((qc)->send_ctx[1]) \ | |
26 : &((qc)->send_ctx[2])) | |
27 | 16 |
28 #define ngx_quic_lost_threshold(qc) \ | 17 #define ngx_quic_lost_threshold(qc) \ |
29 ngx_max(NGX_QUIC_TIME_THR * ngx_max((qc)->latest_rtt, (qc)->avg_rtt), \ | 18 ngx_max(NGX_QUIC_TIME_THR * ngx_max((qc)->latest_rtt, (qc)->avg_rtt), \ |
30 NGX_QUIC_TIME_GRANULARITY) | 19 NGX_QUIC_TIME_GRANULARITY) |
31 | 20 |
139 static ngx_int_t ngx_quic_handle_ack_frame_range(ngx_connection_t *c, | 128 static ngx_int_t ngx_quic_handle_ack_frame_range(ngx_connection_t *c, |
140 ngx_quic_send_ctx_t *ctx, uint64_t min, uint64_t max, | 129 ngx_quic_send_ctx_t *ctx, uint64_t min, uint64_t max, |
141 ngx_msec_t *send_time); | 130 ngx_msec_t *send_time); |
142 static void ngx_quic_rtt_sample(ngx_connection_t *c, ngx_quic_ack_frame_t *ack, | 131 static void ngx_quic_rtt_sample(ngx_connection_t *c, ngx_quic_ack_frame_t *ack, |
143 enum ssl_encryption_level_t level, ngx_msec_t send_time); | 132 enum ssl_encryption_level_t level, ngx_msec_t send_time); |
144 static ngx_inline ngx_msec_t ngx_quic_pto(ngx_connection_t *c, | |
145 ngx_quic_send_ctx_t *ctx); | |
146 static void ngx_quic_handle_stream_ack(ngx_connection_t *c, | 133 static void ngx_quic_handle_stream_ack(ngx_connection_t *c, |
147 ngx_quic_frame_t *f); | 134 ngx_quic_frame_t *f); |
148 | 135 |
149 static ngx_int_t ngx_quic_handle_ordered_frame(ngx_connection_t *c, | 136 static ngx_int_t ngx_quic_handle_ordered_frame(ngx_connection_t *c, |
150 ngx_quic_frames_stream_t *fs, ngx_quic_frame_t *frame, | 137 ngx_quic_frames_stream_t *fs, ngx_quic_frame_t *frame, |
175 ngx_quic_header_t *pkt, ngx_quic_reset_stream_frame_t *f); | 162 ngx_quic_header_t *pkt, ngx_quic_reset_stream_frame_t *f); |
176 static ngx_int_t ngx_quic_handle_stop_sending_frame(ngx_connection_t *c, | 163 static ngx_int_t ngx_quic_handle_stop_sending_frame(ngx_connection_t *c, |
177 ngx_quic_header_t *pkt, ngx_quic_stop_sending_frame_t *f); | 164 ngx_quic_header_t *pkt, ngx_quic_stop_sending_frame_t *f); |
178 static ngx_int_t ngx_quic_handle_max_streams_frame(ngx_connection_t *c, | 165 static ngx_int_t ngx_quic_handle_max_streams_frame(ngx_connection_t *c, |
179 ngx_quic_header_t *pkt, ngx_quic_max_streams_frame_t *f); | 166 ngx_quic_header_t *pkt, ngx_quic_max_streams_frame_t *f); |
180 static ngx_int_t ngx_quic_handle_path_challenge_frame(ngx_connection_t *c, | |
181 ngx_quic_header_t *pkt, ngx_quic_path_challenge_frame_t *f); | |
182 static ngx_int_t ngx_quic_handle_new_connection_id_frame(ngx_connection_t *c, | 167 static ngx_int_t ngx_quic_handle_new_connection_id_frame(ngx_connection_t *c, |
183 ngx_quic_header_t *pkt, ngx_quic_new_conn_id_frame_t *f); | 168 ngx_quic_header_t *pkt, ngx_quic_new_conn_id_frame_t *f); |
184 static ngx_int_t ngx_quic_retire_connection_id(ngx_connection_t *c, | 169 static ngx_int_t ngx_quic_retire_connection_id(ngx_connection_t *c, |
185 enum ssl_encryption_level_t level, uint64_t seqnum); | 170 enum ssl_encryption_level_t level, uint64_t seqnum); |
186 static ngx_int_t ngx_quic_handle_retire_connection_id_frame(ngx_connection_t *c, | 171 static ngx_int_t ngx_quic_handle_retire_connection_id_frame(ngx_connection_t *c, |
2753 return NGX_ERROR; | 2738 return NGX_ERROR; |
2754 } | 2739 } |
2755 | 2740 |
2756 break; | 2741 break; |
2757 | 2742 |
2743 case NGX_QUIC_FT_PATH_RESPONSE: | |
2744 | |
2745 if (ngx_quic_handle_path_response_frame(c, pkt, | |
2746 &frame.u.path_response) | |
2747 != NGX_OK) | |
2748 { | |
2749 return NGX_ERROR; | |
2750 } | |
2751 | |
2752 break; | |
2753 | |
2758 case NGX_QUIC_FT_NEW_CONNECTION_ID: | 2754 case NGX_QUIC_FT_NEW_CONNECTION_ID: |
2759 | 2755 |
2760 if (ngx_quic_handle_new_connection_id_frame(c, pkt, &frame.u.ncid) | 2756 if (ngx_quic_handle_new_connection_id_frame(c, pkt, &frame.u.ncid) |
2761 != NGX_OK) | 2757 != NGX_OK) |
2762 { | 2758 { |
2772 != NGX_OK) | 2768 != NGX_OK) |
2773 { | 2769 { |
2774 return NGX_ERROR; | 2770 return NGX_ERROR; |
2775 } | 2771 } |
2776 | 2772 |
2777 break; | |
2778 | |
2779 case NGX_QUIC_FT_PATH_RESPONSE: | |
2780 | |
2781 /* TODO: handle */ | |
2782 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, | |
2783 "quic frame handler not implemented"); | |
2784 break; | 2773 break; |
2785 | 2774 |
2786 default: | 2775 default: |
2787 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, | 2776 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
2788 "quic missing frame handler"); | 2777 "quic missing frame handler"); |
3508 "quic rtt sample latest:%M min:%M avg:%M var:%M", | 3497 "quic rtt sample latest:%M min:%M avg:%M var:%M", |
3509 latest_rtt, qc->min_rtt, qc->avg_rtt, qc->rttvar); | 3498 latest_rtt, qc->min_rtt, qc->avg_rtt, qc->rttvar); |
3510 } | 3499 } |
3511 | 3500 |
3512 | 3501 |
3513 static ngx_inline ngx_msec_t | 3502 ngx_msec_t |
3514 ngx_quic_pto(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx) | 3503 ngx_quic_pto(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx) |
3515 { | 3504 { |
3516 ngx_msec_t duration; | 3505 ngx_msec_t duration; |
3517 ngx_quic_connection_t *qc; | 3506 ngx_quic_connection_t *qc; |
3518 | 3507 |
4370 | 4359 |
4371 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, | 4360 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
4372 "quic max_streams_uni:%uL", f->limit); | 4361 "quic max_streams_uni:%uL", f->limit); |
4373 } | 4362 } |
4374 } | 4363 } |
4375 | |
4376 return NGX_OK; | |
4377 } | |
4378 | |
4379 | |
4380 static ngx_int_t | |
4381 ngx_quic_handle_path_challenge_frame(ngx_connection_t *c, | |
4382 ngx_quic_header_t *pkt, ngx_quic_path_challenge_frame_t *f) | |
4383 { | |
4384 ngx_quic_frame_t *frame; | |
4385 ngx_quic_connection_t *qc; | |
4386 | |
4387 qc = ngx_quic_get_connection(c); | |
4388 | |
4389 frame = ngx_quic_alloc_frame(c); | |
4390 if (frame == NULL) { | |
4391 return NGX_ERROR; | |
4392 } | |
4393 | |
4394 frame->level = pkt->level; | |
4395 frame->type = NGX_QUIC_FT_PATH_RESPONSE; | |
4396 frame->u.path_response = *f; | |
4397 | |
4398 ngx_quic_queue_frame(qc, frame); | |
4399 | 4364 |
4400 return NGX_OK; | 4365 return NGX_OK; |
4401 } | 4366 } |
4402 | 4367 |
4403 | 4368 |