ackhandler: remove error return value of SentPacketHandler.ResetForRetry (#4834)

This commit is contained in:
Marten Seemann 2025-01-06 15:05:19 +08:00 committed by GitHub
parent f41a6a644d
commit d87e2bb649
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 14 additions and 23 deletions

View file

@ -1086,10 +1086,7 @@ func (s *connection) handleRetryPacket(hdr *wire.Header, data []byte, rcvTime ti
newDestConnID := hdr.SrcConnectionID newDestConnID := hdr.SrcConnectionID
s.receivedRetry = true s.receivedRetry = true
if err := s.sentPacketHandler.ResetForRetry(rcvTime); err != nil { s.sentPacketHandler.ResetForRetry(rcvTime)
s.closeLocal(err)
return false
}
s.handshakeDestConnID = newDestConnID s.handshakeDestConnID = newDestConnID
s.retrySrcConnID = &newDestConnID s.retrySrcConnID = &newDestConnID
s.cryptoStreamHandler.ChangeConnectionID(newDestConnID) s.cryptoStreamHandler.ChangeConnectionID(newDestConnID)

View file

@ -16,7 +16,7 @@ type SentPacketHandler interface {
ReceivedAck(f *wire.AckFrame, encLevel protocol.EncryptionLevel, rcvTime time.Time) (bool /* 1-RTT packet acked */, error) ReceivedAck(f *wire.AckFrame, encLevel protocol.EncryptionLevel, rcvTime time.Time) (bool /* 1-RTT packet acked */, error)
ReceivedBytes(protocol.ByteCount) ReceivedBytes(protocol.ByteCount)
DropPackets(protocol.EncryptionLevel) DropPackets(protocol.EncryptionLevel)
ResetForRetry(rcvTime time.Time) error ResetForRetry(rcvTime time.Time)
SetHandshakeConfirmed() SetHandshakeConfirmed()
// The SendMode determines if and what kind of packets can be sent. // The SendMode determines if and what kind of packets can be sent.

View file

@ -864,7 +864,7 @@ func (h *sentPacketHandler) queueFramesForRetransmission(p *packet) {
p.Frames = nil p.Frames = nil
} }
func (h *sentPacketHandler) ResetForRetry(now time.Time) error { func (h *sentPacketHandler) ResetForRetry(now time.Time) {
h.bytesInFlight = 0 h.bytesInFlight = 0
var firstPacketSendTime time.Time var firstPacketSendTime time.Time
h.initialPackets.history.Iterate(func(p *packet) (bool, error) { h.initialPackets.history.Iterate(func(p *packet) (bool, error) {
@ -911,7 +911,6 @@ func (h *sentPacketHandler) ResetForRetry(now time.Time) error {
} }
} }
h.ptoCount = 0 h.ptoCount = 0
return nil
} }
func (h *sentPacketHandler) SetHandshakeConfirmed() { func (h *sentPacketHandler) SetHandshakeConfirmed() {

View file

@ -1325,16 +1325,13 @@ var _ = Describe("SentPacketHandler", func() {
perspective = protocol.PerspectiveClient perspective = protocol.PerspectiveClient
}) })
It("considers the server's address validated right away", func() {
})
It("queues outstanding packets for retransmission, cancels alarms and resets PTO count when receiving a Retry", func() { It("queues outstanding packets for retransmission, cancels alarms and resets PTO count when receiving a Retry", func() {
sentPacket(initialPacket(&packet{PacketNumber: 42})) sentPacket(initialPacket(&packet{PacketNumber: 42}))
Expect(handler.GetLossDetectionTimeout()).ToNot(BeZero()) Expect(handler.GetLossDetectionTimeout()).ToNot(BeZero())
Expect(handler.bytesInFlight).ToNot(BeZero()) Expect(handler.bytesInFlight).ToNot(BeZero())
Expect(handler.SendMode(time.Now())).To(Equal(SendAny)) Expect(handler.SendMode(time.Now())).To(Equal(SendAny))
// now receive a Retry // now receive a Retry
Expect(handler.ResetForRetry(time.Now())).To(Succeed()) handler.ResetForRetry(time.Now())
Expect(lostPackets).To(Equal([]protocol.PacketNumber{42})) Expect(lostPackets).To(Equal([]protocol.PacketNumber{42}))
Expect(handler.bytesInFlight).To(BeZero()) Expect(handler.bytesInFlight).To(BeZero())
Expect(handler.GetLossDetectionTimeout()).To(BeZero()) Expect(handler.GetLossDetectionTimeout()).To(BeZero())
@ -1369,7 +1366,7 @@ var _ = Describe("SentPacketHandler", func() {
}) })
Expect(handler.bytesInFlight).ToNot(BeZero()) Expect(handler.bytesInFlight).ToNot(BeZero())
// now receive a Retry // now receive a Retry
Expect(handler.ResetForRetry(time.Now())).To(Succeed()) handler.ResetForRetry(time.Now())
Expect(handler.bytesInFlight).To(BeZero()) Expect(handler.bytesInFlight).To(BeZero())
Expect(lostInitial).To(BeTrue()) Expect(lostInitial).To(BeTrue())
Expect(lost0RTT).To(BeTrue()) Expect(lost0RTT).To(BeTrue())
@ -1390,7 +1387,7 @@ var _ = Describe("SentPacketHandler", func() {
EncryptionLevel: protocol.EncryptionInitial, EncryptionLevel: protocol.EncryptionInitial,
SendTime: now.Add(500 * time.Millisecond), SendTime: now.Add(500 * time.Millisecond),
})) }))
Expect(handler.ResetForRetry(now.Add(time.Second))).To(Succeed()) handler.ResetForRetry(now.Add(time.Second))
Expect(handler.rttStats.SmoothedRTT()).To(Equal(time.Second)) Expect(handler.rttStats.SmoothedRTT()).To(Equal(time.Second))
}) })
@ -1406,7 +1403,7 @@ var _ = Describe("SentPacketHandler", func() {
EncryptionLevel: protocol.EncryptionInitial, EncryptionLevel: protocol.EncryptionInitial,
SendTime: now.Add(2 * time.Millisecond), SendTime: now.Add(2 * time.Millisecond),
})) }))
Expect(handler.ResetForRetry(now.Add(4 * time.Millisecond))).To(Succeed()) handler.ResetForRetry(now.Add(4 * time.Millisecond))
Expect(minRTTAfterRetry).To(BeNumerically(">", 4*time.Millisecond)) Expect(minRTTAfterRetry).To(BeNumerically(">", 4*time.Millisecond))
Expect(handler.rttStats.SmoothedRTT()).To(Equal(minRTTAfterRetry)) Expect(handler.rttStats.SmoothedRTT()).To(Equal(minRTTAfterRetry))
}) })
@ -1425,7 +1422,7 @@ var _ = Describe("SentPacketHandler", func() {
EncryptionLevel: protocol.EncryptionInitial, EncryptionLevel: protocol.EncryptionInitial,
SendTime: now.Add(500 * time.Millisecond), SendTime: now.Add(500 * time.Millisecond),
})) }))
Expect(handler.ResetForRetry(now.Add(time.Second))).To(Succeed()) handler.ResetForRetry(now.Add(time.Second))
Expect(handler.rttStats.SmoothedRTT()).To(BeZero()) Expect(handler.rttStats.SmoothedRTT()).To(BeZero())
}) })
}) })

View file

@ -384,11 +384,9 @@ func (c *MockSentPacketHandlerReceivedBytesCall) DoAndReturn(f func(protocol.Byt
} }
// ResetForRetry mocks base method. // ResetForRetry mocks base method.
func (m *MockSentPacketHandler) ResetForRetry(rcvTime time.Time) error { func (m *MockSentPacketHandler) ResetForRetry(rcvTime time.Time) {
m.ctrl.T.Helper() m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ResetForRetry", rcvTime) m.ctrl.Call(m, "ResetForRetry", rcvTime)
ret0, _ := ret[0].(error)
return ret0
} }
// ResetForRetry indicates an expected call of ResetForRetry. // ResetForRetry indicates an expected call of ResetForRetry.
@ -404,19 +402,19 @@ type MockSentPacketHandlerResetForRetryCall struct {
} }
// Return rewrite *gomock.Call.Return // Return rewrite *gomock.Call.Return
func (c *MockSentPacketHandlerResetForRetryCall) Return(arg0 error) *MockSentPacketHandlerResetForRetryCall { func (c *MockSentPacketHandlerResetForRetryCall) Return() *MockSentPacketHandlerResetForRetryCall {
c.Call = c.Call.Return(arg0) c.Call = c.Call.Return()
return c return c
} }
// Do rewrite *gomock.Call.Do // Do rewrite *gomock.Call.Do
func (c *MockSentPacketHandlerResetForRetryCall) Do(f func(time.Time) error) *MockSentPacketHandlerResetForRetryCall { func (c *MockSentPacketHandlerResetForRetryCall) Do(f func(time.Time)) *MockSentPacketHandlerResetForRetryCall {
c.Call = c.Call.Do(f) c.Call = c.Call.Do(f)
return c return c
} }
// DoAndReturn rewrite *gomock.Call.DoAndReturn // DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockSentPacketHandlerResetForRetryCall) DoAndReturn(f func(time.Time) error) *MockSentPacketHandlerResetForRetryCall { func (c *MockSentPacketHandlerResetForRetryCall) DoAndReturn(f func(time.Time)) *MockSentPacketHandlerResetForRetryCall {
c.Call = c.Call.DoAndReturn(f) c.Call = c.Call.DoAndReturn(f)
return c return c
} }