Skip to content

Commit

Permalink
reset the loss detection timer when the client's address is validated
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Apr 2, 2021
1 parent a695bae commit b6634fe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
24 changes: 15 additions & 9 deletions internal/ackhandler/sent_packet_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,10 @@ func (h *sentPacketHandler) ReceivedBytes(n protocol.ByteCount) {
}
}

func (h *sentPacketHandler) ReceivedPacket(encLevel protocol.EncryptionLevel) {
if h.perspective == protocol.PerspectiveServer && encLevel == protocol.EncryptionHandshake {
func (h *sentPacketHandler) ReceivedPacket(l protocol.EncryptionLevel) {
if h.perspective == protocol.PerspectiveServer && l == protocol.EncryptionHandshake && !h.peerAddressValidated {
h.peerAddressValidated = true
h.setLossDetectionTimer()
}
}

Expand Down Expand Up @@ -485,7 +486,8 @@ func (h *sentPacketHandler) hasOutstandingPackets() bool {

func (h *sentPacketHandler) setLossDetectionTimer() {
oldAlarm := h.alarm // only needed in case tracing is enabled
if lossTime, encLevel := h.getLossTimeAndSpace(); !lossTime.IsZero() {
lossTime, encLevel := h.getLossTimeAndSpace()
if !lossTime.IsZero() {
// Early retransmit timer or time loss detection.
h.alarm = lossTime
if h.tracer != nil && h.alarm != oldAlarm {
Expand All @@ -497,19 +499,23 @@ func (h *sentPacketHandler) setLossDetectionTimer() {
// Cancel the alarm if amplification limited.
if h.isAmplificationLimited() {
h.alarm = time.Time{}
h.logger.Debugf("Canceling loss detection timer. Amplification limited.")
if h.tracer != nil && !oldAlarm.IsZero() {
h.tracer.LossTimerCanceled()
if !oldAlarm.IsZero() {
h.logger.Debugf("Canceling loss detection timer. Amplification limited.")
if h.tracer != nil {
h.tracer.LossTimerCanceled()
}
}
return
}

// Cancel the alarm if no packets are outstanding
if !h.hasOutstandingPackets() && h.peerCompletedAddressValidation {
h.alarm = time.Time{}
h.logger.Debugf("Canceling loss detection timer. No packets in flight.")
if h.tracer != nil && !oldAlarm.IsZero() {
h.tracer.LossTimerCanceled()
if !oldAlarm.IsZero() {
h.logger.Debugf("Canceling loss detection timer. No packets in flight.")
if h.tracer != nil {
h.tracer.LossTimerCanceled()
}
}
return
}
Expand Down
15 changes: 15 additions & 0 deletions internal/ackhandler/sent_packet_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,21 @@ var _ = Describe("SentPacketHandler", func() {
handler.ReceivedBytes(1)
Expect(handler.GetLossDetectionTimeout()).ToNot(BeZero())
})

It("resets the loss detection timer when the client's address is validated", func() {
handler.ReceivedBytes(300)
handler.SentPacket(&Packet{
PacketNumber: 1,
Length: 900,
EncryptionLevel: protocol.EncryptionHandshake,
Frames: []Frame{{Frame: &wire.PingFrame{}}},
SendTime: time.Now(),
})
// Amplification limited. We don't need to set a timer now.
Expect(handler.GetLossDetectionTimeout()).To(BeZero())
handler.ReceivedPacket(protocol.EncryptionHandshake)
Expect(handler.GetLossDetectionTimeout()).ToNot(BeZero())
})
})

Context("amplification limit, for the client", func() {
Expand Down

0 comments on commit b6634fe

Please sign in to comment.