Skip to content

Commit

Permalink
Small editorial tweaks
Browse files Browse the repository at this point in the history
Capitalize and shorten title
Rename some variables
Indent a little more
  • Loading branch information
martinthomson committed Jun 29, 2018
1 parent e607539 commit 52ba67e
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions draft-ietf-quic-transport.md
Expand Up @@ -4780,36 +4780,36 @@ from 0xFF00 to 0xFFFF are reserved for Private Use {{!RFC8126}}.

--- back

# Sample code for packet number decoding {#sample-packet-number-decoding}
# Sample Packet Number Decoding Algorithm {#sample-packet-number-decoding}

The following pseudo-code shows how an implementation can decode packet
numbers after packet protection has been removed.
numbers after packet number protection has been removed.

~~~
DecodePacketNumber(largest_pn, truncated_pn, pn_nbits):
expected_pn = largest_pn + 1
pn_len = 1 << pn_nbits
pn_win = pn_len / 2
pn_mask = pn_len - 1
// The incoming packet number should be greater than
// expected_pn - pn_win and less than or equal to
// expected_pn + pn_win
//
// This means we can't just strip the trailing bits from
// expected_pn and add the truncated_pn because that might
// yield a value outside the window.
//
// The following code calculates a candidate value and
// makes sure it's within the packet number window.
candidate_pn = (expected_pn & ~pn_mask) | truncated_pn
if candidate_pn <= expected_pn - pn_win:
return candidate_pn + pn_len
// Note the extra check for underflow when candidate_pn
// is near zero.
if candidate_pn > expected_pn + pn_win and
candidate_pn > pn_len:
return candidate_pn - pn_len
return candidate_pn
expected_pn = largest_pn + 1
pn_win = 1 << pn_nbits
pn_hwin = pn_win / 2
pn_mask = pn_win - 1
// The incoming packet number should be greater than
// expected_pn - pn_hwin and less than or equal to
// expected_pn + pn_hwin
//
// This means we can't just strip the trailing bits from
// expected_pn and add the truncated_pn because that might
// yield a value outside the window.
//
// The following code calculates a candidate value and
// makes sure it's within the packet number window.
candidate_pn = (expected_pn & ~pn_mask) | truncated_pn
if candidate_pn <= expected_pn - pn_hwin:
return candidate_pn + pn_win
// Note the extra check for underflow when candidate_pn
// is near zero.
if candidate_pn > expected_pn + pn_hwin and
candidate_pn > pn_win:
return candidate_pn - pn_win
return candidate_pn
~~~

# Change Log
Expand Down

0 comments on commit 52ba67e

Please sign in to comment.