From d48c08037a54b398b90fb22615812ef0fcf65aeb Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 26 Mar 2021 15:55:30 +0700 Subject: [PATCH] don't use a lower RTT than 5ms after receiving a Retry packet --- internal/ackhandler/sent_packet_handler.go | 5 ++++- internal/ackhandler/sent_packet_handler_test.go | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/internal/ackhandler/sent_packet_handler.go b/internal/ackhandler/sent_packet_handler.go index 91ff05a3..e314e8f1 100644 --- a/internal/ackhandler/sent_packet_handler.go +++ b/internal/ackhandler/sent_packet_handler.go @@ -21,6 +21,8 @@ const ( packetThreshold = 3 // Before validating the client's address, the server won't send more than 3x bytes than it received. amplificationFactor = 3 + // We use Retry packets to derive an RTT estimate. Make sure we don't set the RTT to a super low value yet. + minRTTAfterRetry = 5 * time.Millisecond ) type packetNumberSpace struct { @@ -768,8 +770,9 @@ func (h *sentPacketHandler) ResetForRetry() error { // Only use the Retry to estimate the RTT if we didn't send any retransmission for the Initial. // Otherwise, we don't know which Initial the Retry was sent in response to. if h.ptoCount == 0 { + // Don't set the RTT to a value lower than 5ms here. now := time.Now() - h.rttStats.UpdateRTT(now.Sub(firstPacketSendTime), 0, now) + h.rttStats.UpdateRTT(utils.MaxDuration(minRTTAfterRetry, now.Sub(firstPacketSendTime)), 0, now) if h.logger.Debug() { h.logger.Debugf("\tupdated RTT: %s (σ: %s)", h.rttStats.SmoothedRTT(), h.rttStats.MeanDeviation()) } diff --git a/internal/ackhandler/sent_packet_handler_test.go b/internal/ackhandler/sent_packet_handler_test.go index 380be3c8..7e515f0d 100644 --- a/internal/ackhandler/sent_packet_handler_test.go +++ b/internal/ackhandler/sent_packet_handler_test.go @@ -1201,6 +1201,21 @@ var _ = Describe("SentPacketHandler", func() { Expect(handler.rttStats.SmoothedRTT()).To(BeNumerically("~", 500*time.Millisecond, 100*time.Millisecond)) }) + It("uses a Retry for an RTT estimate, but doesn't set the RTT to a value lower than 5ms", func() { + handler.SentPacket(ackElicitingPacket(&Packet{ + PacketNumber: 42, + EncryptionLevel: protocol.EncryptionInitial, + SendTime: time.Now().Add(-500 * time.Microsecond), + })) + handler.SentPacket(ackElicitingPacket(&Packet{ + PacketNumber: 43, + EncryptionLevel: protocol.EncryptionInitial, + SendTime: time.Now().Add(-10 * time.Microsecond), + })) + Expect(handler.ResetForRetry()).To(Succeed()) + Expect(handler.rttStats.SmoothedRTT()).To(Equal(minRTTAfterRetry)) + }) + It("doesn't use a Retry for an RTT estimate, if it was not retransmitted", func() { handler.SentPacket(ackElicitingPacket(&Packet{ PacketNumber: 42,