From 6c27967c8a2bda610536529724b0b3e0eafa12da Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 8 May 2019 13:26:08 +0900 Subject: [PATCH] include the timer granularity in the advertised max_ack_delay --- client.go | 2 +- internal/ackhandler/sent_packet_handler.go | 8 +++----- internal/ackhandler/sent_packet_handler_test.go | 2 +- internal/protocol/params.go | 8 ++++++++ server.go | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/client.go b/client.go index 21a14ab7b..78d0d70b5 100644 --- a/client.go +++ b/client.go @@ -352,7 +352,7 @@ func (c *client) createNewTLSSession(version protocol.VersionNumber) error { IdleTimeout: c.config.IdleTimeout, MaxBidiStreams: uint64(c.config.MaxIncomingStreams), MaxUniStreams: uint64(c.config.MaxIncomingUniStreams), - MaxAckDelay: protocol.MaxAckDelay, + MaxAckDelay: protocol.MaxAckDelayInclGranularity, AckDelayExponent: protocol.AckDelayExponent, DisableMigration: true, } diff --git a/internal/ackhandler/sent_packet_handler.go b/internal/ackhandler/sent_packet_handler.go index 7c3e21538..e875e7646 100644 --- a/internal/ackhandler/sent_packet_handler.go +++ b/internal/ackhandler/sent_packet_handler.go @@ -17,8 +17,6 @@ const ( // Maximum reordering in time space before time based loss detection considers a packet lost. // Specified as an RTT multiplier. timeThreshold = 9.0 / 8 - // Timer granularity. The timer will not be set to a value smaller than granularity. - granularity = time.Millisecond ) type packetNumberSpace struct { @@ -341,7 +339,7 @@ func (h *sentPacketHandler) detectLostPackets( lossDelay := time.Duration(timeThreshold * maxRTT) // Minimum time of granularity before packets are deemed lost. - lossDelay = utils.MaxDuration(lossDelay, granularity) + lossDelay = utils.MaxDuration(lossDelay, protocol.TimerGranularity) var lostPackets []*Packet pnSpace.history.Iterate(func(packet *Packet) (bool, error) { @@ -616,7 +614,7 @@ func (h *sentPacketHandler) queuePacketForRetransmission(p *Packet, pnSpace *pac } func (h *sentPacketHandler) computeCryptoTimeout() time.Duration { - duration := utils.MaxDuration(2*h.rttStats.SmoothedOrInitialRTT(), granularity) + duration := utils.MaxDuration(2*h.rttStats.SmoothedOrInitialRTT(), protocol.TimerGranularity) // exponential backoff // There's an implicit limit to this set by the crypto timeout. return duration << h.cryptoCount @@ -624,7 +622,7 @@ func (h *sentPacketHandler) computeCryptoTimeout() time.Duration { func (h *sentPacketHandler) computePTOTimeout() time.Duration { // TODO(#1236): include the max_ack_delay - duration := utils.MaxDuration(h.rttStats.SmoothedOrInitialRTT()+4*h.rttStats.MeanDeviation(), granularity) + duration := utils.MaxDuration(h.rttStats.SmoothedOrInitialRTT()+4*h.rttStats.MeanDeviation(), protocol.TimerGranularity) return duration << h.ptoCount } diff --git a/internal/ackhandler/sent_packet_handler_test.go b/internal/ackhandler/sent_packet_handler_test.go index 1c2aeb5ad..fa82c2fd0 100644 --- a/internal/ackhandler/sent_packet_handler_test.go +++ b/internal/ackhandler/sent_packet_handler_test.go @@ -593,7 +593,7 @@ var _ = Describe("SentPacketHandler", func() { It("uses the granularity for short RTTs", func() { rtt := time.Microsecond updateRTT(rtt) - Expect(handler.computePTOTimeout()).To(Equal(granularity)) + Expect(handler.computePTOTimeout()).To(Equal(protocol.TimerGranularity)) }) It("implements exponential backoff", func() { diff --git a/internal/protocol/params.go b/internal/protocol/params.go index 6488a36c4..72555a861 100644 --- a/internal/protocol/params.go +++ b/internal/protocol/params.go @@ -126,5 +126,13 @@ const DefaultConnectionIDLength = 4 // AckDelayExponent is the ack delay exponent used when sending ACKs. const AckDelayExponent = 3 +// Estimated timer granularity. +// The loss detection timer will not be set to a value smaller than granularity. +const TimerGranularity = time.Millisecond + // MaxAckDelay is the maximum time by which we delay sending ACKs. const MaxAckDelay = 25 * time.Millisecond + +// MaxAckDelayInclGranularity is the max_ack_delay including the timer granularity. +// This is the value that should be advertised to the peer. +const MaxAckDelayInclGranularity = MaxAckDelay + TimerGranularity diff --git a/server.go b/server.go index be3864687..e6139d548 100644 --- a/server.go +++ b/server.go @@ -445,7 +445,7 @@ func (s *server) createNewSession( IdleTimeout: s.config.IdleTimeout, MaxBidiStreams: uint64(s.config.MaxIncomingStreams), MaxUniStreams: uint64(s.config.MaxIncomingUniStreams), - MaxAckDelay: protocol.MaxAckDelay, + MaxAckDelay: protocol.MaxAckDelayInclGranularity, AckDelayExponent: protocol.AckDelayExponent, DisableMigration: true, StatelessResetToken: &token,