-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathgenerated.rs
565 lines (563 loc) · 19.2 KB
/
generated.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
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// DO NOT MODIFY THIS FILE
// This file was generated with the `s2n-quic-events` crate and any required
// changes should be made there.
use super::*;
pub mod api {
#"]
use super::*;
pub use traits::Subscriber;
#[derive(Clone, Debug)]
#[non_exhaustive]
#[doc = " Frame was sent"]
pub struct FrameSent {
pub packet_header: PacketHeader,
pub path_id: u64,
pub frame: Frame,
}
impl Event for FrameSent {
const NAME: &'static str = "transport:frame_sent";
}
}
#[cfg(feature = "event-tracing")]
pub mod tracing {
#"]
use super::api;
#[doc = r" Emits events with [`tracing`](https://docs.rs/tracing)"]
#[derive(Clone, Debug)]
pub struct Subscriber {
client: tracing::Span,
server: tracing::Span,
}
impl Default for Subscriber {
fn default() -> Self {
let root = tracing :: span ! (target : "s2n_quic_dc" , tracing :: Level :: DEBUG , "s2n_quic_dc");
let client =
tracing :: span ! (parent : root . id () , tracing :: Level :: DEBUG , "client");
let server =
tracing :: span ! (parent : root . id () , tracing :: Level :: DEBUG , "server");
Self { client, server }
}
}
impl super::Subscriber for Subscriber {
type ConnectionContext = tracing::Span;
fn create_connection_context(
&self,
meta: &api::ConnectionMeta,
_info: &api::ConnectionInfo,
) -> Self::ConnectionContext {
let parent = match meta.endpoint_type {
api::EndpointType::Client {} => self.client.id(),
api::EndpointType::Server {} => self.server.id(),
};
tracing :: span ! (target : "s2n_quic_dc" , parent : parent , tracing :: Level :: DEBUG , "conn" , id = meta . id)
}
#[inline]
fn on_frame_sent(
&self,
context: &Self::ConnectionContext,
_meta: &api::ConnectionMeta,
event: &api::FrameSent,
) {
let id = context.id();
let api::FrameSent {
packet_header,
path_id,
frame,
} = event;
tracing :: event ! (target : "frame_sent" , parent : id , tracing :: Level :: DEBUG , packet_header = tracing :: field :: debug (packet_header) , path_id = tracing :: field :: debug (path_id) , frame = tracing :: field :: debug (frame));
}
}
}
pub mod builder {
use super::*;
#[derive(Clone, Debug)]
#[doc = " Frame was sent"]
pub struct FrameSent {
pub packet_header: PacketHeader,
pub path_id: u64,
pub frame: Frame,
}
impl IntoEvent<api::FrameSent> for FrameSent {
#[inline]
fn into_event(self) -> api::FrameSent {
let FrameSent {
packet_header,
path_id,
frame,
} = self;
api::FrameSent {
packet_header: packet_header.into_event(),
path_id: path_id.into_event(),
frame: frame.into_event(),
}
}
}
}
pub use traits::*;
mod traits {
use super::*;
use crate::query;
use api::*;
use core::fmt;
#[doc = r" Provides metadata related to an event"]
pub trait Meta: fmt::Debug {
#[doc = r" Returns whether the local endpoint is a Client or Server"]
fn endpoint_type(&self) -> &EndpointType;
#[doc = r" A context from which the event is being emitted"]
#[doc = r""]
#[doc = r" An event can occur in the context of an Endpoint or Connection"]
fn subject(&self) -> Subject;
#[doc = r" The time the event occurred"]
fn timestamp(&self) -> &crate::event::Timestamp;
}
impl Meta for ConnectionMeta {
fn endpoint_type(&self) -> &EndpointType {
&self.endpoint_type
}
fn subject(&self) -> Subject {
Subject::Connection { id: self.id }
}
fn timestamp(&self) -> &crate::event::Timestamp {
&self.timestamp
}
}
impl Meta for EndpointMeta {
fn endpoint_type(&self) -> &EndpointType {
&self.endpoint_type
}
fn subject(&self) -> Subject {
Subject::Endpoint {}
}
fn timestamp(&self) -> &crate::event::Timestamp {
&self.timestamp
}
}
#[doc = r" Allows for events to be subscribed to"]
pub trait Subscriber: 'static + Send {
#[doc = r" An application provided type associated with each connection."]
#[doc = r""]
#[doc = r" The context provides a mechanism for applications to provide a custom type"]
#[doc = r" and update it on each event, e.g. computing statistics. Each event"]
#[doc = r" invocation (e.g. [`Subscriber::on_packet_sent`]) also provides mutable"]
#[doc = r" access to the context `&mut ConnectionContext` and allows for updating the"]
#[doc = r" context."]
#[doc = r""]
#[doc = r" ```no_run"]
#[doc = r" # mod s2n_quic { pub mod provider { pub mod event {"]
#[doc = r" # pub use s2n_quic_core::event::{api as events, api::ConnectionInfo, api::ConnectionMeta, Subscriber};"]
#[doc = r" # }}}"]
#[doc = r" use s2n_quic::provider::event::{"]
#[doc = r" ConnectionInfo, ConnectionMeta, Subscriber, events::PacketSent"]
#[doc = r" };"]
#[doc = r""]
#[doc = r" pub struct MyEventSubscriber;"]
#[doc = r""]
#[doc = r" pub struct MyEventContext {"]
#[doc = r" packet_sent: u64,"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" impl Subscriber for MyEventSubscriber {"]
#[doc = r" type ConnectionContext = MyEventContext;"]
#[doc = r""]
#[doc = r" fn create_connection_context("]
#[doc = r" &mut self, _meta: &ConnectionMeta,"]
#[doc = r" _info: &ConnectionInfo,"]
#[doc = r" ) -> Self::ConnectionContext {"]
#[doc = r" MyEventContext { packet_sent: 0 }"]
#[doc = r" }"]
#[doc = r""]
#[doc = r" fn on_packet_sent("]
#[doc = r" &mut self,"]
#[doc = r" context: &mut Self::ConnectionContext,"]
#[doc = r" _meta: &ConnectionMeta,"]
#[doc = r" _event: &PacketSent,"]
#[doc = r" ) {"]
#[doc = r" context.packet_sent += 1;"]
#[doc = r" }"]
#[doc = r" }"]
#[doc = r" ```"]
type ConnectionContext: 'static + Send;
#[doc = r" Creates a context to be passed to each connection-related event"]
fn create_connection_context(
&self,
meta: &ConnectionMeta,
info: &ConnectionInfo,
) -> Self::ConnectionContext;
#[doc = "Called when the `FrameSent` event is triggered"]
#[inline]
fn on_frame_sent(
&self,
context: &Self::ConnectionContext,
meta: &ConnectionMeta,
event: &FrameSent,
) {
let _ = context;
let _ = meta;
let _ = event;
}
#[doc = r" Called for each event that relates to the endpoint and all connections"]
#[inline]
fn on_event<M: Meta, E: Event>(&self, meta: &M, event: &E) {
let _ = meta;
let _ = event;
}
#[doc = r" Called for each event that relates to a connection"]
#[inline]
fn on_connection_event<E: Event>(
&self,
context: &Self::ConnectionContext,
meta: &ConnectionMeta,
event: &E,
) {
let _ = context;
let _ = meta;
let _ = event;
}
#[doc = r" Used for querying the `Subscriber::ConnectionContext` on a Subscriber"]
#[inline]
fn query(
context: &Self::ConnectionContext,
query: &mut dyn query::Query,
) -> query::ControlFlow {
query.execute(context)
}
}
#[doc = r" Subscriber is implemented for a 2-element tuple to make it easy to compose multiple"]
#[doc = r" subscribers."]
impl<A, B> Subscriber for (A, B)
where
A: Subscriber,
B: Subscriber,
{
type ConnectionContext = (A::ConnectionContext, B::ConnectionContext);
#[inline]
fn create_connection_context(
&self,
meta: &ConnectionMeta,
info: &ConnectionInfo,
) -> Self::ConnectionContext {
(
self.0.create_connection_context(meta, info),
self.1.create_connection_context(meta, info),
)
}
#[inline]
fn on_frame_sent(
&self,
context: &Self::ConnectionContext,
meta: &ConnectionMeta,
event: &FrameSent,
) {
(self.0).on_frame_sent(&context.0, meta, event);
(self.1).on_frame_sent(&context.1, meta, event);
}
#[inline]
fn on_event<M: Meta, E: Event>(&self, meta: &M, event: &E) {
self.0.on_event(meta, event);
self.1.on_event(meta, event);
}
#[inline]
fn on_connection_event<E: Event>(
&self,
context: &Self::ConnectionContext,
meta: &ConnectionMeta,
event: &E,
) {
self.0.on_connection_event(&context.0, meta, event);
self.1.on_connection_event(&context.1, meta, event);
}
#[inline]
fn query(
context: &Self::ConnectionContext,
query: &mut dyn query::Query,
) -> query::ControlFlow {
query
.execute(context)
.and_then(|| A::query(&context.0, query))
.and_then(|| B::query(&context.1, query))
}
}
pub trait EndpointPublisher {
#[doc = r" Returns the QUIC version, if any"]
fn quic_version(&self) -> Option<u32>;
}
pub struct EndpointPublisherSubscriber<'a, Sub: Subscriber> {
meta: EndpointMeta,
quic_version: Option<u32>,
subscriber: &'a Sub,
}
impl<'a, Sub: Subscriber> fmt::Debug for EndpointPublisherSubscriber<'a, Sub> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ConnectionPublisherSubscriber")
.field("meta", &self.meta)
.field("quic_version", &self.quic_version)
.finish()
}
}
impl<'a, Sub: Subscriber> EndpointPublisherSubscriber<'a, Sub> {
#[inline]
pub fn new(
meta: builder::EndpointMeta,
quic_version: Option<u32>,
subscriber: &'a Sub,
) -> Self {
Self {
meta: meta.into_event(),
quic_version,
subscriber,
}
}
}
impl<'a, Sub: Subscriber> EndpointPublisher for EndpointPublisherSubscriber<'a, Sub> {
#[inline]
fn quic_version(&self) -> Option<u32> {
self.quic_version
}
}
pub trait ConnectionPublisher {
#[doc = "Publishes a `FrameSent` event to the publisher's subscriber"]
fn on_frame_sent(&self, event: builder::FrameSent);
#[doc = r" Returns the QUIC version negotiated for the current connection, if any"]
fn quic_version(&self) -> u32;
#[doc = r" Returns the [`Subject`] for the current publisher"]
fn subject(&self) -> Subject;
}
pub struct ConnectionPublisherSubscriber<'a, Sub: Subscriber> {
meta: ConnectionMeta,
quic_version: u32,
subscriber: &'a Sub,
context: &'a Sub::ConnectionContext,
}
impl<'a, Sub: Subscriber> fmt::Debug for ConnectionPublisherSubscriber<'a, Sub> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("ConnectionPublisherSubscriber")
.field("meta", &self.meta)
.field("quic_version", &self.quic_version)
.finish()
}
}
impl<'a, Sub: Subscriber> ConnectionPublisherSubscriber<'a, Sub> {
#[inline]
pub fn new(
meta: builder::ConnectionMeta,
quic_version: u32,
subscriber: &'a Sub,
context: &'a Sub::ConnectionContext,
) -> Self {
Self {
meta: meta.into_event(),
quic_version,
subscriber,
context,
}
}
}
impl<'a, Sub: Subscriber> ConnectionPublisher for ConnectionPublisherSubscriber<'a, Sub> {
#[inline]
fn on_frame_sent(&self, event: builder::FrameSent) {
let event = event.into_event();
self.subscriber
.on_frame_sent(self.context, &self.meta, &event);
self.subscriber
.on_connection_event(self.context, &self.meta, &event);
self.subscriber.on_event(&self.meta, &event);
}
#[inline]
fn quic_version(&self) -> u32 {
self.quic_version
}
#[inline]
fn subject(&self) -> api::Subject {
self.meta.subject()
}
}
}
pub mod metrics {
use super::*;
use core::sync::atomic::{AtomicU32, Ordering};
use s2n_quic_core::event::metrics::Recorder;
#[derive(Clone, Debug)]
pub struct Subscriber<S: super::Subscriber>
where
S::ConnectionContext: Recorder,
{
subscriber: S,
}
impl<S: super::Subscriber> Subscriber<S>
where
S::ConnectionContext: Recorder,
{
pub fn new(subscriber: S) -> Self {
Self { subscriber }
}
}
pub struct Context<R: Recorder> {
recorder: R,
frame_sent: AtomicU32,
}
impl<S: super::Subscriber> super::Subscriber for Subscriber<S>
where
S::ConnectionContext: Recorder,
{
type ConnectionContext = Context<S::ConnectionContext>;
fn create_connection_context(
&self,
meta: &api::ConnectionMeta,
info: &api::ConnectionInfo,
) -> Self::ConnectionContext {
Context {
recorder: self.subscriber.create_connection_context(meta, info),
frame_sent: AtomicU32::new(0),
}
}
#[inline]
fn on_frame_sent(
&self,
context: &Self::ConnectionContext,
meta: &api::ConnectionMeta,
event: &api::FrameSent,
) {
context.frame_sent.fetch_add(1, Ordering::Relaxed);
self.subscriber
.on_frame_sent(&mut context.recorder, meta, event);
}
}
impl<R: Recorder> Drop for Context<R> {
fn drop(&mut self) {
self.recorder
.increment_counter("frame_sent", self.frame_sent.load(Ordering::Relaxed) as _);
}
}
}
#[cfg(any(test, feature = "testing"))]
pub mod testing {
use super::*;
use crate::event::snapshot::Location;
use core::sync::atomic::{AtomicU32, Ordering};
use std::sync::Mutex;
#[derive(Clone, Debug)]
pub struct Subscriber {
location: Option<Location>,
output: Mutex<Vec<String>>,
pub frame_sent: AtomicU32,
}
impl Drop for Subscriber {
fn drop(&mut self) {
if std::thread::panicking() {
return;
}
if let Some(location) = self.location.as_ref() {
location.snapshot_log(&self.output.lock().unwrap());
}
}
}
impl Subscriber {
#[doc = r" Creates a subscriber with snapshot assertions enabled"]
#[track_caller]
pub fn snapshot() -> Self {
let mut sub = Self::no_snapshot();
sub.location = Location::from_thread_name();
sub
}
#[doc = r" Creates a subscriber with snapshot assertions enabled"]
#[track_caller]
pub fn named_snapshot<Name: core::fmt::Display>(name: Name) -> Self {
let mut sub = Self::no_snapshot();
sub.location = Some(Location::new(name));
sub
}
#[doc = r" Creates a subscriber with snapshot assertions disabled"]
pub fn no_snapshot() -> Self {
Self {
location: None,
output: Default::default(),
frame_sent: AtomicU32::new(0),
}
}
}
impl super::Subscriber for Subscriber {
type ConnectionContext = ();
fn create_connection_context(
&self,
_meta: &api::ConnectionMeta,
_info: &api::ConnectionInfo,
) -> Self::ConnectionContext {
}
fn on_frame_sent(
&self,
_context: &Self::ConnectionContext,
meta: &api::ConnectionMeta,
event: &api::FrameSent,
) {
self.frame_sent.fetch_add(1, Ordering::Relaxed);
if self.location.is_some() {
self.output
.lock()
.unwrap()
.push(format!("{meta:?} {event:?}"));
}
}
}
#[derive(Clone, Debug)]
pub struct Publisher {
location: Option<Location>,
output: Mutex<Vec<String>>,
pub frame_sent: AtomicU32,
}
impl Publisher {
#[doc = r" Creates a publisher with snapshot assertions enabled"]
#[track_caller]
pub fn snapshot() -> Self {
let mut sub = Self::no_snapshot();
sub.location = Location::from_thread_name();
sub
}
#[doc = r" Creates a subscriber with snapshot assertions enabled"]
#[track_caller]
pub fn named_snapshot<Name: core::fmt::Display>(name: Name) -> Self {
let mut sub = Self::no_snapshot();
sub.location = Some(Location::new(name));
sub
}
#[doc = r" Creates a publisher with snapshot assertions disabled"]
pub fn no_snapshot() -> Self {
Self {
location: None,
output: Default::default(),
frame_sent: AtomicU32::new(0),
}
}
}
impl super::EndpointPublisher for Publisher {
fn quic_version(&self) -> Option<u32> {
Some(1)
}
}
impl super::ConnectionPublisher for Publisher {
fn on_frame_sent(&self, event: builder::FrameSent) {
self.frame_sent.fetch_add(1, Ordering::Relaxed);
let event = event.into_event();
if self.location.is_some() {
self.output.lock().unwrap().push(format!("{event:?}"));
}
}
fn quic_version(&self) -> u32 {
1
}
fn subject(&self) -> api::Subject {
api::Subject::Connection { id: 0 }
}
}
impl Drop for Publisher {
fn drop(&mut self) {
if std::thread::panicking() {
return;
}
if let Some(location) = self.location.as_ref() {
location.snapshot_log(&self.output.lock().unwrap());
}
}
}
}