fix dropping of 0-RTT packets

This commit is contained in:
Marten Seemann 2020-09-07 12:42:33 +07:00
parent bed802aee5
commit ad40c9cc83
3 changed files with 23 additions and 14 deletions

View file

@ -1036,7 +1036,7 @@ var _ = Describe("SentPacketHandler", func() {
EncryptionLevel: protocol.Encryption0RTT,
}))
}
for i := protocol.PacketNumber(0); i < 6; i++ {
for i := protocol.PacketNumber(6); i < 12; i++ {
handler.SentPacket(ackElicitingPacket(&Packet{PacketNumber: i}))
}
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(12)))

View file

@ -31,11 +31,12 @@ func (h *sentPacketHistory) GetPacket(p protocol.PacketNumber) *Packet {
}
// Iterate iterates through all packets.
// The callback must not modify the history.
func (h *sentPacketHistory) Iterate(cb func(*Packet) (cont bool, err error)) error {
cont := true
for el := h.packetList.Front(); cont && el != nil; el = el.Next() {
var next *PacketElement
for el := h.packetList.Front(); cont && el != nil; el = next {
var err error
next = el.Next()
cont, err = cb(&el.Value)
if err != nil {
return err
@ -45,8 +46,6 @@ func (h *sentPacketHistory) Iterate(cb func(*Packet) (cont bool, err error)) err
}
// FirstOutStanding returns the first outstanding packet.
// It must not be modified (e.g. retransmitted).
// Use DequeueFirstPacketForRetransmission() to retransmit it.
func (h *sentPacketHistory) FirstOutstanding() *Packet {
if !h.HasOutstandingPackets() {
return nil

View file

@ -90,37 +90,47 @@ var _ = Describe("SentPacketHistory", func() {
It("iterates over all packets", func() {
var iterations []protocol.PacketNumber
err := hist.Iterate(func(p *Packet) (bool, error) {
Expect(hist.Iterate(func(p *Packet) (bool, error) {
iterations = append(iterations, p.PacketNumber)
return true, nil
})
Expect(err).ToNot(HaveOccurred())
})).To(Succeed())
Expect(iterations).To(Equal([]protocol.PacketNumber{10, 14, 18}))
})
It("stops iterating", func() {
var iterations []protocol.PacketNumber
err := hist.Iterate(func(p *Packet) (bool, error) {
Expect(hist.Iterate(func(p *Packet) (bool, error) {
iterations = append(iterations, p.PacketNumber)
return p.PacketNumber != 14, nil
})
Expect(err).ToNot(HaveOccurred())
})).To(Succeed())
Expect(iterations).To(Equal([]protocol.PacketNumber{10, 14}))
})
It("returns the error", func() {
testErr := errors.New("test error")
var iterations []protocol.PacketNumber
err := hist.Iterate(func(p *Packet) (bool, error) {
Expect(hist.Iterate(func(p *Packet) (bool, error) {
iterations = append(iterations, p.PacketNumber)
if p.PacketNumber == 14 {
return false, testErr
}
return true, nil
})
Expect(err).To(MatchError(testErr))
})).To(MatchError(testErr))
Expect(iterations).To(Equal([]protocol.PacketNumber{10, 14}))
})
It("allows deletions", func() {
var iterations []protocol.PacketNumber
Expect(hist.Iterate(func(p *Packet) (bool, error) {
iterations = append(iterations, p.PacketNumber)
if p.PacketNumber == 14 {
Expect(hist.Remove(14)).To(Succeed())
}
return true, nil
})).To(Succeed())
expectInHistory([]protocol.PacketNumber{10, 18})
Expect(iterations).To(Equal([]protocol.PacketNumber{10, 14, 18}))
})
})
Context("outstanding packets", func() {