diff --git a/internal/ackhandler/received_packet_handler.go b/internal/ackhandler/received_packet_handler.go index 10200f4c..a3af8502 100644 --- a/internal/ackhandler/received_packet_handler.go +++ b/internal/ackhandler/received_packet_handler.go @@ -99,7 +99,7 @@ func (h *receivedPacketHandler) hasNewMissingPackets() bool { return false } highestRange := h.packetHistory.GetHighestAckRange() - return highestRange.First >= h.lastAck.LargestAcked && highestRange.Len() <= maxPacketsAfterNewMissing + return highestRange.Smallest >= h.lastAck.LargestAcked && highestRange.Len() <= maxPacketsAfterNewMissing } // maybeQueueAck queues an ACK, if necessary. @@ -166,7 +166,7 @@ func (h *receivedPacketHandler) GetAckFrame() *wire.AckFrame { ackRanges := h.packetHistory.GetAckRanges() ack := &wire.AckFrame{ LargestAcked: h.largestObserved, - LowestAcked: ackRanges[len(ackRanges)-1].First, + LowestAcked: ackRanges[len(ackRanges)-1].Smallest, PacketReceivedTime: h.largestObservedReceivedTime, } diff --git a/internal/ackhandler/received_packet_handler_test.go b/internal/ackhandler/received_packet_handler_test.go index 21a6a74b..6acd3c8a 100644 --- a/internal/ackhandler/received_packet_handler_test.go +++ b/internal/ackhandler/received_packet_handler_test.go @@ -251,8 +251,8 @@ var _ = Describe("receivedPacketHandler", func() { Expect(ack.LargestAcked).To(Equal(protocol.PacketNumber(4))) Expect(ack.LowestAcked).To(Equal(protocol.PacketNumber(1))) Expect(ack.AckRanges).To(Equal([]wire.AckRange{ - {First: 4, Last: 4}, - {First: 1, Last: 1}, + {Smallest: 4, Largest: 4}, + {Smallest: 1, Largest: 1}, })) }) @@ -268,8 +268,8 @@ var _ = Describe("receivedPacketHandler", func() { Expect(ack.LargestAcked).To(Equal(protocol.PacketNumber(3))) Expect(ack.LowestAcked).To(Equal(protocol.PacketNumber(0))) Expect(ack.AckRanges).To(Equal([]wire.AckRange{ - {First: 3, Last: 3}, - {First: 0, Last: 1}, + {Smallest: 3, Largest: 3}, + {Smallest: 0, Largest: 1}, })) }) diff --git a/internal/ackhandler/received_packet_history.go b/internal/ackhandler/received_packet_history.go index ba119544..758286df 100644 --- a/internal/ackhandler/received_packet_history.go +++ b/internal/ackhandler/received_packet_history.go @@ -104,7 +104,7 @@ func (h *receivedPacketHistory) GetAckRanges() []wire.AckRange { ackRanges := make([]wire.AckRange, h.ranges.Len()) i := 0 for el := h.ranges.Back(); el != nil; el = el.Prev() { - ackRanges[i] = wire.AckRange{First: el.Value.Start, Last: el.Value.End} + ackRanges[i] = wire.AckRange{Smallest: el.Value.Start, Largest: el.Value.End} i++ } return ackRanges @@ -114,8 +114,8 @@ func (h *receivedPacketHistory) GetHighestAckRange() wire.AckRange { ackRange := wire.AckRange{} if h.ranges.Len() > 0 { r := h.ranges.Back().Value - ackRange.First = r.Start - ackRange.Last = r.End + ackRange.Smallest = r.Start + ackRange.Largest = r.End } return ackRange } diff --git a/internal/ackhandler/received_packet_history_test.go b/internal/ackhandler/received_packet_history_test.go index ed9789b3..4a24b95c 100644 --- a/internal/ackhandler/received_packet_history_test.go +++ b/internal/ackhandler/received_packet_history_test.go @@ -208,7 +208,7 @@ var _ = Describe("receivedPacketHistory", func() { hist.ReceivedPacket(5) ackRanges := hist.GetAckRanges() Expect(ackRanges).To(HaveLen(1)) - Expect(ackRanges[0]).To(Equal(wire.AckRange{First: 4, Last: 5})) + Expect(ackRanges[0]).To(Equal(wire.AckRange{Smallest: 4, Largest: 5})) }) It("gets multiple ACK ranges", func() { @@ -221,9 +221,9 @@ var _ = Describe("receivedPacketHistory", func() { hist.ReceivedPacket(2) ackRanges := hist.GetAckRanges() Expect(ackRanges).To(HaveLen(3)) - Expect(ackRanges[0]).To(Equal(wire.AckRange{First: 10, Last: 11})) - Expect(ackRanges[1]).To(Equal(wire.AckRange{First: 4, Last: 6})) - Expect(ackRanges[2]).To(Equal(wire.AckRange{First: 1, Last: 2})) + Expect(ackRanges[0]).To(Equal(wire.AckRange{Smallest: 10, Largest: 11})) + Expect(ackRanges[1]).To(Equal(wire.AckRange{Smallest: 4, Largest: 6})) + Expect(ackRanges[2]).To(Equal(wire.AckRange{Smallest: 1, Largest: 2})) }) }) @@ -235,14 +235,14 @@ var _ = Describe("receivedPacketHistory", func() { It("gets a single ACK range", func() { hist.ReceivedPacket(4) hist.ReceivedPacket(5) - Expect(hist.GetHighestAckRange()).To(Equal(wire.AckRange{First: 4, Last: 5})) + Expect(hist.GetHighestAckRange()).To(Equal(wire.AckRange{Smallest: 4, Largest: 5})) }) It("gets the highest of multiple ACK ranges", func() { hist.ReceivedPacket(3) hist.ReceivedPacket(6) hist.ReceivedPacket(7) - Expect(hist.GetHighestAckRange()).To(Equal(wire.AckRange{First: 6, Last: 7})) + Expect(hist.GetHighestAckRange()).To(Equal(wire.AckRange{Smallest: 6, Largest: 7})) }) }) }) diff --git a/internal/ackhandler/sent_packet_handler.go b/internal/ackhandler/sent_packet_handler.go index 72ab4df8..3ab5f980 100644 --- a/internal/ackhandler/sent_packet_handler.go +++ b/internal/ackhandler/sent_packet_handler.go @@ -251,14 +251,14 @@ func (h *sentPacketHandler) determineNewlyAckedPackets(ackFrame *wire.AckFrame) if ackFrame.HasMissingRanges() { ackRange := ackFrame.AckRanges[len(ackFrame.AckRanges)-1-ackRangeIndex] - for p.PacketNumber > ackRange.Last && ackRangeIndex < len(ackFrame.AckRanges)-1 { + for p.PacketNumber > ackRange.Largest && ackRangeIndex < len(ackFrame.AckRanges)-1 { ackRangeIndex++ ackRange = ackFrame.AckRanges[len(ackFrame.AckRanges)-1-ackRangeIndex] } - if p.PacketNumber >= ackRange.First { // packet i contained in ACK range - if p.PacketNumber > ackRange.Last { - return false, fmt.Errorf("BUG: ackhandler would have acked wrong packet 0x%x, while evaluating range 0x%x -> 0x%x", p.PacketNumber, ackRange.First, ackRange.Last) + if p.PacketNumber >= ackRange.Smallest { // packet i contained in ACK range + if p.PacketNumber > ackRange.Largest { + return false, fmt.Errorf("BUG: ackhandler would have acked wrong packet 0x%x, while evaluating range 0x%x -> 0x%x", p.PacketNumber, ackRange.Smallest, ackRange.Largest) } ackedPackets = append(ackedPackets, p) } diff --git a/internal/ackhandler/sent_packet_handler_test.go b/internal/ackhandler/sent_packet_handler_test.go index ee2aae04..b1dc3364 100644 --- a/internal/ackhandler/sent_packet_handler_test.go +++ b/internal/ackhandler/sent_packet_handler_test.go @@ -42,11 +42,11 @@ func handshakePacket(p *Packet) *Packet { func createAck(ranges []wire.AckRange) *wire.AckFrame { sort.Slice(ranges, func(i, j int) bool { - return ranges[i].First > ranges[j].First + return ranges[i].Smallest > ranges[j].Smallest }) ack := &wire.AckFrame{ - LowestAcked: ranges[len(ranges)-1].First, - LargestAcked: ranges[0].Last, + LowestAcked: ranges[len(ranges)-1].Smallest, + LargestAcked: ranges[0].Largest, } if len(ranges) > 1 { ack.AckRanges = ranges @@ -210,13 +210,13 @@ var _ = Describe("SentPacketHandler", func() { }) It("rejects ACKs for skipped packets", func() { - ack := createAck([]wire.AckRange{{First: 10, Last: 12}}) + ack := createAck([]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{{First: 10, Last: 10}, {First: 12, Last: 12}}) + ack := createAck([]wire.AckRange{{Smallest: 10, Largest: 10}, {Smallest: 12, Largest: 12}}) err := handler.ReceivedAck(ack, 1337, protocol.EncryptionForwardSecure, time.Now()) Expect(err).ToNot(HaveOccurred()) Expect(handler.largestAcked).ToNot(BeZero()) @@ -237,15 +237,15 @@ var _ = Describe("SentPacketHandler", func() { Context("ACK validation", func() { It("accepts ACKs sent in packet 0", func() { - ack := createAck([]wire.AckRange{{First: 0, Last: 5}}) + ack := createAck([]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{{First: 0, Last: 3}}) - ack2 := createAck([]wire.AckRange{{First: 0, Last: 4}}) + ack1 := createAck([]wire.AckRange{{Smallest: 0, Largest: 3}}) + ack2 := createAck([]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 +258,8 @@ var _ = Describe("SentPacketHandler", func() { It("rejects out of order ACKs", func() { // acks packets 0, 1, 2, 3 - ack1 := createAck([]wire.AckRange{{First: 0, Last: 3}}) - ack2 := createAck([]wire.AckRange{{First: 0, Last: 4}}) + ack1 := createAck([]wire.AckRange{{Smallest: 0, Largest: 3}}) + ack2 := createAck([]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 +270,14 @@ var _ = Describe("SentPacketHandler", func() { }) It("rejects ACKs with a too high LargestAcked packet number", func() { - ack := createAck([]wire.AckRange{{First: 0, Last: 9999}}) + ack := createAck([]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{{First: 1, Last: 3}}) + ack := createAck([]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 +290,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{{First: 0, Last: 5}}) + ack := createAck([]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 +299,7 @@ var _ = Describe("SentPacketHandler", func() { }) It("acks packet 0", func() { - ack := createAck([]wire.AckRange{{First: 0, Last: 0}}) + ack := createAck([]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,14 +307,14 @@ var _ = Describe("SentPacketHandler", func() { }) It("handles an ACK frame with one missing packet range", func() { - ack := createAck([]wire.AckRange{{First: 1, Last: 3}, {First: 6, Last: 9}}) // lose 4 and 5 + ack := createAck([]wire.AckRange{{Smallest: 1, Largest: 3}, {Smallest: 6, Largest: 9}}) // lose 4 and 5 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{{First: 3, Last: 8}}) + ack := createAck([]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}) @@ -322,10 +322,10 @@ var _ = Describe("SentPacketHandler", func() { It("handles an ACK with multiple missing packet ranges", func() { ack := createAck([]wire.AckRange{ // packets 2, 4 and 5, and 8 were lost - {First: 9, Last: 9}, - {First: 6, Last: 7}, - {First: 3, Last: 3}, - {First: 1, Last: 1}, + {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()) @@ -333,12 +333,12 @@ var _ = Describe("SentPacketHandler", func() { }) It("processes an ACK frame that would be sent after a late arrival of a packet", func() { - ack1 := createAck([]wire.AckRange{{First: 1, Last: 2}, {First: 4, Last: 6}}) // 3 lost + ack1 := createAck([]wire.AckRange{{Smallest: 1, Largest: 2}, {Smallest: 4, Largest: 6}}) // 3 lost 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{{First: 1, Last: 6}}) // now ack 3 + ack2 := createAck([]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 +346,12 @@ 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{{First: 0, Last: 2}, {First: 4, Last: 6}}) + ack1 := createAck([]wire.AckRange{{Smallest: 0, Largest: 2}, {Smallest: 4, Largest: 6}}) 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{{First: 1, Last: 7}}) + ack2 := createAck([]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,15 +359,15 @@ var _ = Describe("SentPacketHandler", func() { }) It("processes an ACK that contains old ACK ranges", func() { - ack1 := createAck([]wire.AckRange{{First: 1, Last: 6}}) + ack1 := createAck([]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{ - {First: 1, Last: 1}, - {First: 3, Last: 3}, - {First: 8, Last: 8}, + {Smallest: 1, Largest: 1}, + {Smallest: 3, Largest: 3}, + {Smallest: 8, Largest: 8}, }) err = handler.ReceivedAck(ack2, 2, protocol.EncryptionForwardSecure, time.Now()) Expect(err).ToNot(HaveOccurred()) @@ -419,25 +419,25 @@ var _ = Describe("SentPacketHandler", func() { }) It("determines which ACK we have received an ACK for", func() { - err := handler.ReceivedAck(createAck([]wire.AckRange{{First: 13, Last: 15}}), 1, protocol.EncryptionForwardSecure, time.Now()) + err := handler.ReceivedAck(createAck([]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{{First: 13, Last: 13}}), 1, protocol.EncryptionForwardSecure, time.Now()) + err := handler.ReceivedAck(createAck([]wire.AckRange{{Smallest: 13, Largest: 13}}), 1, protocol.EncryptionForwardSecure, time.Now()) Expect(err).ToNot(HaveOccurred()) Expect(handler.GetLowestPacketNotConfirmedAcked()).To(Equal(protocol.PacketNumber(101))) - err = handler.ReceivedAck(createAck([]wire.AckRange{{First: 15, Last: 15}}), 2, protocol.EncryptionForwardSecure, time.Now()) + err = handler.ReceivedAck(createAck([]wire.AckRange{{Smallest: 15, Largest: 15}}), 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{{First: 14, Last: 14}}), 1, protocol.EncryptionForwardSecure, time.Now()) + err := handler.ReceivedAck(createAck([]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{{First: 13, Last: 13}}), 2, protocol.EncryptionForwardSecure, time.Now()) + err = handler.ReceivedAck(createAck([]wire.AckRange{{Smallest: 13, Largest: 13}}), 2, protocol.EncryptionForwardSecure, time.Now()) Expect(err).ToNot(HaveOccurred()) Expect(handler.GetLowestPacketNotConfirmedAcked()).To(Equal(protocol.PacketNumber(201))) }) @@ -474,7 +474,7 @@ var _ = Describe("SentPacketHandler", func() { losePacket(5) handler.SentPacketsAsRetransmission([]*Packet{retransmittablePacket(&Packet{PacketNumber: 7, Length: 11})}, 5) // ack 5 and 7 - ack := createAck([]wire.AckRange{{First: 5, Last: 5}, {First: 7, Last: 7}}) + ack := createAck([]wire.AckRange{{Smallest: 5, Largest: 5}, {Smallest: 7, Largest: 7}}) err := handler.ReceivedAck(ack, 1, protocol.EncryptionForwardSecure, time.Now()) Expect(err).ToNot(HaveOccurred()) Expect(handler.packetHistory.Len()).To(BeZero()) @@ -916,7 +916,7 @@ 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{{First: 1, Last: 1}}), 1, protocol.EncryptionForwardSecure, now) + err := handler.ReceivedAck(createAck([]wire.AckRange{{Smallest: 1, Largest: 1}}), 1, protocol.EncryptionForwardSecure, now) // RTT is now 1 minute Expect(handler.rttStats.SmoothedRTT()).To(Equal(time.Minute)) Expect(err).NotTo(HaveOccurred()) @@ -944,7 +944,7 @@ var _ = Describe("SentPacketHandler", func() { Frames: []wire.Frame{&streamFrame}, Length: 1, }) - ack := createAck([]wire.AckRange{{First: 13, Last: 13}}) + ack := createAck([]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)")) }) diff --git a/internal/wire/ack_frame.go b/internal/wire/ack_frame.go index 1a95bb9f..110c5396 100644 --- a/internal/wire/ack_frame.go +++ b/internal/wire/ack_frame.go @@ -64,7 +64,7 @@ func parseAckFrame(r *bytes.Reader, version protocol.VersionNumber) (*AckFrame, // read all the other ACK ranges if numBlocks > 0 { - frame.AckRanges = append(frame.AckRanges, AckRange{First: smallest, Last: frame.LargestAcked}) + frame.AckRanges = append(frame.AckRanges, AckRange{Smallest: smallest, Largest: frame.LargestAcked}) } for i := uint64(0); i < numBlocks; i++ { g, err := utils.ReadVarInt(r) @@ -87,7 +87,7 @@ func parseAckFrame(r *bytes.Reader, version protocol.VersionNumber) (*AckFrame, return nil, errInvalidAckRanges } smallest = largest - ackBlock - frame.AckRanges = append(frame.AckRanges, AckRange{First: smallest, Last: largest}) + frame.AckRanges = append(frame.AckRanges, AckRange{Smallest: smallest, Largest: largest}) } frame.LowestAcked = smallest @@ -112,7 +112,7 @@ func (f *AckFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error var lowestInFirstRange protocol.PacketNumber if f.HasMissingRanges() { utils.WriteVarInt(b, uint64(len(f.AckRanges)-1)) - lowestInFirstRange = f.AckRanges[0].First + lowestInFirstRange = f.AckRanges[0].Smallest } else { utils.WriteVarInt(b, 0) lowestInFirstRange = f.LowestAcked @@ -131,9 +131,9 @@ func (f *AckFrame) Write(b *bytes.Buffer, version protocol.VersionNumber) error lowest = lowestInFirstRange continue } - utils.WriteVarInt(b, uint64(lowest-ackRange.Last-2)) - utils.WriteVarInt(b, uint64(ackRange.Last-ackRange.First)) - lowest = ackRange.First + utils.WriteVarInt(b, uint64(lowest-ackRange.Largest-2)) + utils.WriteVarInt(b, uint64(ackRange.Largest-ackRange.Smallest)) + lowest = ackRange.Smallest } return nil } @@ -149,7 +149,7 @@ func (f *AckFrame) Length(version protocol.VersionNumber) protocol.ByteCount { var lowestInFirstRange protocol.PacketNumber if f.HasMissingRanges() { length += utils.VarIntLen(uint64(len(f.AckRanges) - 1)) - lowestInFirstRange = f.AckRanges[0].First + lowestInFirstRange = f.AckRanges[0].Smallest } else { length += utils.VarIntLen(0) lowestInFirstRange = f.LowestAcked @@ -162,12 +162,12 @@ func (f *AckFrame) Length(version protocol.VersionNumber) protocol.ByteCount { var lowest protocol.PacketNumber for i, ackRange := range f.AckRanges { if i == 0 { - lowest = ackRange.First + lowest = ackRange.Smallest continue } - length += utils.VarIntLen(uint64(lowest - ackRange.Last - 2)) - length += utils.VarIntLen(uint64(ackRange.Last - ackRange.First)) - lowest = ackRange.First + length += utils.VarIntLen(uint64(lowest - ackRange.Largest - 2)) + length += utils.VarIntLen(uint64(ackRange.Largest - ackRange.Smallest)) + lowest = ackRange.Smallest } return length } @@ -187,13 +187,13 @@ func (f *AckFrame) validateAckRanges() bool { return false } - if f.AckRanges[0].Last != f.LargestAcked { + if f.AckRanges[0].Largest != f.LargestAcked { return false } // check the validity of every single ACK range for _, ackRange := range f.AckRanges { - if ackRange.First > ackRange.Last { + if ackRange.Smallest > ackRange.Largest { return false } } @@ -204,10 +204,10 @@ func (f *AckFrame) validateAckRanges() bool { continue } lastAckRange := f.AckRanges[i-1] - if lastAckRange.First <= ackRange.First { + if lastAckRange.Smallest <= ackRange.Smallest { return false } - if lastAckRange.First <= ackRange.Last+1 { + if lastAckRange.Smallest <= ackRange.Largest+1 { return false } } @@ -224,7 +224,7 @@ func (f *AckFrame) AcksPacket(p protocol.PacketNumber) bool { if f.HasMissingRanges() { // TODO: this could be implemented as a binary search for _, ackRange := range f.AckRanges { - if p >= ackRange.First && p <= ackRange.Last { + if p >= ackRange.Smallest && p <= ackRange.Largest { return true } } diff --git a/internal/wire/ack_frame_legacy.go b/internal/wire/ack_frame_legacy.go index 1f1c22e9..e4c0a5d2 100644 --- a/internal/wire/ack_frame_legacy.go +++ b/internal/wire/ack_frame_legacy.go @@ -76,8 +76,8 @@ func parseAckFrameLegacy(r *bytes.Reader, _ protocol.VersionNumber) (*AckFrame, if hasMissingRanges { ackRange := AckRange{ - First: protocol.PacketNumber(largestAcked-ackBlockLength) + 1, - Last: frame.LargestAcked, + Smallest: protocol.PacketNumber(largestAcked-ackBlockLength) + 1, + Largest: frame.LargestAcked, } frame.AckRanges = append(frame.AckRanges, ackRange) @@ -98,14 +98,14 @@ func parseAckFrameLegacy(r *bytes.Reader, _ protocol.VersionNumber) (*AckFrame, length := protocol.PacketNumber(ackBlockLength) if inLongBlock { - frame.AckRanges[len(frame.AckRanges)-1].First -= protocol.PacketNumber(gap) + length - frame.AckRanges[len(frame.AckRanges)-1].Last -= protocol.PacketNumber(gap) + frame.AckRanges[len(frame.AckRanges)-1].Smallest -= protocol.PacketNumber(gap) + length + frame.AckRanges[len(frame.AckRanges)-1].Largest -= protocol.PacketNumber(gap) } else { lastRangeComplete = false ackRange := AckRange{ - Last: frame.AckRanges[len(frame.AckRanges)-1].First - protocol.PacketNumber(gap) - 1, + Largest: frame.AckRanges[len(frame.AckRanges)-1].Smallest - protocol.PacketNumber(gap) - 1, } - ackRange.First = ackRange.Last - length + 1 + ackRange.Smallest = ackRange.Largest - length + 1 frame.AckRanges = append(frame.AckRanges, ackRange) } @@ -122,7 +122,7 @@ func parseAckFrameLegacy(r *bytes.Reader, _ protocol.VersionNumber) (*AckFrame, frame.AckRanges = frame.AckRanges[:len(frame.AckRanges)-1] } - frame.LowestAcked = frame.AckRanges[len(frame.AckRanges)-1].First + frame.LowestAcked = frame.AckRanges[len(frame.AckRanges)-1].Smallest } else { if frame.LargestAcked == 0 { frame.LowestAcked = 0 @@ -218,13 +218,13 @@ func (f *AckFrame) writeLegacy(b *bytes.Buffer, _ protocol.VersionNumber) error if !f.HasMissingRanges() { firstAckBlockLength = f.LargestAcked - f.LowestAcked + 1 } else { - if f.LargestAcked != f.AckRanges[0].Last { + if f.LargestAcked != f.AckRanges[0].Largest { return errInconsistentAckLargestAcked } - if f.LowestAcked != f.AckRanges[len(f.AckRanges)-1].First { + if f.LowestAcked != f.AckRanges[len(f.AckRanges)-1].Smallest { return errInconsistentAckLowestAcked } - firstAckBlockLength = f.LargestAcked - f.AckRanges[0].First + 1 + firstAckBlockLength = f.LargestAcked - f.AckRanges[0].Smallest + 1 numRangesWritten++ } @@ -244,8 +244,8 @@ func (f *AckFrame) writeLegacy(b *bytes.Buffer, _ protocol.VersionNumber) error continue } - length := ackRange.Last - ackRange.First + 1 - gap := f.AckRanges[i-1].First - ackRange.Last - 1 + length := ackRange.Largest - ackRange.Smallest + 1 + gap := f.AckRanges[i-1].Smallest - ackRange.Largest - 1 num := gap/0xFF + 1 if gap%0xFF == 0 { @@ -337,7 +337,7 @@ func (f *AckFrame) numWritableNackRanges() uint64 { } lastAckRange := f.AckRanges[i-1] - gap := lastAckRange.First - ackRange.Last - 1 + gap := lastAckRange.Smallest - ackRange.Largest - 1 rangeLength := 1 + uint64(gap)/0xFF if uint64(gap)%0xFF == 0 { rangeLength-- @@ -358,7 +358,7 @@ func (f *AckFrame) getMissingSequenceNumberDeltaLen() protocol.PacketNumberLen { if f.HasMissingRanges() { for _, ackRange := range f.AckRanges { - rangeLength := ackRange.Last - ackRange.First + 1 + rangeLength := ackRange.Largest - ackRange.Smallest + 1 if rangeLength > maxRangeLength { maxRangeLength = rangeLength } diff --git a/internal/wire/ack_frame_legacy_test.go b/internal/wire/ack_frame_legacy_test.go index d600d2f2..612fbb34 100644 --- a/internal/wire/ack_frame_legacy_test.go +++ b/internal/wire/ack_frame_legacy_test.go @@ -212,8 +212,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { 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{First: 0x18 - 0x3 + 1, Last: 0x18})) - Expect(frame.AckRanges[1]).To(Equal(AckRange{First: (0x18 - 0x3 + 1) - (0x2 + 1) - (0x10 - 1), Last: (0x18 - 0x3 + 1) - (0x2 + 1)})) + 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(b.Len()).To(BeZero()) }) @@ -262,13 +262,13 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { 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{First: 31, Last: 0x27})) - Expect(frame.AckRanges[1]).To(Equal(AckRange{First: 29, Last: 29})) - Expect(frame.AckRanges[2]).To(Equal(AckRange{First: 27, Last: 27})) - Expect(frame.AckRanges[3]).To(Equal(AckRange{First: 25, Last: 25})) - Expect(frame.AckRanges[4]).To(Equal(AckRange{First: 23, Last: 23})) - Expect(frame.AckRanges[5]).To(Equal(AckRange{First: 21, Last: 21})) - Expect(frame.AckRanges[6]).To(Equal(AckRange{First: 1, Last: 19})) + Expect(frame.AckRanges[0]).To(Equal(AckRange{Smallest: 31, Largest: 0x27})) + Expect(frame.AckRanges[1]).To(Equal(AckRange{Smallest: 29, Largest: 29})) + Expect(frame.AckRanges[2]).To(Equal(AckRange{Smallest: 27, Largest: 27})) + Expect(frame.AckRanges[3]).To(Equal(AckRange{Smallest: 25, Largest: 25})) + 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(b.Len()).To(BeZero()) }) @@ -289,10 +289,10 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { 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{First: 60, Last: 0x52})) - Expect(frame.AckRanges[1]).To(Equal(AckRange{First: 34, Last: 49})) - Expect(frame.AckRanges[2]).To(Equal(AckRange{First: 22, Last: 29})) - Expect(frame.AckRanges[3]).To(Equal(AckRange{First: 2, Last: 19})) + 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(b.Len()).To(BeZero()) }) @@ -313,8 +313,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { 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{First: 20 + 255, Last: 0x115})) - Expect(frame.AckRanges[1]).To(Equal(AckRange{First: 1, Last: 19})) + 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(b.Len()).To(BeZero()) }) @@ -335,8 +335,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { 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{First: 20 + 256, Last: 0x114})) - Expect(frame.AckRanges[1]).To(Equal(AckRange{First: 1, Last: 19})) + 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(b.Len()).To(BeZero()) }) @@ -362,9 +362,9 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { 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{First: 20 + 3*301, Last: 20 + 3*301})) - Expect(frame.AckRanges[1]).To(Equal(AckRange{First: 20 + 2*301, Last: 20 + 2*301})) - Expect(frame.AckRanges[2]).To(Equal(AckRange{First: 20 + 1*301, Last: 20 + 1*301})) + Expect(frame.AckRanges[0]).To(Equal(AckRange{Smallest: 20 + 3*301, Largest: 20 + 3*301})) + Expect(frame.AckRanges[1]).To(Equal(AckRange{Smallest: 20 + 2*301, Largest: 20 + 2*301})) + Expect(frame.AckRanges[2]).To(Equal(AckRange{Smallest: 20 + 1*301, Largest: 20 + 1*301})) Expect(b.Len()).To(BeZero()) }) @@ -384,8 +384,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { 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{First: 300, Last: 0x144})) - Expect(frame.AckRanges[1]).To(Equal(AckRange{First: 1, Last: 19})) + 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(b.Len()).To(BeZero()) }) @@ -414,8 +414,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { 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{First: 2365, Last: 0x95b})) - Expect(frame.AckRanges[1]).To(Equal(AckRange{First: 1, Last: 19})) + 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(b.Len()).To(BeZero()) }) @@ -440,10 +440,10 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { 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{First: 2400, Last: 0x966})) - Expect(frame.AckRanges[1]).To(Equal(AckRange{First: 1250, Last: 1899})) - Expect(frame.AckRanges[2]).To(Equal(AckRange{First: 820, Last: 1049})) - Expect(frame.AckRanges[3]).To(Equal(AckRange{First: 1, Last: 19})) + 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(b.Len()).To(BeZero()) }) @@ -462,8 +462,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { 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{First: 0xdeadbeefcafe - 0x1337 + 1, Last: 0xdeadbeefcafe})) - Expect(frame.AckRanges[1]).To(Equal(AckRange{First: (0xdeadbeefcafe - 0x1337 + 1) - (0x20 + 1) - (0x12345678 - 1), Last: (0xdeadbeefcafe - 0x1337 + 1) - (0x20 + 1)})) + Expect(frame.AckRanges[0]).To(Equal(AckRange{Smallest: 0xdeadbeefcafe - 0x1337 + 1, Largest: 0xdeadbeefcafe})) + Expect(frame.AckRanges[1]).To(Equal(AckRange{Smallest: (0xdeadbeefcafe - 0x1337 + 1) - (0x20 + 1) - (0x12345678 - 1), Largest: (0xdeadbeefcafe - 0x1337 + 1) - (0x20 + 1)})) }) It("parses a frame with with a 6 byte ack block length", func() { @@ -480,8 +480,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { 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{First: 0xdeadbeefcafe - 0x1337 + 1, Last: 0xdeadbeefcafe})) - Expect(frame.AckRanges[1]).To(Equal(AckRange{First: (0xdeadbeefcafe - 0x1337 + 1) - (0x20 + 1) - (0xab12345678 - 1), Last: (0xdeadbeefcafe - 0x1337 + 1) - (0x20 + 1)})) + Expect(frame.AckRanges[0]).To(Equal(AckRange{Smallest: 0xdeadbeefcafe - 0x1337 + 1, Largest: 0xdeadbeefcafe})) + Expect(frame.AckRanges[1]).To(Equal(AckRange{Smallest: (0xdeadbeefcafe - 0x1337 + 1) - (0x20 + 1) - (0xab12345678 - 1), Largest: (0xdeadbeefcafe - 0x1337 + 1) - (0x20 + 1)})) }) }) }) @@ -561,8 +561,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 40, LowestAcked: 0, AckRanges: []AckRange{ - {First: 25, Last: 40}, - {First: 0, Last: 23}, + {Smallest: 25, Largest: 40}, + {Smallest: 0, Largest: 23}, }, } err := frameOrig.Write(b, versionBigEndian) @@ -581,10 +581,10 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 25, LowestAcked: 1, AckRanges: []AckRange{ - {First: 22, Last: 25}, - {First: 15, Last: 18}, - {First: 13, Last: 13}, - {First: 1, Last: 10}, + {Smallest: 22, Largest: 25}, + {Smallest: 15, Largest: 18}, + {Smallest: 13, Largest: 13}, + {Smallest: 1, Largest: 10}, }, } err := frameOrig.Write(b, versionBigEndian) @@ -603,8 +603,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 26, LowestAcked: 1, AckRanges: []AckRange{ - {First: 12, Last: 25}, - {First: 1, Last: 10}, + {Smallest: 12, Largest: 25}, + {Smallest: 1, Largest: 10}, }, } err := frame.Write(b, versionBigEndian) @@ -616,8 +616,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 25, LowestAcked: 2, AckRanges: []AckRange{ - {First: 12, Last: 25}, - {First: 1, Last: 10}, + {Smallest: 12, Largest: 25}, + {Smallest: 1, Largest: 10}, }, } err := frame.Write(b, versionBigEndian) @@ -630,8 +630,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 300, LowestAcked: 1, AckRanges: []AckRange{ - {First: 20 + 254, Last: 300}, - {First: 1, Last: 19}, + {Smallest: 20 + 254, Largest: 300}, + {Smallest: 1, Largest: 19}, }, } Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(2))) @@ -649,8 +649,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 300, LowestAcked: 1, AckRanges: []AckRange{ - {First: 20 + 255, Last: 300}, - {First: 1, Last: 19}, + {Smallest: 20 + 255, Largest: 300}, + {Smallest: 1, Largest: 19}, }, } Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(2))) @@ -668,8 +668,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 300, LowestAcked: 1, AckRanges: []AckRange{ - {First: 20 + 256, Last: 300}, - {First: 1, Last: 19}, + {Smallest: 20 + 256, Largest: 300}, + {Smallest: 1, Largest: 19}, }, } Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(3))) @@ -687,8 +687,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 600, LowestAcked: 1, AckRanges: []AckRange{ - {First: 20 + 510, Last: 600}, - {First: 1, Last: 19}, + {Smallest: 20 + 510, Largest: 600}, + {Smallest: 1, Largest: 19}, }, } Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(3))) @@ -706,8 +706,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 600, LowestAcked: 1, AckRanges: []AckRange{ - {First: 20 + 511, Last: 600}, - {First: 1, Last: 19}, + {Smallest: 20 + 511, Largest: 600}, + {Smallest: 1, Largest: 19}, }, } Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(4))) @@ -725,8 +725,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 600, LowestAcked: 1, AckRanges: []AckRange{ - {First: 20 + 512, Last: 600}, - {First: 1, Last: 19}, + {Smallest: 20 + 512, Largest: 600}, + {Smallest: 1, Largest: 19}, }, } Expect(frameOrig.numWritableNackRanges()).To(Equal(uint64(4))) @@ -744,8 +744,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 3000, LowestAcked: 1, AckRanges: []AckRange{ - {First: 2900, Last: 3000}, - {First: 1, Last: 19}, + {Smallest: 2900, Largest: 3000}, + {Smallest: 1, Largest: 19}, }, } err := frameOrig.Write(b, versionBigEndian) @@ -762,9 +762,9 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 3600, LowestAcked: 1, AckRanges: []AckRange{ - {First: 2900, Last: 3600}, - {First: 1000, Last: 2500}, - {First: 1, Last: 19}, + {Smallest: 2900, Largest: 3600}, + {Smallest: 1000, Largest: 2500}, + {Smallest: 1, Largest: 19}, }, } err := frameOrig.Write(b, versionBigEndian) @@ -849,9 +849,9 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 5001, LowestAcked: 1, AckRanges: []AckRange{ - {First: 5000, Last: 5001}, - {First: 250, Last: 300}, - {First: 1, Last: 200}, + {Smallest: 5000, Largest: 5001}, + {Smallest: 250, Largest: 300}, + {Smallest: 1, Largest: 200}, }, } err := frameOrig.Write(b, versionBigEndian) @@ -871,8 +871,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 10000, LowestAcked: 1, AckRanges: []AckRange{ - {First: 9990, Last: 10000}, - {First: 1, Last: 9988}, + {Smallest: 9990, Largest: 10000}, + {Smallest: 1, Largest: 9988}, }, } err := frameOrig.Write(b, versionBigEndian) @@ -892,8 +892,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 10000, LowestAcked: 1, AckRanges: []AckRange{ - {First: 9990, Last: 10000}, - {First: 1, Last: 256}, + {Smallest: 9990, Largest: 10000}, + {Smallest: 1, Largest: 256}, }, } err := frameOrig.Write(b, versionBigEndian) @@ -913,8 +913,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 0xdeadbeef, LowestAcked: 1, AckRanges: []AckRange{ - {First: 9990, Last: 0xdeadbeef}, - {First: 1, Last: 9988}, + {Smallest: 9990, Largest: 0xdeadbeef}, + {Smallest: 1, Largest: 9988}, }, } err := frameOrig.Write(b, versionBigEndian) @@ -934,8 +934,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 0xdeadbeef, LowestAcked: 1, AckRanges: []AckRange{ - {First: 9990, Last: 0xdeadbeef}, - {First: 1, Last: 256}, + {Smallest: 9990, Largest: 0xdeadbeef}, + {Smallest: 1, Largest: 256}, }, } err := frameOrig.Write(b, versionBigEndian) @@ -955,8 +955,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 0xdeadbeefcafe, LowestAcked: 1, AckRanges: []AckRange{ - {First: 9990, Last: 0xdeadbeefcafe}, - {First: 1, Last: 9988}, + {Smallest: 9990, Largest: 0xdeadbeefcafe}, + {Smallest: 1, Largest: 9988}, }, } err := frameOrig.Write(b, versionBigEndian) @@ -976,8 +976,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 0xdeadbeefcafe, LowestAcked: 1, AckRanges: []AckRange{ - {First: 9990, Last: 0xdeadbeefcafe}, - {First: 1, Last: 256}, + {Smallest: 9990, Largest: 0xdeadbeefcafe}, + {Smallest: 1, Largest: 256}, }, } err := frameOrig.Write(b, versionBigEndian) @@ -997,11 +997,11 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { It("skips the lowest ACK ranges, if there are more than 255 AckRanges", func() { ackRanges := make([]AckRange, 300) for i := 1; i <= 300; i++ { - ackRanges[300-i] = AckRange{First: protocol.PacketNumber(3 * i), Last: protocol.PacketNumber(3*i + 1)} + ackRanges[300-i] = AckRange{Smallest: protocol.PacketNumber(3 * i), Largest: protocol.PacketNumber(3*i + 1)} } frameOrig := &AckFrame{ - LargestAcked: ackRanges[0].Last, - LowestAcked: ackRanges[len(ackRanges)-1].First, + LargestAcked: ackRanges[0].Largest, + LowestAcked: ackRanges[len(ackRanges)-1].Smallest, AckRanges: ackRanges, } err := frameOrig.Write(b, versionBigEndian) @@ -1010,7 +1010,7 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { frame, err := parseAckFrame(r, versionBigEndian) Expect(err).ToNot(HaveOccurred()) Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.LowestAcked).To(Equal(ackRanges[254].First)) + Expect(frame.LowestAcked).To(Equal(ackRanges[254].Smallest)) Expect(frame.AckRanges).To(HaveLen(0xFF)) Expect(frame.validateAckRanges()).To(BeTrue()) }) @@ -1019,11 +1019,11 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { ackRanges := make([]AckRange, 100) // every AckRange will take 4 written ACK ranges for i := 1; i <= 100; i++ { - ackRanges[100-i] = AckRange{First: protocol.PacketNumber(1000 * i), Last: protocol.PacketNumber(1000*i + 1)} + ackRanges[100-i] = AckRange{Smallest: protocol.PacketNumber(1000 * i), Largest: protocol.PacketNumber(1000*i + 1)} } frameOrig := &AckFrame{ - LargestAcked: ackRanges[0].Last, - LowestAcked: ackRanges[len(ackRanges)-1].First, + LargestAcked: ackRanges[0].Largest, + LowestAcked: ackRanges[len(ackRanges)-1].Smallest, AckRanges: ackRanges, } err := frameOrig.Write(b, versionBigEndian) @@ -1032,19 +1032,19 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { frame, err := parseAckFrame(r, versionBigEndian) Expect(err).ToNot(HaveOccurred()) Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) - Expect(frame.LowestAcked).To(Equal(ackRanges[255/4].First)) + Expect(frame.LowestAcked).To(Equal(ackRanges[255/4].Smallest)) Expect(frame.validateAckRanges()).To(BeTrue()) }) It("works with huge gaps", func() { ackRanges := []AckRange{ - {First: 2 * 255 * 200, Last: 2*255*200 + 1}, - {First: 1 * 255 * 200, Last: 1*255*200 + 1}, - {First: 1, Last: 2}, + {Smallest: 2 * 255 * 200, Largest: 2*255*200 + 1}, + {Smallest: 1 * 255 * 200, Largest: 1*255*200 + 1}, + {Smallest: 1, Largest: 2}, } frameOrig := &AckFrame{ - LargestAcked: ackRanges[0].Last, - LowestAcked: ackRanges[len(ackRanges)-1].First, + LargestAcked: ackRanges[0].Largest, + LowestAcked: ackRanges[len(ackRanges)-1].Smallest, AckRanges: ackRanges, } err := frameOrig.Write(b, versionBigEndian) @@ -1054,7 +1054,7 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { Expect(err).ToNot(HaveOccurred()) Expect(frame.LargestAcked).To(Equal(frameOrig.LargestAcked)) Expect(frame.AckRanges).To(HaveLen(2)) - Expect(frame.LowestAcked).To(Equal(ackRanges[1].First)) + Expect(frame.LowestAcked).To(Equal(ackRanges[1].Smallest)) Expect(frame.validateAckRanges()).To(BeTrue()) }) }) @@ -1084,9 +1084,9 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 2000, LowestAcked: 10, AckRanges: []AckRange{ - {First: 1000, Last: 2000}, - {First: 50, Last: 900}, - {First: 10, Last: 23}, + {Smallest: 1000, Largest: 2000}, + {Smallest: 50, Largest: 900}, + {Smallest: 10, Largest: 23}, }, } err := f.Write(b, versionBigEndian) @@ -1099,9 +1099,9 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: 2000, LowestAcked: 1, AckRanges: []AckRange{ - {First: 1500, Last: 2000}, - {First: 290, Last: 295}, - {First: 1, Last: 19}, + {Smallest: 1500, Largest: 2000}, + {Smallest: 290, Largest: 295}, + {Smallest: 1, Largest: 19}, }, } err := f.Write(b, versionBigEndian) @@ -1115,9 +1115,9 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LargestAcked: largestAcked, LowestAcked: 1, AckRanges: []AckRange{ - {First: 1500, Last: largestAcked}, - {First: 290, Last: 295}, - {First: 1, Last: 19}, + {Smallest: 1500, Largest: largestAcked}, + {Smallest: 290, Largest: 295}, + {Smallest: 1, Largest: 19}, }, } err := f.Write(b, versionBigEndian) @@ -1136,39 +1136,39 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { It("rejects ACK ranges with a single range", func() { ack := AckFrame{ LargestAcked: 10, - AckRanges: []AckRange{{First: 1, Last: 10}}, + AckRanges: []AckRange{{Smallest: 1, Largest: 10}}, } Expect(ack.validateAckRanges()).To(BeFalse()) }) - It("rejects ACK ranges with Last of the first range unequal to LargestObserved", func() { + It("rejects ACK ranges with Largest of the first range unequal to LargestObserved", func() { ack := AckFrame{ LargestAcked: 10, AckRanges: []AckRange{ - {First: 8, Last: 9}, - {First: 2, Last: 3}, + {Smallest: 8, Largest: 9}, + {Smallest: 2, Largest: 3}, }, } Expect(ack.validateAckRanges()).To(BeFalse()) }) - It("rejects ACK ranges with First greater than Last", func() { + It("rejects ACK ranges with Smallest greater than Largest", func() { ack := AckFrame{ LargestAcked: 10, AckRanges: []AckRange{ - {First: 8, Last: 10}, - {First: 4, Last: 3}, + {Smallest: 8, Largest: 10}, + {Smallest: 4, Largest: 3}, }, } Expect(ack.validateAckRanges()).To(BeFalse()) }) - It("rejects ACK ranges with First greater than LargestObserved", func() { + It("rejects ACK ranges with Smallest greater than LargestObserved", func() { ack := AckFrame{ LargestAcked: 5, AckRanges: []AckRange{ - {First: 4, Last: 10}, - {First: 1, Last: 2}, + {Smallest: 4, Largest: 10}, + {Smallest: 1, Largest: 2}, }, } Expect(ack.validateAckRanges()).To(BeFalse()) @@ -1178,8 +1178,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { ack := AckFrame{ LargestAcked: 7, AckRanges: []AckRange{ - {First: 2, Last: 2}, - {First: 6, Last: 7}, + {Smallest: 2, Largest: 2}, + {Smallest: 6, Largest: 7}, }, } Expect(ack.validateAckRanges()).To(BeFalse()) @@ -1189,8 +1189,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { ack := AckFrame{ LargestAcked: 7, AckRanges: []AckRange{ - {First: 5, Last: 7}, - {First: 2, Last: 5}, + {Smallest: 5, Largest: 7}, + {Smallest: 2, Largest: 5}, }, } Expect(ack.validateAckRanges()).To(BeFalse()) @@ -1200,8 +1200,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { ack := AckFrame{ LargestAcked: 7, AckRanges: []AckRange{ - {First: 4, Last: 7}, - {First: 5, Last: 6}, + {Smallest: 4, Largest: 7}, + {Smallest: 5, Largest: 6}, }, } Expect(ack.validateAckRanges()).To(BeFalse()) @@ -1211,8 +1211,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { ack := AckFrame{ LargestAcked: 7, AckRanges: []AckRange{ - {First: 5, Last: 7}, - {First: 2, Last: 4}, + {Smallest: 5, Largest: 7}, + {Smallest: 2, Largest: 4}, }, } Expect(ack.validateAckRanges()).To(BeFalse()) @@ -1222,8 +1222,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { ack := AckFrame{ LargestAcked: 10, AckRanges: []AckRange{ - {First: 5, Last: 10}, - {First: 1, Last: 3}, + {Smallest: 5, Largest: 10}, + {Smallest: 1, Largest: 3}, }, } Expect(ack.validateAckRanges()).To(BeTrue()) @@ -1233,9 +1233,9 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { ack := AckFrame{ LargestAcked: 20, AckRanges: []AckRange{ - {First: 15, Last: 20}, - {First: 10, Last: 12}, - {First: 1, Last: 3}, + {Smallest: 15, Largest: 20}, + {Smallest: 10, Largest: 12}, + {Smallest: 1, Largest: 3}, }, } Expect(ack.validateAckRanges()).To(BeTrue()) @@ -1262,8 +1262,8 @@ var _ = Describe("ACK Frame (for gQUIC)", func() { LowestAcked: 5, LargestAcked: 20, AckRanges: []AckRange{ - {First: 15, Last: 20}, - {First: 5, Last: 8}, + {Smallest: 15, Largest: 20}, + {Smallest: 5, Largest: 8}, }, } Expect(f.AcksPacket(4)).To(BeFalse()) diff --git a/internal/wire/ack_frame_test.go b/internal/wire/ack_frame_test.go index 86eb2d45..e0a872fb 100644 --- a/internal/wire/ack_frame_test.go +++ b/internal/wire/ack_frame_test.go @@ -83,8 +83,8 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() { Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(750))) Expect(frame.HasMissingRanges()).To(BeTrue()) Expect(frame.AckRanges).To(Equal([]AckRange{ - {Last: 1000, First: 900}, - {Last: 800, First: 750}, + {Largest: 1000, Smallest: 900}, + {Largest: 800, Smallest: 750}, })) Expect(b.Len()).To(BeZero()) }) @@ -106,9 +106,9 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() { Expect(frame.LowestAcked).To(Equal(protocol.PacketNumber(94))) Expect(frame.HasMissingRanges()).To(BeTrue()) Expect(frame.AckRanges).To(Equal([]AckRange{ - {Last: 100, First: 100}, - {Last: 98, First: 98}, - {Last: 95, First: 94}, + {Largest: 100, Smallest: 100}, + {Largest: 98, Smallest: 98}, + {Largest: 95, Smallest: 94}, })) Expect(b.Len()).To(BeZero()) }) @@ -172,8 +172,8 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() { LargestAcked: 1000, LowestAcked: 100, AckRanges: []AckRange{ - {First: 400, Last: 1000}, - {First: 100, Last: 200}, + {Smallest: 400, Largest: 1000}, + {Smallest: 100, Largest: 200}, }, } Expect(f.validateAckRanges()).To(BeTrue()) @@ -194,10 +194,10 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() { LargestAcked: 10, LowestAcked: 1, AckRanges: []AckRange{ - {First: 10, Last: 10}, - {First: 8, Last: 8}, - {First: 5, Last: 6}, - {First: 1, Last: 3}, + {Smallest: 10, Largest: 10}, + {Smallest: 8, Largest: 8}, + {Smallest: 5, Largest: 6}, + {Smallest: 1, Largest: 3}, }, } Expect(f.validateAckRanges()).To(BeTrue()) @@ -222,39 +222,39 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() { It("rejects ACK ranges with a single range", func() { ack := AckFrame{ LargestAcked: 10, - AckRanges: []AckRange{{First: 1, Last: 10}}, + AckRanges: []AckRange{{Smallest: 1, Largest: 10}}, } Expect(ack.validateAckRanges()).To(BeFalse()) }) - It("rejects ACK ranges with Last of the first range unequal to LargestObserved", func() { + It("rejects ACK ranges with Largest of the first range unequal to LargestObserved", func() { ack := AckFrame{ LargestAcked: 10, AckRanges: []AckRange{ - {First: 8, Last: 9}, - {First: 2, Last: 3}, + {Smallest: 8, Largest: 9}, + {Smallest: 2, Largest: 3}, }, } Expect(ack.validateAckRanges()).To(BeFalse()) }) - It("rejects ACK ranges with First greater than Last", func() { + It("rejects ACK ranges with Smallest greater than Largest", func() { ack := AckFrame{ LargestAcked: 10, AckRanges: []AckRange{ - {First: 8, Last: 10}, - {First: 4, Last: 3}, + {Smallest: 8, Largest: 10}, + {Smallest: 4, Largest: 3}, }, } Expect(ack.validateAckRanges()).To(BeFalse()) }) - It("rejects ACK ranges with First greater than LargestObserved", func() { + It("rejects ACK ranges with Smallest greater than LargestObserved", func() { ack := AckFrame{ LargestAcked: 5, AckRanges: []AckRange{ - {First: 4, Last: 10}, - {First: 1, Last: 2}, + {Smallest: 4, Largest: 10}, + {Smallest: 1, Largest: 2}, }, } Expect(ack.validateAckRanges()).To(BeFalse()) @@ -264,8 +264,8 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() { ack := AckFrame{ LargestAcked: 7, AckRanges: []AckRange{ - {First: 2, Last: 2}, - {First: 6, Last: 7}, + {Smallest: 2, Largest: 2}, + {Smallest: 6, Largest: 7}, }, } Expect(ack.validateAckRanges()).To(BeFalse()) @@ -275,8 +275,8 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() { ack := AckFrame{ LargestAcked: 7, AckRanges: []AckRange{ - {First: 5, Last: 7}, - {First: 2, Last: 5}, + {Smallest: 5, Largest: 7}, + {Smallest: 2, Largest: 5}, }, } Expect(ack.validateAckRanges()).To(BeFalse()) @@ -286,8 +286,8 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() { ack := AckFrame{ LargestAcked: 7, AckRanges: []AckRange{ - {First: 4, Last: 7}, - {First: 5, Last: 6}, + {Smallest: 4, Largest: 7}, + {Smallest: 5, Largest: 6}, }, } Expect(ack.validateAckRanges()).To(BeFalse()) @@ -297,8 +297,8 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() { ack := AckFrame{ LargestAcked: 7, AckRanges: []AckRange{ - {First: 5, Last: 7}, - {First: 2, Last: 4}, + {Smallest: 5, Largest: 7}, + {Smallest: 2, Largest: 4}, }, } Expect(ack.validateAckRanges()).To(BeFalse()) @@ -308,8 +308,8 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() { ack := AckFrame{ LargestAcked: 10, AckRanges: []AckRange{ - {First: 5, Last: 10}, - {First: 1, Last: 3}, + {Smallest: 5, Largest: 10}, + {Smallest: 1, Largest: 3}, }, } Expect(ack.validateAckRanges()).To(BeTrue()) @@ -319,9 +319,9 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() { ack := AckFrame{ LargestAcked: 20, AckRanges: []AckRange{ - {First: 15, Last: 20}, - {First: 10, Last: 12}, - {First: 1, Last: 3}, + {Smallest: 15, Largest: 20}, + {Smallest: 10, Largest: 12}, + {Smallest: 1, Largest: 3}, }, } Expect(ack.validateAckRanges()).To(BeTrue()) @@ -348,8 +348,8 @@ var _ = Describe("ACK Frame (for IETF QUIC)", func() { LowestAcked: 5, LargestAcked: 20, AckRanges: []AckRange{ - {First: 15, Last: 20}, - {First: 5, Last: 8}, + {Smallest: 15, Largest: 20}, + {Smallest: 5, Largest: 8}, }, } Expect(f.AcksPacket(4)).To(BeFalse()) diff --git a/internal/wire/ack_range.go b/internal/wire/ack_range.go index 783528e6..0f418580 100644 --- a/internal/wire/ack_range.go +++ b/internal/wire/ack_range.go @@ -4,11 +4,11 @@ import "github.com/lucas-clemente/quic-go/internal/protocol" // AckRange is an ACK range type AckRange struct { - First protocol.PacketNumber - Last protocol.PacketNumber + Smallest protocol.PacketNumber + Largest protocol.PacketNumber } // Len returns the number of packets contained in this ACK range func (r AckRange) Len() protocol.PacketNumber { - return r.Last - r.First + 1 + return r.Largest - r.Smallest + 1 } diff --git a/internal/wire/ack_range_test.go b/internal/wire/ack_range_test.go index a9d268f1..84ef71b5 100644 --- a/internal/wire/ack_range_test.go +++ b/internal/wire/ack_range_test.go @@ -7,7 +7,7 @@ import ( var _ = Describe("ACK range", func() { It("returns the length", func() { - Expect(AckRange{First: 10, Last: 10}.Len()).To(BeEquivalentTo(1)) - Expect(AckRange{First: 10, Last: 13}.Len()).To(BeEquivalentTo(4)) + Expect(AckRange{Smallest: 10, Largest: 10}.Len()).To(BeEquivalentTo(1)) + Expect(AckRange{Smallest: 10, Largest: 13}.Len()).To(BeEquivalentTo(4)) }) })