diff --git a/conn_id_manager.go b/conn_id_manager.go index f4bc5c0e..ee1729a7 100644 --- a/conn_id_manager.go +++ b/conn_id_manager.go @@ -68,9 +68,9 @@ func (h *connIDManager) Add(f *wire.NewConnectionIDFrame) error { } func (h *connIDManager) add(f *wire.NewConnectionIDFrame) error { - // If the NEW_CONNECTION_ID frame is reordered, such that its sequence number - // was already retired, send the RETIRE_CONNECTION_ID frame immediately. - if f.SequenceNumber < h.highestRetired { + // If the NEW_CONNECTION_ID frame is reordered, such that its sequence number is smaller than the currently active + // connection ID or if it was already retired, send the RETIRE_CONNECTION_ID frame immediately. + if f.SequenceNumber <= h.activeSequenceNumber || f.SequenceNumber < h.highestRetired { h.queueControlFrame(&wire.RetireConnectionIDFrame{ SequenceNumber: f.SequenceNumber, }) diff --git a/conn_id_manager_test.go b/conn_id_manager_test.go index 49345d19..3c3a6cfb 100644 --- a/conn_id_manager_test.go +++ b/conn_id_manager_test.go @@ -181,6 +181,26 @@ var _ = Describe("Connection ID Manager", func() { Expect(frameQueue[0].(*wire.RetireConnectionIDFrame).SequenceNumber).To(BeEquivalentTo(4)) }) + It("ignores reordered connection IDs, if their sequence number was already retired or less than active", func() { + Expect(m.Add(&wire.NewConnectionIDFrame{ + SequenceNumber: 10, + ConnectionID: protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef}, + RetirePriorTo: 5, + })).To(Succeed()) + Expect(frameQueue).To(HaveLen(1)) + Expect(frameQueue[0].(*wire.RetireConnectionIDFrame).SequenceNumber).To(BeZero()) + frameQueue = nil + Expect(m.Get()).To(Equal(protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef})) + + Expect(m.Add(&wire.NewConnectionIDFrame{ + SequenceNumber: 9, + ConnectionID: protocol.ConnectionID{0xde, 0xca, 0xfb, 0xad}, + RetirePriorTo: 5, + })).To(Succeed()) + Expect(frameQueue).To(HaveLen(1)) + Expect(frameQueue[0].(*wire.RetireConnectionIDFrame).SequenceNumber).To(BeEquivalentTo(9)) + }) + It("errors when the peer sends too connection IDs", func() { for i := uint8(1); i < protocol.MaxActiveConnectionIDs; i++ { Expect(m.Add(&wire.NewConnectionIDFrame{