mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
immediately remove reset tokens when retiring a connection ID
This commit is contained in:
parent
ed1956f5a9
commit
05066ae877
7 changed files with 8 additions and 52 deletions
|
@ -30,7 +30,6 @@ type connIDManager struct {
|
||||||
|
|
||||||
addStatelessResetToken func(protocol.StatelessResetToken)
|
addStatelessResetToken func(protocol.StatelessResetToken)
|
||||||
removeStatelessResetToken func(protocol.StatelessResetToken)
|
removeStatelessResetToken func(protocol.StatelessResetToken)
|
||||||
retireStatelessResetToken func(protocol.StatelessResetToken)
|
|
||||||
queueControlFrame func(wire.Frame)
|
queueControlFrame func(wire.Frame)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +37,6 @@ func newConnIDManager(
|
||||||
initialDestConnID protocol.ConnectionID,
|
initialDestConnID protocol.ConnectionID,
|
||||||
addStatelessResetToken func(protocol.StatelessResetToken),
|
addStatelessResetToken func(protocol.StatelessResetToken),
|
||||||
removeStatelessResetToken func(protocol.StatelessResetToken),
|
removeStatelessResetToken func(protocol.StatelessResetToken),
|
||||||
retireStatelessResetToken func(protocol.StatelessResetToken),
|
|
||||||
queueControlFrame func(wire.Frame),
|
queueControlFrame func(wire.Frame),
|
||||||
) *connIDManager {
|
) *connIDManager {
|
||||||
b := make([]byte, 8)
|
b := make([]byte, 8)
|
||||||
|
@ -48,7 +46,6 @@ func newConnIDManager(
|
||||||
activeConnectionID: initialDestConnID,
|
activeConnectionID: initialDestConnID,
|
||||||
addStatelessResetToken: addStatelessResetToken,
|
addStatelessResetToken: addStatelessResetToken,
|
||||||
removeStatelessResetToken: removeStatelessResetToken,
|
removeStatelessResetToken: removeStatelessResetToken,
|
||||||
retireStatelessResetToken: retireStatelessResetToken,
|
|
||||||
queueControlFrame: queueControlFrame,
|
queueControlFrame: queueControlFrame,
|
||||||
rand: mrand.New(mrand.NewSource(seed)),
|
rand: mrand.New(mrand.NewSource(seed)),
|
||||||
}
|
}
|
||||||
|
@ -150,7 +147,7 @@ func (h *connIDManager) updateConnectionID() {
|
||||||
})
|
})
|
||||||
h.highestRetired = utils.MaxUint64(h.highestRetired, h.activeSequenceNumber)
|
h.highestRetired = utils.MaxUint64(h.highestRetired, h.activeSequenceNumber)
|
||||||
if h.activeStatelessResetToken != nil {
|
if h.activeStatelessResetToken != nil {
|
||||||
h.retireStatelessResetToken(*h.activeStatelessResetToken)
|
h.removeStatelessResetToken(*h.activeStatelessResetToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
front := h.queue.Remove(h.queue.Front())
|
front := h.queue.Remove(h.queue.Front())
|
||||||
|
|
|
@ -12,7 +12,6 @@ var _ = Describe("Connection ID Manager", func() {
|
||||||
m *connIDManager
|
m *connIDManager
|
||||||
frameQueue []wire.Frame
|
frameQueue []wire.Frame
|
||||||
tokenAdded *protocol.StatelessResetToken
|
tokenAdded *protocol.StatelessResetToken
|
||||||
retiredTokens []protocol.StatelessResetToken
|
|
||||||
removedTokens []protocol.StatelessResetToken
|
removedTokens []protocol.StatelessResetToken
|
||||||
)
|
)
|
||||||
initialConnID := protocol.ConnectionID{0, 0, 0, 0}
|
initialConnID := protocol.ConnectionID{0, 0, 0, 0}
|
||||||
|
@ -20,13 +19,11 @@ var _ = Describe("Connection ID Manager", func() {
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
frameQueue = nil
|
frameQueue = nil
|
||||||
tokenAdded = nil
|
tokenAdded = nil
|
||||||
retiredTokens = nil
|
|
||||||
removedTokens = nil
|
removedTokens = nil
|
||||||
m = newConnIDManager(
|
m = newConnIDManager(
|
||||||
initialConnID,
|
initialConnID,
|
||||||
func(token protocol.StatelessResetToken) { tokenAdded = &token },
|
func(token protocol.StatelessResetToken) { tokenAdded = &token },
|
||||||
func(token protocol.StatelessResetToken) { removedTokens = append(removedTokens, token) },
|
func(token protocol.StatelessResetToken) { removedTokens = append(removedTokens, token) },
|
||||||
func(token protocol.StatelessResetToken) { retiredTokens = append(retiredTokens, token) },
|
|
||||||
func(f wire.Frame,
|
func(f wire.Frame,
|
||||||
) {
|
) {
|
||||||
frameQueue = append(frameQueue, f)
|
frameQueue = append(frameQueue, f)
|
||||||
|
@ -282,8 +279,8 @@ var _ = Describe("Connection ID Manager", func() {
|
||||||
if !connID.Equal(lastConnID) {
|
if !connID.Equal(lastConnID) {
|
||||||
counter++
|
counter++
|
||||||
lastConnID = connID
|
lastConnID = connID
|
||||||
Expect(retiredTokens).To(HaveLen(1))
|
Expect(removedTokens).To(HaveLen(1))
|
||||||
retiredTokens = nil
|
removedTokens = nil
|
||||||
Expect(m.Add(&wire.NewConnectionIDFrame{
|
Expect(m.Add(&wire.NewConnectionIDFrame{
|
||||||
SequenceNumber: uint64(s),
|
SequenceNumber: uint64(s),
|
||||||
ConnectionID: protocol.ConnectionID{s, s, s, s},
|
ConnectionID: protocol.ConnectionID{s, s, s, s},
|
||||||
|
@ -344,13 +341,12 @@ var _ = Describe("Connection ID Manager", func() {
|
||||||
ConnectionID: protocol.ConnectionID{1, 3, 3, 7},
|
ConnectionID: protocol.ConnectionID{1, 3, 3, 7},
|
||||||
})).To(Succeed())
|
})).To(Succeed())
|
||||||
Expect(m.Get()).To(Equal(protocol.ConnectionID{2, 2, 2, 2}))
|
Expect(m.Get()).To(Equal(protocol.ConnectionID{2, 2, 2, 2}))
|
||||||
Expect(retiredTokens).To(HaveLen(1))
|
Expect(removedTokens).To(HaveLen(1))
|
||||||
Expect(retiredTokens[0]).To(Equal(protocol.StatelessResetToken{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}))
|
Expect(removedTokens[0]).To(Equal(protocol.StatelessResetToken{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}))
|
||||||
})
|
})
|
||||||
|
|
||||||
It("removes the currently active stateless reset token when it is closed", func() {
|
It("removes the currently active stateless reset token when it is closed", func() {
|
||||||
m.Close()
|
m.Close()
|
||||||
Expect(retiredTokens).To(BeEmpty())
|
|
||||||
Expect(removedTokens).To(BeEmpty())
|
Expect(removedTokens).To(BeEmpty())
|
||||||
Expect(m.Add(&wire.NewConnectionIDFrame{
|
Expect(m.Add(&wire.NewConnectionIDFrame{
|
||||||
SequenceNumber: 1,
|
SequenceNumber: 1,
|
||||||
|
@ -360,7 +356,6 @@ var _ = Describe("Connection ID Manager", func() {
|
||||||
m.SetHandshakeComplete()
|
m.SetHandshakeComplete()
|
||||||
Expect(m.Get()).To(Equal(protocol.ConnectionID{1, 2, 3, 4}))
|
Expect(m.Get()).To(Equal(protocol.ConnectionID{1, 2, 3, 4}))
|
||||||
m.Close()
|
m.Close()
|
||||||
Expect(retiredTokens).To(BeEmpty())
|
|
||||||
Expect(removedTokens).To(HaveLen(1))
|
Expect(removedTokens).To(HaveLen(1))
|
||||||
Expect(removedTokens[0]).To(Equal(protocol.StatelessResetToken{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}))
|
Expect(removedTokens[0]).To(Equal(protocol.StatelessResetToken{16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}))
|
||||||
})
|
})
|
||||||
|
|
|
@ -162,18 +162,6 @@ func (mr *MockPacketHandlerManagerMockRecorder) Retire(arg0 interface{}) *gomock
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Retire", reflect.TypeOf((*MockPacketHandlerManager)(nil).Retire), arg0)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Retire", reflect.TypeOf((*MockPacketHandlerManager)(nil).Retire), arg0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RetireResetToken mocks base method
|
|
||||||
func (m *MockPacketHandlerManager) RetireResetToken(arg0 protocol.StatelessResetToken) {
|
|
||||||
m.ctrl.T.Helper()
|
|
||||||
m.ctrl.Call(m, "RetireResetToken", arg0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RetireResetToken indicates an expected call of RetireResetToken
|
|
||||||
func (mr *MockPacketHandlerManagerMockRecorder) RetireResetToken(arg0 interface{}) *gomock.Call {
|
|
||||||
mr.mock.ctrl.T.Helper()
|
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RetireResetToken", reflect.TypeOf((*MockPacketHandlerManager)(nil).RetireResetToken), arg0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetServer mocks base method
|
// SetServer mocks base method
|
||||||
func (m *MockPacketHandlerManager) SetServer(arg0 unknownPacketHandler) {
|
func (m *MockPacketHandlerManager) SetServer(arg0 unknownPacketHandler) {
|
||||||
m.ctrl.T.Helper()
|
m.ctrl.T.Helper()
|
||||||
|
|
|
@ -121,15 +121,3 @@ func (mr *MockSessionRunnerMockRecorder) Retire(arg0 interface{}) *gomock.Call {
|
||||||
mr.mock.ctrl.T.Helper()
|
mr.mock.ctrl.T.Helper()
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Retire", reflect.TypeOf((*MockSessionRunner)(nil).Retire), arg0)
|
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Retire", reflect.TypeOf((*MockSessionRunner)(nil).Retire), arg0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RetireResetToken mocks base method
|
|
||||||
func (m *MockSessionRunner) RetireResetToken(arg0 protocol.StatelessResetToken) {
|
|
||||||
m.ctrl.T.Helper()
|
|
||||||
m.ctrl.Call(m, "RetireResetToken", arg0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// RetireResetToken indicates an expected call of RetireResetToken
|
|
||||||
func (mr *MockSessionRunnerMockRecorder) RetireResetToken(arg0 interface{}) *gomock.Call {
|
|
||||||
mr.mock.ctrl.T.Helper()
|
|
||||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RetireResetToken", reflect.TypeOf((*MockSessionRunner)(nil).RetireResetToken), arg0)
|
|
||||||
}
|
|
||||||
|
|
|
@ -222,14 +222,6 @@ func (h *packetHandlerMap) RemoveResetToken(token protocol.StatelessResetToken)
|
||||||
h.mutex.Unlock()
|
h.mutex.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *packetHandlerMap) RetireResetToken(token protocol.StatelessResetToken) {
|
|
||||||
time.AfterFunc(h.deleteRetiredSessionsAfter, func() {
|
|
||||||
h.mutex.Lock()
|
|
||||||
delete(h.resetTokens, token)
|
|
||||||
h.mutex.Unlock()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *packetHandlerMap) SetServer(s unknownPacketHandler) {
|
func (h *packetHandlerMap) SetServer(s unknownPacketHandler) {
|
||||||
h.mutex.Lock()
|
h.mutex.Lock()
|
||||||
h.server = s
|
h.server = s
|
||||||
|
|
|
@ -322,20 +322,19 @@ var _ = Describe("Packet Handler Map", func() {
|
||||||
Eventually(destroyed).Should(BeClosed())
|
Eventually(destroyed).Should(BeClosed())
|
||||||
})
|
})
|
||||||
|
|
||||||
It("retires reset tokens", func() {
|
It("removes reset tokens", func() {
|
||||||
handler.deleteRetiredSessionsAfter = scaleDuration(10 * time.Millisecond)
|
|
||||||
connID := protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0x42}
|
connID := protocol.ConnectionID{0xde, 0xad, 0xbe, 0xef, 0x42}
|
||||||
packetHandler := NewMockPacketHandler(mockCtrl)
|
packetHandler := NewMockPacketHandler(mockCtrl)
|
||||||
handler.Add(connID, packetHandler)
|
handler.Add(connID, packetHandler)
|
||||||
token := protocol.StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
token := protocol.StatelessResetToken{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
|
||||||
handler.AddResetToken(token, NewMockPacketHandler(mockCtrl))
|
handler.AddResetToken(token, NewMockPacketHandler(mockCtrl))
|
||||||
handler.RetireResetToken(token)
|
handler.RemoveResetToken(token)
|
||||||
|
// don't EXPECT any call to packetHandler.destroy()
|
||||||
packetHandler.EXPECT().handlePacket(gomock.Any())
|
packetHandler.EXPECT().handlePacket(gomock.Any())
|
||||||
p := append([]byte{0x40} /* short header packet */, connID.Bytes()...)
|
p := append([]byte{0x40} /* short header packet */, connID.Bytes()...)
|
||||||
p = append(p, make([]byte, 50)...)
|
p = append(p, make([]byte, 50)...)
|
||||||
p = append(p, token[:]...)
|
p = append(p, token[:]...)
|
||||||
|
|
||||||
time.Sleep(scaleDuration(30 * time.Millisecond))
|
|
||||||
handler.handlePacket(&receivedPacket{data: p})
|
handler.handlePacket(&receivedPacket{data: p})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,6 @@ type sessionRunner interface {
|
||||||
ReplaceWithClosed(protocol.ConnectionID, packetHandler)
|
ReplaceWithClosed(protocol.ConnectionID, packetHandler)
|
||||||
AddResetToken(protocol.StatelessResetToken, packetHandler)
|
AddResetToken(protocol.StatelessResetToken, packetHandler)
|
||||||
RemoveResetToken(protocol.StatelessResetToken)
|
RemoveResetToken(protocol.StatelessResetToken)
|
||||||
RetireResetToken(protocol.StatelessResetToken)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type handshakeRunner struct {
|
type handshakeRunner struct {
|
||||||
|
@ -258,7 +257,6 @@ var newSession = func(
|
||||||
destConnID,
|
destConnID,
|
||||||
func(token protocol.StatelessResetToken) { runner.AddResetToken(token, s) },
|
func(token protocol.StatelessResetToken) { runner.AddResetToken(token, s) },
|
||||||
runner.RemoveResetToken,
|
runner.RemoveResetToken,
|
||||||
runner.RetireResetToken,
|
|
||||||
s.queueControlFrame,
|
s.queueControlFrame,
|
||||||
)
|
)
|
||||||
s.connIDGenerator = newConnIDGenerator(
|
s.connIDGenerator = newConnIDGenerator(
|
||||||
|
@ -382,7 +380,6 @@ var newClientSession = func(
|
||||||
destConnID,
|
destConnID,
|
||||||
func(token protocol.StatelessResetToken) { runner.AddResetToken(token, s) },
|
func(token protocol.StatelessResetToken) { runner.AddResetToken(token, s) },
|
||||||
runner.RemoveResetToken,
|
runner.RemoveResetToken,
|
||||||
runner.RetireResetToken,
|
|
||||||
s.queueControlFrame,
|
s.queueControlFrame,
|
||||||
)
|
)
|
||||||
s.connIDGenerator = newConnIDGenerator(
|
s.connIDGenerator = newConnIDGenerator(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue