From c06a0ca037fc1c390c7e0f30bf16a3f98620e5a9 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Thu, 29 Nov 2018 12:03:19 +0700 Subject: [PATCH] rename InferPacketNumber to DecodePacketNumber That's how it's called in the draft. --- internal/protocol/packet_number.go | 4 ++-- internal/protocol/packet_number_test.go | 20 ++++++++++---------- session.go | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/protocol/packet_number.go b/internal/protocol/packet_number.go index 17f68055..405a07ac 100644 --- a/internal/protocol/packet_number.go +++ b/internal/protocol/packet_number.go @@ -16,8 +16,8 @@ const ( PacketNumberLen4 PacketNumberLen = 4 ) -// InferPacketNumber calculates the packet number based on the received packet number, its length and the last seen packet number -func InferPacketNumber( +// DecodePacketNumber calculates the packet number based on the received packet number, its length and the last seen packet number +func DecodePacketNumber( packetNumberLength PacketNumberLen, lastPacketNumber PacketNumber, wirePacketNumber PacketNumber, diff --git a/internal/protocol/packet_number_test.go b/internal/protocol/packet_number_test.go index f75a32fb..861bbb6c 100644 --- a/internal/protocol/packet_number_test.go +++ b/internal/protocol/packet_number_test.go @@ -11,7 +11,7 @@ import ( // Tests taken and extended from chrome var _ = Describe("packet number calculation", func() { It("works with the example from the draft", func() { - Expect(InferPacketNumber(PacketNumberLen2, 0xa82f30ea, 0x9b32)).To(Equal(PacketNumber(0xa82f9b32))) + Expect(DecodePacketNumber(PacketNumberLen2, 0xa82f30ea, 0x9b32)).To(Equal(PacketNumber(0xa82f9b32))) }) getEpoch := func(len PacketNumberLen) uint64 { @@ -25,7 +25,7 @@ var _ = Describe("packet number calculation", func() { epoch := getEpoch(length) epochMask := epoch - 1 wirePacketNumber := expected & epochMask - Expect(InferPacketNumber(length, PacketNumber(last), PacketNumber(wirePacketNumber))).To(Equal(PacketNumber(expected))) + Expect(DecodePacketNumber(length, PacketNumber(last), PacketNumber(wirePacketNumber))).To(Equal(PacketNumber(expected))) } for _, l := range []PacketNumberLen{PacketNumberLen1, PacketNumberLen2, PacketNumberLen4} { @@ -167,8 +167,8 @@ var _ = Describe("packet number calculation", func() { length := GetPacketNumberLengthForHeader(packetNumber, leastUnacked) wirePacketNumber := (uint64(packetNumber) << (64 - length*8)) >> (64 - length*8) - inferedPacketNumber := InferPacketNumber(length, leastUnacked, PacketNumber(wirePacketNumber)) - Expect(inferedPacketNumber).To(Equal(packetNumber)) + decodedPacketNumber := DecodePacketNumber(length, leastUnacked, PacketNumber(wirePacketNumber)) + Expect(decodedPacketNumber).To(Equal(packetNumber)) } }) @@ -180,8 +180,8 @@ var _ = Describe("packet number calculation", func() { epochMask := getEpoch(length) - 1 wirePacketNumber := uint64(packetNumber) & epochMask - inferedPacketNumber := InferPacketNumber(length, leastUnacked, PacketNumber(wirePacketNumber)) - Expect(inferedPacketNumber).To(Equal(packetNumber)) + decodedPacketNumber := DecodePacketNumber(length, leastUnacked, PacketNumber(wirePacketNumber)) + Expect(decodedPacketNumber).To(Equal(packetNumber)) } }) @@ -194,8 +194,8 @@ var _ = Describe("packet number calculation", func() { epochMask := getEpoch(length) - 1 wirePacketNumber := uint64(packetNumber) & epochMask - inferedPacketNumber := InferPacketNumber(length, leastUnacked, PacketNumber(wirePacketNumber)) - Expect(inferedPacketNumber).To(Equal(packetNumber)) + decodedPacketNumber := DecodePacketNumber(length, leastUnacked, PacketNumber(wirePacketNumber)) + Expect(decodedPacketNumber).To(Equal(packetNumber)) increment = getEpoch(length) / 8 } @@ -208,8 +208,8 @@ var _ = Describe("packet number calculation", func() { length := GetPacketNumberLengthForHeader(packetNumber, leastUnacked) wirePacketNumber := (uint64(packetNumber) << (64 - length*8)) >> (64 - length*8) - inferedPacketNumber := InferPacketNumber(length, leastUnacked, PacketNumber(wirePacketNumber)) - Expect(inferedPacketNumber).To(Equal(packetNumber)) + decodedPacketNumber := DecodePacketNumber(length, leastUnacked, PacketNumber(wirePacketNumber)) + Expect(decodedPacketNumber).To(Equal(packetNumber)) } }) }) diff --git a/session.go b/session.go index 024a12d2..9b606120 100644 --- a/session.go +++ b/session.go @@ -505,7 +505,7 @@ func (s *session) handlePacketImpl(p *receivedPacket) error { } // Calculate packet number - hdr.PacketNumber = protocol.InferPacketNumber( + hdr.PacketNumber = protocol.DecodePacketNumber( hdr.PacketNumberLen, s.largestRcvdPacketNumber, hdr.PacketNumber,