forked from quic-go/quic-go
save the RTT along the session ticket and use it on resumed connections
This commit is contained in:
@@ -18,6 +18,8 @@ const (
|
||||
|
||||
// RTTStats provides round-trip statistics
|
||||
type RTTStats struct {
|
||||
hasMeasurement bool
|
||||
|
||||
minRTT time.Duration
|
||||
latestRTT time.Duration
|
||||
smoothedRTT time.Duration
|
||||
@@ -84,7 +86,8 @@ func (r *RTTStats) UpdateRTT(sendDelta, ackDelay time.Duration, now time.Time) {
|
||||
}
|
||||
r.latestRTT = sample
|
||||
// First time call.
|
||||
if r.smoothedRTT == 0 {
|
||||
if !r.hasMeasurement {
|
||||
r.hasMeasurement = true
|
||||
r.smoothedRTT = sample
|
||||
r.meanDeviation = sample / 2
|
||||
} else {
|
||||
@@ -93,10 +96,21 @@ func (r *RTTStats) UpdateRTT(sendDelta, ackDelay time.Duration, now time.Time) {
|
||||
}
|
||||
}
|
||||
|
||||
// SetMaxAckDelay sets the max_ack_delay
|
||||
func (r *RTTStats) SetMaxAckDelay(mad time.Duration) {
|
||||
r.maxAckDelay = mad
|
||||
}
|
||||
|
||||
// SetInitialRTT sets the initial RTT.
|
||||
// It is used during the 0-RTT handshake when restoring the RTT stats from the session state.
|
||||
func (r *RTTStats) SetInitialRTT(t time.Duration) {
|
||||
if r.hasMeasurement {
|
||||
panic("initial RTT set after first measurement")
|
||||
}
|
||||
r.smoothedRTT = t
|
||||
r.latestRTT = t
|
||||
}
|
||||
|
||||
// OnConnectionMigration is called when connection migrates and rtt measurement needs to be reset.
|
||||
func (r *RTTStats) OnConnectionMigration() {
|
||||
r.latestRTT = 0
|
||||
|
||||
@@ -129,7 +129,7 @@ var _ = Describe("RTT stats", func() {
|
||||
})
|
||||
|
||||
It("ResetAfterConnectionMigrations", func() {
|
||||
rttStats.UpdateRTT((200 * time.Millisecond), 0, time.Time{})
|
||||
rttStats.UpdateRTT(200*time.Millisecond, 0, time.Time{})
|
||||
Expect(rttStats.LatestRTT()).To(Equal((200 * time.Millisecond)))
|
||||
Expect(rttStats.SmoothedRTT()).To(Equal((200 * time.Millisecond)))
|
||||
Expect(rttStats.MinRTT()).To(Equal((200 * time.Millisecond)))
|
||||
@@ -145,4 +145,15 @@ var _ = Describe("RTT stats", func() {
|
||||
Expect(rttStats.MinRTT()).To(Equal(time.Duration(0)))
|
||||
})
|
||||
|
||||
It("restores the RTT", func() {
|
||||
rttStats.SetInitialRTT(10 * time.Second)
|
||||
Expect(rttStats.LatestRTT()).To(Equal(10 * time.Second))
|
||||
Expect(rttStats.SmoothedRTT()).To(Equal(10 * time.Second))
|
||||
Expect(rttStats.MeanDeviation()).To(BeZero())
|
||||
// update the RTT and make sure that the initial value is immediately forgotten
|
||||
rttStats.UpdateRTT(200*time.Millisecond, 0, time.Time{})
|
||||
Expect(rttStats.LatestRTT()).To(Equal(200 * time.Millisecond))
|
||||
Expect(rttStats.SmoothedRTT()).To(Equal(200 * time.Millisecond))
|
||||
Expect(rttStats.MeanDeviation()).To(Equal(100 * time.Millisecond))
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user