-
Notifications
You must be signed in to change notification settings - Fork 120
/
common.rs
1007 lines (916 loc) · 29.5 KB
/
common.rs
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 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
struct ConnectionMeta {
#[builder(crate::endpoint::Type)]
endpoint_type: EndpointType,
id: u64,
#[builder(crate::time::Timestamp)]
timestamp: crate::event::Timestamp,
}
struct EndpointMeta {
#[builder(crate::endpoint::Type)]
endpoint_type: EndpointType,
#[builder(crate::time::Timestamp)]
timestamp: crate::event::Timestamp,
}
struct ConnectionInfo {}
// https://tools.ietf.org/id/draft-marx-qlog-event-definitions-quic-h3-02#5.3.3
struct TransportParameters<'a> {
original_destination_connection_id: Option<ConnectionId<'a>>,
initial_source_connection_id: Option<ConnectionId<'a>>,
retry_source_connection_id: Option<ConnectionId<'a>>,
stateless_reset_token: Option<&'a [u8]>,
preferred_address: Option<PreferredAddress<'a>>,
migration_support: bool,
max_idle_timeout: Duration,
ack_delay_exponent: u8,
max_ack_delay: Duration,
max_udp_payload_size: u64,
active_connection_id_limit: u64,
initial_max_stream_data_bidi_local: u64,
initial_max_stream_data_bidi_remote: u64,
initial_max_stream_data_uni: u64,
initial_max_streams_bidi: u64,
initial_max_streams_uni: u64,
max_datagram_frame_size: u64,
dc_supported_versions: &'a [u32],
}
struct PreferredAddress<'a> {
ipv4_address: Option<SocketAddress<'a>>,
ipv6_address: Option<SocketAddress<'a>>,
connection_id: ConnectionId<'a>,
stateless_reset_token: &'a [u8],
}
impl<'a> IntoEvent<builder::PreferredAddress<'a>>
for &'a crate::transport::parameters::PreferredAddress
{
#[inline]
fn into_event(self) -> builder::PreferredAddress<'a> {
builder::PreferredAddress {
ipv4_address: self.ipv4_address.as_ref().map(|addr| addr.into_event()),
ipv6_address: self.ipv6_address.as_ref().map(|addr| addr.into_event()),
connection_id: self.connection_id.into_event(),
stateless_reset_token: self.stateless_reset_token.as_ref(),
}
}
}
impl<'a> IntoEvent<builder::SocketAddress<'a>> for &'a crate::inet::ipv4::SocketAddressV4 {
#[inline]
fn into_event(self) -> builder::SocketAddress<'a> {
builder::SocketAddress::IpV4 {
ip: &self.ip.octets,
port: self.port.into(),
}
}
}
impl<'a> IntoEvent<builder::SocketAddress<'a>> for &'a crate::inet::ipv6::SocketAddressV6 {
#[inline]
fn into_event(self) -> builder::SocketAddress<'a> {
builder::SocketAddress::IpV6 {
ip: &self.ip.octets,
port: self.port.into(),
}
}
}
impl IntoEvent<bool> for &crate::transport::parameters::MigrationSupport {
#[inline]
fn into_event(self) -> bool {
match self {
crate::transport::parameters::MigrationSupport::Enabled => true,
crate::transport::parameters::MigrationSupport::Disabled => false,
}
}
}
#[builder_derive(derive(Copy))]
struct Path<'a> {
local_addr: SocketAddress<'a>,
local_cid: ConnectionId<'a>,
remote_addr: SocketAddress<'a>,
remote_cid: ConnectionId<'a>,
id: u64,
is_active: bool,
}
#[derive(Clone)]
#[builder_derive(derive(Copy))]
struct ConnectionId<'a> {
bytes: &'a [u8],
}
impl<'a> core::fmt::Debug for ConnectionId<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "0x")?;
for byte in self.bytes {
write!(f, "{byte:02x}")?;
}
Ok(())
}
}
macro_rules! impl_conn_id {
($name:ident) => {
impl<'a> IntoEvent<builder::ConnectionId<'a>> for &'a crate::connection::id::$name {
#[inline]
fn into_event(self) -> builder::ConnectionId<'a> {
builder::ConnectionId {
bytes: self.as_bytes(),
}
}
}
};
}
impl_conn_id!(LocalId);
impl_conn_id!(PeerId);
impl_conn_id!(UnboundedId);
impl_conn_id!(InitialId);
#[derive(Clone)]
#[builder_derive(derive(Copy))]
enum SocketAddress<'a> {
IpV4 { ip: &'a [u8; 4], port: u16 },
IpV6 { ip: &'a [u8; 16], port: u16 },
}
impl<'a> core::fmt::Debug for SocketAddress<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
Self::IpV4 { ip, port } => {
let addr = crate::inet::SocketAddressV4::new(**ip, *port);
write!(f, "{addr}")?;
}
Self::IpV6 { ip, port } => {
let addr = crate::inet::SocketAddressV6::new(**ip, *port);
write!(f, "{addr}")?;
}
}
Ok(())
}
}
impl<'a> core::fmt::Display for SocketAddress<'a> {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
Self::IpV4 { ip, port } => {
let addr = crate::inet::SocketAddressV4::new(**ip, *port);
addr.fmt(f)?;
}
Self::IpV6 { ip, port } => {
let addr = crate::inet::SocketAddressV6::new(**ip, *port);
addr.fmt(f)?;
}
}
Ok(())
}
}
impl<'a> SocketAddress<'a> {
#[inline]
pub fn ip(&self) -> &'a [u8] {
match self {
Self::IpV4 { ip, .. } => &ip[..],
Self::IpV6 { ip, .. } => &ip[..],
}
}
#[inline]
pub fn port(&self) -> u16 {
match self {
Self::IpV4 { port, .. } => *port,
Self::IpV6 { port, .. } => *port,
}
}
}
impl<'a> IntoEvent<api::SocketAddress<'a>> for &'a crate::inet::SocketAddress {
#[inline]
fn into_event(self) -> api::SocketAddress<'a> {
match self {
crate::inet::SocketAddress::IpV4(addr) => api::SocketAddress::IpV4 {
ip: &addr.ip.octets,
port: addr.port.into(),
},
crate::inet::SocketAddress::IpV6(addr) => api::SocketAddress::IpV6 {
ip: &addr.ip.octets,
port: addr.port.into(),
},
}
}
}
impl<'a> IntoEvent<builder::SocketAddress<'a>> for &'a crate::inet::SocketAddress {
#[inline]
fn into_event(self) -> builder::SocketAddress<'a> {
match self {
crate::inet::SocketAddress::IpV4(addr) => addr.into_event(),
crate::inet::SocketAddress::IpV6(addr) => addr.into_event(),
}
}
}
#[cfg(feature = "std")]
impl From<SocketAddress<'_>> for std::net::SocketAddr {
#[inline]
fn from(address: SocketAddress) -> Self {
use std::net;
match address {
SocketAddress::IpV4 { ip, port } => {
let ip = net::IpAddr::V4(net::Ipv4Addr::from(*ip));
Self::new(ip, port)
}
SocketAddress::IpV6 { ip, port } => {
let ip = net::IpAddr::V6(net::Ipv6Addr::from(*ip));
Self::new(ip, port)
}
}
}
}
#[cfg(feature = "std")]
impl From<&SocketAddress<'_>> for std::net::SocketAddr {
#[inline]
fn from(address: &SocketAddress) -> Self {
use std::net;
match address {
SocketAddress::IpV4 { ip, port } => {
let ip = net::IpAddr::V4(net::Ipv4Addr::from(**ip));
Self::new(ip, *port)
}
SocketAddress::IpV6 { ip, port } => {
let ip = net::IpAddr::V6(net::Ipv6Addr::from(**ip));
Self::new(ip, *port)
}
}
}
}
enum DuplicatePacketError {
/// The packet number was already received and is a duplicate.
Duplicate,
/// The received packet number was outside the range of tracked packet numbers.
///
/// This can happen when packets are heavily delayed or reordered. Currently, the maximum
/// amount of reordering is limited to 128 packets. For example, if packet number `142`
/// is received, the allowed range would be limited to `14-142`. If an endpoint received
/// packet `< 14`, it would trigger this event.
TooOld,
}
impl IntoEvent<builder::DuplicatePacketError> for crate::packet::number::SlidingWindowError {
#[inline]
fn into_event(self) -> builder::DuplicatePacketError {
use crate::packet::number::SlidingWindowError;
match self {
SlidingWindowError::TooOld => builder::DuplicatePacketError::TooOld {},
SlidingWindowError::Duplicate => builder::DuplicatePacketError::Duplicate {},
}
}
}
struct EcnCounts {
/// A variable-length integer representing the total number of packets
/// received with the ECT(0) codepoint.
ect_0_count: u64,
/// A variable-length integer representing the total number of packets
/// received with the ECT(1) codepoint.
ect_1_count: u64,
/// A variable-length integer representing the total number of packets
/// received with the CE codepoint.
ce_count: u64,
}
impl IntoEvent<builder::EcnCounts> for crate::frame::ack::EcnCounts {
#[inline]
fn into_event(self) -> builder::EcnCounts {
builder::EcnCounts {
ect_0_count: self.ect_0_count.into_event(),
ect_1_count: self.ect_1_count.into_event(),
ce_count: self.ce_count.into_event(),
}
}
}
//= https://tools.ietf.org/id/draft-marx-qlog-event-definitions-quic-h3-02#A.7
enum Frame {
Padding,
Ping,
Ack {
ecn_counts: Option<EcnCounts>,
largest_acknowledged: u64,
ack_range_count: u64,
},
ResetStream {
id: u64,
error_code: u64,
final_size: u64,
},
StopSending {
id: u64,
error_code: u64,
},
Crypto {
offset: u64,
len: u16,
},
NewToken,
Stream {
id: u64,
offset: u64,
len: u16,
is_fin: bool,
},
MaxData {
value: u64,
},
MaxStreamData {
stream_type: StreamType,
id: u64,
value: u64,
},
MaxStreams {
stream_type: StreamType,
value: u64,
},
DataBlocked {
data_limit: u64,
},
StreamDataBlocked {
stream_id: u64,
stream_data_limit: u64,
},
StreamsBlocked {
stream_type: StreamType,
stream_limit: u64,
},
NewConnectionId {
sequence_number: u64,
retire_prior_to: u64,
},
RetireConnectionId,
PathChallenge,
PathResponse,
ConnectionClose,
HandshakeDone,
Datagram {
len: u16,
},
DcStatelessResetTokens,
}
impl IntoEvent<builder::Frame> for &crate::frame::Padding {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::Padding {}
}
}
impl IntoEvent<builder::Frame> for &crate::frame::Ping {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::Ping {}
}
}
impl<AckRanges: crate::frame::ack::AckRanges> IntoEvent<builder::Frame>
for &crate::frame::Ack<AckRanges>
{
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::Ack {
ecn_counts: self.ecn_counts.map(|val| val.into_event()),
largest_acknowledged: self.largest_acknowledged().into_event(),
ack_range_count: self.ack_ranges().len() as u64,
}
}
}
impl IntoEvent<builder::Frame> for &crate::frame::ResetStream {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::ResetStream {
id: self.stream_id.as_u64(),
error_code: self.application_error_code.as_u64(),
final_size: self.final_size.as_u64(),
}
}
}
impl IntoEvent<builder::Frame> for &crate::frame::StopSending {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::StopSending {
id: self.stream_id.as_u64(),
error_code: self.application_error_code.as_u64(),
}
}
}
impl<'a> IntoEvent<builder::Frame> for &crate::frame::NewToken<'a> {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::NewToken {}
}
}
impl IntoEvent<builder::Frame> for &crate::frame::MaxData {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::MaxData {
value: self.maximum_data.as_u64(),
}
}
}
impl IntoEvent<builder::Frame> for &crate::frame::MaxStreamData {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::MaxStreamData {
id: self.stream_id.as_u64(),
stream_type: crate::stream::StreamId::from_varint(self.stream_id)
.stream_type()
.into_event(),
value: self.maximum_stream_data.as_u64(),
}
}
}
impl IntoEvent<builder::Frame> for &crate::frame::MaxStreams {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::MaxStreams {
stream_type: self.stream_type.into_event(),
value: self.maximum_streams.as_u64(),
}
}
}
impl IntoEvent<builder::Frame> for &crate::frame::DataBlocked {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::DataBlocked {
data_limit: self.data_limit.as_u64(),
}
}
}
impl IntoEvent<builder::Frame> for &crate::frame::StreamDataBlocked {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::StreamDataBlocked {
stream_id: self.stream_id.as_u64(),
stream_data_limit: self.stream_data_limit.as_u64(),
}
}
}
impl IntoEvent<builder::Frame> for &crate::frame::StreamsBlocked {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::StreamsBlocked {
stream_type: self.stream_type.into_event(),
stream_limit: self.stream_limit.as_u64(),
}
}
}
impl<'a> IntoEvent<builder::Frame> for &crate::frame::NewConnectionId<'a> {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::NewConnectionId {
sequence_number: self.sequence_number.as_u64(),
retire_prior_to: self.retire_prior_to.as_u64(),
}
}
}
impl IntoEvent<builder::Frame> for &crate::frame::RetireConnectionId {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::RetireConnectionId {}
}
}
impl<'a> IntoEvent<builder::Frame> for &crate::frame::PathChallenge<'a> {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::PathChallenge {}
}
}
impl<'a> IntoEvent<builder::Frame> for &crate::frame::PathResponse<'a> {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::PathResponse {}
}
}
impl<'a> IntoEvent<builder::Frame> for &crate::frame::ConnectionClose<'a> {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::ConnectionClose {}
}
}
impl IntoEvent<builder::Frame> for &crate::frame::HandshakeDone {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::HandshakeDone {}
}
}
impl<Data> IntoEvent<builder::Frame> for &crate::frame::Stream<Data>
where
Data: s2n_codec::EncoderValue,
{
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::Stream {
id: self.stream_id.as_u64(),
offset: self.offset.as_u64(),
len: self.data.encoding_size() as _,
is_fin: self.is_fin,
}
}
}
impl<Data> IntoEvent<builder::Frame> for &crate::frame::Crypto<Data>
where
Data: s2n_codec::EncoderValue,
{
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::Crypto {
offset: self.offset.as_u64(),
len: self.data.encoding_size() as _,
}
}
}
impl<Data> IntoEvent<builder::Frame> for &crate::frame::Datagram<Data>
where
Data: s2n_codec::EncoderValue,
{
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::Datagram {
len: self.data.encoding_size() as _,
}
}
}
impl<'a> IntoEvent<builder::Frame> for &crate::frame::DcStatelessResetTokens<'a> {
#[inline]
fn into_event(self) -> builder::Frame {
builder::Frame::DcStatelessResetTokens {}
}
}
enum StreamType {
Bidirectional,
Unidirectional,
}
impl IntoEvent<builder::StreamType> for &crate::stream::StreamType {
#[inline]
fn into_event(self) -> builder::StreamType {
match self {
crate::stream::StreamType::Bidirectional => builder::StreamType::Bidirectional {},
crate::stream::StreamType::Unidirectional => builder::StreamType::Unidirectional {},
}
}
}
//= https://tools.ietf.org/id/draft-marx-qlog-event-definitions-quic-h3-02#A.2
//
//= https://tools.ietf.org/id/draft-marx-qlog-event-definitions-quic-h3-02#A.4
enum PacketHeader {
Initial { number: u64, version: u32 },
Handshake { number: u64, version: u32 },
ZeroRtt { number: u64, version: u32 },
OneRtt { number: u64 },
Retry { version: u32 },
// The Version field of a Version Negotiation packet MUST be set to 0x00000000.
VersionNegotiation,
StatelessReset,
}
impl builder::PacketHeader {
#[inline]
pub fn new(
packet_number: crate::packet::number::PacketNumber,
version: u32,
) -> builder::PacketHeader {
use crate::packet::number::PacketNumberSpace;
use builder::PacketHeader;
match packet_number.space() {
PacketNumberSpace::Initial => PacketHeader::Initial {
number: packet_number.into_event(),
version,
},
PacketNumberSpace::Handshake => PacketHeader::Handshake {
number: packet_number.into_event(),
version,
},
PacketNumberSpace::ApplicationData => PacketHeader::OneRtt {
number: packet_number.into_event(),
},
}
}
}
enum PacketType {
Initial,
Handshake,
ZeroRtt,
OneRtt,
Retry,
VersionNegotiation,
StatelessReset,
}
enum KeyType {
Initial,
Handshake,
ZeroRtt,
OneRtt { generation: u16 },
}
/// A context from which the event is being emitted
///
/// An event can occur in the context of an Endpoint or Connection
enum Subject {
Endpoint,
//= https://tools.ietf.org/id/draft-marx-qlog-event-definitions-quic-h3-02#4
//# it is recommended to use
//# QUIC's Original Destination Connection ID (ODCID, the CID chosen by
//# the client when first contacting the server)
/// This maps to an internal connection id, which is a stable identifier across CID changes.
Connection {
id: u64,
},
}
/// An endpoint may be either a Server or a Client
#[exhaustive]
enum EndpointType {
Server,
Client,
}
impl core::fmt::Display for EndpointType {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
match self {
Self::Client {} => write!(f, "client"),
Self::Server {} => write!(f, "server"),
}
}
}
impl IntoEvent<api::EndpointType> for crate::endpoint::Type {
#[inline]
fn into_event(self) -> api::EndpointType {
match self {
Self::Client => api::EndpointType::Client {},
Self::Server => api::EndpointType::Server {},
}
}
}
impl IntoEvent<builder::EndpointType> for crate::endpoint::Type {
#[inline]
fn into_event(self) -> builder::EndpointType {
match self {
Self::Client => builder::EndpointType::Client {},
Self::Server => builder::EndpointType::Server {},
}
}
}
enum DatagramDropReason {
/// There was an error while attempting to decode the datagram.
DecodingFailed,
/// There was an error while parsing the Retry token.
InvalidRetryToken,
/// The peer specified an unsupported QUIC version.
UnsupportedVersion,
/// The peer sent an invalid Destination Connection Id.
InvalidDestinationConnectionId,
/// The peer sent an invalid Source Connection Id.
InvalidSourceConnectionId,
/// Application provided invalid MTU configuration.
InvalidMtuConfiguration {
/// MTU configuration for the endpoint
endpoint_mtu_config: MtuConfig,
// TODO expose connection level mtu config.
// TODO expose the remote address.
// https://github.com/aws/s2n-quic/issues/2254
// error from mtu::Config
// remote_addr: SocketAddress<'a>,
},
/// The Destination Connection Id is unknown and does not map to a Connection.
///
/// Connections are mapped to Destination Connections Ids (DCID) and packets
/// in a Datagram are routed to a connection based on the DCID in the first
/// packet. If a Connection is not found for the specified DCID then the
/// datagram can not be processed and is dropped.
UnknownDestinationConnectionId,
/// The connection attempt was rejected.
RejectedConnectionAttempt,
/// A datagram was received from an unknown server address.
UnknownServerAddress,
/// The peer initiated a connection migration before the handshake was confirmed.
ConnectionMigrationDuringHandshake,
/// The attempted connection migration was rejected.
RejectedConnectionMigration,
/// The maximum number of paths per connection was exceeded.
PathLimitExceeded,
/// The peer initiated a connection migration without supplying enough connection IDs to use.
InsufficientConnectionIds,
}
struct MtuConfig {
initial_mtu: u16,
base_mtu: u16,
max_mtu: u16,
}
impl<'a> IntoEvent<builder::MtuConfig> for &'a crate::path::mtu::Config {
#[inline]
fn into_event(self) -> builder::MtuConfig {
builder::MtuConfig {
initial_mtu: self.initial_mtu().into(),
base_mtu: self.base_mtu().into(),
max_mtu: self.max_mtu().into(),
}
}
}
enum KeySpace {
Initial {},
Handshake {},
ZeroRtt {},
OneRtt {},
}
enum PacketSkipReason {
//= https://www.rfc-editor.org/rfc/rfc9002#section-6.2.4
//# If the sender wants to elicit a faster acknowledgement on PTO, it can
//# skip a packet number to eliminate the acknowledgment delay.
/// Skipped a packet number to elicit a quicker PTO acknowledgment
PtoProbe {},
//= https://www.rfc-editor.org/rfc/rfc9000#section-21.4
//# An endpoint that acknowledges packets it has not received might cause
//# a congestion controller to permit sending at rates beyond what the
//# network supports. An endpoint MAY skip packet numbers when sending
//# packets to detect this behavior.
/// Skipped a packet number to detect an Optimistic Ack attack
OptimisticAckMitigation {},
}
enum PacketDropReason<'a> {
/// A connection error occurred and is no longer able to process packets.
ConnectionError { path: Path<'a> },
/// The handshake needed to be complete before processing the packet.
///
/// To ensure the connection stays secure, short packets can only be processed
/// once the handshake has completed.
HandshakeNotComplete { path: Path<'a> },
/// The packet contained a version which did not match the version negotiated
/// during the handshake.
VersionMismatch { version: u32, path: Path<'a> },
/// A datagram contained more than one destination connection ID, which is
/// not allowed.
ConnectionIdMismatch {
packet_cid: &'a [u8],
path: Path<'a>,
},
/// There was a failure when attempting to remove header protection.
UnprotectFailed { space: KeySpace, path: Path<'a> },
/// There was a failure when attempting to decrypt the packet.
DecryptionFailed {
path: Path<'a>,
packet_header: PacketHeader,
},
/// Packet decoding failed.
///
/// The payload is decoded one packet at a time. If decoding fails
/// then the remaining packets are also discarded.
DecodingFailed { path: Path<'a> },
/// The client received a non-empty retry token.
NonEmptyRetryToken { path: Path<'a> },
/// A Retry packet was discarded.
RetryDiscarded {
reason: RetryDiscardReason<'a>,
path: Path<'a>,
},
/// The received Initial packet was not transported in a datagram of at least 1200 bytes
UndersizedInitialPacket { path: Path<'a> },
/// The destination connection ID in the packet was the initial connection ID but was in
/// a non-initial packet.
InitialConnectionIdInvalidSpace {
path: Path<'a>,
packet_type: PacketType,
},
}
#[deprecated(note = "use on_rx_ack_range_dropped event instead")]
enum AckAction {
/// Ack range for received packets was dropped due to space constraints
///
/// For the purpose of processing Acks, RX packet numbers are stored as
/// packet_number ranges in an IntervalSet; only lower and upper bounds
/// are stored instead of individual packet_numbers. Ranges are merged
/// when possible so only disjointed ranges are stored.
///
/// When at `capacity`, the lowest packet_number range is dropped.
RxAckRangeDropped {
/// The packet number range which was dropped
packet_number_range: core::ops::RangeInclusive<u64>,
/// The number of disjoint ranges the IntervalSet can store
capacity: usize,
/// The store packet_number range in the IntervalSet
stored_range: core::ops::RangeInclusive<u64>,
},
}
enum RetryDiscardReason<'a> {
/// Received a Retry packet with SCID field equal to DCID field.
ScidEqualsDcid { cid: &'a [u8] },
/// A client only processes at most one Retry packet.
RetryAlreadyProcessed,
/// The client discards Retry packets if a valid Initial packet
/// has been received and processed.
InitialAlreadyProcessed,
/// The Retry packet received contained an invalid retry integrity tag
InvalidIntegrityTag,
}
enum MigrationDenyReason {
BlockedPort,
PortScopeChanged,
IpScopeChange,
ConnectionMigrationDisabled,
}
/// The current state of the ECN controller for the path
enum EcnState {
/// ECN capability is being actively tested
Testing,
/// ECN capability has been tested, but not validated yet
Unknown,
/// ECN capability testing has failed validation
Failed,
/// ECN capability has been confirmed
Capable,
}
/// Events tracking the progress of handshake status
enum HandshakeStatus {
/// The handshake has completed.
Complete,
/// The handshake has been confirmed.
Confirmed,
/// A HANDSHAKE_DONE frame was delivered or received.
///
/// A Client endpoint receives a HANDSHAKE_DONE frame and
/// only a Server is allowed to send the HANDSHAKE_DONE
/// frame.
HandshakeDoneAcked,
/// A HANDSHAKE_DONE frame was declared lost.
///
/// The Server is responsible for re-transmitting the
/// HANDSHAKE_DONE frame until it is acked by the peer.
HandshakeDoneLost,
}
/// The source that caused a congestion event
enum CongestionSource {
/// Explicit Congestion Notification
Ecn,
/// One or more packets were detected lost
PacketLoss,
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[allow(non_camel_case_types)] // we prefer to match the standard identifier
enum CipherSuite {
TLS_AES_128_GCM_SHA256,
TLS_AES_256_GCM_SHA384,
TLS_CHACHA20_POLY1305_SHA256,
Unknown,
}
impl CipherSuite {
#[inline]
pub fn as_str(&self) -> &'static str {
match self {
Self::TLS_AES_128_GCM_SHA256 {} => "TLS_AES_128_GCM_SHA256",
Self::TLS_AES_256_GCM_SHA384 {} => "TLS_AES_256_GCM_SHA384",
Self::TLS_CHACHA20_POLY1305_SHA256 {} => "TLS_CHACHA20_POLY1305_SHA256",
Self::Unknown {} => "UNKNOWN",
}
}
}
enum PathChallengeStatus {
Validated,
Abandoned,
}
/// The reason the slow start congestion controller state has been exited
enum SlowStartExitCause {
/// A packet was determined lost
PacketLoss,
/// An Explicit Congestion Notification: Congestion Experienced marking was received
Ecn,
/// The round trip time estimate was updated
Rtt,
/// Slow Start exited due to a reason other than those above
///
/// With the Cubic congestion controller, this reason is used after the initial exiting of
/// Slow Start, when the previously determined Slow Start threshold is exceed by the
/// congestion window.
Other,
}
/// The reason the MTU was updated
enum MtuUpdatedCause {
/// The MTU was initialized with the default value
NewPath,
/// An MTU probe was acknowledged by the peer
ProbeAcknowledged,
/// A blackhole was detected
Blackhole,
/// An early packet using the configured InitialMtu was lost
InitialMtuPacketLost,
}
/// A bandwidth delivery rate estimate with associated metadata
struct RateSample {
/// The length of the sampling interval
interval: Duration,
/// The amount of data in bytes marked as delivered over the sampling interval
delivered_bytes: u64,
/// The amount of data in bytes marked as lost over the sampling interval
lost_bytes: u64,
/// The number of packets marked as explicit congestion experienced over the sampling interval
ecn_ce_count: u64,
/// PacketInfo::is_app_limited from the most recent acknowledged packet
is_app_limited: bool,
/// PacketInfo::delivered_bytes from the most recent acknowledged packet
prior_delivered_bytes: u64,
/// PacketInfo::bytes_in_flight from the most recent acknowledged packet
bytes_in_flight: u32,
/// PacketInfo::lost_bytes from the most recent acknowledged packet
prior_lost_bytes: u64,
/// PacketInfo::ecn_ce_count from the most recent acknowledged packet
prior_ecn_ce_count: u64,
/// The delivery rate for this rate sample
delivery_rate_bytes_per_second: u64,
}
// The BBR congestion controller State
enum BbrState {
Startup,
Drain,
ProbeBwDown,
ProbeBwCruise,
ProbeBwRefill,
ProbeBwUp,
ProbeRtt,