OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_QUIC_QUIC_PROTOCOL_H_ | 5 #ifndef NET_QUIC_QUIC_PROTOCOL_H_ |
6 #define NET_QUIC_QUIC_PROTOCOL_H_ | 6 #define NET_QUIC_QUIC_PROTOCOL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "base/logging.h" | 22 #include "base/logging.h" |
23 #include "base/macros.h" | 23 #include "base/macros.h" |
24 #include "base/memory/ref_counted.h" | 24 #include "base/memory/ref_counted.h" |
25 #include "base/strings/string_piece.h" | 25 #include "base/strings/string_piece.h" |
26 #include "net/base/int128.h" | 26 #include "net/base/int128.h" |
27 #include "net/base/iovec.h" | 27 #include "net/base/iovec.h" |
28 #include "net/base/ip_endpoint.h" | 28 #include "net/base/ip_endpoint.h" |
29 #include "net/base/net_export.h" | 29 #include "net/base/net_export.h" |
30 #include "net/quic/core/interval_set.h" | 30 #include "net/quic/core/interval_set.h" |
31 #include "net/quic/core/quic_bandwidth.h" | 31 #include "net/quic/core/quic_bandwidth.h" |
| 32 #include "net/quic/core/quic_buffer_allocator.h" |
| 33 #include "net/quic/core/quic_constants.h" |
| 34 #include "net/quic/core/quic_error_codes.h" |
32 #include "net/quic/core/quic_time.h" | 35 #include "net/quic/core/quic_time.h" |
33 #include "net/quic/core/quic_types.h" | 36 #include "net/quic/core/quic_types.h" |
| 37 #include "net/quic/core/quic_versions.h" |
34 | 38 |
35 namespace net { | 39 namespace net { |
36 | 40 |
37 class QuicPacket; | 41 class QuicPacket; |
38 struct QuicPacketHeader; | 42 struct QuicPacketHeader; |
39 class QuicAckListenerInterface; | |
40 | |
41 typedef uint64_t QuicConnectionId; | |
42 typedef uint32_t QuicStreamId; | |
43 typedef uint64_t QuicStreamOffset; | |
44 typedef uint64_t QuicPacketNumber; | |
45 typedef uint8_t QuicPathId; | |
46 typedef uint64_t QuicPublicResetNonceProof; | |
47 typedef uint8_t QuicPacketEntropyHash; | |
48 typedef uint32_t QuicHeaderId; | |
49 // QuicTag is the type of a tag in the wire protocol. | |
50 typedef uint32_t QuicTag; | |
51 typedef std::vector<QuicTag> QuicTagVector; | |
52 typedef std::map<QuicTag, std::string> QuicTagValueMap; | |
53 typedef uint16_t QuicPacketLength; | |
54 | |
55 // Default initial maximum size in bytes of a QUIC packet. | |
56 const QuicByteCount kDefaultMaxPacketSize = 1350; | |
57 // Default initial maximum size in bytes of a QUIC packet for servers. | |
58 const QuicByteCount kDefaultServerMaxPacketSize = 1000; | |
59 // The maximum packet size of any QUIC packet, based on ethernet's max size, | |
60 // minus the IP and UDP headers. IPv6 has a 40 byte header, UDP adds an | |
61 // additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's | |
62 // max packet size is 1500 bytes, 1500 - 48 = 1452. | |
63 const QuicByteCount kMaxPacketSize = 1452; | |
64 // Default maximum packet size used in the Linux TCP implementation. | |
65 // Used in QUIC for congestion window computations in bytes. | |
66 const QuicByteCount kDefaultTCPMSS = 1460; | |
67 | |
68 // We match SPDY's use of 32 (since we'd compete with SPDY). | |
69 const QuicPacketCount kInitialCongestionWindow = 32; | |
70 | |
71 // Minimum size of initial flow control window, for both stream and session. | |
72 const uint32_t kMinimumFlowControlSendWindow = 16 * 1024; // 16 KB | |
73 | |
74 // Maximum flow control receive window limits for connection and stream. | |
75 const QuicByteCount kStreamReceiveWindowLimit = 16 * 1024 * 1024; // 16 MB | |
76 const QuicByteCount kSessionReceiveWindowLimit = 24 * 1024 * 1024; // 24 MB | |
77 | |
78 // Default limit on the size of uncompressed headers. | |
79 const QuicByteCount kDefaultMaxUncompressedHeaderSize = 16 * 1024; // 16 KB | |
80 | |
81 // Minimum size of the CWND, in packets, when doing bandwidth resumption. | |
82 const QuicPacketCount kMinCongestionWindowForBandwidthResumption = 10; | |
83 | |
84 // Maximum number of tracked packets. | |
85 const QuicPacketCount kMaxTrackedPackets = 10000; | |
86 | |
87 // Default size of the socket receive buffer in bytes. | |
88 const QuicByteCount kDefaultSocketReceiveBuffer = 1024 * 1024; | |
89 | |
90 // Don't allow a client to suggest an RTT shorter than 10ms. | |
91 const uint32_t kMinInitialRoundTripTimeUs = 10 * kNumMicrosPerMilli; | |
92 | |
93 // Don't allow a client to suggest an RTT longer than 15 seconds. | |
94 const uint32_t kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond; | |
95 | |
96 // Maximum number of open streams per connection. | |
97 const size_t kDefaultMaxStreamsPerConnection = 100; | |
98 | |
99 // Number of bytes reserved for public flags in the packet header. | |
100 const size_t kPublicFlagsSize = 1; | |
101 // Number of bytes reserved for version number in the packet header. | |
102 const size_t kQuicVersionSize = 4; | |
103 // Number of bytes reserved for path id in the packet header. | |
104 const size_t kQuicPathIdSize = 1; | |
105 // Number of bytes reserved for private flags in the packet header. | |
106 const size_t kPrivateFlagsSize = 1; | |
107 | |
108 // Signifies that the QuicPacket will contain version of the protocol. | |
109 const bool kIncludeVersion = true; | |
110 // Signifies that the QuicPacket will contain path id. | |
111 const bool kIncludePathId = true; | |
112 // Signifies that the QuicPacket will include a diversification nonce. | |
113 const bool kIncludeDiversificationNonce = true; | |
114 | |
115 // Stream ID is reserved to denote an invalid ID. | |
116 const QuicStreamId kInvalidStreamId = 0; | |
117 | |
118 // Reserved ID for the crypto stream. | |
119 const QuicStreamId kCryptoStreamId = 1; | |
120 | |
121 // Reserved ID for the headers stream. | |
122 const QuicStreamId kHeadersStreamId = 3; | |
123 | |
124 // Header key used to identify final offset on data stream when sending HTTP/2 | |
125 // trailing headers over QUIC. | |
126 NET_EXPORT_PRIVATE extern const char* const kFinalOffsetHeaderKey; | |
127 | |
128 // Maximum delayed ack time, in ms. | |
129 const int64_t kMaxDelayedAckTimeMs = 25; | |
130 | |
131 // Minimum tail loss probe time in ms. | |
132 static const int64_t kMinTailLossProbeTimeoutMs = 10; | |
133 | |
134 // The timeout before the handshake succeeds. | |
135 const int64_t kInitialIdleTimeoutSecs = 5; | |
136 // The default idle timeout. | |
137 const int64_t kDefaultIdleTimeoutSecs = 30; | |
138 // The maximum idle timeout that can be negotiated. | |
139 const int64_t kMaximumIdleTimeoutSecs = 60 * 10; // 10 minutes. | |
140 // The default timeout for a connection until the crypto handshake succeeds. | |
141 const int64_t kMaxTimeForCryptoHandshakeSecs = 10; // 10 secs. | |
142 | |
143 // Default limit on the number of undecryptable packets the connection buffers | |
144 // before the CHLO/SHLO arrive. | |
145 const size_t kDefaultMaxUndecryptablePackets = 10; | |
146 | |
147 // Default ping timeout. | |
148 const int64_t kPingTimeoutSecs = 15; // 15 secs. | |
149 | |
150 // Minimum number of RTTs between Server Config Updates (SCUP) sent to client. | |
151 const int kMinIntervalBetweenServerConfigUpdatesRTTs = 10; | |
152 | |
153 // Minimum time between Server Config Updates (SCUP) sent to client. | |
154 const int kMinIntervalBetweenServerConfigUpdatesMs = 1000; | |
155 | |
156 // Minimum number of packets between Server Config Updates (SCUP). | |
157 const int kMinPacketsBetweenServerConfigUpdates = 100; | |
158 | |
159 // The number of open streams that a server will accept is set to be slightly | |
160 // larger than the negotiated limit. Immediately closing the connection if the | |
161 // client opens slightly too many streams is not ideal: the client may have sent | |
162 // a FIN that was lost, and simultaneously opened a new stream. The number of | |
163 // streams a server accepts is a fixed increment over the negotiated limit, or a | |
164 // percentage increase, whichever is larger. | |
165 const float kMaxStreamsMultiplier = 1.1f; | |
166 const int kMaxStreamsMinimumIncrement = 10; | |
167 | |
168 // Available streams are ones with IDs less than the highest stream that has | |
169 // been opened which have neither been opened or reset. The limit on the number | |
170 // of available streams is 10 times the limit on the number of open streams. | |
171 const int kMaxAvailableStreamsMultiplier = 10; | |
172 | |
173 // Track the number of promises that are not yet claimed by a | |
174 // corresponding get. This must be smaller than | |
175 // kMaxAvailableStreamsMultiplier, because RST on a promised stream my | |
176 // create available streams entries. | |
177 const int kMaxPromisedStreamsMultiplier = kMaxAvailableStreamsMultiplier - 1; | |
178 | |
179 // TCP RFC calls for 1 second RTO however Linux differs from this default and | |
180 // define the minimum RTO to 200ms, we will use the same until we have data to | |
181 // support a higher or lower value. | |
182 static const int64_t kMinRetransmissionTimeMs = 200; | |
183 | |
184 // We define an unsigned 16-bit floating point value, inspired by IEEE floats | |
185 // (http://en.wikipedia.org/wiki/Half_precision_floating-point_format), | |
186 // with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden | |
187 // bit) and denormals, but without signs, transfinites or fractions. Wire format | |
188 // 16 bits (little-endian byte order) are split into exponent (high 5) and | |
189 // mantissa (low 11) and decoded as: | |
190 // uint64_t value; | |
191 // if (exponent == 0) value = mantissa; | |
192 // else value = (mantissa | 1 << 11) << (exponent - 1) | |
193 const int kUFloat16ExponentBits = 5; | |
194 const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30 | |
195 const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11 | |
196 const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12 | |
197 const uint64_t kUFloat16MaxValue = // 0x3FFC0000000 | |
198 ((UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1) | |
199 << kUFloat16MaxExponent; | |
200 | |
201 // Default path ID. | |
202 const QuicPathId kDefaultPathId = 0; | |
203 // Invalid path ID. | |
204 const QuicPathId kInvalidPathId = 0xff; | |
205 | |
206 // kDiversificationNonceSize is the size, in bytes, of the nonce that a server | |
207 // may set in the packet header to ensure that its INITIAL keys are not | |
208 // duplicated. | |
209 const size_t kDiversificationNonceSize = 32; | |
210 | |
211 // The largest gap in packets we'll accept without closing the connection. | |
212 // This will likely have to be tuned. | |
213 const QuicPacketNumber kMaxPacketGap = 5000; | |
214 | |
215 enum TransmissionType : int8_t { | |
216 NOT_RETRANSMISSION, | |
217 FIRST_TRANSMISSION_TYPE = NOT_RETRANSMISSION, | |
218 HANDSHAKE_RETRANSMISSION, // Retransmits due to handshake timeouts. | |
219 ALL_UNACKED_RETRANSMISSION, // Retransmits all unacked packets. | |
220 ALL_INITIAL_RETRANSMISSION, // Retransmits all initially encrypted packets. | |
221 LOSS_RETRANSMISSION, // Retransmits due to loss detection. | |
222 RTO_RETRANSMISSION, // Retransmits due to retransmit time out. | |
223 TLP_RETRANSMISSION, // Tail loss probes. | |
224 LAST_TRANSMISSION_TYPE = TLP_RETRANSMISSION, | |
225 }; | |
226 | |
227 enum HasRetransmittableData : int8_t { | |
228 NO_RETRANSMITTABLE_DATA, | |
229 HAS_RETRANSMITTABLE_DATA, | |
230 }; | |
231 | |
232 enum IsHandshake : int8_t { NOT_HANDSHAKE, IS_HANDSHAKE }; | |
233 | |
234 enum class Perspective { IS_SERVER, IS_CLIENT }; | |
235 | |
236 // Describes whether a ConnectionClose was originated by the peer. | |
237 enum class ConnectionCloseSource { FROM_PEER, FROM_SELF }; | |
238 | |
239 // Should a connection be closed silently or not. | |
240 enum class ConnectionCloseBehavior { | |
241 SILENT_CLOSE, | |
242 SEND_CONNECTION_CLOSE_PACKET, | |
243 SEND_CONNECTION_CLOSE_PACKET_WITH_NO_ACK | |
244 }; | |
245 | |
246 NET_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, | |
247 const Perspective& s); | |
248 enum QuicFrameType { | |
249 // Regular frame types. The values set here cannot change without the | |
250 // introduction of a new QUIC version. | |
251 PADDING_FRAME = 0, | |
252 RST_STREAM_FRAME = 1, | |
253 CONNECTION_CLOSE_FRAME = 2, | |
254 GOAWAY_FRAME = 3, | |
255 WINDOW_UPDATE_FRAME = 4, | |
256 BLOCKED_FRAME = 5, | |
257 STOP_WAITING_FRAME = 6, | |
258 PING_FRAME = 7, | |
259 PATH_CLOSE_FRAME = 8, | |
260 | |
261 // STREAM and ACK frames are special frames. They are encoded differently on | |
262 // the wire and their values do not need to be stable. | |
263 STREAM_FRAME, | |
264 ACK_FRAME, | |
265 // The path MTU discovery frame is encoded as a PING frame on the wire. | |
266 MTU_DISCOVERY_FRAME, | |
267 NUM_FRAME_TYPES | |
268 }; | |
269 | |
270 enum QuicConnectionIdLength { | |
271 PACKET_0BYTE_CONNECTION_ID = 0, | |
272 PACKET_8BYTE_CONNECTION_ID = 8 | |
273 }; | |
274 | |
275 enum QuicPacketNumberLength : int8_t { | |
276 PACKET_1BYTE_PACKET_NUMBER = 1, | |
277 PACKET_2BYTE_PACKET_NUMBER = 2, | |
278 PACKET_4BYTE_PACKET_NUMBER = 4, | |
279 PACKET_6BYTE_PACKET_NUMBER = 6 | |
280 }; | |
281 | |
282 // Used to indicate a QuicSequenceNumberLength using two flag bits. | |
283 enum QuicPacketNumberLengthFlags { | |
284 PACKET_FLAGS_1BYTE_PACKET = 0, // 00 | |
285 PACKET_FLAGS_2BYTE_PACKET = 1, // 01 | |
286 PACKET_FLAGS_4BYTE_PACKET = 1 << 1, // 10 | |
287 PACKET_FLAGS_6BYTE_PACKET = 1 << 1 | 1, // 11 | |
288 }; | |
289 | |
290 // The public flags are specified in one byte. | |
291 enum QuicPacketPublicFlags { | |
292 PACKET_PUBLIC_FLAGS_NONE = 0, | |
293 | |
294 // Bit 0: Does the packet header contains version info? | |
295 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0, | |
296 | |
297 // Bit 1: Is this packet a public reset packet? | |
298 PACKET_PUBLIC_FLAGS_RST = 1 << 1, | |
299 | |
300 // Bit 2: indicates the that public header includes a nonce. | |
301 PACKET_PUBLIC_FLAGS_NONCE = 1 << 2, | |
302 | |
303 // Bit 3: indicates whether a ConnectionID is included. | |
304 PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID = 0, | |
305 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID = 1 << 3, | |
306 | |
307 // QUIC_VERSION_32 and earlier use two bits for an 8 byte | |
308 // connection id. | |
309 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID_OLD = 1 << 3 | 1 << 2, | |
310 | |
311 // Bits 4 and 5 describe the packet number length as follows: | |
312 // --00----: 1 byte | |
313 // --01----: 2 bytes | |
314 // --10----: 4 bytes | |
315 // --11----: 6 bytes | |
316 PACKET_PUBLIC_FLAGS_1BYTE_PACKET = PACKET_FLAGS_1BYTE_PACKET << 4, | |
317 PACKET_PUBLIC_FLAGS_2BYTE_PACKET = PACKET_FLAGS_2BYTE_PACKET << 4, | |
318 PACKET_PUBLIC_FLAGS_4BYTE_PACKET = PACKET_FLAGS_4BYTE_PACKET << 4, | |
319 PACKET_PUBLIC_FLAGS_6BYTE_PACKET = PACKET_FLAGS_6BYTE_PACKET << 4, | |
320 | |
321 // Bit 6: Does the packet header contain a path id? | |
322 PACKET_PUBLIC_FLAGS_MULTIPATH = 1 << 6, | |
323 | |
324 // Reserved, unimplemented flags: | |
325 | |
326 // Bit 7: indicates the presence of a second flags byte. | |
327 PACKET_PUBLIC_FLAGS_TWO_OR_MORE_BYTES = 1 << 7, | |
328 | |
329 // All bits set (bit 7 is not currently used): 01111111 | |
330 PACKET_PUBLIC_FLAGS_MAX = (1 << 7) - 1, | |
331 }; | |
332 | |
333 // The private flags are specified in one byte. | |
334 enum QuicPacketPrivateFlags { | |
335 PACKET_PRIVATE_FLAGS_NONE = 0, | |
336 | |
337 // Bit 0: Does this packet contain an entropy bit? | |
338 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0, | |
339 | |
340 // (bits 1-7 are not used): 00000001 | |
341 PACKET_PRIVATE_FLAGS_MAX = (1 << 1) - 1 | |
342 }; | |
343 | |
344 // The available versions of QUIC. Guaranteed that the integer value of the enum | |
345 // will match the version number. | |
346 // When adding a new version to this enum you should add it to | |
347 // kSupportedQuicVersions (if appropriate), and also add a new case to the | |
348 // helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and | |
349 // QuicVersionToString. | |
350 enum QuicVersion { | |
351 // Special case to indicate unknown/unsupported QUIC version. | |
352 QUIC_VERSION_UNSUPPORTED = 0, | |
353 | |
354 QUIC_VERSION_32 = 32, // FEC related fields are removed from wire format. | |
355 QUIC_VERSION_33 = 33, // Adds diversification nonces. | |
356 QUIC_VERSION_34 = 34, // Deprecates entropy, removes private flag from packet | |
357 // header, uses new ack and stop waiting wire format. | |
358 QUIC_VERSION_35 = 35, // Allows endpoints to independently set stream limit. | |
359 QUIC_VERSION_36 = 36, // Add support to force HOL blocking. | |
360 | |
361 // IMPORTANT: if you are adding to this std::list, follow the instructions at | |
362 // http://sites/quic/adding-and-removing-versions | |
363 }; | |
364 | |
365 // This vector contains QUIC versions which we currently support. | |
366 // This should be ordered such that the highest supported version is the first | |
367 // element, with subsequent elements in descending order (versions can be | |
368 // skipped as necessary). | |
369 // | |
370 // IMPORTANT: if you are adding to this list, follow the instructions at | |
371 // http://sites/quic/adding-and-removing-versions | |
372 static const QuicVersion kSupportedQuicVersions[] = { | |
373 QUIC_VERSION_36, QUIC_VERSION_35, QUIC_VERSION_34, QUIC_VERSION_33, | |
374 QUIC_VERSION_32}; | |
375 | |
376 typedef std::vector<QuicVersion> QuicVersionVector; | |
377 | |
378 // Returns a vector of QUIC versions in kSupportedQuicVersions. | |
379 NET_EXPORT_PRIVATE QuicVersionVector AllSupportedVersions(); | |
380 | |
381 // Returns a vector of QUIC versions from kSupportedQuicVersions which exclude | |
382 // any versions which are disabled by flags. | |
383 NET_EXPORT_PRIVATE QuicVersionVector CurrentSupportedVersions(); | |
384 | |
385 // Returns a vector of QUIC versions from |versions| which exclude any versions | |
386 // which are disabled by flags. | |
387 NET_EXPORT_PRIVATE QuicVersionVector | |
388 FilterSupportedVersions(QuicVersionVector versions); | |
389 | |
390 // Returns QUIC version of |index| in result of |versions|. Returns | |
391 // QUIC_VERSION_UNSUPPORTED if |index| is out of bounds. | |
392 NET_EXPORT_PRIVATE QuicVersionVector | |
393 VersionOfIndex(const QuicVersionVector& versions, int index); | |
394 | |
395 // QuicTag is written to and read from the wire, but we prefer to use | |
396 // the more readable QuicVersion at other levels. | |
397 // Helper function which translates from a QuicVersion to a QuicTag. Returns 0 | |
398 // if QuicVersion is unsupported. | |
399 NET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version); | |
400 | |
401 // Returns appropriate QuicVersion from a QuicTag. | |
402 // Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood. | |
403 NET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag); | |
404 | |
405 // Helper function which translates from a QuicVersion to a string. | |
406 // Returns strings corresponding to enum names (e.g. QUIC_VERSION_6). | |
407 NET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version); | |
408 | |
409 // Returns comma separated list of string representations of QuicVersion enum | |
410 // values in the supplied |versions| vector. | |
411 NET_EXPORT_PRIVATE std::string QuicVersionVectorToString( | |
412 const QuicVersionVector& versions); | |
413 | |
414 // Version and Crypto tags are written to the wire with a big-endian | |
415 // representation of the name of the tag. For example | |
416 // the client hello tag (CHLO) will be written as the | |
417 // following 4 bytes: 'C' 'H' 'L' 'O'. Since it is | |
418 // stored in memory as a little endian uint32_t, we need | |
419 // to reverse the order of the bytes. | |
420 | |
421 // MakeQuicTag returns a value given the four bytes. For example: | |
422 // MakeQuicTag('C', 'H', 'L', 'O'); | |
423 NET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d); | |
424 | |
425 // Returns true if the tag vector contains the specified tag. | |
426 NET_EXPORT_PRIVATE bool ContainsQuicTag(const QuicTagVector& tag_vector, | |
427 QuicTag tag); | |
428 | 43 |
429 // Size in bytes of the data packet header. | 44 // Size in bytes of the data packet header. |
430 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicVersion version, | 45 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicVersion version, |
431 const QuicPacketHeader& header); | 46 const QuicPacketHeader& header); |
432 | 47 |
433 NET_EXPORT_PRIVATE size_t | 48 NET_EXPORT_PRIVATE size_t |
434 GetPacketHeaderSize(QuicVersion version, | 49 GetPacketHeaderSize(QuicVersion version, |
435 QuicConnectionIdLength connection_id_length, | 50 QuicConnectionIdLength connection_id_length, |
436 bool include_version, | 51 bool include_version, |
437 bool include_path_id, | 52 bool include_path_id, |
438 bool include_diversification_nonce, | 53 bool include_diversification_nonce, |
439 QuicPacketNumberLength packet_number_length); | 54 QuicPacketNumberLength packet_number_length); |
440 | 55 |
441 // Index of the first byte in a QUIC packet of encrypted data. | 56 // Index of the first byte in a QUIC packet of encrypted data. |
442 NET_EXPORT_PRIVATE size_t | 57 NET_EXPORT_PRIVATE size_t |
443 GetStartOfEncryptedData(QuicVersion version, const QuicPacketHeader& header); | 58 GetStartOfEncryptedData(QuicVersion version, const QuicPacketHeader& header); |
444 | 59 |
445 NET_EXPORT_PRIVATE size_t | 60 NET_EXPORT_PRIVATE size_t |
446 GetStartOfEncryptedData(QuicVersion version, | 61 GetStartOfEncryptedData(QuicVersion version, |
447 QuicConnectionIdLength connection_id_length, | 62 QuicConnectionIdLength connection_id_length, |
448 bool include_version, | 63 bool include_version, |
449 bool include_path_id, | 64 bool include_path_id, |
450 bool include_diversification_nonce, | 65 bool include_diversification_nonce, |
451 QuicPacketNumberLength packet_number_length); | 66 QuicPacketNumberLength packet_number_length); |
452 | 67 |
453 enum QuicRstStreamErrorCode { | |
454 // Complete response has been sent, sending a RST to ask the other endpoint | |
455 // to stop sending request data without discarding the response. | |
456 QUIC_STREAM_NO_ERROR = 0, | |
457 | |
458 // There was some error which halted stream processing. | |
459 QUIC_ERROR_PROCESSING_STREAM, | |
460 // We got two fin or reset offsets which did not match. | |
461 QUIC_MULTIPLE_TERMINATION_OFFSETS, | |
462 // We got bad payload and can not respond to it at the protocol level. | |
463 QUIC_BAD_APPLICATION_PAYLOAD, | |
464 // Stream closed due to connection error. No reset frame is sent when this | |
465 // happens. | |
466 QUIC_STREAM_CONNECTION_ERROR, | |
467 // GoAway frame sent. No more stream can be created. | |
468 QUIC_STREAM_PEER_GOING_AWAY, | |
469 // The stream has been cancelled. | |
470 QUIC_STREAM_CANCELLED, | |
471 // Closing stream locally, sending a RST to allow for proper flow control | |
472 // accounting. Sent in response to a RST from the peer. | |
473 QUIC_RST_ACKNOWLEDGEMENT, | |
474 // Receiver refused to create the stream (because its limit on open streams | |
475 // has been reached). The sender should retry the request later (using | |
476 // another stream). | |
477 QUIC_REFUSED_STREAM, | |
478 // Invalid URL in PUSH_PROMISE request header. | |
479 QUIC_INVALID_PROMISE_URL, | |
480 // Server is not authoritative for this URL. | |
481 QUIC_UNAUTHORIZED_PROMISE_URL, | |
482 // Can't have more than one active PUSH_PROMISE per URL. | |
483 QUIC_DUPLICATE_PROMISE_URL, | |
484 // Vary check failed. | |
485 QUIC_PROMISE_VARY_MISMATCH, | |
486 // Only GET and HEAD methods allowed. | |
487 QUIC_INVALID_PROMISE_METHOD, | |
488 // The push stream is unclaimed and timed out. | |
489 QUIC_PUSH_STREAM_TIMED_OUT, | |
490 // Received headers were too large. | |
491 QUIC_HEADERS_TOO_LARGE, | |
492 // No error. Used as bound while iterating. | |
493 QUIC_STREAM_LAST_ERROR, | |
494 }; | |
495 // QUIC error codes are encoded to a single octet on-the-wire. | |
496 static_assert(static_cast<int>(QUIC_STREAM_LAST_ERROR) <= | |
497 std::numeric_limits<uint8_t>::max(), | |
498 "QuicErrorCode exceeds single octet"); | |
499 | |
500 // These values must remain stable as they are uploaded to UMA histograms. | |
501 // To add a new error code, use the current value of QUIC_LAST_ERROR and | |
502 // increment QUIC_LAST_ERROR. | |
503 enum QuicErrorCode { | |
504 QUIC_NO_ERROR = 0, | |
505 | |
506 // Connection has reached an invalid state. | |
507 QUIC_INTERNAL_ERROR = 1, | |
508 // There were data frames after the a fin or reset. | |
509 QUIC_STREAM_DATA_AFTER_TERMINATION = 2, | |
510 // Control frame is malformed. | |
511 QUIC_INVALID_PACKET_HEADER = 3, | |
512 // Frame data is malformed. | |
513 QUIC_INVALID_FRAME_DATA = 4, | |
514 // The packet contained no payload. | |
515 QUIC_MISSING_PAYLOAD = 48, | |
516 // FEC data is malformed. | |
517 QUIC_INVALID_FEC_DATA = 5, | |
518 // STREAM frame data is malformed. | |
519 QUIC_INVALID_STREAM_DATA = 46, | |
520 // STREAM frame data overlaps with buffered data. | |
521 QUIC_OVERLAPPING_STREAM_DATA = 87, | |
522 // Received STREAM frame data is not encrypted. | |
523 QUIC_UNENCRYPTED_STREAM_DATA = 61, | |
524 // Attempt to send unencrypted STREAM frame. | |
525 QUIC_ATTEMPT_TO_SEND_UNENCRYPTED_STREAM_DATA = 88, | |
526 // Received a frame which is likely the result of memory corruption. | |
527 QUIC_MAYBE_CORRUPTED_MEMORY = 89, | |
528 // FEC frame data is not encrypted. | |
529 QUIC_UNENCRYPTED_FEC_DATA = 77, | |
530 // RST_STREAM frame data is malformed. | |
531 QUIC_INVALID_RST_STREAM_DATA = 6, | |
532 // CONNECTION_CLOSE frame data is malformed. | |
533 QUIC_INVALID_CONNECTION_CLOSE_DATA = 7, | |
534 // GOAWAY frame data is malformed. | |
535 QUIC_INVALID_GOAWAY_DATA = 8, | |
536 // WINDOW_UPDATE frame data is malformed. | |
537 QUIC_INVALID_WINDOW_UPDATE_DATA = 57, | |
538 // BLOCKED frame data is malformed. | |
539 QUIC_INVALID_BLOCKED_DATA = 58, | |
540 // STOP_WAITING frame data is malformed. | |
541 QUIC_INVALID_STOP_WAITING_DATA = 60, | |
542 // PATH_CLOSE frame data is malformed. | |
543 QUIC_INVALID_PATH_CLOSE_DATA = 78, | |
544 // ACK frame data is malformed. | |
545 QUIC_INVALID_ACK_DATA = 9, | |
546 | |
547 // Version negotiation packet is malformed. | |
548 QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10, | |
549 // Public RST packet is malformed. | |
550 QUIC_INVALID_PUBLIC_RST_PACKET = 11, | |
551 // There was an error decrypting. | |
552 QUIC_DECRYPTION_FAILURE = 12, | |
553 // There was an error encrypting. | |
554 QUIC_ENCRYPTION_FAILURE = 13, | |
555 // The packet exceeded kMaxPacketSize. | |
556 QUIC_PACKET_TOO_LARGE = 14, | |
557 // The peer is going away. May be a client or server. | |
558 QUIC_PEER_GOING_AWAY = 16, | |
559 // A stream ID was invalid. | |
560 QUIC_INVALID_STREAM_ID = 17, | |
561 // A priority was invalid. | |
562 QUIC_INVALID_PRIORITY = 49, | |
563 // Too many streams already open. | |
564 QUIC_TOO_MANY_OPEN_STREAMS = 18, | |
565 // The peer created too many available streams. | |
566 QUIC_TOO_MANY_AVAILABLE_STREAMS = 76, | |
567 // Received public reset for this connection. | |
568 QUIC_PUBLIC_RESET = 19, | |
569 // Invalid protocol version. | |
570 QUIC_INVALID_VERSION = 20, | |
571 | |
572 // The Header ID for a stream was too far from the previous. | |
573 QUIC_INVALID_HEADER_ID = 22, | |
574 // Negotiable parameter received during handshake had invalid value. | |
575 QUIC_INVALID_NEGOTIATED_VALUE = 23, | |
576 // There was an error decompressing data. | |
577 QUIC_DECOMPRESSION_FAILURE = 24, | |
578 // The connection timed out due to no network activity. | |
579 QUIC_NETWORK_IDLE_TIMEOUT = 25, | |
580 // The connection timed out waiting for the handshake to complete. | |
581 QUIC_HANDSHAKE_TIMEOUT = 67, | |
582 // There was an error encountered migrating addresses. | |
583 QUIC_ERROR_MIGRATING_ADDRESS = 26, | |
584 // There was an error encountered migrating port only. | |
585 QUIC_ERROR_MIGRATING_PORT = 86, | |
586 // There was an error while writing to the socket. | |
587 QUIC_PACKET_WRITE_ERROR = 27, | |
588 // There was an error while reading from the socket. | |
589 QUIC_PACKET_READ_ERROR = 51, | |
590 // We received a STREAM_FRAME with no data and no fin flag set. | |
591 QUIC_EMPTY_STREAM_FRAME_NO_FIN = 50, | |
592 // We received invalid data on the headers stream. | |
593 QUIC_INVALID_HEADERS_STREAM_DATA = 56, | |
594 // The peer received too much data, violating flow control. | |
595 QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA = 59, | |
596 // The peer sent too much data, violating flow control. | |
597 QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA = 63, | |
598 // The peer received an invalid flow control window. | |
599 QUIC_FLOW_CONTROL_INVALID_WINDOW = 64, | |
600 // The connection has been IP pooled into an existing connection. | |
601 QUIC_CONNECTION_IP_POOLED = 62, | |
602 // The connection has too many outstanding sent packets. | |
603 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS = 68, | |
604 // The connection has too many outstanding received packets. | |
605 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS = 69, | |
606 // The quic connection has been cancelled. | |
607 QUIC_CONNECTION_CANCELLED = 70, | |
608 // Disabled QUIC because of high packet loss rate. | |
609 QUIC_BAD_PACKET_LOSS_RATE = 71, | |
610 // Disabled QUIC because of too many PUBLIC_RESETs post handshake. | |
611 QUIC_PUBLIC_RESETS_POST_HANDSHAKE = 73, | |
612 // Disabled QUIC because of too many timeouts with streams open. | |
613 QUIC_TIMEOUTS_WITH_OPEN_STREAMS = 74, | |
614 // Closed because we failed to serialize a packet. | |
615 QUIC_FAILED_TO_SERIALIZE_PACKET = 75, | |
616 // QUIC timed out after too many RTOs. | |
617 QUIC_TOO_MANY_RTOS = 85, | |
618 | |
619 // Crypto errors. | |
620 | |
621 // Hanshake failed. | |
622 QUIC_HANDSHAKE_FAILED = 28, | |
623 // Handshake message contained out of order tags. | |
624 QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29, | |
625 // Handshake message contained too many entries. | |
626 QUIC_CRYPTO_TOO_MANY_ENTRIES = 30, | |
627 // Handshake message contained an invalid value length. | |
628 QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31, | |
629 // A crypto message was received after the handshake was complete. | |
630 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32, | |
631 // A crypto message was received with an illegal message tag. | |
632 QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33, | |
633 // A crypto message was received with an illegal parameter. | |
634 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34, | |
635 // An invalid channel id signature was supplied. | |
636 QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52, | |
637 // A crypto message was received with a mandatory parameter missing. | |
638 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35, | |
639 // A crypto message was received with a parameter that has no overlap | |
640 // with the local parameter. | |
641 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36, | |
642 // A crypto message was received that contained a parameter with too few | |
643 // values. | |
644 QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37, | |
645 // A demand for an unsupport proof type was received. | |
646 QUIC_UNSUPPORTED_PROOF_DEMAND = 94, | |
647 // An internal error occured in crypto processing. | |
648 QUIC_CRYPTO_INTERNAL_ERROR = 38, | |
649 // A crypto handshake message specified an unsupported version. | |
650 QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39, | |
651 // A crypto handshake message resulted in a stateless reject. | |
652 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT = 72, | |
653 // There was no intersection between the crypto primitives supported by the | |
654 // peer and ourselves. | |
655 QUIC_CRYPTO_NO_SUPPORT = 40, | |
656 // The server rejected our client hello messages too many times. | |
657 QUIC_CRYPTO_TOO_MANY_REJECTS = 41, | |
658 // The client rejected the server's certificate chain or signature. | |
659 QUIC_PROOF_INVALID = 42, | |
660 // A crypto message was received with a duplicate tag. | |
661 QUIC_CRYPTO_DUPLICATE_TAG = 43, | |
662 // A crypto message was received with the wrong encryption level (i.e. it | |
663 // should have been encrypted but was not.) | |
664 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44, | |
665 // The server config for a server has expired. | |
666 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45, | |
667 // We failed to setup the symmetric keys for a connection. | |
668 QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53, | |
669 // A handshake message arrived, but we are still validating the | |
670 // previous handshake message. | |
671 QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54, | |
672 // A server config update arrived before the handshake is complete. | |
673 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE = 65, | |
674 // CHLO cannot fit in one packet. | |
675 QUIC_CRYPTO_CHLO_TOO_LARGE = 90, | |
676 // This connection involved a version negotiation which appears to have been | |
677 // tampered with. | |
678 QUIC_VERSION_NEGOTIATION_MISMATCH = 55, | |
679 | |
680 // Multipath errors. | |
681 // Multipath is not enabled, but a packet with multipath flag on is received. | |
682 QUIC_BAD_MULTIPATH_FLAG = 79, | |
683 // A path is supposed to exist but does not. | |
684 QUIC_MULTIPATH_PATH_DOES_NOT_EXIST = 91, | |
685 // A path is supposed to be active but is not. | |
686 QUIC_MULTIPATH_PATH_NOT_ACTIVE = 92, | |
687 | |
688 // IP address changed causing connection close. | |
689 QUIC_IP_ADDRESS_CHANGED = 80, | |
690 | |
691 // Connection migration errors. | |
692 // Network changed, but connection had no migratable streams. | |
693 QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS = 81, | |
694 // Connection changed networks too many times. | |
695 QUIC_CONNECTION_MIGRATION_TOO_MANY_CHANGES = 82, | |
696 // Connection migration was attempted, but there was no new network to | |
697 // migrate to. | |
698 QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK = 83, | |
699 // Network changed, but connection had one or more non-migratable streams. | |
700 QUIC_CONNECTION_MIGRATION_NON_MIGRATABLE_STREAM = 84, | |
701 | |
702 // Stream frames arrived too discontiguously so that stream sequencer buffer | |
703 // maintains too many gaps. | |
704 QUIC_TOO_MANY_FRAME_GAPS = 93, | |
705 | |
706 // Sequencer buffer get into weird state where continuing read/write will lead | |
707 // to crash. | |
708 QUIC_STREAM_SEQUENCER_INVALID_STATE = 95, | |
709 | |
710 // Connection closed because of server hits max number of sessions allowed. | |
711 // TODO(fayang): Add monitoring for QUIC_TOO_MANY_SESSIONS_ON_SERVER. | |
712 QUIC_TOO_MANY_SESSIONS_ON_SERVER = 96, | |
713 | |
714 // No error. Used as bound while iterating. | |
715 QUIC_LAST_ERROR = 97, | |
716 }; | |
717 | |
718 typedef std::array<char, 32> DiversificationNonce; | |
719 | |
720 struct NET_EXPORT_PRIVATE QuicPacketPublicHeader { | 68 struct NET_EXPORT_PRIVATE QuicPacketPublicHeader { |
721 QuicPacketPublicHeader(); | 69 QuicPacketPublicHeader(); |
722 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other); | 70 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other); |
723 ~QuicPacketPublicHeader(); | 71 ~QuicPacketPublicHeader(); |
724 | 72 |
725 // Universal header. All QuicPacket headers will have a connection_id and | 73 // Universal header. All QuicPacket headers will have a connection_id and |
726 // public flags. | 74 // public flags. |
727 QuicConnectionId connection_id; | 75 QuicConnectionId connection_id; |
728 QuicConnectionIdLength connection_id_length; | 76 QuicConnectionIdLength connection_id_length; |
729 bool multipath_flag; | 77 bool multipath_flag; |
730 bool reset_flag; | 78 bool reset_flag; |
731 bool version_flag; | 79 bool version_flag; |
732 QuicPacketNumberLength packet_number_length; | 80 QuicPacketNumberLength packet_number_length; |
733 QuicVersionVector versions; | 81 QuicVersionVector versions; |
734 // nonce contains an optional, 32-byte nonce value. If not included in the | 82 // nonce contains an optional, 32-byte nonce value. If not included in the |
735 // packet, |nonce| will be empty. | 83 // packet, |nonce| will be empty. |
736 DiversificationNonce* nonce; | 84 DiversificationNonce* nonce; |
737 }; | 85 }; |
738 | 86 |
739 // An integer which cannot be a packet number. | |
740 const QuicPacketNumber kInvalidPacketNumber = 0; | |
741 | |
742 // Header for Data packets. | 87 // Header for Data packets. |
743 struct NET_EXPORT_PRIVATE QuicPacketHeader { | 88 struct NET_EXPORT_PRIVATE QuicPacketHeader { |
744 QuicPacketHeader(); | 89 QuicPacketHeader(); |
745 explicit QuicPacketHeader(const QuicPacketPublicHeader& header); | 90 explicit QuicPacketHeader(const QuicPacketPublicHeader& header); |
746 QuicPacketHeader(const QuicPacketHeader& other); | 91 QuicPacketHeader(const QuicPacketHeader& other); |
747 | 92 |
748 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, | 93 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, |
749 const QuicPacketHeader& s); | 94 const QuicPacketHeader& s); |
750 | 95 |
751 QuicPacketPublicHeader public_header; | 96 QuicPacketPublicHeader public_header; |
752 QuicPacketNumber packet_number; | 97 QuicPacketNumber packet_number; |
753 QuicPathId path_id; | 98 QuicPathId path_id; |
754 bool entropy_flag; | |
755 QuicPacketEntropyHash entropy_hash; | |
756 }; | 99 }; |
757 | 100 |
758 struct NET_EXPORT_PRIVATE QuicPublicResetPacket { | 101 struct NET_EXPORT_PRIVATE QuicPublicResetPacket { |
759 QuicPublicResetPacket(); | 102 QuicPublicResetPacket(); |
760 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header); | 103 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header); |
761 | 104 |
762 QuicPacketPublicHeader public_header; | 105 QuicPacketPublicHeader public_header; |
763 QuicPublicResetNonceProof nonce_proof; | 106 QuicPublicResetNonceProof nonce_proof; |
764 // TODO(fayang): remove rejected_packet_number when deprecating | 107 // TODO(fayang): remove rejected_packet_number when deprecating |
765 // FLAGS_quic_remove_packet_number_from_public_reset. | 108 // FLAGS_quic_remove_packet_number_from_public_reset. |
766 QuicPacketNumber rejected_packet_number; | 109 QuicPacketNumber rejected_packet_number; |
767 IPEndPoint client_address; | 110 IPEndPoint client_address; |
768 }; | 111 }; |
769 | 112 |
770 enum QuicVersionNegotiationState { | |
771 START_NEGOTIATION = 0, | |
772 // Server-side this implies we've sent a version negotiation packet and are | |
773 // waiting on the client to select a compatible version. Client-side this | |
774 // implies we've gotten a version negotiation packet, are retransmitting the | |
775 // initial packets with a supported version and are waiting for our first | |
776 // packet from the server. | |
777 NEGOTIATION_IN_PROGRESS, | |
778 // This indicates this endpoint has received a packet from the peer with a | |
779 // version this endpoint supports. Version negotiation is complete, and the | |
780 // version number will no longer be sent with future packets. | |
781 NEGOTIATED_VERSION | |
782 }; | |
783 | |
784 typedef QuicPacketPublicHeader QuicVersionNegotiationPacket; | 113 typedef QuicPacketPublicHeader QuicVersionNegotiationPacket; |
785 | 114 |
786 // A padding frame contains no payload. | 115 // A padding frame contains no payload. |
787 struct NET_EXPORT_PRIVATE QuicPaddingFrame { | 116 struct NET_EXPORT_PRIVATE QuicPaddingFrame { |
788 QuicPaddingFrame() : num_padding_bytes(-1) {} | 117 QuicPaddingFrame() : num_padding_bytes(-1) {} |
789 explicit QuicPaddingFrame(int num_padding_bytes) | 118 explicit QuicPaddingFrame(int num_padding_bytes) |
790 : num_padding_bytes(num_padding_bytes) {} | 119 : num_padding_bytes(num_padding_bytes) {} |
791 | 120 |
792 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, | 121 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, |
793 const QuicPaddingFrame& s); | 122 const QuicPaddingFrame& s); |
794 | 123 |
795 // -1: full padding to the end of a max-sized packet | 124 // -1: full padding to the end of a max-sized packet |
796 // otherwise: only pad up to num_padding_bytes bytes | 125 // otherwise: only pad up to num_padding_bytes bytes |
797 int num_padding_bytes; | 126 int num_padding_bytes; |
798 }; | 127 }; |
799 | 128 |
800 // A ping frame contains no payload, though it is retransmittable, | 129 // A ping frame contains no payload, though it is retransmittable, |
801 // and ACK'd just like other normal frames. | 130 // and ACK'd just like other normal frames. |
802 struct NET_EXPORT_PRIVATE QuicPingFrame {}; | 131 struct NET_EXPORT_PRIVATE QuicPingFrame {}; |
803 | 132 |
804 // A path MTU discovery frame contains no payload and is serialized as a ping | 133 // A path MTU discovery frame contains no payload and is serialized as a ping |
805 // frame. | 134 // frame. |
806 struct NET_EXPORT_PRIVATE QuicMtuDiscoveryFrame {}; | 135 struct NET_EXPORT_PRIVATE QuicMtuDiscoveryFrame {}; |
807 | 136 |
808 class NET_EXPORT_PRIVATE QuicBufferAllocator { | |
809 public: | |
810 virtual ~QuicBufferAllocator(); | |
811 | |
812 // Returns or allocates a new buffer of |size|. Never returns null. | |
813 virtual char* New(size_t size) = 0; | |
814 | |
815 // Returns or allocates a new buffer of |size| if |flag_enable| is true. | |
816 // Otherwise, returns a buffer that is compatible with this class directly | |
817 // with operator new. Never returns null. | |
818 virtual char* New(size_t size, bool flag_enable) = 0; | |
819 | |
820 // Releases a buffer. | |
821 virtual void Delete(char* buffer) = 0; | |
822 | |
823 // Marks the allocator as being idle. Serves as a hint to notify the allocator | |
824 // that it should release any resources it's still holding on to. | |
825 virtual void MarkAllocatorIdle() {} | |
826 }; | |
827 | |
828 // Deleter for stream buffers. Copyable to support platforms where the deleter | 137 // Deleter for stream buffers. Copyable to support platforms where the deleter |
829 // of a unique_ptr must be copyable. Otherwise it would be nice for this to be | 138 // of a unique_ptr must be copyable. Otherwise it would be nice for this to be |
830 // move-only. | 139 // move-only. |
831 class NET_EXPORT_PRIVATE StreamBufferDeleter { | 140 class NET_EXPORT_PRIVATE StreamBufferDeleter { |
832 public: | 141 public: |
833 StreamBufferDeleter() : allocator_(nullptr) {} | 142 StreamBufferDeleter() : allocator_(nullptr) {} |
834 explicit StreamBufferDeleter(QuicBufferAllocator* allocator) | 143 explicit StreamBufferDeleter(QuicBufferAllocator* allocator) |
835 : allocator_(allocator) {} | 144 : allocator_(allocator) {} |
836 | 145 |
837 // Deletes |buffer| using |allocator_|. | 146 // Deletes |buffer| using |allocator_|. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 | 199 |
891 struct NET_EXPORT_PRIVATE QuicStopWaitingFrame { | 200 struct NET_EXPORT_PRIVATE QuicStopWaitingFrame { |
892 QuicStopWaitingFrame(); | 201 QuicStopWaitingFrame(); |
893 ~QuicStopWaitingFrame(); | 202 ~QuicStopWaitingFrame(); |
894 | 203 |
895 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | 204 NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
896 std::ostream& os, | 205 std::ostream& os, |
897 const QuicStopWaitingFrame& s); | 206 const QuicStopWaitingFrame& s); |
898 // Path which this stop waiting frame belongs to. | 207 // Path which this stop waiting frame belongs to. |
899 QuicPathId path_id; | 208 QuicPathId path_id; |
900 // Entropy hash of all packets up to, but not including, the least unacked | |
901 // packet. | |
902 QuicPacketEntropyHash entropy_hash; | |
903 // The lowest packet we've sent which is unacked, and we expect an ack for. | 209 // The lowest packet we've sent which is unacked, and we expect an ack for. |
904 QuicPacketNumber least_unacked; | 210 QuicPacketNumber least_unacked; |
905 }; | 211 }; |
906 | 212 |
907 // A sequence of packet numbers where each number is unique. Intended to be used | 213 // A sequence of packet numbers where each number is unique. Intended to be used |
908 // in a sliding window fashion, where smaller old packet numbers are removed and | 214 // in a sliding window fashion, where smaller old packet numbers are removed and |
909 // larger new packet numbers are added, with the occasional random access. | 215 // larger new packet numbers are added, with the occasional random access. |
910 class NET_EXPORT_PRIVATE PacketNumberQueue { | 216 class NET_EXPORT_PRIVATE PacketNumberQueue { |
911 public: | 217 public: |
912 using const_iterator = IntervalSet<QuicPacketNumber>::const_iterator; | 218 using const_iterator = IntervalSet<QuicPacketNumber>::const_iterator; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 | 293 |
988 struct NET_EXPORT_PRIVATE QuicAckFrame { | 294 struct NET_EXPORT_PRIVATE QuicAckFrame { |
989 QuicAckFrame(); | 295 QuicAckFrame(); |
990 QuicAckFrame(const QuicAckFrame& other); | 296 QuicAckFrame(const QuicAckFrame& other); |
991 ~QuicAckFrame(); | 297 ~QuicAckFrame(); |
992 | 298 |
993 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, | 299 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, |
994 const QuicAckFrame& s); | 300 const QuicAckFrame& s); |
995 | 301 |
996 // The highest packet number we've observed from the peer. | 302 // The highest packet number we've observed from the peer. |
997 // | |
998 // In general, this should be the largest packet number we've received. In | |
999 // the case of truncated acks, we may have to advertise a lower "upper bound" | |
1000 // than largest received, to avoid implicitly acking missing packets that | |
1001 // don't fit in the missing packet list due to size limitations. In this | |
1002 // case, largest_observed may be a packet which is also in the missing packets | |
1003 // list. | |
1004 QuicPacketNumber largest_observed; | 303 QuicPacketNumber largest_observed; |
1005 | 304 |
1006 // Time elapsed since largest_observed was received until this Ack frame was | 305 // Time elapsed since largest_observed was received until this Ack frame was |
1007 // sent. | 306 // sent. |
1008 QuicTime::Delta ack_delay_time; | 307 QuicTime::Delta ack_delay_time; |
1009 | 308 |
1010 // Vector of <packet_number, time> for when packets arrived. | 309 // Vector of <packet_number, time> for when packets arrived. |
1011 PacketTimeVector received_packet_times; | 310 PacketTimeVector received_packet_times; |
1012 | 311 |
1013 // Set of packets. | 312 // Set of packets. |
1014 PacketNumberQueue packets; | 313 PacketNumberQueue packets; |
1015 | 314 |
1016 // Path which this ack belongs to. | 315 // Path which this ack belongs to. |
1017 QuicPathId path_id; | 316 QuicPathId path_id; |
1018 | |
1019 // Entropy hash of all packets up to largest observed not including missing | |
1020 // packets. | |
1021 QuicPacketEntropyHash entropy_hash; | |
1022 | |
1023 // Whether the ack had to be truncated when sent. | |
1024 bool is_truncated; | |
1025 | |
1026 // If true, |packets| express missing packets. Otherwise, |packets| express | |
1027 // received packets. | |
1028 bool missing; | |
1029 }; | 317 }; |
1030 | 318 |
1031 // True if the packet number is greater than largest_observed or is listed | 319 // True if the packet number is greater than largest_observed or is listed |
1032 // as missing. | 320 // as missing. |
1033 // Always returns false for packet numbers less than least_unacked. | 321 // Always returns false for packet numbers less than least_unacked. |
1034 bool NET_EXPORT_PRIVATE | 322 bool NET_EXPORT_PRIVATE |
1035 IsAwaitingPacket(const QuicAckFrame& ack_frame, | 323 IsAwaitingPacket(const QuicAckFrame& ack_frame, |
1036 QuicPacketNumber packet_number, | 324 QuicPacketNumber packet_number, |
1037 QuicPacketNumber peer_least_packet_awaiting_ack); | 325 QuicPacketNumber peer_least_packet_awaiting_ack); |
1038 | 326 |
1039 // Defines for all types of congestion control algorithms that can be used in | |
1040 // QUIC. Note that this is separate from the congestion feedback type - | |
1041 // some congestion control algorithms may use the same feedback type | |
1042 // (Reno and Cubic are the classic example for that). | |
1043 enum CongestionControlType { | |
1044 kCubic, | |
1045 kCubicBytes, | |
1046 kReno, | |
1047 kRenoBytes, | |
1048 kBBR, | |
1049 }; | |
1050 | |
1051 enum LossDetectionType { | |
1052 kNack, // Used to mimic TCP's loss detection. | |
1053 kTime, // Time based loss detection. | |
1054 kAdaptiveTime, // Adaptive time based loss detection. | |
1055 kLazyFack, // Nack based but with FACK disabled for the first ack. | |
1056 }; | |
1057 | |
1058 struct NET_EXPORT_PRIVATE QuicRstStreamFrame { | 327 struct NET_EXPORT_PRIVATE QuicRstStreamFrame { |
1059 QuicRstStreamFrame(); | 328 QuicRstStreamFrame(); |
1060 QuicRstStreamFrame(QuicStreamId stream_id, | 329 QuicRstStreamFrame(QuicStreamId stream_id, |
1061 QuicRstStreamErrorCode error_code, | 330 QuicRstStreamErrorCode error_code, |
1062 QuicStreamOffset bytes_written); | 331 QuicStreamOffset bytes_written); |
1063 | 332 |
1064 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | 333 NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
1065 std::ostream& os, | 334 std::ostream& os, |
1066 const QuicRstStreamFrame& r); | 335 const QuicRstStreamFrame& r); |
1067 | 336 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 QuicPathCloseFrame() {} | 417 QuicPathCloseFrame() {} |
1149 explicit QuicPathCloseFrame(QuicPathId path_id); | 418 explicit QuicPathCloseFrame(QuicPathId path_id); |
1150 | 419 |
1151 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | 420 NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
1152 std::ostream& os, | 421 std::ostream& os, |
1153 const QuicPathCloseFrame& p); | 422 const QuicPathCloseFrame& p); |
1154 | 423 |
1155 QuicPathId path_id; | 424 QuicPathId path_id; |
1156 }; | 425 }; |
1157 | 426 |
1158 // EncryptionLevel enumerates the stages of encryption that a QUIC connection | |
1159 // progresses through. When retransmitting a packet, the encryption level needs | |
1160 // to be specified so that it is retransmitted at a level which the peer can | |
1161 // understand. | |
1162 enum EncryptionLevel : int8_t { | |
1163 ENCRYPTION_NONE = 0, | |
1164 ENCRYPTION_INITIAL = 1, | |
1165 ENCRYPTION_FORWARD_SECURE = 2, | |
1166 | |
1167 NUM_ENCRYPTION_LEVELS, | |
1168 }; | |
1169 | |
1170 enum PeerAddressChangeType { | |
1171 // IP address and port remain unchanged. | |
1172 NO_CHANGE, | |
1173 // Port changed, but IP address remains unchanged. | |
1174 PORT_CHANGE, | |
1175 // IPv4 address changed, but within the /24 subnet (port may have changed.) | |
1176 IPV4_SUBNET_CHANGE, | |
1177 // IPv4 address changed, excluding /24 subnet change (port may have changed.) | |
1178 IPV4_TO_IPV4_CHANGE, | |
1179 // IP address change from an IPv4 to an IPv6 address (port may have changed.) | |
1180 IPV4_TO_IPV6_CHANGE, | |
1181 // IP address change from an IPv6 to an IPv4 address (port may have changed.) | |
1182 IPV6_TO_IPV4_CHANGE, | |
1183 // IP address change from an IPv6 to an IPv6 address (port may have changed.) | |
1184 IPV6_TO_IPV6_CHANGE, | |
1185 }; | |
1186 | |
1187 struct NET_EXPORT_PRIVATE QuicFrame { | 427 struct NET_EXPORT_PRIVATE QuicFrame { |
1188 QuicFrame(); | 428 QuicFrame(); |
1189 explicit QuicFrame(QuicPaddingFrame padding_frame); | 429 explicit QuicFrame(QuicPaddingFrame padding_frame); |
1190 explicit QuicFrame(QuicMtuDiscoveryFrame frame); | 430 explicit QuicFrame(QuicMtuDiscoveryFrame frame); |
1191 explicit QuicFrame(QuicPingFrame frame); | 431 explicit QuicFrame(QuicPingFrame frame); |
1192 | 432 |
1193 explicit QuicFrame(QuicStreamFrame* stream_frame); | 433 explicit QuicFrame(QuicStreamFrame* stream_frame); |
1194 explicit QuicFrame(QuicAckFrame* frame); | 434 explicit QuicFrame(QuicAckFrame* frame); |
1195 explicit QuicFrame(QuicRstStreamFrame* frame); | 435 explicit QuicFrame(QuicRstStreamFrame* frame); |
1196 explicit QuicFrame(QuicConnectionCloseFrame* frame); | 436 explicit QuicFrame(QuicConnectionCloseFrame* frame); |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1369 // Called when an unrecoverable error is encountered. | 609 // Called when an unrecoverable error is encountered. |
1370 virtual void OnUnrecoverableError(QuicErrorCode error, | 610 virtual void OnUnrecoverableError(QuicErrorCode error, |
1371 const std::string& error_details, | 611 const std::string& error_details, |
1372 ConnectionCloseSource source) = 0; | 612 ConnectionCloseSource source) = 0; |
1373 }; | 613 }; |
1374 | 614 |
1375 // Used to generate filtered supported versions based on flags. | 615 // Used to generate filtered supported versions based on flags. |
1376 class NET_EXPORT_PRIVATE QuicVersionManager { | 616 class NET_EXPORT_PRIVATE QuicVersionManager { |
1377 public: | 617 public: |
1378 explicit QuicVersionManager(QuicVersionVector supported_versions); | 618 explicit QuicVersionManager(QuicVersionVector supported_versions); |
1379 ~QuicVersionManager(); | 619 virtual ~QuicVersionManager(); |
1380 | 620 |
1381 // Returns supported versions based on flags. | 621 // Returns currently supported QUIC versions. |
1382 const QuicVersionVector& GetSupportedVersions(); | 622 const QuicVersionVector& GetSupportedVersions(); |
1383 | 623 |
| 624 protected: |
| 625 // Maybe refilter filtered_supported_versions_ based on flags. |
| 626 void MaybeRefilterSupportedVersions(); |
| 627 |
| 628 // Refilters filtered_supported_versions_. |
| 629 virtual void RefilterSupportedVersions(); |
| 630 |
| 631 const QuicVersionVector& filtered_supported_versions() const { |
| 632 return filtered_supported_versions_; |
| 633 } |
| 634 |
1384 private: | 635 private: |
1385 // FLAGS_quic_disable_pre_34 | 636 // FLAGS_quic_enable_version_36_v3 |
1386 bool disable_pre_34_; | |
1387 // FLAGS_quic_enable_version_35 | |
1388 bool enable_version_35_; | |
1389 // FLAGS_quic_enable_version_36_v2 | |
1390 bool enable_version_36_; | 637 bool enable_version_36_; |
1391 // The list of versions that may be supported. | 638 // The list of versions that may be supported. |
1392 QuicVersionVector allowed_supported_versions_; | 639 QuicVersionVector allowed_supported_versions_; |
1393 // This vector contains QUIC versions which are currently supported based | 640 // This vector contains QUIC versions which are currently supported based |
1394 // on flags. | 641 // on flags. |
1395 QuicVersionVector filtered_supported_versions_; | 642 QuicVersionVector filtered_supported_versions_; |
1396 }; | 643 }; |
1397 | 644 |
1398 struct NET_EXPORT_PRIVATE AckListenerWrapper { | 645 struct NET_EXPORT_PRIVATE AckListenerWrapper { |
1399 AckListenerWrapper(QuicAckListenerInterface* listener, | 646 AckListenerWrapper(QuicAckListenerInterface* listener, |
1400 QuicPacketLength data_length); | 647 QuicPacketLength data_length); |
1401 AckListenerWrapper(const AckListenerWrapper& other); | 648 AckListenerWrapper(const AckListenerWrapper& other); |
1402 ~AckListenerWrapper(); | 649 ~AckListenerWrapper(); |
1403 | 650 |
1404 scoped_refptr<QuicAckListenerInterface> ack_listener; | 651 scoped_refptr<QuicAckListenerInterface> ack_listener; |
1405 QuicPacketLength length; | 652 QuicPacketLength length; |
1406 }; | 653 }; |
1407 | 654 |
1408 struct NET_EXPORT_PRIVATE SerializedPacket { | 655 struct NET_EXPORT_PRIVATE SerializedPacket { |
1409 SerializedPacket(QuicPathId path_id, | 656 SerializedPacket(QuicPathId path_id, |
1410 QuicPacketNumber packet_number, | 657 QuicPacketNumber packet_number, |
1411 QuicPacketNumberLength packet_number_length, | 658 QuicPacketNumberLength packet_number_length, |
1412 const char* encrypted_buffer, | 659 const char* encrypted_buffer, |
1413 QuicPacketLength encrypted_length, | 660 QuicPacketLength encrypted_length, |
1414 QuicPacketEntropyHash entropy_hash, | |
1415 bool has_ack, | 661 bool has_ack, |
1416 bool has_stop_waiting); | 662 bool has_stop_waiting); |
1417 SerializedPacket(const SerializedPacket& other); | 663 SerializedPacket(const SerializedPacket& other); |
1418 ~SerializedPacket(); | 664 ~SerializedPacket(); |
1419 | 665 |
1420 // Not owned. | 666 // Not owned. |
1421 const char* encrypted_buffer; | 667 const char* encrypted_buffer; |
1422 QuicPacketLength encrypted_length; | 668 QuicPacketLength encrypted_length; |
1423 QuicFrames retransmittable_frames; | 669 QuicFrames retransmittable_frames; |
1424 IsHandshake has_crypto_handshake; | 670 IsHandshake has_crypto_handshake; |
1425 // -1: full padding to the end of a max-sized packet | 671 // -1: full padding to the end of a max-sized packet |
1426 // 0: no padding | 672 // 0: no padding |
1427 // otherwise: only pad up to num_padding_bytes bytes | 673 // otherwise: only pad up to num_padding_bytes bytes |
1428 int16_t num_padding_bytes; | 674 int16_t num_padding_bytes; |
1429 QuicPathId path_id; | 675 QuicPathId path_id; |
1430 QuicPacketNumber packet_number; | 676 QuicPacketNumber packet_number; |
1431 QuicPacketNumberLength packet_number_length; | 677 QuicPacketNumberLength packet_number_length; |
1432 EncryptionLevel encryption_level; | 678 EncryptionLevel encryption_level; |
1433 QuicPacketEntropyHash entropy_hash; | |
1434 bool has_ack; | 679 bool has_ack; |
1435 bool has_stop_waiting; | 680 bool has_stop_waiting; |
1436 TransmissionType transmission_type; | 681 TransmissionType transmission_type; |
1437 QuicPathId original_path_id; | 682 QuicPathId original_path_id; |
1438 QuicPacketNumber original_packet_number; | 683 QuicPacketNumber original_packet_number; |
1439 | 684 |
1440 // Optional notifiers which will be informed when this packet has been ACKed. | 685 // Optional notifiers which will be informed when this packet has been ACKed. |
1441 std::list<AckListenerWrapper> listeners; | 686 std::list<AckListenerWrapper> listeners; |
1442 }; | 687 }; |
1443 | 688 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1505 QuicPacketNumber packet_number; | 750 QuicPacketNumber packet_number; |
1506 const QuicFrames& retransmittable_frames; | 751 const QuicFrames& retransmittable_frames; |
1507 TransmissionType transmission_type; | 752 TransmissionType transmission_type; |
1508 QuicPathId path_id; | 753 QuicPathId path_id; |
1509 bool has_crypto_handshake; | 754 bool has_crypto_handshake; |
1510 int num_padding_bytes; | 755 int num_padding_bytes; |
1511 EncryptionLevel encryption_level; | 756 EncryptionLevel encryption_level; |
1512 QuicPacketNumberLength packet_number_length; | 757 QuicPacketNumberLength packet_number_length; |
1513 }; | 758 }; |
1514 | 759 |
1515 // Convenience wrapper to wrap an iovec array and the total length, which must | |
1516 // be less than or equal to the actual total length of the iovecs. | |
1517 struct NET_EXPORT_PRIVATE QuicIOVector { | |
1518 QuicIOVector(const struct iovec* iov, int iov_count, size_t total_length) | |
1519 : iov(iov), iov_count(iov_count), total_length(total_length) {} | |
1520 | |
1521 const struct iovec* iov; | |
1522 const int iov_count; | |
1523 const size_t total_length; | |
1524 }; | |
1525 | |
1526 } // namespace net | 760 } // namespace net |
1527 | 761 |
1528 #endif // NET_QUIC_QUIC_PROTOCOL_H_ | 762 #endif // NET_QUIC_QUIC_PROTOCOL_H_ |
OLD | NEW |