OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_QUIC_QUIC_PROTOCOL_H_ | |
6 #define NET_QUIC_QUIC_PROTOCOL_H_ | |
7 | |
8 #include <stddef.h> | |
9 #include <stdint.h> | |
10 | |
11 #include <limits> | |
12 #include <list> | |
13 #include <map> | |
14 #include <memory> | |
15 #include <ostream> | |
16 #include <set> | |
17 #include <string> | |
18 #include <utility> | |
19 #include <vector> | |
20 | |
21 #include "base/logging.h" | |
22 #include "base/macros.h" | |
23 #include "base/memory/ref_counted.h" | |
24 #include "base/strings/string_piece.h" | |
25 #include "net/base/int128.h" | |
26 #include "net/base/iovec.h" | |
27 #include "net/base/ip_endpoint.h" | |
28 #include "net/base/net_export.h" | |
29 #include "net/quic/interval_set.h" | |
30 #include "net/quic/quic_bandwidth.h" | |
31 #include "net/quic/quic_time.h" | |
32 #include "net/quic/quic_types.h" | |
33 | |
34 namespace net { | |
35 | |
36 class QuicPacket; | |
37 struct QuicPacketHeader; | |
38 class QuicAckListenerInterface; | |
39 | |
40 typedef uint64_t QuicConnectionId; | |
41 typedef uint32_t QuicStreamId; | |
42 typedef uint64_t QuicStreamOffset; | |
43 typedef uint64_t QuicPacketNumber; | |
44 typedef uint8_t QuicPathId; | |
45 typedef uint64_t QuicPublicResetNonceProof; | |
46 typedef uint8_t QuicPacketEntropyHash; | |
47 typedef uint32_t QuicHeaderId; | |
48 // QuicTag is the type of a tag in the wire protocol. | |
49 typedef uint32_t QuicTag; | |
50 typedef std::vector<QuicTag> QuicTagVector; | |
51 typedef std::map<QuicTag, std::string> QuicTagValueMap; | |
52 typedef uint16_t QuicPacketLength; | |
53 | |
54 // Default initial maximum size in bytes of a QUIC packet. | |
55 const QuicByteCount kDefaultMaxPacketSize = 1350; | |
56 // Default initial maximum size in bytes of a QUIC packet for servers. | |
57 const QuicByteCount kDefaultServerMaxPacketSize = 1000; | |
58 // The maximum packet size of any QUIC packet, based on ethernet's max size, | |
59 // minus the IP and UDP headers. IPv6 has a 40 byte header, UDP adds an | |
60 // additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's | |
61 // max packet size is 1500 bytes, 1500 - 48 = 1452. | |
62 const QuicByteCount kMaxPacketSize = 1452; | |
63 // Default maximum packet size used in the Linux TCP implementation. | |
64 // Used in QUIC for congestion window computations in bytes. | |
65 const QuicByteCount kDefaultTCPMSS = 1460; | |
66 | |
67 // We match SPDY's use of 32 (since we'd compete with SPDY). | |
68 const QuicPacketCount kInitialCongestionWindow = 32; | |
69 | |
70 // Minimum size of initial flow control window, for both stream and session. | |
71 const uint32_t kMinimumFlowControlSendWindow = 16 * 1024; // 16 KB | |
72 | |
73 // Maximum flow control receive window limits for connection and stream. | |
74 const QuicByteCount kStreamReceiveWindowLimit = 16 * 1024 * 1024; // 16 MB | |
75 const QuicByteCount kSessionReceiveWindowLimit = 24 * 1024 * 1024; // 24 MB | |
76 | |
77 // Minimum size of the CWND, in packets, when doing bandwidth resumption. | |
78 const QuicPacketCount kMinCongestionWindowForBandwidthResumption = 10; | |
79 | |
80 // Maximum number of tracked packets. | |
81 const QuicPacketCount kMaxTrackedPackets = 10000; | |
82 | |
83 // Default size of the socket receive buffer in bytes. | |
84 const QuicByteCount kDefaultSocketReceiveBuffer = 1024 * 1024; | |
85 // Minimum size of the socket receive buffer in bytes. | |
86 // Smaller values are ignored. | |
87 const QuicByteCount kMinSocketReceiveBuffer = 16 * 1024; | |
88 | |
89 // Fraction of the receive buffer that can be used, based on conservative | |
90 // estimates and testing on Linux. | |
91 // An alternative to kUsableRecieveBufferFraction. | |
92 static const float kConservativeReceiveBufferFraction = 0.6f; | |
93 | |
94 // Don't allow a client to suggest an RTT shorter than 10ms. | |
95 const uint32_t kMinInitialRoundTripTimeUs = 10 * kNumMicrosPerMilli; | |
96 | |
97 // Don't allow a client to suggest an RTT longer than 15 seconds. | |
98 const uint32_t kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond; | |
99 | |
100 // Maximum number of open streams per connection. | |
101 const size_t kDefaultMaxStreamsPerConnection = 100; | |
102 | |
103 // Number of bytes reserved for public flags in the packet header. | |
104 const size_t kPublicFlagsSize = 1; | |
105 // Number of bytes reserved for version number in the packet header. | |
106 const size_t kQuicVersionSize = 4; | |
107 // Number of bytes reserved for path id in the packet header. | |
108 const size_t kQuicPathIdSize = 1; | |
109 // Number of bytes reserved for private flags in the packet header. | |
110 const size_t kPrivateFlagsSize = 1; | |
111 | |
112 // Signifies that the QuicPacket will contain version of the protocol. | |
113 const bool kIncludeVersion = true; | |
114 // Signifies that the QuicPacket will contain path id. | |
115 const bool kIncludePathId = true; | |
116 // Signifies that the QuicPacket will include a diversification nonce. | |
117 const bool kIncludeDiversificationNonce = true; | |
118 | |
119 // Stream ID is reserved to denote an invalid ID. | |
120 const QuicStreamId kInvalidStreamId = 0; | |
121 | |
122 // Reserved ID for the crypto stream. | |
123 const QuicStreamId kCryptoStreamId = 1; | |
124 | |
125 // Reserved ID for the headers stream. | |
126 const QuicStreamId kHeadersStreamId = 3; | |
127 | |
128 // Header key used to identify final offset on data stream when sending HTTP/2 | |
129 // trailing headers over QUIC. | |
130 NET_EXPORT_PRIVATE extern const char* const kFinalOffsetHeaderKey; | |
131 | |
132 // Maximum delayed ack time, in ms. | |
133 const int64_t kMaxDelayedAckTimeMs = 25; | |
134 | |
135 // Minimum tail loss probe time in ms. | |
136 static const int64_t kMinTailLossProbeTimeoutMs = 10; | |
137 | |
138 // The timeout before the handshake succeeds. | |
139 const int64_t kInitialIdleTimeoutSecs = 5; | |
140 // The default idle timeout. | |
141 const int64_t kDefaultIdleTimeoutSecs = 30; | |
142 // The maximum idle timeout that can be negotiated. | |
143 const int64_t kMaximumIdleTimeoutSecs = 60 * 10; // 10 minutes. | |
144 // The default timeout for a connection until the crypto handshake succeeds. | |
145 const int64_t kMaxTimeForCryptoHandshakeSecs = 10; // 10 secs. | |
146 | |
147 // Default limit on the number of undecryptable packets the connection buffers | |
148 // before the CHLO/SHLO arrive. | |
149 const size_t kDefaultMaxUndecryptablePackets = 10; | |
150 | |
151 // Default ping timeout. | |
152 const int64_t kPingTimeoutSecs = 15; // 15 secs. | |
153 | |
154 // Minimum number of RTTs between Server Config Updates (SCUP) sent to client. | |
155 const int kMinIntervalBetweenServerConfigUpdatesRTTs = 10; | |
156 | |
157 // Minimum time between Server Config Updates (SCUP) sent to client. | |
158 const int kMinIntervalBetweenServerConfigUpdatesMs = 1000; | |
159 | |
160 // Minimum number of packets between Server Config Updates (SCUP). | |
161 const int kMinPacketsBetweenServerConfigUpdates = 100; | |
162 | |
163 // The number of open streams that a server will accept is set to be slightly | |
164 // larger than the negotiated limit. Immediately closing the connection if the | |
165 // client opens slightly too many streams is not ideal: the client may have sent | |
166 // a FIN that was lost, and simultaneously opened a new stream. The number of | |
167 // streams a server accepts is a fixed increment over the negotiated limit, or a | |
168 // percentage increase, whichever is larger. | |
169 const float kMaxStreamsMultiplier = 1.1f; | |
170 const int kMaxStreamsMinimumIncrement = 10; | |
171 | |
172 // Available streams are ones with IDs less than the highest stream that has | |
173 // been opened which have neither been opened or reset. The limit on the number | |
174 // of available streams is 10 times the limit on the number of open streams. | |
175 const int kMaxAvailableStreamsMultiplier = 10; | |
176 | |
177 // Track the number of promises that are not yet claimed by a | |
178 // corresponding get. This must be smaller than | |
179 // kMaxAvailableStreamsMultiplier, because RST on a promised stream my | |
180 // create available streams entries. | |
181 const int kMaxPromisedStreamsMultiplier = kMaxAvailableStreamsMultiplier - 1; | |
182 | |
183 // TCP RFC calls for 1 second RTO however Linux differs from this default and | |
184 // define the minimum RTO to 200ms, we will use the same until we have data to | |
185 // support a higher or lower value. | |
186 static const int64_t kMinRetransmissionTimeMs = 200; | |
187 | |
188 // We define an unsigned 16-bit floating point value, inspired by IEEE floats | |
189 // (http://en.wikipedia.org/wiki/Half_precision_floating-point_format), | |
190 // with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden | |
191 // bit) and denormals, but without signs, transfinites or fractions. Wire format | |
192 // 16 bits (little-endian byte order) are split into exponent (high 5) and | |
193 // mantissa (low 11) and decoded as: | |
194 // uint64_t value; | |
195 // if (exponent == 0) value = mantissa; | |
196 // else value = (mantissa | 1 << 11) << (exponent - 1) | |
197 const int kUFloat16ExponentBits = 5; | |
198 const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30 | |
199 const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11 | |
200 const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12 | |
201 const uint64_t kUFloat16MaxValue = // 0x3FFC0000000 | |
202 ((UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1) | |
203 << kUFloat16MaxExponent; | |
204 | |
205 // Default path ID. | |
206 const QuicPathId kDefaultPathId = 0; | |
207 // Invalid path ID. | |
208 const QuicPathId kInvalidPathId = 0xff; | |
209 | |
210 // kDiversificationNonceSize is the size, in bytes, of the nonce that a server | |
211 // may set in the packet header to ensure that its INITIAL keys are not | |
212 // duplicated. | |
213 const size_t kDiversificationNonceSize = 32; | |
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 }; | |
244 | |
245 NET_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, | |
246 const Perspective& s); | |
247 enum QuicFrameType { | |
248 // Regular frame types. The values set here cannot change without the | |
249 // introduction of a new QUIC version. | |
250 PADDING_FRAME = 0, | |
251 RST_STREAM_FRAME = 1, | |
252 CONNECTION_CLOSE_FRAME = 2, | |
253 GOAWAY_FRAME = 3, | |
254 WINDOW_UPDATE_FRAME = 4, | |
255 BLOCKED_FRAME = 5, | |
256 STOP_WAITING_FRAME = 6, | |
257 PING_FRAME = 7, | |
258 PATH_CLOSE_FRAME = 8, | |
259 | |
260 // STREAM and ACK frames are special frames. They are encoded differently on | |
261 // the wire and their values do not need to be stable. | |
262 STREAM_FRAME, | |
263 ACK_FRAME, | |
264 // The path MTU discovery frame is encoded as a PING frame on the wire. | |
265 MTU_DISCOVERY_FRAME, | |
266 NUM_FRAME_TYPES | |
267 }; | |
268 | |
269 enum QuicConnectionIdLength { | |
270 PACKET_0BYTE_CONNECTION_ID = 0, | |
271 PACKET_8BYTE_CONNECTION_ID = 8 | |
272 }; | |
273 | |
274 enum QuicPacketNumberLength : int8_t { | |
275 PACKET_1BYTE_PACKET_NUMBER = 1, | |
276 PACKET_2BYTE_PACKET_NUMBER = 2, | |
277 PACKET_4BYTE_PACKET_NUMBER = 4, | |
278 PACKET_6BYTE_PACKET_NUMBER = 6 | |
279 }; | |
280 | |
281 // Used to indicate a QuicSequenceNumberLength using two flag bits. | |
282 enum QuicPacketNumberLengthFlags { | |
283 PACKET_FLAGS_1BYTE_PACKET = 0, // 00 | |
284 PACKET_FLAGS_2BYTE_PACKET = 1, // 01 | |
285 PACKET_FLAGS_4BYTE_PACKET = 1 << 1, // 10 | |
286 PACKET_FLAGS_6BYTE_PACKET = 1 << 1 | 1, // 11 | |
287 }; | |
288 | |
289 // The public flags are specified in one byte. | |
290 enum QuicPacketPublicFlags { | |
291 PACKET_PUBLIC_FLAGS_NONE = 0, | |
292 | |
293 // Bit 0: Does the packet header contains version info? | |
294 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0, | |
295 | |
296 // Bit 1: Is this packet a public reset packet? | |
297 PACKET_PUBLIC_FLAGS_RST = 1 << 1, | |
298 | |
299 // Bit 2: indicates the that public header includes a nonce. | |
300 PACKET_PUBLIC_FLAGS_NONCE = 1 << 2, | |
301 | |
302 // Bit 3: indicates whether a ConnectionID is included. | |
303 PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID = 0, | |
304 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID = 1 << 3, | |
305 | |
306 // QUIC_VERSION_32 and earlier use two bits for an 8 byte | |
307 // connection id. | |
308 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID_OLD = 1 << 3 | 1 << 2, | |
309 | |
310 // Bits 4 and 5 describe the packet number length as follows: | |
311 // --00----: 1 byte | |
312 // --01----: 2 bytes | |
313 // --10----: 4 bytes | |
314 // --11----: 6 bytes | |
315 PACKET_PUBLIC_FLAGS_1BYTE_PACKET = PACKET_FLAGS_1BYTE_PACKET << 4, | |
316 PACKET_PUBLIC_FLAGS_2BYTE_PACKET = PACKET_FLAGS_2BYTE_PACKET << 4, | |
317 PACKET_PUBLIC_FLAGS_4BYTE_PACKET = PACKET_FLAGS_4BYTE_PACKET << 4, | |
318 PACKET_PUBLIC_FLAGS_6BYTE_PACKET = PACKET_FLAGS_6BYTE_PACKET << 4, | |
319 | |
320 // Bit 6: Does the packet header contain a path id? | |
321 PACKET_PUBLIC_FLAGS_MULTIPATH = 1 << 6, | |
322 | |
323 // Reserved, unimplemented flags: | |
324 | |
325 // Bit 7: indicates the presence of a second flags byte. | |
326 PACKET_PUBLIC_FLAGS_TWO_OR_MORE_BYTES = 1 << 7, | |
327 | |
328 // All bits set (bit 7 is not currently used): 01111111 | |
329 PACKET_PUBLIC_FLAGS_MAX = (1 << 7) - 1, | |
330 }; | |
331 | |
332 // The private flags are specified in one byte. | |
333 enum QuicPacketPrivateFlags { | |
334 PACKET_PRIVATE_FLAGS_NONE = 0, | |
335 | |
336 // Bit 0: Does this packet contain an entropy bit? | |
337 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0, | |
338 | |
339 // Bit 1: Payload is part of an FEC group? | |
340 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1, | |
341 | |
342 // Bit 2: Payload is FEC as opposed to frames? | |
343 PACKET_PRIVATE_FLAGS_FEC = 1 << 2, | |
344 | |
345 // All bits set (bits 3-7 are not currently used): 00000111 | |
346 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1, | |
347 | |
348 // For version 32 (bits 1-7 are not used): 00000001 | |
349 PACKET_PRIVATE_FLAGS_MAX_VERSION_32 = (1 << 1) - 1 | |
350 }; | |
351 | |
352 // The available versions of QUIC. Guaranteed that the integer value of the enum | |
353 // will match the version number. | |
354 // When adding a new version to this enum you should add it to | |
355 // kSupportedQuicVersions (if appropriate), and also add a new case to the | |
356 // helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and | |
357 // QuicVersionToString. | |
358 enum QuicVersion { | |
359 // Special case to indicate unknown/unsupported QUIC version. | |
360 QUIC_VERSION_UNSUPPORTED = 0, | |
361 | |
362 QUIC_VERSION_30 = 30, // Add server side support of cert transparency. | |
363 QUIC_VERSION_31 = 31, // Adds a hash of the client hello to crypto proof. | |
364 QUIC_VERSION_32 = 32, // FEC related fields are removed from wire format. | |
365 QUIC_VERSION_33 = 33, // Adds diversification nonces. | |
366 QUIC_VERSION_34 = 34, // Deprecates entropy, removes private flag from packet | |
367 // header, uses new ack and stop waiting wire format. | |
368 QUIC_VERSION_35 = 35, // Allows endpoints to independently set stream limit. | |
369 QUIC_VERSION_36 = 36, // Add support to force HOL blocking. | |
370 }; | |
371 | |
372 // This vector contains QUIC versions which we currently support. | |
373 // This should be ordered such that the highest supported version is the first | |
374 // element, with subsequent elements in descending order (versions can be | |
375 // skipped as necessary). | |
376 // | |
377 // IMPORTANT: if you are adding to this list, follow the instructions at | |
378 // http://sites/quic/adding-and-removing-versions | |
379 static const QuicVersion kSupportedQuicVersions[] = { | |
380 QUIC_VERSION_36, QUIC_VERSION_35, QUIC_VERSION_34, QUIC_VERSION_33, | |
381 QUIC_VERSION_32, QUIC_VERSION_31, QUIC_VERSION_30}; | |
382 | |
383 typedef std::vector<QuicVersion> QuicVersionVector; | |
384 | |
385 // Returns a vector of QUIC versions in kSupportedQuicVersions. | |
386 NET_EXPORT_PRIVATE QuicVersionVector QuicSupportedVersions(); | |
387 | |
388 // Returns a vector of QUIC versions from |versions| which exclude any versions | |
389 // which are disabled by flags. | |
390 NET_EXPORT_PRIVATE QuicVersionVector | |
391 FilterSupportedVersions(QuicVersionVector versions); | |
392 | |
393 // QuicTag is written to and read from the wire, but we prefer to use | |
394 // the more readable QuicVersion at other levels. | |
395 // Helper function which translates from a QuicVersion to a QuicTag. Returns 0 | |
396 // if QuicVersion is unsupported. | |
397 NET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version); | |
398 | |
399 // Returns appropriate QuicVersion from a QuicTag. | |
400 // Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood. | |
401 NET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag); | |
402 | |
403 // Helper function which translates from a QuicVersion to a string. | |
404 // Returns strings corresponding to enum names (e.g. QUIC_VERSION_6). | |
405 NET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version); | |
406 | |
407 // Returns comma separated list of string representations of QuicVersion enum | |
408 // values in the supplied |versions| vector. | |
409 NET_EXPORT_PRIVATE std::string QuicVersionVectorToString( | |
410 const QuicVersionVector& versions); | |
411 | |
412 // Version and Crypto tags are written to the wire with a big-endian | |
413 // representation of the name of the tag. For example | |
414 // the client hello tag (CHLO) will be written as the | |
415 // following 4 bytes: 'C' 'H' 'L' 'O'. Since it is | |
416 // stored in memory as a little endian uint32_t, we need | |
417 // to reverse the order of the bytes. | |
418 | |
419 // MakeQuicTag returns a value given the four bytes. For example: | |
420 // MakeQuicTag('C', 'H', 'L', 'O'); | |
421 NET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d); | |
422 | |
423 // Returns true if the tag vector contains the specified tag. | |
424 NET_EXPORT_PRIVATE bool ContainsQuicTag(const QuicTagVector& tag_vector, | |
425 QuicTag tag); | |
426 | |
427 // Size in bytes of the data packet header. | |
428 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicVersion version, | |
429 const QuicPacketHeader& header); | |
430 | |
431 NET_EXPORT_PRIVATE size_t | |
432 GetPacketHeaderSize(QuicVersion version, | |
433 QuicConnectionIdLength connection_id_length, | |
434 bool include_version, | |
435 bool include_path_id, | |
436 bool include_diversification_nonce, | |
437 QuicPacketNumberLength packet_number_length); | |
438 | |
439 // Index of the first byte in a QUIC packet of encrypted data. | |
440 NET_EXPORT_PRIVATE size_t | |
441 GetStartOfEncryptedData(QuicVersion version, const QuicPacketHeader& header); | |
442 | |
443 NET_EXPORT_PRIVATE size_t | |
444 GetStartOfEncryptedData(QuicVersion version, | |
445 QuicConnectionIdLength connection_id_length, | |
446 bool include_version, | |
447 bool include_path_id, | |
448 bool include_diversification_nonce, | |
449 QuicPacketNumberLength packet_number_length); | |
450 | |
451 enum QuicRstStreamErrorCode { | |
452 // Complete response has been sent, sending a RST to ask the other endpoint | |
453 // to stop sending request data without discarding the response. | |
454 QUIC_STREAM_NO_ERROR = 0, | |
455 | |
456 // There was some error which halted stream processing. | |
457 QUIC_ERROR_PROCESSING_STREAM, | |
458 // We got two fin or reset offsets which did not match. | |
459 QUIC_MULTIPLE_TERMINATION_OFFSETS, | |
460 // We got bad payload and can not respond to it at the protocol level. | |
461 QUIC_BAD_APPLICATION_PAYLOAD, | |
462 // Stream closed due to connection error. No reset frame is sent when this | |
463 // happens. | |
464 QUIC_STREAM_CONNECTION_ERROR, | |
465 // GoAway frame sent. No more stream can be created. | |
466 QUIC_STREAM_PEER_GOING_AWAY, | |
467 // The stream has been cancelled. | |
468 QUIC_STREAM_CANCELLED, | |
469 // Closing stream locally, sending a RST to allow for proper flow control | |
470 // accounting. Sent in response to a RST from the peer. | |
471 QUIC_RST_ACKNOWLEDGEMENT, | |
472 // Receiver refused to create the stream (because its limit on open streams | |
473 // has been reached). The sender should retry the request later (using | |
474 // another stream). | |
475 QUIC_REFUSED_STREAM, | |
476 // Invalid URL in PUSH_PROMISE request header. | |
477 QUIC_INVALID_PROMISE_URL, | |
478 // Server is not authoritative for this URL. | |
479 QUIC_UNAUTHORIZED_PROMISE_URL, | |
480 // Can't have more than one active PUSH_PROMISE per URL. | |
481 QUIC_DUPLICATE_PROMISE_URL, | |
482 // Vary check failed. | |
483 QUIC_PROMISE_VARY_MISMATCH, | |
484 // Only GET and HEAD methods allowed. | |
485 QUIC_INVALID_PROMISE_METHOD, | |
486 // No error. Used as bound while iterating. | |
487 QUIC_STREAM_LAST_ERROR, | |
488 }; | |
489 // QUIC error codes are encoded to a single octet on-the-wire. | |
490 static_assert(static_cast<int>(QUIC_STREAM_LAST_ERROR) <= | |
491 std::numeric_limits<uint8_t>::max(), | |
492 "QuicErrorCode exceeds single octet"); | |
493 | |
494 // Because receiving an unknown QuicRstStreamErrorCode results in connection | |
495 // teardown, we use this to make sure any errors predating a given version are | |
496 // downgraded to the most appropriate existing error. | |
497 NET_EXPORT_PRIVATE QuicRstStreamErrorCode | |
498 AdjustErrorForVersion(QuicRstStreamErrorCode error_code, QuicVersion version); | |
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 // An internal error occured in crypto processing. | |
646 QUIC_CRYPTO_INTERNAL_ERROR = 38, | |
647 // A crypto handshake message specified an unsupported version. | |
648 QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39, | |
649 // A crypto handshake message resulted in a stateless reject. | |
650 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT = 72, | |
651 // There was no intersection between the crypto primitives supported by the | |
652 // peer and ourselves. | |
653 QUIC_CRYPTO_NO_SUPPORT = 40, | |
654 // The server rejected our client hello messages too many times. | |
655 QUIC_CRYPTO_TOO_MANY_REJECTS = 41, | |
656 // The client rejected the server's certificate chain or signature. | |
657 QUIC_PROOF_INVALID = 42, | |
658 // A crypto message was received with a duplicate tag. | |
659 QUIC_CRYPTO_DUPLICATE_TAG = 43, | |
660 // A crypto message was received with the wrong encryption level (i.e. it | |
661 // should have been encrypted but was not.) | |
662 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44, | |
663 // The server config for a server has expired. | |
664 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45, | |
665 // We failed to setup the symmetric keys for a connection. | |
666 QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53, | |
667 // A handshake message arrived, but we are still validating the | |
668 // previous handshake message. | |
669 QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54, | |
670 // A server config update arrived before the handshake is complete. | |
671 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE = 65, | |
672 // CHLO cannot fit in one packet. | |
673 QUIC_CRYPTO_CHLO_TOO_LARGE = 90, | |
674 // This connection involved a version negotiation which appears to have been | |
675 // tampered with. | |
676 QUIC_VERSION_NEGOTIATION_MISMATCH = 55, | |
677 | |
678 // Multipath errors. | |
679 // Multipath is not enabled, but a packet with multipath flag on is received. | |
680 QUIC_BAD_MULTIPATH_FLAG = 79, | |
681 // A path is supposed to exist but does not. | |
682 QUIC_MULTIPATH_PATH_DOES_NOT_EXIST = 91, | |
683 // A path is supposed to be active but is not. | |
684 QUIC_MULTIPATH_PATH_NOT_ACTIVE = 92, | |
685 | |
686 // IP address changed causing connection close. | |
687 QUIC_IP_ADDRESS_CHANGED = 80, | |
688 | |
689 // Connection migration errors. | |
690 // Network changed, but connection had no migratable streams. | |
691 QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS = 81, | |
692 // Connection changed networks too many times. | |
693 QUIC_CONNECTION_MIGRATION_TOO_MANY_CHANGES = 82, | |
694 // Connection migration was attempted, but there was no new network to | |
695 // migrate to. | |
696 QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK = 83, | |
697 // Network changed, but connection had one or more non-migratable streams. | |
698 QUIC_CONNECTION_MIGRATION_NON_MIGRATABLE_STREAM = 84, | |
699 | |
700 // No error. Used as bound while iterating. | |
701 QUIC_LAST_ERROR = 93, | |
702 }; | |
703 | |
704 typedef char DiversificationNonce[32]; | |
705 | |
706 struct NET_EXPORT_PRIVATE QuicPacketPublicHeader { | |
707 QuicPacketPublicHeader(); | |
708 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other); | |
709 ~QuicPacketPublicHeader(); | |
710 | |
711 // Universal header. All QuicPacket headers will have a connection_id and | |
712 // public flags. | |
713 QuicConnectionId connection_id; | |
714 QuicConnectionIdLength connection_id_length; | |
715 bool multipath_flag; | |
716 bool reset_flag; | |
717 bool version_flag; | |
718 QuicPacketNumberLength packet_number_length; | |
719 QuicVersionVector versions; | |
720 // nonce contains an optional, 32-byte nonce value. If not included in the | |
721 // packet, |nonce| will be empty. | |
722 DiversificationNonce* nonce; | |
723 }; | |
724 | |
725 // An integer which cannot be a packet number. | |
726 const QuicPacketNumber kInvalidPacketNumber = 0; | |
727 | |
728 // Header for Data packets. | |
729 struct NET_EXPORT_PRIVATE QuicPacketHeader { | |
730 QuicPacketHeader(); | |
731 explicit QuicPacketHeader(const QuicPacketPublicHeader& header); | |
732 QuicPacketHeader(const QuicPacketHeader& other); | |
733 | |
734 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, | |
735 const QuicPacketHeader& s); | |
736 | |
737 QuicPacketPublicHeader public_header; | |
738 QuicPacketNumber packet_number; | |
739 QuicPathId path_id; | |
740 bool entropy_flag; | |
741 QuicPacketEntropyHash entropy_hash; | |
742 bool fec_flag; | |
743 }; | |
744 | |
745 struct NET_EXPORT_PRIVATE QuicPublicResetPacket { | |
746 QuicPublicResetPacket(); | |
747 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header); | |
748 | |
749 QuicPacketPublicHeader public_header; | |
750 QuicPublicResetNonceProof nonce_proof; | |
751 QuicPacketNumber rejected_packet_number; | |
752 IPEndPoint client_address; | |
753 }; | |
754 | |
755 enum QuicVersionNegotiationState { | |
756 START_NEGOTIATION = 0, | |
757 // Server-side this implies we've sent a version negotiation packet and are | |
758 // waiting on the client to select a compatible version. Client-side this | |
759 // implies we've gotten a version negotiation packet, are retransmitting the | |
760 // initial packets with a supported version and are waiting for our first | |
761 // packet from the server. | |
762 NEGOTIATION_IN_PROGRESS, | |
763 // This indicates this endpoint has received a packet from the peer with a | |
764 // version this endpoint supports. Version negotiation is complete, and the | |
765 // version number will no longer be sent with future packets. | |
766 NEGOTIATED_VERSION | |
767 }; | |
768 | |
769 typedef QuicPacketPublicHeader QuicVersionNegotiationPacket; | |
770 | |
771 // A padding frame contains no payload. | |
772 struct NET_EXPORT_PRIVATE QuicPaddingFrame { | |
773 QuicPaddingFrame() : num_padding_bytes(-1) {} | |
774 explicit QuicPaddingFrame(int num_padding_bytes) | |
775 : num_padding_bytes(num_padding_bytes) {} | |
776 | |
777 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, | |
778 const QuicPaddingFrame& s); | |
779 | |
780 // -1: full padding to the end of a max-sized packet | |
781 // otherwise: only pad up to num_padding_bytes bytes | |
782 int num_padding_bytes; | |
783 }; | |
784 | |
785 // A ping frame contains no payload, though it is retransmittable, | |
786 // and ACK'd just like other normal frames. | |
787 struct NET_EXPORT_PRIVATE QuicPingFrame {}; | |
788 | |
789 // A path MTU discovery frame contains no payload and is serialized as a ping | |
790 // frame. | |
791 struct NET_EXPORT_PRIVATE QuicMtuDiscoveryFrame {}; | |
792 | |
793 class NET_EXPORT_PRIVATE QuicBufferAllocator { | |
794 public: | |
795 virtual ~QuicBufferAllocator(); | |
796 | |
797 // Returns or allocates a new buffer of |size|. Never returns null. | |
798 virtual char* New(size_t size) = 0; | |
799 | |
800 // Returns or allocates a new buffer of |size| if |flag_enable| is true. | |
801 // Otherwise, returns a buffer that is compatible with this class directly | |
802 // with operator new. Never returns null. | |
803 virtual char* New(size_t size, bool flag_enable) = 0; | |
804 | |
805 // Releases a buffer. | |
806 virtual void Delete(char* buffer) = 0; | |
807 | |
808 // Marks the allocator as being idle. Serves as a hint to notify the allocator | |
809 // that it should release any resources it's still holding on to. | |
810 virtual void MarkAllocatorIdle() {} | |
811 }; | |
812 | |
813 // Deleter for stream buffers. Copyable to support platforms where the deleter | |
814 // of a unique_ptr must be copyable. Otherwise it would be nice for this to be | |
815 // move-only. | |
816 class NET_EXPORT_PRIVATE StreamBufferDeleter { | |
817 public: | |
818 StreamBufferDeleter() : allocator_(nullptr) {} | |
819 explicit StreamBufferDeleter(QuicBufferAllocator* allocator) | |
820 : allocator_(allocator) {} | |
821 | |
822 // Deletes |buffer| using |allocator_|. | |
823 void operator()(char* buffer) const; | |
824 | |
825 private: | |
826 // Not owned; must be valid so long as the buffer stored in the unique_ptr | |
827 // that owns |this| is valid. | |
828 QuicBufferAllocator* allocator_; | |
829 }; | |
830 | |
831 using UniqueStreamBuffer = std::unique_ptr<char[], StreamBufferDeleter>; | |
832 | |
833 // Allocates memory of size |size| using |allocator| for a QUIC stream buffer. | |
834 NET_EXPORT_PRIVATE UniqueStreamBuffer | |
835 NewStreamBuffer(QuicBufferAllocator* allocator, size_t size); | |
836 | |
837 struct NET_EXPORT_PRIVATE QuicStreamFrame { | |
838 QuicStreamFrame(); | |
839 QuicStreamFrame(QuicStreamId stream_id, | |
840 bool fin, | |
841 QuicStreamOffset offset, | |
842 base::StringPiece data); | |
843 QuicStreamFrame(QuicStreamId stream_id, | |
844 bool fin, | |
845 QuicStreamOffset offset, | |
846 QuicPacketLength data_length, | |
847 UniqueStreamBuffer buffer); | |
848 ~QuicStreamFrame(); | |
849 | |
850 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, | |
851 const QuicStreamFrame& s); | |
852 | |
853 QuicStreamId stream_id; | |
854 bool fin; | |
855 QuicPacketLength data_length; | |
856 const char* data_buffer; | |
857 QuicStreamOffset offset; // Location of this data in the stream. | |
858 // nullptr when the QuicStreamFrame is received, and non-null when sent. | |
859 UniqueStreamBuffer buffer; | |
860 | |
861 private: | |
862 QuicStreamFrame(QuicStreamId stream_id, | |
863 bool fin, | |
864 QuicStreamOffset offset, | |
865 const char* data_buffer, | |
866 QuicPacketLength data_length, | |
867 UniqueStreamBuffer buffer); | |
868 | |
869 DISALLOW_COPY_AND_ASSIGN(QuicStreamFrame); | |
870 }; | |
871 static_assert(sizeof(QuicStreamFrame) <= 64, | |
872 "Keep the QuicStreamFrame size to a cacheline."); | |
873 | |
874 typedef std::vector<std::pair<QuicPacketNumber, QuicTime>> PacketTimeVector; | |
875 | |
876 struct NET_EXPORT_PRIVATE QuicStopWaitingFrame { | |
877 QuicStopWaitingFrame(); | |
878 ~QuicStopWaitingFrame(); | |
879 | |
880 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
881 std::ostream& os, | |
882 const QuicStopWaitingFrame& s); | |
883 // Path which this stop waiting frame belongs to. | |
884 QuicPathId path_id; | |
885 // Entropy hash of all packets up to, but not including, the least unacked | |
886 // packet. | |
887 QuicPacketEntropyHash entropy_hash; | |
888 // The lowest packet we've sent which is unacked, and we expect an ack for. | |
889 QuicPacketNumber least_unacked; | |
890 }; | |
891 | |
892 // A sequence of packet numbers where each number is unique. Intended to be used | |
893 // in a sliding window fashion, where smaller old packet numbers are removed and | |
894 // larger new packet numbers are added, with the occasional random access. | |
895 class NET_EXPORT_PRIVATE PacketNumberQueue { | |
896 public: | |
897 using const_interval_iterator = IntervalSet<QuicPacketNumber>::const_iterator; | |
898 using const_reverse_interval_iterator = | |
899 IntervalSet<QuicPacketNumber>::const_reverse_iterator; | |
900 // TODO(jdorfman): remove const_iterator and change the callers to iterate | |
901 // over the intervals. | |
902 class NET_EXPORT_PRIVATE const_iterator | |
903 : public std::iterator<std::input_iterator_tag, | |
904 QuicPacketNumber, | |
905 std::ptrdiff_t, | |
906 const QuicPacketNumber*, | |
907 const QuicPacketNumber&> { | |
908 public: | |
909 const_iterator( | |
910 IntervalSet<QuicPacketNumber>::const_iterator interval_set_iter, | |
911 QuicPacketNumber first, | |
912 QuicPacketNumber last); | |
913 const_iterator(const const_iterator& other); | |
914 const_iterator& operator=(const const_iterator& other); | |
915 // TODO(rtenneti): on windows RValue reference gives errors. | |
916 // const_iterator(const_iterator&& other); | |
917 ~const_iterator(); | |
918 | |
919 // TODO(rtenneti): on windows RValue reference gives errors. | |
920 // const_iterator& operator=(const_iterator&& other); | |
921 bool operator!=(const const_iterator& other) const; | |
922 bool operator==(const const_iterator& other) const; | |
923 value_type operator*() const; | |
924 const_iterator& operator++(); | |
925 const_iterator operator++(int /* postincrement */); | |
926 | |
927 private: | |
928 IntervalSet<QuicPacketNumber>::const_iterator interval_set_iter_; | |
929 QuicPacketNumber current_; | |
930 QuicPacketNumber last_; | |
931 }; | |
932 | |
933 PacketNumberQueue(); | |
934 PacketNumberQueue(const PacketNumberQueue& other); | |
935 // TODO(rtenneti): on windows RValue reference gives errors. | |
936 // PacketNumberQueue(PacketNumberQueue&& other); | |
937 ~PacketNumberQueue(); | |
938 | |
939 PacketNumberQueue& operator=(const PacketNumberQueue& other); | |
940 // PacketNumberQueue& operator=(PacketNumberQueue&& other); | |
941 | |
942 // Adds |packet_number| to the set of packets in the queue. | |
943 void Add(QuicPacketNumber packet_number); | |
944 | |
945 // Adds packets between [lower, higher) to the set of packets in the queue. It | |
946 // is undefined behavior to call this with |higher| < |lower|. | |
947 void Add(QuicPacketNumber lower, QuicPacketNumber higher); | |
948 | |
949 // Removes |packet_number| from the set of packets in the queue. | |
950 void Remove(QuicPacketNumber packet_number); | |
951 | |
952 // Removes packets numbers between [lower, higher) to the set of packets in | |
953 // the queue. It is undefined behavior to call this with |higher| < |lower|. | |
954 void Remove(QuicPacketNumber lower, QuicPacketNumber higher); | |
955 | |
956 // Removes packets with values less than |higher| from the set of packets in | |
957 // the queue. Returns true if packets were removed. | |
958 bool RemoveUpTo(QuicPacketNumber higher); | |
959 | |
960 // Mutates packet number set so that it contains only those packet numbers | |
961 // from minimum to maximum packet number not currently in the set. Do nothing | |
962 // if packet number set is empty. | |
963 void Complement(); | |
964 | |
965 // Returns true if the queue contains |packet_number|. | |
966 bool Contains(QuicPacketNumber packet_number) const; | |
967 | |
968 // Returns true if the queue is empty. | |
969 bool Empty() const; | |
970 | |
971 // Returns the minimum packet number stored in the queue. It is undefined | |
972 // behavior to call this if the queue is empty. | |
973 QuicPacketNumber Min() const; | |
974 | |
975 // Returns the maximum packet number stored in the queue. It is undefined | |
976 // behavior to call this if the queue is empty. | |
977 QuicPacketNumber Max() const; | |
978 | |
979 // Returns the number of unique packets stored in the queue. Inefficient; only | |
980 // exposed for testing. | |
981 size_t NumPacketsSlow() const; | |
982 | |
983 // Returns the number of disjoint packet number intervals contained in the | |
984 // queue. | |
985 size_t NumIntervals() const; | |
986 | |
987 // Returns the length of last interval. | |
988 QuicPacketNumber LastIntervalLength() const; | |
989 | |
990 // Returns iterators over the individual packet numbers. | |
991 const_iterator begin() const; | |
992 const_iterator end() const; | |
993 const_iterator lower_bound(QuicPacketNumber packet_number) const; | |
994 | |
995 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
996 std::ostream& os, | |
997 const PacketNumberQueue& q); | |
998 | |
999 // Returns iterators over the packet number intervals. | |
1000 const_interval_iterator begin_intervals() const; | |
1001 const_interval_iterator end_intervals() const; | |
1002 const_reverse_interval_iterator rbegin_intervals() const; | |
1003 const_reverse_interval_iterator rend_intervals() const; | |
1004 | |
1005 private: | |
1006 IntervalSet<QuicPacketNumber> packet_number_intervals_; | |
1007 }; | |
1008 | |
1009 struct NET_EXPORT_PRIVATE QuicAckFrame { | |
1010 QuicAckFrame(); | |
1011 QuicAckFrame(const QuicAckFrame& other); | |
1012 ~QuicAckFrame(); | |
1013 | |
1014 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, | |
1015 const QuicAckFrame& s); | |
1016 | |
1017 // The highest packet number we've observed from the peer. | |
1018 // | |
1019 // In general, this should be the largest packet number we've received. In | |
1020 // the case of truncated acks, we may have to advertise a lower "upper bound" | |
1021 // than largest received, to avoid implicitly acking missing packets that | |
1022 // don't fit in the missing packet list due to size limitations. In this | |
1023 // case, largest_observed may be a packet which is also in the missing packets | |
1024 // list. | |
1025 QuicPacketNumber largest_observed; | |
1026 | |
1027 // Time elapsed since largest_observed was received until this Ack frame was | |
1028 // sent. | |
1029 QuicTime::Delta ack_delay_time; | |
1030 | |
1031 // Vector of <packet_number, time> for when packets arrived. | |
1032 PacketTimeVector received_packet_times; | |
1033 | |
1034 // Set of packets. | |
1035 PacketNumberQueue packets; | |
1036 | |
1037 // Path which this ack belongs to. | |
1038 QuicPathId path_id; | |
1039 | |
1040 // Entropy hash of all packets up to largest observed not including missing | |
1041 // packets. | |
1042 QuicPacketEntropyHash entropy_hash; | |
1043 | |
1044 // Whether the ack had to be truncated when sent. | |
1045 bool is_truncated; | |
1046 | |
1047 // If true, |packets| express missing packets. Otherwise, |packets| express | |
1048 // received packets. | |
1049 bool missing; | |
1050 }; | |
1051 | |
1052 // True if the packet number is greater than largest_observed or is listed | |
1053 // as missing. | |
1054 // Always returns false for packet numbers less than least_unacked. | |
1055 bool NET_EXPORT_PRIVATE | |
1056 IsAwaitingPacket(const QuicAckFrame& ack_frame, | |
1057 QuicPacketNumber packet_number, | |
1058 QuicPacketNumber peer_least_packet_awaiting_ack); | |
1059 | |
1060 // Defines for all types of congestion control algorithms that can be used in | |
1061 // QUIC. Note that this is separate from the congestion feedback type - | |
1062 // some congestion control algorithms may use the same feedback type | |
1063 // (Reno and Cubic are the classic example for that). | |
1064 enum CongestionControlType { | |
1065 kCubic, | |
1066 kCubicBytes, | |
1067 kReno, | |
1068 kRenoBytes, | |
1069 kBBR, | |
1070 }; | |
1071 | |
1072 enum LossDetectionType { | |
1073 kNack, // Used to mimic TCP's loss detection. | |
1074 kTime, // Time based loss detection. | |
1075 kAdaptiveTime, // Adaptive time based loss detection. | |
1076 }; | |
1077 | |
1078 struct NET_EXPORT_PRIVATE QuicRstStreamFrame { | |
1079 QuicRstStreamFrame(); | |
1080 QuicRstStreamFrame(QuicStreamId stream_id, | |
1081 QuicRstStreamErrorCode error_code, | |
1082 QuicStreamOffset bytes_written); | |
1083 | |
1084 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
1085 std::ostream& os, | |
1086 const QuicRstStreamFrame& r); | |
1087 | |
1088 QuicStreamId stream_id; | |
1089 QuicRstStreamErrorCode error_code; | |
1090 | |
1091 // Used to update flow control windows. On termination of a stream, both | |
1092 // endpoints must inform the peer of the number of bytes they have sent on | |
1093 // that stream. This can be done through normal termination (data packet with | |
1094 // FIN) or through a RST. | |
1095 QuicStreamOffset byte_offset; | |
1096 }; | |
1097 | |
1098 struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame { | |
1099 QuicConnectionCloseFrame(); | |
1100 | |
1101 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
1102 std::ostream& os, | |
1103 const QuicConnectionCloseFrame& c); | |
1104 | |
1105 QuicErrorCode error_code; | |
1106 std::string error_details; | |
1107 }; | |
1108 | |
1109 struct NET_EXPORT_PRIVATE QuicGoAwayFrame { | |
1110 QuicGoAwayFrame(); | |
1111 QuicGoAwayFrame(QuicErrorCode error_code, | |
1112 QuicStreamId last_good_stream_id, | |
1113 const std::string& reason); | |
1114 | |
1115 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, | |
1116 const QuicGoAwayFrame& g); | |
1117 | |
1118 QuicErrorCode error_code; | |
1119 QuicStreamId last_good_stream_id; | |
1120 std::string reason_phrase; | |
1121 }; | |
1122 | |
1123 // Flow control updates per-stream and at the connection levoel. | |
1124 // Based on SPDY's WINDOW_UPDATE frame, but uses an absolute byte offset rather | |
1125 // than a window delta. | |
1126 // TODO(rjshade): A possible future optimization is to make stream_id and | |
1127 // byte_offset variable length, similar to stream frames. | |
1128 struct NET_EXPORT_PRIVATE QuicWindowUpdateFrame { | |
1129 QuicWindowUpdateFrame() {} | |
1130 QuicWindowUpdateFrame(QuicStreamId stream_id, QuicStreamOffset byte_offset); | |
1131 | |
1132 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
1133 std::ostream& os, | |
1134 const QuicWindowUpdateFrame& w); | |
1135 | |
1136 // The stream this frame applies to. 0 is a special case meaning the overall | |
1137 // connection rather than a specific stream. | |
1138 QuicStreamId stream_id; | |
1139 | |
1140 // Byte offset in the stream or connection. The receiver of this frame must | |
1141 // not send data which would result in this offset being exceeded. | |
1142 QuicStreamOffset byte_offset; | |
1143 }; | |
1144 | |
1145 // The BLOCKED frame is used to indicate to the remote endpoint that this | |
1146 // endpoint believes itself to be flow-control blocked but otherwise ready to | |
1147 // send data. The BLOCKED frame is purely advisory and optional. | |
1148 // Based on SPDY's BLOCKED frame (undocumented as of 2014-01-28). | |
1149 struct NET_EXPORT_PRIVATE QuicBlockedFrame { | |
1150 QuicBlockedFrame() {} | |
1151 explicit QuicBlockedFrame(QuicStreamId stream_id); | |
1152 | |
1153 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, | |
1154 const QuicBlockedFrame& b); | |
1155 | |
1156 // The stream this frame applies to. 0 is a special case meaning the overall | |
1157 // connection rather than a specific stream. | |
1158 QuicStreamId stream_id; | |
1159 }; | |
1160 | |
1161 // The PATH_CLOSE frame is used to explicitly close a path. Both endpoints can | |
1162 // send a PATH_CLOSE frame to initiate a path termination. A path is considered | |
1163 // to be closed either a PATH_CLOSE frame is sent or received. An endpoint drops | |
1164 // receive side of a closed path, and packets with retransmittable frames on a | |
1165 // closed path are marked as retransmissions which will be transmitted on other | |
1166 // paths. | |
1167 struct NET_EXPORT_PRIVATE QuicPathCloseFrame { | |
1168 QuicPathCloseFrame() {} | |
1169 explicit QuicPathCloseFrame(QuicPathId path_id); | |
1170 | |
1171 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
1172 std::ostream& os, | |
1173 const QuicPathCloseFrame& p); | |
1174 | |
1175 QuicPathId path_id; | |
1176 }; | |
1177 | |
1178 // EncryptionLevel enumerates the stages of encryption that a QUIC connection | |
1179 // progresses through. When retransmitting a packet, the encryption level needs | |
1180 // to be specified so that it is retransmitted at a level which the peer can | |
1181 // understand. | |
1182 enum EncryptionLevel : int8_t { | |
1183 ENCRYPTION_NONE = 0, | |
1184 ENCRYPTION_INITIAL = 1, | |
1185 ENCRYPTION_FORWARD_SECURE = 2, | |
1186 | |
1187 NUM_ENCRYPTION_LEVELS, | |
1188 }; | |
1189 | |
1190 enum PeerAddressChangeType { | |
1191 // IP address and port remain unchanged. | |
1192 NO_CHANGE, | |
1193 // Port changed, but IP address remains unchanged. | |
1194 PORT_CHANGE, | |
1195 // IPv4 address changed, but within the /24 subnet (port may have changed.) | |
1196 IPV4_SUBNET_CHANGE, | |
1197 // IP address change from an IPv4 to an IPv6 address (port may have changed.) | |
1198 IPV4_TO_IPV6_CHANGE, | |
1199 // IP address change from an IPv6 to an IPv4 address (port may have changed.) | |
1200 IPV6_TO_IPV4_CHANGE, | |
1201 // IP address change from an IPv6 to an IPv6 address (port may have changed.) | |
1202 IPV6_TO_IPV6_CHANGE, | |
1203 // All other peer address changes. | |
1204 UNSPECIFIED_CHANGE, | |
1205 }; | |
1206 | |
1207 struct NET_EXPORT_PRIVATE QuicFrame { | |
1208 QuicFrame(); | |
1209 explicit QuicFrame(QuicPaddingFrame padding_frame); | |
1210 explicit QuicFrame(QuicMtuDiscoveryFrame frame); | |
1211 explicit QuicFrame(QuicPingFrame frame); | |
1212 | |
1213 explicit QuicFrame(QuicStreamFrame* stream_frame); | |
1214 explicit QuicFrame(QuicAckFrame* frame); | |
1215 explicit QuicFrame(QuicRstStreamFrame* frame); | |
1216 explicit QuicFrame(QuicConnectionCloseFrame* frame); | |
1217 explicit QuicFrame(QuicStopWaitingFrame* frame); | |
1218 explicit QuicFrame(QuicGoAwayFrame* frame); | |
1219 explicit QuicFrame(QuicWindowUpdateFrame* frame); | |
1220 explicit QuicFrame(QuicBlockedFrame* frame); | |
1221 explicit QuicFrame(QuicPathCloseFrame* frame); | |
1222 | |
1223 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, | |
1224 const QuicFrame& frame); | |
1225 | |
1226 QuicFrameType type; | |
1227 union { | |
1228 // Frames smaller than a pointer are inline. | |
1229 QuicPaddingFrame padding_frame; | |
1230 QuicMtuDiscoveryFrame mtu_discovery_frame; | |
1231 QuicPingFrame ping_frame; | |
1232 | |
1233 // Frames larger than a pointer. | |
1234 QuicStreamFrame* stream_frame; | |
1235 QuicAckFrame* ack_frame; | |
1236 QuicStopWaitingFrame* stop_waiting_frame; | |
1237 QuicRstStreamFrame* rst_stream_frame; | |
1238 QuicConnectionCloseFrame* connection_close_frame; | |
1239 QuicGoAwayFrame* goaway_frame; | |
1240 QuicWindowUpdateFrame* window_update_frame; | |
1241 QuicBlockedFrame* blocked_frame; | |
1242 QuicPathCloseFrame* path_close_frame; | |
1243 }; | |
1244 }; | |
1245 // QuicFrameType consumes 8 bytes with padding. | |
1246 static_assert(sizeof(QuicFrame) <= 16, | |
1247 "Frames larger than 8 bytes should be referenced by pointer."); | |
1248 | |
1249 typedef std::vector<QuicFrame> QuicFrames; | |
1250 | |
1251 class NET_EXPORT_PRIVATE QuicData { | |
1252 public: | |
1253 QuicData(const char* buffer, size_t length); | |
1254 QuicData(char* buffer, size_t length, bool owns_buffer); | |
1255 virtual ~QuicData(); | |
1256 | |
1257 base::StringPiece AsStringPiece() const { | |
1258 return base::StringPiece(data(), length()); | |
1259 } | |
1260 | |
1261 const char* data() const { return buffer_; } | |
1262 size_t length() const { return length_; } | |
1263 bool owns_buffer() const { return owns_buffer_; } | |
1264 | |
1265 private: | |
1266 const char* buffer_; | |
1267 size_t length_; | |
1268 bool owns_buffer_; | |
1269 | |
1270 DISALLOW_COPY_AND_ASSIGN(QuicData); | |
1271 }; | |
1272 | |
1273 class NET_EXPORT_PRIVATE QuicPacket : public QuicData { | |
1274 public: | |
1275 // TODO(fayang): 4 fields from public header are passed in as arguments. | |
1276 // Consider to add a convenience method which directly accepts the entire | |
1277 // public header. | |
1278 QuicPacket(char* buffer, | |
1279 size_t length, | |
1280 bool owns_buffer, | |
1281 QuicConnectionIdLength connection_id_length, | |
1282 bool includes_version, | |
1283 bool includes_path_id, | |
1284 bool includes_diversification_nonce, | |
1285 QuicPacketNumberLength packet_number_length); | |
1286 | |
1287 base::StringPiece AssociatedData(QuicVersion version) const; | |
1288 base::StringPiece Plaintext(QuicVersion version) const; | |
1289 | |
1290 char* mutable_data() { return buffer_; } | |
1291 | |
1292 private: | |
1293 char* buffer_; | |
1294 const QuicConnectionIdLength connection_id_length_; | |
1295 const bool includes_version_; | |
1296 const bool includes_path_id_; | |
1297 const bool includes_diversification_nonce_; | |
1298 const QuicPacketNumberLength packet_number_length_; | |
1299 | |
1300 DISALLOW_COPY_AND_ASSIGN(QuicPacket); | |
1301 }; | |
1302 | |
1303 class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData { | |
1304 public: | |
1305 QuicEncryptedPacket(const char* buffer, size_t length); | |
1306 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer); | |
1307 | |
1308 // Clones the packet into a new packet which owns the buffer. | |
1309 QuicEncryptedPacket* Clone() const; | |
1310 | |
1311 // By default, gtest prints the raw bytes of an object. The bool data | |
1312 // member (in the base class QuicData) causes this object to have padding | |
1313 // bytes, which causes the default gtest object printer to read | |
1314 // uninitialize memory. So we need to teach gtest how to print this object. | |
1315 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
1316 std::ostream& os, | |
1317 const QuicEncryptedPacket& s); | |
1318 | |
1319 private: | |
1320 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket); | |
1321 }; | |
1322 | |
1323 // A received encrypted QUIC packet, with a recorded time of receipt. | |
1324 class NET_EXPORT_PRIVATE QuicReceivedPacket : public QuicEncryptedPacket { | |
1325 public: | |
1326 QuicReceivedPacket(const char* buffer, size_t length, QuicTime receipt_time); | |
1327 QuicReceivedPacket(char* buffer, | |
1328 size_t length, | |
1329 QuicTime receipt_time, | |
1330 bool owns_buffer); | |
1331 | |
1332 // Clones the packet into a new packet which owns the buffer. | |
1333 QuicReceivedPacket* Clone() const; | |
1334 | |
1335 // Returns the time at which the packet was received. | |
1336 QuicTime receipt_time() const { return receipt_time_; } | |
1337 | |
1338 // By default, gtest prints the raw bytes of an object. The bool data | |
1339 // member (in the base class QuicData) causes this object to have padding | |
1340 // bytes, which causes the default gtest object printer to read | |
1341 // uninitialize memory. So we need to teach gtest how to print this object. | |
1342 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
1343 std::ostream& os, | |
1344 const QuicReceivedPacket& s); | |
1345 | |
1346 private: | |
1347 const QuicTime receipt_time_; | |
1348 | |
1349 DISALLOW_COPY_AND_ASSIGN(QuicReceivedPacket); | |
1350 }; | |
1351 | |
1352 // Pure virtual class to listen for packet acknowledgements. | |
1353 class NET_EXPORT_PRIVATE QuicAckListenerInterface | |
1354 : public base::RefCounted<QuicAckListenerInterface> { | |
1355 public: | |
1356 QuicAckListenerInterface() {} | |
1357 | |
1358 // Called when a packet is acked. Called once per packet. | |
1359 // |acked_bytes| is the number of data bytes acked. | |
1360 virtual void OnPacketAcked(int acked_bytes, | |
1361 QuicTime::Delta ack_delay_time) = 0; | |
1362 | |
1363 // Called when a packet is retransmitted. Called once per packet. | |
1364 // |retransmitted_bytes| is the number of data bytes retransmitted. | |
1365 virtual void OnPacketRetransmitted(int retransmitted_bytes) = 0; | |
1366 | |
1367 protected: | |
1368 friend class base::RefCounted<QuicAckListenerInterface>; | |
1369 | |
1370 // Delegates are ref counted. | |
1371 virtual ~QuicAckListenerInterface() {} | |
1372 }; | |
1373 | |
1374 // Pure virtual class to close connection on unrecoverable errors. | |
1375 class NET_EXPORT_PRIVATE QuicConnectionCloseDelegateInterface { | |
1376 public: | |
1377 virtual ~QuicConnectionCloseDelegateInterface() {} | |
1378 | |
1379 // Called when an unrecoverable error is encountered. | |
1380 virtual void OnUnrecoverableError(QuicErrorCode error, | |
1381 const std::string& error_details, | |
1382 ConnectionCloseSource source) = 0; | |
1383 }; | |
1384 | |
1385 struct NET_EXPORT_PRIVATE AckListenerWrapper { | |
1386 AckListenerWrapper(QuicAckListenerInterface* listener, | |
1387 QuicPacketLength data_length); | |
1388 AckListenerWrapper(const AckListenerWrapper& other); | |
1389 ~AckListenerWrapper(); | |
1390 | |
1391 scoped_refptr<QuicAckListenerInterface> ack_listener; | |
1392 QuicPacketLength length; | |
1393 }; | |
1394 | |
1395 struct NET_EXPORT_PRIVATE SerializedPacket { | |
1396 SerializedPacket(QuicPathId path_id, | |
1397 QuicPacketNumber packet_number, | |
1398 QuicPacketNumberLength packet_number_length, | |
1399 const char* encrypted_buffer, | |
1400 QuicPacketLength encrypted_length, | |
1401 QuicPacketEntropyHash entropy_hash, | |
1402 bool has_ack, | |
1403 bool has_stop_waiting); | |
1404 SerializedPacket(const SerializedPacket& other); | |
1405 ~SerializedPacket(); | |
1406 | |
1407 // Not owned. | |
1408 const char* encrypted_buffer; | |
1409 QuicPacketLength encrypted_length; | |
1410 QuicFrames retransmittable_frames; | |
1411 IsHandshake has_crypto_handshake; | |
1412 // -1: full padding to the end of a max-sized packet | |
1413 // 0: no padding | |
1414 // otherwise: only pad up to num_padding_bytes bytes | |
1415 int16_t num_padding_bytes; | |
1416 QuicPathId path_id; | |
1417 QuicPacketNumber packet_number; | |
1418 QuicPacketNumberLength packet_number_length; | |
1419 EncryptionLevel encryption_level; | |
1420 QuicPacketEntropyHash entropy_hash; | |
1421 bool has_ack; | |
1422 bool has_stop_waiting; | |
1423 TransmissionType transmission_type; | |
1424 QuicPathId original_path_id; | |
1425 QuicPacketNumber original_packet_number; | |
1426 | |
1427 // Optional notifiers which will be informed when this packet has been ACKed. | |
1428 std::list<AckListenerWrapper> listeners; | |
1429 }; | |
1430 | |
1431 struct NET_EXPORT_PRIVATE TransmissionInfo { | |
1432 // Used by STL when assigning into a map. | |
1433 TransmissionInfo(); | |
1434 | |
1435 // Constructs a Transmission with a new all_transmissions set | |
1436 // containing |packet_number|. | |
1437 TransmissionInfo(EncryptionLevel level, | |
1438 QuicPacketNumberLength packet_number_length, | |
1439 TransmissionType transmission_type, | |
1440 QuicTime sent_time, | |
1441 QuicPacketLength bytes_sent, | |
1442 bool has_crypto_handshake, | |
1443 int num_padding_bytes); | |
1444 | |
1445 TransmissionInfo(const TransmissionInfo& other); | |
1446 | |
1447 ~TransmissionInfo(); | |
1448 | |
1449 QuicFrames retransmittable_frames; | |
1450 EncryptionLevel encryption_level; | |
1451 QuicPacketNumberLength packet_number_length; | |
1452 QuicPacketLength bytes_sent; | |
1453 QuicTime sent_time; | |
1454 // Reason why this packet was transmitted. | |
1455 TransmissionType transmission_type; | |
1456 // In flight packets have not been abandoned or lost. | |
1457 bool in_flight; | |
1458 // True if the packet can never be acked, so it can be removed. Occurs when | |
1459 // a packet is never sent, after it is acknowledged once, or if it's a crypto | |
1460 // packet we never expect to receive an ack for. | |
1461 bool is_unackable; | |
1462 // True if the packet contains stream data from the crypto stream. | |
1463 bool has_crypto_handshake; | |
1464 // Non-zero if the packet needs padding if it's retransmitted. | |
1465 int16_t num_padding_bytes; | |
1466 // Stores the packet number of the next retransmission of this packet. | |
1467 // Zero if the packet has not been retransmitted. | |
1468 QuicPacketNumber retransmission; | |
1469 // Non-empty if there is a listener for this packet. | |
1470 std::list<AckListenerWrapper> ack_listeners; | |
1471 }; | |
1472 | |
1473 // Struct to store the pending retransmission information. | |
1474 struct PendingRetransmission { | |
1475 PendingRetransmission(QuicPathId path_id, | |
1476 QuicPacketNumber packet_number, | |
1477 TransmissionType transmission_type, | |
1478 const QuicFrames& retransmittable_frames, | |
1479 bool has_crypto_handshake, | |
1480 int num_padding_bytes, | |
1481 EncryptionLevel encryption_level, | |
1482 QuicPacketNumberLength packet_number_length) | |
1483 : packet_number(packet_number), | |
1484 retransmittable_frames(retransmittable_frames), | |
1485 transmission_type(transmission_type), | |
1486 path_id(path_id), | |
1487 has_crypto_handshake(has_crypto_handshake), | |
1488 num_padding_bytes(num_padding_bytes), | |
1489 encryption_level(encryption_level), | |
1490 packet_number_length(packet_number_length) {} | |
1491 | |
1492 QuicPacketNumber packet_number; | |
1493 const QuicFrames& retransmittable_frames; | |
1494 TransmissionType transmission_type; | |
1495 QuicPathId path_id; | |
1496 bool has_crypto_handshake; | |
1497 int num_padding_bytes; | |
1498 EncryptionLevel encryption_level; | |
1499 QuicPacketNumberLength packet_number_length; | |
1500 }; | |
1501 | |
1502 // Convenience wrapper to wrap an iovec array and the total length, which must | |
1503 // be less than or equal to the actual total length of the iovecs. | |
1504 struct NET_EXPORT_PRIVATE QuicIOVector { | |
1505 QuicIOVector(const struct iovec* iov, int iov_count, size_t total_length) | |
1506 : iov(iov), iov_count(iov_count), total_length(total_length) {} | |
1507 | |
1508 const struct iovec* iov; | |
1509 const int iov_count; | |
1510 const size_t total_length; | |
1511 }; | |
1512 | |
1513 } // namespace net | |
1514 | |
1515 #endif // NET_QUIC_QUIC_PROTOCOL_H_ | |
OLD | NEW |