mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 20:57:36 +03:00
parent
283f75aa98
commit
a1ba23aebd
2 changed files with 39 additions and 3 deletions
|
@ -22,9 +22,11 @@ type receivedPacketHandler struct {
|
|||
highestInOrderObserved protocol.PacketNumber
|
||||
highestInOrderObservedEntropy EntropyAccumulator
|
||||
largestObserved protocol.PacketNumber
|
||||
packetHistory map[protocol.PacketNumber]packetHistoryEntry
|
||||
currentAckFrame *frames.AckFrame
|
||||
stateChanged bool // has an ACK for this state already been sent? Will be set to false every time a new packet arrives, and to false every time an ACK is sent
|
||||
|
||||
packetHistory map[protocol.PacketNumber]packetHistoryEntry
|
||||
smallestInPacketHistory protocol.PacketNumber
|
||||
}
|
||||
|
||||
// NewReceivedPacketHandler creates a new receivedPacketHandler
|
||||
|
@ -59,6 +61,9 @@ func (h *receivedPacketHandler) ReceivedPacket(packetNumber protocol.PacketNumbe
|
|||
EntropyBit: entropyBit,
|
||||
TimeReceived: time.Now(),
|
||||
}
|
||||
|
||||
h.garbageCollect()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -72,6 +77,8 @@ func (h *receivedPacketHandler) ReceivedStopWaiting(f *frames.StopWaitingFrame)
|
|||
h.highestInOrderObserved = f.LeastUnacked - 1
|
||||
h.highestInOrderObservedEntropy = EntropyAccumulator(f.Entropy)
|
||||
|
||||
h.garbageCollect()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -130,3 +137,10 @@ func (h *receivedPacketHandler) GetAckFrame(dequeue bool) (*frames.AckFrame, err
|
|||
}
|
||||
return h.currentAckFrame, nil
|
||||
}
|
||||
|
||||
func (h *receivedPacketHandler) garbageCollect() {
|
||||
for i := h.smallestInPacketHistory; i < h.highestInOrderObserved; i++ {
|
||||
delete(h.packetHistory, i)
|
||||
}
|
||||
h.smallestInPacketHistory = h.highestInOrderObserved
|
||||
}
|
||||
|
|
|
@ -25,13 +25,13 @@ var _ = Describe("receivedPacketHandler", func() {
|
|||
It("handles a packet that arrives late", func() {
|
||||
err := handler.ReceivedPacket(protocol.PacketNumber(1), false)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(handler.packetHistory).To(HaveKey(protocol.PacketNumber(1)))
|
||||
err = handler.ReceivedPacket(protocol.PacketNumber(3), false)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(handler.packetHistory).To(HaveKey(protocol.PacketNumber(3)))
|
||||
err = handler.ReceivedPacket(protocol.PacketNumber(2), false)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(handler.packetHistory).To(HaveKey(protocol.PacketNumber(1)))
|
||||
Expect(handler.packetHistory).To(HaveKey(protocol.PacketNumber(2)))
|
||||
Expect(handler.packetHistory).To(HaveKey(protocol.PacketNumber(3)))
|
||||
})
|
||||
|
||||
It("rejects packets with packet number 0", func() {
|
||||
|
@ -334,4 +334,26 @@ var _ = Describe("receivedPacketHandler", func() {
|
|||
Expect(ack.NackRanges).To(BeEmpty())
|
||||
})
|
||||
})
|
||||
|
||||
Context("Garbage Collector", func() {
|
||||
It("only keeps packets with packet numbers higher than the highestInOrderObserved in packetHistory", func() {
|
||||
handler.ReceivedPacket(1, true)
|
||||
handler.ReceivedPacket(2, true)
|
||||
handler.ReceivedPacket(4, true)
|
||||
Expect(handler.packetHistory).ToNot(HaveKey(protocol.PacketNumber(1)))
|
||||
Expect(handler.packetHistory).To(HaveKey(protocol.PacketNumber(2)))
|
||||
Expect(handler.packetHistory).To(HaveKey(protocol.PacketNumber(4)))
|
||||
})
|
||||
|
||||
It("garbage collects packetHistory after receiving a StopWaiting", func() {
|
||||
handler.ReceivedPacket(1, true)
|
||||
handler.ReceivedPacket(2, true)
|
||||
handler.ReceivedPacket(4, true)
|
||||
swf := frames.StopWaitingFrame{LeastUnacked: 4}
|
||||
handler.ReceivedStopWaiting(&swf)
|
||||
Expect(handler.packetHistory).ToNot(HaveKey(protocol.PacketNumber(1)))
|
||||
Expect(handler.packetHistory).ToNot(HaveKey(protocol.PacketNumber(2)))
|
||||
Expect(handler.packetHistory).To(HaveKey(protocol.PacketNumber(4)))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue