From f35a32989cc1fc76dee43f775ad2803096ce07f7 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Wed, 27 Nov 2019 19:22:48 +0700 Subject: [PATCH] enforce the active_connection_id_limit --- conn_id_manager.go | 3 ++- conn_id_manager_test.go | 21 +++++++-------------- internal/qerr/error_codes.go | 3 +++ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/conn_id_manager.go b/conn_id_manager.go index 2fc10145..dcb36b96 100644 --- a/conn_id_manager.go +++ b/conn_id_manager.go @@ -7,6 +7,7 @@ import ( mrand "math/rand" "github.com/lucas-clemente/quic-go/internal/protocol" + "github.com/lucas-clemente/quic-go/internal/qerr" "github.com/lucas-clemente/quic-go/internal/utils" "github.com/lucas-clemente/quic-go/internal/wire" ) @@ -57,7 +58,7 @@ func (h *connIDManager) Add(f *wire.NewConnectionIDFrame) error { return err } if h.queue.Len() >= protocol.MaxActiveConnectionIDs { - h.updateConnectionID() + return qerr.ConnectionIDLimitError } return nil } diff --git a/conn_id_manager_test.go b/conn_id_manager_test.go index 66047f10..43754c8a 100644 --- a/conn_id_manager_test.go +++ b/conn_id_manager_test.go @@ -176,26 +176,19 @@ var _ = Describe("Connection ID Manager", func() { Expect(frameQueue[0].(*wire.RetireConnectionIDFrame).SequenceNumber).To(BeEquivalentTo(4)) }) - It("retires old connection IDs when the peer sends too many new ones", func() { - for i := uint8(1); i <= protocol.MaxActiveConnectionIDs; i++ { + It("errors when the peer sends too connection IDs", func() { + for i := uint8(1); i < protocol.MaxActiveConnectionIDs; i++ { Expect(m.Add(&wire.NewConnectionIDFrame{ SequenceNumber: uint64(i), ConnectionID: protocol.ConnectionID{i, i, i, i}, StatelessResetToken: [16]byte{i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i}, })).To(Succeed()) } - Expect(frameQueue).To(HaveLen(1)) - Expect(frameQueue[0].(*wire.RetireConnectionIDFrame).SequenceNumber).To(BeZero()) - Expect(retiredTokens).To(BeEmpty()) - frameQueue = nil Expect(m.Add(&wire.NewConnectionIDFrame{ - SequenceNumber: protocol.MaxActiveConnectionIDs + 1, - ConnectionID: protocol.ConnectionID{1, 2, 3, 4}, - })).To(Succeed()) - Expect(frameQueue).To(HaveLen(1)) - Expect(frameQueue[0].(*wire.RetireConnectionIDFrame).SequenceNumber).To(BeEquivalentTo(1)) - Expect(retiredTokens).To(HaveLen(1)) - Expect(retiredTokens[0]).To(Equal([16]byte{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})) + SequenceNumber: uint64(9999), + ConnectionID: protocol.ConnectionID{1, 2, 3, 4}, + StatelessResetToken: [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, + })).To(MatchError("CONNECTION_ID_LIMIT_ERROR")) }) It("initiates the first connection ID update as soon as possible", func() { @@ -211,7 +204,7 @@ var _ = Describe("Connection ID Manager", func() { It("initiates subsequent updates when enough packets are sent", func() { var s uint8 - for s = uint8(1); s <= protocol.MaxActiveConnectionIDs; s++ { + for s = uint8(1); s < protocol.MaxActiveConnectionIDs; s++ { Expect(m.Add(&wire.NewConnectionIDFrame{ SequenceNumber: uint64(s), ConnectionID: protocol.ConnectionID{s, s, s, s}, diff --git a/internal/qerr/error_codes.go b/internal/qerr/error_codes.go index 4158fcdb..d9d669bf 100644 --- a/internal/qerr/error_codes.go +++ b/internal/qerr/error_codes.go @@ -20,6 +20,7 @@ const ( FinalSizeError ErrorCode = 0x6 FrameEncodingError ErrorCode = 0x7 TransportParameterError ErrorCode = 0x8 + ConnectionIDLimitError ErrorCode = 0x9 ProtocolViolation ErrorCode = 0xa CryptoBufferExceeded ErrorCode = 0xd ) @@ -64,6 +65,8 @@ func (e ErrorCode) String() string { return "FRAME_ENCODING_ERROR" case TransportParameterError: return "TRANSPORT_PARAMETER_ERROR" + case ConnectionIDLimitError: + return "CONNECTION_ID_LIMIT_ERROR" case ProtocolViolation: return "PROTOCOL_VIOLATION" case CryptoBufferExceeded: