diff --git a/ackhandler/received_packet_handler.go b/ackhandler/received_packet_handler.go index 7416ed88..dcc1b309 100644 --- a/ackhandler/received_packet_handler.go +++ b/ackhandler/received_packet_handler.go @@ -75,7 +75,7 @@ func (h *receivedPacketHandler) ReceivedPacket(packetNumber protocol.PacketNumbe h.receivedTimes[packetNumber] = time.Now() - if uint32(len(h.receivedTimes)) > protocol.MaxTrackedReceivedPackets { + if protocol.PacketNumber(len(h.receivedTimes)) > protocol.MaxTrackedReceivedPackets { return errTooManyOutstandingReceivedPackets } diff --git a/ackhandler/received_packet_handler_test.go b/ackhandler/received_packet_handler_test.go index 5e55d9e5..948ce93d 100644 --- a/ackhandler/received_packet_handler_test.go +++ b/ackhandler/received_packet_handler_test.go @@ -83,7 +83,7 @@ var _ = Describe("receivedPacketHandler", func() { }) It("doesn't store more than MaxTrackedReceivedPackets packets", func() { - for i := uint32(0); i < protocol.MaxTrackedReceivedPackets; i++ { + for i := protocol.PacketNumber(0); i < protocol.MaxTrackedReceivedPackets; i++ { packetNumber := protocol.PacketNumber(1 + 2*i) err := handler.ReceivedPacket(packetNumber) Expect(err).ToNot(HaveOccurred()) diff --git a/ackhandler/sent_packet_handler.go b/ackhandler/sent_packet_handler.go index 3d10ab2e..13d725f6 100644 --- a/ackhandler/sent_packet_handler.go +++ b/ackhandler/sent_packet_handler.go @@ -274,7 +274,7 @@ func (h *sentPacketHandler) CongestionAllowsSending() bool { func (h *sentPacketHandler) CheckForError() error { length := len(h.retransmissionQueue) + h.packetHistory.Len() - if uint32(length) > protocol.MaxTrackedSentPackets { + if protocol.PacketNumber(length) > protocol.MaxTrackedSentPackets { return ErrTooManyTrackedSentPackets } return nil diff --git a/ackhandler/sent_packet_handler_test.go b/ackhandler/sent_packet_handler_test.go index b22dcac7..45c4c995 100644 --- a/ackhandler/sent_packet_handler_test.go +++ b/ackhandler/sent_packet_handler_test.go @@ -213,7 +213,7 @@ var _ = Describe("SentPacketHandler", func() { Context("DOS mitigation", func() { It("checks the size of the packet history, for unacked packets", func() { - for i := uint32(1); i < protocol.MaxTrackedSentPackets+10; i++ { + for i := protocol.PacketNumber(1); i < protocol.MaxTrackedSentPackets+10; i++ { packet := Packet{PacketNumber: protocol.PacketNumber(i), Frames: []frames.Frame{&streamFrame}, Length: 1} err := handler.SentPacket(&packet) Expect(err).ToNot(HaveOccurred()) diff --git a/protocol/server_parameters.go b/protocol/server_parameters.go index 7cc1f651..8db73a3e 100644 --- a/protocol/server_parameters.go +++ b/protocol/server_parameters.go @@ -44,7 +44,7 @@ const MaxNewStreamIDDelta = 4 * MaxStreamsPerConnection const MaxIdleConnectionStateLifetime = 60 * time.Second // MaxSessionUnprocessedPackets is the max number of packets stored in each session that are not yet processed. -const MaxSessionUnprocessedPackets = 2000 +const MaxSessionUnprocessedPackets = DefaultMaxCongestionWindow // RetransmissionThreshold + 1 is the number of times a packet has to be NACKed so that it gets retransmitted const RetransmissionThreshold = 3 @@ -59,13 +59,10 @@ const MaxTrackedSkippedPackets = 10 const STKExpiryTimeSec = 24 * 60 * 60 // MaxTrackedSentPackets is maximum number of sent packets saved for either later retransmission or entropy calculation -// TODO: find a reasonable value here -// TODO: decrease this value after dropping support for QUIC 33 and earlier -const MaxTrackedSentPackets = 2000 +const MaxTrackedSentPackets = 2 * DefaultMaxCongestionWindow // MaxTrackedReceivedPackets is the maximum number of received packets saved for doing the entropy calculations -// TODO: think about what to do with this when adding support for QUIC 34 -const MaxTrackedReceivedPackets = 2000 +const MaxTrackedReceivedPackets = 2 * DefaultMaxCongestionWindow // MaxStreamFrameSorterGaps is the maximum number of gaps between received StreamFrames // prevents DOS attacks against the streamFrameSorter diff --git a/session_test.go b/session_test.go index a2a10d38..c13ff0c9 100644 --- a/session_test.go +++ b/session_test.go @@ -762,7 +762,7 @@ var _ = Describe("Session", func() { It("errors when the SentPacketHandler has too many packets tracked", func() { streamFrame := frames.StreamFrame{StreamID: 5, Data: []byte("foobar")} - for i := uint32(1); i < protocol.MaxTrackedSentPackets+10; i++ { + for i := protocol.PacketNumber(1); i < protocol.MaxTrackedSentPackets+10; i++ { packet := ackhandler.Packet{PacketNumber: protocol.PacketNumber(i), Frames: []frames.Frame{&streamFrame}, Length: 1} err := session.sentPacketHandler.SentPacket(&packet) Expect(err).ToNot(HaveOccurred()) @@ -774,7 +774,7 @@ var _ = Describe("Session", func() { It("stores up to MaxSessionUnprocessedPackets packets", func(done Done) { // Nothing here should block - for i := 0; i < protocol.MaxSessionUnprocessedPackets+10; i++ { + for i := protocol.PacketNumber(0); i < protocol.MaxSessionUnprocessedPackets+10; i++ { session.handlePacket(nil, nil, nil) } close(done)