retire stateless tokens when updating the connection ID

This commit is contained in:
Marten Seemann 2019-10-26 16:43:17 +07:00
parent 5203b026e3
commit 326279894b
3 changed files with 26 additions and 10 deletions

View file

@ -15,19 +15,22 @@ type connIDManager struct {
activeConnectionID protocol.ConnectionID
activeStatelessResetToken *[16]byte
addStatelessResetToken func([16]byte)
queueControlFrame func(wire.Frame)
addStatelessResetToken func([16]byte)
retireStatelessResetToken func([16]byte)
queueControlFrame func(wire.Frame)
}
func newConnIDManager(
initialDestConnID protocol.ConnectionID,
addStatelessResetToken func([16]byte),
retireStatelessResetToken func([16]byte),
queueControlFrame func(wire.Frame),
) *connIDManager {
return &connIDManager{
activeConnectionID: initialDestConnID,
addStatelessResetToken: addStatelessResetToken,
queueControlFrame: queueControlFrame,
activeConnectionID: initialDestConnID,
addStatelessResetToken: addStatelessResetToken,
retireStatelessResetToken: retireStatelessResetToken,
queueControlFrame: queueControlFrame,
}
}
@ -98,10 +101,14 @@ func (h *connIDManager) updateConnectionID() {
h.queueControlFrame(&wire.RetireConnectionIDFrame{
SequenceNumber: h.activeSequenceNumber,
})
if h.activeStatelessResetToken != nil {
h.retireStatelessResetToken(*h.activeStatelessResetToken)
}
front := h.queue.Remove(h.queue.Front())
h.activeSequenceNumber = front.SequenceNumber
h.activeConnectionID = front.ConnectionID
h.activeStatelessResetToken = front.StatelessResetToken
h.addStatelessResetToken(*h.activeStatelessResetToken)
}
// is called when the server performs a Retry

View file

@ -9,18 +9,21 @@ import (
var _ = Describe("Connection ID Manager", func() {
var (
m *connIDManager
frameQueue []wire.Frame
tokenAdded *[16]byte
m *connIDManager
frameQueue []wire.Frame
tokenAdded *[16]byte
retiredTokens [][16]byte
)
initialConnID := protocol.ConnectionID{1, 1, 1, 1}
BeforeEach(func() {
frameQueue = nil
tokenAdded = nil
retiredTokens = nil
m = newConnIDManager(
initialConnID,
func(token [16]byte) { tokenAdded = &token },
func(token [16]byte) { retiredTokens = append(retiredTokens, token) },
func(f wire.Frame,
) {
frameQueue = append(frameQueue, f)
@ -138,12 +141,14 @@ var _ = Describe("Connection ID Manager", func() {
It("retires old connection IDs when the peer sends too many new ones", func() {
for i := uint8(1); i <= protocol.MaxActiveConnectionIDs; i++ {
Expect(m.Add(&wire.NewConnectionIDFrame{
SequenceNumber: uint64(i),
ConnectionID: protocol.ConnectionID{i, i, i, i},
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,
@ -151,5 +156,7 @@ var _ = Describe("Connection ID Manager", func() {
})).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}))
})
})

View file

@ -209,6 +209,7 @@ var newSession = func(
s.connIDManager = newConnIDManager(
destConnID,
func(token [16]byte) { runner.AddResetToken(token, s) },
runner.RetireResetToken,
s.queueControlFrame,
)
s.preSetup()
@ -281,6 +282,7 @@ var newClientSession = func(
s.connIDManager = newConnIDManager(
destConnID,
func(token [16]byte) { runner.AddResetToken(token, s) },
runner.RetireResetToken,
s.queueControlFrame,
)
s.preSetup()