Skip to content

Commit

Permalink
Add qlog feature flag to reduce the size of complied library
Browse files Browse the repository at this point in the history
  • Loading branch information
iyangsj committed Oct 19, 2024
1 parent 9cc6a62 commit d606630
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 15 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/tquic-features.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Features

on:
push:
branches: [ "develop" ]
pull_request:
branches: [ "develop" ]

env:
CARGO_TERM_COLOR: always

jobs:
features:
name: Build and test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'recursive'
- name: Update rust
run: rustup update
- name: Build without default features
run: cargo build --all --no-default-features && cargo test --no-default-features
- name: Build with feature(s) ffi
run: cargo build --all --no-default-features -F ffi && cargo test --no-default-features -F ffi
- name: Build with feature(s) qlog
run: cargo build --all --no-default-features -F qlog && cargo test --no-default-features -F qlog
- name: Build with feature(s) ffi,qlog
run: cargo build --all --no-default-features -F ffi,qlog && cargo test --no-default-features -F ffi,qlog

17 changes: 13 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,19 @@ include = [
"/deps/boringssl/LICENSE",
]

[package.metadata.docs.rs]
no-default-features = true
features = ["qlog"]

[features]
default = ["qlog"]

# build the FFI API
ffi = []

# enable support for the qlog
qlog = ["dep:serde", "dep:serde_json", "dep:serde_derive", "dep:serde_with"]

[dependencies]
bytes = "1"
rustc-hash = "1.1"
Expand All @@ -43,10 +52,10 @@ strum_macros = "0.24"
rand = "0.8.5"
smallvec = { version = "1.10", features = ["serde", "union"] }
lru = "0.12"
serde = { version = "1.0.139", features = ["derive"] }
serde_json = { version = "1.0", features = ["preserve_order"] }
serde_derive = "1.0"
serde_with = "3.0.0"
serde = { version = "1.0.139", features = ["derive"], optional=true }
serde_json = { version = "1.0", features = ["preserve_order"], optional=true }
serde_derive = { version = "1.0", optional=true }
serde_with = { version="3.0.0", optional=true }
hex = "0.4"
priority-queue = "1.3.2"
sfv = { version = "0.9" }
Expand Down
24 changes: 24 additions & 0 deletions src/connection/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ use crate::multipath_scheduler::*;
use crate::packet;
use crate::packet::PacketHeader;
use crate::packet::PacketType;
#[cfg(feature = "qlog")]
use crate::qlog;
#[cfg(feature = "qlog")]
use crate::qlog::events;
use crate::tls;
use crate::tls::Keys;
Expand Down Expand Up @@ -160,6 +162,7 @@ pub struct Connection {
context: Option<Box<dyn Any + Send + Sync>>,

/// Qlog writer
#[cfg(feature = "qlog")]
qlog: Option<qlog::QlogWriter>,

/// Unique trace id for deubg logging
Expand Down Expand Up @@ -272,6 +275,7 @@ impl Connection {
events: EventQueue::default(),
queues: None,
context: None,
#[cfg(feature = "qlog")]
qlog: None,
trace_id,
};
Expand Down Expand Up @@ -357,6 +361,7 @@ impl Connection {
/// Set qlog output to the given [`writer`]
///
/// [`Writer`]: https://doc.rust-lang.org/std/io/trait.Write.html
#[cfg(feature = "qlog")]
pub fn set_qlog(
&mut self,
writer: Box<dyn std::io::Write + Send + Sync>,
Expand Down Expand Up @@ -603,6 +608,7 @@ impl Connection {
// Process each QUIC frame in the QUIC packet
let mut ack_eliciting_pkt = false;
let mut probing_pkt = true;
#[cfg(feature = "qlog")]
let mut qframes = vec![];

while !payload.is_empty() {
Expand All @@ -613,6 +619,7 @@ impl Connection {
if !frame.probing() {
probing_pkt = false;
}
#[cfg(feature = "qlog")]
if self.qlog.is_some() {
qframes.push(frame.to_qlog());
}
Expand All @@ -622,6 +629,7 @@ impl Connection {
}

// Write events to qlog.
#[cfg(feature = "qlog")]
if let Some(qlog) = &mut self.qlog {
// Write TransportPacketReceived event to qlog.
Self::qlog_quic_packet_received(qlog, &hdr, pkt_num, read, payload_len, qframes);
Expand Down Expand Up @@ -750,6 +758,7 @@ impl Connection {
space_id,
&mut self.spaces,
handshake_status,
#[cfg(feature = "qlog")]
self.qlog.as_mut(),
now,
)?;
Expand Down Expand Up @@ -1205,6 +1214,7 @@ impl Connection {
self.flags.insert(AppliedPeerTransportParams);

// Write TransportParametersSet event to qlog.
#[cfg(feature = "qlog")]
if let Some(qlog) = &mut self.qlog {
Self::qlog_quic_params_set(
qlog,
Expand Down Expand Up @@ -1427,6 +1437,7 @@ impl Connection {
.on_stream_frame_acked(stream_id, offset, length);

// Write QuicStreamDataMoved event to qlog
#[cfg(feature = "qlog")]
if let Some(qlog) = &mut self.qlog {
Self::qlog_quic_data_acked(qlog, stream_id, offset, length);
}
Expand Down Expand Up @@ -1788,6 +1799,7 @@ impl Connection {
);

// Write events to qlog.
#[cfg(feature = "qlog")]
if let Some(qlog) = &mut self.qlog {
// Write TransportPacketSent event to qlog.
let mut qframes = Vec::with_capacity(sent_pkt.frames.len());
Expand Down Expand Up @@ -3231,13 +3243,15 @@ impl Connection {
path.space_id,
&mut self.spaces,
handshake_status,
#[cfg(feature = "qlog")]
self.qlog.as_mut(),
now,
);
self.stats.lost_count += lost_pkts;
self.stats.lost_bytes += lost_bytes;

// Write RecoveryMetricsUpdate event to qlog.
#[cfg(feature = "qlog")]
if let Some(qlog) = &mut self.qlog {
path.recovery.qlog_recovery_metrics_updated(qlog);
}
Expand Down Expand Up @@ -3832,6 +3846,7 @@ impl Connection {
match self.streams.stream_read(stream_id, out) {
Ok((read, fin)) => {
// Write QuicStreamDataMoved event to qlog
#[cfg(feature = "qlog")]
if let Some(qlog) = &mut self.qlog {
Self::qlog_transport_data_read(qlog, stream_id, read_off.unwrap_or(0), read);
}
Expand All @@ -3850,6 +3865,7 @@ impl Connection {
match self.streams.stream_write(stream_id, buf, fin) {
Ok(written) => {
// Write QuicStreamDataMoved event to qlog
#[cfg(feature = "qlog")]
if let Some(qlog) = &mut self.qlog {
Self::qlog_transport_data_write(
qlog,
Expand Down Expand Up @@ -4072,6 +4088,7 @@ impl Connection {
}

/// Write a QuicParametersSet event to the qlog.
#[cfg(feature = "qlog")]
fn qlog_quic_params_set(
qlog: &mut qlog::QlogWriter,
params: &TransportParams,
Expand All @@ -4083,6 +4100,7 @@ impl Connection {
}

/// Write a QuicPacketReceived event to the qlog.
#[cfg(feature = "qlog")]
fn qlog_quic_packet_received(
qlog: &mut qlog::QlogWriter,
hdr: &PacketHeader,
Expand Down Expand Up @@ -4118,6 +4136,7 @@ impl Connection {
}

/// Write a QuicPacketSent event to the qlog.
#[cfg(feature = "qlog")]
fn qlog_quic_packet_sent(
qlog: &mut qlog::QlogWriter,
hdr: &PacketHeader,
Expand Down Expand Up @@ -4156,6 +4175,7 @@ impl Connection {
}

/// Write a QuicStreamDataMoved event to the qlog.
#[cfg(feature = "qlog")]
fn qlog_quic_data_acked(
qlog: &mut qlog::QlogWriter,
stream_id: u64,
Expand All @@ -4174,6 +4194,7 @@ impl Connection {
}

/// Write a QuicStreamDataMoved event to the qlog.
#[cfg(feature = "qlog")]
fn qlog_transport_data_read(
qlog: &mut qlog::QlogWriter,
stream_id: u64,
Expand All @@ -4192,6 +4213,7 @@ impl Connection {
}

/// Write a QuicStreamDataMoved event to the qlog.
#[cfg(feature = "qlog")]
fn qlog_transport_data_write(
qlog: &mut qlog::QlogWriter,
stream_id: u64,
Expand Down Expand Up @@ -6277,6 +6299,7 @@ pub(crate) mod tests {
}

#[test]
#[cfg(feature = "qlog")]
fn ping() -> Result<()> {
let mut client_config = TestPair::new_test_config(false)?;
client_config.enable_dplpmtud(false);
Expand Down Expand Up @@ -7638,6 +7661,7 @@ pub(crate) mod tests {
}

#[test]
#[cfg(feature = "qlog")]
fn conn_write_qlog() -> Result<()> {
let clog = NamedTempFile::new().unwrap();
let mut cfile = clog.reopen().unwrap();
Expand Down
Loading

0 comments on commit d606630

Please sign in to comment.