remove the {Lowest, Largest}Acked from the ACK frame

All ACK ranges are now saved in the AckRanges slices. This eliminates a
bunch of special cases for ACKs that don't report any packets missing.
This commit is contained in:
Marten Seemann 2018-04-17 11:50:22 +09:00
parent 7de877fc3f
commit 52c3e6e863
15 changed files with 389 additions and 515 deletions

View file

@ -91,7 +91,7 @@ func (h *receivedPacketHandler) isMissing(p protocol.PacketNumber) bool {
if h.lastAck == nil {
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 {
@ -99,7 +99,7 @@ func (h *receivedPacketHandler) hasNewMissingPackets() bool {
return false
}
highestRange := h.packetHistory.GetHighestAckRange()
return highestRange.Smallest >= h.lastAck.LargestAcked && highestRange.Len() <= maxPacketsAfterNewMissing
return highestRange.Smallest >= h.lastAck.LargestAcked() && highestRange.Len() <= maxPacketsAfterNewMissing
}
// maybeQueueAck queues an ACK, if necessary.
@ -163,17 +163,11 @@ func (h *receivedPacketHandler) GetAckFrame() *wire.AckFrame {
return nil
}
ackRanges := h.packetHistory.GetAckRanges()
ack := &wire.AckFrame{
LargestAcked: h.largestObserved,
LowestAcked: ackRanges[len(ackRanges)-1].Smallest,
AckRanges: h.packetHistory.GetAckRanges(),
PacketReceivedTime: h.largestObservedReceivedTime,
}
if len(ackRanges) > 1 {
ack.AckRanges = ackRanges
}
h.lastAck = ack
h.ackAlarm = time.Time{}
h.ackQueued = false

View file

@ -212,9 +212,9 @@ var _ = Describe("receivedPacketHandler", func() {
Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked).To(Equal(protocol.PacketNumber(2)))
Expect(ack.LowestAcked).To(Equal(protocol.PacketNumber(1)))
Expect(ack.AckRanges).To(BeEmpty())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(2)))
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(1)))
Expect(ack.HasMissingRanges()).To(BeFalse())
})
It("generates an ACK for packet number 0", func() {
@ -222,9 +222,9 @@ var _ = Describe("receivedPacketHandler", func() {
Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked).To(Equal(protocol.PacketNumber(0)))
Expect(ack.LowestAcked).To(Equal(protocol.PacketNumber(0)))
Expect(ack.AckRanges).To(BeEmpty())
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(0)))
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(0)))
Expect(ack.HasMissingRanges()).To(BeFalse())
})
It("saves the last sent ACK", func() {
@ -248,8 +248,8 @@ var _ = Describe("receivedPacketHandler", func() {
Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked).To(Equal(protocol.PacketNumber(4)))
Expect(ack.LowestAcked).To(Equal(protocol.PacketNumber(1)))
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(4)))
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(1)))
Expect(ack.AckRanges).To(Equal([]wire.AckRange{
{Smallest: 4, Largest: 4},
{Smallest: 1, Largest: 1},
@ -265,8 +265,8 @@ var _ = Describe("receivedPacketHandler", func() {
Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked).To(Equal(protocol.PacketNumber(3)))
Expect(ack.LowestAcked).To(Equal(protocol.PacketNumber(0)))
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(3)))
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(0)))
Expect(ack.AckRanges).To(Equal([]wire.AckRange{
{Smallest: 3, Largest: 3},
{Smallest: 0, Largest: 1},
@ -287,8 +287,8 @@ var _ = Describe("receivedPacketHandler", func() {
Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked).To(Equal(protocol.PacketNumber(10)))
Expect(ack.LowestAcked).To(Equal(protocol.PacketNumber(10)))
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(10)))
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(10)))
})
It("deletes packets from the packetHistory when a lower limit is set", func() {
@ -300,8 +300,8 @@ var _ = Describe("receivedPacketHandler", func() {
// check that the packets were deleted from the receivedPacketHistory by checking the values in an ACK frame
ack := handler.GetAckFrame()
Expect(ack).ToNot(BeNil())
Expect(ack.LargestAcked).To(Equal(protocol.PacketNumber(12)))
Expect(ack.LowestAcked).To(Equal(protocol.PacketNumber(7)))
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(12)))
Expect(ack.LowestAcked()).To(Equal(protocol.PacketNumber(7)))
Expect(ack.HasMissingRanges()).To(BeFalse())
})
@ -312,7 +312,7 @@ var _ = Describe("receivedPacketHandler", func() {
Expect(err).ToNot(HaveOccurred())
ack := handler.GetAckFrame()
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() {

View file

@ -150,7 +150,7 @@ func (h *sentPacketHandler) sentPacketImpl(packet *Packet) bool /* isRetransmitt
if len(packet.Frames) > 0 {
if ackFrame, ok := packet.Frames[0].(*wire.AckFrame); ok {
packet.largestAcked = ackFrame.LargestAcked
packet.largestAcked = ackFrame.LargestAcked()
}
}
@ -176,7 +176,8 @@ func (h *sentPacketHandler) sentPacketImpl(packet *Packet) bool /* isRetransmitt
}
func (h *sentPacketHandler) ReceivedAck(ackFrame *wire.AckFrame, withPacketNumber protocol.PacketNumber, encLevel protocol.EncryptionLevel, rcvTime time.Time) error {
if ackFrame.LargestAcked > h.lastSentPacketNumber {
largestAcked := ackFrame.LargestAcked()
if largestAcked > h.lastSentPacketNumber {
return qerr.Error(qerr.InvalidAckData, "Received ACK for an unsent package")
}
@ -186,13 +187,13 @@ func (h *sentPacketHandler) ReceivedAck(ackFrame *wire.AckFrame, withPacketNumbe
return nil
}
h.largestReceivedPacketWithAck = withPacketNumber
h.largestAcked = utils.MaxPacketNumber(h.largestAcked, ackFrame.LargestAcked)
h.largestAcked = utils.MaxPacketNumber(h.largestAcked, largestAcked)
if h.skippedPacketsAcked(ackFrame) {
return qerr.Error(qerr.InvalidAckData, "Received an ACK for a skipped packet number")
}
if rttUpdated := h.maybeUpdateRTT(ackFrame.LargestAcked, ackFrame.DelayTime, rcvTime); rttUpdated {
if rttUpdated := h.maybeUpdateRTT(largestAcked, ackFrame.DelayTime, rcvTime); rttUpdated {
h.congestion.MaybeExitSlowStart()
}
@ -238,13 +239,15 @@ func (h *sentPacketHandler) GetLowestPacketNotConfirmedAcked() protocol.PacketNu
func (h *sentPacketHandler) determineNewlyAckedPackets(ackFrame *wire.AckFrame) ([]*Packet, error) {
var ackedPackets []*Packet
ackRangeIndex := 0
lowestAcked := ackFrame.LowestAcked()
largestAcked := ackFrame.LargestAcked()
err := h.packetHistory.Iterate(func(p *Packet) (bool, error) {
// Ignore packets below the LowestAcked
if p.PacketNumber < ackFrame.LowestAcked {
// Ignore packets below the lowest acked
if p.PacketNumber < lowestAcked {
return true, nil
}
// Break after LargestAcked is reached
if p.PacketNumber > ackFrame.LargestAcked {
// Break after largest acked is reached
if p.PacketNumber > largestAcked {
return false, nil
}

View file

@ -1,7 +1,6 @@
package ackhandler
import (
"sort"
"time"
"github.com/golang/mock/gomock"
@ -30,7 +29,9 @@ func retransmittablePacket(p *Packet) *Packet {
func nonRetransmittablePacket(p *Packet) *Packet {
p = retransmittablePacket(p)
p.Frames = []wire.Frame{&wire.AckFrame{}}
p.Frames = []wire.Frame{
&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}},
}
return p
}
@ -40,20 +41,6 @@ func handshakePacket(p *Packet) *Packet {
return p
}
func createAck(ranges []wire.AckRange) *wire.AckFrame {
sort.Slice(ranges, func(i, j int) bool {
return ranges[i].Smallest > ranges[j].Smallest
})
ack := &wire.AckFrame{
LowestAcked: ranges[len(ranges)-1].Smallest,
LargestAcked: ranges[0].Largest,
}
if len(ranges) > 1 {
ack.AckRanges = ranges
}
return ack
}
var _ = Describe("SentPacketHandler", func() {
var (
handler *sentPacketHandler
@ -210,13 +197,20 @@ var _ = Describe("SentPacketHandler", func() {
})
It("rejects ACKs for skipped packets", func() {
ack := createAck([]wire.AckRange{{Smallest: 10, Largest: 12}})
ack := &wire.AckFrame{
AckRanges: []wire.AckRange{{Smallest: 10, Largest: 12}},
}
err := handler.ReceivedAck(ack, 1337, protocol.EncryptionForwardSecure, time.Now())
Expect(err).To(MatchError("InvalidAckData: Received an ACK for a skipped packet number"))
})
It("accepts an ACK that correctly nacks a skipped packet", func() {
ack := createAck([]wire.AckRange{{Smallest: 10, Largest: 10}, {Smallest: 12, Largest: 12}})
ack := &wire.AckFrame{
AckRanges: []wire.AckRange{
{Smallest: 12, Largest: 12},
{Smallest: 10, Largest: 10},
},
}
err := handler.ReceivedAck(ack, 1337, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
Expect(handler.largestAcked).ToNot(BeZero())
@ -237,15 +231,15 @@ var _ = Describe("SentPacketHandler", func() {
Context("ACK validation", func() {
It("accepts ACKs sent in packet 0", func() {
ack := createAck([]wire.AckRange{{Smallest: 0, Largest: 5}})
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 0, Largest: 5}}}
err := handler.ReceivedAck(ack, 0, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
Expect(handler.largestAcked).To(Equal(protocol.PacketNumber(5)))
})
It("rejects duplicate ACKs", func() {
ack1 := createAck([]wire.AckRange{{Smallest: 0, Largest: 3}})
ack2 := createAck([]wire.AckRange{{Smallest: 0, Largest: 4}})
ack1 := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 0, Largest: 3}}}
ack2 := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 0, Largest: 4}}}
err := handler.ReceivedAck(ack1, 1337, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
Expect(handler.largestAcked).To(Equal(protocol.PacketNumber(3)))
@ -258,8 +252,8 @@ var _ = Describe("SentPacketHandler", func() {
It("rejects out of order ACKs", func() {
// acks packets 0, 1, 2, 3
ack1 := createAck([]wire.AckRange{{Smallest: 0, Largest: 3}})
ack2 := createAck([]wire.AckRange{{Smallest: 0, Largest: 4}})
ack1 := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 0, Largest: 3}}}
ack2 := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 0, Largest: 4}}}
err := handler.ReceivedAck(ack1, 1337, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
// this wouldn't happen in practive
@ -270,14 +264,14 @@ var _ = Describe("SentPacketHandler", func() {
})
It("rejects ACKs with a too high LargestAcked packet number", func() {
ack := createAck([]wire.AckRange{{Smallest: 0, Largest: 9999}})
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 0, Largest: 9999}}}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).To(MatchError("InvalidAckData: Received ACK for an unsent package"))
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(10)))
})
It("ignores repeated ACKs", func() {
ack := createAck([]wire.AckRange{{Smallest: 1, Largest: 3}})
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 3}}}
err := handler.ReceivedAck(ack, 1337, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(7)))
@ -290,7 +284,7 @@ var _ = Describe("SentPacketHandler", func() {
Context("acks and nacks the right packets", func() {
It("adjusts the LargestAcked, and adjusts the bytes in flight", func() {
ack := createAck([]wire.AckRange{{Smallest: 0, Largest: 5}})
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 0, Largest: 5}}}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
Expect(handler.largestAcked).To(Equal(protocol.PacketNumber(5)))
@ -299,7 +293,7 @@ var _ = Describe("SentPacketHandler", func() {
})
It("acks packet 0", func() {
ack := createAck([]wire.AckRange{{Smallest: 0, Largest: 0}})
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 0, Largest: 0}}}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
Expect(getPacket(0)).To(BeNil())
@ -307,38 +301,50 @@ var _ = Describe("SentPacketHandler", func() {
})
It("handles an ACK frame with one missing packet range", func() {
ack := createAck([]wire.AckRange{{Smallest: 1, Largest: 3}, {Smallest: 6, Largest: 9}}) // lose 4 and 5
ack := &wire.AckFrame{ // lose 4 and 5
AckRanges: []wire.AckRange{
{Smallest: 6, Largest: 9},
{Smallest: 1, Largest: 3},
},
}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
expectInPacketHistory([]protocol.PacketNumber{0, 4, 5})
})
It("does not ack packets below the LowestAcked", func() {
ack := createAck([]wire.AckRange{{Smallest: 3, Largest: 8}})
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 3, Largest: 8}}}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
expectInPacketHistory([]protocol.PacketNumber{0, 1, 2, 9})
})
It("handles an ACK with multiple missing packet ranges", func() {
ack := createAck([]wire.AckRange{ // packets 2, 4 and 5, and 8 were lost
{Smallest: 9, Largest: 9},
{Smallest: 6, Largest: 7},
{Smallest: 3, Largest: 3},
{Smallest: 1, Largest: 1},
})
ack := &wire.AckFrame{ // packets 2, 4 and 5, and 8 were lost
AckRanges: []wire.AckRange{
{Smallest: 9, Largest: 9},
{Smallest: 6, Largest: 7},
{Smallest: 3, Largest: 3},
{Smallest: 1, Largest: 1},
},
}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
expectInPacketHistory([]protocol.PacketNumber{0, 2, 4, 5, 8})
})
It("processes an ACK frame that would be sent after a late arrival of a packet", func() {
ack1 := createAck([]wire.AckRange{{Smallest: 1, Largest: 2}, {Smallest: 4, Largest: 6}}) // 3 lost
ack1 := &wire.AckFrame{ // 3 lost
AckRanges: []wire.AckRange{
{Smallest: 4, Largest: 6},
{Smallest: 1, Largest: 2},
},
}
err := handler.ReceivedAck(ack1, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
expectInPacketHistory([]protocol.PacketNumber{0, 3, 7, 8, 9})
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(5)))
ack2 := createAck([]wire.AckRange{{Smallest: 1, Largest: 6}}) // now ack 3
ack2 := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 6}}} // now ack 3
err = handler.ReceivedAck(ack2, 2, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
expectInPacketHistory([]protocol.PacketNumber{0, 7, 8, 9})
@ -346,12 +352,17 @@ var _ = Describe("SentPacketHandler", func() {
})
It("processes an ACK frame that would be sent after a late arrival of a packet and another packet", func() {
ack1 := createAck([]wire.AckRange{{Smallest: 0, Largest: 2}, {Smallest: 4, Largest: 6}})
ack1 := &wire.AckFrame{
AckRanges: []wire.AckRange{
{Smallest: 4, Largest: 6},
{Smallest: 0, Largest: 2},
},
}
err := handler.ReceivedAck(ack1, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
expectInPacketHistory([]protocol.PacketNumber{3, 7, 8, 9})
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(4)))
ack2 := createAck([]wire.AckRange{{Smallest: 1, Largest: 7}})
ack2 := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 7}}}
err = handler.ReceivedAck(ack2, 2, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(2)))
@ -359,16 +370,18 @@ var _ = Describe("SentPacketHandler", func() {
})
It("processes an ACK that contains old ACK ranges", func() {
ack1 := createAck([]wire.AckRange{{Smallest: 1, Largest: 6}})
ack1 := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 6}}}
err := handler.ReceivedAck(ack1, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
expectInPacketHistory([]protocol.PacketNumber{0, 7, 8, 9})
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(4)))
ack2 := createAck([]wire.AckRange{
{Smallest: 1, Largest: 1},
{Smallest: 3, Largest: 3},
{Smallest: 8, Largest: 8},
})
ack2 := &wire.AckFrame{
AckRanges: []wire.AckRange{
{Smallest: 8, Largest: 8},
{Smallest: 3, Largest: 3},
{Smallest: 1, Largest: 1},
},
}
err = handler.ReceivedAck(ack2, 2, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
expectInPacketHistory([]protocol.PacketNumber{0, 7, 9})
@ -384,13 +397,16 @@ var _ = Describe("SentPacketHandler", func() {
getPacket(2).SendTime = now.Add(-5 * time.Minute)
getPacket(6).SendTime = now.Add(-1 * time.Minute)
// Now, check that the proper times are used when calculating the deltas
err := handler.ReceivedAck(&wire.AckFrame{LargestAcked: 1}, 1, protocol.EncryptionForwardSecure, time.Now())
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).NotTo(HaveOccurred())
Expect(handler.rttStats.LatestRTT()).To(BeNumerically("~", 10*time.Minute, 1*time.Second))
err = handler.ReceivedAck(&wire.AckFrame{LargestAcked: 2}, 2, protocol.EncryptionForwardSecure, time.Now())
ack = &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 2}}}
err = handler.ReceivedAck(ack, 2, protocol.EncryptionForwardSecure, time.Now())
Expect(err).NotTo(HaveOccurred())
Expect(handler.rttStats.LatestRTT()).To(BeNumerically("~", 5*time.Minute, 1*time.Second))
err = handler.ReceivedAck(&wire.AckFrame{LargestAcked: 6}, 3, protocol.EncryptionForwardSecure, time.Now())
ack = &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 6}}}
err = handler.ReceivedAck(ack, 3, protocol.EncryptionForwardSecure, time.Now())
Expect(err).NotTo(HaveOccurred())
Expect(handler.rttStats.LatestRTT()).To(BeNumerically("~", 1*time.Minute, 1*time.Second))
})
@ -400,7 +416,11 @@ var _ = Describe("SentPacketHandler", func() {
// make sure the rttStats have a min RTT, so that the delay is used
handler.rttStats.UpdateRTT(5*time.Minute, 0, time.Now())
getPacket(1).SendTime = now.Add(-10 * time.Minute)
err := handler.ReceivedAck(&wire.AckFrame{LargestAcked: 1, DelayTime: 5 * time.Minute}, 1, protocol.EncryptionForwardSecure, time.Now())
ack := &wire.AckFrame{
AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}},
DelayTime: 5 * time.Minute,
}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).NotTo(HaveOccurred())
Expect(handler.rttStats.LatestRTT()).To(BeNumerically("~", 5*time.Minute, 1*time.Second))
})
@ -408,9 +428,11 @@ var _ = Describe("SentPacketHandler", func() {
Context("determining which ACKs we have received an ACK for", func() {
BeforeEach(func() {
ack1 := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 80, Largest: 100}}}
ack2 := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 50, Largest: 200}}}
morePackets := []*Packet{
{PacketNumber: 13, Frames: []wire.Frame{&wire.AckFrame{LowestAcked: 80, LargestAcked: 100}, &streamFrame}, Length: 1},
{PacketNumber: 14, Frames: []wire.Frame{&wire.AckFrame{LowestAcked: 50, LargestAcked: 200}, &streamFrame}, Length: 1},
{PacketNumber: 13, Frames: []wire.Frame{ack1, &streamFrame}, Length: 1},
{PacketNumber: 14, Frames: []wire.Frame{ack2, &streamFrame}, Length: 1},
{PacketNumber: 15, Frames: []wire.Frame{&streamFrame}, Length: 1},
}
for _, packet := range morePackets {
@ -419,25 +441,27 @@ var _ = Describe("SentPacketHandler", func() {
})
It("determines which ACK we have received an ACK for", func() {
err := handler.ReceivedAck(createAck([]wire.AckRange{{Smallest: 13, Largest: 15}}), 1, protocol.EncryptionForwardSecure, time.Now())
err := handler.ReceivedAck(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 13, Largest: 15}}}, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
Expect(handler.GetLowestPacketNotConfirmedAcked()).To(Equal(protocol.PacketNumber(201)))
})
It("doesn't do anything when the acked packet didn't contain an ACK", func() {
err := handler.ReceivedAck(createAck([]wire.AckRange{{Smallest: 13, Largest: 13}}), 1, protocol.EncryptionForwardSecure, time.Now())
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 13, Largest: 13}}}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
Expect(handler.GetLowestPacketNotConfirmedAcked()).To(Equal(protocol.PacketNumber(101)))
err = handler.ReceivedAck(createAck([]wire.AckRange{{Smallest: 15, Largest: 15}}), 2, protocol.EncryptionForwardSecure, time.Now())
ack = &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 15, Largest: 15}}}
err = handler.ReceivedAck(ack, 2, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
Expect(handler.GetLowestPacketNotConfirmedAcked()).To(Equal(protocol.PacketNumber(101)))
})
It("doesn't decrease the value", func() {
err := handler.ReceivedAck(createAck([]wire.AckRange{{Smallest: 14, Largest: 14}}), 1, protocol.EncryptionForwardSecure, time.Now())
err := handler.ReceivedAck(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 14, Largest: 14}}}, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
Expect(handler.GetLowestPacketNotConfirmedAcked()).To(Equal(protocol.PacketNumber(201)))
err = handler.ReceivedAck(createAck([]wire.AckRange{{Smallest: 13, Largest: 13}}), 2, protocol.EncryptionForwardSecure, time.Now())
err = handler.ReceivedAck(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 13, Largest: 13}}}, 2, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
Expect(handler.GetLowestPacketNotConfirmedAcked()).To(Equal(protocol.PacketNumber(201)))
})
@ -462,7 +486,8 @@ var _ = Describe("SentPacketHandler", func() {
handler.SentPacketsAsRetransmission([]*Packet{retransmittablePacket(&Packet{PacketNumber: 6, Length: 11})}, 5)
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(11)))
// ack 5
err := handler.ReceivedAck(&wire.AckFrame{LowestAcked: 5, LargestAcked: 5}, 1, protocol.EncryptionForwardSecure, time.Now())
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 5, Largest: 5}}}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
expectInPacketHistory([]protocol.PacketNumber{6})
Expect(handler.bytesInFlight).To(Equal(protocol.ByteCount(11)))
@ -474,7 +499,12 @@ var _ = Describe("SentPacketHandler", func() {
losePacket(5)
handler.SentPacketsAsRetransmission([]*Packet{retransmittablePacket(&Packet{PacketNumber: 7, Length: 11})}, 5)
// ack 5 and 7
ack := createAck([]wire.AckRange{{Smallest: 5, Largest: 5}, {Smallest: 7, Largest: 7}})
ack := &wire.AckFrame{
AckRanges: []wire.AckRange{
{Smallest: 7, Largest: 7},
{Smallest: 5, Largest: 5},
},
}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
Expect(handler.packetHistory.Len()).To(BeZero())
@ -493,8 +523,8 @@ var _ = Describe("SentPacketHandler", func() {
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1}))
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 2}))
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 3}))
ack := wire.AckFrame{LargestAcked: 3, LowestAcked: 3}
err := handler.ReceivedAck(&ack, 2, protocol.EncryptionForwardSecure, time.Now())
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 3, Largest: 3}}}
err := handler.ReceivedAck(ack, 2, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
Expect(handler.GetStopWaitingFrame(false)).To(Equal(&wire.StopWaitingFrame{LeastUnacked: 4}))
})
@ -543,7 +573,8 @@ var _ = Describe("SentPacketHandler", func() {
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 1}))
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 2}))
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 3}))
err := handler.ReceivedAck(&wire.AckFrame{LargestAcked: 2, LowestAcked: 1}, 1, protocol.EncryptionForwardSecure, time.Now())
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 2}}}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).NotTo(HaveOccurred())
})
@ -579,7 +610,8 @@ var _ = Describe("SentPacketHandler", func() {
cong.EXPECT().OnPacketLost(protocol.PacketNumber(4), protocol.ByteCount(1), protocol.ByteCount(5)),
)
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 5}))
err := handler.ReceivedAck(&wire.AckFrame{LargestAcked: 5, LowestAcked: 5}, 1, protocol.EncryptionForwardSecure, time.Now())
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 5, Largest: 5}}}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
})
@ -601,7 +633,8 @@ var _ = Describe("SentPacketHandler", func() {
cong.EXPECT().OnPacketAcked(protocol.PacketNumber(2), protocol.ByteCount(1), protocol.ByteCount(3)),
cong.EXPECT().OnPacketLost(protocol.PacketNumber(1), protocol.ByteCount(1), protocol.ByteCount(3)),
)
err := handler.ReceivedAck(&wire.AckFrame{LargestAcked: 2, LowestAcked: 2}, 1, protocol.EncryptionForwardSecure, time.Now())
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 2}}}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
})
@ -616,10 +649,12 @@ var _ = Describe("SentPacketHandler", func() {
cong.EXPECT().OnPacketAcked(protocol.PacketNumber(2), protocol.ByteCount(1), protocol.ByteCount(2)),
cong.EXPECT().OnPacketLost(protocol.PacketNumber(1), protocol.ByteCount(1), protocol.ByteCount(2)),
)
err := handler.ReceivedAck(&wire.AckFrame{LargestAcked: 2, LowestAcked: 2}, 1, protocol.EncryptionForwardSecure, time.Now())
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 2}}}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
// don't EXPECT any further calls to the congestion controller
err = handler.ReceivedAck(&wire.AckFrame{LargestAcked: 2, LowestAcked: 1}, 2, protocol.EncryptionForwardSecure, time.Now())
ack = &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 2}}}
err = handler.ReceivedAck(ack, 2, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
})
@ -636,7 +671,8 @@ var _ = Describe("SentPacketHandler", func() {
cong.EXPECT().OnPacketAcked(protocol.PacketNumber(2), protocol.ByteCount(1), protocol.ByteCount(4)),
cong.EXPECT().OnPacketLost(protocol.PacketNumber(1), protocol.ByteCount(1), protocol.ByteCount(4)),
)
err := handler.ReceivedAck(&wire.AckFrame{LargestAcked: 2, LowestAcked: 2}, 1, protocol.EncryptionForwardSecure, time.Now().Add(-30*time.Minute))
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 2}}}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now().Add(-30*time.Minute))
Expect(err).ToNot(HaveOccurred())
// receive the second ACK
gomock.InOrder(
@ -644,7 +680,8 @@ var _ = Describe("SentPacketHandler", func() {
cong.EXPECT().OnPacketAcked(protocol.PacketNumber(4), protocol.ByteCount(1), protocol.ByteCount(2)),
cong.EXPECT().OnPacketLost(protocol.PacketNumber(3), protocol.ByteCount(1), protocol.ByteCount(2)),
)
err = handler.ReceivedAck(&wire.AckFrame{LargestAcked: 4, LowestAcked: 4}, 2, protocol.EncryptionForwardSecure, time.Now())
ack = &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 4, Largest: 4}}}
err = handler.ReceivedAck(ack, 2, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
})
@ -799,7 +836,8 @@ var _ = Describe("SentPacketHandler", func() {
// Send a probe packet and receive an ACK for it.
// This verifies the RTO.
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 3}))
err = handler.ReceivedAck(&wire.AckFrame{LargestAcked: 3, LowestAcked: 3}, 1, protocol.EncryptionForwardSecure, time.Now())
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 3, Largest: 3}}}
err = handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
Expect(handler.packetHistory.Len()).To(BeZero())
Expect(handler.bytesInFlight).To(BeZero())
@ -829,7 +867,8 @@ var _ = Describe("SentPacketHandler", func() {
// Send a probe packet and receive an ACK for it.
// This verifies the RTO.
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 6}))
err := handler.ReceivedAck(&wire.AckFrame{LargestAcked: 6, LowestAcked: 6}, 1, protocol.EncryptionForwardSecure, time.Now())
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 6, Largest: 6}}}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
Expect(handler.packetHistory.Len()).To(BeZero())
Expect(handler.bytesInFlight).To(BeZero())
@ -843,7 +882,8 @@ var _ = Describe("SentPacketHandler", func() {
Expect(err).ToNot(HaveOccurred())
Expect(handler.DequeuePacketForRetransmission()).ToNot(BeNil())
handler.SentPacketsAsRetransmission([]*Packet{retransmittablePacket(&Packet{PacketNumber: 6})}, 5)
err = handler.ReceivedAck(&wire.AckFrame{LargestAcked: 5, LowestAcked: 5}, 1, protocol.EncryptionForwardSecure, time.Now())
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 5, Largest: 5}}}
err = handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now())
Expect(err).ToNot(HaveOccurred())
err = handler.OnAlarm()
Expect(err).ToNot(HaveOccurred())
@ -866,7 +906,8 @@ var _ = Describe("SentPacketHandler", func() {
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 2, SendTime: now.Add(-time.Second)}))
Expect(handler.lossTime.IsZero()).To(BeTrue())
err := handler.ReceivedAck(&wire.AckFrame{LargestAcked: 2, LowestAcked: 2}, 1, protocol.EncryptionForwardSecure, now)
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 2}}}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, now)
Expect(err).NotTo(HaveOccurred())
Expect(handler.DequeuePacketForRetransmission()).ToNot(BeNil())
Expect(handler.DequeuePacketForRetransmission()).To(BeNil())
@ -882,7 +923,8 @@ var _ = Describe("SentPacketHandler", func() {
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 3, SendTime: now.Add(-time.Second)}))
Expect(handler.lossTime.IsZero()).To(BeTrue())
err := handler.ReceivedAck(&wire.AckFrame{LargestAcked: 2, LowestAcked: 2}, 1, protocol.EncryptionForwardSecure, now.Add(-time.Second))
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 2}}}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, now.Add(-time.Second))
Expect(err).NotTo(HaveOccurred())
Expect(handler.rttStats.SmoothedRTT()).To(Equal(time.Second))
@ -916,7 +958,8 @@ var _ = Describe("SentPacketHandler", func() {
handler.SentPacket(handshakePacket(&Packet{PacketNumber: 4, SendTime: lastHandshakePacketSendTime}))
handler.SentPacket(retransmittablePacket(&Packet{PacketNumber: 5, SendTime: now}))
err := handler.ReceivedAck(createAck([]wire.AckRange{{Smallest: 1, Largest: 1}}), 1, protocol.EncryptionForwardSecure, now)
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, now)
// RTT is now 1 minute
Expect(handler.rttStats.SmoothedRTT()).To(Equal(time.Minute))
Expect(err).NotTo(HaveOccurred())
@ -944,7 +987,7 @@ var _ = Describe("SentPacketHandler", func() {
Frames: []wire.Frame{&streamFrame},
Length: 1,
})
ack := createAck([]wire.AckRange{{Smallest: 13, Largest: 13}})
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 13, Largest: 13}}}
err := handler.ReceivedAck(ack, 1, protocol.EncryptionSecure, time.Now())
Expect(err).To(MatchError("Received ACK with encryption level encrypted (not forward-secure) that acks a packet 13 (encryption level forward-secure)"))
})

View file

@ -30,8 +30,9 @@ func (s *stopWaitingManager) GetStopWaitingFrame(force bool) *wire.StopWaitingFr
}
func (s *stopWaitingManager) ReceivedAck(ack *wire.AckFrame) {
if ack.LargestAcked >= s.nextLeastUnacked {
s.nextLeastUnacked = ack.LargestAcked + 1
largestAcked := ack.LargestAcked()
if largestAcked >= s.nextLeastUnacked {
s.nextLeastUnacked = largestAcked + 1
}
}

View file

@ -18,37 +18,37 @@ var _ = Describe("StopWaitingManager", func() {
})
It("returns a StopWaitingFrame, when a new ACK arrives", func() {
manager.ReceivedAck(&wire.AckFrame{LargestAcked: 10})
manager.ReceivedAck(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}})
Expect(manager.GetStopWaitingFrame(false)).To(Equal(&wire.StopWaitingFrame{LeastUnacked: 11}))
})
It("does not decrease the LeastUnacked", func() {
manager.ReceivedAck(&wire.AckFrame{LargestAcked: 10})
manager.ReceivedAck(&wire.AckFrame{LargestAcked: 9})
manager.ReceivedAck(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}})
manager.ReceivedAck(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 9}}})
Expect(manager.GetStopWaitingFrame(false)).To(Equal(&wire.StopWaitingFrame{LeastUnacked: 11}))
})
It("does not send the same StopWaitingFrame twice", func() {
manager.ReceivedAck(&wire.AckFrame{LargestAcked: 10})
manager.ReceivedAck(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}})
Expect(manager.GetStopWaitingFrame(false)).ToNot(BeNil())
Expect(manager.GetStopWaitingFrame(false)).To(BeNil())
})
It("gets the same StopWaitingFrame twice, if forced", func() {
manager.ReceivedAck(&wire.AckFrame{LargestAcked: 10})
manager.ReceivedAck(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}})
Expect(manager.GetStopWaitingFrame(false)).ToNot(BeNil())
Expect(manager.GetStopWaitingFrame(true)).ToNot(BeNil())
Expect(manager.GetStopWaitingFrame(true)).ToNot(BeNil())
})
It("increases the LeastUnacked when a retransmission is queued", func() {
manager.ReceivedAck(&wire.AckFrame{LargestAcked: 10})
manager.ReceivedAck(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}})
manager.QueuedRetransmissionForPacketNumber(20)
Expect(manager.GetStopWaitingFrame(false)).To(Equal(&wire.StopWaitingFrame{LeastUnacked: 21}))
})
It("does not decrease the LeastUnacked when a retransmission is queued", func() {
manager.ReceivedAck(&wire.AckFrame{LargestAcked: 10})
manager.ReceivedAck(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}})
manager.QueuedRetransmissionForPacketNumber(9)
Expect(manager.GetStopWaitingFrame(false)).To(Equal(&wire.StopWaitingFrame{LeastUnacked: 11}))
})

View file

@ -14,9 +14,7 @@ const ackDelayExponent = 3
// An AckFrame is an ACK frame
type AckFrame struct {
LargestAcked protocol.PacketNumber
LowestAcked protocol.PacketNumber
AckRanges []AckRange // has to be ordered. The highest ACK range goes first, the lowest ACK range goes last
AckRanges []AckRange // has to be ordered. The highest ACK range goes first, the lowest ACK range goes last
// time when the LargestAcked was receiveid
// this field will not be set for received ACKs frames
@ -36,11 +34,11 @@ func parseAckFrame(r *bytes.Reader, version protocol.VersionNumber) (*AckFrame,
frame := &AckFrame{}
largestAcked, err := utils.ReadVarInt(r)
la, err := utils.ReadVarInt(r)
if err != nil {
return nil, err
}
frame.LargestAcked = protocol.PacketNumber(largestAcked)
largestAcked := protocol.PacketNumber(la)
delay, err := utils.ReadVarInt(r)
if err != nil {
return nil, err
@ -57,15 +55,13 @@ func parseAckFrame(r *bytes.Reader, version protocol.VersionNumber) (*AckFrame,
return nil, err
}
ackBlock := protocol.PacketNumber(ab)
if ackBlock > frame.LargestAcked {
if ackBlock > largestAcked {
return nil, errors.New("invalid first ACK range")
}
smallest := frame.LargestAcked - ackBlock
smallest := largestAcked - ackBlock
// read all the other ACK ranges
if numBlocks > 0 {
frame.AckRanges = append(frame.AckRanges, AckRange{Smallest: smallest, Largest: frame.LargestAcked})
}
frame.AckRanges = append(frame.AckRanges, AckRange{Smallest: smallest, Largest: largestAcked})
for i := uint64(0); i < numBlocks; i++ {
g, err := utils.ReadVarInt(r)
if err != nil {
@ -90,11 +86,9 @@ func parseAckFrame(r *bytes.Reader, version protocol.VersionNumber) (*AckFrame,
frame.AckRanges = append(frame.AckRanges, AckRange{Smallest: smallest, Largest: largest})
}
frame.LowestAcked = smallest
if !frame.validateAckRanges() {
return nil, errInvalidAckRanges
}
return frame, nil
}
@ -104,36 +98,31 @@ func (f *AckFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error
return f.writeLegacy(b, version)
}
largestAcked := f.AckRanges[0].Largest
lowestInFirstRange := f.AckRanges[0].Smallest
b.WriteByte(0xe)
utils.WriteVarInt(b, uint64(f.LargestAcked))
utils.WriteVarInt(b, uint64(largestAcked))
utils.WriteVarInt(b, encodeAckDelay(f.DelayTime))
// TODO: limit the number of ACK ranges, such that the frame doesn't grow larger than an upper bound
var lowestInFirstRange protocol.PacketNumber
if f.HasMissingRanges() {
utils.WriteVarInt(b, uint64(len(f.AckRanges)-1))
lowestInFirstRange = f.AckRanges[0].Smallest
} else {
utils.WriteVarInt(b, 0)
lowestInFirstRange = f.LowestAcked
}
utils.WriteVarInt(b, uint64(len(f.AckRanges)-1))
// write the first range
utils.WriteVarInt(b, uint64(f.LargestAcked-lowestInFirstRange))
utils.WriteVarInt(b, uint64(largestAcked-lowestInFirstRange))
// write all the other range
if !f.HasMissingRanges() {
return nil
}
var lowest protocol.PacketNumber
for i, ackRange := range f.AckRanges {
if i == 0 {
lowest = lowestInFirstRange
continue
if f.HasMissingRanges() {
var lowest protocol.PacketNumber
for i, ackRange := range f.AckRanges {
if i == 0 {
lowest = lowestInFirstRange
continue
}
utils.WriteVarInt(b, uint64(lowest-ackRange.Largest-2))
utils.WriteVarInt(b, uint64(ackRange.Largest-ackRange.Smallest))
lowest = ackRange.Smallest
}
utils.WriteVarInt(b, uint64(lowest-ackRange.Largest-2))
utils.WriteVarInt(b, uint64(ackRange.Largest-ackRange.Smallest))
lowest = ackRange.Smallest
}
return nil
}
@ -144,17 +133,12 @@ func (f *AckFrame) Length(version protocol.VersionNumber) protocol.ByteCount {
return f.lengthLegacy(version)
}
length := 1 + utils.VarIntLen(uint64(f.LargestAcked)) + utils.VarIntLen(encodeAckDelay(f.DelayTime))
largestAcked := f.AckRanges[0].Largest
length := 1 + utils.VarIntLen(uint64(largestAcked)) + utils.VarIntLen(encodeAckDelay(f.DelayTime))
var lowestInFirstRange protocol.PacketNumber
if f.HasMissingRanges() {
length += utils.VarIntLen(uint64(len(f.AckRanges) - 1))
lowestInFirstRange = f.AckRanges[0].Smallest
} else {
length += utils.VarIntLen(0)
lowestInFirstRange = f.LowestAcked
}
length += utils.VarIntLen(uint64(f.LargestAcked - lowestInFirstRange))
length += utils.VarIntLen(uint64(len(f.AckRanges) - 1))
lowestInFirstRange := f.AckRanges[0].Smallest
length += utils.VarIntLen(uint64(largestAcked - lowestInFirstRange))
if !f.HasMissingRanges() {
return length
@ -174,20 +158,11 @@ func (f *AckFrame) Length(version protocol.VersionNumber) protocol.ByteCount {
// HasMissingRanges returns if this frame reports any missing packets
func (f *AckFrame) HasMissingRanges() bool {
return len(f.AckRanges) > 0
return len(f.AckRanges) > 1
}
func (f *AckFrame) validateAckRanges() bool {
if len(f.AckRanges) == 0 {
return true
}
// if there are missing packets, there will always be at least 2 ACK ranges
if len(f.AckRanges) == 1 {
return false
}
if f.AckRanges[0].Largest != f.LargestAcked {
return false
}
@ -215,23 +190,29 @@ func (f *AckFrame) validateAckRanges() bool {
return true
}
// LargestAcked is the largest acked packet number
func (f *AckFrame) LargestAcked() protocol.PacketNumber {
return f.AckRanges[0].Largest
}
// LowestAcked is the lowest acked packet number
func (f *AckFrame) LowestAcked() protocol.PacketNumber {
return f.AckRanges[len(f.AckRanges)-1].Smallest
}
// AcksPacket determines if this ACK frame acks a certain packet number
func (f *AckFrame) AcksPacket(p protocol.PacketNumber) bool {
if p < f.LowestAcked || p > f.LargestAcked { // this is just a performance optimization
if p < f.LowestAcked() || p > f.LargestAcked() { // this is just a performance optimization
return false
}
if f.HasMissingRanges() {
// TODO: this could be implemented as a binary search
for _, ackRange := range f.AckRanges {
if p >= ackRange.Smallest && p <= ackRange.Largest {
return true
}
// TODO: this could be implemented as a binary search
for _, ackRange := range f.AckRanges {
if p >= ackRange.Smallest && p <= ackRange.Largest {
return true
}
return false
}
// if packet doesn't have missing ranges
return (p >= f.LowestAcked && p <= f.LargestAcked)
return false
}
func encodeAckDelay(delay time.Duration) uint64 {

View file

@ -9,11 +9,7 @@ import (
"github.com/lucas-clemente/quic-go/internal/utils"
)
var (
errInconsistentAckLargestAcked = errors.New("internal inconsistency: LargestAcked does not match ACK ranges")
errInconsistentAckLowestAcked = errors.New("internal inconsistency: LowestAcked does not match ACK ranges")
errInvalidAckRanges = errors.New("AckFrame: ACK frame contains invalid ACK ranges")
)
var errInvalidAckRanges = errors.New("AckFrame: ACK frame contains invalid ACK ranges")
func parseAckFrameLegacy(r *bytes.Reader, _ protocol.VersionNumber) (*AckFrame, error) {
frame := &AckFrame{}
@ -23,11 +19,7 @@ func parseAckFrameLegacy(r *bytes.Reader, _ protocol.VersionNumber) (*AckFrame,
return nil, err
}
hasMissingRanges := false
if typeByte&0x20 == 0x20 {
hasMissingRanges = true
}
hasMissingRanges := typeByte&0x20 == 0x20
largestAckedLen := 2 * ((typeByte & 0x0C) >> 2)
if largestAckedLen == 0 {
largestAckedLen = 1
@ -38,11 +30,11 @@ func parseAckFrameLegacy(r *bytes.Reader, _ protocol.VersionNumber) (*AckFrame,
missingSequenceNumberDeltaLen = 1
}
largestAcked, err := utils.BigEndian.ReadUintN(r, largestAckedLen)
la, err := utils.BigEndian.ReadUintN(r, largestAckedLen)
if err != nil {
return nil, err
}
frame.LargestAcked = protocol.PacketNumber(largestAcked)
largestAcked := protocol.PacketNumber(la)
delay, err := utils.BigEndian.ReadUfloat16(r)
if err != nil {
@ -62,11 +54,12 @@ func parseAckFrameLegacy(r *bytes.Reader, _ protocol.VersionNumber) (*AckFrame,
return nil, errInvalidAckRanges
}
ackBlockLength, err := utils.BigEndian.ReadUintN(r, missingSequenceNumberDeltaLen)
abl, err := utils.BigEndian.ReadUintN(r, missingSequenceNumberDeltaLen)
if err != nil {
return nil, err
}
if frame.LargestAcked > 0 && ackBlockLength < 1 {
ackBlockLength := protocol.PacketNumber(abl)
if largestAcked > 0 && ackBlockLength < 1 {
return nil, errors.New("invalid first ACK range")
}
@ -76,8 +69,8 @@ func parseAckFrameLegacy(r *bytes.Reader, _ protocol.VersionNumber) (*AckFrame,
if hasMissingRanges {
ackRange := AckRange{
Smallest: protocol.PacketNumber(largestAcked-ackBlockLength) + 1,
Largest: frame.LargestAcked,
Smallest: largestAcked - ackBlockLength + 1,
Largest: largestAcked,
}
frame.AckRanges = append(frame.AckRanges, ackRange)
@ -90,29 +83,27 @@ func parseAckFrameLegacy(r *bytes.Reader, _ protocol.VersionNumber) (*AckFrame,
return nil, err
}
ackBlockLength, err = utils.BigEndian.ReadUintN(r, missingSequenceNumberDeltaLen)
abl, err := utils.BigEndian.ReadUintN(r, missingSequenceNumberDeltaLen)
if err != nil {
return nil, err
}
length := protocol.PacketNumber(ackBlockLength)
ackBlockLength := protocol.PacketNumber(abl)
if inLongBlock {
frame.AckRanges[len(frame.AckRanges)-1].Smallest -= protocol.PacketNumber(gap) + length
frame.AckRanges[len(frame.AckRanges)-1].Smallest -= protocol.PacketNumber(gap) + ackBlockLength
frame.AckRanges[len(frame.AckRanges)-1].Largest -= protocol.PacketNumber(gap)
} else {
lastRangeComplete = false
ackRange := AckRange{
Largest: frame.AckRanges[len(frame.AckRanges)-1].Smallest - protocol.PacketNumber(gap) - 1,
}
ackRange.Smallest = ackRange.Largest - length + 1
ackRange.Smallest = ackRange.Largest - ackBlockLength + 1
frame.AckRanges = append(frame.AckRanges, ackRange)
}
if length > 0 {
if ackBlockLength > 0 {
lastRangeComplete = true
}
inLongBlock = (ackBlockLength == 0)
}
@ -121,13 +112,11 @@ func parseAckFrameLegacy(r *bytes.Reader, _ protocol.VersionNumber) (*AckFrame,
if !lastRangeComplete {
frame.AckRanges = frame.AckRanges[:len(frame.AckRanges)-1]
}
frame.LowestAcked = frame.AckRanges[len(frame.AckRanges)-1].Smallest
} else {
if frame.LargestAcked == 0 {
frame.LowestAcked = 0
} else {
frame.LowestAcked = protocol.PacketNumber(largestAcked + 1 - ackBlockLength)
frame.AckRanges = make([]AckRange, 1)
if largestAcked != 0 {
frame.AckRanges[0].Largest = largestAcked
frame.AckRanges[0].Smallest = largestAcked + 1 - ackBlockLength
}
}
@ -171,7 +160,8 @@ func parseAckFrameLegacy(r *bytes.Reader, _ protocol.VersionNumber) (*AckFrame,
}
func (f *AckFrame) writeLegacy(b *bytes.Buffer, _ protocol.VersionNumber) error {
largestAckedLen := protocol.GetPacketNumberLength(f.LargestAcked)
largestAcked := f.LargestAcked()
largestAckedLen := protocol.GetPacketNumberLength(largestAcked)
typeByte := uint8(0x40)
@ -192,13 +182,13 @@ func (f *AckFrame) writeLegacy(b *bytes.Buffer, _ protocol.VersionNumber) error
switch largestAckedLen {
case protocol.PacketNumberLen1:
b.WriteByte(uint8(f.LargestAcked))
b.WriteByte(uint8(largestAcked))
case protocol.PacketNumberLen2:
utils.BigEndian.WriteUint16(b, uint16(f.LargestAcked))
utils.BigEndian.WriteUint16(b, uint16(largestAcked))
case protocol.PacketNumberLen4:
utils.BigEndian.WriteUint32(b, uint32(f.LargestAcked))
utils.BigEndian.WriteUint32(b, uint32(largestAcked))
case protocol.PacketNumberLen6:
utils.BigEndian.WriteUint48(b, uint64(f.LargestAcked)&(1<<48-1))
utils.BigEndian.WriteUint48(b, uint64(largestAcked)&(1<<48-1))
}
f.DelayTime = time.Since(f.PacketReceivedTime)
@ -216,15 +206,9 @@ func (f *AckFrame) writeLegacy(b *bytes.Buffer, _ protocol.VersionNumber) error
var firstAckBlockLength protocol.PacketNumber
if !f.HasMissingRanges() {
firstAckBlockLength = f.LargestAcked - f.LowestAcked + 1
firstAckBlockLength = largestAcked - f.LowestAcked() + 1
} else {
if f.LargestAcked != f.AckRanges[0].Largest {
return errInconsistentAckLargestAcked
}
if f.LowestAcked != f.AckRanges[len(f.AckRanges)-1].Smallest {
return errInconsistentAckLowestAcked
}
firstAckBlockLength = f.LargestAcked - f.AckRanges[0].Smallest + 1
firstAckBlockLength = largestAcked - f.AckRanges[0].Smallest + 1
numRangesWritten++
}
@ -310,7 +294,7 @@ func (f *AckFrame) writeLegacy(b *bytes.Buffer, _ protocol.VersionNumber) error
func (f *AckFrame) lengthLegacy(_ protocol.VersionNumber) protocol.ByteCount {
length := protocol.ByteCount(1 + 2 + 1) // 1 TypeByte, 2 ACK delay time, 1 Num Timestamp
length += protocol.ByteCount(protocol.GetPacketNumberLength(f.LargestAcked))
length += protocol.ByteCount(protocol.GetPacketNumberLength(f.LargestAcked()))
missingSequenceNumberDeltaLen := protocol.ByteCount(f.getMissingSequenceNumberDeltaLen())
@ -364,7 +348,7 @@ func (f *AckFrame) getMissingSequenceNumberDeltaLen() protocol.PacketNumberLen {
}
}
} else {
maxRangeLength = f.LargestAcked - f.LowestAcked + 1
maxRangeLength = f.LargestAcked() - f.LowestAcked() + 1
}
if maxRangeLength <= 0xFF {

View file

@ -21,8 +21,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x1c)))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(1)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0x1c)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(1)))
Expect(frame.HasMissingRanges()).To(BeFalse())
Expect(b.Len()).To(BeZero())
})
@ -36,8 +36,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0)))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(0)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(0)))
Expect(frame.HasMissingRanges()).To(BeFalse())
Expect(b.Len()).To(BeZero())
})
@ -51,8 +51,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x10)))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(0x10)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0x10)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(0x10)))
Expect(frame.HasMissingRanges()).To(BeFalse())
Expect(b.Len()).To(BeZero())
})
@ -66,8 +66,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x10)))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(0)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0x10)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(0)))
Expect(frame.HasMissingRanges()).To(BeFalse())
Expect(b.Len()).To(BeZero())
})
@ -121,7 +121,7 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(3)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(3)))
Expect(frame.DelayTime).To(Equal(142 * time.Microsecond))
})
@ -160,8 +160,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x1337)))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(0x1337 - 0x9 + 1)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0x1337)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(0x1337 - 0x9 + 1)))
Expect(frame.HasMissingRanges()).To(BeFalse())
Expect(b.Len()).To(BeZero())
})
@ -175,8 +175,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0xdecafbad)))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(0xdecafbad - 5 + 1)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0xdecafbad)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(0xdecafbad - 5 + 1)))
Expect(frame.HasMissingRanges()).To(BeFalse())
Expect(b.Len()).To(BeZero())
})
@ -190,8 +190,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0xdeadbeefcafe)))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(0xdeadbeefcafe - 5 + 1)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0xdeadbeefcafe)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(0xdeadbeefcafe - 5 + 1)))
Expect(frame.HasMissingRanges()).To(BeFalse())
Expect(b.Len()).To(BeZero())
})
@ -209,12 +209,12 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x18)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0x18)))
Expect(frame.HasMissingRanges()).To(BeTrue())
Expect(frame.AckRanges).To(HaveLen(2))
Expect(frame.AckRanges[0]).To(Equal(AckRange{Smallest: 0x18 - 0x3 + 1, Largest: 0x18}))
Expect(frame.AckRanges[1]).To(Equal(AckRange{Smallest: (0x18 - 0x3 + 1) - (0x2 + 1) - (0x10 - 1), Largest: (0x18 - 0x3 + 1) - (0x2 + 1)}))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(4)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(4)))
Expect(b.Len()).To(BeZero())
})
@ -259,7 +259,7 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x27)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0x27)))
Expect(frame.HasMissingRanges()).To(BeTrue())
Expect(frame.AckRanges).To(HaveLen(7))
Expect(frame.AckRanges[0]).To(Equal(AckRange{Smallest: 31, Largest: 0x27}))
@ -269,7 +269,7 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
Expect(frame.AckRanges[4]).To(Equal(AckRange{Smallest: 23, Largest: 23}))
Expect(frame.AckRanges[5]).To(Equal(AckRange{Smallest: 21, Largest: 21}))
Expect(frame.AckRanges[6]).To(Equal(AckRange{Smallest: 1, Largest: 19}))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(1)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(1)))
Expect(b.Len()).To(BeZero())
})
@ -286,14 +286,14 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x52)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0x52)))
Expect(frame.HasMissingRanges()).To(BeTrue())
Expect(frame.AckRanges).To(HaveLen(4))
Expect(frame.AckRanges[0]).To(Equal(AckRange{Smallest: 60, Largest: 0x52}))
Expect(frame.AckRanges[1]).To(Equal(AckRange{Smallest: 34, Largest: 49}))
Expect(frame.AckRanges[2]).To(Equal(AckRange{Smallest: 22, Largest: 29}))
Expect(frame.AckRanges[3]).To(Equal(AckRange{Smallest: 2, Largest: 19}))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(2)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(2)))
Expect(b.Len()).To(BeZero())
})
@ -310,12 +310,12 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x115)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0x115)))
Expect(frame.HasMissingRanges()).To(BeTrue())
Expect(frame.AckRanges).To(HaveLen(2))
Expect(frame.AckRanges[0]).To(Equal(AckRange{Smallest: 20 + 255, Largest: 0x115}))
Expect(frame.AckRanges[1]).To(Equal(AckRange{Smallest: 1, Largest: 19}))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(1)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(1)))
Expect(b.Len()).To(BeZero())
})
@ -332,12 +332,12 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x114)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0x114)))
Expect(frame.HasMissingRanges()).To(BeTrue())
Expect(frame.AckRanges).To(HaveLen(2))
Expect(frame.AckRanges[0]).To(Equal(AckRange{Smallest: 20 + 256, Largest: 0x114}))
Expect(frame.AckRanges[1]).To(Equal(AckRange{Smallest: 1, Largest: 19}))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(1)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(1)))
Expect(b.Len()).To(BeZero())
})
@ -359,7 +359,7 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x39b)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0x39b)))
Expect(frame.HasMissingRanges()).To(BeTrue())
Expect(frame.AckRanges).To(HaveLen(3))
Expect(frame.AckRanges[0]).To(Equal(AckRange{Smallest: 20 + 3*301, Largest: 20 + 3*301}))
@ -381,12 +381,12 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x144)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0x144)))
Expect(frame.HasMissingRanges()).To(BeTrue())
Expect(frame.AckRanges).To(HaveLen(2))
Expect(frame.AckRanges[0]).To(Equal(AckRange{Smallest: 300, Largest: 0x144}))
Expect(frame.AckRanges[1]).To(Equal(AckRange{Smallest: 1, Largest: 19}))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(1)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(1)))
Expect(b.Len()).To(BeZero())
})
@ -411,12 +411,12 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x95b)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0x95b)))
Expect(frame.HasMissingRanges()).To(BeTrue())
Expect(frame.AckRanges).To(HaveLen(2))
Expect(frame.AckRanges[0]).To(Equal(AckRange{Smallest: 2365, Largest: 0x95b}))
Expect(frame.AckRanges[1]).To(Equal(AckRange{Smallest: 1, Largest: 19}))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(1)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(1)))
Expect(b.Len()).To(BeZero())
})
@ -437,14 +437,14 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0x966)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0x966)))
Expect(frame.HasMissingRanges()).To(BeTrue())
Expect(frame.AckRanges).To(HaveLen(4))
Expect(frame.AckRanges[0]).To(Equal(AckRange{Smallest: 2400, Largest: 0x966}))
Expect(frame.AckRanges[1]).To(Equal(AckRange{Smallest: 1250, Largest: 1899}))
Expect(frame.AckRanges[2]).To(Equal(AckRange{Smallest: 820, Largest: 1049}))
Expect(frame.AckRanges[3]).To(Equal(AckRange{Smallest: 1, Largest: 19}))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(1)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(1)))
Expect(b.Len()).To(BeZero())
})
@ -459,7 +459,7 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0xdeadbeefcafe)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0xdeadbeefcafe)))
Expect(frame.HasMissingRanges()).To(BeTrue())
Expect(frame.AckRanges).To(HaveLen(2))
Expect(frame.AckRanges[0]).To(Equal(AckRange{Smallest: 0xdeadbeefcafe - 0x1337 + 1, Largest: 0xdeadbeefcafe}))
@ -477,7 +477,7 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
})
frame, err := parseAckFrame(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(0xdeadbeefcafe)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(0xdeadbeefcafe)))
Expect(frame.HasMissingRanges()).To(BeTrue())
Expect(frame.AckRanges).To(HaveLen(2))
Expect(frame.AckRanges[0]).To(Equal(AckRange{Smallest: 0xdeadbeefcafe - 0x1337 + 1, Largest: 0xdeadbeefcafe}))
@ -497,69 +497,63 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
Context("self-consistency", func() {
It("writes a simple ACK frame", func() {
frameOrig := &AckFrame{
LargestAcked: 1,
LowestAcked: 1,
AckRanges: []AckRange{{Smallest: 1, Largest: 1}},
}
err := frameOrig.Write(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.HasMissingRanges()).To(BeFalse())
Expect(r.Len()).To(BeZero())
})
It("writes an ACK that also acks packet 0", func() {
frameOrig := &AckFrame{
LargestAcked: 1,
LowestAcked: 0,
AckRanges: []AckRange{{Smallest: 0, Largest: 1}},
}
err := frameOrig.Write(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.HasMissingRanges()).To(BeFalse())
Expect(r.Len()).To(BeZero())
})
It("writes the correct block length in a simple ACK frame", func() {
frameOrig := &AckFrame{
LargestAcked: 20,
LowestAcked: 10,
AckRanges: []AckRange{{Smallest: 10, Largest: 20}},
}
err := frameOrig.Write(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.LowestAcked()).To(Equal(frameOrig.LowestAcked()))
Expect(frame.HasMissingRanges()).To(BeFalse())
Expect(r.Len()).To(BeZero())
})
It("writes a simple ACK frame with a high packet number", func() {
frameOrig := &AckFrame{
LargestAcked: 0xdeadbeefcafe,
LowestAcked: 0xdeadbeefcafe,
AckRanges: []AckRange{{Smallest: 0xdeadbeefcafe, Largest: 0xdeadbeefcafe}},
}
err := frameOrig.Write(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.HasMissingRanges()).To(BeFalse())
Expect(r.Len()).To(BeZero())
})
It("writes an ACK frame with one packet missing", func() {
frameOrig := &AckFrame{
LargestAcked: 40,
LowestAcked: 0,
AckRanges: []AckRange{
{Smallest: 25, Largest: 40},
{Smallest: 0, Largest: 23},
@ -570,16 +564,14 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.LowestAcked()).To(Equal(frameOrig.LowestAcked()))
Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges))
Expect(r.Len()).To(BeZero())
})
It("writes an ACK frame with multiple missing packets", func() {
frameOrig := &AckFrame{
LargestAcked: 25,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 22, Largest: 25},
{Smallest: 15, Largest: 18},
@ -592,43 +584,15 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.LowestAcked()).To(Equal(frameOrig.LowestAcked()))
Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges))
Expect(r.Len()).To(BeZero())
})
It("rejects a frame with incorrect LargestObserved value", func() {
frame := &AckFrame{
LargestAcked: 26,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 12, Largest: 25},
{Smallest: 1, Largest: 10},
},
}
err := frame.Write(b, versionBigEndian)
Expect(err).To(MatchError(errInconsistentAckLargestAcked))
})
It("rejects a frame with incorrect LargestObserved value", func() {
frame := &AckFrame{
LargestAcked: 25,
LowestAcked: 2,
AckRanges: []AckRange{
{Smallest: 12, Largest: 25},
{Smallest: 1, Largest: 10},
},
}
err := frame.Write(b, versionBigEndian)
Expect(err).To(MatchError(errInconsistentAckLowestAcked))
})
Context("longer gaps between ACK blocks", func() {
It("only writes one block for 254 lost packets", func() {
frameOrig := &AckFrame{
LargestAcked: 300,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 20 + 254, Largest: 300},
{Smallest: 1, Largest: 19},
@ -640,14 +604,12 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges))
})
It("only writes one block for 255 lost packets", func() {
frameOrig := &AckFrame{
LargestAcked: 300,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 20 + 255, Largest: 300},
{Smallest: 1, Largest: 19},
@ -659,14 +621,12 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges))
})
It("writes two blocks for 256 lost packets", func() {
frameOrig := &AckFrame{
LargestAcked: 300,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 20 + 256, Largest: 300},
{Smallest: 1, Largest: 19},
@ -678,14 +638,12 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges))
})
It("writes two blocks for 510 lost packets", func() {
frameOrig := &AckFrame{
LargestAcked: 600,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 20 + 510, Largest: 600},
{Smallest: 1, Largest: 19},
@ -697,14 +655,12 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges))
})
It("writes three blocks for 511 lost packets", func() {
frameOrig := &AckFrame{
LargestAcked: 600,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 20 + 511, Largest: 600},
{Smallest: 1, Largest: 19},
@ -716,14 +672,12 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges))
})
It("writes three blocks for 512 lost packets", func() {
frameOrig := &AckFrame{
LargestAcked: 600,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 20 + 512, Largest: 600},
{Smallest: 1, Largest: 19},
@ -735,14 +689,12 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges))
})
It("writes multiple blocks for a lot of lost packets", func() {
frameOrig := &AckFrame{
LargestAcked: 3000,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 2900, Largest: 3000},
{Smallest: 1, Largest: 19},
@ -753,14 +705,12 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges))
})
It("writes multiple longer blocks for 256 lost packets", func() {
frameOrig := &AckFrame{
LargestAcked: 3600,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 2900, Largest: 3600},
{Smallest: 1000, Largest: 2500},
@ -772,7 +722,7 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges))
})
})
@ -780,8 +730,7 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
Context("largest acked length", func() {
It("writes a 1 largest acked", func() {
frameOrig := &AckFrame{
LargestAcked: 200,
LowestAcked: 1,
AckRanges: []AckRange{{Smallest: 1, Largest: 200}},
}
err := frameOrig.Write(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
@ -789,15 +738,14 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.LowestAcked()).To(Equal(frameOrig.LowestAcked()))
Expect(r.Len()).To(BeZero())
})
It("writes a 2 byte largest acked", func() {
frameOrig := &AckFrame{
LargestAcked: 0x100,
LowestAcked: 1,
AckRanges: []AckRange{{Smallest: 1, Largest: 0x100}},
}
err := frameOrig.Write(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
@ -805,15 +753,14 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.LowestAcked()).To(Equal(frameOrig.LowestAcked()))
Expect(r.Len()).To(BeZero())
})
It("writes a 4 byte largest acked", func() {
frameOrig := &AckFrame{
LargestAcked: 0x10000,
LowestAcked: 1,
AckRanges: []AckRange{{Smallest: 1, Largest: 0x10000}},
}
err := frameOrig.Write(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
@ -821,15 +768,14 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.LowestAcked()).To(Equal(frameOrig.LowestAcked()))
Expect(r.Len()).To(BeZero())
})
It("writes a 6 byte largest acked", func() {
frameOrig := &AckFrame{
LargestAcked: 0x100000000,
LowestAcked: 1,
AckRanges: []AckRange{{Smallest: 1, Largest: 0x100000000}},
}
err := frameOrig.Write(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
@ -837,8 +783,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.LowestAcked()).To(Equal(frameOrig.LowestAcked()))
Expect(r.Len()).To(BeZero())
})
})
@ -846,8 +792,6 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
Context("ack block length", func() {
It("writes a 1 byte ack block length, if all ACK blocks are short", func() {
frameOrig := &AckFrame{
LargestAcked: 5001,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 5000, Largest: 5001},
{Smallest: 250, Largest: 300},
@ -860,16 +804,14 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.LowestAcked()).To(Equal(frameOrig.LowestAcked()))
Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges))
Expect(r.Len()).To(BeZero())
})
It("writes a 2 byte ack block length, for a frame with one ACK block", func() {
frameOrig := &AckFrame{
LargestAcked: 10000,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 9990, Largest: 10000},
{Smallest: 1, Largest: 9988},
@ -881,16 +823,14 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.LowestAcked()).To(Equal(frameOrig.LowestAcked()))
Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges))
Expect(r.Len()).To(BeZero())
})
It("writes a 2 byte ack block length, for a frame with multiple ACK blocks", func() {
frameOrig := &AckFrame{
LargestAcked: 10000,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 9990, Largest: 10000},
{Smallest: 1, Largest: 256},
@ -902,16 +842,14 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.LowestAcked()).To(Equal(frameOrig.LowestAcked()))
Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges))
Expect(r.Len()).To(BeZero())
})
It("writes a 4 byte ack block length, for a frame with single ACK blocks", func() {
frameOrig := &AckFrame{
LargestAcked: 0xdeadbeef,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 9990, Largest: 0xdeadbeef},
{Smallest: 1, Largest: 9988},
@ -923,16 +861,14 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.LowestAcked()).To(Equal(frameOrig.LowestAcked()))
Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges))
Expect(r.Len()).To(BeZero())
})
It("writes a 4 byte ack block length, for a frame with multiple ACK blocks", func() {
frameOrig := &AckFrame{
LargestAcked: 0xdeadbeef,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 9990, Largest: 0xdeadbeef},
{Smallest: 1, Largest: 256},
@ -944,16 +880,14 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.LowestAcked()).To(Equal(frameOrig.LowestAcked()))
Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges))
Expect(r.Len()).To(BeZero())
})
It("writes a 6 byte ack block length, for a frame with a single ACK blocks", func() {
frameOrig := &AckFrame{
LargestAcked: 0xdeadbeefcafe,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 9990, Largest: 0xdeadbeefcafe},
{Smallest: 1, Largest: 9988},
@ -965,16 +899,14 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.LowestAcked()).To(Equal(frameOrig.LowestAcked()))
Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges))
Expect(r.Len()).To(BeZero())
})
It("writes a 6 byte ack block length, for a frame with multiple ACK blocks", func() {
frameOrig := &AckFrame{
LargestAcked: 0xdeadbeefcafe,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 9990, Largest: 0xdeadbeefcafe},
{Smallest: 1, Largest: 256},
@ -986,8 +918,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LowestAcked).To(Equal(frameOrig.LowestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.LowestAcked()).To(Equal(frameOrig.LowestAcked()))
Expect(frame.AckRanges).To(Equal(frameOrig.AckRanges))
Expect(r.Len()).To(BeZero())
})
@ -999,18 +931,14 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
for i := 1; i <= 300; i++ {
ackRanges[300-i] = AckRange{Smallest: protocol.PacketNumber(3 * i), Largest: protocol.PacketNumber(3*i + 1)}
}
frameOrig := &AckFrame{
LargestAcked: ackRanges[0].Largest,
LowestAcked: ackRanges[len(ackRanges)-1].Smallest,
AckRanges: ackRanges,
}
frameOrig := &AckFrame{AckRanges: ackRanges}
err := frameOrig.Write(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LowestAcked).To(Equal(ackRanges[254].Smallest))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.LowestAcked()).To(Equal(ackRanges[254].Smallest))
Expect(frame.AckRanges).To(HaveLen(0xFF))
Expect(frame.validateAckRanges()).To(BeTrue())
})
@ -1021,18 +949,14 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
for i := 1; i <= 100; i++ {
ackRanges[100-i] = AckRange{Smallest: protocol.PacketNumber(1000 * i), Largest: protocol.PacketNumber(1000*i + 1)}
}
frameOrig := &AckFrame{
LargestAcked: ackRanges[0].Largest,
LowestAcked: ackRanges[len(ackRanges)-1].Smallest,
AckRanges: ackRanges,
}
frameOrig := &AckFrame{AckRanges: ackRanges}
err := frameOrig.Write(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LowestAcked).To(Equal(ackRanges[255/4].Smallest))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.LowestAcked()).To(Equal(ackRanges[255/4].Smallest))
Expect(frame.validateAckRanges()).To(BeTrue())
})
@ -1042,19 +966,15 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
{Smallest: 1 * 255 * 200, Largest: 1*255*200 + 1},
{Smallest: 1, Largest: 2},
}
frameOrig := &AckFrame{
LargestAcked: ackRanges[0].Largest,
LowestAcked: ackRanges[len(ackRanges)-1].Smallest,
AckRanges: ackRanges,
}
frameOrig := &AckFrame{AckRanges: ackRanges}
err := frameOrig.Write(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
r := bytes.NewReader(b.Bytes())
frame, err := parseAckFrame(r, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked))
Expect(frame.LargestAcked()).To(Equal(frameOrig.LargestAcked()))
Expect(frame.AckRanges).To(HaveLen(2))
Expect(frame.LowestAcked).To(Equal(ackRanges[1].Smallest))
Expect(frame.LowestAcked()).To(Equal(ackRanges[1].Smallest))
Expect(frame.validateAckRanges()).To(BeTrue())
})
})
@ -1063,7 +983,7 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
Context("min length", func() {
It("has proper min length", func() {
f := &AckFrame{
LargestAcked: 1,
AckRanges: []AckRange{{Smallest: 1, Largest: 1}},
}
err := f.Write(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
@ -1072,7 +992,7 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
It("has proper min length with a large LargestObserved", func() {
f := &AckFrame{
LargestAcked: 0xDEADBEEFCAFE,
AckRanges: []AckRange{{Smallest: 1, Largest: 0xdeadbeefcafe}},
}
err := f.Write(b, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
@ -1081,8 +1001,6 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
It("has the proper min length for an ACK with missing packets", func() {
f := &AckFrame{
LargestAcked: 2000,
LowestAcked: 10,
AckRanges: []AckRange{
{Smallest: 1000, Largest: 2000},
{Smallest: 50, Largest: 900},
@ -1096,8 +1014,6 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
It("has the proper min length for an ACK with long gaps of missing packets", func() {
f := &AckFrame{
LargestAcked: 2000,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 1500, Largest: 2000},
{Smallest: 290, Largest: 295},
@ -1112,8 +1028,6 @@ var _ = Describe("ACK Frame (for gQUIC)", func() {
It("has the proper min length for an ACK with a long ACK range", func() {
largestAcked := protocol.PacketNumber(2 + 0xFFFFFF)
f := &AckFrame{
LargestAcked: largestAcked,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 1500, Largest: largestAcked},
{Smallest: 290, Largest: 295},

View file

@ -21,8 +21,8 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
b := bytes.NewReader(data)
frame, err := parseAckFrame(b, versionIETFFrames)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(100)))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(90)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(100)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(90)))
Expect(frame.HasMissingRanges()).To(BeFalse())
Expect(b.Len()).To(BeZero())
})
@ -36,8 +36,8 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
b := bytes.NewReader(data)
frame, err := parseAckFrame(b, versionIETFFrames)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(55)))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(55)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(55)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(55)))
Expect(frame.HasMissingRanges()).To(BeFalse())
Expect(b.Len()).To(BeZero())
})
@ -51,8 +51,8 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
b := bytes.NewReader(data)
frame, err := parseAckFrame(b, versionIETFFrames)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(20)))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(0)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(20)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(0)))
Expect(frame.HasMissingRanges()).To(BeFalse())
Expect(b.Len()).To(BeZero())
})
@ -79,8 +79,8 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
b := bytes.NewReader(data)
frame, err := parseAckFrame(b, versionIETFFrames)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(1000)))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(750)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(1000)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(750)))
Expect(frame.HasMissingRanges()).To(BeTrue())
Expect(frame.AckRanges).To(Equal([]AckRange{
{Largest: 1000, Smallest: 900},
@ -102,8 +102,8 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
b := bytes.NewReader(data)
frame, err := parseAckFrame(b, versionIETFFrames)
Expect(err).ToNot(HaveOccurred())
Expect(frame.LargestAcked).To(Equal(protocol.PacketNumber(100)))
Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(94)))
Expect(frame.LargestAcked()).To(Equal(protocol.PacketNumber(100)))
Expect(frame.LowestAcked()).To(Equal(protocol.PacketNumber(94)))
Expect(frame.HasMissingRanges()).To(BeTrue())
Expect(frame.AckRanges).To(Equal([]AckRange{
{Largest: 100, Smallest: 100},
@ -134,9 +134,8 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
It("writes a frame that acks a single packet", func() {
buf := &bytes.Buffer{}
f := &AckFrame{
LargestAcked: 0xdeadbeef,
LowestAcked: 0xdeadbeef,
DelayTime: 18 * time.Second,
AckRanges: []AckRange{{Smallest: 0xdeadbeef, Largest: 0xdeadbeef}},
DelayTime: 18 * time.Second,
}
err := f.Write(buf, versionIETFFrames)
Expect(err).ToNot(HaveOccurred())
@ -152,8 +151,7 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
It("writes a frame that acks many packets", func() {
buf := &bytes.Buffer{}
f := &AckFrame{
LargestAcked: 0xdecafbad,
LowestAcked: 0x1337,
AckRanges: []AckRange{{Smallest: 0x1337, Largest: 0xdeadbeef}},
}
err := f.Write(buf, versionIETFFrames)
Expect(err).ToNot(HaveOccurred())
@ -169,8 +167,6 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
It("writes a frame with a a single gap", func() {
buf := &bytes.Buffer{}
f := &AckFrame{
LargestAcked: 1000,
LowestAcked: 100,
AckRanges: []AckRange{
{Smallest: 400, Largest: 1000},
{Smallest: 100, Largest: 200},
@ -191,8 +187,6 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
It("writes a frame with multiple ranges", func() {
buf := &bytes.Buffer{}
f := &AckFrame{
LargestAcked: 10,
LowestAcked: 1,
AckRanges: []AckRange{
{Smallest: 10, Largest: 10},
{Smallest: 8, Largest: 8},
@ -214,33 +208,19 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
})
Context("ACK range validator", func() {
It("rejects ACKs without ranges", func() {
Expect((&AckFrame{}).validateAckRanges()).To(BeFalse())
})
It("accepts an ACK without NACK Ranges", func() {
ack := AckFrame{LargestAcked: 7}
ack := AckFrame{
AckRanges: []AckRange{{Smallest: 1, Largest: 7}},
}
Expect(ack.validateAckRanges()).To(BeTrue())
})
It("rejects ACK ranges with a single range", func() {
ack := AckFrame{
LargestAcked: 10,
AckRanges: []AckRange{{Smallest: 1, Largest: 10}},
}
Expect(ack.validateAckRanges()).To(BeFalse())
})
It("rejects ACK ranges with Largest of the first range unequal to LargestObserved", func() {
ack := AckFrame{
LargestAcked: 10,
AckRanges: []AckRange{
{Smallest: 8, Largest: 9},
{Smallest: 2, Largest: 3},
},
}
Expect(ack.validateAckRanges()).To(BeFalse())
})
It("rejects ACK ranges with Smallest greater than Largest", func() {
ack := AckFrame{
LargestAcked: 10,
AckRanges: []AckRange{
{Smallest: 8, Largest: 10},
{Smallest: 4, Largest: 3},
@ -249,20 +229,8 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
Expect(ack.validateAckRanges()).To(BeFalse())
})
It("rejects ACK ranges with Smallest greater than LargestObserved", func() {
ack := AckFrame{
LargestAcked: 5,
AckRanges: []AckRange{
{Smallest: 4, Largest: 10},
{Smallest: 1, Largest: 2},
},
}
Expect(ack.validateAckRanges()).To(BeFalse())
})
It("rejects ACK ranges in the wrong order", func() {
ack := AckFrame{
LargestAcked: 7,
AckRanges: []AckRange{
{Smallest: 2, Largest: 2},
{Smallest: 6, Largest: 7},
@ -273,7 +241,6 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
It("rejects with overlapping ACK ranges", func() {
ack := AckFrame{
LargestAcked: 7,
AckRanges: []AckRange{
{Smallest: 5, Largest: 7},
{Smallest: 2, Largest: 5},
@ -284,7 +251,6 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
It("rejects ACK ranges that are part of a larger ACK range", func() {
ack := AckFrame{
LargestAcked: 7,
AckRanges: []AckRange{
{Smallest: 4, Largest: 7},
{Smallest: 5, Largest: 6},
@ -295,7 +261,6 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
It("rejects with directly adjacent ACK ranges", func() {
ack := AckFrame{
LargestAcked: 7,
AckRanges: []AckRange{
{Smallest: 5, Largest: 7},
{Smallest: 2, Largest: 4},
@ -306,7 +271,6 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
It("accepts an ACK with one lost packet", func() {
ack := AckFrame{
LargestAcked: 10,
AckRanges: []AckRange{
{Smallest: 5, Largest: 10},
{Smallest: 1, Largest: 3},
@ -317,7 +281,6 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
It("accepts an ACK with multiple lost packets", func() {
ack := AckFrame{
LargestAcked: 20,
AckRanges: []AckRange{
{Smallest: 15, Largest: 20},
{Smallest: 10, Largest: 12},
@ -331,8 +294,7 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
Context("check if ACK frame acks a certain packet", func() {
It("works with an ACK without any ranges", func() {
f := AckFrame{
LowestAcked: 5,
LargestAcked: 10,
AckRanges: []AckRange{{Smallest: 5, Largest: 10}},
}
Expect(f.AcksPacket(1)).To(BeFalse())
Expect(f.AcksPacket(4)).To(BeFalse())
@ -345,8 +307,6 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() {
It("works with an ACK with multiple ACK ranges", func() {
f := AckFrame{
LowestAcked: 5,
LargestAcked: 20,
AckRanges: []AckRange{
{Smallest: 15, Largest: 20},
{Smallest: 5, Largest: 8},

View file

@ -144,17 +144,14 @@ var _ = Describe("Frame parsing", func() {
})
It("unpacks ACK frames", func() {
f := &AckFrame{
LargestAcked: 0x13,
LowestAcked: 1,
}
f := &AckFrame{AckRanges: []AckRange{{Smallest: 1, Largest: 0x13}}}
err := f.Write(buf, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
frame, err := ParseNextFrame(bytes.NewReader(buf.Bytes()), nil, versionBigEndian)
Expect(err).ToNot(HaveOccurred())
Expect(frame).ToNot(BeNil())
Expect(frame).To(BeAssignableToTypeOf(f))
Expect(frame.(*AckFrame).LargestAcked).To(Equal(protocol.PacketNumber(0x13)))
Expect(frame.(*AckFrame).LargestAcked()).To(Equal(protocol.PacketNumber(0x13)))
})
It("errors on invalid type", func() {
@ -282,17 +279,14 @@ var _ = Describe("Frame parsing", func() {
})
It("unpacks ACK frames", func() {
f := &AckFrame{
LargestAcked: 0x13,
LowestAcked: 1,
}
f := &AckFrame{AckRanges: []AckRange{{Smallest: 1, Largest: 0x13}}}
err := f.Write(buf, versionIETFFrames)
Expect(err).ToNot(HaveOccurred())
frame, err := ParseNextFrame(bytes.NewReader(buf.Bytes()), nil, versionIETFFrames)
Expect(err).ToNot(HaveOccurred())
Expect(frame).ToNot(BeNil())
Expect(frame).To(BeAssignableToTypeOf(f))
Expect(frame.(*AckFrame).LargestAcked).To(Equal(protocol.PacketNumber(0x13)))
Expect(frame.(*AckFrame).LargestAcked()).To(Equal(protocol.PacketNumber(0x13)))
})
It("errors on invalid type", func() {

View file

@ -21,7 +21,11 @@ func LogFrame(logger utils.Logger, frame Frame, sent bool) {
logger.Debugf("\t%s &wire.StopWaitingFrame{LeastUnacked: 0x%x}", dir, f.LeastUnacked)
}
case *AckFrame:
logger.Debugf("\t%s &wire.AckFrame{LargestAcked: 0x%x, LowestAcked: 0x%x, AckRanges: %#v, DelayTime: %s}", dir, f.LargestAcked, f.LowestAcked, f.AckRanges, f.DelayTime.String())
if len(f.AckRanges) > 1 {
logger.Debugf("\t%s &wire.AckFrame{LargestAcked: 0x%x, LowestAcked: 0x%x, AckRanges: %#v, DelayTime: %s}", dir, f.LargestAcked(), f.LowestAcked(), f.AckRanges, f.DelayTime.String())
} else {
logger.Debugf("\t%s &wire.AckFrame{LargestAcked: 0x%x, LowestAcked: 0x%x, DelayTime: %s}", dir, f.LargestAcked(), f.LowestAcked(), f.DelayTime.String())
}
default:
logger.Debugf("\t%s %#v", dir, frame)
}

View file

@ -56,14 +56,25 @@ var _ = Describe("Frame logging", func() {
Expect(buf.Bytes()).To(ContainSubstring("\t<- &wire.StreamFrame{StreamID: 42, FinBit: false, Offset: 0x1337, Data length: 0x100, Offset + Data length: 0x1437}\n"))
})
It("logs ACK frames", func() {
It("logs ACK frames without missing packets", func() {
frame := &AckFrame{
LargestAcked: 0x1337,
LowestAcked: 0x42,
DelayTime: 1 * time.Millisecond,
AckRanges: []AckRange{{Smallest: 0x42, Largest: 0x1337}},
DelayTime: 1 * time.Millisecond,
}
LogFrame(logger, frame, false)
Expect(buf.Bytes()).To(ContainSubstring("\t<- &wire.AckFrame{LargestAcked: 0x1337, LowestAcked: 0x42, AckRanges: []wire.AckRange(nil), DelayTime: 1ms}\n"))
Expect(buf.String()).To(ContainSubstring("\t<- &wire.AckFrame{LargestAcked: 0x1337, LowestAcked: 0x42, DelayTime: 1ms}\n"))
})
It("logs ACK frames with missing packets", func() {
frame := &AckFrame{
AckRanges: []AckRange{
{Smallest: 0x5, Largest: 0x8},
{Smallest: 0x2, Largest: 0x3},
},
DelayTime: 12 * time.Millisecond,
}
LogFrame(logger, frame, false)
Expect(buf.String()).To(ContainSubstring("\t<- &wire.AckFrame{LargestAcked: 0x8, LowestAcked: 0x2, AckRanges: []wire.AckRange{wire.AckRange{Smallest:0x5, Largest:0x8}, wire.AckRange{Smallest:0x2, Largest:0x3}}, DelayTime: 12ms}\n"))
})
It("logs incoming StopWaiting frames", func() {

View file

@ -2,7 +2,6 @@ package quic
import (
"bytes"
"math"
"net"
"github.com/golang/mock/gomock"
@ -340,7 +339,7 @@ var _ = Describe("Packet packer", func() {
})
It("packs many control frames into 1 packets", func() {
f := &wire.AckFrame{LargestAcked: 1}
f := &wire.AckFrame{AckRanges: []wire.AckRange{{Largest: 1, Smallest: 1}}}
b := &bytes.Buffer{}
err := f.Write(b, packer.version)
Expect(err).ToNot(HaveOccurred())
@ -398,7 +397,7 @@ var _ = Describe("Packet packer", func() {
mockStreamFramer.EXPECT().HasCryptoStreamData().Times(protocol.MaxNonRetransmittableAcks)
mockStreamFramer.EXPECT().PopStreamFrames(gomock.Any()).Times(protocol.MaxNonRetransmittableAcks)
for i := 0; i < protocol.MaxNonRetransmittableAcks; i++ {
packer.QueueControlFrame(&wire.AckFrame{})
packer.QueueControlFrame(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}})
p, err := packer.PackPacket()
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
@ -410,13 +409,13 @@ var _ = Describe("Packet packer", func() {
sendMaxNumNonRetransmittableAcks()
mockStreamFramer.EXPECT().HasCryptoStreamData().Times(2)
mockStreamFramer.EXPECT().PopStreamFrames(gomock.Any()).Times(2)
packer.QueueControlFrame(&wire.AckFrame{})
packer.QueueControlFrame(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}})
p, err := packer.PackPacket()
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
Expect(p.frames).To(ContainElement(&wire.PingFrame{}))
// make sure the next packet doesn't contain another PING
packer.QueueControlFrame(&wire.AckFrame{})
packer.QueueControlFrame(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 2}}})
p, err = packer.PackPacket()
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
@ -430,7 +429,7 @@ var _ = Describe("Packet packer", func() {
p, err := packer.PackPacket()
Expect(err).ToNot(HaveOccurred())
Expect(p).To(BeNil())
packer.QueueControlFrame(&wire.AckFrame{})
packer.QueueControlFrame(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}})
p, err = packer.PackPacket()
Expect(err).ToNot(HaveOccurred())
Expect(p.frames).To(HaveLen(2))
@ -442,7 +441,7 @@ var _ = Describe("Packet packer", func() {
mockStreamFramer.EXPECT().HasCryptoStreamData()
mockStreamFramer.EXPECT().PopStreamFrames(gomock.Any())
packer.QueueControlFrame(&wire.MaxDataFrame{})
packer.QueueControlFrame(&wire.AckFrame{})
packer.QueueControlFrame(&wire.StopWaitingFrame{})
p, err := packer.PackPacket()
Expect(p).ToNot(BeNil())
Expect(err).ToNot(HaveOccurred())
@ -592,7 +591,7 @@ var _ = Describe("Packet packer", func() {
mockStreamFramer.EXPECT().HasCryptoStreamData()
// don't expect a call to mockStreamFramer.PopStreamFrames
packer.cryptoSetup.(*mockCryptoSetup).encLevelSeal = protocol.EncryptionUnencrypted
ack := &wire.AckFrame{LargestAcked: 10}
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Largest: 10, Smallest: 1}}}
packer.QueueControlFrame(ack)
p, err := packer.PackPacket()
Expect(err).ToNot(HaveOccurred())
@ -603,7 +602,7 @@ var _ = Describe("Packet packer", func() {
It("packs a single ACK", func() {
mockStreamFramer.EXPECT().HasCryptoStreamData()
mockStreamFramer.EXPECT().PopStreamFrames(gomock.Any())
ack := &wire.AckFrame{LargestAcked: 42}
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Largest: 42, Smallest: 1}}}
packer.QueueControlFrame(ack)
p, err := packer.PackPacket()
Expect(err).NotTo(HaveOccurred())
@ -614,7 +613,7 @@ var _ = Describe("Packet packer", func() {
It("does not return nil if we only have a single ACK but request it to be sent", func() {
mockStreamFramer.EXPECT().HasCryptoStreamData()
mockStreamFramer.EXPECT().PopStreamFrames(gomock.Any())
ack := &wire.AckFrame{}
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 1}}}
packer.QueueControlFrame(ack)
p, err := packer.PackPacket()
Expect(err).NotTo(HaveOccurred())
@ -890,21 +889,23 @@ var _ = Describe("Packet packer", func() {
Context("packing ACK packets", func() {
It("packs ACK packets", func() {
packer.QueueControlFrame(&wire.AckFrame{})
packer.QueueControlFrame(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}})
p, err := packer.PackAckPacket()
Expect(err).NotTo(HaveOccurred())
Expect(p.frames).To(Equal([]wire.Frame{&wire.AckFrame{DelayTime: math.MaxInt64}}))
Expect(p.frames).To(HaveLen(1))
Expect(p.frames[0]).To(BeAssignableToTypeOf(&wire.AckFrame{}))
ack := p.frames[0].(*wire.AckFrame)
Expect(ack.LargestAcked()).To(Equal(protocol.PacketNumber(10)))
})
It("packs ACK packets with STOP_WAITING frames", func() {
packer.QueueControlFrame(&wire.AckFrame{})
packer.QueueControlFrame(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 10}}})
packer.QueueControlFrame(&wire.StopWaitingFrame{})
p, err := packer.PackAckPacket()
Expect(err).NotTo(HaveOccurred())
Expect(p.frames).To(Equal([]wire.Frame{
&wire.AckFrame{DelayTime: math.MaxInt64},
&wire.StopWaitingFrame{PacketNumber: 1, PacketNumberLen: 2},
}))
Expect(p.frames).To(HaveLen(2))
Expect(p.frames[0]).To(BeAssignableToTypeOf(&wire.AckFrame{}))
Expect(p.frames[1]).To(Equal(&wire.StopWaitingFrame{PacketNumber: 1, PacketNumberLen: 2}))
})
})

View file

@ -260,7 +260,7 @@ var _ = Describe("Session", func() {
Context("handling ACK frames", func() {
It("informs the SentPacketHandler about ACKs", func() {
f := &wire.AckFrame{LargestAcked: 3, LowestAcked: 2}
f := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 3}}}
sph := mockackhandler.NewMockSentPacketHandler(mockCtrl)
sph.EXPECT().ReceivedAck(f, protocol.PacketNumber(42), protocol.EncryptionSecure, gomock.Any())
sph.EXPECT().GetLowestPacketNotConfirmedAcked()
@ -271,6 +271,7 @@ var _ = Describe("Session", func() {
})
It("tells the ReceivedPacketHandler to ignore low ranges", func() {
ack := &wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 2, Largest: 3}}}
sph := mockackhandler.NewMockSentPacketHandler(mockCtrl)
sph.EXPECT().ReceivedAck(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any())
sph.EXPECT().GetLowestPacketNotConfirmedAcked().Return(protocol.PacketNumber(0x42))
@ -278,7 +279,7 @@ var _ = Describe("Session", func() {
rph := mockackhandler.NewMockReceivedPacketHandler(mockCtrl)
rph.EXPECT().IgnoreBelow(protocol.PacketNumber(0x42))
sess.receivedPacketHandler = rph
err := sess.handleAckFrame(&wire.AckFrame{LargestAcked: 3, LowestAcked: 2}, protocol.EncryptionUnencrypted)
err := sess.handleAckFrame(ack, protocol.EncryptionUnencrypted)
Expect(err).ToNot(HaveOccurred())
})
})
@ -1253,11 +1254,11 @@ var _ = Describe("Session", func() {
sph.EXPECT().ShouldSendNumPackets().Return(1)
sph.EXPECT().SentPacket(gomock.Any()).Do(func(p *ackhandler.Packet) {
Expect(p.Frames[0]).To(BeAssignableToTypeOf(&wire.AckFrame{}))
Expect(p.Frames[0].(*wire.AckFrame).LargestAcked).To(Equal(protocol.PacketNumber(0x1337)))
Expect(p.Frames[0].(*wire.AckFrame).LargestAcked()).To(Equal(protocol.PacketNumber(0x1337)))
})
sess.sentPacketHandler = sph
rph := mockackhandler.NewMockReceivedPacketHandler(mockCtrl)
rph.EXPECT().GetAckFrame().Return(&wire.AckFrame{LargestAcked: 0x1337})
rph.EXPECT().GetAckFrame().Return(&wire.AckFrame{AckRanges: []wire.AckRange{{Smallest: 1, Largest: 0x1337}}})
rph.EXPECT().GetAlarmTimeout().Return(time.Now().Add(10 * time.Millisecond))
rph.EXPECT().GetAlarmTimeout().Return(time.Now().Add(time.Hour))
sess.receivedPacketHandler = rph
@ -1681,23 +1682,6 @@ var _ = Describe("Session", func() {
})
})
Context("ignoring errors", func() {
It("ignores duplicate acks", func() {
sess.sentPacketHandler.SentPacket(&ackhandler.Packet{
PacketNumber: 1,
Length: 1,
})
err := sess.handleFrames([]wire.Frame{&wire.AckFrame{
LargestAcked: 1,
}}, protocol.EncryptionUnspecified)
Expect(err).NotTo(HaveOccurred())
err = sess.handleFrames([]wire.Frame{&wire.AckFrame{
LargestAcked: 1,
}}, protocol.EncryptionUnspecified)
Expect(err).NotTo(HaveOccurred())
})
})
It("returns the local address", func() {
addr := &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: 1337}
mconn.localAddr = addr