proxygen
QPACKEncoder.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 <folly/io/IOBuf.h>
13 #include <list>
18 #include <vector>
19 #include <set>
20 
21 namespace proxygen {
22 
23 class HPACKDecodeBuffer;
24 
25 class QPACKEncoder : public HPACKEncoderBase, public QPACKContext {
26 
27  public:
28  explicit QPACKEncoder(bool huffman,
29  uint32_t tableSize=HPACK::kTableSize);
30 
35  using Buf = std::unique_ptr<folly::IOBuf>;
36  struct EncodeResult {
38  : control(std::move(c)), stream(std::move(s)) {}
41  };
42 
43  // Returns a pair of buffers. One for the control stream and one for the
44  // request stream
46  const std::vector<HPACKHeader>& headers,
47  uint32_t headroom,
48  uint64_t streamId);
49 
51  std::unique_ptr<folly::IOBuf> buf);
52 
54 
56 
59  }
60 
61  void setMaxVulnerable(uint32_t maxVulnerable) {
62  maxVulnerable_ = maxVulnerable;
63  }
64 
65  private:
66  bool allowVulnerable() const {
68  }
69 
70  bool shouldIndex(const HPACKHeader& header) const;
71 
72  void encodeControl(const HPACKHeader& header);
73 
74  std::pair<bool, uint32_t> maybeDuplicate(uint32_t relativeIndex);
75 
77  encodeQ(const std::vector<HPACKHeader>& headers, uint64_t streamId);
78 
79  std::tuple<bool, uint32_t, uint32_t> getNameIndexQ(
80  const HPACKHeaderName& headerName);
81 
83  const HPACKHeader& header, bool isStaticName, uint32_t nameIndex,
84  uint32_t absoluteNameIndex, uint32_t baseIndex, uint32_t* largestReference);
85 
86  void encodeHeaderQ(const HPACKHeader& header, uint32_t baseIndex,
87  uint32_t* largestReference);
88 
89  void encodeInsertQ(const HPACKHeader& header,
90  bool isStaticName,
91  uint32_t nameIndex);
92 
93  void encodeLiteralQ(const HPACKHeader& header,
94  bool isStaticName,
95  bool postBase,
96  uint32_t nameIndex,
97  const HPACK::Instruction& idxInstr);
98 
100  const HPACKHeader& header,
101  bool isStaticName,
102  uint32_t nameIndex,
103  uint8_t staticFlag,
104  const HPACK::Instruction& idxInstr,
105  const HPACK::Instruction& litInstr);
106 
107  void trackReference(uint32_t index, uint32_t* largestReference);
108 
109  void encodeDuplicate(uint32_t index);
110 
112  uint8_t prefixLength,
113  bool all);
114 
116  using BlockReferences = std::set<uint32_t>;
119  bool vulnerable{false};
120  };
121  // Map streamID -> list of table index references for each outstanding block;
122  std::unordered_map<uint64_t, std::list<OutstandingBlock>> outstanding_;
128 };
129 
130 }
const uint32_t kTableSize
std::vector< uint8_t > buffer(kBufferSize+16)
std::set< uint32_t > BlockReferences
Definition: QPACKEncoder.h:116
QPACKHeaderTable table_
Definition: QPACKContext.h:54
void encodeInsertQ(const HPACKHeader &header, bool isStaticName, uint32_t nameIndex)
void encodeControl(const HPACKHeader &header)
std::pair< bool, uint32_t > maybeDuplicate(uint32_t relativeIndex)
void setMaxVulnerable(uint32_t maxVulnerable)
Definition: QPACKEncoder.h:61
HPACKEncodeBuffer controlBuffer_
Definition: QPACKEncoder.h:115
bool shouldIndex(const HPACKHeader &header) const
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void encodeLiteralQHelper(HPACKEncodeBuffer &buffer, const HPACKHeader &header, bool isStaticName, uint32_t nameIndex, uint8_t staticFlag, const HPACK::Instruction &idxInstr, const HPACK::Instruction &litInstr)
STL namespace.
HPACK::DecodeError onHeaderAck(uint64_t streamId, bool all)
void encodeDuplicate(uint32_t index)
void encodeStreamLiteralQ(const HPACKHeader &header, bool isStaticName, uint32_t nameIndex, uint32_t absoluteNameIndex, uint32_t baseIndex, uint32_t *largestReference)
OutstandingBlock * curOutstanding_
Definition: QPACKEncoder.h:123
HPACK::DecodeError decodeDecoderStream(std::unique_ptr< folly::IOBuf > buf)
void setHeaderTableSize(uint32_t size)
Definition: QPACKEncoder.h:57
EncodeResult encode(const std::vector< HPACKHeader > &headers, uint32_t headroom, uint64_t streamId)
void trackReference(uint32_t index, uint32_t *largestReference)
QPACKEncoder(bool huffman, uint32_t tableSize=HPACK::kTableSize)
constexpr auto size(C const &c) -> decltype(c.size())
Definition: Access.h:45
void encodeHeaderQ(const HPACKHeader &header, uint32_t baseIndex, uint32_t *largestReference)
static Options cacheChainLength()
Definition: IOBufQueue.h:83
bool allowVulnerable() const
Definition: QPACKEncoder.h:66
void encodeLiteralQ(const HPACKHeader &header, bool isStaticName, bool postBase, uint32_t nameIndex, const HPACK::Instruction &idxInstr)
void setHeaderTableSize(HeaderTable &table, uint32_t size)
HPACK::DecodeError decodeHeaderAck(HPACKDecodeBuffer &dbuf, uint8_t prefixLength, bool all)
folly::IOBufQueue decoderIngress_
Definition: QPACKEncoder.h:127
HPACK::DecodeError onTableStateSync(uint32_t inserts)
static set< string > s
std::unordered_map< uint64_t, std::list< OutstandingBlock > > outstanding_
Definition: QPACKEncoder.h:122
std::unique_ptr< folly::IOBuf > Buf
Definition: QPACKEncoder.h:35
char c
std::tuple< bool, uint32_t, uint32_t > getNameIndexQ(const HPACKHeaderName &headerName)
const uint32_t kDefaultBlocking
QPACKEncoder::EncodeResult encodeQ(const std::vector< HPACKHeader > &headers, uint64_t streamId)
Composed all(Predicate pred=Predicate())
Definition: Base.h:786