proxygen
QPACKCodec.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
10 #pragma once
11 
12 #include <memory>
14 #include <proxygen/lib/http/codec/compress/HPACKCodec.h> // table info
19 #include <string>
20 #include <vector>
21 
22 namespace folly { namespace io {
23 class Cursor;
24 }}
25 
26 namespace proxygen {
27 
28 class HPACKHeader;
29 
30 /*
31  * Current version of the wire protocol. When we're making changes to the wire
32  * protocol we need to change this version and the ALPN string so that old
33  * clients will not be able to negotiate it anymore.
34  */
35 
36 class QPACKCodec : public HeaderCodec {
37  public:
38  QPACKCodec();
39  ~QPACKCodec() override {}
40 
41  // QPACK encode: id is used for internal tracking of references
43  std::vector<compress::Header>& headers, uint64_t id) noexcept;
44 
45  HPACK::DecodeError decodeEncoderStream(std::unique_ptr<folly::IOBuf> buf) {
46  // stats?
47  return decoder_.decodeEncoderStream(std::move(buf));
48  }
49 
50  // QPACK blocking decode. The decoder may queue the block if there are
51  // unsatisfied dependencies
52  void decodeStreaming(
53  uint64_t streamId,
54  std::unique_ptr<folly::IOBuf> block,
55  uint32_t length,
56  HPACK::StreamingCallback* streamingCb) noexcept;
57 
59  encoder_.setHeaderTableSize(size);
60  }
61 
63  decoder_.setHeaderTableMaxSize(size);
64  }
65 
66  // Process bytes on the decoder stream
68  std::unique_ptr<folly::IOBuf> buf) {
69  return encoder_.decodeDecoderStream(std::move(buf));
70  }
71 
72  // QPACK when a stream is reset. Clears all reference counts for outstanding
73  // blocks
74  void onStreamReset(uint64_t streamId) {
75  encoder_.onHeaderAck(streamId, true);
76  }
77 
78  std::unique_ptr<folly::IOBuf> encodeTableStateSync() {
79  return decoder_.encodeTableStateSync();
80  }
81 
82  std::unique_ptr<folly::IOBuf> encodeHeaderAck(uint64_t streamId) {
83  return decoder_.encodeHeaderAck(streamId);
84  }
85 
86  std::unique_ptr<folly::IOBuf> encodeCancelStream(uint64_t streamId) {
87  return decoder_.encodeCancelStream(streamId);
88  }
89 
90  void describe(std::ostream& os) const;
91 
92  void setMaxUncompressed(uint64_t maxUncompressed) override {
93  HeaderCodec::setMaxUncompressed(maxUncompressed);
94  decoder_.setMaxUncompressed(maxUncompressed);
95  }
96 
98  return HPACKTableInfo(encoder_.getTableSize(),
99  encoder_.getBytesStored(),
100  encoder_.getHeadersStored(),
101  decoder_.getTableSize(),
102  decoder_.getBytesStored(),
103  decoder_.getHeadersStored());
104  }
105 
107  encoder_.setHeaderIndexingStrategy(indexingStrat);
108  }
110  return encoder_.getHeaderIndexingStrategy();
111  }
112 
114  return decoder_.getHolBlockCount();
115  }
116 
118  return decoder_.getQueuedBytes();
119  }
120 
121  void setMaxVulnerable(uint32_t maxVulnerable) {
122  encoder_.setMaxVulnerable(maxVulnerable);
123  }
124 
125  void setMaxBlocking(uint32_t maxBlocking) {
126  decoder_.setMaxBlocking(maxBlocking);
127  }
128 
129  protected:
132 
133  private:
134  void recordCompressedSize(const QPACKEncoder::EncodeResult& encodeRes);
135 
136  std::vector<HPACKHeader> decodedHeaders_;
137 };
138 
139 std::ostream& operator<<(std::ostream& os, const QPACKCodec& codec);
140 }
std::unique_ptr< folly::IOBuf > encodeCancelStream(uint64_t streamId)
Definition: QPACKCodec.h:86
unique_ptr< IOBuf > encode(vector< HPACKHeader > &headers, HPACKEncoder &encoder)
std::vector< HPACKHeader > decodedHeaders_
Definition: QPACKCodec.h:136
~QPACKCodec() override
Definition: QPACKCodec.h:39
QPACKDecoder decoder_
Definition: QPACKCodec.h:131
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
CodecFactory codec
void setMaxVulnerable(uint32_t maxVulnerable)
Definition: QPACKCodec.h:121
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
requires E e noexcept(noexcept(s.error(std::move(e))))
void onStreamReset(uint64_t streamId)
Definition: QPACKCodec.h:74
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
HPACK::DecodeError decodeEncoderStream(std::unique_ptr< folly::IOBuf > buf)
Definition: QPACKCodec.h:45
void setDecoderHeaderTableMaxSize(uint32_t size)
Definition: QPACKCodec.h:62
std::unique_ptr< folly::IOBuf > encodeHeaderAck(uint64_t streamId)
Definition: QPACKCodec.h:82
HPACK::DecodeError decodeDecoderStream(std::unique_ptr< folly::IOBuf > buf)
Definition: QPACKCodec.h:67
void setMaxBlocking(uint32_t maxBlocking)
Definition: QPACKCodec.h:125
void setHeaderIndexingStrategy(const HeaderIndexingStrategy *indexingStrat)
Definition: QPACKCodec.h:106
HPACKTableInfo getHPACKTableInfo() const
Definition: QPACKCodec.h:97
QPACKEncoder encoder_
Definition: QPACKCodec.h:130
uint64_t getQueuedBytes() const
Definition: QPACKCodec.h:117
std::unique_ptr< folly::IOBuf > encodeTableStateSync()
Definition: QPACKCodec.h:78
void setEncoderHeaderTableSize(uint32_t size)
Definition: QPACKCodec.h:58
const HeaderIndexingStrategy * getHeaderIndexingStrategy() const
Definition: QPACKCodec.h:109
void setMaxUncompressed(uint64_t maxUncompressed) override
Definition: QPACKCodec.h:92
uint64_t getHolBlockCount() const
Definition: QPACKCodec.h:113
std::ostream & operator<<(std::ostream &out, dynamic const &d)
Definition: dynamic-inl.h:1158