Skip to main content

qlog/events/
mod.rs

1// Copyright (C) 2021, Cloudflare, Inc.
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8//     * Redistributions of source code must retain the above copyright notice,
9//       this list of conditions and the following disclaimer.
10//
11//     * Redistributions in binary form must reproduce the above copyright
12//       notice, this list of conditions and the following disclaimer in the
13//       documentation and/or other materials provided with the distribution.
14//
15// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
19// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27use crate::Bytes;
28use crate::Token;
29use http3::*;
30use quic::*;
31
32use serde::Deserialize;
33use serde::Serialize;
34
35use std::collections::BTreeMap;
36
37pub type ExData = BTreeMap<String, serde_json::Value>;
38
39pub const LOGLEVEL_URI: &str = "urn:ietf:params:qlog:events:loglevel-13";
40
41pub const QUIC_URI: &str = "urn:ietf:params:qlog:events:quic-12";
42pub const HTTP3_URI: &str = "urn:ietf:params:qlog:events:http3-12";
43
44#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug, Default)]
45#[serde(untagged)]
46pub enum EventType {
47    QuicEventType(QuicEventType),
48
49    Http3EventType(Http3EventType),
50
51    LogLevelEventType(LogLevelEventType),
52
53    #[default]
54    None,
55}
56
57use crate::TimeFormat;
58
59#[serde_with::skip_serializing_none]
60#[derive(Serialize, Deserialize, Clone, Debug)]
61pub struct Event {
62    pub time: f64,
63
64    // Strictly, the qlog 02 spec says we should have a name field in the
65    // `Event` structure. However, serde's autogenerated Deserialize code
66    // struggles to read Events properly because the `EventData` types often
67    // alias. In order to work around that, we use can use a trick that will
68    // give serde autogen all the information that it needs while also produced
69    // a legal qlog. Specifically, strongly linking an EventData enum variant
70    // with the wire-format name.
71    //
72    // The trick is to use Adjacent Tagging
73    // (https://serde.rs/enum-representations.html#adjacently-tagged) with
74    // Struct flattening (https://serde.rs/attr-flatten.html). At a high level
75    // this first creates an `EventData` JSON object:
76    //
77    // {name: <enum variant name>, data: enum variant data }
78    //
79    // and then flattens those fields into the `Event` object.
80    #[serde(flatten)]
81    pub data: EventData,
82
83    #[serde(flatten)]
84    pub ex_data: Box<ExData>,
85
86    pub group_id: Option<Box<String>>,
87
88    pub time_format: Option<TimeFormat>,
89
90    #[serde(skip)]
91    ty: EventType,
92}
93
94impl Event {
95    /// Returns a new `Event` object with the provided time and data.
96    pub fn with_time(time: f64, data: EventData) -> Self {
97        Self::with_time_ex(time, data, Default::default())
98    }
99
100    /// Returns a new `Event` object with the provided time, data and ex_data.
101    pub fn with_time_ex(time: f64, data: EventData, ex_data: ExData) -> Self {
102        let ty = EventType::from(&data);
103        Event {
104            time,
105            data,
106            ex_data: Box::new(ex_data),
107            group_id: Default::default(),
108            time_format: Default::default(),
109            ty,
110        }
111    }
112}
113
114impl Eventable for Event {
115    fn importance(&self) -> EventImportance {
116        self.ty.into()
117    }
118
119    fn set_time(&mut self, time: f64) {
120        self.time = time;
121    }
122}
123
124impl PartialEq for Event {
125    // custom comparison to skip over the `ty` field
126    fn eq(&self, other: &Event) -> bool {
127        self.time == other.time &&
128            self.data == other.data &&
129            self.ex_data == other.ex_data &&
130            self.group_id == other.group_id &&
131            self.time_format == other.time_format
132    }
133}
134
135#[derive(Serialize, Deserialize, Clone, Debug)]
136pub struct JsonEvent {
137    pub time: f64,
138
139    #[serde(skip)]
140    pub importance: EventImportance,
141
142    pub name: String,
143    pub data: serde_json::Value,
144}
145
146impl Eventable for JsonEvent {
147    fn importance(&self) -> EventImportance {
148        self.importance
149    }
150
151    fn set_time(&mut self, time: f64) {
152        self.time = time;
153    }
154}
155
156#[derive(Clone, Copy, Debug, Default)]
157pub enum EventImportance {
158    #[default]
159    Core,
160    Base,
161    Extra,
162}
163
164impl EventImportance {
165    /// Returns true if this importance level is included by `other`.
166    pub fn is_contained_in(&self, other: &EventImportance) -> bool {
167        match (other, self) {
168            (EventImportance::Core, EventImportance::Core) => true,
169
170            (EventImportance::Base, EventImportance::Core) |
171            (EventImportance::Base, EventImportance::Base) => true,
172
173            (EventImportance::Extra, EventImportance::Core) |
174            (EventImportance::Extra, EventImportance::Base) |
175            (EventImportance::Extra, EventImportance::Extra) => true,
176
177            (..) => false,
178        }
179    }
180}
181
182impl From<EventType> for EventImportance {
183    fn from(ty: EventType) -> Self {
184        match ty {
185            EventType::QuicEventType(QuicEventType::ServerListening) =>
186                EventImportance::Extra,
187            EventType::QuicEventType(QuicEventType::ConnectionStarted) =>
188                EventImportance::Base,
189            EventType::QuicEventType(QuicEventType::ConnectionClosed) =>
190                EventImportance::Base,
191            EventType::QuicEventType(QuicEventType::ConnectionIdUpdated) =>
192                EventImportance::Base,
193            EventType::QuicEventType(QuicEventType::SpinBitUpdated) =>
194                EventImportance::Base,
195            EventType::QuicEventType(QuicEventType::ConnectionStateUpdated) =>
196                EventImportance::Base,
197            EventType::QuicEventType(QuicEventType::TupleAssigned) =>
198                EventImportance::Extra,
199            EventType::QuicEventType(QuicEventType::MtuUpdated) =>
200                EventImportance::Extra,
201
202            EventType::QuicEventType(QuicEventType::VersionInformation) =>
203                EventImportance::Core,
204            EventType::QuicEventType(QuicEventType::AlpnInformation) =>
205                EventImportance::Core,
206            EventType::QuicEventType(QuicEventType::ParametersSet) =>
207                EventImportance::Core,
208            EventType::QuicEventType(QuicEventType::ParametersRestored) =>
209                EventImportance::Base,
210            EventType::QuicEventType(QuicEventType::PacketSent) =>
211                EventImportance::Core,
212            EventType::QuicEventType(QuicEventType::PacketReceived) =>
213                EventImportance::Core,
214            EventType::QuicEventType(QuicEventType::PacketDropped) =>
215                EventImportance::Base,
216            EventType::QuicEventType(QuicEventType::PacketBuffered) =>
217                EventImportance::Base,
218            EventType::QuicEventType(QuicEventType::PacketsAcked) =>
219                EventImportance::Extra,
220            EventType::QuicEventType(QuicEventType::UdpDatagramsSent) =>
221                EventImportance::Extra,
222            EventType::QuicEventType(QuicEventType::UdpDatagramsReceived) =>
223                EventImportance::Extra,
224            EventType::QuicEventType(QuicEventType::UdpDatagramDropped) =>
225                EventImportance::Extra,
226            EventType::QuicEventType(QuicEventType::StreamStateUpdated) =>
227                EventImportance::Base,
228            EventType::QuicEventType(QuicEventType::FramesProcessed) =>
229                EventImportance::Extra,
230            EventType::QuicEventType(QuicEventType::StreamDataMoved) =>
231                EventImportance::Base,
232            EventType::QuicEventType(QuicEventType::DatagramDataMoved) =>
233                EventImportance::Base,
234            EventType::QuicEventType(
235                QuicEventType::ConnectionDataBlockedUpdated,
236            ) => EventImportance::Extra,
237            EventType::QuicEventType(QuicEventType::StreamDataBlockedUpdated) =>
238                EventImportance::Extra,
239            EventType::QuicEventType(
240                QuicEventType::DatagramDataBlockedUpdated,
241            ) => EventImportance::Extra,
242            EventType::QuicEventType(QuicEventType::MigrationStateUpdated) =>
243                EventImportance::Base,
244
245            EventType::QuicEventType(QuicEventType::KeyUpdated) =>
246                EventImportance::Base,
247            EventType::QuicEventType(QuicEventType::KeyDiscarded) =>
248                EventImportance::Base,
249
250            EventType::QuicEventType(QuicEventType::RecoveryParametersSet) =>
251                EventImportance::Base,
252            EventType::QuicEventType(QuicEventType::RecoveryMetricsUpdated) =>
253                EventImportance::Core,
254            EventType::QuicEventType(QuicEventType::CongestionStateUpdated) =>
255                EventImportance::Base,
256            EventType::QuicEventType(QuicEventType::TimerUpdated) =>
257                EventImportance::Extra,
258            EventType::QuicEventType(QuicEventType::PacketLost) =>
259                EventImportance::Core,
260            EventType::QuicEventType(QuicEventType::MarkedForRetransmit) =>
261                EventImportance::Extra,
262            EventType::QuicEventType(QuicEventType::EcnStateUpdated) =>
263                EventImportance::Extra,
264
265            EventType::Http3EventType(Http3EventType::ParametersSet) =>
266                EventImportance::Base,
267            EventType::Http3EventType(Http3EventType::StreamTypeSet) =>
268                EventImportance::Base,
269            EventType::Http3EventType(Http3EventType::PriorityUpdated) =>
270                EventImportance::Base,
271            EventType::Http3EventType(Http3EventType::FrameCreated) =>
272                EventImportance::Core,
273            EventType::Http3EventType(Http3EventType::FrameParsed) =>
274                EventImportance::Core,
275            EventType::Http3EventType(Http3EventType::DatagramCreated) =>
276                EventImportance::Base,
277            EventType::Http3EventType(Http3EventType::DatagramParsed) =>
278                EventImportance::Base,
279            EventType::Http3EventType(Http3EventType::PushResolved) =>
280                EventImportance::Extra,
281
282            _ => unimplemented!(),
283        }
284    }
285}
286
287pub trait Eventable {
288    fn importance(&self) -> EventImportance;
289
290    fn set_time(&mut self, time: f64);
291}
292
293impl From<&EventData> for EventType {
294    fn from(event_data: &EventData) -> Self {
295        match event_data {
296            EventData::QuicServerListening { .. } =>
297                EventType::QuicEventType(QuicEventType::ServerListening),
298            EventData::QuicConnectionStarted { .. } =>
299                EventType::QuicEventType(QuicEventType::ConnectionStarted),
300            EventData::QuicConnectionClosed { .. } =>
301                EventType::QuicEventType(QuicEventType::ConnectionClosed),
302            EventData::QuicConnectionIdUpdated { .. } =>
303                EventType::QuicEventType(QuicEventType::ConnectionIdUpdated),
304            EventData::QuicSpinBitUpdated { .. } =>
305                EventType::QuicEventType(QuicEventType::SpinBitUpdated),
306            EventData::QuicConnectionStateUpdated { .. } =>
307                EventType::QuicEventType(QuicEventType::ConnectionStateUpdated),
308            EventData::QuicTupleAssigned { .. } =>
309                EventType::QuicEventType(QuicEventType::TupleAssigned),
310            EventData::QuicMtuUpdated { .. } =>
311                EventType::QuicEventType(QuicEventType::MtuUpdated),
312
313            EventData::QuicVersionInformation { .. } =>
314                EventType::QuicEventType(QuicEventType::VersionInformation),
315            EventData::QuicAlpnInformation { .. } =>
316                EventType::QuicEventType(QuicEventType::AlpnInformation),
317            EventData::QuicParametersSet { .. } =>
318                EventType::QuicEventType(QuicEventType::ParametersSet),
319            EventData::QuicParametersRestored { .. } =>
320                EventType::QuicEventType(QuicEventType::ParametersRestored),
321            EventData::QuicPacketSent { .. } =>
322                EventType::QuicEventType(QuicEventType::PacketSent),
323            EventData::QuicPacketReceived { .. } =>
324                EventType::QuicEventType(QuicEventType::PacketReceived),
325            EventData::QuicPacketDropped { .. } =>
326                EventType::QuicEventType(QuicEventType::PacketDropped),
327            EventData::QuicPacketBuffered { .. } =>
328                EventType::QuicEventType(QuicEventType::PacketBuffered),
329            EventData::QuicPacketsAcked { .. } =>
330                EventType::QuicEventType(QuicEventType::PacketsAcked),
331            EventData::QuicUdpDatagramsSent { .. } =>
332                EventType::QuicEventType(QuicEventType::UdpDatagramsSent),
333            EventData::QuicUdpDatagramsReceived { .. } =>
334                EventType::QuicEventType(QuicEventType::UdpDatagramsReceived),
335            EventData::QuicUdpDatagramDropped { .. } =>
336                EventType::QuicEventType(QuicEventType::UdpDatagramDropped),
337            EventData::QuicStreamStateUpdated { .. } =>
338                EventType::QuicEventType(QuicEventType::StreamStateUpdated),
339            EventData::QuicFramesProcessed { .. } =>
340                EventType::QuicEventType(QuicEventType::FramesProcessed),
341            EventData::QuicStreamDataMoved { .. } =>
342                EventType::QuicEventType(QuicEventType::StreamDataMoved),
343            EventData::QuicDatagramDataMoved { .. } =>
344                EventType::QuicEventType(QuicEventType::DatagramDataMoved),
345            EventData::QuicConnectionDataBlockedUpdated { .. } =>
346                EventType::QuicEventType(
347                    QuicEventType::ConnectionDataBlockedUpdated,
348                ),
349            EventData::QuicStreamDataBlockedUpdated { .. } =>
350                EventType::QuicEventType(QuicEventType::StreamDataBlockedUpdated),
351            EventData::QuicDatagramDataBlockedUpdated { .. } =>
352                EventType::QuicEventType(
353                    QuicEventType::DatagramDataBlockedUpdated,
354                ),
355            EventData::QuicMigrationStateUpdated { .. } =>
356                EventType::QuicEventType(QuicEventType::MigrationStateUpdated),
357
358            EventData::QuicKeyUpdated { .. } =>
359                EventType::QuicEventType(QuicEventType::KeyUpdated),
360            EventData::QuicKeyDiscarded { .. } =>
361                EventType::QuicEventType(QuicEventType::KeyDiscarded),
362
363            EventData::QuicRecoveryParametersSet { .. } =>
364                EventType::QuicEventType(QuicEventType::RecoveryParametersSet),
365            EventData::QuicMetricsUpdated { .. } =>
366                EventType::QuicEventType(QuicEventType::RecoveryMetricsUpdated),
367            EventData::QuicCongestionStateUpdated { .. } =>
368                EventType::QuicEventType(QuicEventType::CongestionStateUpdated),
369            EventData::QuicTimerUpdated { .. } =>
370                EventType::QuicEventType(QuicEventType::TimerUpdated),
371            EventData::QuicPacketLost { .. } =>
372                EventType::QuicEventType(QuicEventType::PacketLost),
373            EventData::QuicMarkedForRetransmit { .. } =>
374                EventType::QuicEventType(QuicEventType::MarkedForRetransmit),
375            EventData::QuicEcnStateUpdated { .. } =>
376                EventType::QuicEventType(QuicEventType::EcnStateUpdated),
377
378            EventData::Http3ParametersSet { .. } =>
379                EventType::Http3EventType(Http3EventType::ParametersSet),
380            EventData::Http3ParametersRestored { .. } =>
381                EventType::Http3EventType(Http3EventType::ParametersRestored),
382            EventData::Http3StreamTypeSet { .. } =>
383                EventType::Http3EventType(Http3EventType::StreamTypeSet),
384            EventData::Http3PriorityUpdated { .. } =>
385                EventType::Http3EventType(Http3EventType::PriorityUpdated),
386            EventData::Http3FrameCreated { .. } =>
387                EventType::Http3EventType(Http3EventType::FrameCreated),
388            EventData::Http3FrameParsed { .. } =>
389                EventType::Http3EventType(Http3EventType::FrameParsed),
390            EventData::Http3DatagramCreated { .. } =>
391                EventType::Http3EventType(Http3EventType::DatagramCreated),
392            EventData::Http3DatagramParsed { .. } =>
393                EventType::Http3EventType(Http3EventType::DatagramParsed),
394            EventData::Http3PushResolved { .. } =>
395                EventType::Http3EventType(Http3EventType::PushResolved),
396
397            EventData::LogLevelError { .. } =>
398                EventType::LogLevelEventType(LogLevelEventType::Error),
399            EventData::LogLevelWarning { .. } =>
400                EventType::LogLevelEventType(LogLevelEventType::Warning),
401            EventData::LogLevelInfo { .. } =>
402                EventType::LogLevelEventType(LogLevelEventType::Info),
403            EventData::LogLevelDebug { .. } =>
404                EventType::LogLevelEventType(LogLevelEventType::Debug),
405            EventData::LogLevelVerbose { .. } =>
406                EventType::LogLevelEventType(LogLevelEventType::Verbose),
407            //_ => EventType::None,
408        }
409    }
410}
411
412#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
413#[serde(rename_all = "snake_case")]
414pub enum DataRecipient {
415    User,
416    Application,
417    Transport,
418    Network,
419    Dropped,
420}
421
422#[serde_with::skip_serializing_none]
423#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug, Default)]
424pub struct RawInfo {
425    pub length: Option<u64>,
426    pub payload_length: Option<u64>,
427
428    pub data: Option<Box<Bytes>>,
429}
430
431#[serde_with::skip_serializing_none]
432#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
433#[serde(tag = "name", content = "data")]
434#[allow(clippy::large_enum_variant)]
435pub enum EventData {
436    // QUIC
437    #[serde(rename = "quic:server_listening")]
438    QuicServerListening(quic::ServerListening),
439
440    #[serde(rename = "quic:connection_started")]
441    QuicConnectionStarted(quic::ConnectionStarted),
442
443    #[serde(rename = "quic:connection_closed")]
444    QuicConnectionClosed(quic::ConnectionClosed),
445
446    #[serde(rename = "quic:connection_id_updated")]
447    QuicConnectionIdUpdated(quic::ConnectionIdUpdated),
448
449    #[serde(rename = "quic:spin_bit_updated")]
450    QuicSpinBitUpdated(quic::SpinBitUpdated),
451
452    #[serde(rename = "quic:connection_state_updated")]
453    QuicConnectionStateUpdated(quic::ConnectionStateUpdated),
454
455    #[serde(rename = "quic:tuple_assigned")]
456    QuicTupleAssigned(quic::TupleAssigned),
457
458    #[serde(rename = "quic:mtu_updated")]
459    QuicMtuUpdated(quic::MtuUpdated),
460
461    #[serde(rename = "quic:version_information")]
462    QuicVersionInformation(quic::QuicVersionInformation),
463
464    #[serde(rename = "quic:alpn_information")]
465    QuicAlpnInformation(quic::AlpnInformation),
466
467    #[serde(rename = "quic:parameters_set")]
468    QuicParametersSet(Box<quic::ParametersSet>),
469
470    #[serde(rename = "quic:parameters_restored")]
471    QuicParametersRestored(quic::ParametersRestored),
472
473    #[serde(rename = "quic:packet_sent")]
474    QuicPacketSent(quic::PacketSent),
475
476    #[serde(rename = "quic:packet_received")]
477    QuicPacketReceived(quic::PacketReceived),
478
479    #[serde(rename = "quic:packet_dropped")]
480    QuicPacketDropped(quic::PacketDropped),
481
482    #[serde(rename = "quic:packet_buffered")]
483    QuicPacketBuffered(quic::PacketBuffered),
484
485    #[serde(rename = "quic:packets_acked")]
486    QuicPacketsAcked(quic::PacketsAcked),
487
488    #[serde(rename = "quic:datagrams_sent")]
489    QuicUdpDatagramsSent(quic::UdpDatagramsSent),
490
491    #[serde(rename = "quic:datagrams_received")]
492    QuicUdpDatagramsReceived(quic::UdpDatagramsReceived),
493
494    #[serde(rename = "quic:datagram_dropped")]
495    QuicUdpDatagramDropped(quic::UdpDatagramDropped),
496
497    #[serde(rename = "quic:stream_state_updated")]
498    QuicStreamStateUpdated(quic::StreamStateUpdated),
499
500    #[serde(rename = "quic:frames_processed")]
501    QuicFramesProcessed(quic::FramesProcessed),
502
503    #[serde(rename = "quic:stream_data_moved")]
504    QuicStreamDataMoved(quic::StreamDataMoved),
505
506    #[serde(rename = "quic:datagram_data_moved")]
507    QuicDatagramDataMoved(quic::DatagramDataMoved),
508
509    #[serde(rename = "quic:connection_data_blocked_updated")]
510    QuicConnectionDataBlockedUpdated(quic::ConnectionDataBlockedUpdated),
511
512    #[serde(rename = "quic:stream_data_blocked_updated")]
513    QuicStreamDataBlockedUpdated(quic::StreamDataBlockedUpdated),
514
515    #[serde(rename = "quic:datagram_data_blocked_updated")]
516    QuicDatagramDataBlockedUpdated(quic::DatagramDataBlockedUpdated),
517
518    #[serde(rename = "quic:migration_state_updated")]
519    QuicMigrationStateUpdated(quic::MigrationStateUpdated),
520
521    #[serde(rename = "quic:key_updated")]
522    QuicKeyUpdated(quic::KeyUpdated),
523
524    #[serde(rename = "quic:key_retired")]
525    QuicKeyDiscarded(quic::KeyDiscarded),
526
527    #[serde(rename = "quic:recovery_parameters_set")]
528    QuicRecoveryParametersSet(quic::RecoveryParametersSet),
529
530    #[serde(rename = "quic:recovery_metrics_updated")]
531    QuicMetricsUpdated(quic::RecoveryMetricsUpdated),
532
533    #[serde(rename = "quic:congestion_state_updated")]
534    QuicCongestionStateUpdated(quic::CongestionStateUpdated),
535
536    #[serde(rename = "quic:timer_updated")]
537    QuicTimerUpdated(quic::TimerUpdated),
538
539    #[serde(rename = "quic:packet_lost")]
540    QuicPacketLost(quic::PacketLost),
541
542    #[serde(rename = "quic:marked_for_retransmit")]
543    QuicMarkedForRetransmit(quic::MarkedForRetransmit),
544
545    #[serde(rename = "quic:ecn_state_updated")]
546    QuicEcnStateUpdated(quic::EcnStateUpdated),
547
548    // HTTP/3
549    #[serde(rename = "http3:parameters_set")]
550    Http3ParametersSet(http3::ParametersSet),
551
552    #[serde(rename = "http3:parameters_restored")]
553    Http3ParametersRestored(http3::ParametersRestored),
554
555    #[serde(rename = "http3:stream_type_set")]
556    Http3StreamTypeSet(http3::StreamTypeSet),
557
558    #[serde(rename = "http3:priority_updated")]
559    Http3PriorityUpdated(http3::PriorityUpdated),
560
561    #[serde(rename = "http3:frame_created")]
562    Http3FrameCreated(http3::FrameCreated),
563
564    #[serde(rename = "http3:frame_parsed")]
565    Http3FrameParsed(http3::FrameParsed),
566
567    #[serde(rename = "http3:datagram_created")]
568    Http3DatagramCreated(http3::DatagramCreated),
569
570    #[serde(rename = "http3:datagram_parsed")]
571    Http3DatagramParsed(http3::DatagramParsed),
572
573    #[serde(rename = "http3:push_resolved")]
574    Http3PushResolved(http3::PushResolved),
575
576    // LogLevel
577    #[serde(rename = "loglevel:error")]
578    LogLevelError {
579        code: Option<u64>,
580        message: Option<String>,
581    },
582
583    #[serde(rename = "loglevel:warning")]
584    LogLevelWarning {
585        code: Option<u64>,
586        message: Option<String>,
587    },
588
589    #[serde(rename = "loglevel:info")]
590    LogLevelInfo {
591        code: Option<u64>,
592        message: Option<String>,
593    },
594
595    #[serde(rename = "loglevel:debug")]
596    LogLevelDebug {
597        code: Option<u64>,
598        message: Option<String>,
599    },
600
601    #[serde(rename = "loglevel:verbose")]
602    LogLevelVerbose {
603        code: Option<u64>,
604        message: Option<String>,
605    },
606}
607
608impl EventData {
609    /// Returns size of `EventData` array of `QuicFrame`s if it exists.
610    pub fn contains_quic_frames(&self) -> Option<usize> {
611        // For some EventData variants, the frame array is optional
612        // but for others it is mandatory.
613        match self {
614            EventData::QuicPacketSent(pkt) =>
615                pkt.frames.as_ref().map(|f| f.len()),
616
617            EventData::QuicPacketReceived(pkt) =>
618                pkt.frames.as_ref().map(|f| f.len()),
619
620            EventData::QuicPacketLost(pkt) =>
621                pkt.frames.as_ref().map(|f| f.len()),
622
623            EventData::QuicMarkedForRetransmit(ev) => Some(ev.frames.len()),
624            EventData::QuicFramesProcessed(ev) => Some(ev.frames.len()),
625
626            _ => None,
627        }
628    }
629}
630
631#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Eq, Debug)]
632#[serde(rename_all = "snake_case")]
633pub enum LogLevelEventType {
634    Error,
635    Warning,
636    Info,
637    Debug,
638    Verbose,
639}
640
641#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
642#[serde(untagged)]
643pub enum ConnectionClosedEventError {
644    TransportError(TransportError),
645    CryptoError(CryptoError),
646}
647
648#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
649#[serde(untagged)]
650pub enum ConnectionClosedFrameError {
651    TransportError(TransportError),
652    ApplicationError(ApplicationError),
653    CryptoError(CryptoError),
654}
655
656#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
657#[serde(rename_all = "snake_case")]
658pub enum ApplicationError {
659    HttpNoError,
660    HttpGeneralProtocolError,
661    HttpInternalError,
662    HttpRequestCancelled,
663    HttpIncompleteRequest,
664    HttpConnectError,
665    HttpFrameError,
666    HttpExcessiveLoad,
667    HttpVersionFallback,
668    HttpIdError,
669    HttpStreamCreationError,
670    HttpClosedCriticalStream,
671    HttpEarlyResponse,
672    HttpMissingSettings,
673    HttpUnexpectedFrame,
674    HttpRequestRejection,
675    HttpSettingsError,
676    Unknown,
677}
678
679// TODO
680#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
681#[serde(rename_all = "snake_case")]
682pub enum CryptoError {
683    Prefix,
684}
685
686#[serde_with::skip_serializing_none]
687#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
688pub struct TupleEndpointInfo {
689    pub ip_v4: Option<String>,
690    pub port_v4: Option<u16>,
691    pub ip_v6: Option<String>,
692    pub port_v6: Option<u16>,
693
694    pub connection_ids: Option<Vec<Bytes>>,
695}
696
697pub mod http3;
698pub mod quic;