proxygen
|
#include <QPACKHeaderTable.h>
Public Types | |
enum | { UNACKED = std::numeric_limits<uint32_t>::max() } |
Public Types inherited from proxygen::HeaderTable | |
using | names_map = std::unordered_map< HPACKHeaderName, std::list< uint32_t >> |
Public Member Functions | |
QPACKHeaderTable (uint32_t capacityVal, bool trackReferences) | |
~QPACKHeaderTable () | |
QPACKHeaderTable (const QPACKHeaderTable &)=delete | |
QPACKHeaderTable & | operator= (const QPACKHeaderTable &)=delete |
uint32_t | getBaseIndex () const |
bool | isVulnerable (uint32_t absIndex) const |
bool | canIndex (const HPACKHeader &header) |
bool | isDraining (uint32_t relativeIndex) |
std::pair< bool, uint32_t > | maybeDuplicate (uint32_t relativeIndex, bool allowVulnerable) |
bool | add (HPACKHeader header) override |
bool | setCapacity (uint32_t capacity) override |
uint32_t | getIndex (const HPACKHeader &header, bool allowVulnerable=true) const |
const HPACKHeader & | getHeader (uint32_t index, uint32_t base=0) const |
bool | isValid (uint32_t index, uint32_t base=0) const |
uint32_t | nameIndex (const HPACKHeaderName &headerName, bool allowVulnerable=true) const |
bool | onTableStateSync (uint32_t inserts) |
void | setMaxAcked (uint32_t maxAcked) |
uint32_t | relativeToAbsolute (uint32_t relativeIndex) const |
uint32_t | absoluteToRelative (uint32_t absIndex) const |
void | addRef (uint32_t absIndex) |
void | subRef (uint32_t absIndex) |
Public Member Functions inherited from proxygen::HeaderTable | |
HeaderTable (uint32_t capacityVal) | |
virtual | ~HeaderTable () |
HeaderTable (const HeaderTable &)=delete | |
HeaderTable & | operator= (const HeaderTable &)=delete |
uint32_t | getIndex (const HPACKHeader &header) const |
const HPACKHeader & | getHeader (uint32_t index) const |
bool | isValid (uint32_t index) const |
bool | hasName (const HPACKHeaderName &headerName) |
const names_map & | names () const |
uint32_t | nameIndex (const HPACKHeaderName &headerName) const |
uint32_t | capacity () const |
uint32_t | getMaxTableLength (uint32_t capacityVal) |
uint32_t | size () const |
uint32_t | bytes () const |
size_t | length () const |
bool | operator== (const HeaderTable &other) const |
Private Member Functions | |
uint32_t | getIndexImpl (const HPACKHeaderName &header, const folly::fbstring &value, bool nameOnly, bool allowVulnerable=true) const |
void | increaseTableLengthTo (uint32_t newLength) override |
void | resizeTable (uint32_t newLength) override |
void | updateResizedTable (uint32_t oldTail, uint32_t oldLength, uint32_t newLength) override |
uint32_t | removeLast () override |
bool | canEvict (uint32_t needed) |
uint32_t | evict (uint32_t needed, uint32_t desiredCapacity) override |
uint32_t | toInternal (uint32_t externalIndex, uint32_t base) const |
uint32_t | internalToAbsolute (uint32_t internalIndex) const |
uint32_t | absoluteToInternal (uint32_t absoluteIndex) const |
Private Attributes | |
uint32_t | baseIndex_ {0} |
uint32_t | drainedBytes_ {0} |
uint32_t | minUsable_ {1} |
uint32_t | maxAcked_ {0} |
std::unique_ptr< std::vector< uint16_t > > | refCount_ |
uint32_t | minFree_ {0} |
Additional Inherited Members | |
Static Public Member Functions inherited from proxygen::HeaderTable | |
static uint32_t | toExternal (uint32_t head, uint32_t length, uint32_t internalIndex) |
static uint32_t | toInternal (uint32_t head, uint32_t length, uint32_t externalIndex) |
Protected Member Functions inherited from proxygen::HeaderTable | |
void | init (uint32_t capacityVal) |
void | reset () |
uint32_t | next (uint32_t i) const |
uint32_t | tail () const |
uint32_t | toExternal (uint32_t internalIndex) const |
uint32_t | toInternal (uint32_t externalIndex) const |
Protected Attributes inherited from proxygen::HeaderTable | |
uint32_t | capacity_ {0} |
uint32_t | bytes_ {0} |
std::vector< HPACKHeader > | table_ |
uint32_t | size_ {0} |
uint32_t | head_ {0} |
names_map | names_ |
Data structure for maintaining indexed headers, based on a fixed-length ring with FIFO semantics. Externally it acts as an array.
Definition at line 22 of file QPACKHeaderTable.h.
anonymous enum |
proxygen::QPACKHeaderTable::QPACKHeaderTable | ( | uint32_t | capacityVal, |
bool | trackReferences | ||
) |
Definition at line 39 of file QPACKHeaderTable.cpp.
References minFree_, refCount_, and proxygen::HeaderTable::table_.
Referenced by ~QPACKHeaderTable().
|
inline |
Definition at line 30 of file QPACKHeaderTable.h.
References operator=(), and QPACKHeaderTable().
|
delete |
Definition at line 276 of file QPACKHeaderTable.cpp.
References absoluteToRelative(), and toInternal().
Referenced by absoluteToRelative(), add(), addRef(), and subRef().
Convert an absolute index to a relative index
Definition at line 154 of file QPACKHeaderTable.h.
References absoluteToInternal(), addRef(), baseIndex_, canEvict(), evict(), getIndexImpl(), increaseTableLengthTo(), internalToAbsolute(), removeLast(), resizeTable(), subRef(), toInternal(), uint32_t, updateResizedTable(), and value.
Referenced by absoluteToInternal(), proxygen::QPACKEncoder::encodeHeaderQ(), proxygen::QPACKEncoder::getNameIndexQ(), and toInternal().
|
overridevirtual |
Add the header entry at the beginning of the table (index=1)
Reimplemented from proxygen::HeaderTable.
Definition at line 49 of file QPACKHeaderTable.cpp.
References absoluteToInternal(), proxygen::HeaderTable::add(), baseIndex_, proxygen::HeaderTable::bytes(), proxygen::HeaderTable::bytes_, proxygen::HeaderTable::capacity_, drainedBytes_, proxygen::ERROR, proxygen::HeaderTable::head_, internalToAbsolute(), max, minFree_, minUsable_, folly::gen::move, refCount_, and proxygen::HeaderTable::table_.
Referenced by proxygen::QPACKDecoder::decodeEncoderStreamInstruction(), proxygen::QPACKDecoder::decodeLiteralHeaderQ(), proxygen::QPACKEncoder::encodeHeaderQ(), isDraining(), maybeDuplicate(), and proxygen::QPACKContext::seedHeaderTable().
void proxygen::QPACKHeaderTable::addRef | ( | uint32_t | absIndex | ) |
Add a reference for the given index. Entries with non-zero references cannot be evicted
Definition at line 254 of file QPACKHeaderTable.cpp.
References absoluteToInternal(), and refCount_.
Referenced by absoluteToRelative(), and proxygen::QPACKEncoder::trackReference().
|
private |
Return true if the table can evict needed bytes
Definition at line 192 of file QPACKHeaderTable.cpp.
References proxygen::HeaderTable::capacity_, i, internalToAbsolute(), maxAcked_, proxygen::HeaderTable::next(), refCount_, proxygen::HeaderTable::size(), proxygen::HeaderTable::size_, proxygen::HeaderTable::table_, proxygen::HeaderTable::tail(), and uint32_t.
Referenced by absoluteToRelative(), canIndex(), and evict().
|
inline |
Returns true if the header can be added to the table. May be linear in the number of entries
Definition at line 53 of file QPACKHeaderTable.h.
References proxygen::HPACKHeader::bytes(), proxygen::HeaderTable::bytes_, canEvict(), proxygen::HeaderTable::capacity_, and minFree_.
Referenced by proxygen::QPACKEncoder::encodeHeaderQ(), and maybeDuplicate().
|
overrideprivatevirtual |
Evict entries to make space for the needed amount of bytes.
Reimplemented from proxygen::HeaderTable.
Definition at line 184 of file QPACKHeaderTable.cpp.
References proxygen::HeaderTable::bytes_, canEvict(), and proxygen::HeaderTable::evict().
Referenced by absoluteToRelative().
|
inline |
Return Base Index - the total number of headers inserted to this table, including evictions
Definition at line 38 of file QPACKHeaderTable.h.
References baseIndex_.
Referenced by proxygen::QPACKDecoder::decodeStreaming(), proxygen::QPACKDecoder::drainQueue(), proxygen::QPACKEncoder::encodeHeaderQ(), proxygen::QPACKEncoder::encodeQ(), proxygen::QPACKDecoder::encodeTableStateSync(), and proxygen::QPACKDecoder::enqueueHeaderBlock().
const HPACKHeader & proxygen::QPACKHeaderTable::getHeader | ( | uint32_t | index, |
uint32_t | base = 0 |
||
) | const |
Get the table entry at the given external index. If base is 0, index is relative to head/baseIndex. If base is non-zero, index is relative to base.
Definition at line 129 of file QPACKHeaderTable.cpp.
References isValid(), proxygen::HeaderTable::table_, and toInternal().
Referenced by proxygen::QPACKContext::getHeader(), isDraining(), and maybeDuplicate().
uint32_t proxygen::QPACKHeaderTable::getIndex | ( | const HPACKHeader & | header, |
bool | allowVulnerable = true |
||
) | const |
Get the index of the given header, if found. The index is relative to head/baseIndex. If allowVulnerable is true, the index returned may not have been acknowledged by the decoder.
Definition at line 88 of file QPACKHeaderTable.cpp.
References getIndexImpl(), proxygen::HPACKHeader::name, and proxygen::HPACKHeader::value.
Referenced by proxygen::QPACKEncoder::encodeHeaderQ(), and isDraining().
|
private |
Definition at line 93 of file QPACKHeaderTable.cpp.
References i, internalToAbsolute(), maxAcked_, proxygen::HeaderTable::names_, proxygen::HeaderTable::table_, proxygen::HeaderTable::toExternal(), and UNACKED.
Referenced by absoluteToRelative(), getIndex(), and nameIndex().
|
overrideprivatevirtual |
Reimplemented from proxygen::HeaderTable.
Definition at line 159 of file QPACKHeaderTable.cpp.
References baseIndex_, proxygen::HeaderTable::head_, proxygen::HeaderTable::increaseTableLengthTo(), internalToAbsolute(), proxygen::HeaderTable::size_, and proxygen::HeaderTable::tail().
Referenced by absoluteToRelative().
Definition at line 270 of file QPACKHeaderTable.cpp.
References relativeToAbsolute(), and proxygen::HeaderTable::toExternal().
Referenced by absoluteToRelative(), add(), canEvict(), getIndexImpl(), increaseTableLengthTo(), and removeLast().
|
inline |
Returns true if the index should not be used so table space can be freed
Definition at line 63 of file QPACKHeaderTable.h.
References add(), proxygen::HeaderTable::capacity(), getHeader(), getIndex(), isValid(), maybeDuplicate(), minUsable_, nameIndex(), relativeToAbsolute(), setCapacity(), and uint32_t.
Checks if an external index is valid. If base is 0, index is relative to head/baseIndex. If base is non-zero, index is relative to base.
Definition at line 212 of file QPACKHeaderTable.cpp.
References baseIndex_, int64_t, and proxygen::HeaderTable::isValid().
Referenced by proxygen::QPACKEncoder::encodeHeaderQ(), getHeader(), isDraining(), proxygen::QPACKDecoder::isValid(), maybeDuplicate(), and relativeToAbsolute().
|
inline |
Returns true if the absolute index has not been ack'ed yet.
Definition at line 45 of file QPACKHeaderTable.h.
References maxAcked_.
Referenced by maybeDuplicate(), TEST(), and proxygen::QPACKEncoder::trackReference().
std::pair< bool, uint32_t > proxygen::QPACKHeaderTable::maybeDuplicate | ( | uint32_t | relativeIndex, |
bool | allowVulnerable | ||
) |
Returns the absolute index for a reference to the header at relativeIndex, along with a boolean indicating if the returned index is a duplicate. It may return 0 if the entry at relativeIndex was draining and could not be duplicated, or vulnerable references are not allowed.
Definition at line 228 of file QPACKHeaderTable.cpp.
References add(), baseIndex_, canIndex(), proxygen::HPACKHeader::copy(), getHeader(), isValid(), isVulnerable(), minUsable_, relativeToAbsolute(), uint32_t, and UNACKED.
Referenced by isDraining(), and proxygen::QPACKEncoder::maybeDuplicate().
uint32_t proxygen::QPACKHeaderTable::nameIndex | ( | const HPACKHeaderName & | headerName, |
bool | allowVulnerable = true |
||
) | const |
Get any index of a header that has the given name. From all the headers with the given name we pick the last one added to the header table, but the way we pick the header can be arbitrary.
See getIndex for a description of base/allowVulnerable
Definition at line 123 of file QPACKHeaderTable.cpp.
References getIndexImpl(), and value.
Referenced by proxygen::QPACKEncoder::getNameIndexQ(), and isDraining().
|
inline |
Definition at line 121 of file QPACKHeaderTable.h.
References baseIndex_, proxygen::ERROR, and maxAcked_.
Referenced by proxygen::QPACKEncoder::onTableStateSync().
|
delete |
Referenced by ~QPACKHeaderTable().
Convert a relative index to an absolute index
Definition at line 146 of file QPACKHeaderTable.h.
References baseIndex_, and isValid().
Referenced by internalToAbsolute(), isDraining(), and maybeDuplicate().
|
overrideprivatevirtual |
Removes one header entry from the beginning of the header table.
Reimplemented from proxygen::HeaderTable.
Definition at line 135 of file QPACKHeaderTable.cpp.
References baseIndex_, drainedBytes_, int32_t, internalToAbsolute(), minUsable_, refCount_, proxygen::HeaderTable::removeLast(), proxygen::HeaderTable::size(), and proxygen::HeaderTable::tail().
Referenced by absoluteToRelative().
|
overrideprivatevirtual |
Reimplemented from proxygen::HeaderTable.
Definition at line 167 of file QPACKHeaderTable.cpp.
References refCount_, and proxygen::HeaderTable::resizeTable().
Referenced by absoluteToRelative().
|
overridevirtual |
Sets the current capacity of the header table, and evicts entries if needed. Returns false if eviction failed.
Reimplemented from proxygen::HeaderTable.
Definition at line 78 of file QPACKHeaderTable.cpp.
References minFree_, refCount_, and proxygen::HeaderTable::setCapacity().
Referenced by isDraining().
|
inline |
Definition at line 135 of file QPACKHeaderTable.h.
References baseIndex_, and maxAcked_.
Referenced by proxygen::QPACKEncoder::onHeaderAck().
void proxygen::QPACKHeaderTable::subRef | ( | uint32_t | absIndex | ) |
Subtract a reference for the given index
Definition at line 261 of file QPACKHeaderTable.cpp.
References absoluteToInternal(), refCount_, and uint32_t.
Referenced by absoluteToRelative(), and proxygen::QPACKEncoder::onHeaderAck().
|
private |
Translate external index to internal one.
Definition at line 281 of file QPACKHeaderTable.cpp.
References absoluteToRelative(), proxygen::HeaderTable::toInternal(), and uint32_t.
Referenced by absoluteToInternal(), absoluteToRelative(), and getHeader().
|
overrideprivatevirtual |
Reimplemented from proxygen::HeaderTable.
Definition at line 174 of file QPACKHeaderTable.cpp.
References refCount_, and proxygen::HeaderTable::updateResizedTable().
Referenced by absoluteToRelative().
|
private |
Definition at line 212 of file QPACKHeaderTable.h.
Referenced by absoluteToRelative(), add(), getBaseIndex(), increaseTableLengthTo(), isValid(), maybeDuplicate(), onTableStateSync(), relativeToAbsolute(), removeLast(), and setMaxAcked().
|
private |
Definition at line 213 of file QPACKHeaderTable.h.
Referenced by add(), and removeLast().
|
private |
Definition at line 215 of file QPACKHeaderTable.h.
Referenced by canEvict(), getIndexImpl(), isVulnerable(), onTableStateSync(), and setMaxAcked().
|
private |
Definition at line 217 of file QPACKHeaderTable.h.
Referenced by add(), canIndex(), QPACKHeaderTable(), and setCapacity().
|
private |
Definition at line 214 of file QPACKHeaderTable.h.
Referenced by add(), isDraining(), maybeDuplicate(), and removeLast().
|
private |
Definition at line 216 of file QPACKHeaderTable.h.
Referenced by add(), addRef(), canEvict(), QPACKHeaderTable(), removeLast(), resizeTable(), setCapacity(), subRef(), and updateResizedTable().