move calculation of the PTO to the rttStats

The PTO value is needed at various places in the protocol. Calculating
it on the rttStats struct will allow us to pass around this struct.
This commit is contained in:
Marten Seemann
2019-06-29 14:49:33 +07:00
parent 4366eac105
commit 66abcdfc5c
4 changed files with 23 additions and 19 deletions

View File

@@ -3,6 +3,7 @@ package congestion
import (
"time"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/utils"
)
@@ -56,6 +57,10 @@ func (r *RTTStats) MeanDeviation() time.Duration { return r.meanDeviation }
func (r *RTTStats) MaxAckDelay() time.Duration { return r.maxAckDelay }
func (r *RTTStats) PTO() time.Duration {
return r.SmoothedOrInitialRTT() + utils.MaxDuration(4*r.MeanDeviation(), protocol.TimerGranularity) + r.MaxAckDelay()
}
// UpdateRTT updates the RTT based on a new sample.
func (r *RTTStats) UpdateRTT(sendDelta, ackDelay time.Duration, now time.Time) {
if sendDelta == utils.InfDuration || sendDelta <= 0 {

View File

@@ -3,6 +3,7 @@ package congestion
import (
"time"
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
@@ -64,6 +65,22 @@ var _ = Describe("RTT stats", func() {
Expect(rttStats.MaxAckDelay()).To(Equal(42 * time.Minute))
})
It("computes the PTO", func() {
maxAckDelay := 42 * time.Minute
rttStats.SetMaxAckDelay(maxAckDelay)
rtt := time.Second
rttStats.UpdateRTT(rtt, 0, time.Time{})
Expect(rttStats.SmoothedRTT()).To(Equal(rtt))
Expect(rttStats.MeanDeviation()).To(Equal(rtt / 2))
Expect(rttStats.PTO()).To(Equal(rtt + 4*(rtt/2) + maxAckDelay))
})
It("uses the granularity for computing the PTO for short RTTs", func() {
rtt := time.Microsecond
rttStats.UpdateRTT(rtt, 0, time.Time{})
Expect(rttStats.PTO()).To(Equal(rtt + protocol.TimerGranularity))
})
It("ExpireSmoothedMetrics", func() {
initialRtt := (10 * time.Millisecond)
rttStats.UpdateRTT(initialRtt, 0, time.Time{})