diff --git a/ackhandler/entropy_accumulator.go b/ackhandler/entropy_accumulator.go index fe120571e..f6b11aa33 100644 --- a/ackhandler/entropy_accumulator.go +++ b/ackhandler/entropy_accumulator.go @@ -12,6 +12,11 @@ func (e *EntropyAccumulator) Add(packetNumber protocol.PacketNumber, entropyFlag } } +// Add the contribution of the entropy flag of a given packet number +func (e *EntropyAccumulator) Substract(packetNumber protocol.PacketNumber, entropyFlag bool) { + e.Add(packetNumber, entropyFlag) +} + // Get the byte of entropy func (e *EntropyAccumulator) Get() byte { return byte(*e) diff --git a/ackhandler/entropy_accumulator_test.go b/ackhandler/entropy_accumulator_test.go index adb7f0974..02813c679 100644 --- a/ackhandler/entropy_accumulator_test.go +++ b/ackhandler/entropy_accumulator_test.go @@ -11,15 +11,31 @@ var _ = Describe("EntropyAccumulator", func() { Expect(e.Get()).To(BeZero()) }) - It("adds entropy", func() { - var e EntropyAccumulator - e.Add(9, true) - Expect(e.Get()).To(Equal(byte(0x02))) + Context("Add", func() { + It("adds entropy", func() { + var e EntropyAccumulator + e.Add(9, true) + Expect(e.Get()).To(Equal(byte(0x02))) + }) + + It("doesn't add entropy for zero entropy flags", func() { + var e EntropyAccumulator + e.Add(9, false) + Expect(e.Get()).To(BeZero()) + }) }) - It("doesn't add entropy for zero entropy flags", func() { - var e EntropyAccumulator - e.Add(9, false) - Expect(e.Get()).To(BeZero()) + Context("Substract", func() { + It("calculates the correct entropy", func() { + var e1 EntropyAccumulator + e1.Add(3, true) + + var e2 EntropyAccumulator + e2.Add(1, true) + e2.Add(3, true) + e2.Substract(1, true) + + Expect(e1).To(Equal(e2)) + }) }) })