diff --git a/internal/ackhandler/sent_packet_handler.go b/internal/ackhandler/sent_packet_handler.go index e875e764..9a05ef76 100644 --- a/internal/ackhandler/sent_packet_handler.go +++ b/internal/ackhandler/sent_packet_handler.go @@ -205,7 +205,12 @@ func (h *sentPacketHandler) ReceivedAck(ackFrame *wire.AckFrame, withPacketNumbe // maybe update the RTT if p := pnSpace.history.GetPacket(ackFrame.LargestAcked()); p != nil { - h.rttStats.UpdateRTT(rcvTime.Sub(p.SendTime), ackFrame.DelayTime, rcvTime) + // don't use the ack delay for Initial and Handshake packets + var ackDelay time.Duration + if encLevel == protocol.Encryption1RTT { + ackDelay = ackFrame.DelayTime + } + h.rttStats.UpdateRTT(rcvTime.Sub(p.SendTime), ackDelay, rcvTime) 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 fa82c2fd..18685622 100644 --- a/internal/ackhandler/sent_packet_handler_test.go +++ b/internal/ackhandler/sent_packet_handler_test.go @@ -292,6 +292,20 @@ var _ = Describe("SentPacketHandler", func() { Expect(handler.rttStats.LatestRTT()).To(BeNumerically("~", 1*time.Minute, 1*time.Second)) }) + It("ignores the DelayTime for Initial and Handshake packets", func() { + handler.SentPacket(cryptoPacket(&Packet{PacketNumber: 1})) + now := time.Now() + // make sure the rttStats have a min RTT, so that the delay is used + handler.rttStats.UpdateRTT(5*time.Minute, 0, time.Now()) + getPacket(1, protocol.EncryptionInitial).SendTime = now.Add(-10 * time.Minute) + ack := &wire.AckFrame{ + AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}, + DelayTime: 5 * time.Minute, + } + Expect(handler.ReceivedAck(ack, 1, protocol.EncryptionInitial, time.Now())).To(Succeed()) + Expect(handler.rttStats.LatestRTT()).To(BeNumerically("~", 10*time.Minute, 1*time.Second)) + }) + It("uses the DelayTime in the ACK frame", func() { now := time.Now() // make sure the rttStats have a min RTT, so that the delay is used @@ -301,8 +315,7 @@ var _ = Describe("SentPacketHandler", func() { AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}, DelayTime: 5 * time.Minute, } - err := handler.ReceivedAck(ack, 1, protocol.Encryption1RTT, time.Now()) - Expect(err).NotTo(HaveOccurred()) + Expect(handler.ReceivedAck(ack, 1, protocol.Encryption1RTT, time.Now())).To(Succeed()) Expect(handler.rttStats.LatestRTT()).To(BeNumerically("~", 5*time.Minute, 1*time.Second)) }) })