diff --git a/packet_packer_test.go b/packet_packer_test.go index c0a3ab8b..c6c81d59 100644 --- a/packet_packer_test.go +++ b/packet_packer_test.go @@ -31,7 +31,7 @@ var _ = Describe("Packet packer", func() { packetNumberGenerator: newPacketNumberGenerator(protocol.SkipPacketAveragePeriodLength), streamFramer: streamFramer, } - publicHeaderLen = 1 + 8 + 1 // 1 flag byte, 8 connection ID, 1 packet number + publicHeaderLen = 1 + 8 + 2 // 1 flag byte, 8 connection ID, 2 packet number packer.version = protocol.Version34 }) diff --git a/protocol/packet_number.go b/protocol/packet_number.go index 3900464d..c4f468ad 100644 --- a/protocol/packet_number.go +++ b/protocol/packet_number.go @@ -28,11 +28,9 @@ func delta(a, b PacketNumber) PacketNumber { } // GetPacketNumberLengthForPublicHeader gets the length of the packet number for the public header +// it never chooses a PacketNumberLen of 1 byte, since this is too short under certain circumstances func GetPacketNumberLengthForPublicHeader(packetNumber PacketNumber, leastUnacked PacketNumber) PacketNumberLen { diff := uint64(packetNumber - leastUnacked) - if diff < (2 << (uint8(PacketNumberLen1)*8 - 2)) { - return PacketNumberLen1 - } if diff < (2 << (uint8(PacketNumberLen2)*8 - 2)) { return PacketNumberLen2 } diff --git a/protocol/packet_number_test.go b/protocol/packet_number_test.go index f179504f..aa1886a2 100644 --- a/protocol/packet_number_test.go +++ b/protocol/packet_number_test.go @@ -128,20 +128,20 @@ var _ = Describe("packet number calculation", func() { Context("shortening a packet number for the publicHeader", func() { Context("shortening", func() { - It("sends out low packet numbers as 1 byte", func() { + It("sends out low packet numbers as 2 byte", func() { length := GetPacketNumberLengthForPublicHeader(4, 2) - Expect(length).To(Equal(PacketNumberLen1)) - }) - - It("sends out high packet numbers as 1 byte, if all ACKs are received", func() { - length := GetPacketNumberLengthForPublicHeader(0xDEADBEEF, 0xDEADBEEF-1) - Expect(length).To(Equal(PacketNumberLen1)) - }) - - It("sends out higher packet numbers as 2 bytes, if a lot of ACKs are missing", func() { - length := GetPacketNumberLengthForPublicHeader(200, 2) Expect(length).To(Equal(PacketNumberLen2)) }) + + It("sends out high packet numbers as 2 byte, if all ACKs are received", func() { + length := GetPacketNumberLengthForPublicHeader(0xDEADBEEF, 0xDEADBEEF-1) + Expect(length).To(Equal(PacketNumberLen2)) + }) + + It("sends out higher packet numbers as 4 bytes, if a lot of ACKs are missing", func() { + length := GetPacketNumberLengthForPublicHeader(40000, 2) + Expect(length).To(Equal(PacketNumberLen4)) + }) }) Context("self-consistency", func() {