also pass non-ack-eliciting packets to packet history (but don't save)

This commit is contained in:
Marten Seemann 2020-09-07 16:40:44 +07:00
parent 74f2610349
commit 0044a69d73
4 changed files with 33 additions and 32 deletions

View file

@ -209,9 +209,7 @@ func (h *sentPacketHandler) SentPacket(packet *Packet) {
h.dropPackets(protocol.EncryptionInitial)
}
isAckEliciting := h.sentPacketImpl(packet)
if isAckEliciting {
h.getPacketNumberSpace(packet.EncryptionLevel).history.SentPacket(packet)
}
h.getPacketNumberSpace(packet.EncryptionLevel).history.SentPacket(packet, isAckEliciting)
if h.tracer != nil && isAckEliciting {
h.tracer.UpdatedMetrics(h.rttStats, h.congestion.GetCongestionWindow(), h.bytesInFlight, h.packetsInFlight())
}

View file

@ -141,13 +141,6 @@ var _ = Describe("SentPacketHandler", func() {
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: 2, SendTime: sendTime.Add(time.Hour), EncryptionLevel: protocol.Encryption1RTT}))
Expect(handler.initialPackets.lastAckElicitingPacketTime).To(Equal(sendTime))
})
It("does not store non-ack-eliciting packets", func() {
handler.SentPacket(nonAckElicitingPacket(&Packet{PacketNumber: 1}))
Expect(handler.appDataPackets.history.Len()).To(BeZero())
Expect(handler.appDataPackets.lastAckElicitingPacketTime).To(BeZero())
Expect(handler.bytesInFlight).To(BeZero())
})
})
Context("ACK processing", func() {

View file

@ -22,7 +22,10 @@ func newSentPacketHistory(rttStats *utils.RTTStats) *sentPacketHistory {
}
}
func (h *sentPacketHistory) SentPacket(p *Packet) {
func (h *sentPacketHistory) SentPacket(p *Packet, isAckEliciting bool) {
if !isAckEliciting {
return
}
el := h.packetList.PushBack(*p)
h.packetMap[p.PacketNumber] = el
}

View file

@ -37,15 +37,22 @@ var _ = Describe("SentPacketHistory", func() {
})
It("saves sent packets", func() {
hist.SentPacket(&Packet{PacketNumber: 1})
hist.SentPacket(&Packet{PacketNumber: 3})
hist.SentPacket(&Packet{PacketNumber: 4})
hist.SentPacket(&Packet{PacketNumber: 1}, true)
hist.SentPacket(&Packet{PacketNumber: 3}, true)
hist.SentPacket(&Packet{PacketNumber: 4}, true)
expectInHistory([]protocol.PacketNumber{1, 3, 4})
})
It("doesn't save non-ack-eliciting packets", func() {
hist.SentPacket(&Packet{PacketNumber: 1}, true)
hist.SentPacket(&Packet{PacketNumber: 3}, false)
hist.SentPacket(&Packet{PacketNumber: 4}, true)
expectInHistory([]protocol.PacketNumber{1, 4})
})
It("gets the length", func() {
hist.SentPacket(&Packet{PacketNumber: 1})
hist.SentPacket(&Packet{PacketNumber: 10})
hist.SentPacket(&Packet{PacketNumber: 1}, true)
hist.SentPacket(&Packet{PacketNumber: 10}, true)
Expect(hist.Len()).To(Equal(2))
})
@ -55,8 +62,8 @@ var _ = Describe("SentPacketHistory", func() {
})
It("gets the first outstanding packet", func() {
hist.SentPacket(&Packet{PacketNumber: 2})
hist.SentPacket(&Packet{PacketNumber: 3})
hist.SentPacket(&Packet{PacketNumber: 2}, true)
hist.SentPacket(&Packet{PacketNumber: 3}, true)
front := hist.FirstOutstanding()
Expect(front).ToNot(BeNil())
Expect(front.PacketNumber).To(Equal(protocol.PacketNumber(2)))
@ -64,25 +71,25 @@ var _ = Describe("SentPacketHistory", func() {
})
It("removes packets", func() {
hist.SentPacket(&Packet{PacketNumber: 1})
hist.SentPacket(&Packet{PacketNumber: 4})
hist.SentPacket(&Packet{PacketNumber: 8})
hist.SentPacket(&Packet{PacketNumber: 1}, true)
hist.SentPacket(&Packet{PacketNumber: 4}, true)
hist.SentPacket(&Packet{PacketNumber: 8}, true)
err := hist.Remove(4)
Expect(err).ToNot(HaveOccurred())
expectInHistory([]protocol.PacketNumber{1, 8})
})
It("errors when trying to remove a non existing packet", func() {
hist.SentPacket(&Packet{PacketNumber: 1})
hist.SentPacket(&Packet{PacketNumber: 1}, true)
err := hist.Remove(2)
Expect(err).To(MatchError("packet 2 not found in sent packet history"))
})
Context("iterating", func() {
BeforeEach(func() {
hist.SentPacket(&Packet{PacketNumber: 10})
hist.SentPacket(&Packet{PacketNumber: 14})
hist.SentPacket(&Packet{PacketNumber: 18})
hist.SentPacket(&Packet{PacketNumber: 10}, true)
hist.SentPacket(&Packet{PacketNumber: 14}, true)
hist.SentPacket(&Packet{PacketNumber: 18}, true)
})
It("iterates over all packets", func() {
@ -133,7 +140,7 @@ var _ = Describe("SentPacketHistory", func() {
Context("outstanding packets", func() {
It("says if it has outstanding packets", func() {
Expect(hist.HasOutstandingPackets()).To(BeFalse())
hist.SentPacket(&Packet{EncryptionLevel: protocol.Encryption1RTT})
hist.SentPacket(&Packet{EncryptionLevel: protocol.Encryption1RTT}, true)
Expect(hist.HasOutstandingPackets()).To(BeTrue())
})
@ -141,7 +148,7 @@ var _ = Describe("SentPacketHistory", func() {
hist.SentPacket(&Packet{
PacketNumber: 10,
EncryptionLevel: protocol.Encryption1RTT,
})
}, true)
Expect(hist.HasOutstandingPackets()).To(BeTrue())
Expect(hist.Remove(10)).To(Succeed())
Expect(hist.HasOutstandingPackets()).To(BeFalse())
@ -151,11 +158,11 @@ var _ = Describe("SentPacketHistory", func() {
hist.SentPacket(&Packet{
PacketNumber: 10,
EncryptionLevel: protocol.Encryption1RTT,
})
}, true)
hist.SentPacket(&Packet{
PacketNumber: 11,
EncryptionLevel: protocol.Encryption1RTT,
})
}, true)
Expect(hist.Remove(11)).To(Succeed())
Expect(hist.HasOutstandingPackets()).To(BeTrue())
Expect(hist.Remove(10)).To(Succeed())
@ -173,7 +180,7 @@ var _ = Describe("SentPacketHistory", func() {
It("deletes old packets after 3 PTOs", func() {
now := time.Now()
hist.SentPacket(&Packet{PacketNumber: 10, SendTime: now.Add(-3 * pto), declaredLost: true})
hist.SentPacket(&Packet{PacketNumber: 10, SendTime: now.Add(-3 * pto), declaredLost: true}, true)
Expect(hist.Len()).To(Equal(1))
hist.DeleteOldPackets(now.Add(-time.Nanosecond))
Expect(hist.Len()).To(Equal(1))
@ -183,8 +190,8 @@ var _ = Describe("SentPacketHistory", func() {
It("doesn't delete a packet if it hasn't been declared lost yet", func() {
now := time.Now()
hist.SentPacket(&Packet{PacketNumber: 10, SendTime: now.Add(-3 * pto), declaredLost: true})
hist.SentPacket(&Packet{PacketNumber: 11, SendTime: now.Add(-3 * pto), declaredLost: false})
hist.SentPacket(&Packet{PacketNumber: 10, SendTime: now.Add(-3 * pto), declaredLost: true}, true)
hist.SentPacket(&Packet{PacketNumber: 11, SendTime: now.Add(-3 * pto), declaredLost: false}, true)
Expect(hist.Len()).To(Equal(2))
hist.DeleteOldPackets(now)
Expect(hist.Len()).To(Equal(1))