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 <limits> | |
10 #include <list> | |
11 #include <map> | |
12 #include <ostream> | |
13 #include <set> | |
14 #include <string> | |
15 #include <utility> | |
16 #include <vector> | |
17 | |
18 #include "base/basictypes.h" | |
19 #include "base/containers/hash_tables.h" | |
20 #include "base/logging.h" | |
21 #include "base/strings/string_piece.h" | |
22 #include "net/base/int128.h" | |
23 #include "net/base/ip_endpoint.h" | |
24 #include "net/base/net_export.h" | |
25 #include "net/quic/iovector.h" | |
26 #include "net/quic/quic_bandwidth.h" | |
27 #include "net/quic/quic_time.h" | |
28 | |
29 namespace net { | |
30 | |
31 class QuicAckNotifier; | |
32 class QuicPacket; | |
33 struct QuicPacketHeader; | |
34 | |
35 typedef uint64 QuicConnectionId; | |
36 typedef uint32 QuicStreamId; | |
37 typedef uint64 QuicStreamOffset; | |
38 typedef uint64 QuicPacketSequenceNumber; | |
39 typedef QuicPacketSequenceNumber QuicFecGroupNumber; | |
40 typedef uint64 QuicPublicResetNonceProof; | |
41 typedef uint8 QuicPacketEntropyHash; | |
42 typedef uint32 QuicHeaderId; | |
43 // QuicTag is the type of a tag in the wire protocol. | |
44 typedef uint32 QuicTag; | |
45 typedef std::vector<QuicTag> QuicTagVector; | |
46 typedef std::map<QuicTag, std::string> QuicTagValueMap; | |
47 // TODO(rtenneti): Didn't use SpdyPriority because SpdyPriority is uint8 and | |
48 // QuicPriority is uint32. Use SpdyPriority when we change the QUIC_VERSION. | |
49 typedef uint32 QuicPriority; | |
50 | |
51 // Default and initial maximum size in bytes of a QUIC packet. | |
52 const QuicByteCount kDefaultMaxPacketSize = 1350; | |
53 // Default initial maximum size in bytes of a QUIC packet for servers. | |
54 const QuicByteCount kDefaultServerMaxPacketSize = 1000; | |
55 // The maximum packet size of any QUIC packet, based on ethernet's max size, | |
56 // minus the IP and UDP headers. IPv6 has a 40 byte header, UPD adds an | |
57 // additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's | |
58 // max packet size is 1500 bytes, 1500 - 48 = 1452. | |
59 const QuicByteCount kMaxPacketSize = 1452; | |
60 // Default maximum packet size used in Linux TCP implementations. | |
61 const QuicByteCount kDefaultTCPMSS = 1460; | |
62 | |
63 // We match SPDY's use of 32 when secure (since we'd compete with SPDY). | |
64 const QuicPacketCount kInitialCongestionWindowSecure = 32; | |
65 // Be conservative, and just use double a typical TCP ICWND for HTTP. | |
66 const QuicPacketCount kInitialCongestionWindowInsecure = 20; | |
67 | |
68 // Minimum size of initial flow control window, for both stream and session. | |
69 const uint32 kMinimumFlowControlSendWindow = 16 * 1024; // 16 KB | |
70 | |
71 // Minimum size of the CWND, in packets, when doing bandwidth resumption. | |
72 const QuicPacketCount kMinCongestionWindowForBandwidthResumption = 10; | |
73 | |
74 // Maximum size of the CWND, in packets, for TCP congestion control algorithms. | |
75 const QuicPacketCount kMaxTcpCongestionWindow = 200; | |
76 | |
77 // Default size of the socket receive buffer in bytes. | |
78 const QuicByteCount kDefaultSocketReceiveBuffer = 256 * 1024; | |
79 // Minimum size of the socket receive buffer in bytes. | |
80 // Smaller values are ignored. | |
81 const QuicByteCount kMinSocketReceiveBuffer = 16 * 1024; | |
82 | |
83 // Don't allow a client to suggest an RTT shorter than 10ms. | |
84 const uint32 kMinInitialRoundTripTimeUs = 10 * kNumMicrosPerMilli; | |
85 | |
86 // Don't allow a client to suggest an RTT longer than 15 seconds. | |
87 const uint32 kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond; | |
88 | |
89 // Maximum number of open streams per connection. | |
90 const size_t kDefaultMaxStreamsPerConnection = 100; | |
91 | |
92 // Number of bytes reserved for public flags in the packet header. | |
93 const size_t kPublicFlagsSize = 1; | |
94 // Number of bytes reserved for version number in the packet header. | |
95 const size_t kQuicVersionSize = 4; | |
96 // Number of bytes reserved for private flags in the packet header. | |
97 const size_t kPrivateFlagsSize = 1; | |
98 // Number of bytes reserved for FEC group in the packet header. | |
99 const size_t kFecGroupSize = 1; | |
100 | |
101 // Signifies that the QuicPacket will contain version of the protocol. | |
102 const bool kIncludeVersion = true; | |
103 | |
104 // Index of the first byte in a QUIC packet which is used in hash calculation. | |
105 const size_t kStartOfHashData = 0; | |
106 | |
107 // Limit on the delta between stream IDs. | |
108 const QuicStreamId kMaxStreamIdDelta = 200; | |
109 // Limit on the delta between header IDs. | |
110 const QuicHeaderId kMaxHeaderIdDelta = 200; | |
111 | |
112 // Reserved ID for the crypto stream. | |
113 const QuicStreamId kCryptoStreamId = 1; | |
114 | |
115 // Reserved ID for the headers stream. | |
116 const QuicStreamId kHeadersStreamId = 3; | |
117 | |
118 // Maximum delayed ack time, in ms. | |
119 const int64 kMaxDelayedAckTimeMs = 25; | |
120 | |
121 // The timeout before the handshake succeeds. | |
122 const int64 kInitialIdleTimeoutSecs = 5; | |
123 // The default idle timeout. | |
124 const int64 kDefaultIdleTimeoutSecs = 30; | |
125 // The maximum idle timeout that can be negotiated. | |
126 const int64 kMaximumIdleTimeoutSecs = 60 * 10; // 10 minutes. | |
127 // The default timeout for a connection until the crypto handshake succeeds. | |
128 const int64 kMaxTimeForCryptoHandshakeSecs = 10; // 10 secs. | |
129 | |
130 // Default limit on the number of undecryptable packets the connection buffers | |
131 // before the CHLO/SHLO arrive. | |
132 const size_t kDefaultMaxUndecryptablePackets = 10; | |
133 | |
134 // Default ping timeout. | |
135 const int64 kPingTimeoutSecs = 15; // 15 secs. | |
136 | |
137 // Minimum number of RTTs between Server Config Updates (SCUP) sent to client. | |
138 const int kMinIntervalBetweenServerConfigUpdatesRTTs = 10; | |
139 | |
140 // Minimum time between Server Config Updates (SCUP) sent to client. | |
141 const int kMinIntervalBetweenServerConfigUpdatesMs = 1000; | |
142 | |
143 // Minimum number of packets between Server Config Updates (SCUP). | |
144 const int kMinPacketsBetweenServerConfigUpdates = 100; | |
145 | |
146 // The number of open streams that a server will accept is set to be slightly | |
147 // larger than the negotiated limit. Immediately closing the connection if the | |
148 // client opens slightly too many streams is not ideal: the client may have sent | |
149 // a FIN that was lost, and simultaneously opened a new stream. The number of | |
150 // streams a server accepts is a fixed increment over the negotiated limit, or a | |
151 // percentage increase, whichever is larger. | |
152 const float kMaxStreamsMultiplier = 1.1f; | |
153 const int kMaxStreamsMinimumIncrement = 10; | |
154 | |
155 // We define an unsigned 16-bit floating point value, inspired by IEEE floats | |
156 // (http://en.wikipedia.org/wiki/Half_precision_floating-point_format), | |
157 // with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden | |
158 // bit) and denormals, but without signs, transfinites or fractions. Wire format | |
159 // 16 bits (little-endian byte order) are split into exponent (high 5) and | |
160 // mantissa (low 11) and decoded as: | |
161 // uint64 value; | |
162 // if (exponent == 0) value = mantissa; | |
163 // else value = (mantissa | 1 << 11) << (exponent - 1) | |
164 const int kUFloat16ExponentBits = 5; | |
165 const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30 | |
166 const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11 | |
167 const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12 | |
168 const uint64 kUFloat16MaxValue = // 0x3FFC0000000 | |
169 ((GG_UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1) << | |
170 kUFloat16MaxExponent; | |
171 | |
172 enum TransmissionType { | |
173 NOT_RETRANSMISSION, | |
174 FIRST_TRANSMISSION_TYPE = NOT_RETRANSMISSION, | |
175 HANDSHAKE_RETRANSMISSION, // Retransmits due to handshake timeouts. | |
176 ALL_UNACKED_RETRANSMISSION, // Retransmits all unacked packets. | |
177 ALL_INITIAL_RETRANSMISSION, // Retransmits all initially encrypted packets. | |
178 LOSS_RETRANSMISSION, // Retransmits due to loss detection. | |
179 RTO_RETRANSMISSION, // Retransmits due to retransmit time out. | |
180 TLP_RETRANSMISSION, // Tail loss probes. | |
181 LAST_TRANSMISSION_TYPE = TLP_RETRANSMISSION, | |
182 }; | |
183 | |
184 enum HasRetransmittableData { | |
185 NO_RETRANSMITTABLE_DATA, | |
186 HAS_RETRANSMITTABLE_DATA, | |
187 }; | |
188 | |
189 enum IsHandshake { | |
190 NOT_HANDSHAKE, | |
191 IS_HANDSHAKE | |
192 }; | |
193 | |
194 // Indicates FEC protection level for data being written. | |
195 enum FecProtection { | |
196 MUST_FEC_PROTECT, // Callee must FEC protect this data. | |
197 MAY_FEC_PROTECT // Callee does not have to but may FEC protect this data. | |
198 }; | |
199 | |
200 // Indicates FEC policy. | |
201 enum FecPolicy { | |
202 FEC_PROTECT_ALWAYS, // All data in the stream should be FEC protected. | |
203 FEC_PROTECT_OPTIONAL // Data in the stream does not need FEC protection. | |
204 }; | |
205 | |
206 enum QuicFrameType { | |
207 // Regular frame types. The values set here cannot change without the | |
208 // introduction of a new QUIC version. | |
209 PADDING_FRAME = 0, | |
210 RST_STREAM_FRAME = 1, | |
211 CONNECTION_CLOSE_FRAME = 2, | |
212 GOAWAY_FRAME = 3, | |
213 WINDOW_UPDATE_FRAME = 4, | |
214 BLOCKED_FRAME = 5, | |
215 STOP_WAITING_FRAME = 6, | |
216 PING_FRAME = 7, | |
217 | |
218 // STREAM and ACK frames are special frames. They are encoded differently on | |
219 // the wire and their values do not need to be stable. | |
220 STREAM_FRAME, | |
221 ACK_FRAME, | |
222 NUM_FRAME_TYPES | |
223 }; | |
224 | |
225 enum QuicConnectionIdLength { | |
226 PACKET_0BYTE_CONNECTION_ID = 0, | |
227 PACKET_1BYTE_CONNECTION_ID = 1, | |
228 PACKET_4BYTE_CONNECTION_ID = 4, | |
229 PACKET_8BYTE_CONNECTION_ID = 8 | |
230 }; | |
231 | |
232 enum InFecGroup { | |
233 NOT_IN_FEC_GROUP, | |
234 IN_FEC_GROUP, | |
235 }; | |
236 | |
237 enum QuicSequenceNumberLength { | |
238 PACKET_1BYTE_SEQUENCE_NUMBER = 1, | |
239 PACKET_2BYTE_SEQUENCE_NUMBER = 2, | |
240 PACKET_4BYTE_SEQUENCE_NUMBER = 4, | |
241 PACKET_6BYTE_SEQUENCE_NUMBER = 6 | |
242 }; | |
243 | |
244 // Used to indicate a QuicSequenceNumberLength using two flag bits. | |
245 enum QuicSequenceNumberLengthFlags { | |
246 PACKET_FLAGS_1BYTE_SEQUENCE = 0, // 00 | |
247 PACKET_FLAGS_2BYTE_SEQUENCE = 1, // 01 | |
248 PACKET_FLAGS_4BYTE_SEQUENCE = 1 << 1, // 10 | |
249 PACKET_FLAGS_6BYTE_SEQUENCE = 1 << 1 | 1, // 11 | |
250 }; | |
251 | |
252 // The public flags are specified in one byte. | |
253 enum QuicPacketPublicFlags { | |
254 PACKET_PUBLIC_FLAGS_NONE = 0, | |
255 | |
256 // Bit 0: Does the packet header contains version info? | |
257 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0, | |
258 | |
259 // Bit 1: Is this packet a public reset packet? | |
260 PACKET_PUBLIC_FLAGS_RST = 1 << 1, | |
261 | |
262 // Bits 2 and 3 specify the length of the ConnectionId as follows: | |
263 // ----00--: 0 bytes | |
264 // ----01--: 1 byte | |
265 // ----10--: 4 bytes | |
266 // ----11--: 8 bytes | |
267 PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID = 0, | |
268 PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID = 1 << 2, | |
269 PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID = 1 << 3, | |
270 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID = 1 << 3 | 1 << 2, | |
271 | |
272 // Bits 4 and 5 describe the packet sequence number length as follows: | |
273 // --00----: 1 byte | |
274 // --01----: 2 bytes | |
275 // --10----: 4 bytes | |
276 // --11----: 6 bytes | |
277 PACKET_PUBLIC_FLAGS_1BYTE_SEQUENCE = PACKET_FLAGS_1BYTE_SEQUENCE << 4, | |
278 PACKET_PUBLIC_FLAGS_2BYTE_SEQUENCE = PACKET_FLAGS_2BYTE_SEQUENCE << 4, | |
279 PACKET_PUBLIC_FLAGS_4BYTE_SEQUENCE = PACKET_FLAGS_4BYTE_SEQUENCE << 4, | |
280 PACKET_PUBLIC_FLAGS_6BYTE_SEQUENCE = PACKET_FLAGS_6BYTE_SEQUENCE << 4, | |
281 | |
282 // All bits set (bits 6 and 7 are not currently used): 00111111 | |
283 PACKET_PUBLIC_FLAGS_MAX = (1 << 6) - 1 | |
284 }; | |
285 | |
286 // The private flags are specified in one byte. | |
287 enum QuicPacketPrivateFlags { | |
288 PACKET_PRIVATE_FLAGS_NONE = 0, | |
289 | |
290 // Bit 0: Does this packet contain an entropy bit? | |
291 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0, | |
292 | |
293 // Bit 1: Payload is part of an FEC group? | |
294 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1, | |
295 | |
296 // Bit 2: Payload is FEC as opposed to frames? | |
297 PACKET_PRIVATE_FLAGS_FEC = 1 << 2, | |
298 | |
299 // All bits set (bits 3-7 are not currently used): 00000111 | |
300 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1 | |
301 }; | |
302 | |
303 // The available versions of QUIC. Guaranteed that the integer value of the enum | |
304 // will match the version number. | |
305 // When adding a new version to this enum you should add it to | |
306 // kSupportedQuicVersions (if appropriate), and also add a new case to the | |
307 // helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and | |
308 // QuicVersionToString. | |
309 enum QuicVersion { | |
310 // Special case to indicate unknown/unsupported QUIC version. | |
311 QUIC_VERSION_UNSUPPORTED = 0, | |
312 | |
313 QUIC_VERSION_23 = 23, // Timestamp in the ack frame. | |
314 QUIC_VERSION_24 = 24, // SPDY/4 header compression. | |
315 }; | |
316 | |
317 // This vector contains QUIC versions which we currently support. | |
318 // This should be ordered such that the highest supported version is the first | |
319 // element, with subsequent elements in descending order (versions can be | |
320 // skipped as necessary). | |
321 // | |
322 // IMPORTANT: if you are adding to this list, follow the instructions at | |
323 // http://sites/quic/adding-and-removing-versions | |
324 static const QuicVersion kSupportedQuicVersions[] = {QUIC_VERSION_24, | |
325 QUIC_VERSION_23}; | |
326 | |
327 typedef std::vector<QuicVersion> QuicVersionVector; | |
328 | |
329 // Returns a vector of QUIC versions in kSupportedQuicVersions. | |
330 NET_EXPORT_PRIVATE QuicVersionVector QuicSupportedVersions(); | |
331 | |
332 // QuicTag is written to and read from the wire, but we prefer to use | |
333 // the more readable QuicVersion at other levels. | |
334 // Helper function which translates from a QuicVersion to a QuicTag. Returns 0 | |
335 // if QuicVersion is unsupported. | |
336 NET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version); | |
337 | |
338 // Returns appropriate QuicVersion from a QuicTag. | |
339 // Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood. | |
340 NET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag); | |
341 | |
342 // Helper function which translates from a QuicVersion to a string. | |
343 // Returns strings corresponding to enum names (e.g. QUIC_VERSION_6). | |
344 NET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version); | |
345 | |
346 // Returns comma separated list of string representations of QuicVersion enum | |
347 // values in the supplied |versions| vector. | |
348 NET_EXPORT_PRIVATE std::string QuicVersionVectorToString( | |
349 const QuicVersionVector& versions); | |
350 | |
351 // Version and Crypto tags are written to the wire with a big-endian | |
352 // representation of the name of the tag. For example | |
353 // the client hello tag (CHLO) will be written as the | |
354 // following 4 bytes: 'C' 'H' 'L' 'O'. Since it is | |
355 // stored in memory as a little endian uint32, we need | |
356 // to reverse the order of the bytes. | |
357 | |
358 // MakeQuicTag returns a value given the four bytes. For example: | |
359 // MakeQuicTag('C', 'H', 'L', 'O'); | |
360 NET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d); | |
361 | |
362 // Returns true if the tag vector contains the specified tag. | |
363 NET_EXPORT_PRIVATE bool ContainsQuicTag(const QuicTagVector& tag_vector, | |
364 QuicTag tag); | |
365 | |
366 // Size in bytes of the data or fec packet header. | |
367 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(const QuicPacketHeader& header); | |
368 | |
369 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize( | |
370 QuicConnectionIdLength connection_id_length, | |
371 bool include_version, | |
372 QuicSequenceNumberLength sequence_number_length, | |
373 InFecGroup is_in_fec_group); | |
374 | |
375 // Index of the first byte in a QUIC packet of FEC protected data. | |
376 NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData( | |
377 QuicConnectionIdLength connection_id_length, | |
378 bool include_version, | |
379 QuicSequenceNumberLength sequence_number_length); | |
380 // Index of the first byte in a QUIC packet of encrypted data. | |
381 NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData( | |
382 QuicConnectionIdLength connection_id_length, | |
383 bool include_version, | |
384 QuicSequenceNumberLength sequence_number_length); | |
385 | |
386 enum QuicRstStreamErrorCode { | |
387 QUIC_STREAM_NO_ERROR = 0, | |
388 | |
389 // There was some error which halted stream processing. | |
390 QUIC_ERROR_PROCESSING_STREAM, | |
391 // We got two fin or reset offsets which did not match. | |
392 QUIC_MULTIPLE_TERMINATION_OFFSETS, | |
393 // We got bad payload and can not respond to it at the protocol level. | |
394 QUIC_BAD_APPLICATION_PAYLOAD, | |
395 // Stream closed due to connection error. No reset frame is sent when this | |
396 // happens. | |
397 QUIC_STREAM_CONNECTION_ERROR, | |
398 // GoAway frame sent. No more stream can be created. | |
399 QUIC_STREAM_PEER_GOING_AWAY, | |
400 // The stream has been cancelled. | |
401 QUIC_STREAM_CANCELLED, | |
402 // Closing stream locally, sending a RST to allow for proper flow control | |
403 // accounting. Sent in response to a RST from the peer. | |
404 QUIC_RST_ACKNOWLEDGEMENT, | |
405 | |
406 // No error. Used as bound while iterating. | |
407 QUIC_STREAM_LAST_ERROR, | |
408 }; | |
409 | |
410 // Because receiving an unknown QuicRstStreamErrorCode results in connection | |
411 // teardown, we use this to make sure any errors predating a given version are | |
412 // downgraded to the most appropriate existing error. | |
413 NET_EXPORT_PRIVATE QuicRstStreamErrorCode AdjustErrorForVersion( | |
414 QuicRstStreamErrorCode error_code, | |
415 QuicVersion version); | |
416 | |
417 // These values must remain stable as they are uploaded to UMA histograms. | |
418 // To add a new error code, use the current value of QUIC_LAST_ERROR and | |
419 // increment QUIC_LAST_ERROR. | |
420 enum QuicErrorCode { | |
421 QUIC_NO_ERROR = 0, | |
422 | |
423 // Connection has reached an invalid state. | |
424 QUIC_INTERNAL_ERROR = 1, | |
425 // There were data frames after the a fin or reset. | |
426 QUIC_STREAM_DATA_AFTER_TERMINATION = 2, | |
427 // Control frame is malformed. | |
428 QUIC_INVALID_PACKET_HEADER = 3, | |
429 // Frame data is malformed. | |
430 QUIC_INVALID_FRAME_DATA = 4, | |
431 // The packet contained no payload. | |
432 QUIC_MISSING_PAYLOAD = 48, | |
433 // FEC data is malformed. | |
434 QUIC_INVALID_FEC_DATA = 5, | |
435 // STREAM frame data is malformed. | |
436 QUIC_INVALID_STREAM_DATA = 46, | |
437 // STREAM frame data is not encrypted. | |
438 QUIC_UNENCRYPTED_STREAM_DATA = 61, | |
439 // RST_STREAM frame data is malformed. | |
440 QUIC_INVALID_RST_STREAM_DATA = 6, | |
441 // CONNECTION_CLOSE frame data is malformed. | |
442 QUIC_INVALID_CONNECTION_CLOSE_DATA = 7, | |
443 // GOAWAY frame data is malformed. | |
444 QUIC_INVALID_GOAWAY_DATA = 8, | |
445 // WINDOW_UPDATE frame data is malformed. | |
446 QUIC_INVALID_WINDOW_UPDATE_DATA = 57, | |
447 // BLOCKED frame data is malformed. | |
448 QUIC_INVALID_BLOCKED_DATA = 58, | |
449 // STOP_WAITING frame data is malformed. | |
450 QUIC_INVALID_STOP_WAITING_DATA = 60, | |
451 // ACK frame data is malformed. | |
452 QUIC_INVALID_ACK_DATA = 9, | |
453 | |
454 // deprecated: QUIC_INVALID_CONGESTION_FEEDBACK_DATA = 47, | |
455 | |
456 // Version negotiation packet is malformed. | |
457 QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10, | |
458 // Public RST packet is malformed. | |
459 QUIC_INVALID_PUBLIC_RST_PACKET = 11, | |
460 // There was an error decrypting. | |
461 QUIC_DECRYPTION_FAILURE = 12, | |
462 // There was an error encrypting. | |
463 QUIC_ENCRYPTION_FAILURE = 13, | |
464 // The packet exceeded kMaxPacketSize. | |
465 QUIC_PACKET_TOO_LARGE = 14, | |
466 // Data was sent for a stream which did not exist. | |
467 QUIC_PACKET_FOR_NONEXISTENT_STREAM = 15, | |
468 // The peer is going away. May be a client or server. | |
469 QUIC_PEER_GOING_AWAY = 16, | |
470 // A stream ID was invalid. | |
471 QUIC_INVALID_STREAM_ID = 17, | |
472 // A priority was invalid. | |
473 QUIC_INVALID_PRIORITY = 49, | |
474 // Too many streams already open. | |
475 QUIC_TOO_MANY_OPEN_STREAMS = 18, | |
476 // The peer must send a FIN/RST for each stream, and has not been doing so. | |
477 QUIC_TOO_MANY_UNFINISHED_STREAMS = 66, | |
478 // Received public reset for this connection. | |
479 QUIC_PUBLIC_RESET = 19, | |
480 // Invalid protocol version. | |
481 QUIC_INVALID_VERSION = 20, | |
482 | |
483 // deprecated: QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED = 21 | |
484 | |
485 // The Header ID for a stream was too far from the previous. | |
486 QUIC_INVALID_HEADER_ID = 22, | |
487 // Negotiable parameter received during handshake had invalid value. | |
488 QUIC_INVALID_NEGOTIATED_VALUE = 23, | |
489 // There was an error decompressing data. | |
490 QUIC_DECOMPRESSION_FAILURE = 24, | |
491 // We hit our prenegotiated (or default) timeout | |
492 QUIC_CONNECTION_TIMED_OUT = 25, | |
493 // We hit our overall connection timeout | |
494 QUIC_CONNECTION_OVERALL_TIMED_OUT = 67, | |
495 // There was an error encountered migrating addresses | |
496 QUIC_ERROR_MIGRATING_ADDRESS = 26, | |
497 // There was an error while writing to the socket. | |
498 QUIC_PACKET_WRITE_ERROR = 27, | |
499 // There was an error while reading from the socket. | |
500 QUIC_PACKET_READ_ERROR = 51, | |
501 // We received a STREAM_FRAME with no data and no fin flag set. | |
502 QUIC_INVALID_STREAM_FRAME = 50, | |
503 // We received invalid data on the headers stream. | |
504 QUIC_INVALID_HEADERS_STREAM_DATA = 56, | |
505 // The peer received too much data, violating flow control. | |
506 QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA = 59, | |
507 // The peer sent too much data, violating flow control. | |
508 QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA = 63, | |
509 // The peer received an invalid flow control window. | |
510 QUIC_FLOW_CONTROL_INVALID_WINDOW = 64, | |
511 // The connection has been IP pooled into an existing connection. | |
512 QUIC_CONNECTION_IP_POOLED = 62, | |
513 // The connection has too many outstanding sent packets. | |
514 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS = 68, | |
515 // The connection has too many outstanding received packets. | |
516 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS = 69, | |
517 // The quic connection job to load server config is cancelled. | |
518 QUIC_CONNECTION_CANCELLED = 70, | |
519 | |
520 // Crypto errors. | |
521 | |
522 // Hanshake failed. | |
523 QUIC_HANDSHAKE_FAILED = 28, | |
524 // Handshake message contained out of order tags. | |
525 QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29, | |
526 // Handshake message contained too many entries. | |
527 QUIC_CRYPTO_TOO_MANY_ENTRIES = 30, | |
528 // Handshake message contained an invalid value length. | |
529 QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31, | |
530 // A crypto message was received after the handshake was complete. | |
531 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32, | |
532 // A crypto message was received with an illegal message tag. | |
533 QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33, | |
534 // A crypto message was received with an illegal parameter. | |
535 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34, | |
536 // An invalid channel id signature was supplied. | |
537 QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52, | |
538 // A crypto message was received with a mandatory parameter missing. | |
539 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35, | |
540 // A crypto message was received with a parameter that has no overlap | |
541 // with the local parameter. | |
542 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36, | |
543 // A crypto message was received that contained a parameter with too few | |
544 // values. | |
545 QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37, | |
546 // An internal error occured in crypto processing. | |
547 QUIC_CRYPTO_INTERNAL_ERROR = 38, | |
548 // A crypto handshake message specified an unsupported version. | |
549 QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39, | |
550 // There was no intersection between the crypto primitives supported by the | |
551 // peer and ourselves. | |
552 QUIC_CRYPTO_NO_SUPPORT = 40, | |
553 // The server rejected our client hello messages too many times. | |
554 QUIC_CRYPTO_TOO_MANY_REJECTS = 41, | |
555 // The client rejected the server's certificate chain or signature. | |
556 QUIC_PROOF_INVALID = 42, | |
557 // A crypto message was received with a duplicate tag. | |
558 QUIC_CRYPTO_DUPLICATE_TAG = 43, | |
559 // A crypto message was received with the wrong encryption level (i.e. it | |
560 // should have been encrypted but was not.) | |
561 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44, | |
562 // The server config for a server has expired. | |
563 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45, | |
564 // We failed to setup the symmetric keys for a connection. | |
565 QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53, | |
566 // A handshake message arrived, but we are still validating the | |
567 // previous handshake message. | |
568 QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54, | |
569 // A server config update arrived before the handshake is complete. | |
570 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE = 65, | |
571 // This connection involved a version negotiation which appears to have been | |
572 // tampered with. | |
573 QUIC_VERSION_NEGOTIATION_MISMATCH = 55, | |
574 | |
575 // No error. Used as bound while iterating. | |
576 QUIC_LAST_ERROR = 71, | |
577 }; | |
578 | |
579 struct NET_EXPORT_PRIVATE QuicPacketPublicHeader { | |
580 QuicPacketPublicHeader(); | |
581 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other); | |
582 ~QuicPacketPublicHeader(); | |
583 | |
584 // Universal header. All QuicPacket headers will have a connection_id and | |
585 // public flags. | |
586 QuicConnectionId connection_id; | |
587 QuicConnectionIdLength connection_id_length; | |
588 bool reset_flag; | |
589 bool version_flag; | |
590 QuicSequenceNumberLength sequence_number_length; | |
591 QuicVersionVector versions; | |
592 }; | |
593 | |
594 // Header for Data or FEC packets. | |
595 struct NET_EXPORT_PRIVATE QuicPacketHeader { | |
596 QuicPacketHeader(); | |
597 explicit QuicPacketHeader(const QuicPacketPublicHeader& header); | |
598 | |
599 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
600 std::ostream& os, const QuicPacketHeader& s); | |
601 | |
602 QuicPacketPublicHeader public_header; | |
603 bool fec_flag; | |
604 bool entropy_flag; | |
605 QuicPacketEntropyHash entropy_hash; | |
606 QuicPacketSequenceNumber packet_sequence_number; | |
607 InFecGroup is_in_fec_group; | |
608 QuicFecGroupNumber fec_group; | |
609 }; | |
610 | |
611 struct NET_EXPORT_PRIVATE QuicPublicResetPacket { | |
612 QuicPublicResetPacket(); | |
613 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header); | |
614 | |
615 QuicPacketPublicHeader public_header; | |
616 QuicPublicResetNonceProof nonce_proof; | |
617 QuicPacketSequenceNumber rejected_sequence_number; | |
618 IPEndPoint client_address; | |
619 }; | |
620 | |
621 enum QuicVersionNegotiationState { | |
622 START_NEGOTIATION = 0, | |
623 // Server-side this implies we've sent a version negotiation packet and are | |
624 // waiting on the client to select a compatible version. Client-side this | |
625 // implies we've gotten a version negotiation packet, are retransmitting the | |
626 // initial packets with a supported version and are waiting for our first | |
627 // packet from the server. | |
628 NEGOTIATION_IN_PROGRESS, | |
629 // This indicates this endpoint has received a packet from the peer with a | |
630 // version this endpoint supports. Version negotiation is complete, and the | |
631 // version number will no longer be sent with future packets. | |
632 NEGOTIATED_VERSION | |
633 }; | |
634 | |
635 typedef QuicPacketPublicHeader QuicVersionNegotiationPacket; | |
636 | |
637 // A padding frame contains no payload. | |
638 struct NET_EXPORT_PRIVATE QuicPaddingFrame { | |
639 }; | |
640 | |
641 // A ping frame contains no payload, though it is retransmittable, | |
642 // and ACK'd just like other normal frames. | |
643 struct NET_EXPORT_PRIVATE QuicPingFrame { | |
644 }; | |
645 | |
646 struct NET_EXPORT_PRIVATE QuicStreamFrame { | |
647 QuicStreamFrame(); | |
648 QuicStreamFrame(const QuicStreamFrame& frame); | |
649 QuicStreamFrame(QuicStreamId stream_id, | |
650 bool fin, | |
651 QuicStreamOffset offset, | |
652 IOVector data); | |
653 | |
654 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
655 std::ostream& os, const QuicStreamFrame& s); | |
656 | |
657 // Returns a copy of the IOVector |data| as a heap-allocated string. | |
658 // Caller must take ownership of the returned string. | |
659 std::string* GetDataAsString() const; | |
660 | |
661 QuicStreamId stream_id; | |
662 bool fin; | |
663 QuicStreamOffset offset; // Location of this data in the stream. | |
664 IOVector data; | |
665 | |
666 // TODO(rjshade): Remove with FLAGS_quic_attach_ack_notifiers_to_packets. | |
667 // If this is set, then when this packet is ACKed the AckNotifier will be | |
668 // informed. | |
669 QuicAckNotifier* notifier; | |
670 }; | |
671 | |
672 // TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing | |
673 // is finalized. | |
674 typedef std::set<QuicPacketSequenceNumber> SequenceNumberSet; | |
675 typedef std::list<QuicPacketSequenceNumber> SequenceNumberList; | |
676 | |
677 typedef std::list< | |
678 std::pair<QuicPacketSequenceNumber, QuicTime> > PacketTimeList; | |
679 | |
680 struct NET_EXPORT_PRIVATE QuicStopWaitingFrame { | |
681 QuicStopWaitingFrame(); | |
682 ~QuicStopWaitingFrame(); | |
683 | |
684 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
685 std::ostream& os, const QuicStopWaitingFrame& s); | |
686 // Entropy hash of all packets up to, but not including, the least unacked | |
687 // packet. | |
688 QuicPacketEntropyHash entropy_hash; | |
689 // The lowest packet we've sent which is unacked, and we expect an ack for. | |
690 QuicPacketSequenceNumber least_unacked; | |
691 }; | |
692 | |
693 struct NET_EXPORT_PRIVATE QuicAckFrame { | |
694 QuicAckFrame(); | |
695 ~QuicAckFrame(); | |
696 | |
697 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
698 std::ostream& os, const QuicAckFrame& s); | |
699 | |
700 // Entropy hash of all packets up to largest observed not including missing | |
701 // packets. | |
702 QuicPacketEntropyHash entropy_hash; | |
703 | |
704 // The highest packet sequence number we've observed from the peer. | |
705 // | |
706 // In general, this should be the largest packet number we've received. In | |
707 // the case of truncated acks, we may have to advertise a lower "upper bound" | |
708 // than largest received, to avoid implicitly acking missing packets that | |
709 // don't fit in the missing packet list due to size limitations. In this | |
710 // case, largest_observed may be a packet which is also in the missing packets | |
711 // list. | |
712 QuicPacketSequenceNumber largest_observed; | |
713 | |
714 // Time elapsed since largest_observed was received until this Ack frame was | |
715 // sent. | |
716 QuicTime::Delta delta_time_largest_observed; | |
717 | |
718 // TODO(satyamshekhar): Can be optimized using an interval set like data | |
719 // structure. | |
720 // The set of packets which we're expecting and have not received. | |
721 SequenceNumberSet missing_packets; | |
722 | |
723 // Whether the ack had to be truncated when sent. | |
724 bool is_truncated; | |
725 | |
726 // Packets which have been revived via FEC. | |
727 // All of these must also be in missing_packets. | |
728 SequenceNumberSet revived_packets; | |
729 | |
730 // List of <sequence_number, time> for when packets arrived. | |
731 PacketTimeList received_packet_times; | |
732 }; | |
733 | |
734 // True if the sequence number is greater than largest_observed or is listed | |
735 // as missing. | |
736 // Always returns false for sequence numbers less than least_unacked. | |
737 bool NET_EXPORT_PRIVATE IsAwaitingPacket( | |
738 const QuicAckFrame& ack_frame, | |
739 QuicPacketSequenceNumber sequence_number); | |
740 | |
741 // Inserts missing packets between [lower, higher). | |
742 void NET_EXPORT_PRIVATE InsertMissingPacketsBetween( | |
743 QuicAckFrame* ack_frame, | |
744 QuicPacketSequenceNumber lower, | |
745 QuicPacketSequenceNumber higher); | |
746 | |
747 // Defines for all types of congestion control algorithms that can be used in | |
748 // QUIC. Note that this is separate from the congestion feedback type - | |
749 // some congestion control algorithms may use the same feedback type | |
750 // (Reno and Cubic are the classic example for that). | |
751 enum CongestionControlType { | |
752 kCubic, | |
753 kReno, | |
754 kBBR, | |
755 }; | |
756 | |
757 enum LossDetectionType { | |
758 kNack, // Used to mimic TCP's loss detection. | |
759 kTime, // Time based loss detection. | |
760 }; | |
761 | |
762 struct NET_EXPORT_PRIVATE QuicRstStreamFrame { | |
763 QuicRstStreamFrame(); | |
764 QuicRstStreamFrame(QuicStreamId stream_id, | |
765 QuicRstStreamErrorCode error_code, | |
766 QuicStreamOffset bytes_written); | |
767 | |
768 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
769 std::ostream& os, const QuicRstStreamFrame& r); | |
770 | |
771 QuicStreamId stream_id; | |
772 QuicRstStreamErrorCode error_code; | |
773 std::string error_details; | |
774 | |
775 // Used to update flow control windows. On termination of a stream, both | |
776 // endpoints must inform the peer of the number of bytes they have sent on | |
777 // that stream. This can be done through normal termination (data packet with | |
778 // FIN) or through a RST. | |
779 QuicStreamOffset byte_offset; | |
780 }; | |
781 | |
782 struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame { | |
783 QuicConnectionCloseFrame(); | |
784 | |
785 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
786 std::ostream& os, const QuicConnectionCloseFrame& c); | |
787 | |
788 QuicErrorCode error_code; | |
789 std::string error_details; | |
790 }; | |
791 | |
792 struct NET_EXPORT_PRIVATE QuicGoAwayFrame { | |
793 QuicGoAwayFrame(); | |
794 QuicGoAwayFrame(QuicErrorCode error_code, | |
795 QuicStreamId last_good_stream_id, | |
796 const std::string& reason); | |
797 | |
798 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
799 std::ostream& os, const QuicGoAwayFrame& g); | |
800 | |
801 QuicErrorCode error_code; | |
802 QuicStreamId last_good_stream_id; | |
803 std::string reason_phrase; | |
804 }; | |
805 | |
806 // Flow control updates per-stream and at the connection levoel. | |
807 // Based on SPDY's WINDOW_UPDATE frame, but uses an absolute byte offset rather | |
808 // than a window delta. | |
809 // TODO(rjshade): A possible future optimization is to make stream_id and | |
810 // byte_offset variable length, similar to stream frames. | |
811 struct NET_EXPORT_PRIVATE QuicWindowUpdateFrame { | |
812 QuicWindowUpdateFrame() {} | |
813 QuicWindowUpdateFrame(QuicStreamId stream_id, QuicStreamOffset byte_offset); | |
814 | |
815 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
816 std::ostream& os, const QuicWindowUpdateFrame& w); | |
817 | |
818 // The stream this frame applies to. 0 is a special case meaning the overall | |
819 // connection rather than a specific stream. | |
820 QuicStreamId stream_id; | |
821 | |
822 // Byte offset in the stream or connection. The receiver of this frame must | |
823 // not send data which would result in this offset being exceeded. | |
824 QuicStreamOffset byte_offset; | |
825 }; | |
826 | |
827 // The BLOCKED frame is used to indicate to the remote endpoint that this | |
828 // endpoint believes itself to be flow-control blocked but otherwise ready to | |
829 // send data. The BLOCKED frame is purely advisory and optional. | |
830 // Based on SPDY's BLOCKED frame (undocumented as of 2014-01-28). | |
831 struct NET_EXPORT_PRIVATE QuicBlockedFrame { | |
832 QuicBlockedFrame() {} | |
833 explicit QuicBlockedFrame(QuicStreamId stream_id); | |
834 | |
835 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
836 std::ostream& os, const QuicBlockedFrame& b); | |
837 | |
838 // The stream this frame applies to. 0 is a special case meaning the overall | |
839 // connection rather than a specific stream. | |
840 QuicStreamId stream_id; | |
841 }; | |
842 | |
843 // EncryptionLevel enumerates the stages of encryption that a QUIC connection | |
844 // progresses through. When retransmitting a packet, the encryption level needs | |
845 // to be specified so that it is retransmitted at a level which the peer can | |
846 // understand. | |
847 enum EncryptionLevel { | |
848 ENCRYPTION_NONE = 0, | |
849 ENCRYPTION_INITIAL = 1, | |
850 ENCRYPTION_FORWARD_SECURE = 2, | |
851 | |
852 NUM_ENCRYPTION_LEVELS, | |
853 }; | |
854 | |
855 struct NET_EXPORT_PRIVATE QuicFrame { | |
856 QuicFrame(); | |
857 explicit QuicFrame(QuicPaddingFrame* padding_frame); | |
858 explicit QuicFrame(QuicStreamFrame* stream_frame); | |
859 explicit QuicFrame(QuicAckFrame* frame); | |
860 | |
861 explicit QuicFrame(QuicRstStreamFrame* frame); | |
862 explicit QuicFrame(QuicConnectionCloseFrame* frame); | |
863 explicit QuicFrame(QuicStopWaitingFrame* frame); | |
864 explicit QuicFrame(QuicPingFrame* frame); | |
865 explicit QuicFrame(QuicGoAwayFrame* frame); | |
866 explicit QuicFrame(QuicWindowUpdateFrame* frame); | |
867 explicit QuicFrame(QuicBlockedFrame* frame); | |
868 | |
869 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
870 std::ostream& os, const QuicFrame& frame); | |
871 | |
872 QuicFrameType type; | |
873 union { | |
874 QuicPaddingFrame* padding_frame; | |
875 QuicStreamFrame* stream_frame; | |
876 QuicAckFrame* ack_frame; | |
877 | |
878 QuicStopWaitingFrame* stop_waiting_frame; | |
879 | |
880 QuicPingFrame* ping_frame; | |
881 QuicRstStreamFrame* rst_stream_frame; | |
882 QuicConnectionCloseFrame* connection_close_frame; | |
883 QuicGoAwayFrame* goaway_frame; | |
884 QuicWindowUpdateFrame* window_update_frame; | |
885 QuicBlockedFrame* blocked_frame; | |
886 }; | |
887 }; | |
888 | |
889 typedef std::vector<QuicFrame> QuicFrames; | |
890 | |
891 struct NET_EXPORT_PRIVATE QuicFecData { | |
892 QuicFecData(); | |
893 | |
894 // The FEC group number is also the sequence number of the first | |
895 // FEC protected packet. The last protected packet's sequence number will | |
896 // be one less than the sequence number of the FEC packet. | |
897 QuicFecGroupNumber fec_group; | |
898 base::StringPiece redundancy; | |
899 }; | |
900 | |
901 class NET_EXPORT_PRIVATE QuicData { | |
902 public: | |
903 QuicData(const char* buffer, size_t length); | |
904 QuicData(char* buffer, size_t length, bool owns_buffer); | |
905 virtual ~QuicData(); | |
906 | |
907 base::StringPiece AsStringPiece() const { | |
908 return base::StringPiece(data(), length()); | |
909 } | |
910 | |
911 const char* data() const { return buffer_; } | |
912 size_t length() const { return length_; } | |
913 | |
914 private: | |
915 const char* buffer_; | |
916 size_t length_; | |
917 bool owns_buffer_; | |
918 | |
919 DISALLOW_COPY_AND_ASSIGN(QuicData); | |
920 }; | |
921 | |
922 class NET_EXPORT_PRIVATE QuicPacket : public QuicData { | |
923 public: | |
924 QuicPacket(char* buffer, | |
925 size_t length, | |
926 bool owns_buffer, | |
927 QuicConnectionIdLength connection_id_length, | |
928 bool includes_version, | |
929 QuicSequenceNumberLength sequence_number_length); | |
930 | |
931 base::StringPiece FecProtectedData() const; | |
932 base::StringPiece AssociatedData() const; | |
933 base::StringPiece BeforePlaintext() const; | |
934 base::StringPiece Plaintext() const; | |
935 | |
936 char* mutable_data() { return buffer_; } | |
937 | |
938 private: | |
939 char* buffer_; | |
940 const QuicConnectionIdLength connection_id_length_; | |
941 const bool includes_version_; | |
942 const QuicSequenceNumberLength sequence_number_length_; | |
943 | |
944 DISALLOW_COPY_AND_ASSIGN(QuicPacket); | |
945 }; | |
946 | |
947 class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData { | |
948 public: | |
949 QuicEncryptedPacket(const char* buffer, size_t length); | |
950 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer); | |
951 | |
952 // Clones the packet into a new packet which owns the buffer. | |
953 QuicEncryptedPacket* Clone() const; | |
954 | |
955 // By default, gtest prints the raw bytes of an object. The bool data | |
956 // member (in the base class QuicData) causes this object to have padding | |
957 // bytes, which causes the default gtest object printer to read | |
958 // uninitialize memory. So we need to teach gtest how to print this object. | |
959 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | |
960 std::ostream& os, const QuicEncryptedPacket& s); | |
961 | |
962 private: | |
963 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket); | |
964 }; | |
965 | |
966 class NET_EXPORT_PRIVATE RetransmittableFrames { | |
967 public: | |
968 RetransmittableFrames(); | |
969 ~RetransmittableFrames(); | |
970 | |
971 // Allocates a local copy of the referenced StringPiece has QuicStreamFrame | |
972 // use it. | |
973 // Takes ownership of |stream_frame|. | |
974 const QuicFrame& AddStreamFrame(QuicStreamFrame* stream_frame); | |
975 // Takes ownership of the frame inside |frame|. | |
976 const QuicFrame& AddNonStreamFrame(const QuicFrame& frame); | |
977 const QuicFrames& frames() const { return frames_; } | |
978 | |
979 IsHandshake HasCryptoHandshake() const { | |
980 return has_crypto_handshake_; | |
981 } | |
982 | |
983 void set_encryption_level(EncryptionLevel level); | |
984 EncryptionLevel encryption_level() const { | |
985 return encryption_level_; | |
986 } | |
987 | |
988 private: | |
989 QuicFrames frames_; | |
990 EncryptionLevel encryption_level_; | |
991 IsHandshake has_crypto_handshake_; | |
992 // Data referenced by the StringPiece of a QuicStreamFrame. | |
993 std::vector<std::string*> stream_data_; | |
994 | |
995 DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames); | |
996 }; | |
997 | |
998 struct NET_EXPORT_PRIVATE SerializedPacket { | |
999 SerializedPacket(QuicPacketSequenceNumber sequence_number, | |
1000 QuicSequenceNumberLength sequence_number_length, | |
1001 QuicEncryptedPacket* packet, | |
1002 QuicPacketEntropyHash entropy_hash, | |
1003 RetransmittableFrames* retransmittable_frames); | |
1004 ~SerializedPacket(); | |
1005 | |
1006 QuicPacketSequenceNumber sequence_number; | |
1007 QuicSequenceNumberLength sequence_number_length; | |
1008 QuicEncryptedPacket* packet; | |
1009 QuicPacketEntropyHash entropy_hash; | |
1010 RetransmittableFrames* retransmittable_frames; | |
1011 bool is_fec_packet; | |
1012 | |
1013 // Optional notifiers which will be informed when this packet has been ACKed. | |
1014 std::list<QuicAckNotifier*> notifiers; | |
1015 }; | |
1016 | |
1017 struct NET_EXPORT_PRIVATE TransmissionInfo { | |
1018 // Used by STL when assigning into a map. | |
1019 TransmissionInfo(); | |
1020 | |
1021 // Constructs a Transmission with a new all_tranmissions set | |
1022 // containing |sequence_number|. | |
1023 TransmissionInfo(RetransmittableFrames* retransmittable_frames, | |
1024 QuicSequenceNumberLength sequence_number_length, | |
1025 TransmissionType transmission_type, | |
1026 QuicTime sent_time); | |
1027 | |
1028 RetransmittableFrames* retransmittable_frames; | |
1029 QuicSequenceNumberLength sequence_number_length; | |
1030 // Zero when the packet is serialized, non-zero once it's sent. | |
1031 QuicTime sent_time; | |
1032 // Zero when the packet is serialized, non-zero once it's sent. | |
1033 QuicByteCount bytes_sent; | |
1034 QuicPacketCount nack_count; | |
1035 // Reason why this packet was transmitted. | |
1036 TransmissionType transmission_type; | |
1037 // Stores the sequence numbers of all transmissions of this packet. | |
1038 // Must always be nullptr or have multiple elements. | |
1039 SequenceNumberList* all_transmissions; | |
1040 // In flight packets have not been abandoned or lost. | |
1041 bool in_flight; | |
1042 // True if the packet can never be acked, so it can be removed. | |
1043 bool is_unackable; | |
1044 // True if the packet is an FEC packet. | |
1045 bool is_fec_packet; | |
1046 }; | |
1047 | |
1048 } // namespace net | |
1049 | |
1050 #endif // NET_QUIC_QUIC_PROTOCOL_H_ | |
OLD | NEW |