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. // 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. // It does not store packet contents.
type receivedPacketHistory struct { type receivedPacketHistory struct {
ranges *utils.PacketIntervalList ranges *utils.PacketIntervalList

View file

@ -9,7 +9,7 @@ import (
"github.com/lucas-clemente/quic-go/internal/wire" "github.com/lucas-clemente/quic-go/internal/wire"
) )
type receivedPacketHandler struct { type receivedPacketTracker struct {
largestObserved protocol.PacketNumber largestObserved protocol.PacketNumber
ignoreBelow protocol.PacketNumber ignoreBelow protocol.PacketNumber
largestObservedReceivedTime time.Time largestObservedReceivedTime time.Time
@ -59,7 +59,7 @@ func NewReceivedPacketHandler(
logger utils.Logger, logger utils.Logger,
version protocol.VersionNumber, version protocol.VersionNumber,
) ReceivedPacketHandler { ) ReceivedPacketHandler {
return &receivedPacketHandler{ return &receivedPacketTracker{
packetHistory: newReceivedPacketHistory(), packetHistory: newReceivedPacketHistory(),
ackSendDelay: ackSendDelay, ackSendDelay: ackSendDelay,
rttStats: rttStats, 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 { if packetNumber < h.ignoreBelow {
return nil return nil
} }
@ -88,7 +88,7 @@ func (h *receivedPacketHandler) ReceivedPacket(packetNumber protocol.PacketNumbe
// IgnoreBelow sets a lower limit for acking packets. // IgnoreBelow sets a lower limit for acking packets.
// Packets with packet numbers smaller than p will not be acked. // 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 { if p <= h.ignoreBelow {
return return
} }
@ -100,14 +100,14 @@ func (h *receivedPacketHandler) IgnoreBelow(p protocol.PacketNumber) {
} }
// isMissing says if a packet was reported missing in the last ACK. // 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 { if h.lastAck == nil || p < h.ignoreBelow {
return false return false
} }
return p < h.lastAck.LargestAcked() && !h.lastAck.AcksPacket(p) return p < h.lastAck.LargestAcked() && !h.lastAck.AcksPacket(p)
} }
func (h *receivedPacketHandler) hasNewMissingPackets() bool { func (h *receivedPacketTracker) hasNewMissingPackets() bool {
if h.lastAck == nil { if h.lastAck == nil {
return false return false
} }
@ -118,7 +118,7 @@ func (h *receivedPacketHandler) hasNewMissingPackets() bool {
// maybeQueueAck queues an ACK, if necessary. // maybeQueueAck queues an ACK, if necessary.
// It is implemented analogously to Chrome's QuicConnection::MaybeQueueAck() // It is implemented analogously to Chrome's QuicConnection::MaybeQueueAck()
// in ACK_DECIMATION_WITH_REORDERING mode. // 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++ h.packetsReceivedSinceLastAck++
// always ack the first packet // 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() now := time.Now()
if !h.ackQueued && (h.ackAlarm.IsZero() || h.ackAlarm.After(now)) { if !h.ackQueued && (h.ackAlarm.IsZero() || h.ackAlarm.After(now)) {
return nil return nil
@ -212,4 +212,4 @@ func (h *receivedPacketHandler) GetAckFrame() *wire.AckFrame {
return ack 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" . "github.com/onsi/gomega"
) )
var _ = Describe("receivedPacketHandler", func() { var _ = Describe("Received Packet Tracker", func() {
var ( var (
handler *receivedPacketHandler tracker *receivedPacketTracker
rttStats *congestion.RTTStats rttStats *congestion.RTTStats
) )
BeforeEach(func() { BeforeEach(func() {
rttStats = &congestion.RTTStats{} rttStats = &congestion.RTTStats{}
handler = NewReceivedPacketHandler(rttStats, utils.DefaultLogger, protocol.VersionWhatever).(*receivedPacketHandler) tracker = NewReceivedPacketHandler(rttStats, utils.DefaultLogger, protocol.VersionWhatever).(*receivedPacketTracker)
}) })
Context("accepting packets", func() { Context("accepting packets", func() {
It("handles a packet that arrives late", 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()) 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()) 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()) Expect(err).ToNot(HaveOccurred())
}) })
It("saves the time when each packet arrived", func() { 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(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() { It("updates the largestObserved and the largestObservedReceivedTime", func() {
now := time.Now() now := time.Now()
handler.largestObserved = 3 tracker.largestObserved = 3
handler.largestObservedReceivedTime = now.Add(-1 * time.Second) tracker.largestObservedReceivedTime = now.Add(-1 * time.Second)
err := handler.ReceivedPacket(5, now, true) err := tracker.ReceivedPacket(5, now, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(handler.largestObserved).To(Equal(protocol.PacketNumber(5))) Expect(tracker.largestObserved).To(Equal(protocol.PacketNumber(5)))
Expect(handler.largestObservedReceivedTime).To(Equal(now)) Expect(tracker.largestObservedReceivedTime).To(Equal(now))
}) })
It("doesn't update the largestObserved and the largestObservedReceivedTime for a belated packet", func() { It("doesn't update the largestObserved and the largestObservedReceivedTime for a belated packet", func() {
now := time.Now() now := time.Now()
timestamp := now.Add(-1 * time.Second) timestamp := now.Add(-1 * time.Second)
handler.largestObserved = 5 tracker.largestObserved = 5
handler.largestObservedReceivedTime = timestamp tracker.largestObservedReceivedTime = timestamp
err := handler.ReceivedPacket(4, now, true) err := tracker.ReceivedPacket(4, now, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(handler.largestObserved).To(Equal(protocol.PacketNumber(5))) Expect(tracker.largestObserved).To(Equal(protocol.PacketNumber(5)))
Expect(handler.largestObservedReceivedTime).To(Equal(timestamp)) Expect(tracker.largestObservedReceivedTime).To(Equal(timestamp))
}) })
It("passes on errors from receivedPacketHistory", func() { It("passes on errors from receivedPacketHistory", func() {
var err error var err error
for i := protocol.PacketNumber(0); i < 5*protocol.MaxTrackedReceivedAckRanges; i++ { 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 // this will eventually return an error
// details about when exactly the receivedPacketHistory errors are tested there // details about when exactly the receivedPacketHistory errors are tested there
if err != nil { if err != nil {
@ -78,50 +78,50 @@ var _ = Describe("receivedPacketHandler", func() {
Context("queueing ACKs", func() { Context("queueing ACKs", func() {
receiveAndAck10Packets := func() { receiveAndAck10Packets := func() {
for i := 1; i <= 10; i++ { 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(err).ToNot(HaveOccurred())
} }
Expect(handler.GetAckFrame()).ToNot(BeNil()) Expect(tracker.GetAckFrame()).ToNot(BeNil())
Expect(handler.ackQueued).To(BeFalse()) Expect(tracker.ackQueued).To(BeFalse())
} }
receiveAndAckPacketsUntilAckDecimation := func() { receiveAndAckPacketsUntilAckDecimation := func() {
for i := 1; i <= minReceivedBeforeAckDecimation; i++ { 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(err).ToNot(HaveOccurred())
} }
Expect(handler.GetAckFrame()).ToNot(BeNil()) Expect(tracker.GetAckFrame()).ToNot(BeNil())
Expect(handler.ackQueued).To(BeFalse()) Expect(tracker.ackQueued).To(BeFalse())
} }
It("always queues an ACK for the first packet", func() { It("always queues an ACK for the first packet", func() {
Expect(handler.ReceivedPacket(1, time.Now(), false)).To(Succeed()) Expect(tracker.ReceivedPacket(1, time.Now(), false)).To(Succeed())
Expect(handler.ackQueued).To(BeTrue()) Expect(tracker.ackQueued).To(BeTrue())
Expect(handler.GetAlarmTimeout()).To(BeZero()) Expect(tracker.GetAlarmTimeout()).To(BeZero())
Expect(handler.GetAckFrame().DelayTime).To(BeNumerically("~", 0, time.Second)) Expect(tracker.GetAckFrame().DelayTime).To(BeNumerically("~", 0, time.Second))
}) })
It("works with packet number 0", func() { It("works with packet number 0", func() {
Expect(handler.ReceivedPacket(0, time.Now(), false)).To(Succeed()) Expect(tracker.ReceivedPacket(0, time.Now(), false)).To(Succeed())
Expect(handler.ackQueued).To(BeTrue()) Expect(tracker.ackQueued).To(BeTrue())
Expect(handler.GetAlarmTimeout()).To(BeZero()) Expect(tracker.GetAlarmTimeout()).To(BeZero())
Expect(handler.GetAckFrame().DelayTime).To(BeNumerically("~", 0, time.Second)) Expect(tracker.GetAckFrame().DelayTime).To(BeNumerically("~", 0, time.Second))
}) })
It("queues an ACK for every second retransmittable packet at the beginning", func() { It("queues an ACK for every second retransmittable packet at the beginning", func() {
receiveAndAck10Packets() receiveAndAck10Packets()
p := protocol.PacketNumber(11) p := protocol.PacketNumber(11)
for i := 0; i <= 20; i++ { 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(err).ToNot(HaveOccurred())
Expect(handler.ackQueued).To(BeFalse()) Expect(tracker.ackQueued).To(BeFalse())
p++ p++
err = handler.ReceivedPacket(p, time.Time{}, true) err = tracker.ReceivedPacket(p, time.Time{}, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(handler.ackQueued).To(BeTrue()) Expect(tracker.ackQueued).To(BeTrue())
p++ p++
// dequeue the ACK frame // dequeue the ACK frame
Expect(handler.GetAckFrame()).ToNot(BeNil()) Expect(tracker.GetAckFrame()).ToNot(BeNil())
} }
}) })
@ -129,73 +129,73 @@ var _ = Describe("receivedPacketHandler", func() {
receiveAndAck10Packets() receiveAndAck10Packets()
p := protocol.PacketNumber(10000) p := protocol.PacketNumber(10000)
for i := 0; i < 9; i++ { 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(err).ToNot(HaveOccurred())
Expect(handler.ackQueued).To(BeFalse()) Expect(tracker.ackQueued).To(BeFalse())
p++ p++
} }
Expect(handler.GetAlarmTimeout()).NotTo(BeZero()) Expect(tracker.GetAlarmTimeout()).NotTo(BeZero())
err := handler.ReceivedPacket(p, time.Now(), true) err := tracker.ReceivedPacket(p, time.Now(), true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(handler.ackQueued).To(BeTrue()) Expect(tracker.ackQueued).To(BeTrue())
Expect(handler.GetAlarmTimeout()).To(BeZero()) Expect(tracker.GetAlarmTimeout()).To(BeZero())
}) })
It("only sets the timer when receiving a retransmittable packets", func() { It("only sets the timer when receiving a retransmittable packets", func() {
receiveAndAck10Packets() receiveAndAck10Packets()
err := handler.ReceivedPacket(11, time.Now(), false) err := tracker.ReceivedPacket(11, time.Now(), false)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(handler.ackQueued).To(BeFalse()) Expect(tracker.ackQueued).To(BeFalse())
Expect(handler.GetAlarmTimeout()).To(BeZero()) Expect(tracker.GetAlarmTimeout()).To(BeZero())
rcvTime := time.Now().Add(10 * time.Millisecond) rcvTime := time.Now().Add(10 * time.Millisecond)
err = handler.ReceivedPacket(12, rcvTime, true) err = tracker.ReceivedPacket(12, rcvTime, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
Expect(handler.ackQueued).To(BeFalse()) Expect(tracker.ackQueued).To(BeFalse())
Expect(handler.GetAlarmTimeout()).To(Equal(rcvTime.Add(ackSendDelay))) Expect(tracker.GetAlarmTimeout()).To(Equal(rcvTime.Add(ackSendDelay)))
}) })
It("queues an ACK if it was reported missing before", func() { It("queues an ACK if it was reported missing before", func() {
receiveAndAck10Packets() receiveAndAck10Packets()
err := handler.ReceivedPacket(11, time.Time{}, true) err := tracker.ReceivedPacket(11, time.Time{}, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(13, time.Time{}, true) err = tracker.ReceivedPacket(13, time.Time{}, true)
Expect(err).ToNot(HaveOccurred()) 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).ToNot(BeNil())
Expect(ack.HasMissingRanges()).To(BeTrue()) Expect(ack.HasMissingRanges()).To(BeTrue())
Expect(handler.ackQueued).To(BeFalse()) Expect(tracker.ackQueued).To(BeFalse())
err = handler.ReceivedPacket(12, time.Time{}, false) err = tracker.ReceivedPacket(12, time.Time{}, false)
Expect(err).ToNot(HaveOccurred()) 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() { It("doesn't queue an ACK if it was reported missing before, but is below the threshold", func() {
receiveAndAck10Packets() receiveAndAck10Packets()
// 11 is missing // 11 is missing
err := handler.ReceivedPacket(12, time.Time{}, true) err := tracker.ReceivedPacket(12, time.Time{}, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(13, time.Time{}, true) err = tracker.ReceivedPacket(13, time.Time{}, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame() // ACK: 1-10, 12-13 ack := tracker.GetAckFrame() // ACK: 1-10, 12-13
Expect(ack).ToNot(BeNil()) Expect(ack).ToNot(BeNil())
// now receive 11 // now receive 11
handler.IgnoreBelow(12) tracker.IgnoreBelow(12)
err = handler.ReceivedPacket(11, time.Time{}, false) err = tracker.ReceivedPacket(11, time.Time{}, false)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
ack = handler.GetAckFrame() ack = tracker.GetAckFrame()
Expect(ack).To(BeNil()) Expect(ack).To(BeNil())
}) })
It("doesn't queue an ACK if the packet closes a gap that was not yet reported", func() { It("doesn't queue an ACK if the packet closes a gap that was not yet reported", func() {
receiveAndAckPacketsUntilAckDecimation() receiveAndAckPacketsUntilAckDecimation()
p := protocol.PacketNumber(minReceivedBeforeAckDecimation + 1) 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(err).ToNot(HaveOccurred())
Expect(handler.ackQueued).To(BeFalse()) Expect(tracker.ackQueued).To(BeFalse())
Expect(handler.GetAlarmTimeout()).ToNot(BeZero()) Expect(tracker.GetAlarmTimeout()).ToNot(BeZero())
err = handler.ReceivedPacket(p, time.Now(), true) // p is not missing any more err = tracker.ReceivedPacket(p, time.Now(), true) // p is not missing any more
Expect(err).ToNot(HaveOccurred()) 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() { 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() receiveAndAckPacketsUntilAckDecimation()
p := protocol.PacketNumber(minReceivedBeforeAckDecimation + 1) p := protocol.PacketNumber(minReceivedBeforeAckDecimation + 1)
for i := p; i < p+6; i++ { for i := p; i < p+6; i++ {
err := handler.ReceivedPacket(i, now, true) err := tracker.ReceivedPacket(i, now, true)
Expect(err).ToNot(HaveOccurred()) 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(err).ToNot(HaveOccurred())
Expect(rttStats.MinRTT()).To(Equal(rtt)) Expect(rttStats.MinRTT()).To(Equal(rtt))
Expect(handler.ackAlarm.Sub(now)).To(Equal(rtt / 8)) Expect(tracker.ackAlarm.Sub(now)).To(Equal(rtt / 8))
ack := handler.GetAckFrame() ack := tracker.GetAckFrame()
Expect(ack.HasMissingRanges()).To(BeTrue()) Expect(ack.HasMissingRanges()).To(BeTrue())
Expect(ack).ToNot(BeNil()) Expect(ack).ToNot(BeNil())
}) })
@ -220,15 +220,15 @@ var _ = Describe("receivedPacketHandler", func() {
Context("ACK generation", func() { Context("ACK generation", func() {
BeforeEach(func() { BeforeEach(func() {
handler.ackQueued = true tracker.ackQueued = true
}) })
It("generates a simple ACK frame", func() { 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()) Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(2, time.Time{}, true) err = tracker.ReceivedPacket(2, time.Time{}, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame() ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil()) Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(2))) Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(2)))
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(1))) 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() { 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()) Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame() ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil()) Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(0))) Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(0)))
Expect(ack.LowestAcked()).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() { It("sets the delay time", func() {
err := handler.ReceivedPacket(1, time.Time{}, true) err := tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred()) 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()) Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame() ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil()) Expect(ack).ToNot(BeNil())
Expect(ack.DelayTime).To(BeNumerically("~", 1337*time.Millisecond, 50*time.Millisecond)) Expect(ack.DelayTime).To(BeNumerically("~", 1337*time.Millisecond, 50*time.Millisecond))
}) })
It("saves the last sent ACK", func() { 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()) Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame() ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil()) Expect(ack).ToNot(BeNil())
Expect(handler.lastAck).To(Equal(ack)) Expect(tracker.lastAck).To(Equal(ack))
err = handler.ReceivedPacket(2, time.Time{}, true) err = tracker.ReceivedPacket(2, time.Time{}, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
handler.ackQueued = true tracker.ackQueued = true
ack = handler.GetAckFrame() ack = tracker.GetAckFrame()
Expect(ack).ToNot(BeNil()) 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() { 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()) Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(4, time.Time{}, true) err = tracker.ReceivedPacket(4, time.Time{}, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame() ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil()) Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(4))) Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(4)))
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(1))) 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() { 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()) Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(1, time.Time{}, true) err = tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(3, time.Time{}, true) err = tracker.ReceivedPacket(3, time.Time{}, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame() ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil()) Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(3))) Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(3)))
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(0))) Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(0)))
@ -302,18 +302,18 @@ var _ = Describe("receivedPacketHandler", func() {
}) })
It("accepts packets below the lower limit", func() { It("accepts packets below the lower limit", func() {
handler.IgnoreBelow(6) tracker.IgnoreBelow(6)
err := handler.ReceivedPacket(2, time.Time{}, true) err := tracker.ReceivedPacket(2, time.Time{}, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
}) })
It("doesn't add delayed packets to the packetHistory", func() { It("doesn't add delayed packets to the packetHistory", func() {
handler.IgnoreBelow(7) tracker.IgnoreBelow(7)
err := handler.ReceivedPacket(4, time.Time{}, true) err := tracker.ReceivedPacket(4, time.Time{}, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
err = handler.ReceivedPacket(10, time.Time{}, true) err = tracker.ReceivedPacket(10, time.Time{}, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame() ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil()) Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(10))) Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(10)))
Expect(ack.LowestAcked()).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() { It("deletes packets from the packetHistory when a lower limit is set", func() {
for i := 1; i <= 12; i++ { 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()) 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 // 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).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(12))) Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(12)))
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(7))) 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 // TODO: remove this test when dropping support for STOP_WAITINGs
It("handles a lower limit of 0", func() { It("handles a lower limit of 0", func() {
handler.IgnoreBelow(0) tracker.IgnoreBelow(0)
err := handler.ReceivedPacket(1337, time.Time{}, true) err := tracker.ReceivedPacket(1337, time.Time{}, true)
Expect(err).ToNot(HaveOccurred()) Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame() ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil()) Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(1337))) Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(1337)))
}) })
It("resets all counters needed for the ACK queueing decision when sending an ACK", func() { 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()) Expect(err).ToNot(HaveOccurred())
handler.ackAlarm = time.Now().Add(-time.Minute) tracker.ackAlarm = time.Now().Add(-time.Minute)
Expect(handler.GetAckFrame()).ToNot(BeNil()) Expect(tracker.GetAckFrame()).ToNot(BeNil())
Expect(handler.packetsReceivedSinceLastAck).To(BeZero()) Expect(tracker.packetsReceivedSinceLastAck).To(BeZero())
Expect(handler.GetAlarmTimeout()).To(BeZero()) Expect(tracker.GetAlarmTimeout()).To(BeZero())
Expect(handler.retransmittablePacketsReceivedSinceLastAck).To(BeZero()) Expect(tracker.retransmittablePacketsReceivedSinceLastAck).To(BeZero())
Expect(handler.ackQueued).To(BeFalse()) Expect(tracker.ackQueued).To(BeFalse())
}) })
It("doesn't generate an ACK when none is queued and the timer is not set", func() { 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()) Expect(err).ToNot(HaveOccurred())
handler.ackQueued = false tracker.ackQueued = false
handler.ackAlarm = time.Time{} tracker.ackAlarm = time.Time{}
Expect(handler.GetAckFrame()).To(BeNil()) Expect(tracker.GetAckFrame()).To(BeNil())
}) })
It("doesn't generate an ACK when none is queued and the timer has not yet expired", func() { 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()) Expect(err).ToNot(HaveOccurred())
handler.ackQueued = false tracker.ackQueued = false
handler.ackAlarm = time.Now().Add(time.Minute) tracker.ackAlarm = time.Now().Add(time.Minute)
Expect(handler.GetAckFrame()).To(BeNil()) Expect(tracker.GetAckFrame()).To(BeNil())
}) })
It("generates an ACK when the timer has expired", func() { 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()) Expect(err).ToNot(HaveOccurred())
handler.ackQueued = false tracker.ackQueued = false
handler.ackAlarm = time.Now().Add(-time.Minute) tracker.ackAlarm = time.Now().Add(-time.Minute)
Expect(handler.GetAckFrame()).ToNot(BeNil()) Expect(tracker.GetAckFrame()).ToNot(BeNil())
}) })
}) })
}) })