From 4366eac105c08d92cf6f996e84285d2a7a820d59 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sat, 29 Jun 2019 14:02:05 +0700 Subject: [PATCH] don't include the exponential backoff in the PTO calculation According to the spec, the PTO is defined without the backoff. The backoff is applied when setting the PTO alarm. --- internal/ackhandler/sent_packet_handler.go | 5 ++--- internal/ackhandler/sent_packet_handler_test.go | 13 ++++++++----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/internal/ackhandler/sent_packet_handler.go b/internal/ackhandler/sent_packet_handler.go index 2d81fc6f2..9f3022283 100644 --- a/internal/ackhandler/sent_packet_handler.go +++ b/internal/ackhandler/sent_packet_handler.go @@ -342,7 +342,7 @@ func (h *sentPacketHandler) updateLossDetectionAlarm() { // Early retransmit timer or time loss detection. h.alarm = h.lossTime } else { // PTO alarm - h.alarm = h.lastSentAckElicitingPacketTime.Add(h.computePTOTimeout()) + h.alarm = h.lastSentAckElicitingPacketTime.Add(h.computePTOTimeout() << h.ptoCount) } } @@ -658,8 +658,7 @@ func (h *sentPacketHandler) computeCryptoTimeout() time.Duration { } func (h *sentPacketHandler) computePTOTimeout() time.Duration { - duration := h.rttStats.SmoothedOrInitialRTT() + utils.MaxDuration(4*h.rttStats.MeanDeviation(), protocol.TimerGranularity) + h.rttStats.MaxAckDelay() - return duration << h.ptoCount + return h.rttStats.SmoothedOrInitialRTT() + utils.MaxDuration(4*h.rttStats.MeanDeviation(), protocol.TimerGranularity) + h.rttStats.MaxAckDelay() } func (h *sentPacketHandler) ResetForRetry() error { diff --git a/internal/ackhandler/sent_packet_handler_test.go b/internal/ackhandler/sent_packet_handler_test.go index de9d60ebd..3942a3fe4 100644 --- a/internal/ackhandler/sent_packet_handler_test.go +++ b/internal/ackhandler/sent_packet_handler_test.go @@ -626,13 +626,16 @@ var _ = Describe("SentPacketHandler", func() { }) It("implements exponential backoff", func() { - handler.ptoCount = 0 - timeout := handler.computePTOTimeout() - Expect(timeout).ToNot(BeZero()) + sendTime := time.Now().Add(-time.Hour) + handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 1, SendTime: sendTime})) + timeout := handler.GetAlarmTimeout().Sub(sendTime) + Expect(handler.GetAlarmTimeout().Sub(sendTime)).To(Equal(timeout)) handler.ptoCount = 1 - Expect(handler.computePTOTimeout()).To(Equal(2 * timeout)) + handler.updateLossDetectionAlarm() + Expect(handler.GetAlarmTimeout().Sub(sendTime)).To(Equal(2 * timeout)) handler.ptoCount = 2 - Expect(handler.computePTOTimeout()).To(Equal(4 * timeout)) + handler.updateLossDetectionAlarm() + Expect(handler.GetAlarmTimeout().Sub(sendTime)).To(Equal(4 * timeout)) }) It("sets the TPO send mode until two packets is sent", func() {