7
7
package quic
8
8
9
9
import (
10
+ "context"
11
+ "log/slog"
10
12
"math"
11
13
"time"
12
14
)
@@ -179,21 +181,24 @@ func (c *lossState) nextNumber(space numberSpace) packetNumber {
179
181
}
180
182
181
183
// packetSent records a sent packet.
182
- func (c * lossState ) packetSent (now time.Time , space numberSpace , sent * sentPacket ) {
184
+ func (c * lossState ) packetSent (now time.Time , log * slog. Logger , space numberSpace , sent * sentPacket ) {
183
185
sent .time = now
184
186
c .spaces [space ].add (sent )
185
187
size := sent .size
186
188
if c .antiAmplificationLimit != antiAmplificationUnlimited {
187
189
c .antiAmplificationLimit = max (0 , c .antiAmplificationLimit - size )
188
190
}
189
191
if sent .inFlight {
190
- c .cc .packetSent (now , space , sent )
192
+ c .cc .packetSent (now , log , space , sent )
191
193
c .pacer .packetSent (now , size , c .cc .congestionWindow , c .rtt .smoothedRTT )
192
194
if sent .ackEliciting {
193
195
c .spaces [space ].lastAckEliciting = sent .num
194
196
c .ptoExpired = false // reset expired PTO timer after sending probe
195
197
}
196
198
c .scheduleTimer (now )
199
+ if logEnabled (log , QLogLevelPacket ) {
200
+ logBytesInFlight (log , c .cc .bytesInFlight )
201
+ }
197
202
}
198
203
if sent .ackEliciting {
199
204
c .consecutiveNonAckElicitingPackets = 0
@@ -267,7 +272,7 @@ func (c *lossState) receiveAckRange(now time.Time, space numberSpace, rangeIndex
267
272
268
273
// receiveAckEnd finishes processing an ack frame.
269
274
// The lossf function is called for each packet newly detected as lost.
270
- func (c * lossState ) receiveAckEnd (now time.Time , space numberSpace , ackDelay time.Duration , lossf func (numberSpace , * sentPacket , packetFate )) {
275
+ func (c * lossState ) receiveAckEnd (now time.Time , log * slog. Logger , space numberSpace , ackDelay time.Duration , lossf func (numberSpace , * sentPacket , packetFate )) {
271
276
c .spaces [space ].sentPacketList .clean ()
272
277
// Update the RTT sample when the largest acknowledged packet in the ACK frame
273
278
// is newly acknowledged, and at least one newly acknowledged packet is ack-eliciting.
@@ -286,24 +291,44 @@ func (c *lossState) receiveAckEnd(now time.Time, space numberSpace, ackDelay tim
286
291
// https://www.rfc-editor.org/rfc/rfc9002.html#section-6.2.2.1-3
287
292
c .timer = time.Time {}
288
293
c .detectLoss (now , lossf )
289
- c .cc .packetBatchEnd (now , space , & c .rtt , c .maxAckDelay )
294
+ c .cc .packetBatchEnd (now , log , space , & c .rtt , c .maxAckDelay )
295
+
296
+ if logEnabled (log , QLogLevelPacket ) {
297
+ var ssthresh slog.Attr
298
+ if c .cc .slowStartThreshold != math .MaxInt {
299
+ ssthresh = slog .Int ("ssthresh" , c .cc .slowStartThreshold )
300
+ }
301
+ log .LogAttrs (context .Background (), QLogLevelPacket ,
302
+ "recovery:metrics_updated" ,
303
+ slog .Duration ("min_rtt" , c .rtt .minRTT ),
304
+ slog .Duration ("smoothed_rtt" , c .rtt .smoothedRTT ),
305
+ slog .Duration ("latest_rtt" , c .rtt .latestRTT ),
306
+ slog .Duration ("rtt_variance" , c .rtt .rttvar ),
307
+ slog .Int ("congestion_window" , c .cc .congestionWindow ),
308
+ slog .Int ("bytes_in_flight" , c .cc .bytesInFlight ),
309
+ ssthresh ,
310
+ )
311
+ }
290
312
}
291
313
292
314
// discardPackets declares that packets within a number space will not be delivered
293
315
// and that data contained in them should be resent.
294
316
// For example, after receiving a Retry packet we discard already-sent Initial packets.
295
- func (c * lossState ) discardPackets (space numberSpace , lossf func (numberSpace , * sentPacket , packetFate )) {
317
+ func (c * lossState ) discardPackets (space numberSpace , log * slog. Logger , lossf func (numberSpace , * sentPacket , packetFate )) {
296
318
for i := 0 ; i < c .spaces [space ].size ; i ++ {
297
319
sent := c .spaces [space ].nth (i )
298
320
sent .lost = true
299
321
c .cc .packetDiscarded (sent )
300
322
lossf (numberSpace (space ), sent , packetLost )
301
323
}
302
324
c .spaces [space ].clean ()
325
+ if logEnabled (log , QLogLevelPacket ) {
326
+ logBytesInFlight (log , c .cc .bytesInFlight )
327
+ }
303
328
}
304
329
305
330
// discardKeys is called when dropping packet protection keys for a number space.
306
- func (c * lossState ) discardKeys (now time.Time , space numberSpace ) {
331
+ func (c * lossState ) discardKeys (now time.Time , log * slog. Logger , space numberSpace ) {
307
332
// https://www.rfc-editor.org/rfc/rfc9002.html#section-6.4
308
333
for i := 0 ; i < c .spaces [space ].size ; i ++ {
309
334
sent := c .spaces [space ].nth (i )
@@ -313,6 +338,9 @@ func (c *lossState) discardKeys(now time.Time, space numberSpace) {
313
338
c .spaces [space ].maxAcked = - 1
314
339
c .spaces [space ].lastAckEliciting = - 1
315
340
c .scheduleTimer (now )
341
+ if logEnabled (log , QLogLevelPacket ) {
342
+ logBytesInFlight (log , c .cc .bytesInFlight )
343
+ }
316
344
}
317
345
318
346
func (c * lossState ) lossDuration () time.Duration {
@@ -459,3 +487,10 @@ func (c *lossState) ptoBasePeriod() time.Duration {
459
487
}
460
488
return pto
461
489
}
490
+
491
+ func logBytesInFlight (log * slog.Logger , bytesInFlight int ) {
492
+ log .LogAttrs (context .Background (), QLogLevelPacket ,
493
+ "recovery:metrics_updated" ,
494
+ slog .Int ("bytes_in_flight" , bytesInFlight ),
495
+ )
496
+ }
0 commit comments