proxygen
Main Page
Related Pages
Namespaces
Classes
Files
Examples
File List
File Members
QPACKHeaderTable.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 <
proxygen/lib/http/codec/compress/HPACKHeader.h
>
13
#include <
proxygen/lib/http/codec/compress/HeaderTable.h
>
14
15
namespace
proxygen
{
16
22
class
QPACKHeaderTable
:
public
HeaderTable
{
23
public
:
24
enum
{
25
UNACKED
=
std::numeric_limits<uint32_t>::max
()
26
};
27
28
QPACKHeaderTable
(
uint32_t
capacityVal,
bool
trackReferences);
29
30
~QPACKHeaderTable
() {}
31
QPACKHeaderTable
(
const
QPACKHeaderTable
&) =
delete
;
32
QPACKHeaderTable
&
operator=
(
const
QPACKHeaderTable
&) =
delete
;
33
38
uint32_t
getBaseIndex
()
const
{
39
return
baseIndex_
;
40
}
41
45
bool
isVulnerable
(
uint32_t
absIndex)
const
{
46
return
(absIndex >
maxAcked_
);
47
}
48
53
bool
canIndex
(
const
HPACKHeader
& header) {
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
}
59
63
bool
isDraining
(
uint32_t
relativeIndex) {
64
return
relativeToAbsolute
(relativeIndex) <
minUsable_
;
65
}
66
73
std::pair<bool, uint32_t>
maybeDuplicate
(
74
uint32_t
relativeIndex,
bool
allowVulnerable);
75
81
bool
add
(
HPACKHeader
header)
override
;
82
83
bool
setCapacity
(
uint32_t
capacity
)
override
;
84
92
uint32_t
getIndex
(
const
HPACKHeader
& header,
93
bool
allowVulnerable =
true
)
const
;
94
102
const
HPACKHeader
&
getHeader
(
uint32_t
index,
uint32_t
base = 0)
const
;
103
109
bool
isValid
(
uint32_t
index,
uint32_t
base = 0)
const
;
110
118
uint32_t
nameIndex
(
const
HPACKHeaderName
& headerName,
119
bool
allowVulnerable =
true
)
const
;
120
121
bool
onTableStateSync
(
uint32_t
inserts) {
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
}
134
135
void
setMaxAcked
(
uint32_t
maxAcked) {
136
if
(maxAcked <
maxAcked_
) {
137
return
;
138
}
139
CHECK_LE(maxAcked,
baseIndex_
);
140
maxAcked_
= maxAcked;
141
}
142
146
uint32_t
relativeToAbsolute
(
uint32_t
relativeIndex)
const
{
147
DCHECK(
isValid
(relativeIndex, 0));
148
return
baseIndex_
- relativeIndex + 1;
149
}
150
154
uint32_t
absoluteToRelative
(
uint32_t
absIndex)
const
{
155
CHECK_LE(absIndex,
baseIndex_
);
156
return
baseIndex_
- absIndex + 1;
157
}
158
163
void
addRef
(
uint32_t
absIndex);
164
168
void
subRef
(
uint32_t
absIndex);
169
170
private
:
171
/*
172
* Shared implementation for getIndex and nameIndex
173
*/
174
uint32_t
getIndexImpl
(
const
HPACKHeaderName
& header,
175
const
folly::fbstring
&
value
,
176
bool
nameOnly,
177
bool
allowVulnerable=
true
)
const
;
178
179
/*
180
* Increase table length to newLength
181
*/
182
void
increaseTableLengthTo
(
uint32_t
newLength)
override
;
183
184
void
resizeTable
(
uint32_t
newLength)
override
;
185
186
void
updateResizedTable
(
uint32_t
oldTail,
uint32_t
oldLength,
187
uint32_t
newLength)
override
;
191
uint32_t
removeLast
()
override
;
192
196
bool
canEvict
(
uint32_t
needed);
197
201
uint32_t
evict
(
uint32_t
needed,
uint32_t
desiredCapacity)
override
;
202
206
uint32_t
toInternal
(
uint32_t
externalIndex,
uint32_t
base)
const
;
207
208
209
uint32_t
internalToAbsolute
(
uint32_t
internalIndex)
const
;
210
uint32_t
absoluteToInternal
(
uint32_t
absoluteIndex)
const
;
211
212
uint32_t
baseIndex_
{0};
213
uint32_t
drainedBytes_
{0};
214
uint32_t
minUsable_
{1};
215
uint32_t
maxAcked_
{0};
216
std::unique_ptr<std::vector<uint16_t>>
refCount_
;
217
uint32_t
minFree_
{0};
218
};
219
220
}
proxygen::QPACKHeaderTable::updateResizedTable
void updateResizedTable(uint32_t oldTail, uint32_t oldLength, uint32_t newLength) override
Definition:
QPACKHeaderTable.cpp:174
proxygen::QPACKHeaderTable::resizeTable
void resizeTable(uint32_t newLength) override
Definition:
QPACKHeaderTable.cpp:167
proxygen::QPACKHeaderTable
Definition:
QPACKHeaderTable.h:22
proxygen::HeaderTable::capacity
uint32_t capacity() const
Definition:
HeaderTable.h:86
proxygen::QPACKHeaderTable::QPACKHeaderTable
QPACKHeaderTable(uint32_t capacityVal, bool trackReferences)
Definition:
QPACKHeaderTable.cpp:39
proxygen::QPACKHeaderTable::minUsable_
uint32_t minUsable_
Definition:
QPACKHeaderTable.h:214
proxygen::QPACKHeaderTable::UNACKED
Definition:
QPACKHeaderTable.h:25
max
LogLevel max
Definition:
LogLevel.cpp:31
proxygen::QPACKHeaderTable::baseIndex_
uint32_t baseIndex_
Definition:
QPACKHeaderTable.h:212
HeaderTable.h
folly::basic_fbstring< char >
proxygen::HeaderTable
Definition:
HeaderTable.h:26
proxygen::QPACKHeaderTable::internalToAbsolute
uint32_t internalToAbsolute(uint32_t internalIndex) const
Definition:
QPACKHeaderTable.cpp:270
proxygen::QPACKHeaderTable::toInternal
uint32_t toInternal(uint32_t externalIndex, uint32_t base) const
Definition:
QPACKHeaderTable.cpp:281
proxygen::QPACKHeaderTable::absoluteToInternal
uint32_t absoluteToInternal(uint32_t absoluteIndex) const
Definition:
QPACKHeaderTable.cpp:276
proxygen::QPACKHeaderTable::getBaseIndex
uint32_t getBaseIndex() const
Definition:
QPACKHeaderTable.h:38
proxygen::QPACKHeaderTable::removeLast
uint32_t removeLast() override
Definition:
QPACKHeaderTable.cpp:135
proxygen::HPACKHeaderName
Definition:
HPACKHeaderName.h:29
proxygen::QPACKHeaderTable::isVulnerable
bool isVulnerable(uint32_t absIndex) const
Definition:
QPACKHeaderTable.h:45
proxygen::QPACKHeaderTable::isDraining
bool isDraining(uint32_t relativeIndex)
Definition:
QPACKHeaderTable.h:63
HPACKHeader.h
proxygen::QPACKHeaderTable::setMaxAcked
void setMaxAcked(uint32_t maxAcked)
Definition:
QPACKHeaderTable.h:135
proxygen::QPACKHeaderTable::refCount_
std::unique_ptr< std::vector< uint16_t > > refCount_
Definition:
QPACKHeaderTable.h:216
proxygen::QPACKHeaderTable::onTableStateSync
bool onTableStateSync(uint32_t inserts)
Definition:
QPACKHeaderTable.h:121
proxygen::HPACKHeader::bytes
uint32_t bytes() const
Definition:
HPACKHeader.h:49
proxygen::QPACKHeaderTable::add
bool add(HPACKHeader header) override
Definition:
QPACKHeaderTable.cpp:49
proxygen::HPACKHeader
Definition:
HPACKHeader.h:20
proxygen::HeaderTable::bytes_
uint32_t bytes_
Definition:
HeaderTable.h:188
proxygen::QPACKHeaderTable::absoluteToRelative
uint32_t absoluteToRelative(uint32_t absIndex) const
Definition:
QPACKHeaderTable.h:154
proxygen::QPACKHeaderTable::canIndex
bool canIndex(const HPACKHeader &header)
Definition:
QPACKHeaderTable.h:53
proxygen::QPACKHeaderTable::maybeDuplicate
std::pair< bool, uint32_t > maybeDuplicate(uint32_t relativeIndex, bool allowVulnerable)
Definition:
QPACKHeaderTable.cpp:228
proxygen::ZstdStatusType::ERROR
value
static const char *const value
Definition:
Conv.cpp:50
proxygen::QPACKHeaderTable::getIndexImpl
uint32_t getIndexImpl(const HPACKHeaderName &header, const folly::fbstring &value, bool nameOnly, bool allowVulnerable=true) const
Definition:
QPACKHeaderTable.cpp:93
proxygen::QPACKHeaderTable::isValid
bool isValid(uint32_t index, uint32_t base=0) const
Definition:
QPACKHeaderTable.cpp:212
proxygen::QPACKHeaderTable::evict
uint32_t evict(uint32_t needed, uint32_t desiredCapacity) override
Definition:
QPACKHeaderTable.cpp:184
proxygen::HeaderTable::capacity_
uint32_t capacity_
Definition:
HeaderTable.h:187
proxygen::QPACKHeaderTable::drainedBytes_
uint32_t drainedBytes_
Definition:
QPACKHeaderTable.h:213
proxygen::QPACKHeaderTable::addRef
void addRef(uint32_t absIndex)
Definition:
QPACKHeaderTable.cpp:254
proxygen::QPACKHeaderTable::getHeader
const HPACKHeader & getHeader(uint32_t index, uint32_t base=0) const
Definition:
QPACKHeaderTable.cpp:129
proxygen::QPACKHeaderTable::relativeToAbsolute
uint32_t relativeToAbsolute(uint32_t relativeIndex) const
Definition:
QPACKHeaderTable.h:146
proxygen::QPACKHeaderTable::getIndex
uint32_t getIndex(const HPACKHeader &header, bool allowVulnerable=true) const
Definition:
QPACKHeaderTable.cpp:88
proxygen
Definition:
ExMessageHandler.h:14
proxygen::QPACKHeaderTable::increaseTableLengthTo
void increaseTableLengthTo(uint32_t newLength) override
Definition:
QPACKHeaderTable.cpp:159
proxygen::QPACKHeaderTable::minFree_
uint32_t minFree_
Definition:
QPACKHeaderTable.h:217
uint32_t
uint32_t
Definition:
ConstexprMathBenchmark.cpp:186
proxygen::QPACKHeaderTable::subRef
void subRef(uint32_t absIndex)
Definition:
QPACKHeaderTable.cpp:261
proxygen::QPACKHeaderTable::~QPACKHeaderTable
~QPACKHeaderTable()
Definition:
QPACKHeaderTable.h:30
proxygen::QPACKHeaderTable::maxAcked_
uint32_t maxAcked_
Definition:
QPACKHeaderTable.h:215
proxygen::QPACKHeaderTable::operator=
QPACKHeaderTable & operator=(const QPACKHeaderTable &)=delete
proxygen::QPACKHeaderTable::setCapacity
bool setCapacity(uint32_t capacity) override
Definition:
QPACKHeaderTable.cpp:78
proxygen::QPACKHeaderTable::canEvict
bool canEvict(uint32_t needed)
Definition:
QPACKHeaderTable.cpp:192
proxygen::QPACKHeaderTable::nameIndex
uint32_t nameIndex(const HPACKHeaderName &headerName, bool allowVulnerable=true) const
Definition:
QPACKHeaderTable.cpp:123
proxygen
lib
http
codec
compress
QPACKHeaderTable.h
Generated by
1.8.11