mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-06 05:37:36 +03:00
never send 1-byte packet numbers
This commit is contained in:
parent
9bd9c8aa54
commit
eabd38238a
3 changed files with 13 additions and 15 deletions
|
@ -31,7 +31,7 @@ var _ = Describe("Packet packer", func() {
|
||||||
packetNumberGenerator: newPacketNumberGenerator(protocol.SkipPacketAveragePeriodLength),
|
packetNumberGenerator: newPacketNumberGenerator(protocol.SkipPacketAveragePeriodLength),
|
||||||
streamFramer: streamFramer,
|
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
|
packer.version = protocol.Version34
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -28,11 +28,9 @@ func delta(a, b PacketNumber) PacketNumber {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPacketNumberLengthForPublicHeader gets the length of the packet number for the public header
|
// 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 {
|
func GetPacketNumberLengthForPublicHeader(packetNumber PacketNumber, leastUnacked PacketNumber) PacketNumberLen {
|
||||||
diff := uint64(packetNumber - leastUnacked)
|
diff := uint64(packetNumber - leastUnacked)
|
||||||
if diff < (2 << (uint8(PacketNumberLen1)*8 - 2)) {
|
|
||||||
return PacketNumberLen1
|
|
||||||
}
|
|
||||||
if diff < (2 << (uint8(PacketNumberLen2)*8 - 2)) {
|
if diff < (2 << (uint8(PacketNumberLen2)*8 - 2)) {
|
||||||
return PacketNumberLen2
|
return PacketNumberLen2
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,20 +128,20 @@ var _ = Describe("packet number calculation", func() {
|
||||||
|
|
||||||
Context("shortening a packet number for the publicHeader", func() {
|
Context("shortening a packet number for the publicHeader", func() {
|
||||||
Context("shortening", 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)
|
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))
|
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() {
|
Context("self-consistency", func() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue