rename the receivedPacketHandler to receivedPacketTracker

This commit is contained in:
Marten Seemann 2019-01-09 11:30:50 +07:00
parent 5ccc367462
commit 258e43ab95
3 changed files with 135 additions and 134 deletions

View file

@ -8,6 +8,7 @@ import (
)
// The receivedPacketHistory stores if a packet number has already been received.
// It generates ACK ranges which can be used to assemble an ACK frame.
// It does not store packet contents.
type receivedPacketHistory struct {
ranges *utils.PacketIntervalList

View file

@ -9,7 +9,7 @@ import (
"github.com/lucas-clemente/quic-go/internal/wire"
)
type receivedPacketHandler struct {
type receivedPacketTracker struct {
largestObserved protocol.PacketNumber
ignoreBelow protocol.PacketNumber
largestObservedReceivedTime time.Time
@ -59,7 +59,7 @@ func NewReceivedPacketHandler(
logger utils.Logger,
version protocol.VersionNumber,
) ReceivedPacketHandler {
return &receivedPacketHandler{
return &receivedPacketTracker{
packetHistory: newReceivedPacketHistory(),
ackSendDelay: ackSendDelay,
rttStats: rttStats,
@ -68,7 +68,7 @@ func NewReceivedPacketHandler(
}
}
func (h *receivedPacketHandler) ReceivedPacket(packetNumber protocol.PacketNumber, rcvTime time.Time, shouldInstigateAck bool) error {
func (h *receivedPacketTracker) ReceivedPacket(packetNumber protocol.PacketNumber, rcvTime time.Time, shouldInstigateAck bool) error {
if packetNumber < h.ignoreBelow {
return nil
}
@ -88,7 +88,7 @@ func (h *receivedPacketHandler) ReceivedPacket(packetNumber protocol.PacketNumbe
// IgnoreBelow sets a lower limit for acking packets.
// Packets with packet numbers smaller than p will not be acked.
func (h *receivedPacketHandler) IgnoreBelow(p protocol.PacketNumber) {
func (h *receivedPacketTracker) IgnoreBelow(p protocol.PacketNumber) {
if p <= h.ignoreBelow {
return
}
@ -100,14 +100,14 @@ func (h *receivedPacketHandler) IgnoreBelow(p protocol.PacketNumber) {
}
// isMissing says if a packet was reported missing in the last ACK.
func (h *receivedPacketHandler) isMissing(p protocol.PacketNumber) bool {
func (h *receivedPacketTracker) isMissing(p protocol.PacketNumber) bool {
if h.lastAck == nil || p < h.ignoreBelow {
return false
}
return p < h.lastAck.LargestAcked() && !h.lastAck.AcksPacket(p)
}
func (h *receivedPacketHandler) hasNewMissingPackets() bool {
func (h *receivedPacketTracker) hasNewMissingPackets() bool {
if h.lastAck == nil {
return false
}
@ -118,7 +118,7 @@ func (h *receivedPacketHandler) hasNewMissingPackets() bool {
// maybeQueueAck queues an ACK, if necessary.
// It is implemented analogously to Chrome's QuicConnection::MaybeQueueAck()
// in ACK_DECIMATION_WITH_REORDERING mode.
func (h *receivedPacketHandler) maybeQueueAck(packetNumber protocol.PacketNumber, rcvTime time.Time, shouldInstigateAck, wasMissing bool) {
func (h *receivedPacketTracker) maybeQueueAck(packetNumber protocol.PacketNumber, rcvTime time.Time, shouldInstigateAck, wasMissing bool) {
h.packetsReceivedSinceLastAck++
// always ack the first packet
@ -190,7 +190,7 @@ func (h *receivedPacketHandler) maybeQueueAck(packetNumber protocol.PacketNumber
}
}
func (h *receivedPacketHandler) GetAckFrame() *wire.AckFrame {
func (h *receivedPacketTracker) GetAckFrame() *wire.AckFrame {
now := time.Now()
if !h.ackQueued && (h.ackAlarm.IsZero() || h.ackAlarm.After(now)) {
return nil
@ -212,4 +212,4 @@ func (h *receivedPacketHandler) GetAckFrame() *wire.AckFrame {
return ack
}
func (h *receivedPacketHandler) GetAlarmTimeout() time.Time { return h.ackAlarm }
func (h *receivedPacketTracker) GetAlarmTimeout() time.Time { return h.ackAlarm }

View file

@ -12,58 +12,58 @@ import (
. "github.com/onsi/gomega"
)
var _ = Describe("receivedPacketHandler", func() {
var _ = Describe("Received Packet Tracker", func() {
var (
handler *receivedPacketHandler
tracker *receivedPacketTracker
rttStats *congestion.RTTStats
)
BeforeEach(func() {
rttStats = &congestion.RTTStats{}
handler = NewReceivedPacketHandler(rttStats, utils.DefaultLogger, protocol.VersionWhatever).(*receivedPacketHandler)
tracker = NewReceivedPacketHandler(rttStats, utils.DefaultLogger, protocol.VersionWhatever).(*receivedPacketTracker)
})
Context("accepting packets", func() {
It("handles a packet that arrives late", func() {
err := handler.ReceivedPacket(protocol.PacketNumber(1), time.Time{}, true)
err := tracker.ReceivedPacket(protocol.PacketNumber(1), time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(protocol.PacketNumber(3), time.Time{}, true)
err = tracker.ReceivedPacket(protocol.PacketNumber(3), time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(protocol.PacketNumber(2), time.Time{}, true)
err = tracker.ReceivedPacket(protocol.PacketNumber(2), time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
})
It("saves the time when each packet arrived", func() {
err := handler.ReceivedPacket(protocol.PacketNumber(3), time.Now(), true)
err := tracker.ReceivedPacket(protocol.PacketNumber(3), time.Now(), true)
Expect(err).ToNot(HaveOccurred())
Expect(handler.largestObservedReceivedTime).To(BeTemporally("~", time.Now(), 10*time.Millisecond))
Expect(tracker.largestObservedReceivedTime).To(BeTemporally("~", time.Now(), 10*time.Millisecond))
})
It("updates the largestObserved and the largestObservedReceivedTime", func() {
now := time.Now()
handler.largestObserved = 3
handler.largestObservedReceivedTime = now.Add(-1 * time.Second)
err := handler.ReceivedPacket(5, now, true)
tracker.largestObserved = 3
tracker.largestObservedReceivedTime = now.Add(-1 * time.Second)
err := tracker.ReceivedPacket(5, now, true)
Expect(err).ToNot(HaveOccurred())
Expect(handler.largestObserved).To(Equal(protocol.PacketNumber(5)))
Expect(handler.largestObservedReceivedTime).To(Equal(now))
Expect(tracker.largestObserved).To(Equal(protocol.PacketNumber(5)))
Expect(tracker.largestObservedReceivedTime).To(Equal(now))
})
It("doesn't update the largestObserved and the largestObservedReceivedTime for a belated packet", func() {
now := time.Now()
timestamp := now.Add(-1 * time.Second)
handler.largestObserved = 5
handler.largestObservedReceivedTime = timestamp
err := handler.ReceivedPacket(4, now, true)
tracker.largestObserved = 5
tracker.largestObservedReceivedTime = timestamp
err := tracker.ReceivedPacket(4, now, true)
Expect(err).ToNot(HaveOccurred())
Expect(handler.largestObserved).To(Equal(protocol.PacketNumber(5)))
Expect(handler.largestObservedReceivedTime).To(Equal(timestamp))
Expect(tracker.largestObserved).To(Equal(protocol.PacketNumber(5)))
Expect(tracker.largestObservedReceivedTime).To(Equal(timestamp))
})
It("passes on errors from receivedPacketHistory", func() {
var err error
for i := protocol.PacketNumber(0); i < 5*protocol.MaxTrackedReceivedAckRanges; i++ {
err = handler.ReceivedPacket(2*i+1, time.Time{}, true)
err = tracker.ReceivedPacket(2*i+1, time.Time{}, true)
// this will eventually return an error
// details about when exactly the receivedPacketHistory errors are tested there
if err != nil {
@ -78,50 +78,50 @@ var _ = Describe("receivedPacketHandler", func() {
Context("queueing ACKs", func() {
receiveAndAck10Packets := func() {
for i := 1; i <= 10; i++ {
err := handler.ReceivedPacket(protocol.PacketNumber(i), time.Time{}, true)
err := tracker.ReceivedPacket(protocol.PacketNumber(i), time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
}
Expect(handler.GetAckFrame()).ToNot(BeNil())
Expect(handler.ackQueued).To(BeFalse())
Expect(tracker.GetAckFrame()).ToNot(BeNil())
Expect(tracker.ackQueued).To(BeFalse())
}
receiveAndAckPacketsUntilAckDecimation := func() {
for i := 1; i <= minReceivedBeforeAckDecimation; i++ {
err := handler.ReceivedPacket(protocol.PacketNumber(i), time.Time{}, true)
err := tracker.ReceivedPacket(protocol.PacketNumber(i), time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
}
Expect(handler.GetAckFrame()).ToNot(BeNil())
Expect(handler.ackQueued).To(BeFalse())
Expect(tracker.GetAckFrame()).ToNot(BeNil())
Expect(tracker.ackQueued).To(BeFalse())
}
It("always queues an ACK for the first packet", func() {
Expect(handler.ReceivedPacket(1, time.Now(), false)).To(Succeed())
Expect(handler.ackQueued).To(BeTrue())
Expect(handler.GetAlarmTimeout()).To(BeZero())
Expect(handler.GetAckFrame().DelayTime).To(BeNumerically("~", 0, time.Second))
Expect(tracker.ReceivedPacket(1, time.Now(), false)).To(Succeed())
Expect(tracker.ackQueued).To(BeTrue())
Expect(tracker.GetAlarmTimeout()).To(BeZero())
Expect(tracker.GetAckFrame().DelayTime).To(BeNumerically("~", 0, time.Second))
})
It("works with packet number 0", func() {
Expect(handler.ReceivedPacket(0, time.Now(), false)).To(Succeed())
Expect(handler.ackQueued).To(BeTrue())
Expect(handler.GetAlarmTimeout()).To(BeZero())
Expect(handler.GetAckFrame().DelayTime).To(BeNumerically("~", 0, time.Second))
Expect(tracker.ReceivedPacket(0, time.Now(), false)).To(Succeed())
Expect(tracker.ackQueued).To(BeTrue())
Expect(tracker.GetAlarmTimeout()).To(BeZero())
Expect(tracker.GetAckFrame().DelayTime).To(BeNumerically("~", 0, time.Second))
})
It("queues an ACK for every second retransmittable packet at the beginning", func() {
receiveAndAck10Packets()
p := protocol.PacketNumber(11)
for i := 0; i <= 20; i++ {
err := handler.ReceivedPacket(p, time.Time{}, true)
err := tracker.ReceivedPacket(p, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
Expect(handler.ackQueued).To(BeFalse())
Expect(tracker.ackQueued).To(BeFalse())
p++
err = handler.ReceivedPacket(p, time.Time{}, true)
err = tracker.ReceivedPacket(p, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
Expect(handler.ackQueued).To(BeTrue())
Expect(tracker.ackQueued).To(BeTrue())
p++
// dequeue the ACK frame
Expect(handler.GetAckFrame()).ToNot(BeNil())
Expect(tracker.GetAckFrame()).ToNot(BeNil())
}
})
@ -129,73 +129,73 @@ var _ = Describe("receivedPacketHandler", func() {
receiveAndAck10Packets()
p := protocol.PacketNumber(10000)
for i := 0; i < 9; i++ {
err := handler.ReceivedPacket(p, time.Now(), true)
err := tracker.ReceivedPacket(p, time.Now(), true)
Expect(err).ToNot(HaveOccurred())
Expect(handler.ackQueued).To(BeFalse())
Expect(tracker.ackQueued).To(BeFalse())
p++
}
Expect(handler.GetAlarmTimeout()).NotTo(BeZero())
err := handler.ReceivedPacket(p, time.Now(), true)
Expect(tracker.GetAlarmTimeout()).NotTo(BeZero())
err := tracker.ReceivedPacket(p, time.Now(), true)
Expect(err).ToNot(HaveOccurred())
Expect(handler.ackQueued).To(BeTrue())
Expect(handler.GetAlarmTimeout()).To(BeZero())
Expect(tracker.ackQueued).To(BeTrue())
Expect(tracker.GetAlarmTimeout()).To(BeZero())
})
It("only sets the timer when receiving a retransmittable packets", func() {
receiveAndAck10Packets()
err := handler.ReceivedPacket(11, time.Now(), false)
err := tracker.ReceivedPacket(11, time.Now(), false)
Expect(err).ToNot(HaveOccurred())
Expect(handler.ackQueued).To(BeFalse())
Expect(handler.GetAlarmTimeout()).To(BeZero())
Expect(tracker.ackQueued).To(BeFalse())
Expect(tracker.GetAlarmTimeout()).To(BeZero())
rcvTime := time.Now().Add(10 * time.Millisecond)
err = handler.ReceivedPacket(12, rcvTime, true)
err = tracker.ReceivedPacket(12, rcvTime, true)
Expect(err).ToNot(HaveOccurred())
Expect(handler.ackQueued).To(BeFalse())
Expect(handler.GetAlarmTimeout()).To(Equal(rcvTime.Add(ackSendDelay)))
Expect(tracker.ackQueued).To(BeFalse())
Expect(tracker.GetAlarmTimeout()).To(Equal(rcvTime.Add(ackSendDelay)))
})
It("queues an ACK if it was reported missing before", func() {
receiveAndAck10Packets()
err := handler.ReceivedPacket(11, time.Time{}, true)
err := tracker.ReceivedPacket(11, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(13, time.Time{}, true)
err = tracker.ReceivedPacket(13, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame() // ACK: 1-11 and 13, missing: 12
ack := tracker.GetAckFrame() // ACK: 1-11 and 13, missing: 12
Expect(ack).ToNot(BeNil())
Expect(ack.HasMissingRanges()).To(BeTrue())
Expect(handler.ackQueued).To(BeFalse())
err = handler.ReceivedPacket(12, time.Time{}, false)
Expect(tracker.ackQueued).To(BeFalse())
err = tracker.ReceivedPacket(12, time.Time{}, false)
Expect(err).ToNot(HaveOccurred())
Expect(handler.ackQueued).To(BeTrue())
Expect(tracker.ackQueued).To(BeTrue())
})
It("doesn't queue an ACK if it was reported missing before, but is below the threshold", func() {
receiveAndAck10Packets()
// 11 is missing
err := handler.ReceivedPacket(12, time.Time{}, true)
err := tracker.ReceivedPacket(12, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(13, time.Time{}, true)
err = tracker.ReceivedPacket(13, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame() // ACK: 1-10, 12-13
ack := tracker.GetAckFrame() // ACK: 1-10, 12-13
Expect(ack).ToNot(BeNil())
// now receive 11
handler.IgnoreBelow(12)
err = handler.ReceivedPacket(11, time.Time{}, false)
tracker.IgnoreBelow(12)
err = tracker.ReceivedPacket(11, time.Time{}, false)
Expect(err).ToNot(HaveOccurred())
ack = handler.GetAckFrame()
ack = tracker.GetAckFrame()
Expect(ack).To(BeNil())
})
It("doesn't queue an ACK if the packet closes a gap that was not yet reported", func() {
receiveAndAckPacketsUntilAckDecimation()
p := protocol.PacketNumber(minReceivedBeforeAckDecimation + 1)
err := handler.ReceivedPacket(p+1, time.Now(), true) // p is missing now
err := tracker.ReceivedPacket(p+1, time.Now(), true) // p is missing now
Expect(err).ToNot(HaveOccurred())
Expect(handler.ackQueued).To(BeFalse())
Expect(handler.GetAlarmTimeout()).ToNot(BeZero())
err = handler.ReceivedPacket(p, time.Now(), true) // p is not missing any more
Expect(tracker.ackQueued).To(BeFalse())
Expect(tracker.GetAlarmTimeout()).ToNot(BeZero())
err = tracker.ReceivedPacket(p, time.Now(), true) // p is not missing any more
Expect(err).ToNot(HaveOccurred())
Expect(handler.ackQueued).To(BeFalse())
Expect(tracker.ackQueued).To(BeFalse())
})
It("sets an ACK alarm after 1/4 RTT if it creates a new missing range", func() {
@ -205,14 +205,14 @@ var _ = Describe("receivedPacketHandler", func() {
receiveAndAckPacketsUntilAckDecimation()
p := protocol.PacketNumber(minReceivedBeforeAckDecimation + 1)
for i := p; i < p+6; i++ {
err := handler.ReceivedPacket(i, now, true)
err := tracker.ReceivedPacket(i, now, true)
Expect(err).ToNot(HaveOccurred())
}
err := handler.ReceivedPacket(p+10, now, true) // we now know that packets p+7, p+8 and p+9
err := tracker.ReceivedPacket(p+10, now, true) // we now know that packets p+7, p+8 and p+9
Expect(err).ToNot(HaveOccurred())
Expect(rttStats.MinRTT()).To(Equal(rtt))
Expect(handler.ackAlarm.Sub(now)).To(Equal(rtt / 8))
ack := handler.GetAckFrame()
Expect(tracker.ackAlarm.Sub(now)).To(Equal(rtt / 8))
ack := tracker.GetAckFrame()
Expect(ack.HasMissingRanges()).To(BeTrue())
Expect(ack).ToNot(BeNil())
})
@ -220,15 +220,15 @@ var _ = Describe("receivedPacketHandler", func() {
Context("ACK generation", func() {
BeforeEach(func() {
handler.ackQueued = true
tracker.ackQueued = true
})
It("generates a simple ACK frame", func() {
err := handler.ReceivedPacket(1, time.Time{}, true)
err := tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(2, time.Time{}, true)
err = tracker.ReceivedPacket(2, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame()
ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(2)))
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(1)))
@ -236,9 +236,9 @@ var _ = Describe("receivedPacketHandler", func() {
})
It("generates an ACK for packet number 0", func() {
err := handler.ReceivedPacket(0, time.Time{}, true)
err := tracker.ReceivedPacket(0, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame()
ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(0)))
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(0)))
@ -246,35 +246,35 @@ var _ = Describe("receivedPacketHandler", func() {
})
It("sets the delay time", func() {
err := handler.ReceivedPacket(1, time.Time{}, true)
err := tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(2, time.Now().Add(-1337*time.Millisecond), true)
err = tracker.ReceivedPacket(2, time.Now().Add(-1337*time.Millisecond), true)
Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame()
ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.DelayTime).To(BeNumerically("~", 1337*time.Millisecond, 50*time.Millisecond))
})
It("saves the last sent ACK", func() {
err := handler.ReceivedPacket(1, time.Time{}, true)
err := tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame()
ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(handler.lastAck).To(Equal(ack))
err = handler.ReceivedPacket(2, time.Time{}, true)
Expect(tracker.lastAck).To(Equal(ack))
err = tracker.ReceivedPacket(2, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
handler.ackQueued = true
ack = handler.GetAckFrame()
tracker.ackQueued = true
ack = tracker.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(handler.lastAck).To(Equal(ack))
Expect(tracker.lastAck).To(Equal(ack))
})
It("generates an ACK frame with missing packets", func() {
err := handler.ReceivedPacket(1, time.Time{}, true)
err := tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(4, time.Time{}, true)
err = tracker.ReceivedPacket(4, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame()
ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(4)))
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(1)))
@ -285,13 +285,13 @@ var _ = Describe("receivedPacketHandler", func() {
})
It("generates an ACK for packet number 0 and other packets", func() {
err := handler.ReceivedPacket(0, time.Time{}, true)
err := tracker.ReceivedPacket(0, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(1, time.Time{}, true)
err = tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(3, time.Time{}, true)
err = tracker.ReceivedPacket(3, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame()
ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(3)))
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(0)))
@ -302,18 +302,18 @@ var _ = Describe("receivedPacketHandler", func() {
})
It("accepts packets below the lower limit", func() {
handler.IgnoreBelow(6)
err := handler.ReceivedPacket(2, time.Time{}, true)
tracker.IgnoreBelow(6)
err := tracker.ReceivedPacket(2, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
})
It("doesn't add delayed packets to the packetHistory", func() {
handler.IgnoreBelow(7)
err := handler.ReceivedPacket(4, time.Time{}, true)
tracker.IgnoreBelow(7)
err := tracker.ReceivedPacket(4, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(10, time.Time{}, true)
err = tracker.ReceivedPacket(10, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame()
ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(10)))
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(10)))
@ -321,12 +321,12 @@ var _ = Describe("receivedPacketHandler", func() {
It("deletes packets from the packetHistory when a lower limit is set", func() {
for i := 1; i <= 12; i++ {
err := handler.ReceivedPacket(protocol.PacketNumber(i), time.Time{}, true)
err := tracker.ReceivedPacket(protocol.PacketNumber(i), time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
}
handler.IgnoreBelow(7)
tracker.IgnoreBelow(7)
// check that the packets were deleted from the receivedPacketHistory by checking the values in an ACK frame
ack := handler.GetAckFrame()
ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(12)))
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(7)))
@ -335,47 +335,47 @@ var _ = Describe("receivedPacketHandler", func() {
// TODO: remove this test when dropping support for STOP_WAITINGs
It("handles a lower limit of 0", func() {
handler.IgnoreBelow(0)
err := handler.ReceivedPacket(1337, time.Time{}, true)
tracker.IgnoreBelow(0)
err := tracker.ReceivedPacket(1337, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame()
ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(1337)))
})
It("resets all counters needed for the ACK queueing decision when sending an ACK", func() {
err := handler.ReceivedPacket(1, time.Time{}, true)
err := tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
handler.ackAlarm = time.Now().Add(-time.Minute)
Expect(handler.GetAckFrame()).ToNot(BeNil())
Expect(handler.packetsReceivedSinceLastAck).To(BeZero())
Expect(handler.GetAlarmTimeout()).To(BeZero())
Expect(handler.retransmittablePacketsReceivedSinceLastAck).To(BeZero())
Expect(handler.ackQueued).To(BeFalse())
tracker.ackAlarm = time.Now().Add(-time.Minute)
Expect(tracker.GetAckFrame()).ToNot(BeNil())
Expect(tracker.packetsReceivedSinceLastAck).To(BeZero())
Expect(tracker.GetAlarmTimeout()).To(BeZero())
Expect(tracker.retransmittablePacketsReceivedSinceLastAck).To(BeZero())
Expect(tracker.ackQueued).To(BeFalse())
})
It("doesn't generate an ACK when none is queued and the timer is not set", func() {
err := handler.ReceivedPacket(1, time.Time{}, true)
err := tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
handler.ackQueued = false
handler.ackAlarm = time.Time{}
Expect(handler.GetAckFrame()).To(BeNil())
tracker.ackQueued = false
tracker.ackAlarm = time.Time{}
Expect(tracker.GetAckFrame()).To(BeNil())
})
It("doesn't generate an ACK when none is queued and the timer has not yet expired", func() {
err := handler.ReceivedPacket(1, time.Time{}, true)
err := tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
handler.ackQueued = false
handler.ackAlarm = time.Now().Add(time.Minute)
Expect(handler.GetAckFrame()).To(BeNil())
tracker.ackQueued = false
tracker.ackAlarm = time.Now().Add(time.Minute)
Expect(tracker.GetAckFrame()).To(BeNil())
})
It("generates an ACK when the timer has expired", func() {
err := handler.ReceivedPacket(1, time.Time{}, true)
err := tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
handler.ackQueued = false
handler.ackAlarm = time.Now().Add(-time.Minute)
Expect(handler.GetAckFrame()).ToNot(BeNil())
tracker.ackQueued = false
tracker.ackAlarm = time.Now().Add(-time.Minute)
Expect(tracker.GetAckFrame()).ToNot(BeNil())
})
})
})