@@ -52,7 +52,9 @@ use crate::multipath_scheduler::*;
52
52
use crate :: packet;
53
53
use crate :: packet:: PacketHeader ;
54
54
use crate :: packet:: PacketType ;
55
+ #[ cfg( feature = "qlog" ) ]
55
56
use crate :: qlog;
57
+ #[ cfg( feature = "qlog" ) ]
56
58
use crate :: qlog:: events;
57
59
use crate :: tls;
58
60
use crate :: tls:: Keys ;
@@ -160,6 +162,7 @@ pub struct Connection {
160
162
context : Option < Box < dyn Any + Send + Sync > > ,
161
163
162
164
/// Qlog writer
165
+ #[ cfg( feature = "qlog" ) ]
163
166
qlog : Option < qlog:: QlogWriter > ,
164
167
165
168
/// Unique trace id for deubg logging
@@ -272,6 +275,7 @@ impl Connection {
272
275
events : EventQueue :: default ( ) ,
273
276
queues : None ,
274
277
context : None ,
278
+ #[ cfg( feature = "qlog" ) ]
275
279
qlog : None ,
276
280
trace_id,
277
281
} ;
@@ -357,6 +361,7 @@ impl Connection {
357
361
/// Set qlog output to the given [`writer`]
358
362
///
359
363
/// [`Writer`]: https://doc.rust-lang.org/std/io/trait.Write.html
364
+ #[ cfg( feature = "qlog" ) ]
360
365
pub fn set_qlog (
361
366
& mut self ,
362
367
writer : Box < dyn std:: io:: Write + Send + Sync > ,
@@ -603,6 +608,7 @@ impl Connection {
603
608
// Process each QUIC frame in the QUIC packet
604
609
let mut ack_eliciting_pkt = false ;
605
610
let mut probing_pkt = true ;
611
+ #[ cfg( feature = "qlog" ) ]
606
612
let mut qframes = vec ! [ ] ;
607
613
608
614
while !payload. is_empty ( ) {
@@ -613,6 +619,7 @@ impl Connection {
613
619
if !frame. probing ( ) {
614
620
probing_pkt = false ;
615
621
}
622
+ #[ cfg( feature = "qlog" ) ]
616
623
if self . qlog . is_some ( ) {
617
624
qframes. push ( frame. to_qlog ( ) ) ;
618
625
}
@@ -622,6 +629,7 @@ impl Connection {
622
629
}
623
630
624
631
// Write events to qlog.
632
+ #[ cfg( feature = "qlog" ) ]
625
633
if let Some ( qlog) = & mut self . qlog {
626
634
// Write TransportPacketReceived event to qlog.
627
635
Self :: qlog_quic_packet_received ( qlog, & hdr, pkt_num, read, payload_len, qframes) ;
@@ -750,6 +758,7 @@ impl Connection {
750
758
space_id,
751
759
& mut self . spaces ,
752
760
handshake_status,
761
+ #[ cfg( feature = "qlog" ) ]
753
762
self . qlog . as_mut ( ) ,
754
763
now,
755
764
) ?;
@@ -1205,6 +1214,7 @@ impl Connection {
1205
1214
self . flags . insert ( AppliedPeerTransportParams ) ;
1206
1215
1207
1216
// Write TransportParametersSet event to qlog.
1217
+ #[ cfg( feature = "qlog" ) ]
1208
1218
if let Some ( qlog) = & mut self . qlog {
1209
1219
Self :: qlog_quic_params_set (
1210
1220
qlog,
@@ -1427,6 +1437,7 @@ impl Connection {
1427
1437
. on_stream_frame_acked ( stream_id, offset, length) ;
1428
1438
1429
1439
// Write QuicStreamDataMoved event to qlog
1440
+ #[ cfg( feature = "qlog" ) ]
1430
1441
if let Some ( qlog) = & mut self . qlog {
1431
1442
Self :: qlog_quic_data_acked ( qlog, stream_id, offset, length) ;
1432
1443
}
@@ -1680,7 +1691,11 @@ impl Connection {
1680
1691
. tls_session
1681
1692
. get_overhead ( level)
1682
1693
. ok_or ( Error :: InternalError ) ?;
1683
- let total_overhead = pkt_num_offset + pkt_num_len + crypto_overhead;
1694
+ let total_overhead = if !self . is_encryption_disabled ( hdr. pkt_type ) {
1695
+ pkt_num_offset + pkt_num_len + crypto_overhead
1696
+ } else {
1697
+ pkt_num_offset + pkt_num_len
1698
+ } ;
1684
1699
1685
1700
match left. checked_sub ( total_overhead) {
1686
1701
Some ( val) => left = val,
@@ -1727,6 +1742,8 @@ impl Connection {
1727
1742
// fields) in bytes
1728
1743
let payload_len = write_status. written ;
1729
1744
if pkt_type != PacketType :: OneRTT {
1745
+ // Note: This type of packet is always encrypted, even if the disable_1rtt_encryption
1746
+ // transport parameter is successfully negotiated.
1730
1747
let len = pkt_num_len + payload_len + crypto_overhead;
1731
1748
let mut out = & mut out[ hdr_offset..] ;
1732
1749
out. write_varint_with_len ( len as u64 , crate :: LENGTH_FIELD_LEN ) ?;
@@ -1769,6 +1786,7 @@ impl Connection {
1769
1786
in_flight : write_status. in_flight ,
1770
1787
has_data : write_status. has_data ,
1771
1788
pmtu_probe : write_status. is_pmtu_probe ,
1789
+ pacing : write_status. pacing ,
1772
1790
frames : write_status. frames ,
1773
1791
rate_sample_state : Default :: default ( ) ,
1774
1792
buffer_flags : write_status. buffer_flags ,
@@ -1782,6 +1800,7 @@ impl Connection {
1782
1800
) ;
1783
1801
1784
1802
// Write events to qlog.
1803
+ #[ cfg( feature = "qlog" ) ]
1785
1804
if let Some ( qlog) = & mut self . qlog {
1786
1805
// Write TransportPacketSent event to qlog.
1787
1806
let mut qframes = Vec :: with_capacity ( sent_pkt. frames . len ( ) ) ;
@@ -1912,6 +1931,7 @@ impl Connection {
1912
1931
if !st. is_probe && !r. can_send ( ) {
1913
1932
return Err ( Error :: Done ) ;
1914
1933
}
1934
+ st. pacing = true ;
1915
1935
1916
1936
// Write PMTU probe frames
1917
1937
// Note: To probe the path MTU, the write size will exceed `left` but
@@ -3225,13 +3245,15 @@ impl Connection {
3225
3245
path. space_id ,
3226
3246
& mut self . spaces ,
3227
3247
handshake_status,
3248
+ #[ cfg( feature = "qlog" ) ]
3228
3249
self . qlog . as_mut ( ) ,
3229
3250
now,
3230
3251
) ;
3231
3252
self . stats . lost_count += lost_pkts;
3232
3253
self . stats . lost_bytes += lost_bytes;
3233
3254
3234
3255
// Write RecoveryMetricsUpdate event to qlog.
3256
+ #[ cfg( feature = "qlog" ) ]
3235
3257
if let Some ( qlog) = & mut self . qlog {
3236
3258
path. recovery . qlog_recovery_metrics_updated ( qlog) ;
3237
3259
}
@@ -3826,6 +3848,7 @@ impl Connection {
3826
3848
match self . streams . stream_read ( stream_id, out) {
3827
3849
Ok ( ( read, fin) ) => {
3828
3850
// Write QuicStreamDataMoved event to qlog
3851
+ #[ cfg( feature = "qlog" ) ]
3829
3852
if let Some ( qlog) = & mut self . qlog {
3830
3853
Self :: qlog_transport_data_read ( qlog, stream_id, read_off. unwrap_or ( 0 ) , read) ;
3831
3854
}
@@ -3844,6 +3867,7 @@ impl Connection {
3844
3867
match self . streams . stream_write ( stream_id, buf, fin) {
3845
3868
Ok ( written) => {
3846
3869
// Write QuicStreamDataMoved event to qlog
3870
+ #[ cfg( feature = "qlog" ) ]
3847
3871
if let Some ( qlog) = & mut self . qlog {
3848
3872
Self :: qlog_transport_data_write (
3849
3873
qlog,
@@ -4066,6 +4090,7 @@ impl Connection {
4066
4090
}
4067
4091
4068
4092
/// Write a QuicParametersSet event to the qlog.
4093
+ #[ cfg( feature = "qlog" ) ]
4069
4094
fn qlog_quic_params_set (
4070
4095
qlog : & mut qlog:: QlogWriter ,
4071
4096
params : & TransportParams ,
@@ -4077,6 +4102,7 @@ impl Connection {
4077
4102
}
4078
4103
4079
4104
/// Write a QuicPacketReceived event to the qlog.
4105
+ #[ cfg( feature = "qlog" ) ]
4080
4106
fn qlog_quic_packet_received (
4081
4107
qlog : & mut qlog:: QlogWriter ,
4082
4108
hdr : & PacketHeader ,
@@ -4112,6 +4138,7 @@ impl Connection {
4112
4138
}
4113
4139
4114
4140
/// Write a QuicPacketSent event to the qlog.
4141
+ #[ cfg( feature = "qlog" ) ]
4115
4142
fn qlog_quic_packet_sent (
4116
4143
qlog : & mut qlog:: QlogWriter ,
4117
4144
hdr : & PacketHeader ,
@@ -4150,6 +4177,7 @@ impl Connection {
4150
4177
}
4151
4178
4152
4179
/// Write a QuicStreamDataMoved event to the qlog.
4180
+ #[ cfg( feature = "qlog" ) ]
4153
4181
fn qlog_quic_data_acked (
4154
4182
qlog : & mut qlog:: QlogWriter ,
4155
4183
stream_id : u64 ,
@@ -4168,6 +4196,7 @@ impl Connection {
4168
4196
}
4169
4197
4170
4198
/// Write a QuicStreamDataMoved event to the qlog.
4199
+ #[ cfg( feature = "qlog" ) ]
4171
4200
fn qlog_transport_data_read (
4172
4201
qlog : & mut qlog:: QlogWriter ,
4173
4202
stream_id : u64 ,
@@ -4186,6 +4215,7 @@ impl Connection {
4186
4215
}
4187
4216
4188
4217
/// Write a QuicStreamDataMoved event to the qlog.
4218
+ #[ cfg( feature = "qlog" ) ]
4189
4219
fn qlog_transport_data_write (
4190
4220
qlog : & mut qlog:: QlogWriter ,
4191
4221
stream_id : u64 ,
@@ -4455,6 +4485,9 @@ struct FrameWriteStatus {
4455
4485
/// Whether it is a PMTU probe packet
4456
4486
is_pmtu_probe : bool ,
4457
4487
4488
+ /// Whether it consumes the pacer's tokens
4489
+ pacing : bool ,
4490
+
4458
4491
/// Packet overhead (i.e. packet header and crypto overhead) in bytes
4459
4492
overhead : usize ,
4460
4493
@@ -6271,6 +6304,7 @@ pub(crate) mod tests {
6271
6304
}
6272
6305
6273
6306
#[ test]
6307
+ #[ cfg( feature = "qlog" ) ]
6274
6308
fn ping ( ) -> Result < ( ) > {
6275
6309
let mut client_config = TestPair :: new_test_config ( false ) ?;
6276
6310
client_config. enable_dplpmtud ( false ) ;
@@ -7632,6 +7666,7 @@ pub(crate) mod tests {
7632
7666
}
7633
7667
7634
7668
#[ test]
7669
+ #[ cfg( feature = "qlog" ) ]
7635
7670
fn conn_write_qlog ( ) -> Result < ( ) > {
7636
7671
let clog = NamedTempFile :: new ( ) . unwrap ( ) ;
7637
7672
let mut cfile = clog. reopen ( ) . unwrap ( ) ;
0 commit comments