Skip to content

Commit

Permalink
Parenthesize 2 * MaxEntries to prevent naive errors (#1856)
Browse files Browse the repository at this point in the history
* Parenthesize 2 * MaxEntries to prevent naive errors

Transcribing

  LargestReference mod 2*MaxEntries + 1

to C one of its offspring without parentheses around 2 * MaxEntries
will produce an incorrect result.

* Fix lint error (figure too wide) via creative variable renaming

* Add parentheses to disambiguate further; prettify other spots
  • Loading branch information
dtikhonov authored and afrind committed Oct 23, 2018
1 parent 6932dea commit d64ec49
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions draft-ietf-quic-qpack.md
Expand Up @@ -718,30 +718,29 @@ safe to process the rest of the block. If Largest Reference is greater than
zero, the encoder transforms it as follows before encoding:

~~~
LargestReference = LargestReference mod 2*MaxEntries + 1
LargestReference = (LargestReference mod (2 * MaxEntries)) + 1
~~~

The decoder reconstructs the Largest Reference using the following algorithm:

~~~
if LargestReference > 0:
LargestReference -= 1
CurrentWrapped = TableLargestAbsoluteIndex mod 2*MaxEntries
CurrentWrapped = TotalNumberOfInserts mod (2 * MaxEntries)

if CurrentWrapped >= LargestReference + MaxEntries:
# Largest Reference wrapped around 1 extra time
LargestReference += 2*MaxEntries
LargestReference += 2 * MaxEntries
else if CurrentWrapped + MaxEntries < LargestReference
# Decoder wrapped around 1 extra time
CurrentWrapped += 2*MaxEntries
CurrentWrapped += 2 * MaxEntries

LargestReference +=
(TableLargestAbsoluteIndex - CurrentWrapped)
LargestReference += TotalNumberOfInserts - CurrentWrapped
~~~

TableLargestAbsoluteIndex is the Absolute Index of the most recently inserted
item in the decoder's dynamic table. This encoding limits the length of the
prefix on long-lived connections.
TotalNumberOfInserts is the total number of inserts into the decoder's
dynamic table. This encoding limits the length of the prefix on
long-lived connections.

`Base Index` is used to resolve references in the dynamic table as described in
{{relative-indexing}}.
Expand Down

0 comments on commit d64ec49

Please sign in to comment.