proxygen
proxygen::QPACKDecoder Class Reference

#include <QPACKDecoder.h>

Inheritance diagram for proxygen::QPACKDecoder:
proxygen::HPACKDecoderBase proxygen::QPACKContext folly::DestructorCheck

Classes

struct  Partial
 
struct  PendingBlock
 

Public Member Functions

 QPACKDecoder (uint32_t tableSize=HPACK::kTableSize, uint32_t maxUncompressed=HeaderCodec::kMaxUncompressed)
 
void decodeStreaming (uint64_t streamId, std::unique_ptr< folly::IOBuf > block, uint32_t totalBytes, HPACK::StreamingCallback *streamingCb)
 
HPACK::DecodeError decodeEncoderStream (std::unique_ptr< folly::IOBuf > buf)
 
std::unique_ptr< folly::IOBufencodeTableStateSync ()
 
std::unique_ptr< folly::IOBufencodeHeaderAck (uint64_t streamId) const
 
std::unique_ptr< folly::IOBufencodeCancelStream (uint64_t streamId)
 
uint64_t getHolBlockCount () const
 
uint64_t getQueuedBytes () const
 
void setMaxBlocking (uint32_t maxBlocking)
 
- Public Member Functions inherited from proxygen::HPACKDecoderBase
 HPACKDecoderBase (uint32_t tableSize, uint32_t maxUncompressed)
 
HPACK::DecodeError getError () const
 
bool hasError () const
 
void setHeaderTableMaxSize (uint32_t maxSize)
 
void setMaxUncompressed (uint64_t maxUncompressed)
 
- Public Member Functions inherited from proxygen::QPACKContext
 QPACKContext (uint32_t tableSize, bool trackReferences)
 
 ~QPACKContext ()
 
const HPACKHeadergetHeader (bool isStatic, uint32_t index, uint32_t base, bool aboveBase)
 
const QPACKHeaderTablegetTable () const
 
uint32_t getTableSize () const
 
uint32_t getBytesStored () const
 
uint32_t getHeadersStored () const
 
void seedHeaderTable (std::vector< HPACKHeader > &headers)
 
void describe (std::ostream &os) const
 
- Public Member Functions inherited from folly::DestructorCheck
virtual ~DestructorCheck ()
 

Private Member Functions

bool isValid (bool isStatic, uint32_t index, bool aboveBase)
 
uint32_t handleBaseIndex (HPACKDecodeBuffer &dbuf)
 
void decodeStreamingImpl (uint32_t largestReference, uint32_t consumed, HPACKDecodeBuffer &dbuf, HPACK::StreamingCallback *streamingCb)
 
uint32_t decodeHeaderQ (HPACKDecodeBuffer &dbuf, HPACK::StreamingCallback *streamingCb)
 
uint32_t decodeIndexedHeaderQ (HPACKDecodeBuffer &dbuf, uint32_t prefixLength, bool aboveBase, HPACK::StreamingCallback *streamingCb, headers_t *emitted)
 
uint32_t decodeLiteralHeaderQ (HPACKDecodeBuffer &dbuf, bool indexing, bool nameIndexed, uint8_t prefixLength, bool aboveBase, HPACK::StreamingCallback *streamingCb)
 
void decodeEncoderStreamInstruction (HPACKDecodeBuffer &dbuf)
 
void enqueueHeaderBlock (uint64_t streamId, uint32_t largestReference, uint32_t baseIndex, uint32_t consumed, std::unique_ptr< folly::IOBuf > block, size_t length, HPACK::StreamingCallback *streamingCb)
 
bool decodeBlock (uint32_t largestReference, const PendingBlock &pending)
 
void drainQueue ()
 

Private Attributes

uint32_t maxBlocking_ {HPACK::kDefaultBlocking}
 
uint32_t baseIndex_ {0}
 
uint32_t lastAcked_ {0}
 
uint32_t holBlockCount_ {0}
 
uint64_t queuedBytes_ {0}
 
std::multimap< uint32_t, PendingBlockqueue_
 
Partial partial_
 
folly::IOBufQueue ingress_ {folly::IOBufQueue::cacheChainLength()}
 

Additional Inherited Members

- Public Types inherited from proxygen::HPACKDecoderBase
using headers_t = std::vector< HPACKHeader >
 
- Protected Member Functions inherited from proxygen::HPACKDecoderBase
uint32_t emit (const HPACKHeader &header, HPACK::StreamingCallback *streamingCb, headers_t *emitted)
 
void completeDecode (HeaderCodec::Type type, HPACK::StreamingCallback *streamingCb, uint32_t compressedSize, uint32_t emittedSize)
 
void handleTableSizeUpdate (HPACKDecodeBuffer &dbuf, HeaderTable &table)
 
- Protected Member Functions inherited from proxygen::QPACKContext
const StaticHeaderTablegetStaticTable () const
 
- Protected Attributes inherited from proxygen::HPACKDecoderBase
HPACK::DecodeError err_ {HPACK::DecodeError::NONE}
 
uint32_t maxTableSize_
 
uint64_t maxUncompressed_
 
- Protected Attributes inherited from proxygen::QPACKContext
QPACKHeaderTable table_
 

Detailed Description

Definition at line 22 of file QPACKDecoder.h.

Constructor & Destructor Documentation

proxygen::QPACKDecoder::QPACKDecoder ( uint32_t  tableSize = HPACK::kTableSize,
uint32_t  maxUncompressed = HeaderCodec::kMaxUncompressed 
)
inlineexplicit

Definition at line 26 of file QPACKDecoder.h.

References decodeEncoderStream(), decodeStreaming(), encodeCancelStream(), encodeHeaderAck(), encodeTableStateSync(), uint32_t, and uint64_t.

29  : HPACKDecoderBase(tableSize, maxUncompressed),
30  QPACKContext(tableSize, false /* don't track references */) {}
HPACKDecoderBase(uint32_t tableSize, uint32_t maxUncompressed)
QPACKContext(uint32_t tableSize, bool trackReferences)

Member Function Documentation

bool proxygen::QPACKDecoder::decodeBlock ( uint32_t  largestReference,
const PendingBlock pending 
)
private

Definition at line 359 of file QPACKDecoder.cpp.

References proxygen::QPACKDecoder::PendingBlock::baseIndex, baseIndex_, proxygen::QPACKDecoder::PendingBlock::block, proxygen::QPACKDecoder::PendingBlock::cb, proxygen::QPACKDecoder::PendingBlock::consumed, decodeStreamingImpl(), folly::DestructorCheck::Safety::destroyed(), proxygen::QPACKDecoder::PendingBlock::length, proxygen::HPACKDecoderBase::maxUncompressed_, and queuedBytes_.

Referenced by drainQueue().

360  {
361  if (pending.length > 0) {
362  VLOG(5) << "decodeBlock len=" << pending.length;
363  folly::io::Cursor cursor(pending.block.get());
364  HPACKDecodeBuffer dbuf(cursor, pending.length, maxUncompressed_);
365  DCHECK_LE(pending.length, queuedBytes_);
366  queuedBytes_ -= pending.length;
367  baseIndex_ = pending.baseIndex;
368  folly::DestructorCheck::Safety safety(*this);
369  decodeStreamingImpl(largestReference, pending.consumed, dbuf, pending.cb);
370  // The callback way destroy this, if so stop queue processing
371  if (safety.destroyed()) {
372  return true;
373  }
374  }
375  return false;
376 }
void decodeStreamingImpl(uint32_t largestReference, uint32_t consumed, HPACKDecodeBuffer &dbuf, HPACK::StreamingCallback *streamingCb)
HPACK::DecodeError proxygen::QPACKDecoder::decodeEncoderStream ( std::unique_ptr< folly::IOBuf buf)

Definition at line 141 of file QPACKDecoder.cpp.

References folly::IOBufQueue::append(), baseIndex_, proxygen::HPACK::BUFFER_UNDERFLOW, folly::IOBufQueue::chainLength(), proxygen::QPACKDecoder::Partial::consumed, decodeEncoderStreamInstruction(), drainQueue(), proxygen::HPACKDecoderBase::err_, folly::IOBufQueue::front(), proxygen::HPACKDecoderBase::hasError(), ingress_, proxygen::HPACKDecoderBase::maxUncompressed_, folly::gen::move, proxygen::HPACK::NONE, partial_, and folly::IOBufQueue::trimStart().

Referenced by proxygen::hpack::encodeDecode(), QPACKDecoder(), and TEST().

142  {
143  ingress_.append(std::move(buf));
144  Cursor cursor(ingress_.front());
145  HPACKDecodeBuffer dbuf(cursor, ingress_.chainLength(), maxUncompressed_);
146  VLOG(6) << "Decoding control block";
147  baseIndex_ = 0;
149  while (!hasError() && !dbuf.empty()) {
153  drainQueue();
155  }
156  }
157  ingress_.trimStart(dbuf.consumedBytes());
158  if (hasError()) {
159  return err_;
160  } else {
161  drainQueue();
163  }
164 }
const folly::IOBuf * front() const
Definition: IOBufQueue.h:476
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
size_t chainLength() const
Definition: IOBufQueue.h:492
folly::IOBufQueue ingress_
Definition: QPACKDecoder.h:136
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void decodeEncoderStreamInstruction(HPACKDecodeBuffer &dbuf)
void trimStart(size_t amount)
Definition: IOBufQueue.cpp:255
void proxygen::QPACKDecoder::decodeEncoderStreamInstruction ( HPACKDecodeBuffer dbuf)
private

Definition at line 166 of file QPACKDecoder.cpp.

References proxygen::QPACKHeaderTable::add(), proxygen::HPACK::Instruction::code, proxygen::QPACKDecoder::Partial::consumed, proxygen::HPACKDecodeBuffer::consumedBytes(), decodeIndexedHeaderQ(), decodeLiteralHeaderQ(), proxygen::HPACKDecoderBase::handleTableSizeUpdate(), proxygen::HPACKDecoderBase::hasError(), folly::gen::move, partial_, proxygen::HPACKDecodeBuffer::peek(), proxygen::HPACK::Q_DUPLICATE, proxygen::HPACK::Q_INSERT_NAME_REF, proxygen::HPACK::Q_INSERT_NO_NAME_REF, proxygen::HPACK::Q_TABLE_SIZE_UPDATE, proxygen::QPACKContext::table_, uint8_t, and proxygen::QPACKDecoder::Partial::VALUE.

Referenced by decodeEncoderStream(), and setMaxBlocking().

166  {
167  uint8_t byte = dbuf.peek();
168  partial_.consumed = dbuf.consumedBytes();
169  if (partial_.state == Partial::VALUE ||
171  // If partial state is VALUE, it might have been a NO_NAME_REF instruction,
172  // but we've already parsed the name, so it doesn't matter
174  dbuf, true, true, HPACK::Q_INSERT_NAME_REF.prefixLength, false,
175  nullptr);
176  } else if (byte & HPACK::Q_INSERT_NO_NAME_REF.code) {
178  dbuf, true, false, HPACK::Q_INSERT_NO_NAME_REF.prefixLength, false,
179  nullptr);
180  } else if (byte & HPACK::Q_TABLE_SIZE_UPDATE.code) {
182  } else { // must be Q_DUPLICATE=000
183  headers_t emitted;
185  dbuf, HPACK::Q_DUPLICATE.prefixLength, false, nullptr, &emitted);
186  if (!hasError()) {
187  CHECK(!emitted.empty());
188  table_.add(std::move(emitted[0]));
189  }
190  }
191 }
const Instruction Q_INSERT_NO_NAME_REF
QPACKHeaderTable table_
Definition: QPACKContext.h:54
uint32_t decodeLiteralHeaderQ(HPACKDecodeBuffer &dbuf, bool indexing, bool nameIndexed, uint8_t prefixLength, bool aboveBase, HPACK::StreamingCallback *streamingCb)
std::vector< HPACKHeader > headers_t
const Instruction Q_DUPLICATE
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void handleTableSizeUpdate(HPACKDecodeBuffer &dbuf, HeaderTable &table)
uint32_t decodeIndexedHeaderQ(HPACKDecodeBuffer &dbuf, uint32_t prefixLength, bool aboveBase, HPACK::StreamingCallback *streamingCb, headers_t *emitted)
bool add(HPACKHeader header) override
const Instruction Q_TABLE_SIZE_UPDATE
const Instruction Q_INSERT_NAME_REF
uint32_t proxygen::QPACKDecoder::decodeHeaderQ ( HPACKDecodeBuffer dbuf,
HPACK::StreamingCallback streamingCb 
)
private

Definition at line 117 of file QPACKDecoder.cpp.

References decodeIndexedHeaderQ(), decodeLiteralHeaderQ(), proxygen::HPACKDecodeBuffer::peek(), proxygen::HPACK::Q_INDEXED, proxygen::HPACK::Q_INDEXED_POST, proxygen::HPACK::Q_LITERAL, proxygen::HPACK::Q_LITERAL_NAME_REF, proxygen::HPACK::Q_LITERAL_NAME_REF_POST, and uint8_t.

Referenced by decodeStreamingImpl(), and setMaxBlocking().

119  {
120  uint8_t byte = dbuf.peek();
121  if (byte & HPACK::Q_INDEXED.code) {
122  return decodeIndexedHeaderQ(
123  dbuf, HPACK::Q_INDEXED.prefixLength, false, streamingCb, nullptr);
124  } else if (byte & HPACK::Q_LITERAL_NAME_REF.code) {
125  return decodeLiteralHeaderQ(
126  dbuf, false, true, HPACK::Q_LITERAL_NAME_REF.prefixLength, false,
127  streamingCb);
128  } else if (byte & HPACK::Q_LITERAL.code) {
129  return decodeLiteralHeaderQ(
130  dbuf, false, false, HPACK::Q_LITERAL.prefixLength, false, streamingCb);
131  } else if (byte & HPACK::Q_INDEXED_POST.code) {
132  return decodeIndexedHeaderQ(
133  dbuf, HPACK::Q_INDEXED_POST.prefixLength, true, streamingCb, nullptr);
134  } else { // Q_LITERAL_NAME_REF_POST
135  return decodeLiteralHeaderQ(
136  dbuf, false, true, HPACK::Q_LITERAL_NAME_REF_POST.prefixLength, true,
137  streamingCb);
138  }
139 }
uint32_t decodeLiteralHeaderQ(HPACKDecodeBuffer &dbuf, bool indexing, bool nameIndexed, uint8_t prefixLength, bool aboveBase, HPACK::StreamingCallback *streamingCb)
const Instruction Q_INDEXED_POST
const Instruction Q_LITERAL_NAME_REF_POST
const Instruction Q_LITERAL
uint32_t decodeIndexedHeaderQ(HPACKDecodeBuffer &dbuf, uint32_t prefixLength, bool aboveBase, HPACK::StreamingCallback *streamingCb, headers_t *emitted)
const Instruction Q_INDEXED
const Instruction Q_LITERAL_NAME_REF
uint32_t proxygen::QPACKDecoder::decodeIndexedHeaderQ ( HPACKDecodeBuffer dbuf,
uint32_t  prefixLength,
bool  aboveBase,
HPACK::StreamingCallback streamingCb,
headers_t emitted 
)
private

Definition at line 262 of file QPACKDecoder.cpp.

References baseIndex_, proxygen::HPACKDecodeBuffer::decodeInteger(), proxygen::HPACKDecoderBase::emit(), proxygen::HPACKDecoderBase::err_, proxygen::ERROR, proxygen::QPACKContext::getHeader(), proxygen::HPACK::INVALID_INDEX, isValid(), proxygen::HPACK::NONE, proxygen::HPACKDecodeBuffer::peek(), and uint64_t.

Referenced by decodeEncoderStreamInstruction(), decodeHeaderQ(), and setMaxBlocking().

267  {
268  uint64_t index;
269  bool isStatic = !aboveBase && (dbuf.peek() & (1 << prefixLength));
270  err_ = dbuf.decodeInteger(prefixLength, index);
272  LOG(ERROR) << "Decode error decoding index err_=" << err_;
273  return 0;
274  }
275  if (!isStatic) {
276  index++;
277  }
278  // validate the index
279  if (index == 0 || !isValid(isStatic, index, aboveBase)) {
280  LOG(ERROR) << "received invalid index: " << index;
282  return 0;
283  }
284 
285  auto& header = getHeader(isStatic, index, baseIndex_, aboveBase);
286  return emit(header, streamingCb, emitted);
287 }
const HPACKHeader & getHeader(bool isStatic, uint32_t index, uint32_t base, bool aboveBase)
uint32_t emit(const HPACKHeader &header, HPACK::StreamingCallback *streamingCb, headers_t *emitted)
bool isValid(bool isStatic, uint32_t index, bool aboveBase)
uint32_t proxygen::QPACKDecoder::decodeLiteralHeaderQ ( HPACKDecodeBuffer dbuf,
bool  indexing,
bool  nameIndexed,
uint8_t  prefixLength,
bool  aboveBase,
HPACK::StreamingCallback streamingCb 
)
private

Definition at line 193 of file QPACKDecoder.cpp.

References proxygen::QPACKHeaderTable::add(), baseIndex_, proxygen::HPACK::BUFFER_UNDERFLOW, proxygen::QPACKDecoder::Partial::consumed, proxygen::HPACKDecodeBuffer::consumedBytes(), proxygen::HPACKDecodeBuffer::decodeInteger(), proxygen::HPACKDecodeBuffer::decodeLiteral(), proxygen::HPACKDecoderBase::emit(), proxygen::HPACKDecoderBase::err_, proxygen::ERROR, proxygen::QPACKContext::getHeader(), proxygen::QPACKDecoder::Partial::header, proxygen::HPACK::INVALID_INDEX, isValid(), folly::gen::move, proxygen::HPACKHeader::name, proxygen::QPACKDecoder::Partial::NAME, proxygen::HPACK::NONE, folly::partial(), partial_, proxygen::HPACKDecodeBuffer::peek(), proxygen::QPACKContext::table_, uint32_t, uint64_t, proxygen::HPACKHeader::value, and proxygen::QPACKDecoder::Partial::VALUE.

Referenced by decodeEncoderStreamInstruction(), decodeHeaderQ(), and setMaxBlocking().

199  {
200  bool allowPartial = (streamingCb == nullptr);
201  Partial localPartial;
202  Partial* partial = (allowPartial) ? &partial_ : &localPartial;
203  if (partial->state == Partial::NAME) {
204  if (nameIndexed) {
205  uint64_t nameIndex = 0;
206  bool isStaticName = !aboveBase && (dbuf.peek() & (1 << prefixLength));
207  err_ = dbuf.decodeInteger(prefixLength, nameIndex);
208  if (allowPartial && err_ == HPACK::DecodeError::BUFFER_UNDERFLOW) {
209  return 0;
210  }
212  LOG(ERROR) << "Decode error decoding index err_=" << err_;
213  return 0;
214  }
215  if (!isStaticName) {
216  nameIndex++;
217  }
218  // validate the index
219  if (!isValid(isStaticName, nameIndex, aboveBase)) {
220  LOG(ERROR) << "received invalid index: " << nameIndex;
222  return 0;
223  }
224  partial->header.name = getHeader(
225  isStaticName, nameIndex, baseIndex_, aboveBase).name;
226  } else {
227  folly::fbstring headerName;
228  err_ = dbuf.decodeLiteral(prefixLength, headerName);
229  if (allowPartial && err_ == HPACK::DecodeError::BUFFER_UNDERFLOW) {
230  return 0;
231  }
233  LOG(ERROR) << "Error decoding header name err_=" << err_;
234  return 0;
235  }
236  partial->header.name = headerName;
237  }
238  partial->state = Partial::VALUE;
239  partial->consumed = dbuf.consumedBytes();
240  }
241  // value
242  err_ = dbuf.decodeLiteral(partial->header.value);
243  if (allowPartial && err_ == HPACK::DecodeError::BUFFER_UNDERFLOW) {
244  return 0;
245  }
247  LOG(ERROR) << "Error decoding header value name=" << partial->header.name
248  << " err_=" << err_;
249  return 0;
250  }
251  partial->state = Partial::NAME;
252 
253  uint32_t emittedSize = emit(partial->header, streamingCb, nullptr);
254 
255  if (indexing) {
256  table_.add(std::move(partial->header));
257  }
258 
259  return emittedSize;
260 }
QPACKHeaderTable table_
Definition: QPACKContext.h:54
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
bool add(HPACKHeader header) override
const HPACKHeader & getHeader(bool isStatic, uint32_t index, uint32_t base, bool aboveBase)
auto partial(F &&f, Args &&...args) -> detail::partial::Partial< typename std::decay< F >::type, std::tuple< typename std::decay< Args >::type... >>
Definition: Partial.h:119
uint32_t emit(const HPACKHeader &header, HPACK::StreamingCallback *streamingCb, headers_t *emitted)
HPACKHeaderName name
Definition: HPACKHeader.h:82
bool isValid(bool isStatic, uint32_t index, bool aboveBase)
enum proxygen::QPACKDecoder::Partial::@105 NAME
void proxygen::QPACKDecoder::decodeStreaming ( uint64_t  streamId,
std::unique_ptr< folly::IOBuf block,
uint32_t  totalBytes,
HPACK::StreamingCallback streamingCb 
)

Definition at line 25 of file QPACKDecoder.cpp.

References folly::IOBufQueue::append(), baseIndex_, proxygen::HPACKDecoderBase::completeDecode(), decodeStreamingImpl(), enqueueHeaderBlock(), proxygen::HPACKDecoderBase::err_, proxygen::QPACKHeaderTable::getBaseIndex(), handleBaseIndex(), maxBlocking_, proxygen::HPACKDecoderBase::maxUncompressed_, folly::IOBufQueue::move(), folly::gen::move, proxygen::HPACK::NONE, proxygen::HeaderCodec::QPACK, queue_, proxygen::QPACKContext::table_, proxygen::HPACK::TOO_MANY_BLOCKING, folly::IOBufQueue::trimStart(), and uint32_t.

Referenced by checkQError(), proxygen::QPACKCodec::decodeStreaming(), proxygen::hpack::encodeDecode(), QPACKDecoder(), and TEST().

29  {
30  Cursor cursor(block.get());
31  HPACKDecodeBuffer dbuf(cursor, totalBytes, maxUncompressed_);
33  uint32_t largestReference = handleBaseIndex(dbuf);
34  if (largestReference > table_.getBaseIndex()) {
35  VLOG(5) << "largestReference=" << largestReference << " > baseIndex=" <<
36  table_.getBaseIndex() << ", queuing";
37  if (queue_.size() >= maxBlocking_) {
38  VLOG(2) << "QPACK queue is full size=" << queue_.size()
39  << " maxBlocking_=" << maxBlocking_;
41  completeDecode(HeaderCodec::Type::QPACK, streamingCb, 0, 0);
42  } else {
44  q.append(std::move(block));
45  q.trimStart(dbuf.consumedBytes());
46  enqueueHeaderBlock(streamID, largestReference, baseIndex_,
47  dbuf.consumedBytes(), q.move(),
48  totalBytes - dbuf.consumedBytes(), streamingCb);
49  }
50  } else {
51  decodeStreamingImpl(largestReference, 0, dbuf, streamingCb);
52  }
53 }
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
QPACKHeaderTable table_
Definition: QPACKContext.h:54
void enqueueHeaderBlock(uint64_t streamId, uint32_t largestReference, uint32_t baseIndex, uint32_t consumed, std::unique_ptr< folly::IOBuf > block, size_t length, HPACK::StreamingCallback *streamingCb)
std::multimap< uint32_t, PendingBlock > queue_
Definition: QPACKDecoder.h:126
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::unique_ptr< folly::IOBuf > move()
Definition: IOBufQueue.h:459
uint32_t getBaseIndex() const
void completeDecode(HeaderCodec::Type type, HPACK::StreamingCallback *streamingCb, uint32_t compressedSize, uint32_t emittedSize)
void decodeStreamingImpl(uint32_t largestReference, uint32_t consumed, HPACKDecodeBuffer &dbuf, HPACK::StreamingCallback *streamingCb)
void trimStart(size_t amount)
Definition: IOBufQueue.cpp:255
uint32_t handleBaseIndex(HPACKDecodeBuffer &dbuf)
uint32_t streamID
Definition: SPDYCodec.cpp:131
void proxygen::QPACKDecoder::decodeStreamingImpl ( uint32_t  largestReference,
uint32_t  consumed,
HPACKDecodeBuffer dbuf,
HPACK::StreamingCallback streamingCb 
)
private

Definition at line 90 of file QPACKDecoder.cpp.

References proxygen::HPACKDecoderBase::completeDecode(), proxygen::HPACKDecodeBuffer::consumedBytes(), decodeHeaderQ(), proxygen::HPACKDecodeBuffer::empty(), proxygen::HPACKDecoderBase::err_, proxygen::ERROR, proxygen::HPACKDecoderBase::hasError(), proxygen::HPACK::HEADERS_TOO_LARGE, lastAcked_, max, proxygen::HPACKDecoderBase::maxUncompressed_, proxygen::HeaderCodec::QPACK, and uint32_t.

Referenced by decodeBlock(), decodeStreaming(), and setMaxBlocking().

93  {
94  uint32_t emittedSize = 0;
95 
96  while (!hasError() && !dbuf.empty()) {
97  emittedSize += decodeHeaderQ(dbuf, streamingCb);
98  if (emittedSize > maxUncompressed_) {
99  LOG(ERROR) << "exceeded uncompressed size limit of "
100  << maxUncompressed_ << " bytes";
102  break;
103  }
104  emittedSize += 2;
105  }
106 
107  if (!hasError()) {
108  // This is a little premature, since the ack doesn't get generated here.
109  // lastAcked_ is only read in encodeTableStateSync, so all completed header
110  // blocks must be call encodeHeaderAck BEFORE calling encodeTableStateSync.
111  lastAcked_ = std::max(lastAcked_, largestReference);
112  }
114  consumed + dbuf.consumedBytes(), emittedSize);
115 }
LogLevel max
Definition: LogLevel.cpp:31
uint32_t decodeHeaderQ(HPACKDecodeBuffer &dbuf, HPACK::StreamingCallback *streamingCb)
void completeDecode(HeaderCodec::Type type, HPACK::StreamingCallback *streamingCb, uint32_t compressedSize, uint32_t emittedSize)
void proxygen::QPACKDecoder::drainQueue ( )
private

Definition at line 378 of file QPACKDecoder.cpp.

References decodeBlock(), proxygen::QPACKHeaderTable::getBaseIndex(), proxygen::HPACKDecoderBase::hasError(), queue_, and proxygen::QPACKContext::table_.

Referenced by decodeEncoderStream().

378  {
379  auto it = queue_.begin();
380  while (!queue_.empty() && it->first <= table_.getBaseIndex() &&
381  !hasError()) {
382  if (decodeBlock(it->first, it->second)) {
383  return;
384  }
385  queue_.erase(it);
386  it = queue_.begin();
387  }
388 }
QPACKHeaderTable table_
Definition: QPACKContext.h:54
std::multimap< uint32_t, PendingBlock > queue_
Definition: QPACKDecoder.h:126
uint32_t getBaseIndex() const
bool decodeBlock(uint32_t largestReference, const PendingBlock &pending)
std::unique_ptr< folly::IOBuf > proxygen::QPACKDecoder::encodeCancelStream ( uint64_t  streamId)

Definition at line 323 of file QPACKDecoder.cpp.

References proxygen::HPACKEncodeBuffer::encodeInteger(), proxygen::HPACK::Q_CANCEL_STREAM, queue_, and proxygen::HPACKEncodeBuffer::release().

Referenced by QPACKDecoder().

324  {
325  // Remove this stream from the queue
326  auto it = queue_.begin();
327  while (it != queue_.end()) {
328  if (it->second.streamID == streamId) {
329  it = queue_.erase(it);
330  } else {
331  it++;
332  }
333  }
334  HPACKEncodeBuffer ackEncoder(kGrowth, false);
335  ackEncoder.encodeInteger(streamId, HPACK::Q_CANCEL_STREAM);
336  return ackEncoder.release();
337 }
std::multimap< uint32_t, PendingBlock > queue_
Definition: QPACKDecoder.h:126
const Instruction Q_CANCEL_STREAM
std::unique_ptr< folly::IOBuf > proxygen::QPACKDecoder::encodeHeaderAck ( uint64_t  streamId) const

Definition at line 315 of file QPACKDecoder.cpp.

References proxygen::HPACKEncodeBuffer::encodeInteger(), proxygen::HPACK::Q_HEADER_ACK, and proxygen::HPACKEncodeBuffer::release().

Referenced by proxygen::hpack::encodeDecode(), and QPACKDecoder().

316  {
317  HPACKEncodeBuffer ackEncoder(kGrowth, false);
318  VLOG(6) << "encodeHeaderAck id=" << streamId;
319  ackEncoder.encodeInteger(streamId, HPACK::Q_HEADER_ACK);
320  return ackEncoder.release();
321 }
const Instruction Q_HEADER_ACK
std::unique_ptr< folly::IOBuf > proxygen::QPACKDecoder::encodeTableStateSync ( )

Definition at line 302 of file QPACKDecoder.cpp.

References proxygen::HPACKEncodeBuffer::encodeInteger(), proxygen::QPACKHeaderTable::getBaseIndex(), lastAcked_, proxygen::HPACK::Q_TABLE_STATE_SYNC, proxygen::HPACKEncodeBuffer::release(), proxygen::QPACKContext::table_, and uint32_t.

Referenced by proxygen::hpack::encodeDecode(), QPACKDecoder(), and TEST().

302  {
304  if (toAck > 0) {
305  VLOG(6) << "encodeTableStateSync toAck=" << toAck;
306  HPACKEncodeBuffer ackEncoder(kGrowth, false);
307  ackEncoder.encodeInteger(toAck, HPACK::Q_TABLE_STATE_SYNC);
309  return ackEncoder.release();
310  } else {
311  return nullptr;
312  }
313 }
const Instruction Q_TABLE_STATE_SYNC
QPACKHeaderTable table_
Definition: QPACKContext.h:54
uint32_t getBaseIndex() const
void proxygen::QPACKDecoder::enqueueHeaderBlock ( uint64_t  streamId,
uint32_t  largestReference,
uint32_t  baseIndex,
uint32_t  consumed,
std::unique_ptr< folly::IOBuf block,
size_t  length,
HPACK::StreamingCallback streamingCb 
)
private

Definition at line 339 of file QPACKDecoder.cpp.

References proxygen::QPACKHeaderTable::getBaseIndex(), holBlockCount_, folly::gen::move, queue_, queuedBytes_, and proxygen::QPACKContext::table_.

Referenced by decodeStreaming(), and setMaxBlocking().

346  {
347  // TDOO: this queue is currently unbounded and has no timeouts
348  CHECK_GT(largestReference, table_.getBaseIndex());
349  queue_.emplace(
350  std::piecewise_construct,
351  std::forward_as_tuple(largestReference),
352  std::forward_as_tuple(streamID, baseIndex, length, consumed,
353  std::move(block), streamingCb));
354  holBlockCount_++;
355  VLOG(5) << "queued block=" << largestReference << " len=" << length;
356  queuedBytes_ += length;
357 }
QPACKHeaderTable table_
Definition: QPACKContext.h:54
std::multimap< uint32_t, PendingBlock > queue_
Definition: QPACKDecoder.h:126
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
uint32_t getBaseIndex() const
uint32_t streamID
Definition: SPDYCodec.cpp:131
uint64_t proxygen::QPACKDecoder::getHolBlockCount ( ) const
inline

Definition at line 46 of file QPACKDecoder.h.

References holBlockCount_.

46  {
47  return holBlockCount_;
48  }
uint64_t proxygen::QPACKDecoder::getQueuedBytes ( ) const
inline

Definition at line 50 of file QPACKDecoder.h.

References queuedBytes_.

50  {
51  return queuedBytes_;
52  }
uint32_t proxygen::QPACKDecoder::handleBaseIndex ( HPACKDecodeBuffer dbuf)
private

Definition at line 55 of file QPACKDecoder.cpp.

References baseIndex_, proxygen::HPACK::BUFFER_UNDERFLOW, proxygen::HPACKDecodeBuffer::decodeInteger(), proxygen::HPACKDecodeBuffer::empty(), proxygen::HPACKDecoderBase::err_, proxygen::ERROR, proxygen::HPACK::INVALID_INDEX, proxygen::HPACK::NONE, proxygen::HPACKDecodeBuffer::peek(), proxygen::HPACK::Q_DELTA_BASE, proxygen::HPACK::Q_DELTA_BASE_NEG, and uint64_t.

Referenced by decodeStreaming(), and setMaxBlocking().

55  {
56  uint64_t largestReference;
57  err_ = dbuf.decodeInteger(largestReference);
59  LOG(ERROR) << "Decode error decoding largest reference err_=" << err_;
60  return 0;
61  }
62  VLOG(5) << "Decoded largestReference=" << largestReference;
63  uint64_t delta = 0;
64  if (dbuf.empty()) {
65  LOG(ERROR) << "Invalid prefix, no delta-base";
67  return 0;
68  }
69  bool neg = dbuf.peek() & HPACK::Q_DELTA_BASE_NEG;
70  err_ = dbuf.decodeInteger(HPACK::Q_DELTA_BASE.prefixLength, delta);
72  LOG(ERROR) << "Decode error decoding delta base=" << err_;
73  return 0;
74  }
75  if (neg) {
76  if (delta > largestReference) {
77  LOG(ERROR) << "Invalid delta=" << delta << " largestReference="
78  << largestReference;
80  return 0;
81  }
82  baseIndex_ = largestReference - delta;
83  } else {
84  baseIndex_ = largestReference + delta;
85  }
86  VLOG(5) << "Decoded baseIndex_=" << baseIndex_;
87  return largestReference;
88 }
const Instruction Q_DELTA_BASE
const uint8_t Q_DELTA_BASE_NEG
bool proxygen::QPACKDecoder::isValid ( bool  isStatic,
uint32_t  index,
bool  aboveBase 
)
private

Definition at line 289 of file QPACKDecoder.cpp.

References baseIndex_, proxygen::QPACKContext::getStaticTable(), proxygen::HeaderTable::isValid(), proxygen::QPACKHeaderTable::isValid(), proxygen::QPACKContext::table_, and uint32_t.

Referenced by decodeIndexedHeaderQ(), decodeLiteralHeaderQ(), and setMaxBlocking().

289  {
290  if (isStatic) {
291  return getStaticTable().isValid(index);
292  } else {
293  uint32_t baseIndex = baseIndex_;
294  if (aboveBase) {
295  baseIndex = baseIndex + index;
296  index = 1;
297  }
298  return table_.isValid(index, baseIndex);
299  }
300 }
QPACKHeaderTable table_
Definition: QPACKContext.h:54
bool isValid(uint32_t index) const
bool isValid(uint32_t index, uint32_t base=0) const
const StaticHeaderTable & getStaticTable() const
Definition: QPACKContext.h:50
void proxygen::QPACKDecoder::setMaxBlocking ( uint32_t  maxBlocking)
inline

Member Data Documentation

uint32_t proxygen::QPACKDecoder::baseIndex_ {0}
private
uint32_t proxygen::QPACKDecoder::holBlockCount_ {0}
private

Definition at line 124 of file QPACKDecoder.h.

Referenced by enqueueHeaderBlock(), and getHolBlockCount().

folly::IOBufQueue proxygen::QPACKDecoder::ingress_ {folly::IOBufQueue::cacheChainLength()}
private

Definition at line 136 of file QPACKDecoder.h.

Referenced by decodeEncoderStream().

uint32_t proxygen::QPACKDecoder::lastAcked_ {0}
private

Definition at line 123 of file QPACKDecoder.h.

Referenced by decodeStreamingImpl(), and encodeTableStateSync().

uint32_t proxygen::QPACKDecoder::maxBlocking_ {HPACK::kDefaultBlocking}
private

Definition at line 121 of file QPACKDecoder.h.

Referenced by decodeStreaming(), and setMaxBlocking().

Partial proxygen::QPACKDecoder::partial_
private
std::multimap<uint32_t, PendingBlock> proxygen::QPACKDecoder::queue_
private
uint64_t proxygen::QPACKDecoder::queuedBytes_ {0}
private

Definition at line 125 of file QPACKDecoder.h.

Referenced by decodeBlock(), enqueueHeaderBlock(), and getQueuedBytes().


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