From a53569839cb79fd654ae44e27949d348ec3d4c36 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Sun, 24 Nov 2019 09:35:14 +0700 Subject: [PATCH] don't queue the currently active conn ID when receiving a duplicate --- conn_id_manager.go | 4 ++++ conn_id_manager_test.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/conn_id_manager.go b/conn_id_manager.go index d761897d..a2b268df 100644 --- a/conn_id_manager.go +++ b/conn_id_manager.go @@ -89,6 +89,10 @@ func (h *connIDManager) add(f *wire.NewConnectionIDFrame) error { h.retiredPriorTo = f.RetirePriorTo } + if f.SequenceNumber == h.activeSequenceNumber { + return nil + } + // insert a new element at the end if h.queue.Len() == 0 || h.queue.Back().Value.SequenceNumber < f.SequenceNumber { h.queue.PushBack(utils.NewConnectionID{ diff --git a/conn_id_manager_test.go b/conn_id_manager_test.go index b5fc211b..49af58d0 100644 --- a/conn_id_manager_test.go +++ b/conn_id_manager_test.go @@ -95,6 +95,22 @@ var _ = Describe("Connection ID Manager", func() { Expect(rt2).To(BeNil()) }) + It("ignores duplicates for the currently used connection ID", func() { + f := &wire.NewConnectionIDFrame{ + SequenceNumber: 1, + ConnectionID: protocol.ConnectionID{1, 2, 3, 4}, + StatelessResetToken: [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd, 0xe}, + } + Expect(m.Add(f)).To(Succeed()) + Expect(m.Get()).To(Equal(protocol.ConnectionID{1, 2, 3, 4})) + c, _ := get() + Expect(c).To(BeNil()) + // Now send the same connection ID again. It should not be queued. + Expect(m.Add(f)).To(Succeed()) + c, _ = get() + Expect(c).To(BeNil()) + }) + It("rejects duplicates with different connection IDs", func() { Expect(m.Add(&wire.NewConnectionIDFrame{ SequenceNumber: 42,