remove unneeded return value of ReceivedPacketHandler.ReceivedPacket()

This commit is contained in:
Marten Seemann 2019-07-30 12:03:00 +07:00
parent 475ba63164
commit d5585628d8
10 changed files with 78 additions and 147 deletions

View file

@ -46,7 +46,7 @@ type SentPacketHandler interface {
// ReceivedPacketHandler handles ACKs needed to send for incoming packets
type ReceivedPacketHandler interface {
ReceivedPacket(pn protocol.PacketNumber, encLevel protocol.EncryptionLevel, rcvTime time.Time, shouldInstigateAck bool) error
ReceivedPacket(pn protocol.PacketNumber, encLevel protocol.EncryptionLevel, rcvTime time.Time, shouldInstigateAck bool)
IgnoreBelow(protocol.PacketNumber)
DropPackets(protocol.EncryptionLevel)

View file

@ -57,16 +57,16 @@ func (h *receivedPacketHandler) ReceivedPacket(
encLevel protocol.EncryptionLevel,
rcvTime time.Time,
shouldInstigateAck bool,
) error {
) {
switch encLevel {
case protocol.EncryptionInitial:
return h.initialPackets.ReceivedPacket(pn, rcvTime, shouldInstigateAck)
h.initialPackets.ReceivedPacket(pn, rcvTime, shouldInstigateAck)
case protocol.EncryptionHandshake:
return h.handshakePackets.ReceivedPacket(pn, rcvTime, shouldInstigateAck)
h.handshakePackets.ReceivedPacket(pn, rcvTime, shouldInstigateAck)
case protocol.Encryption1RTT:
return h.oneRTTPackets.ReceivedPacket(pn, rcvTime, shouldInstigateAck)
h.oneRTTPackets.ReceivedPacket(pn, rcvTime, shouldInstigateAck)
default:
return fmt.Errorf("received packet with unknown encryption level: %s", encLevel)
panic(fmt.Sprintf("received packet with unknown encryption level: %s", encLevel))
}
}

View file

@ -25,12 +25,12 @@ var _ = Describe("Received Packet Handler", func() {
It("generates ACKs for different packet number spaces", func() {
sendTime := time.Now().Add(-time.Second)
Expect(handler.ReceivedPacket(2, protocol.EncryptionInitial, sendTime, true)).To(Succeed())
Expect(handler.ReceivedPacket(1, protocol.EncryptionHandshake, sendTime, true)).To(Succeed())
Expect(handler.ReceivedPacket(5, protocol.Encryption1RTT, sendTime, true)).To(Succeed())
Expect(handler.ReceivedPacket(3, protocol.EncryptionInitial, sendTime, true)).To(Succeed())
Expect(handler.ReceivedPacket(2, protocol.EncryptionHandshake, sendTime, true)).To(Succeed())
Expect(handler.ReceivedPacket(4, protocol.Encryption1RTT, sendTime, true)).To(Succeed())
handler.ReceivedPacket(2, protocol.EncryptionInitial, sendTime, true)
handler.ReceivedPacket(1, protocol.EncryptionHandshake, sendTime, true)
handler.ReceivedPacket(5, protocol.Encryption1RTT, sendTime, true)
handler.ReceivedPacket(3, protocol.EncryptionInitial, sendTime, true)
handler.ReceivedPacket(2, protocol.EncryptionHandshake, sendTime, true)
handler.ReceivedPacket(4, protocol.Encryption1RTT, sendTime, true)
initialAck := handler.GetAckFrame(protocol.EncryptionInitial)
Expect(initialAck).ToNot(BeNil())
Expect(initialAck.AckRanges).To(HaveLen(1))
@ -50,8 +50,8 @@ var _ = Describe("Received Packet Handler", func() {
It("drops Initial packets", func() {
sendTime := time.Now().Add(-time.Second)
Expect(handler.ReceivedPacket(2, protocol.EncryptionInitial, sendTime, true)).To(Succeed())
Expect(handler.ReceivedPacket(1, protocol.EncryptionHandshake, sendTime, true)).To(Succeed())
handler.ReceivedPacket(2, protocol.EncryptionInitial, sendTime, true)
handler.ReceivedPacket(1, protocol.EncryptionHandshake, sendTime, true)
Expect(handler.GetAckFrame(protocol.EncryptionInitial)).ToNot(BeNil())
handler.DropPackets(protocol.EncryptionInitial)
Expect(handler.GetAckFrame(protocol.EncryptionInitial)).To(BeNil())
@ -60,8 +60,8 @@ var _ = Describe("Received Packet Handler", func() {
It("drops Handshake packets", func() {
sendTime := time.Now().Add(-time.Second)
Expect(handler.ReceivedPacket(1, protocol.EncryptionHandshake, sendTime, true)).To(Succeed())
Expect(handler.ReceivedPacket(2, protocol.Encryption1RTT, sendTime, true)).To(Succeed())
handler.ReceivedPacket(1, protocol.EncryptionHandshake, sendTime, true)
handler.ReceivedPacket(2, protocol.Encryption1RTT, sendTime, true)
Expect(handler.GetAckFrame(protocol.EncryptionHandshake)).ToNot(BeNil())
handler.DropPackets(protocol.EncryptionInitial)
Expect(handler.GetAckFrame(protocol.EncryptionHandshake)).To(BeNil())

View file

@ -22,28 +22,25 @@ func newReceivedPacketHistory() *receivedPacketHistory {
}
// ReceivedPacket registers a packet with PacketNumber p and updates the ranges
func (h *receivedPacketHistory) ReceivedPacket(p protocol.PacketNumber) error {
func (h *receivedPacketHistory) ReceivedPacket(p protocol.PacketNumber) {
// ignore delayed packets, if we already deleted the range
if p < h.deletedBelow {
return nil
}
if err := h.addToRanges(p); err != nil {
return err
return
}
h.addToRanges(p)
h.maybeDeleteOldRanges()
return nil
}
func (h *receivedPacketHistory) addToRanges(p protocol.PacketNumber) error {
func (h *receivedPacketHistory) addToRanges(p protocol.PacketNumber) {
if h.ranges.Len() == 0 {
h.ranges.PushBack(utils.PacketInterval{Start: p, End: p})
return nil
return
}
for el := h.ranges.Back(); el != nil; el = el.Prev() {
// p already included in an existing range. Nothing to do here
if p >= el.Value.Start && p <= el.Value.End {
return nil
return
}
var rangeExtended bool
@ -61,21 +58,20 @@ func (h *receivedPacketHistory) addToRanges(p protocol.PacketNumber) error {
if prev != nil && prev.Value.End+1 == el.Value.Start { // merge two ranges
prev.Value.End = el.Value.End
h.ranges.Remove(el)
return nil
return
}
return nil // if the two ranges were not merge, we're done here
return // if the two ranges were not merge, we're done here
}
// create a new range at the end
if p > el.Value.End {
h.ranges.InsertAfter(utils.PacketInterval{Start: p, End: p}, el)
return nil
return
}
}
// create a new range at the beginning
h.ranges.InsertBefore(utils.PacketInterval{Start: p, End: p}, h.ranges.Front())
return nil
}
// Delete old ranges, if we're tracking more than 500 of them.

View file

@ -188,13 +188,11 @@ var _ = Describe("receivedPacketHistory", func() {
It("doesn't create more than MaxNumAckRanges ranges", func() {
for i := protocol.PacketNumber(0); i < protocol.MaxNumAckRanges; i++ {
err := hist.ReceivedPacket(2 * i)
Expect(err).ToNot(HaveOccurred())
hist.ReceivedPacket(2 * i)
}
Expect(hist.ranges.Len()).To(Equal(protocol.MaxNumAckRanges))
Expect(hist.ranges.Front().Value).To(Equal(utils.PacketInterval{Start: 0, End: 0}))
err := hist.ReceivedPacket(2*protocol.MaxNumAckRanges + 1000)
Expect(err).ToNot(HaveOccurred())
hist.ReceivedPacket(2*protocol.MaxNumAckRanges + 1000)
// check that the oldest ACK range was deleted
Expect(hist.ranges.Len()).To(Equal(protocol.MaxNumAckRanges))
Expect(hist.ranges.Front().Value).To(Equal(utils.PacketInterval{Start: 2, End: 2}))

View file

@ -44,9 +44,9 @@ func newReceivedPacketTracker(
}
}
func (h *receivedPacketTracker) ReceivedPacket(packetNumber protocol.PacketNumber, rcvTime time.Time, shouldInstigateAck bool) error {
func (h *receivedPacketTracker) ReceivedPacket(packetNumber protocol.PacketNumber, rcvTime time.Time, shouldInstigateAck bool) {
if packetNumber < h.ignoreBelow {
return nil
return
}
isMissing := h.isMissing(packetNumber)
@ -55,11 +55,8 @@ func (h *receivedPacketTracker) ReceivedPacket(packetNumber protocol.PacketNumbe
h.largestObservedReceivedTime = rcvTime
}
if err := h.packetHistory.ReceivedPacket(packetNumber); err != nil {
return err
}
h.packetHistory.ReceivedPacket(packetNumber)
h.maybeQueueAck(packetNumber, rcvTime, shouldInstigateAck, isMissing)
return nil
}
// IgnoreBelow sets a lower limit for acking packets.

View file

@ -24,18 +24,8 @@ var _ = Describe("Received Packet Tracker", func() {
})
Context("accepting packets", func() {
It("handles a packet that arrives late", func() {
err := tracker.ReceivedPacket(protocol.PacketNumber(1), time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = tracker.ReceivedPacket(protocol.PacketNumber(3), time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = tracker.ReceivedPacket(protocol.PacketNumber(2), time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
})
It("saves the time when each packet arrived", func() {
err := tracker.ReceivedPacket(protocol.PacketNumber(3), time.Now(), true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(protocol.PacketNumber(3), time.Now(), true)
Expect(tracker.largestObservedReceivedTime).To(BeTemporally("~", time.Now(), 10*time.Millisecond))
})
@ -43,8 +33,7 @@ var _ = Describe("Received Packet Tracker", func() {
now := time.Now()
tracker.largestObserved = 3
tracker.largestObservedReceivedTime = now.Add(-1 * time.Second)
err := tracker.ReceivedPacket(5, now, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(5, now, true)
Expect(tracker.largestObserved).To(Equal(protocol.PacketNumber(5)))
Expect(tracker.largestObservedReceivedTime).To(Equal(now))
})
@ -54,8 +43,7 @@ var _ = Describe("Received Packet Tracker", func() {
timestamp := now.Add(-1 * time.Second)
tracker.largestObserved = 5
tracker.largestObservedReceivedTime = timestamp
err := tracker.ReceivedPacket(4, now, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(4, now, true)
Expect(tracker.largestObserved).To(Equal(protocol.PacketNumber(5)))
Expect(tracker.largestObservedReceivedTime).To(Equal(timestamp))
})
@ -65,8 +53,7 @@ var _ = Describe("Received Packet Tracker", func() {
Context("queueing ACKs", func() {
receiveAndAck10Packets := func() {
for i := 1; i <= 10; i++ {
err := tracker.ReceivedPacket(protocol.PacketNumber(i), time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(protocol.PacketNumber(i), time.Time{}, true)
}
Expect(tracker.GetAckFrame()).ToNot(BeNil())
Expect(tracker.ackQueued).To(BeFalse())
@ -74,22 +61,21 @@ var _ = Describe("Received Packet Tracker", func() {
receiveAndAckPacketsUntilAckDecimation := func() {
for i := 1; i <= minReceivedBeforeAckDecimation; i++ {
err := tracker.ReceivedPacket(protocol.PacketNumber(i), time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(protocol.PacketNumber(i), time.Time{}, true)
}
Expect(tracker.GetAckFrame()).ToNot(BeNil())
Expect(tracker.ackQueued).To(BeFalse())
}
It("always queues an ACK for the first packet", func() {
Expect(tracker.ReceivedPacket(1, time.Now(), false)).To(Succeed())
tracker.ReceivedPacket(1, time.Now(), false)
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(tracker.ReceivedPacket(0, time.Now(), false)).To(Succeed())
tracker.ReceivedPacket(0, time.Now(), false)
Expect(tracker.ackQueued).To(BeTrue())
Expect(tracker.GetAlarmTimeout()).To(BeZero())
Expect(tracker.GetAckFrame().DelayTime).To(BeNumerically("~", 0, time.Second))
@ -99,12 +85,10 @@ var _ = Describe("Received Packet Tracker", func() {
receiveAndAck10Packets()
p := protocol.PacketNumber(11)
for i := 0; i <= 20; i++ {
err := tracker.ReceivedPacket(p, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(p, time.Time{}, true)
Expect(tracker.ackQueued).To(BeFalse())
p++
err = tracker.ReceivedPacket(p, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(p, time.Time{}, true)
Expect(tracker.ackQueued).To(BeTrue())
p++
// dequeue the ACK frame
@ -116,59 +100,49 @@ var _ = Describe("Received Packet Tracker", func() {
receiveAndAck10Packets()
p := protocol.PacketNumber(10000)
for i := 0; i < 9; i++ {
err := tracker.ReceivedPacket(p, time.Now(), true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(p, time.Now(), true)
Expect(tracker.ackQueued).To(BeFalse())
p++
}
Expect(tracker.GetAlarmTimeout()).NotTo(BeZero())
err := tracker.ReceivedPacket(p, time.Now(), true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(p, time.Now(), true)
Expect(tracker.ackQueued).To(BeTrue())
Expect(tracker.GetAlarmTimeout()).To(BeZero())
})
It("only sets the timer when receiving a ack-eliciting packets", func() {
receiveAndAck10Packets()
err := tracker.ReceivedPacket(11, time.Now(), false)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(11, time.Now(), false)
Expect(tracker.ackQueued).To(BeFalse())
Expect(tracker.GetAlarmTimeout()).To(BeZero())
rcvTime := time.Now().Add(10 * time.Millisecond)
err = tracker.ReceivedPacket(12, rcvTime, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(12, rcvTime, true)
Expect(tracker.ackQueued).To(BeFalse())
Expect(tracker.GetAlarmTimeout()).To(Equal(rcvTime.Add(protocol.MaxAckDelay)))
})
It("queues an ACK if it was reported missing before", func() {
receiveAndAck10Packets()
err := tracker.ReceivedPacket(11, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = tracker.ReceivedPacket(13, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(11, time.Time{}, true)
tracker.ReceivedPacket(13, time.Time{}, true)
ack := tracker.GetAckFrame() // ACK: 1-11 and 13, missing: 12
Expect(ack).ToNot(BeNil())
Expect(ack.HasMissingRanges()).To(BeTrue())
Expect(tracker.ackQueued).To(BeFalse())
err = tracker.ReceivedPacket(12, time.Time{}, false)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(12, time.Time{}, false)
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 := tracker.ReceivedPacket(12, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = tracker.ReceivedPacket(13, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(12, time.Time{}, true)
tracker.ReceivedPacket(13, time.Time{}, true)
ack := tracker.GetAckFrame() // ACK: 1-10, 12-13
Expect(ack).ToNot(BeNil())
// now receive 11
tracker.IgnoreBelow(12)
err = tracker.ReceivedPacket(11, time.Time{}, false)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(11, time.Time{}, false)
ack = tracker.GetAckFrame()
Expect(ack).To(BeNil())
})
@ -176,12 +150,10 @@ var _ = Describe("Received Packet Tracker", func() {
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 := tracker.ReceivedPacket(p+1, time.Now(), true) // p is missing now
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(p+1, time.Now(), true) // p is missing now
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())
tracker.ReceivedPacket(p, time.Now(), true) // p is not missing any more
Expect(tracker.ackQueued).To(BeFalse())
})
@ -192,11 +164,9 @@ var _ = Describe("Received Packet Tracker", func() {
receiveAndAckPacketsUntilAckDecimation()
p := protocol.PacketNumber(minReceivedBeforeAckDecimation + 1)
for i := p; i < p+6; i++ {
err := tracker.ReceivedPacket(i, now, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(i, now, true)
}
err := tracker.ReceivedPacket(p+10, now, true) // we now know that packets p+7, p+8 and p+9
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(p+10, now, true) // we now know that packets p+7, p+8 and p+9
Expect(rttStats.MinRTT()).To(Equal(rtt))
Expect(tracker.ackAlarm.Sub(now)).To(Equal(rtt / 8))
ack := tracker.GetAckFrame()
@ -211,10 +181,8 @@ var _ = Describe("Received Packet Tracker", func() {
})
It("generates a simple ACK frame", func() {
err := tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = tracker.ReceivedPacket(2, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(1, time.Time{}, true)
tracker.ReceivedPacket(2, time.Time{}, true)
ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(2)))
@ -223,8 +191,7 @@ var _ = Describe("Received Packet Tracker", func() {
})
It("generates an ACK for packet number 0", func() {
err := tracker.ReceivedPacket(0, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(0, time.Time{}, true)
ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(0)))
@ -233,23 +200,19 @@ var _ = Describe("Received Packet Tracker", func() {
})
It("sets the delay time", func() {
err := tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = tracker.ReceivedPacket(2, time.Now().Add(-1337*time.Millisecond), true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(1, time.Time{}, true)
tracker.ReceivedPacket(2, time.Now().Add(-1337*time.Millisecond), true)
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 := tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(1, time.Time{}, true)
ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(tracker.lastAck).To(Equal(ack))
err = tracker.ReceivedPacket(2, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(2, time.Time{}, true)
tracker.ackQueued = true
ack = tracker.GetAckFrame()
Expect(ack).ToNot(BeNil())
@ -257,10 +220,8 @@ var _ = Describe("Received Packet Tracker", func() {
})
It("generates an ACK frame with missing packets", func() {
err := tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = tracker.ReceivedPacket(4, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(1, time.Time{}, true)
tracker.ReceivedPacket(4, time.Time{}, true)
ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(4)))
@ -272,12 +233,9 @@ var _ = Describe("Received Packet Tracker", func() {
})
It("generates an ACK for packet number 0 and other packets", func() {
err := tracker.ReceivedPacket(0, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = tracker.ReceivedPacket(3, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(0, time.Time{}, true)
tracker.ReceivedPacket(1, time.Time{}, true)
tracker.ReceivedPacket(3, time.Time{}, true)
ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(3)))
@ -288,18 +246,10 @@ var _ = Describe("Received Packet Tracker", func() {
}))
})
It("accepts packets below the lower limit", func() {
tracker.IgnoreBelow(6)
err := tracker.ReceivedPacket(2, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
})
It("doesn't add delayed packets to the packetHistory", func() {
tracker.IgnoreBelow(7)
err := tracker.ReceivedPacket(4, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
err = tracker.ReceivedPacket(10, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(4, time.Time{}, true)
tracker.ReceivedPacket(10, time.Time{}, true)
ack := tracker.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(10)))
@ -308,8 +258,7 @@ var _ = Describe("Received Packet Tracker", func() {
It("deletes packets from the packetHistory when a lower limit is set", func() {
for i := 1; i <= 12; i++ {
err := tracker.ReceivedPacket(protocol.PacketNumber(i), time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(protocol.PacketNumber(i), time.Time{}, true)
}
tracker.IgnoreBelow(7)
// check that the packets were deleted from the receivedPacketHistory by checking the values in an ACK frame
@ -323,16 +272,14 @@ var _ = Describe("Received Packet Tracker", func() {
// TODO: remove this test when dropping support for STOP_WAITINGs
It("handles a lower limit of 0", func() {
tracker.IgnoreBelow(0)
err := tracker.ReceivedPacket(1337, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(1337, time.Time{}, true)
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 := tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(1, time.Time{}, true)
tracker.ackAlarm = time.Now().Add(-time.Minute)
Expect(tracker.GetAckFrame()).ToNot(BeNil())
Expect(tracker.packetsReceivedSinceLastAck).To(BeZero())
@ -342,24 +289,21 @@ var _ = Describe("Received Packet Tracker", func() {
})
It("doesn't generate an ACK when none is queued and the timer is not set", func() {
err := tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(1, time.Time{}, true)
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 := tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(1, time.Time{}, true)
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 := tracker.ReceivedPacket(1, time.Time{}, true)
Expect(err).ToNot(HaveOccurred())
tracker.ReceivedPacket(1, time.Time{}, true)
tracker.ackQueued = false
tracker.ackAlarm = time.Now().Add(-time.Minute)
Expect(tracker.GetAckFrame()).ToNot(BeNil())

View file

@ -89,11 +89,9 @@ func (mr *MockReceivedPacketHandlerMockRecorder) IgnoreBelow(arg0 interface{}) *
}
// ReceivedPacket mocks base method
func (m *MockReceivedPacketHandler) ReceivedPacket(arg0 protocol.PacketNumber, arg1 protocol.EncryptionLevel, arg2 time.Time, arg3 bool) error {
func (m *MockReceivedPacketHandler) ReceivedPacket(arg0 protocol.PacketNumber, arg1 protocol.EncryptionLevel, arg2 time.Time, arg3 bool) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "ReceivedPacket", arg0, arg1, arg2, arg3)
ret0, _ := ret[0].(error)
return ret0
m.ctrl.Call(m, "ReceivedPacket", arg0, arg1, arg2, arg3)
}
// ReceivedPacket indicates an expected call of ReceivedPacket

View file

@ -716,9 +716,7 @@ func (s *session) handleUnpackedPacket(packet *unpackedPacket, rcvTime time.Time
})
}
if err := s.receivedPacketHandler.ReceivedPacket(packet.packetNumber, packet.encryptionLevel, rcvTime, isAckEliciting); err != nil {
return err
}
s.receivedPacketHandler.ReceivedPacket(packet.packetNumber, packet.encryptionLevel, rcvTime, isAckEliciting)
return nil
}

View file

@ -829,7 +829,7 @@ var _ = Describe("Session", func() {
It("sends packets", func() {
packer.EXPECT().PackPacket().Return(getPacket(1), nil)
Expect(sess.receivedPacketHandler.ReceivedPacket(0x035e, protocol.Encryption1RTT, time.Now(), true)).To(Succeed())
sess.receivedPacketHandler.ReceivedPacket(0x035e, protocol.Encryption1RTT, time.Now(), true)
sent, err := sess.sendPacket()
Expect(err).NotTo(HaveOccurred())
Expect(sent).To(BeTrue())
@ -837,7 +837,7 @@ var _ = Describe("Session", func() {
It("doesn't send packets if there's nothing to send", func() {
packer.EXPECT().PackPacket().Return(getPacket(2), nil)
Expect(sess.receivedPacketHandler.ReceivedPacket(0x035e, protocol.Encryption1RTT, time.Now(), true)).To(Succeed())
sess.receivedPacketHandler.ReceivedPacket(0x035e, protocol.Encryption1RTT, time.Now(), true)
sent, err := sess.sendPacket()
Expect(err).NotTo(HaveOccurred())
Expect(sent).To(BeTrue())