diff --git a/internal/ackhandler/sent_packet_handler_test.go b/internal/ackhandler/sent_packet_handler_test.go index 21054d4a..4808ad51 100644 --- a/internal/ackhandler/sent_packet_handler_test.go +++ b/internal/ackhandler/sent_packet_handler_test.go @@ -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))) diff --git a/internal/ackhandler/sent_packet_history.go b/internal/ackhandler/sent_packet_history.go index e8b9bd02..c5f52114 100644 --- a/internal/ackhandler/sent_packet_history.go +++ b/internal/ackhandler/sent_packet_history.go @@ -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 diff --git a/internal/ackhandler/sent_packet_history_test.go b/internal/ackhandler/sent_packet_history_test.go index c0e25d08..2506a58b 100644 --- a/internal/ackhandler/sent_packet_history_test.go +++ b/internal/ackhandler/sent_packet_history_test.go @@ -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() {