proxygen
proxygen::QPACKHeaderTable Class Reference

#include <QPACKHeaderTable.h>

Inheritance diagram for proxygen::QPACKHeaderTable:
proxygen::HeaderTable

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
 
QPACKHeaderTableoperator= (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_tmaybeDuplicate (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 HPACKHeadergetHeader (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
 
HeaderTableoperator= (const HeaderTable &)=delete
 
uint32_t getIndex (const HPACKHeader &header) const
 
const HPACKHeadergetHeader (uint32_t index) const
 
bool isValid (uint32_t index) const
 
bool hasName (const HPACKHeaderName &headerName)
 
const names_mapnames () 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< HPACKHeadertable_
 
uint32_t size_ {0}
 
uint32_t head_ {0}
 
names_map names_
 

Detailed Description

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.

Member Enumeration Documentation

anonymous enum
Enumerator
UNACKED 

Definition at line 24 of file QPACKHeaderTable.h.

Constructor & Destructor Documentation

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().

40  : HeaderTable(capacityVal) {
41  if (trackReferences) {
42  refCount_ = std::make_unique<std::vector<uint16_t>>(table_.size(), 0);
43  minFree_ = getMinFree(capacityVal);
44  } else {
45  minFree_ = 0;
46  }
47 }
std::unique_ptr< std::vector< uint16_t > > refCount_
std::vector< HPACKHeader > table_
Definition: HeaderTable.h:189
HeaderTable(uint32_t capacityVal)
Definition: HeaderTable.h:30
proxygen::QPACKHeaderTable::~QPACKHeaderTable ( )
inline

Definition at line 30 of file QPACKHeaderTable.h.

References operator=(), and QPACKHeaderTable().

30 {}
proxygen::QPACKHeaderTable::QPACKHeaderTable ( const QPACKHeaderTable )
delete

Member Function Documentation

uint32_t proxygen::QPACKHeaderTable::absoluteToInternal ( uint32_t  absoluteIndex) const
private

Definition at line 276 of file QPACKHeaderTable.cpp.

References absoluteToRelative(), and toInternal().

Referenced by absoluteToRelative(), add(), addRef(), and subRef().

277  {
278  return toInternal(absoluteToRelative(absoluteIndex), 0);
279 }
uint32_t toInternal(uint32_t externalIndex, uint32_t base) const
uint32_t absoluteToRelative(uint32_t absIndex) const
uint32_t proxygen::QPACKHeaderTable::absoluteToRelative ( uint32_t  absIndex) const
inline
bool proxygen::QPACKHeaderTable::add ( HPACKHeader  header)
overridevirtual

Add the header entry at the beginning of the table (index=1)

Returns
true if it was able to add the entry

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().

49  {
51  LOG(ERROR) << "Cowardly refusing to add more entries since baseIndex_ "
52  " would wrap";
53  return false;
54  }
55 
56  VLOG(6) << "Adding header=" << header;
57  if (!HeaderTable::add(std::move(header))) {
58  return false;
59  }
60  if (refCount_) {
61  (*refCount_)[head_] = 0;
62  }
63  ++baseIndex_;
64  DCHECK_EQ(internalToAbsolute(head_), baseIndex_);
65  // Increase minUsable_ until the free space + drainedBytes is >= minFree.
66  // For HPACK, minFree is 0 and this is a no-op.
67  while (capacity_ - bytes_ + drainedBytes_ < minFree_ &&
69  auto bytes = table_[absoluteToInternal(minUsable_)].bytes();
70  VLOG(5) << "Draining absolute index " << minUsable_ << " bytes="
71  << bytes << " drainedBytes_= " << (drainedBytes_ + bytes);
73  minUsable_++;
74  }
75  return true;
76 }
LogLevel max
Definition: LogLevel.cpp:31
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
uint32_t internalToAbsolute(uint32_t internalIndex) const
uint32_t absoluteToInternal(uint32_t absoluteIndex) const
uint32_t bytes() const
Definition: HeaderTable.h:112
std::unique_ptr< std::vector< uint16_t > > refCount_
std::vector< HPACKHeader > table_
Definition: HeaderTable.h:189
virtual bool add(HPACKHeader header)
Definition: HeaderTable.cpp:33
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().

254  {
255  // refCount is 16 bits. It should really never get this big in practice,
256  // unless a decoder is not sending HEADER_ACK in a timely way.
257  CHECK(refCount_);
258  (*refCount_)[absoluteToInternal(absIndex)]++;
259 }
uint32_t absoluteToInternal(uint32_t absoluteIndex) const
std::unique_ptr< std::vector< uint16_t > > refCount_
bool proxygen::QPACKHeaderTable::canEvict ( uint32_t  needed)
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().

192  {
193  if (size_ == 0 || !refCount_) {
194  return needed <= capacity_;
195  }
196  uint32_t freeable = 0;
197  uint32_t i = tail();
198  uint32_t nChecked = 0;
199  while (nChecked++ < size() && freeable < needed && ((*refCount_)[i] == 0) &&
200  internalToAbsolute(i) <= maxAcked_) { // don't evict unacked headers
201  freeable += table_[i].bytes();
202  i = next(i);
203  }
204  if (freeable < needed) {
205  VLOG(5) << "header=" << table_[i].name << " blocked eviction, recount="
206  << (*refCount_)[i];
207  return false;
208  }
209  return true;
210 }
uint32_t internalToAbsolute(uint32_t internalIndex) const
std::unique_ptr< std::vector< uint16_t > > refCount_
uint32_t next(uint32_t i) const
std::vector< HPACKHeader > table_
Definition: HeaderTable.h:189
uint32_t size() const
Definition: HeaderTable.h:105
uint32_t tail() const
bool proxygen::QPACKHeaderTable::canIndex ( const HPACKHeader header)
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().

53  {
54  auto totalBytes = bytes_ + header.bytes();
55  // Don't index headers that would immediately be drained
56  return ((header.bytes() <= (capacity_ - minFree_)) &&
57  (totalBytes <= capacity_ || canEvict(totalBytes - capacity_)));
58  }
bool canEvict(uint32_t needed)
uint32_t proxygen::QPACKHeaderTable::evict ( uint32_t  needed,
uint32_t  desiredCapacity 
)
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().

184  {
185  if (bytes_ + needed < desiredCapacity ||
186  !canEvict(bytes_ + needed - desiredCapacity)) {
187  return 0;
188  }
189  return HeaderTable::evict(needed, desiredCapacity);
190 }
virtual uint32_t evict(uint32_t needed, uint32_t desiredCapacity)
bool canEvict(uint32_t needed)
uint32_t proxygen::QPACKHeaderTable::getBaseIndex ( ) const
inline
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.

Returns
the header entry

Definition at line 129 of file QPACKHeaderTable.cpp.

References isValid(), proxygen::HeaderTable::table_, and toInternal().

Referenced by proxygen::QPACKContext::getHeader(), isDraining(), and maybeDuplicate().

130  {
131  CHECK(isValid(index, base));
132  return table_[toInternal(index, base)];
133 }
uint32_t toInternal(uint32_t externalIndex, uint32_t base) const
bool isValid(uint32_t index, uint32_t base=0) const
std::vector< HPACKHeader > table_
Definition: HeaderTable.h:189
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.

Returns
0 in case the header is not found

Definition at line 88 of file QPACKHeaderTable.cpp.

References getIndexImpl(), proxygen::HPACKHeader::name, and proxygen::HPACKHeader::value.

Referenced by proxygen::QPACKEncoder::encodeHeaderQ(), and isDraining().

89  {
90  return getIndexImpl(header.name, header.value, false, allowVulnerable);
91 }
uint32_t getIndexImpl(const HPACKHeaderName &header, const folly::fbstring &value, bool nameOnly, bool allowVulnerable=true) const
uint32_t proxygen::QPACKHeaderTable::getIndexImpl ( const HPACKHeaderName header,
const folly::fbstring value,
bool  nameOnly,
bool  allowVulnerable = true 
) const
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().

96  {
97  auto it = names_.find(headerName);
98  if (it == names_.end()) {
99  return 0;
100  }
101  bool encoderHasUnackedEntry = false;
102  // Searching backwards gives smallest index, but more likely vulnerable
103  // Searching forwards least likely vulnerable but could prevent eviction
104  for (auto indexIt = it->second.rbegin(); indexIt != it->second.rend();
105  ++indexIt) {
106  auto i = *indexIt;
107  if (nameOnly || table_[i].value == value) {
108  // allow vulnerable or not vulnerable
109  if (allowVulnerable || internalToAbsolute(i) <= maxAcked_) {
110  // index *may* be draining, caller has to check
111  return toExternal(i);
112  } else {
113  encoderHasUnackedEntry = true;
114  }
115  }
116  }
117  if (encoderHasUnackedEntry) {
118  return UNACKED;
119  }
120  return 0;
121 }
uint32_t internalToAbsolute(uint32_t internalIndex) const
static uint32_t toExternal(uint32_t head, uint32_t length, uint32_t internalIndex)
std::vector< HPACKHeader > table_
Definition: HeaderTable.h:189
void proxygen::QPACKHeaderTable::increaseTableLengthTo ( uint32_t  newLength)
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().

159  {
161  if (size_ > 0) {
162  DCHECK_EQ(internalToAbsolute(head_), baseIndex_);
163  DCHECK_EQ(internalToAbsolute(tail()), baseIndex_ - size_ + 1);
164  }
165 }
uint32_t internalToAbsolute(uint32_t internalIndex) const
virtual void increaseTableLengthTo(uint32_t newLength)
uint32_t tail() const
uint32_t proxygen::QPACKHeaderTable::internalToAbsolute ( uint32_t  internalIndex) const
private

Definition at line 270 of file QPACKHeaderTable.cpp.

References relativeToAbsolute(), and proxygen::HeaderTable::toExternal().

Referenced by absoluteToRelative(), add(), canEvict(), getIndexImpl(), increaseTableLengthTo(), and removeLast().

271  {
272  return relativeToAbsolute(toExternal(internalIndex));
273 }
static uint32_t toExternal(uint32_t head, uint32_t length, uint32_t internalIndex)
uint32_t relativeToAbsolute(uint32_t relativeIndex) const
bool proxygen::QPACKHeaderTable::isDraining ( uint32_t  relativeIndex)
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.

63  {
64  return relativeToAbsolute(relativeIndex) < minUsable_;
65  }
uint32_t relativeToAbsolute(uint32_t relativeIndex) const
bool proxygen::QPACKHeaderTable::isValid ( uint32_t  index,
uint32_t  base = 0 
) const

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().

212  {
213  int64_t testIndex = index;
214  if (base > 0) {
215  auto baseOffset = ((int64_t)base - (int64_t)baseIndex_);
216  // recompute relative to current baseIndex_. testIndex may go negative
217  // if this is a reference to an entry that hasn't arrived yet
218  testIndex -= baseOffset;
219  }
220  return HeaderTable::isValid(testIndex);
221 }
bool isValid(uint32_t index) const
bool proxygen::QPACKHeaderTable::isVulnerable ( uint32_t  absIndex) const
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().

45  {
46  return (absIndex > maxAcked_);
47  }
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().

230  {
231  if (relativeIndex == UNACKED) {
232  return {false, 0};
233  }
234  DCHECK(isValid(relativeIndex));
235  uint32_t absIndex = relativeToAbsolute(relativeIndex);
236  DCHECK(!isVulnerable(absIndex) || allowVulnerable);
237  if (absIndex < minUsable_) {
238  // draining
239  const HPACKHeader& header = getHeader(relativeIndex);
240  if (canIndex(header)) {
241  CHECK(add(header.copy()));
242  if (allowVulnerable) {
243  return {true, baseIndex_};
244  } else {
245  return {true, 0};
246  }
247  } else {
248  return {false, 0};
249  }
250  }
251  return {false, absIndex};
252 }
bool isVulnerable(uint32_t absIndex) const
bool add(HPACKHeader header) override
bool canIndex(const HPACKHeader &header)
bool isValid(uint32_t index, uint32_t base=0) const
const HPACKHeader & getHeader(uint32_t index, uint32_t base=0) const
uint32_t relativeToAbsolute(uint32_t relativeIndex) const
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().

124  {
126  return getIndexImpl(headerName, value, true /* name only */, allowVulnerable);
127 }
static const char *const value
Definition: Conv.cpp:50
uint32_t getIndexImpl(const HPACKHeaderName &header, const folly::fbstring &value, bool nameOnly, bool allowVulnerable=true) const
bool proxygen::QPACKHeaderTable::onTableStateSync ( uint32_t  inserts)
inline

Definition at line 121 of file QPACKHeaderTable.h.

References baseIndex_, proxygen::ERROR, and maxAcked_.

Referenced by proxygen::QPACKEncoder::onTableStateSync().

121  {
122  // compare this way to avoid overflow
123  if (inserts > baseIndex_ ||
124  maxAcked_ > baseIndex_ - inserts) {
125  LOG(ERROR) << "Decoder ack'd too much maxAcked_="
126  << maxAcked_ << " baseIndex_=" << baseIndex_
127  << " inserts=" << inserts;
128  return false;
129  }
130  maxAcked_ += inserts;
131  CHECK_LE(maxAcked_, baseIndex_);
132  return true;
133  }
QPACKHeaderTable& proxygen::QPACKHeaderTable::operator= ( const QPACKHeaderTable )
delete

Referenced by ~QPACKHeaderTable().

uint32_t proxygen::QPACKHeaderTable::relativeToAbsolute ( uint32_t  relativeIndex) const
inline

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().

146  {
147  DCHECK(isValid(relativeIndex, 0));
148  return baseIndex_ - relativeIndex + 1;
149  }
bool isValid(uint32_t index, uint32_t base=0) const
uint32_t proxygen::QPACKHeaderTable::removeLast ( )
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().

135  {
136  auto idx = tail();
137  if (refCount_) {
138  CHECK_EQ((*refCount_)[idx], 0) << "Removed header with nonzero references";
139  }
140  auto removedBytes = HeaderTable::removeLast();
141  // Only non-zero when minUsable_ > baseIndex_ - size_.
142  if (drainedBytes_ > 0) {
143  VLOG(5) << "Removing draining entry=" << idx << " size=" << removedBytes
144  << " drainedBytes_=" << drainedBytes_ << " new drainedBytes_="
145  << (int32_t(drainedBytes_) - removedBytes);
146  CHECK_GE(drainedBytes_, removedBytes);
147  drainedBytes_ -= removedBytes;
148  } else {
149  // Keep minUsable_ as a valid index when evicting an undrained header
150  if (size() > 0) {
152  } else {
153  minUsable_ = baseIndex_ + 1;
154  }
155  }
156  return removedBytes;
157 }
uint32_t internalToAbsolute(uint32_t internalIndex) const
std::unique_ptr< std::vector< uint16_t > > refCount_
virtual uint32_t removeLast()
uint32_t size() const
Definition: HeaderTable.h:105
uint32_t tail() const
void proxygen::QPACKHeaderTable::resizeTable ( uint32_t  newLength)
overrideprivatevirtual

Reimplemented from proxygen::HeaderTable.

Definition at line 167 of file QPACKHeaderTable.cpp.

References refCount_, and proxygen::HeaderTable::resizeTable().

Referenced by absoluteToRelative().

167  {
168  HeaderTable::resizeTable(newLength);
169  if (refCount_) {
170  refCount_->resize(newLength);
171  }
172 }
std::unique_ptr< std::vector< uint16_t > > refCount_
virtual void resizeTable(uint32_t newLength)
bool proxygen::QPACKHeaderTable::setCapacity ( uint32_t  capacity)
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().

78  {
80  return false;
81  }
82  if (refCount_) {
83  minFree_ = getMinFree(capacity);
84  } // else minFree is always 0
85  return true;
86 }
uint32_t capacity() const
Definition: HeaderTable.h:86
std::unique_ptr< std::vector< uint16_t > > refCount_
virtual bool setCapacity(uint32_t capacity)
void proxygen::QPACKHeaderTable::setMaxAcked ( uint32_t  maxAcked)
inline

Definition at line 135 of file QPACKHeaderTable.h.

References baseIndex_, and maxAcked_.

Referenced by proxygen::QPACKEncoder::onHeaderAck().

135  {
136  if (maxAcked < maxAcked_) {
137  return;
138  }
139  CHECK_LE(maxAcked, baseIndex_);
140  maxAcked_ = maxAcked;
141  }
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().

261  {
262  CHECK(refCount_);
263  uint32_t index = absoluteToInternal(absIndex);
264  CHECK_GT((*refCount_)[index], 0);
265  (*refCount_)[index]--;
266 }
uint32_t absoluteToInternal(uint32_t absoluteIndex) const
std::unique_ptr< std::vector< uint16_t > > refCount_
uint32_t proxygen::QPACKHeaderTable::toInternal ( uint32_t  externalIndex,
uint32_t  base 
) const
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().

282  {
283  if (base > 0) {
284  uint32_t absIndex = base - externalIndex + 1;
285  externalIndex = absoluteToRelative(absIndex);
286  }
287  return HeaderTable::toInternal(externalIndex);
288 }
uint32_t absoluteToRelative(uint32_t absIndex) const
static uint32_t toInternal(uint32_t head, uint32_t length, uint32_t externalIndex)
void proxygen::QPACKHeaderTable::updateResizedTable ( uint32_t  oldTail,
uint32_t  oldLength,
uint32_t  newLength 
)
overrideprivatevirtual

Reimplemented from proxygen::HeaderTable.

Definition at line 174 of file QPACKHeaderTable.cpp.

References refCount_, and proxygen::HeaderTable::updateResizedTable().

Referenced by absoluteToRelative().

175  {
176  HeaderTable::updateResizedTable(oldTail, oldLength, newLength);
177  if (refCount_) {
178  std::move_backward(refCount_->begin() + oldTail,
179  refCount_->begin() + oldLength,
180  refCount_->begin() + newLength);
181  }
182 }
std::unique_ptr< std::vector< uint16_t > > refCount_
virtual void updateResizedTable(uint32_t oldTail, uint32_t oldLength, uint32_t newLength)

Member Data Documentation

uint32_t proxygen::QPACKHeaderTable::baseIndex_ {0}
private
uint32_t proxygen::QPACKHeaderTable::drainedBytes_ {0}
private

Definition at line 213 of file QPACKHeaderTable.h.

Referenced by add(), and removeLast().

uint32_t proxygen::QPACKHeaderTable::maxAcked_ {0}
private
uint32_t proxygen::QPACKHeaderTable::minFree_ {0}
private

Definition at line 217 of file QPACKHeaderTable.h.

Referenced by add(), canIndex(), QPACKHeaderTable(), and setCapacity().

uint32_t proxygen::QPACKHeaderTable::minUsable_ {1}
private

Definition at line 214 of file QPACKHeaderTable.h.

Referenced by add(), isDraining(), maybeDuplicate(), and removeLast().

std::unique_ptr<std::vector<uint16_t> > proxygen::QPACKHeaderTable::refCount_
private

The documentation for this class was generated from the following files: