Skip to content

Commit

Permalink
feat(s2n-quic-dc): Add subscriber event for dc::Path creation (#2510)
Browse files Browse the repository at this point in the history
* Add event for dc::Path creation

This allows a subscriber with knowledge of the concrete path type to
downcast it and register interest for events (e.g., to pull the path
secret ID or other relevant metadata as it gets produced).

* Bless snaphosts

* Fix Rust target detection
  • Loading branch information
Mark-Simulacrum authored Mar 5, 2025
1 parent 1605dc7 commit 1a1dfa8
Show file tree
Hide file tree
Showing 13 changed files with 399 additions and 220 deletions.
2 changes: 1 addition & 1 deletion dc/wireshark/generate-bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ OPTIONS=(

mkdir -p src/wireshark_sys/

RUST_TARGET=$(rustup show | awk 'NF' | awk 'END{print $2}')
RUST_TARGET=$(rustc -vV | grep release: | awk '{ print $2 }')

# This list is filtered to roughly what our current usage requires.
# It's possible there's a better way to do this -- some of the Wireshark
Expand Down
8 changes: 8 additions & 0 deletions quic/s2n-quic-core/events/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,14 @@ struct DcStateChanged {
state: DcState,
}

#[event("transport:dc_path_created")]
/// The DC path has been created
struct DcPathCreated<'a> {
/// This is the dc::Path struct, it's just type-erased. But if an event subscriber knows the
/// type they can downcast.
path: &'a (dyn core::any::Any + Send + 'static),
}

// NOTE - This event MUST come last, since connection-level aggregation depends on it
#[event("connectivity:connection_closed")]
//= https://tools.ietf.org/id/draft-marx-qlog-event-definitions-quic-h3-02#5.1.3
Expand Down
9 changes: 9 additions & 0 deletions quic/s2n-quic-core/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ impl<'a> IntoEvent<&'a str> for &'a str {
}
}

impl<'a> IntoEvent<&'a (dyn core::any::Any + Send + 'static)>
for &'a (dyn core::any::Any + Send + 'static)
{
#[inline]
fn into_event(self) -> Self {
self
}
}

impl<T> IntoEvent<RangeInclusive<T>> for RangeInclusive<T> {
#[inline]
fn into_event(self) -> RangeInclusive<T> {
Expand Down
106 changes: 106 additions & 0 deletions quic/s2n-quic-core/src/event/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2655,6 +2655,25 @@ pub mod api {
}
#[derive(Clone, Debug)]
#[non_exhaustive]
#[doc = " The DC path has been created"]
pub struct DcPathCreated<'a> {
#[doc = " This is the dc::Path struct, it's just type-erased. But if an event subscriber knows the"]
#[doc = " type they can downcast."]
pub path: &'a (dyn core::any::Any + Send + 'static),
}
#[cfg(any(test, feature = "testing"))]
impl<'a> crate::event::snapshot::Fmt for DcPathCreated<'a> {
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
let mut fmt = fmt.debug_struct("DcPathCreated");
fmt.field("path", &self.path);
fmt.finish()
}
}
impl<'a> Event for DcPathCreated<'a> {
const NAME: &'static str = "transport:dc_path_created";
}
#[derive(Clone, Debug)]
#[non_exhaustive]
#[doc = " Connection closed"]
pub struct ConnectionClosed {
pub error: crate::connection::Error,
Expand Down Expand Up @@ -4172,6 +4191,17 @@ pub mod tracing {
tracing :: event ! (target : "dc_state_changed" , parent : id , tracing :: Level :: DEBUG , { state = tracing :: field :: debug (state) });
}
#[inline]
fn on_dc_path_created(
&mut self,
context: &mut Self::ConnectionContext,
_meta: &api::ConnectionMeta,
event: &api::DcPathCreated,
) {
let id = context.id();
let api::DcPathCreated { path } = event;
tracing :: event ! (target : "dc_path_created" , parent : id , tracing :: Level :: DEBUG , { path = tracing :: field :: debug (path) });
}
#[inline]
fn on_connection_closed(
&mut self,
context: &mut Self::ConnectionContext,
Expand Down Expand Up @@ -6334,6 +6364,22 @@ pub mod builder {
}
}
#[derive(Clone, Debug)]
#[doc = " The DC path has been created"]
pub struct DcPathCreated<'a> {
#[doc = " This is the dc::Path struct, it's just type-erased. But if an event subscriber knows the"]
#[doc = " type they can downcast."]
pub path: &'a (dyn core::any::Any + Send + 'static),
}
impl<'a> IntoEvent<api::DcPathCreated<'a>> for DcPathCreated<'a> {
#[inline]
fn into_event(self) -> api::DcPathCreated<'a> {
let DcPathCreated { path } = self;
api::DcPathCreated {
path: path.into_event(),
}
}
}
#[derive(Clone, Debug)]
#[doc = " Connection closed"]
pub struct ConnectionClosed {
pub error: crate::connection::Error,
Expand Down Expand Up @@ -7353,6 +7399,18 @@ mod traits {
let _ = meta;
let _ = event;
}
#[doc = "Called when the `DcPathCreated` event is triggered"]
#[inline]
fn on_dc_path_created(
&mut self,
context: &mut Self::ConnectionContext,
meta: &api::ConnectionMeta,
event: &api::DcPathCreated,
) {
let _ = context;
let _ = meta;
let _ = event;
}
#[doc = "Called when the `ConnectionClosed` event is triggered"]
#[inline]
fn on_connection_closed(
Expand Down Expand Up @@ -8039,6 +8097,16 @@ mod traits {
(self.1).on_dc_state_changed(&mut context.1, meta, event);
}
#[inline]
fn on_dc_path_created(
&mut self,
context: &mut Self::ConnectionContext,
meta: &api::ConnectionMeta,
event: &api::DcPathCreated,
) {
(self.0).on_dc_path_created(&mut context.0, meta, event);
(self.1).on_dc_path_created(&mut context.1, meta, event);
}
#[inline]
fn on_connection_closed(
&mut self,
context: &mut Self::ConnectionContext,
Expand Down Expand Up @@ -8473,6 +8541,8 @@ mod traits {
fn on_bbr_state_changed(&mut self, event: builder::BbrStateChanged);
#[doc = "Publishes a `DcStateChanged` event to the publisher's subscriber"]
fn on_dc_state_changed(&mut self, event: builder::DcStateChanged);
#[doc = "Publishes a `DcPathCreated` event to the publisher's subscriber"]
fn on_dc_path_created(&mut self, event: builder::DcPathCreated);
#[doc = "Publishes a `ConnectionClosed` event to the publisher's subscriber"]
fn on_connection_closed(&mut self, event: builder::ConnectionClosed);
#[doc = r" Returns the QUIC version negotiated for the current connection, if any"]
Expand Down Expand Up @@ -8924,6 +8994,15 @@ mod traits {
self.subscriber.on_event(&self.meta, &event);
}
#[inline]
fn on_dc_path_created(&mut self, event: builder::DcPathCreated) {
let event = event.into_event();
self.subscriber
.on_dc_path_created(self.context, &self.meta, &event);
self.subscriber
.on_connection_event(self.context, &self.meta, &event);
self.subscriber.on_event(&self.meta, &event);
}
#[inline]
fn on_connection_closed(&mut self, event: builder::ConnectionClosed) {
let event = event.into_event();
self.subscriber
Expand Down Expand Up @@ -9230,6 +9309,7 @@ pub mod testing {
pub pacing_rate_updated: u64,
pub bbr_state_changed: u64,
pub dc_state_changed: u64,
pub dc_path_created: u64,
pub connection_closed: u64,
pub version_information: u64,
pub endpoint_packet_sent: u64,
Expand Down Expand Up @@ -9321,6 +9401,7 @@ pub mod testing {
pacing_rate_updated: 0,
bbr_state_changed: 0,
dc_state_changed: 0,
dc_path_created: 0,
connection_closed: 0,
version_information: 0,
endpoint_packet_sent: 0,
Expand Down Expand Up @@ -9965,6 +10046,20 @@ pub mod testing {
self.output.push(out);
}
}
fn on_dc_path_created(
&mut self,
_context: &mut Self::ConnectionContext,
meta: &api::ConnectionMeta,
event: &api::DcPathCreated,
) {
self.dc_path_created += 1;
if self.location.is_some() {
let meta = crate::event::snapshot::Fmt::to_snapshot(meta);
let event = crate::event::snapshot::Fmt::to_snapshot(event);
let out = format!("{meta:?} {event:?}");
self.output.push(out);
}
}
fn on_connection_closed(
&mut self,
_context: &mut Self::ConnectionContext,
Expand Down Expand Up @@ -10177,6 +10272,7 @@ pub mod testing {
pub pacing_rate_updated: u64,
pub bbr_state_changed: u64,
pub dc_state_changed: u64,
pub dc_path_created: u64,
pub connection_closed: u64,
pub version_information: u64,
pub endpoint_packet_sent: u64,
Expand Down Expand Up @@ -10258,6 +10354,7 @@ pub mod testing {
pacing_rate_updated: 0,
bbr_state_changed: 0,
dc_state_changed: 0,
dc_path_created: 0,
connection_closed: 0,
version_information: 0,
endpoint_packet_sent: 0,
Expand Down Expand Up @@ -10800,6 +10897,15 @@ pub mod testing {
self.output.push(out);
}
}
fn on_dc_path_created(&mut self, event: builder::DcPathCreated) {
self.dc_path_created += 1;
let event = event.into_event();
if self.location.is_some() {
let event = crate::event::snapshot::Fmt::to_snapshot(&event);
let out = format!("{event:?}");
self.output.push(out);
}
}
fn on_connection_closed(&mut self, event: builder::ConnectionClosed) {
self.connection_closed += 1;
let event = event.into_event();
Expand Down
15 changes: 15 additions & 0 deletions quic/s2n-quic-core/src/event/generated/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub struct Context<R: Recorder> {
pacing_rate_updated: u64,
bbr_state_changed: u64,
dc_state_changed: u64,
dc_path_created: u64,
connection_closed: u64,
}
impl<S: event::Subscriber> event::Subscriber for Subscriber<S>
Expand Down Expand Up @@ -128,6 +129,7 @@ where
pacing_rate_updated: 0,
bbr_state_changed: 0,
dc_state_changed: 0,
dc_path_created: 0,
connection_closed: 0,
}
}
Expand Down Expand Up @@ -620,6 +622,17 @@ where
.on_dc_state_changed(&mut context.recorder, meta, event);
}
#[inline]
fn on_dc_path_created(
&mut self,
context: &mut Self::ConnectionContext,
meta: &api::ConnectionMeta,
event: &api::DcPathCreated,
) {
context.dc_path_created += 1;
self.subscriber
.on_dc_path_created(&mut context.recorder, meta, event);
}
#[inline]
fn on_connection_closed(
&mut self,
context: &mut Self::ConnectionContext,
Expand Down Expand Up @@ -735,6 +748,8 @@ impl<R: Recorder> Drop for Context<R> {
.increment_counter("bbr_state_changed", self.bbr_state_changed as _);
self.recorder
.increment_counter("dc_state_changed", self.dc_state_changed as _);
self.recorder
.increment_counter("dc_path_created", self.dc_path_created as _);
self.recorder
.increment_counter("connection_closed", self.connection_closed as _);
}
Expand Down
Loading

0 comments on commit 1a1dfa8

Please sign in to comment.