From 8fc0f53a8d581c8fa20e04e71d62667b3a6914c7 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Tue, 27 Feb 2018 20:07:08 +0800 Subject: [PATCH] move constants used by the received packet handler to ackhandler package --- internal/ackhandler/received_packet_handler.go | 11 +++++++++-- internal/ackhandler/received_packet_handler_test.go | 2 +- internal/protocol/server_parameters.go | 7 ------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/ackhandler/received_packet_handler.go b/internal/ackhandler/received_packet_handler.go index c316af4a..cf19b115 100644 --- a/internal/ackhandler/received_packet_handler.go +++ b/internal/ackhandler/received_packet_handler.go @@ -25,11 +25,18 @@ type receivedPacketHandler struct { version protocol.VersionNumber } +const ( + // ackSendDelay is the maximum delay that can be applied to an ACK for a retransmittable packet + ackSendDelay = 25 * time.Millisecond + // retransmittablePacketsBeforeAck is the number of retransmittable that an ACK is sent for + retransmittablePacketsBeforeAck = 10 +) + // NewReceivedPacketHandler creates a new receivedPacketHandler func NewReceivedPacketHandler(version protocol.VersionNumber) ReceivedPacketHandler { return &receivedPacketHandler{ packetHistory: newReceivedPacketHistory(), - ackSendDelay: protocol.AckSendDelay, + ackSendDelay: ackSendDelay, version: version, } } @@ -82,7 +89,7 @@ func (h *receivedPacketHandler) maybeQueueAck(packetNumber protocol.PacketNumber } if !h.ackQueued && shouldInstigateAck { - if h.retransmittablePacketsReceivedSinceLastAck >= protocol.RetransmittablePacketsBeforeAck { + if h.retransmittablePacketsReceivedSinceLastAck >= retransmittablePacketsBeforeAck { h.ackQueued = true } else { if h.ackAlarm.IsZero() { diff --git a/internal/ackhandler/received_packet_handler_test.go b/internal/ackhandler/received_packet_handler_test.go index 2d5b37ce..9cbca137 100644 --- a/internal/ackhandler/received_packet_handler_test.go +++ b/internal/ackhandler/received_packet_handler_test.go @@ -98,7 +98,7 @@ var _ = Describe("receivedPacketHandler", func() { It("queues an ACK for every RetransmittablePacketsBeforeAck retransmittable packet, if they are arriving fast", func() { receiveAndAck10Packets() p := protocol.PacketNumber(11) - for i := 0; i < protocol.RetransmittablePacketsBeforeAck-1; i++ { + for i := 0; i < retransmittablePacketsBeforeAck-1; i++ { err := handler.ReceivedPacket(p, time.Time{}, true) Expect(err).ToNot(HaveOccurred()) Expect(handler.ackQueued).To(BeFalse()) diff --git a/internal/protocol/server_parameters.go b/internal/protocol/server_parameters.go index 263e5e5c..e89d5a9a 100644 --- a/internal/protocol/server_parameters.go +++ b/internal/protocol/server_parameters.go @@ -24,10 +24,6 @@ const MaxUndecryptablePackets = 10 // This timeout allows the Go scheduler to switch to the Go rountine that reads the crypto stream and to escalate the crypto const PublicResetTimeout = 500 * time.Millisecond -// AckSendDelay is the maximum delay that can be applied to an ACK for a retransmittable packet -// This is the value Chromium is using -const AckSendDelay = 25 * time.Millisecond - // ReceiveStreamFlowControlWindow is the stream-level flow control window for receiving data // This is the value that Google servers are using const ReceiveStreamFlowControlWindow = (1 << 10) * 32 // 32 kB @@ -92,9 +88,6 @@ const MaxTrackedReceivedAckRanges = DefaultMaxCongestionWindow // MaxNonRetransmittableAcks is the maximum number of packets containing an ACK, but no retransmittable frames, that we send in a row const MaxNonRetransmittableAcks = 19 -// RetransmittablePacketsBeforeAck is the number of retransmittable that an ACK is sent for -const RetransmittablePacketsBeforeAck = 10 - // MaxStreamFrameSorterGaps is the maximum number of gaps between received StreamFrames // prevents DoS attacks against the streamFrameSorter const MaxStreamFrameSorterGaps = 1000