ackhandler: simplify sentPacketHandler.SentPacket (#3847)

No functional change expected.
This commit is contained in:
Marten Seemann 2023-06-02 12:59:46 +03:00 committed by GitHub
parent 1c3292d120
commit 215ba85db4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -234,11 +234,31 @@ func (h *sentPacketHandler) SentPacket(p *Packet) {
if h.perspective == protocol.PerspectiveClient && p.EncryptionLevel == protocol.EncryptionHandshake && h.initialPackets != nil {
h.dropPackets(protocol.EncryptionInitial)
}
isAckEliciting := h.sentPacketImpl(p)
pnSpace := h.getPacketNumberSpace(p.EncryptionLevel)
if h.logger.Debug() && pnSpace.history.HasOutstandingPackets() {
for pn := utils.Max(0, pnSpace.largestSent+1); pn < p.PacketNumber; pn++ {
h.logger.Debugf("Skipping packet number %d", pn)
}
}
pnSpace.largestSent = p.PacketNumber
isAckEliciting := len(p.Frames) > 0
if isAckEliciting {
h.getPacketNumberSpace(p.EncryptionLevel).history.SentAckElicitingPacket(p)
pnSpace.lastAckElicitingPacketTime = p.SendTime
p.includedInBytesInFlight = true
h.bytesInFlight += p.Length
if h.numProbesToSend > 0 {
h.numProbesToSend--
}
}
h.congestion.OnPacketSent(p.SendTime, h.bytesInFlight, p.PacketNumber, p.Length, isAckEliciting)
if isAckEliciting {
pnSpace.history.SentAckElicitingPacket(p)
} else {
h.getPacketNumberSpace(p.EncryptionLevel).history.SentNonAckElicitingPacket(p.PacketNumber, p.EncryptionLevel, p.SendTime)
pnSpace.history.SentNonAckElicitingPacket(p.PacketNumber, p.EncryptionLevel, p.SendTime)
putPacket(p)
p = nil //nolint:ineffassign // This is just to be on the safe side.
}
@ -263,31 +283,6 @@ func (h *sentPacketHandler) getPacketNumberSpace(encLevel protocol.EncryptionLev
}
}
func (h *sentPacketHandler) sentPacketImpl(packet *Packet) bool /* is ack-eliciting */ {
pnSpace := h.getPacketNumberSpace(packet.EncryptionLevel)
if h.logger.Debug() && pnSpace.history.HasOutstandingPackets() {
for p := utils.Max(0, pnSpace.largestSent+1); p < packet.PacketNumber; p++ {
h.logger.Debugf("Skipping packet number %d", p)
}
}
pnSpace.largestSent = packet.PacketNumber
isAckEliciting := len(packet.Frames) > 0
if isAckEliciting {
pnSpace.lastAckElicitingPacketTime = packet.SendTime
packet.includedInBytesInFlight = true
h.bytesInFlight += packet.Length
if h.numProbesToSend > 0 {
h.numProbesToSend--
}
}
h.congestion.OnPacketSent(packet.SendTime, h.bytesInFlight, packet.PacketNumber, packet.Length, isAckEliciting)
return isAckEliciting
}
func (h *sentPacketHandler) ReceivedAck(ack *wire.AckFrame, encLevel protocol.EncryptionLevel, rcvTime time.Time) (bool /* contained 1-RTT packet */, error) {
pnSpace := h.getPacketNumberSpace(encLevel)