mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-06 05:37:36 +03:00
never use a 6 byte packet number
According to the IETF draft, the only packet number lengths are 1, 2 and 4 bytes. With the given formula for the packet number derivation, we would have only sent a 6 byte packet number if the difference between the largest unacked and the current packet number exceeded 2^31, so this would never have happened anyway.
This commit is contained in:
parent
bbe9affa27
commit
6c394acde7
3 changed files with 13 additions and 19 deletions
|
@ -27,18 +27,14 @@ func delta(a, b PacketNumber) PacketNumber {
|
|||
return a - b
|
||||
}
|
||||
|
||||
// GetPacketNumberLengthForPublicHeader gets the length of the packet number for the public header
|
||||
// GetPacketNumberLengthForHeader 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 GetPacketNumberLengthForHeader(packetNumber PacketNumber, leastUnacked PacketNumber) PacketNumberLen {
|
||||
diff := uint64(packetNumber - leastUnacked)
|
||||
if diff < (2 << (uint8(PacketNumberLen2)*8 - 2)) {
|
||||
if diff < (1 << (uint8(PacketNumberLen2)*8 - 1)) {
|
||||
return PacketNumberLen2
|
||||
}
|
||||
if diff < (2 << (uint8(PacketNumberLen4)*8 - 2)) {
|
||||
return PacketNumberLen4
|
||||
}
|
||||
// we do not check if there are less than 2^46 packets in flight, since flow control and congestion control will limit this number *a lot* sooner
|
||||
return PacketNumberLen6
|
||||
return PacketNumberLen4
|
||||
}
|
||||
|
||||
// GetPacketNumberLength gets the minimum length needed to fully represent the packet number
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue