forked from alibaba/xquic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxqc_stream.c
1758 lines (1477 loc) · 66 KB
/
xqc_stream.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* @copyright Copyright (c) 2022, Alibaba Group Holding Limited
*/
#include "src/common/xqc_memory_pool.h"
#include "src/common/xqc_id_hash.h"
#include "src/transport/xqc_conn.h"
#include "src/transport/xqc_stream.h"
#include "src/transport/xqc_packet_parser.h"
#include "src/transport/xqc_frame_parser.h"
#include "src/transport/xqc_packet_out.h"
#include "src/transport/xqc_send_ctl.h"
#include "src/transport/xqc_frame.h"
#include "src/transport/xqc_engine.h"
#include "src/transport/xqc_packet.h"
#include "src/transport/xqc_utils.h"
#include "src/transport/xqc_pacing.h"
#include "src/tls/xqc_tls.h"
static xqc_stream_id_t
xqc_gen_stream_id(xqc_connection_t *conn, xqc_stream_type_t type)
{
xqc_stream_id_t sid = 0;
if (type == XQC_CLI_BID || type == XQC_SVR_BID) {
sid = conn->cur_stream_id_bidi_local++;
} else if (type == XQC_CLI_UNI || type == XQC_SVR_UNI) {
sid = conn->cur_stream_id_uni_local++;
}
sid = sid << 2 | type;
return sid;
}
void
xqc_stream_ready_to_write(xqc_stream_t *stream)
{
if (!(stream->stream_flag & XQC_STREAM_FLAG_READY_TO_WRITE)) {
if (stream->stream_encrypt_level == XQC_ENC_LEV_1RTT) {
xqc_list_add_tail(&stream->write_stream_list, &stream->stream_conn->conn_write_streams);
}
stream->stream_flag |= XQC_STREAM_FLAG_READY_TO_WRITE;
}
if (!(stream->stream_conn->conn_flag & XQC_CONN_FLAG_TICKING)) {
if (xqc_conns_pq_push(stream->stream_conn->engine->conns_active_pq,
stream->stream_conn, stream->stream_conn->last_ticked_time) != 0) {
return;
}
stream->stream_conn->conn_flag |= XQC_CONN_FLAG_TICKING;
}
}
void
xqc_stream_shutdown_write(xqc_stream_t *stream)
{
if (stream->stream_flag & XQC_STREAM_FLAG_READY_TO_WRITE) {
if (stream->stream_encrypt_level == XQC_ENC_LEV_1RTT) {
xqc_list_del_init(&stream->write_stream_list);
}
stream->stream_flag &= ~XQC_STREAM_FLAG_READY_TO_WRITE;
}
}
void
xqc_stream_ready_to_read(xqc_stream_t *stream)
{
if (!(stream->stream_flag & XQC_STREAM_FLAG_READY_TO_READ)) {
if (stream->stream_encrypt_level == XQC_ENC_LEV_1RTT) {
xqc_list_add_tail(&stream->read_stream_list, &stream->stream_conn->conn_read_streams);
}
stream->stream_flag |= XQC_STREAM_FLAG_READY_TO_READ;
}
if (!(stream->stream_conn->conn_flag & XQC_CONN_FLAG_TICKING)) {
if (xqc_conns_pq_push(stream->stream_conn->engine->conns_active_pq,
stream->stream_conn, stream->stream_conn->last_ticked_time) != 0) {
return;
}
stream->stream_conn->conn_flag |= XQC_CONN_FLAG_TICKING;
}
}
void
xqc_stream_shutdown_read(xqc_stream_t *stream)
{
if (stream->stream_flag & XQC_STREAM_FLAG_READY_TO_READ) {
if (stream->stream_encrypt_level == XQC_ENC_LEV_1RTT) {
xqc_list_del_init(&stream->read_stream_list);
}
stream->stream_flag &= ~XQC_STREAM_FLAG_READY_TO_READ;
}
}
void
xqc_stream_maybe_need_close(xqc_stream_t *stream)
{
if (stream->stream_flag & XQC_STREAM_FLAG_NEED_CLOSE) {
return;
}
if (stream->stream_state_send == XQC_SEND_STREAM_ST_DATA_RECVD
&& stream->stream_stats.all_data_acked_time == 0)
{
stream->stream_stats.all_data_acked_time = xqc_monotonic_timestamp();
}
if ((stream->stream_state_send == XQC_SEND_STREAM_ST_DATA_RECVD || stream->stream_state_send == XQC_SEND_STREAM_ST_RESET_RECVD)
&& (stream->stream_state_recv == XQC_RECV_STREAM_ST_DATA_READ || stream->stream_state_recv == XQC_RECV_STREAM_ST_RESET_READ))
{
xqc_log(stream->stream_conn->log, XQC_LOG_DEBUG, "|stream_id:%ui|stream_type:%d|", stream->stream_id, stream->stream_type);
stream->stream_flag |= XQC_STREAM_FLAG_NEED_CLOSE;
xqc_usec_t now = xqc_monotonic_timestamp();
if (stream->stream_stats.close_time == 0) {
stream->stream_stats.close_time = now;
}
xqc_timer_manager_t *timer_manager = &stream->stream_conn->conn_timer_manager;
xqc_usec_t pto = xqc_conn_get_max_pto(stream->stream_conn);
xqc_usec_t new_expire = now + 3 * pto;
if ((timer_manager->timer[XQC_TIMER_STREAM_CLOSE].timer_is_set
&& new_expire < timer_manager->timer[XQC_TIMER_STREAM_CLOSE].expire_time)
|| !timer_manager->timer[XQC_TIMER_STREAM_CLOSE].timer_is_set)
{
xqc_timer_set(timer_manager, XQC_TIMER_STREAM_CLOSE, now, 3 * pto);
}
stream->stream_close_time = new_expire;
xqc_list_add_tail(&stream->closing_stream_list, &stream->stream_conn->conn_closing_streams);
xqc_stream_shutdown_read(stream);
xqc_stream_shutdown_write(stream);
}
}
void
xqc_stream_close_discarded_stream(xqc_stream_t *stream)
{
xqc_timer_manager_t *timer_manager;
xqc_usec_t now;
xqc_usec_t pto;
xqc_usec_t new_expire;
if (stream->stream_flag & XQC_STREAM_FLAG_NEED_CLOSE) {
return;
}
xqc_log(stream->stream_conn->log, XQC_LOG_DEBUG,
"|stream_id:%ui|stream_type:%d|",
stream->stream_id, stream->stream_type);
stream->stream_flag |= XQC_STREAM_FLAG_NEED_CLOSE;
now = xqc_monotonic_timestamp();
pto = xqc_conn_get_max_pto(stream->stream_conn);
new_expire = now + 3 * pto;
timer_manager = &stream->stream_conn->conn_timer_manager;
if ((timer_manager->timer[XQC_TIMER_STREAM_CLOSE].timer_is_set
&& new_expire < timer_manager->timer[XQC_TIMER_STREAM_CLOSE].expire_time)
|| !timer_manager->timer[XQC_TIMER_STREAM_CLOSE].timer_is_set)
{
xqc_timer_set(timer_manager, XQC_TIMER_STREAM_CLOSE, now, 3 * pto);
}
stream->stream_close_time = new_expire;
xqc_list_add_tail(&stream->closing_stream_list, &stream->stream_conn->conn_closing_streams);
xqc_stream_shutdown_read(stream);
xqc_stream_shutdown_write(stream);
}
xqc_stream_t *
xqc_find_stream_by_id(xqc_stream_id_t stream_id, xqc_id_hash_table_t *streams_hash)
{
xqc_stream_t *stream = xqc_id_hash_find(streams_hash, stream_id);
return stream;
}
void
xqc_stream_set_flow_ctl(xqc_stream_t *stream)
{
xqc_trans_settings_t *local_settings = &stream->stream_conn->local_settings;
xqc_trans_settings_t *remote_settings = &stream->stream_conn->remote_settings;
xqc_connection_t *conn = stream->stream_conn;
if ((remote_settings->max_stream_data_bidi_remote
&& remote_settings->max_stream_data_bidi_local
&& remote_settings->max_stream_data_uni) == XQC_FALSE)
{
remote_settings = &stream->stream_conn->local_settings;
}
/*
* initial_max_stream_data_bidi_local (0x0005): This parameter is an
* integer value specifying the initial flow control limit for
* locally-initiated bidirectional streams. This limit applies to
* newly created bidirectional streams opened by the endpoint that
* sends the transport parameter. In client transport parameters,
* this applies to streams with an identifier with the least
* significant two bits set to 0x0; in server transport parameters,
* this applies to streams with the least significant two bits set to
* 0x1.
*
* initial_max_stream_data_bidi_remote (0x0006): This parameter is an
* integer value specifying the initial flow control limit for peer-
* initiated bidirectional streams. This limit applies to newly
* created bidirectional streams opened by the endpoint that receives
* the transport parameter. In client transport parameters, this
* applies to streams with an identifier with the least significant
* two bits set to 0x1; in server transport parameters, this applies
* to streams with the least significant two bits set to 0x0.
*/
if (conn->conn_type == XQC_CONN_TYPE_CLIENT) {
if (stream->stream_type == XQC_CLI_BID) {
stream->stream_flow_ctl.fc_max_stream_data_can_send = remote_settings->max_stream_data_bidi_remote;
stream->stream_flow_ctl.fc_max_stream_data_can_recv = local_settings->max_stream_data_bidi_local;
stream->stream_flow_ctl.fc_stream_recv_window_size = local_settings->max_stream_data_bidi_local;
} else if (stream->stream_type == XQC_SVR_BID) {
/*
* in server transport parameters,
* this applies to streams with the least significant two bits set to 0x1
*/
stream->stream_flow_ctl.fc_max_stream_data_can_send = remote_settings->max_stream_data_bidi_local;
stream->stream_flow_ctl.fc_max_stream_data_can_recv = local_settings->max_stream_data_bidi_remote;
stream->stream_flow_ctl.fc_stream_recv_window_size = local_settings->max_stream_data_bidi_remote;
} else {
stream->stream_flow_ctl.fc_max_stream_data_can_send = remote_settings->max_stream_data_uni;
stream->stream_flow_ctl.fc_max_stream_data_can_recv = local_settings->max_stream_data_uni;
stream->stream_flow_ctl.fc_stream_recv_window_size = local_settings->max_stream_data_uni;
}
} else { /* conn->conn_type == XQC_CONN_TYPE_SERVER */
if (stream->stream_type == XQC_CLI_BID) {
stream->stream_flow_ctl.fc_max_stream_data_can_send = remote_settings->max_stream_data_bidi_local;
stream->stream_flow_ctl.fc_max_stream_data_can_recv = local_settings->max_stream_data_bidi_remote;
stream->stream_flow_ctl.fc_stream_recv_window_size = local_settings->max_stream_data_bidi_remote;
} else if (stream->stream_type == XQC_SVR_BID) {
stream->stream_flow_ctl.fc_max_stream_data_can_send = remote_settings->max_stream_data_bidi_remote;
stream->stream_flow_ctl.fc_max_stream_data_can_recv = local_settings->max_stream_data_bidi_local;
stream->stream_flow_ctl.fc_stream_recv_window_size = local_settings->max_stream_data_bidi_local;
} else {
stream->stream_flow_ctl.fc_max_stream_data_can_send = remote_settings->max_stream_data_uni;
stream->stream_flow_ctl.fc_max_stream_data_can_recv = local_settings->max_stream_data_uni;
stream->stream_flow_ctl.fc_stream_recv_window_size = local_settings->max_stream_data_uni;
}
}
}
void
xqc_stream_update_flow_ctl(xqc_stream_t *stream)
{
xqc_trans_settings_t *remote_settings = &stream->stream_conn->remote_settings;
xqc_connection_t *conn = stream->stream_conn;
if (conn->conn_type == XQC_CONN_TYPE_CLIENT) {
if (stream->stream_type == XQC_CLI_BID) {
stream->stream_flow_ctl.fc_max_stream_data_can_send = remote_settings->max_stream_data_bidi_remote;
} else if (stream->stream_type == XQC_SVR_BID) {
/*
* in server transport parameters,
* this applies to streams with the least significant two bits set to 0x1
*/
stream->stream_flow_ctl.fc_max_stream_data_can_send = remote_settings->max_stream_data_bidi_local;
} else {
stream->stream_flow_ctl.fc_max_stream_data_can_send = remote_settings->max_stream_data_uni;
}
} else { /* conn->conn_type == XQC_CONN_TYPE_SERVER */
if (stream->stream_type == XQC_CLI_BID) {
stream->stream_flow_ctl.fc_max_stream_data_can_send = remote_settings->max_stream_data_bidi_local;
} else if (stream->stream_type == XQC_SVR_BID) {
stream->stream_flow_ctl.fc_max_stream_data_can_send = remote_settings->max_stream_data_bidi_remote;
} else {
stream->stream_flow_ctl.fc_max_stream_data_can_send = remote_settings->max_stream_data_uni;
}
}
}
uint64_t
xqc_stream_get_init_max_stream_data(xqc_stream_t *stream)
{
xqc_connection_t *conn = stream->stream_conn;
if (stream->stream_type == XQC_SVR_BID) {
if (conn->conn_type == XQC_CONN_TYPE_SERVER) {
return conn->local_settings.max_stream_data_bidi_local;
} else {
return conn->local_settings.max_stream_data_bidi_remote;
}
} else if (stream->stream_type == XQC_CLI_BID) {
if (conn->conn_type == XQC_CONN_TYPE_SERVER) {
return conn->local_settings.max_stream_data_bidi_remote;
} else {
return conn->local_settings.max_stream_data_bidi_local;
}
} else {
return conn->local_settings.max_stream_data_uni;
}
}
int
xqc_stream_do_send_flow_ctl(xqc_stream_t *stream)
{
int ret = XQC_OK;
xqc_log(stream->stream_conn->log, XQC_LOG_DEBUG, "|conn_flow_ctl|window:%ui|",
stream->stream_conn->conn_flow_ctl.fc_max_data_can_send - stream->stream_conn->conn_flow_ctl.fc_data_sent);
/* connection level */
if (stream->stream_conn->conn_flow_ctl.fc_data_sent + stream->stream_conn->pkt_out_size > stream->stream_conn->conn_flow_ctl.fc_max_data_can_send) {
xqc_log(stream->stream_conn->log, XQC_LOG_INFO, "|xqc_stream_send|exceed max_data:%ui|",
stream->stream_conn->conn_flow_ctl.fc_max_data_can_send);
stream->stream_conn->conn_flag |= XQC_CONN_FLAG_DATA_BLOCKED;
xqc_write_data_blocked_to_packet(stream->stream_conn, stream->stream_conn->conn_flow_ctl.fc_max_data_can_send);
ret = -XQC_ECONN_BLOCKED;
}
/* stream level */
if (stream->stream_send_offset + stream->stream_conn->pkt_out_size > stream->stream_flow_ctl.fc_max_stream_data_can_send) {
xqc_log(stream->stream_conn->log, XQC_LOG_INFO, "|xqc_stream_send|exceed max_stream_data:%ui|",
stream->stream_flow_ctl.fc_max_stream_data_can_send);
stream->stream_flag |= XQC_STREAM_FLAG_DATA_BLOCKED;
xqc_write_stream_data_blocked_to_packet(stream->stream_conn, stream->stream_id,
stream->stream_flow_ctl.fc_max_stream_data_can_send);
ret = -XQC_ESTREAM_BLOCKED;
}
return ret;
}
int
xqc_stream_do_recv_flow_ctl(xqc_stream_t *stream)
{
xqc_connection_t *conn = stream->stream_conn;
xqc_usec_t now = xqc_monotonic_timestamp();
/* increase recv window */
xqc_usec_t min_srtt = xqc_conn_get_min_srtt(conn, 0);
xqc_usec_t max_srtt = 0;
uint64_t old_fc_win = 0;
/* stream level */
uint64_t available_window = stream->stream_flow_ctl.fc_max_stream_data_can_recv - stream->stream_data_in.next_read_offset;
if (available_window < stream->stream_flow_ctl.fc_stream_recv_window_size / 2) {
if (!stream->recv_rate_bytes_per_sec) {
if (stream->stream_flow_ctl.fc_last_window_update_time
&& (now - stream->stream_flow_ctl.fc_last_window_update_time < 2 * min_srtt))
{
stream->stream_flow_ctl.fc_stream_recv_window_size
= xqc_min(stream->stream_flow_ctl.fc_stream_recv_window_size * 2, XQC_MAX_RECV_WINDOW);
}
} else {
if (!max_srtt) {
max_srtt = xqc_conn_get_max_srtt(conn);
}
old_fc_win = stream->stream_flow_ctl.fc_stream_recv_window_size;
stream->stream_flow_ctl.fc_stream_recv_window_size = stream->recv_rate_bytes_per_sec * max_srtt / 1000000;
stream->stream_flow_ctl.fc_stream_recv_window_size = xqc_max(conn->conn_settings.init_recv_window, stream->stream_flow_ctl.fc_stream_recv_window_size);
stream->stream_flow_ctl.fc_stream_recv_window_size = xqc_min(XQC_MAX_RECV_WINDOW, stream->stream_flow_ctl.fc_stream_recv_window_size);
xqc_log(conn->log, XQC_LOG_DEBUG,
"|stream_level|fc_win_update|old_fc_win:%ui|fc_win:%ui|",
old_fc_win, stream->stream_flow_ctl.fc_stream_recv_window_size);
}
stream->stream_flow_ctl.fc_last_window_update_time = now;
if (stream->stream_flow_ctl.fc_stream_recv_window_size > available_window) {
stream->stream_flow_ctl.fc_max_stream_data_can_recv += (stream->stream_flow_ctl.fc_stream_recv_window_size - available_window);
xqc_log(conn->log, XQC_LOG_DEBUG,
"|xqc_write_max_stream_data_to_packet|new_max_data:%ui|stream_max_recv_offset:%ui|next_read_offset:%ui|window_size:%ui|",
stream->stream_flow_ctl.fc_max_stream_data_can_recv, stream->stream_max_recv_offset,
stream->stream_data_in.next_read_offset, stream->stream_flow_ctl.fc_stream_recv_window_size);
xqc_write_max_stream_data_to_packet(conn, stream->stream_id, stream->stream_flow_ctl.fc_max_stream_data_can_recv, XQC_PTYPE_SHORT_HEADER);
}
}
/* connection level */
available_window = conn->conn_flow_ctl.fc_max_data_can_recv - conn->conn_flow_ctl.fc_data_read;
if (available_window < conn->conn_flow_ctl.fc_recv_windows_size / 2) {
if (!conn->conn_settings.recv_rate_bytes_per_sec) {
if (conn->conn_flow_ctl.fc_last_window_update_time
&& (now - conn->conn_flow_ctl.fc_last_window_update_time < 2 * min_srtt))
{
conn->conn_flow_ctl.fc_recv_windows_size
= xqc_min(conn->conn_flow_ctl.fc_recv_windows_size * 2, XQC_MAX_RECV_WINDOW);
}
if (conn->conn_flow_ctl.fc_recv_windows_size < 1.5 * stream->stream_flow_ctl.fc_stream_recv_window_size) {
conn->conn_flow_ctl.fc_recv_windows_size = (uint64_t)(1.5 * stream->stream_flow_ctl.fc_stream_recv_window_size);
}
} else {
if (!max_srtt) {
max_srtt = xqc_conn_get_max_srtt(conn);
}
old_fc_win = conn->conn_flow_ctl.fc_recv_windows_size;
conn->conn_flow_ctl.fc_recv_windows_size = conn->conn_settings.recv_rate_bytes_per_sec * max_srtt / 1000000;
conn->conn_flow_ctl.fc_recv_windows_size = xqc_max(XQC_MIN_RECV_WINDOW, conn->conn_flow_ctl.fc_recv_windows_size);
conn->conn_flow_ctl.fc_recv_windows_size = xqc_min(XQC_MAX_RECV_WINDOW, conn->conn_flow_ctl.fc_recv_windows_size);
xqc_log(conn->log, XQC_LOG_DEBUG,
"|conn_level|fc_win_update|old_fc_win:%ui|fc_win:%ui|",
old_fc_win, conn->conn_flow_ctl.fc_recv_windows_size);
}
conn->conn_flow_ctl.fc_last_window_update_time = now;
if (conn->conn_flow_ctl.fc_recv_windows_size > available_window) {
conn->conn_flow_ctl.fc_max_data_can_recv += (conn->conn_flow_ctl.fc_recv_windows_size - available_window);
xqc_log(conn->log, XQC_LOG_DEBUG,
"|xqc_write_max_data_to_packet|new_max_data:%ui|fc_data_recved:%ui|fc_data_read:%ui|window_size:%ui|",
conn->conn_flow_ctl.fc_max_data_can_recv, conn->conn_flow_ctl.fc_data_recved,
conn->conn_flow_ctl.fc_data_read, conn->conn_flow_ctl.fc_recv_windows_size);
xqc_write_max_data_to_packet(conn, conn->conn_flow_ctl.fc_max_data_can_recv);
}
}
return XQC_OK;
}
int
xqc_stream_do_create_flow_ctl(xqc_connection_t *conn, xqc_stream_id_t stream_id, xqc_stream_type_t stream_type)
{
if (stream_id == XQC_UNDEFINE_STREAM_ID) { /* sending part */
if (stream_type == XQC_CLI_BID || stream_type == XQC_SVR_BID) {
if (conn->cur_stream_id_bidi_local >= conn->conn_flow_ctl.fc_max_streams_bidi_can_send) {
xqc_log(conn->log, XQC_LOG_ERROR, "|exceed max_streams_bidi_can_send:%ui|",
conn->conn_flow_ctl.fc_max_streams_bidi_can_send);
xqc_write_streams_blocked_to_packet(conn, conn->conn_flow_ctl.fc_max_streams_bidi_can_send, 1);
return -XQC_EPROTO;
}
} else {
if (conn->cur_stream_id_uni_local >= conn->conn_flow_ctl.fc_max_streams_uni_can_send) {
xqc_log(conn->log, XQC_LOG_ERROR, "|exceed max_streams_uni_can_send:%ui|",
conn->conn_flow_ctl.fc_max_streams_uni_can_send);
xqc_write_streams_blocked_to_packet(conn, conn->conn_flow_ctl.fc_max_streams_uni_can_send, 0);
return -XQC_EPROTO;
}
}
} else { /* receiving part */
stream_type = xqc_get_stream_type(stream_id);
if (stream_type == XQC_CLI_BID || stream_type == XQC_SVR_BID) {
if (stream_id >= 4 * conn->conn_flow_ctl.fc_max_streams_bidi_can_recv + stream_type) {
xqc_log(conn->log, XQC_LOG_ERROR, "|exceed max_streams_bidi_can_recv:%ui|",
conn->conn_flow_ctl.fc_max_streams_bidi_can_recv);
XQC_CONN_ERR(conn, TRA_STREAM_LIMIT_ERROR);
return -XQC_EPROTO;
}
/* increase max streams */
if ((stream_id >> 2) >= conn->conn_flow_ctl.fc_max_streams_bidi_can_recv / 2) {
conn->conn_flow_ctl.fc_max_streams_bidi_can_recv += conn->local_settings.max_streams_bidi;
xqc_write_max_streams_to_packet(conn, conn->conn_flow_ctl.fc_max_streams_bidi_can_recv, 1);
}
} else {
if (stream_id >= 4 * conn->conn_flow_ctl.fc_max_streams_uni_can_recv + stream_type) {
xqc_log(conn->log, XQC_LOG_ERROR, "|exceed max_streams_uni_can_recv:%ui|",
conn->conn_flow_ctl.fc_max_streams_uni_can_recv);
XQC_CONN_ERR(conn, TRA_STREAM_LIMIT_ERROR);
return -XQC_EPROTO;
}
/* increase max streams */
if ((stream_id >> 2) >= conn->conn_flow_ctl.fc_max_streams_uni_can_recv / 2) {
conn->conn_flow_ctl.fc_max_streams_uni_can_recv += conn->local_settings.max_streams_uni;
xqc_write_max_streams_to_packet(conn, conn->conn_flow_ctl.fc_max_streams_uni_can_recv, 0);
}
}
}
return XQC_OK;
}
xqc_stream_t *
xqc_stream_create(xqc_engine_t *engine, const xqc_cid_t *cid, xqc_stream_settings_t *settings,
void *user_data)
{
xqc_connection_t *conn;
xqc_stream_t *stream;
conn = xqc_engine_conns_hash_find(engine, cid, 's');
if (!conn) {
xqc_log(engine->log, XQC_LOG_ERROR, "|can not find connection|cid:%s",
xqc_scid_str(cid));
return NULL;
}
stream = xqc_create_stream_with_conn(conn, XQC_UNDEFINE_STREAM_ID, XQC_CLI_BID, settings, user_data);
if (!stream) {
xqc_log(engine->log, XQC_LOG_ERROR, "|xqc_create_stream_with_conn error|");
return NULL;
}
conn->cli_bidi_streams++;
return stream;
}
xqc_stream_t *
xqc_stream_create_with_direction(xqc_connection_t *conn,
xqc_stream_direction_t dir, void *user_data)
{
xqc_stream_type_t type;
/* get stream type */
if (XQC_CONN_TYPE_CLIENT == xqc_conn_get_type(conn)) {
if (XQC_STREAM_BIDI == dir) {
type = XQC_CLI_BID;
} else {
type = XQC_CLI_UNI;
}
} else {
if (XQC_STREAM_BIDI == dir) {
type = XQC_SVR_BID;
} else {
type = XQC_SVR_UNI;
}
}
/* create stream */
return xqc_create_stream_with_conn(conn, XQC_UNDEFINE_STREAM_ID, type,
NULL, user_data);
}
xqc_stream_t *
xqc_create_stream_with_conn(xqc_connection_t *conn, xqc_stream_id_t stream_id,
xqc_stream_type_t stream_type, xqc_stream_settings_t *settings, void *user_data)
{
xqc_int_t ret;
if (conn->conn_state >= XQC_CONN_STATE_CLOSING) {
xqc_log(conn->log, XQC_LOG_ERROR, "|conn closing, cannot create stream|type:%d|state:%d|flag:%s|",
conn->conn_type, conn->conn_state, xqc_conn_flag_2_str(conn->conn_flag));
return NULL;
}
if (xqc_stream_do_create_flow_ctl(conn, stream_id, stream_type)) {
xqc_log(conn->log, XQC_LOG_ERROR, "|xqc_stream_do_create_flow_ctl error|");
return NULL;
}
xqc_stream_t *stream = xqc_calloc(1, sizeof(xqc_stream_t));
if (stream == NULL) {
xqc_log(conn->log, XQC_LOG_ERROR, "|xqc_calloc error|");
return NULL;
}
xqc_list_add_tail(&stream->all_stream_list, &conn->conn_all_streams);
stream->stream_encrypt_level = XQC_ENC_LEV_1RTT;
stream->stream_conn = conn;
stream->stream_if = &conn->app_proto_cbs.stream_cbs;
stream->user_data = user_data;
stream->stream_state_send = XQC_SEND_STREAM_ST_READY;
stream->stream_state_recv = XQC_RECV_STREAM_ST_RECV;
stream->stream_refcnt = 0;
xqc_memset(&stream->stream_stats, 0, sizeof(stream->stream_stats));
stream->stream_stats.create_time = xqc_monotonic_timestamp();
xqc_memset(&stream->paths_info, 0, sizeof(stream->paths_info));
for (int i = 0; i < XQC_MAX_PATHS_COUNT; ++i) {
stream->paths_info[i].path_id = XQC_MAX_UINT64_VALUE;
}
xqc_stream_set_flow_ctl(stream);
xqc_init_list_head(&stream->stream_data_in.frames_tailq);
xqc_init_list_head(&stream->stream_write_buff_list.write_buff_list);
if (stream_id == XQC_UNDEFINE_STREAM_ID) {
stream->stream_type = stream_type;
stream->stream_id = xqc_gen_stream_id(conn, stream->stream_type);
} else {
stream->stream_id = stream_id;
stream->stream_type = xqc_get_stream_type(stream_id);
}
xqc_id_hash_element_t e = {stream->stream_id, stream};
if (xqc_id_hash_add(conn->streams_hash, e)) {
xqc_log(conn->log, XQC_LOG_ERROR, "|xqc_id_hash_add error|");
goto error;
}
/* newly initiated stream is writable */
if (stream_id == XQC_UNDEFINE_STREAM_ID) {
xqc_stream_ready_to_write(stream);
}
stream->recv_rate_bytes_per_sec = 0;
if (settings) {
if (conn->conn_settings.enable_stream_rate_limit
&& stream->stream_type == XQC_CLI_BID)
{
stream->recv_rate_bytes_per_sec = settings->recv_rate_bytes_per_sec;
}
}
if (stream->stream_if->stream_create_notify) {
ret = stream->stream_if->stream_create_notify(stream, stream->user_data);
if (XQC_OK != ret) {
xqc_log(conn->log, XQC_LOG_WARN, "|stream create notify error|"
"|stream_id:%ui", stream->stream_id);
stream->stream_flag |= XQC_STREAM_FLAG_DISCARDED;
}
}
return stream;
error:
xqc_destroy_stream(stream);
return NULL;
}
void
xqc_stream_set_user_data(xqc_stream_t *stream, void *user_data)
{
stream->user_data = user_data;
}
void *
xqc_get_conn_user_data_by_stream(xqc_stream_t *stream)
{
return stream->stream_conn->user_data;
}
void *
xqc_get_conn_alp_user_data_by_stream(xqc_stream_t *stream)
{
return stream->stream_conn->proto_data;
}
xqc_stream_id_t
xqc_stream_id(xqc_stream_t *stream)
{
return stream->stream_id;
}
void
xqc_destroy_stream(xqc_stream_t *stream)
{
xqc_log(stream->stream_conn->log, XQC_LOG_DEBUG, "|send_state:%d|recv_state:%d|stream_id:%ui|stream_type:%d|",
stream->stream_state_send, stream->stream_state_recv, stream->stream_id, stream->stream_type);
if ((stream->stream_state_send == XQC_SEND_STREAM_ST_DATA_RECVD)
&& (stream->stream_state_recv == XQC_RECV_STREAM_ST_DATA_READ))
{
if(stream->stream_conn) {
stream->stream_conn->finished_streams++;
}
}
if (stream->stream_if->stream_close_notify
&& !(stream->stream_flag & XQC_STREAM_FLAG_DISCARDED))
{
stream->stream_if->stream_close_notify(stream, stream->user_data);
}
xqc_list_del_init(&stream->all_stream_list);
xqc_destroy_frame_list(&stream->stream_data_in.frames_tailq);
xqc_destroy_write_buff_list(&stream->stream_write_buff_list.write_buff_list);
int ret = xqc_id_hash_delete(stream->stream_conn->streams_hash, stream->stream_id);
if (ret != XQC_OK) {
xqc_log(stream->stream_conn->log, XQC_LOG_ERROR, "|delete stream error|conn:%p|stream_id:%ui|ret:%d|",
stream->stream_conn, stream->stream_id, ret);
}
if (xqc_id_hash_delete(stream->stream_conn->passive_streams_hash, stream->stream_id) == XQC_ID_HASH_LOOP) {
xqc_id_hash_table_t* hash_tab = stream->stream_conn->passive_streams_hash;
xqc_id_hash_node_t* node = hash_tab->list[stream->stream_id % hash_tab->count];
xqc_log(stream->stream_conn->log, XQC_LOG_ERROR, "|stream_id:%ui|hash:%ui|value:%p|node:%p|next:%p|",
stream->stream_id, node->element.hash, node->element.value, node, node->next);
}
xqc_stream_shutdown_write(stream);
xqc_stream_shutdown_read(stream);
stream->stream_flag |= XQC_STREAM_FLAG_CLOSED;
#define __calc_delay(a, b) (a? (a) - (b) : 0)
char path_info_buff[200 * XQC_MAX_PATHS_COUNT] = {'\0'};
xqc_stream_path_metrics_print(stream->stream_conn, stream, path_info_buff, 50 * XQC_MAX_PATHS_COUNT);
xqc_log(stream->stream_conn->log, XQC_LOG_STATS,
"|err:0x%xi|close_msg:%s|enable_multipath:%d|"
"send_state:%d|recv_state:%d|stream_id:%ui|stream_type:%d|"
"send_bytes:%ui|read_bytes:%ui|recv_bytes:%ui|stream_len:%ui|"
"create_time:%ui|wrt_delay:%ui|"
"snd_delay:%ui|finwrt_delay:%ui|finsnd_delay:%ui|"
"finrcv_delay:%ui|finread_delay:%ui|all_acked_delay:%ui|"
"firstfinack_dely:%ui|close_delay:%ui|"
"apprst_delay:%ui|rstsnd_delay:%ui|rstrcv_delay:%ui|%s|"
"path_info:%s|",
stream->stream_err, stream->stream_close_msg ? stream->stream_close_msg : "",
stream->stream_conn->enable_multipath ? 1:0,
stream->stream_state_send, stream->stream_state_recv,
stream->stream_id, stream->stream_type,
stream->stream_send_offset,
stream->stream_data_in.next_read_offset,
stream->stream_data_in.merged_offset_end,
stream->stream_data_in.stream_length,
stream->stream_stats.create_time,
__calc_delay(stream->stream_stats.first_write_time, stream->stream_stats.create_time),
__calc_delay(stream->stream_stats.first_snd_time, stream->stream_stats.create_time),
__calc_delay(stream->stream_stats.local_fin_write_time, stream->stream_stats.create_time),
__calc_delay(stream->stream_stats.local_fin_snd_time, stream->stream_stats.create_time),
__calc_delay(stream->stream_stats.peer_fin_rcv_time, stream->stream_stats.create_time),
__calc_delay(stream->stream_stats.peer_fin_read_time, stream->stream_stats.create_time),
__calc_delay(stream->stream_stats.all_data_acked_time, stream->stream_stats.create_time),
__calc_delay(stream->stream_stats.first_fin_ack_time, stream->stream_stats.create_time),
__calc_delay(stream->stream_stats.close_time, stream->stream_stats.create_time),
__calc_delay(stream->stream_stats.app_reset_time, stream->stream_stats.create_time),
__calc_delay(stream->stream_stats.local_reset_time, stream->stream_stats.create_time),
__calc_delay(stream->stream_stats.peer_reset_time, stream->stream_stats.create_time),
xqc_conn_addr_str(stream->stream_conn),
path_info_buff);
#undef __calc_delay
xqc_free(stream);
}
xqc_int_t
xqc_stream_close(xqc_stream_t *stream)
{
xqc_int_t ret;
xqc_connection_t *conn = stream->stream_conn;
xqc_log(conn->log, XQC_LOG_DEBUG, "|stream_id:%ui|stream_state_send:%d|stream_state_recv:%d|conn:%p|conn_state:%s|",
stream->stream_id, stream->stream_state_send, stream->stream_state_recv, conn, xqc_conn_state_2_str(conn->conn_state));
XQC_STREAM_CLOSE_MSG(stream, "local reset");
if (stream->stream_state_send >= XQC_SEND_STREAM_ST_RESET_SENT) {
return XQC_OK;
}
if (conn->conn_state >= XQC_CONN_STATE_CLOSING) {
return XQC_OK;
}
xqc_send_queue_drop_stream_frame_packets(conn, stream->stream_id);
ret = xqc_write_reset_stream_to_packet(conn, stream, H3_REQUEST_CANCELLED, stream->stream_send_offset);
if (ret < 0) {
xqc_log(conn->log, XQC_LOG_ERROR, "|xqc_write_reset_stream_to_packet error|%d|", ret);
XQC_CONN_ERR(conn, TRA_INTERNAL_ERROR);
}
/* A STOP_SENDING frame can be sent for streams in the "Recv" or "Size
Known" states */
if (stream->stream_state_recv == XQC_RECV_STREAM_ST_RECV
|| stream->stream_state_recv == XQC_RECV_STREAM_ST_SIZE_KNOWN)
{
ret = xqc_write_stop_sending_to_packet(conn, stream, H3_REQUEST_CANCELLED);
if (ret < 0) {
xqc_log(conn->log, XQC_LOG_ERROR, "|xqc_write_stop_sending_to_packet error|%d|", ret);
XQC_CONN_ERR(conn, TRA_INTERNAL_ERROR);
}
}
if (!(conn->conn_flag & XQC_CONN_FLAG_TICKING)) {
if (0 == xqc_conns_pq_push(conn->engine->conns_active_pq, conn, conn->last_ticked_time)) {
conn->conn_flag |= XQC_CONN_FLAG_TICKING;
}
}
xqc_stream_shutdown_write(stream);
xqc_engine_main_logic_internal(conn->engine);
return XQC_OK;
}
xqc_int_t
xqc_insert_passive_stream_hash(xqc_connection_t *conn, int64_t cur_max_sid, xqc_stream_id_t stream_id)
{
xqc_stream_type_t type = xqc_get_stream_type(stream_id);
for (int64_t sid = cur_max_sid + 1; sid <= (stream_id >> 2u); ++sid) {
xqc_id_hash_element_t e = {(uint64_t)sid << 2u | type, conn};
if (xqc_id_hash_add(conn->passive_streams_hash, e)) {
xqc_log(conn->log, XQC_LOG_ERROR, "|xqc_id_hash_add error|stream_id:%ui|", stream_id);
XQC_CONN_ERR(conn, TRA_INTERNAL_ERROR);
}
}
return XQC_OK;
}
xqc_stream_t *
xqc_passive_create_stream(xqc_connection_t *conn, xqc_stream_id_t stream_id, void *user_data)
{
if (xqc_stream_do_create_flow_ctl(conn, stream_id, xqc_get_stream_type(stream_id)) != XQC_OK) {
xqc_log(conn->log, XQC_LOG_ERROR, "|xqc_stream_do_create_flow_ctl error|");
return NULL;
}
int64_t sid = stream_id >> 2u;
if (xqc_stream_is_bidi(stream_id) && sid > conn->max_stream_id_bidi_remote) {
xqc_insert_passive_stream_hash(conn, conn->max_stream_id_bidi_remote, stream_id);
conn->max_stream_id_bidi_remote = sid;
} else if (!xqc_stream_is_bidi(stream_id) && sid > conn->max_stream_id_uni_remote) {
xqc_insert_passive_stream_hash(conn, conn->max_stream_id_uni_remote, stream_id);
conn->max_stream_id_uni_remote = sid;
} else {
if (!xqc_id_hash_find(conn->passive_streams_hash, stream_id)) {
/* already closed */
xqc_log(conn->log, XQC_LOG_DEBUG, "|stream already closed|stream_id:%ui|", stream_id);
return NULL;
}
}
xqc_stream_t *stream = xqc_create_stream_with_conn(conn, stream_id, 0, NULL, user_data);
if (stream == NULL) {
xqc_log(conn->log, XQC_LOG_ERROR, "|xqc_create_stream_with_conn error|stream_id:%ui|", stream_id);
XQC_CONN_ERR(conn, TRA_INTERNAL_ERROR);
return NULL;
}
xqc_stream_type_t stream_type;
stream_type = xqc_get_stream_type(stream_id);
if (stream_type == XQC_CLI_BID) {
conn->cli_bidi_streams++;
} else if (stream_type == XQC_SVR_BID) {
conn->svr_bidi_streams++;
}
return stream;
}
xqc_int_t
xqc_stream_update_settings(xqc_stream_t *stream,
xqc_stream_settings_t *settings)
{
xqc_connection_t *conn = NULL;
xqc_usec_t max_srtt = 0;
uint64_t old_fc_win = 0, new_offset = 0;
if (stream && settings
&& settings->recv_rate_bytes_per_sec)
{
conn = stream->stream_conn;
if (conn->conn_settings.enable_stream_rate_limit) {
stream->recv_rate_bytes_per_sec = settings->recv_rate_bytes_per_sec;
max_srtt = xqc_conn_get_max_srtt(conn);
old_fc_win = stream->stream_flow_ctl.fc_stream_recv_window_size;
stream->stream_flow_ctl.fc_stream_recv_window_size = stream->recv_rate_bytes_per_sec * max_srtt / 1000000;
stream->stream_flow_ctl.fc_stream_recv_window_size = xqc_max(conn->conn_settings.init_recv_window, stream->stream_flow_ctl.fc_stream_recv_window_size);
stream->stream_flow_ctl.fc_stream_recv_window_size = xqc_min(XQC_MAX_RECV_WINDOW, stream->stream_flow_ctl.fc_stream_recv_window_size);
xqc_log(conn->log, XQC_LOG_DEBUG,
"|fc_win_update|old_fc_win:%ui|fc_win:%ui|",
old_fc_win, stream->stream_flow_ctl.fc_stream_recv_window_size);
new_offset = stream->stream_data_in.next_read_offset + stream->stream_flow_ctl.fc_stream_recv_window_size;
if(new_offset > stream->stream_flow_ctl.fc_max_stream_data_can_recv) {
stream->stream_flow_ctl.fc_max_stream_data_can_recv = new_offset;
xqc_log(conn->log, XQC_LOG_DEBUG,
"|new_max_data:%ui|stream_max_recv_offset:%ui|next_read_offset:%ui|window_size:%ui|",
stream->stream_flow_ctl.fc_max_stream_data_can_recv, stream->stream_max_recv_offset,
stream->stream_data_in.next_read_offset, stream->stream_flow_ctl.fc_stream_recv_window_size);
xqc_write_max_stream_data_to_packet(conn, stream->stream_id, stream->stream_flow_ctl.fc_max_stream_data_can_recv, XQC_PTYPE_NUM);
}
return XQC_OK;
}
}
return -XQC_EPARAM;
}
xqc_int_t
xqc_read_crypto_stream(xqc_stream_t *stream)
{
xqc_stream_frame_t *stream_frame = NULL;
xqc_connection_t *conn = stream->stream_conn;
xqc_list_head_t *pos, *next;
xqc_list_for_each_safe(pos, next, &stream->stream_data_in.frames_tailq) {
stream_frame = xqc_list_entry(pos, xqc_stream_frame_t, sf_list);
if (stream->stream_data_in.next_read_offset < stream_frame->data_offset) {
break;
}
if (stream->stream_data_in.next_read_offset >= stream_frame->data_offset + stream_frame->data_length) {
xqc_list_del(pos);
xqc_destroy_stream_frame(stream_frame);
continue;
}
size_t data_len = stream_frame->data_offset + stream_frame->data_length - stream->stream_data_in.next_read_offset;
unsigned char *data_start = stream_frame->data + (stream->stream_data_in.next_read_offset - stream_frame->data_offset);
stream->stream_data_in.next_read_offset = stream->stream_data_in.next_read_offset + data_len;
xqc_int_t ret = xqc_tls_process_crypto_data(conn->tls, stream->stream_encrypt_level, data_start, data_len);
xqc_list_del(pos);
xqc_destroy_stream_frame(stream_frame);
if (ret != XQC_OK) {
xqc_log(stream->stream_conn->log, XQC_LOG_ERROR, "|xqc_tls_process_crypto_data error: %d|", ret);
return -XQC_EILLEGAL_FRAME;
}
}
return XQC_OK;
}
int
xqc_crypto_stream_on_read(xqc_stream_t *stream, void *user_data)
{
XQC_DEBUG_PRINT
xqc_encrypt_level_t encrypt_level = stream->stream_encrypt_level;
xqc_conn_state_t cur_state = stream->stream_conn->conn_state;
xqc_conn_state_t next_state;
xqc_connection_t * conn = stream->stream_conn;
if (encrypt_level == XQC_ENC_LEV_INIT) {
switch (cur_state) {
case XQC_CONN_STATE_CLIENT_INITIAL_SENT:
next_state = XQC_CONN_STATE_CLIENT_INITIAL_RECVD;
break;
case XQC_CONN_STATE_SERVER_INIT:
xqc_stream_ready_to_write(stream);
next_state = XQC_CONN_STATE_SERVER_INITIAL_RECVD;
break;
default:
next_state = cur_state;
}
} else if (encrypt_level == XQC_ENC_LEV_HSK) {
switch (cur_state) {
case XQC_CONN_STATE_CLIENT_INITIAL_SENT:
case XQC_CONN_STATE_CLIENT_INITIAL_RECVD:
case XQC_CONN_STATE_CLIENT_HANDSHAKE_RECVD:
xqc_stream_ready_to_write(stream);
next_state = XQC_CONN_STATE_CLIENT_HANDSHAKE_RECVD;
break;
case XQC_CONN_STATE_SERVER_INITIAL_RECVD:
case XQC_CONN_STATE_SERVER_INITIAL_SENT:
xqc_stream_ready_to_write(stream);
next_state = XQC_CONN_STATE_SERVER_HANDSHAKE_RECVD;
break;
case XQC_CONN_STATE_SERVER_HANDSHAKE_SENT:
next_state = XQC_CONN_STATE_ESTABED;
if (conn->crypto_stream[XQC_ENC_LEV_1RTT] != NULL) {
xqc_stream_ready_to_write(conn->crypto_stream[XQC_ENC_LEV_1RTT]);
}
break;
default:
next_state = cur_state;
}
} else if (encrypt_level == XQC_ENC_LEV_1RTT) {
switch (cur_state) {
case XQC_CONN_STATE_ESTABED:
next_state = XQC_CONN_STATE_ESTABED;
break;
default:
xqc_log(stream->stream_conn->log, XQC_LOG_ERROR, "|illegal encrypt_level:%d|",
encrypt_level);
return -XQC_ELEVEL;
}