calculate NACK ranges in the correct order expected by the ACK frame writer

fixes #43
This commit is contained in:
Marten Seemann 2016-05-03 18:31:02 +07:00
parent 6700672440
commit 08d96d2a69
2 changed files with 8 additions and 14 deletions

View file

@ -67,7 +67,7 @@ func (h *receivedPacketHandler) getNackRanges() ([]frames.NackRange, EntropyAccu
var ranges []frames.NackRange var ranges []frames.NackRange
inRange := false inRange := false
entropy := h.highestInOrderObservedEntropy entropy := h.highestInOrderObservedEntropy
for i := h.highestInOrderObserved + 1; i <= h.largestObserved; i++ { for i := h.largestObserved; i > h.highestInOrderObserved; i-- {
entropyBit, ok := h.packetHistory[i] entropyBit, ok := h.packetHistory[i]
if !ok { if !ok {
if !inRange { if !inRange {
@ -78,7 +78,7 @@ func (h *receivedPacketHandler) getNackRanges() ([]frames.NackRange, EntropyAccu
ranges = append(ranges, r) ranges = append(ranges, r)
inRange = true inRange = true
} else { } else {
ranges[len(ranges)-1].LastPacketNumber++ ranges[len(ranges)-1].FirstPacketNumber--
} }
} else { } else {
inRange = false inRange = false

View file

@ -117,8 +117,7 @@ var _ = Describe("receivedPacketHandler", func() {
Expect(handler.largestObserved).To(Equal(protocol.PacketNumber(9))) Expect(handler.largestObserved).To(Equal(protocol.PacketNumber(9)))
nackRanges, entropy := handler.getNackRanges() nackRanges, entropy := handler.getNackRanges()
Expect(len(nackRanges)).To(Equal(1)) Expect(len(nackRanges)).To(Equal(1))
Expect(nackRanges[0].FirstPacketNumber).To(Equal(protocol.PacketNumber(5))) Expect(nackRanges[0]).To(Equal(frames.NackRange{FirstPacketNumber: 5, LastPacketNumber: 5}))
Expect(nackRanges[0].LastPacketNumber).To(Equal(protocol.PacketNumber(5)))
Expect(handler.highestInOrderObserved).To(Equal(protocol.PacketNumber(4))) Expect(handler.highestInOrderObserved).To(Equal(protocol.PacketNumber(4)))
Expect(entropy).To(Equal(expectedEntropy)) Expect(entropy).To(Equal(expectedEntropy))
}) })
@ -139,8 +138,7 @@ var _ = Describe("receivedPacketHandler", func() {
Expect(handler.largestObserved).To(Equal(protocol.PacketNumber(11))) Expect(handler.largestObserved).To(Equal(protocol.PacketNumber(11)))
nackRanges, entropy := handler.getNackRanges() nackRanges, entropy := handler.getNackRanges()
Expect(len(nackRanges)).To(Equal(1)) Expect(len(nackRanges)).To(Equal(1))
Expect(nackRanges[0].FirstPacketNumber).To(Equal(protocol.PacketNumber(5))) Expect(nackRanges[0]).To(Equal(frames.NackRange{FirstPacketNumber: 5, LastPacketNumber: 6}))
Expect(nackRanges[0].LastPacketNumber).To(Equal(protocol.PacketNumber(6)))
Expect(handler.highestInOrderObserved).To(Equal(protocol.PacketNumber(4))) Expect(handler.highestInOrderObserved).To(Equal(protocol.PacketNumber(4)))
Expect(entropy).To(Equal(expectedEntropy)) Expect(entropy).To(Equal(expectedEntropy))
}) })
@ -161,10 +159,8 @@ var _ = Describe("receivedPacketHandler", func() {
Expect(handler.largestObserved).To(Equal(protocol.PacketNumber(9))) Expect(handler.largestObserved).To(Equal(protocol.PacketNumber(9)))
nackRanges, entropy := handler.getNackRanges() nackRanges, entropy := handler.getNackRanges()
Expect(len(nackRanges)).To(Equal(2)) Expect(len(nackRanges)).To(Equal(2))
Expect(nackRanges[0].FirstPacketNumber).To(Equal(protocol.PacketNumber(3))) Expect(nackRanges[0]).To(Equal(frames.NackRange{FirstPacketNumber: 7, LastPacketNumber: 7}))
Expect(nackRanges[0].LastPacketNumber).To(Equal(protocol.PacketNumber(3))) Expect(nackRanges[1]).To(Equal(frames.NackRange{FirstPacketNumber: 3, LastPacketNumber: 3}))
Expect(nackRanges[1].FirstPacketNumber).To(Equal(protocol.PacketNumber(7)))
Expect(nackRanges[1].LastPacketNumber).To(Equal(protocol.PacketNumber(7)))
Expect(handler.highestInOrderObserved).To(Equal(protocol.PacketNumber(2))) Expect(handler.highestInOrderObserved).To(Equal(protocol.PacketNumber(2)))
Expect(entropy).To(Equal(expectedEntropy)) Expect(entropy).To(Equal(expectedEntropy))
}) })
@ -182,10 +178,8 @@ var _ = Describe("receivedPacketHandler", func() {
Expect(handler.largestObserved).To(Equal(protocol.PacketNumber(9))) Expect(handler.largestObserved).To(Equal(protocol.PacketNumber(9)))
nackRanges, entropy := handler.getNackRanges() nackRanges, entropy := handler.getNackRanges()
Expect(len(nackRanges)).To(Equal(2)) Expect(len(nackRanges)).To(Equal(2))
Expect(nackRanges[0].FirstPacketNumber).To(Equal(protocol.PacketNumber(2))) Expect(nackRanges[0]).To(Equal(frames.NackRange{FirstPacketNumber: 7, LastPacketNumber: 8}))
Expect(nackRanges[0].LastPacketNumber).To(Equal(protocol.PacketNumber(4))) Expect(nackRanges[1]).To(Equal(frames.NackRange{FirstPacketNumber: 2, LastPacketNumber: 4}))
Expect(nackRanges[1].FirstPacketNumber).To(Equal(protocol.PacketNumber(7)))
Expect(nackRanges[1].LastPacketNumber).To(Equal(protocol.PacketNumber(8)))
Expect(handler.highestInOrderObserved).To(Equal(protocol.PacketNumber(1))) Expect(handler.highestInOrderObserved).To(Equal(protocol.PacketNumber(1)))
Expect(entropy).To(Equal(expectedEntropy)) Expect(entropy).To(Equal(expectedEntropy))
}) })