fix bug in OutgoingPacketAckHandler entropy calculation for simple ACKs

This commit is contained in:
Marten Seemann
2016-04-23 10:57:44 +07:00
parent a9c00a4303
commit 50d38eac39
2 changed files with 30 additions and 17 deletions

View File

@@ -65,13 +65,6 @@ func (h *outgoingPacketAckHandler) calculateExpectedEntropy(ackFrame *frames.Ack
var expectedEntropy EntropyAccumulator
if !ackFrame.HasNACK() { // if the packet doesn't have NACKs, the correct entropy value is the entropy we sent the LargestObserved packet with. Just look it up in the map
packet, ok := h.packetHistory[ackFrame.LargestObserved]
if !ok {
return 0, errMapAccess
}
expectedEntropy = packet.Entropy
} else { // if the packet has NACKs, the entropy value has to be calculated
// get the entropy for the highestInOrderAckedPacketNumber
// There are two cases:
// 1. the packet with highestInOrderAckedPacketNumber has already been ACKed, then it doesn't exist in the packetHistory map anymore, but the value was saved as h.highestInOrderAckedEntropy
@@ -86,6 +79,7 @@ func (h *outgoingPacketAckHandler) calculateExpectedEntropy(ackFrame *frames.Ack
expectedEntropy = packet.Entropy
}
if ackFrame.HasNACK() { // if the packet has NACKs, the entropy value has to be calculated
nackRangeIndex := len(ackFrame.NackRanges) - 1
nackRange := ackFrame.NackRanges[nackRangeIndex]
for i := highestInOrderAckedPacketNumber + 1; i <= ackFrame.LargestObserved; i++ {

View File

@@ -160,6 +160,25 @@ var _ = Describe("AckHandler", func() {
err = handler.ReceivedAck(&ack)
Expect(err).ToNot(HaveOccurred())
})
It("checks the entropy of an ACK after a previous ACK was already received", func() {
expectedEntropy := EntropyAccumulator(0)
expectedEntropy.Add(1, packets[0].EntropyBit)
ack := frames.AckFrame{
LargestObserved: 1,
Entropy: byte(expectedEntropy),
}
err := handler.ReceivedAck(&ack)
Expect(err).ToNot(HaveOccurred())
expectedEntropy.Add(2, packets[1].EntropyBit)
expectedEntropy.Add(3, packets[2].EntropyBit)
ack = frames.AckFrame{
LargestObserved: 3,
Entropy: byte(expectedEntropy),
}
err = handler.ReceivedAck(&ack)
Expect(err).ToNot(HaveOccurred())
})
})
Context("ACKs with NACK ranges", func() {
@@ -244,7 +263,7 @@ var _ = Describe("AckHandler", func() {
Expect(handler.packetHistory).To(HaveKey(protocol.PacketNumber(2)))
})
It("checks the entropy of an ACK with a NACK after an previous ACK was already received", func() {
It("checks the entropy of an ACK with a NACK after a previous ACK was already received", func() {
expectedEntropy := EntropyAccumulator(0)
expectedEntropy.Add(1, packets[0].EntropyBit)
ack := frames.AckFrame{