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.
5 #ifndef NET_QUIC_QUIC_PROTOCOL_H_
6 #define NET_QUIC_QUIC_PROTOCOL_H_
19 #include "base/basictypes.h"
20 #include "base/containers/hash_tables.h"
21 #include "base/logging.h"
22 #include "base/strings/string_piece.h"
23 #include "net/base/int128.h"
24 #include "net/base/iovec.h"
25 #include "net/base/ip_endpoint.h"
26 #include "net/base/net_export.h"
27 #include "net/quic/quic_bandwidth.h"
28 #include "net/quic/quic_time.h"
29 #include "net/quic/quic_types.h"
33 class QuicAckNotifier
;
35 struct QuicPacketHeader
;
37 typedef uint64 QuicConnectionId
;
38 typedef uint32 QuicStreamId
;
39 typedef uint64 QuicStreamOffset
;
40 typedef uint64 QuicPacketSequenceNumber
;
41 typedef QuicPacketSequenceNumber QuicFecGroupNumber
;
42 typedef uint64 QuicPublicResetNonceProof
;
43 typedef uint8 QuicPacketEntropyHash
;
44 typedef uint32 QuicHeaderId
;
45 // QuicTag is the type of a tag in the wire protocol.
46 typedef uint32 QuicTag
;
47 typedef std::vector
<QuicTag
> QuicTagVector
;
48 typedef std::map
<QuicTag
, std::string
> QuicTagValueMap
;
49 // TODO(rtenneti): Didn't use SpdyPriority because SpdyPriority is uint8 and
50 // QuicPriority is uint32. Use SpdyPriority when we change the QUIC_VERSION.
51 typedef uint32 QuicPriority
;
53 // Default initial maximum size in bytes of a QUIC packet.
54 const QuicByteCount kDefaultMaxPacketSize
= 1350;
55 // Default initial maximum size in bytes of a QUIC packet for servers.
56 const QuicByteCount kDefaultServerMaxPacketSize
= 1000;
57 // The maximum packet size of any QUIC packet, based on ethernet's max size,
58 // minus the IP and UDP headers. IPv6 has a 40 byte header, UPD adds an
59 // additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's
60 // max packet size is 1500 bytes, 1500 - 48 = 1452.
61 const QuicByteCount kMaxPacketSize
= 1452;
62 // Default maximum packet size used in the Linux TCP implementation.
63 // Used in QUIC for congestion window computations in bytes.
64 const QuicByteCount kDefaultTCPMSS
= 1460;
66 // We match SPDY's use of 32 when secure (since we'd compete with SPDY).
67 const QuicPacketCount kInitialCongestionWindowSecure
= 32;
68 // Be conservative, and just use double a typical TCP ICWND for HTTP.
69 const QuicPacketCount kInitialCongestionWindowInsecure
= 20;
71 // Minimum size of initial flow control window, for both stream and session.
72 const uint32 kMinimumFlowControlSendWindow
= 16 * 1024; // 16 KB
74 // Minimum size of the CWND, in packets, when doing bandwidth resumption.
75 const QuicPacketCount kMinCongestionWindowForBandwidthResumption
= 10;
77 // Maximum size of the CWND, in packets.
78 const QuicPacketCount kMaxCongestionWindow
= 200;
80 // Maximum number of tracked packets.
81 const QuicPacketCount kMaxTrackedPackets
= 5000;
83 // Default size of the socket receive buffer in bytes.
84 const QuicByteCount kDefaultSocketReceiveBuffer
= 256 * 1024;
85 // Minimum size of the socket receive buffer in bytes.
86 // Smaller values are ignored.
87 const QuicByteCount kMinSocketReceiveBuffer
= 16 * 1024;
89 // Fraction of the receive buffer that can be used for encrypted bytes.
90 // Allows a 5% overhead for IP and UDP framing, as well as ack only packets.
91 static const float kUsableRecieveBufferFraction
= 0.95f
;
92 // Fraction of the receive buffer that can be used, based on conservative
93 // estimates and testing on Linux.
94 // An alternative to kUsableRecieveBufferFraction.
95 static const float kConservativeReceiveBufferFraction
= 0.6f
;
97 // Don't allow a client to suggest an RTT shorter than 10ms.
98 const uint32 kMinInitialRoundTripTimeUs
= 10 * kNumMicrosPerMilli
;
100 // Don't allow a client to suggest an RTT longer than 15 seconds.
101 const uint32 kMaxInitialRoundTripTimeUs
= 15 * kNumMicrosPerSecond
;
103 // Maximum number of open streams per connection.
104 const size_t kDefaultMaxStreamsPerConnection
= 100;
106 // Number of bytes reserved for public flags in the packet header.
107 const size_t kPublicFlagsSize
= 1;
108 // Number of bytes reserved for version number in the packet header.
109 const size_t kQuicVersionSize
= 4;
110 // Number of bytes reserved for private flags in the packet header.
111 const size_t kPrivateFlagsSize
= 1;
112 // Number of bytes reserved for FEC group in the packet header.
113 const size_t kFecGroupSize
= 1;
115 // Signifies that the QuicPacket will contain version of the protocol.
116 const bool kIncludeVersion
= true;
118 // Index of the first byte in a QUIC packet which is used in hash calculation.
119 const size_t kStartOfHashData
= 0;
121 // Limit on the delta between stream IDs.
122 const QuicStreamId kMaxStreamIdDelta
= 200;
124 // Reserved ID for the crypto stream.
125 const QuicStreamId kCryptoStreamId
= 1;
127 // Reserved ID for the headers stream.
128 const QuicStreamId kHeadersStreamId
= 3;
130 // Maximum delayed ack time, in ms.
131 const int64 kMaxDelayedAckTimeMs
= 25;
133 // The timeout before the handshake succeeds.
134 const int64 kInitialIdleTimeoutSecs
= 5;
135 // The default idle timeout.
136 const int64 kDefaultIdleTimeoutSecs
= 30;
137 // The maximum idle timeout that can be negotiated.
138 const int64 kMaximumIdleTimeoutSecs
= 60 * 10; // 10 minutes.
139 // The default timeout for a connection until the crypto handshake succeeds.
140 const int64 kMaxTimeForCryptoHandshakeSecs
= 10; // 10 secs.
142 // Default limit on the number of undecryptable packets the connection buffers
143 // before the CHLO/SHLO arrive.
144 const size_t kDefaultMaxUndecryptablePackets
= 10;
146 // Default ping timeout.
147 const int64 kPingTimeoutSecs
= 15; // 15 secs.
149 // Minimum number of RTTs between Server Config Updates (SCUP) sent to client.
150 const int kMinIntervalBetweenServerConfigUpdatesRTTs
= 10;
152 // Minimum time between Server Config Updates (SCUP) sent to client.
153 const int kMinIntervalBetweenServerConfigUpdatesMs
= 1000;
155 // Minimum number of packets between Server Config Updates (SCUP).
156 const int kMinPacketsBetweenServerConfigUpdates
= 100;
158 // The number of open streams that a server will accept is set to be slightly
159 // larger than the negotiated limit. Immediately closing the connection if the
160 // client opens slightly too many streams is not ideal: the client may have sent
161 // a FIN that was lost, and simultaneously opened a new stream. The number of
162 // streams a server accepts is a fixed increment over the negotiated limit, or a
163 // percentage increase, whichever is larger.
164 const float kMaxStreamsMultiplier
= 1.1f
;
165 const int kMaxStreamsMinimumIncrement
= 10;
167 // We define an unsigned 16-bit floating point value, inspired by IEEE floats
168 // (http://en.wikipedia.org/wiki/Half_precision_floating-point_format),
169 // with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden
170 // bit) and denormals, but without signs, transfinites or fractions. Wire format
171 // 16 bits (little-endian byte order) are split into exponent (high 5) and
172 // mantissa (low 11) and decoded as:
174 // if (exponent == 0) value = mantissa;
175 // else value = (mantissa | 1 << 11) << (exponent - 1)
176 const int kUFloat16ExponentBits
= 5;
177 const int kUFloat16MaxExponent
= (1 << kUFloat16ExponentBits
) - 2; // 30
178 const int kUFloat16MantissaBits
= 16 - kUFloat16ExponentBits
; // 11
179 const int kUFloat16MantissaEffectiveBits
= kUFloat16MantissaBits
+ 1; // 12
180 const uint64 kUFloat16MaxValue
= // 0x3FFC0000000
181 ((UINT64_C(1) << kUFloat16MantissaEffectiveBits
) - 1) <<
182 kUFloat16MaxExponent
;
184 enum TransmissionType
{
186 FIRST_TRANSMISSION_TYPE
= NOT_RETRANSMISSION
,
187 HANDSHAKE_RETRANSMISSION
, // Retransmits due to handshake timeouts.
188 ALL_UNACKED_RETRANSMISSION
, // Retransmits all unacked packets.
189 ALL_INITIAL_RETRANSMISSION
, // Retransmits all initially encrypted packets.
190 LOSS_RETRANSMISSION
, // Retransmits due to loss detection.
191 RTO_RETRANSMISSION
, // Retransmits due to retransmit time out.
192 TLP_RETRANSMISSION
, // Tail loss probes.
193 LAST_TRANSMISSION_TYPE
= TLP_RETRANSMISSION
,
196 enum HasRetransmittableData
{
197 NO_RETRANSMITTABLE_DATA
,
198 HAS_RETRANSMITTABLE_DATA
,
206 enum class Perspective
{ IS_SERVER
, IS_CLIENT
};
208 NET_EXPORT_PRIVATE
std::ostream
& operator<<(std::ostream
& os
,
209 const Perspective
& s
);
211 // Indicates FEC protection level for data being written.
213 MUST_FEC_PROTECT
, // Callee must FEC protect this data.
214 MAY_FEC_PROTECT
// Callee does not have to but may FEC protect this data.
217 // Indicates FEC policy.
219 FEC_PROTECT_ALWAYS
, // All data in the stream should be FEC protected.
220 FEC_PROTECT_OPTIONAL
// Data in the stream does not need FEC protection.
223 // Indicates FEC policy about when to send FEC packet.
225 // Send FEC packet when FEC group is full or when FEC alarm goes off.
227 // Send FEC packet only when FEC alarm goes off.
232 // Regular frame types. The values set here cannot change without the
233 // introduction of a new QUIC version.
235 RST_STREAM_FRAME
= 1,
236 CONNECTION_CLOSE_FRAME
= 2,
238 WINDOW_UPDATE_FRAME
= 4,
240 STOP_WAITING_FRAME
= 6,
243 // STREAM and ACK frames are special frames. They are encoded differently on
244 // the wire and their values do not need to be stable.
247 // The path MTU discovery frame is encoded as a PING frame on the wire.
252 enum QuicConnectionIdLength
{
253 PACKET_0BYTE_CONNECTION_ID
= 0,
254 PACKET_1BYTE_CONNECTION_ID
= 1,
255 PACKET_4BYTE_CONNECTION_ID
= 4,
256 PACKET_8BYTE_CONNECTION_ID
= 8
264 enum QuicSequenceNumberLength
{
265 PACKET_1BYTE_SEQUENCE_NUMBER
= 1,
266 PACKET_2BYTE_SEQUENCE_NUMBER
= 2,
267 PACKET_4BYTE_SEQUENCE_NUMBER
= 4,
268 PACKET_6BYTE_SEQUENCE_NUMBER
= 6
271 // Used to indicate a QuicSequenceNumberLength using two flag bits.
272 enum QuicSequenceNumberLengthFlags
{
273 PACKET_FLAGS_1BYTE_SEQUENCE
= 0, // 00
274 PACKET_FLAGS_2BYTE_SEQUENCE
= 1, // 01
275 PACKET_FLAGS_4BYTE_SEQUENCE
= 1 << 1, // 10
276 PACKET_FLAGS_6BYTE_SEQUENCE
= 1 << 1 | 1, // 11
279 // The public flags are specified in one byte.
280 enum QuicPacketPublicFlags
{
281 PACKET_PUBLIC_FLAGS_NONE
= 0,
283 // Bit 0: Does the packet header contains version info?
284 PACKET_PUBLIC_FLAGS_VERSION
= 1 << 0,
286 // Bit 1: Is this packet a public reset packet?
287 PACKET_PUBLIC_FLAGS_RST
= 1 << 1,
289 // Bits 2 and 3 specify the length of the ConnectionId as follows:
294 PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID
= 0,
295 PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID
= 1 << 2,
296 PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID
= 1 << 3,
297 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID
= 1 << 3 | 1 << 2,
299 // Bits 4 and 5 describe the packet sequence number length as follows:
304 PACKET_PUBLIC_FLAGS_1BYTE_SEQUENCE
= PACKET_FLAGS_1BYTE_SEQUENCE
<< 4,
305 PACKET_PUBLIC_FLAGS_2BYTE_SEQUENCE
= PACKET_FLAGS_2BYTE_SEQUENCE
<< 4,
306 PACKET_PUBLIC_FLAGS_4BYTE_SEQUENCE
= PACKET_FLAGS_4BYTE_SEQUENCE
<< 4,
307 PACKET_PUBLIC_FLAGS_6BYTE_SEQUENCE
= PACKET_FLAGS_6BYTE_SEQUENCE
<< 4,
309 // All bits set (bits 6 and 7 are not currently used): 00111111
310 PACKET_PUBLIC_FLAGS_MAX
= (1 << 6) - 1
313 // The private flags are specified in one byte.
314 enum QuicPacketPrivateFlags
{
315 PACKET_PRIVATE_FLAGS_NONE
= 0,
317 // Bit 0: Does this packet contain an entropy bit?
318 PACKET_PRIVATE_FLAGS_ENTROPY
= 1 << 0,
320 // Bit 1: Payload is part of an FEC group?
321 PACKET_PRIVATE_FLAGS_FEC_GROUP
= 1 << 1,
323 // Bit 2: Payload is FEC as opposed to frames?
324 PACKET_PRIVATE_FLAGS_FEC
= 1 << 2,
326 // All bits set (bits 3-7 are not currently used): 00000111
327 PACKET_PRIVATE_FLAGS_MAX
= (1 << 3) - 1
330 // The available versions of QUIC. Guaranteed that the integer value of the enum
331 // will match the version number.
332 // When adding a new version to this enum you should add it to
333 // kSupportedQuicVersions (if appropriate), and also add a new case to the
334 // helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and
335 // QuicVersionToString.
337 // Special case to indicate unknown/unsupported QUIC version.
338 QUIC_VERSION_UNSUPPORTED
= 0,
340 QUIC_VERSION_24
= 24, // SPDY/4 header compression.
341 QUIC_VERSION_25
= 25, // SPDY/4 header keys, and removal of error_details
342 // from QuicRstStreamFrame
345 // This vector contains QUIC versions which we currently support.
346 // This should be ordered such that the highest supported version is the first
347 // element, with subsequent elements in descending order (versions can be
348 // skipped as necessary).
350 // IMPORTANT: if you are adding to this list, follow the instructions at
351 // http://sites/quic/adding-and-removing-versions
352 static const QuicVersion kSupportedQuicVersions
[] = {QUIC_VERSION_25
,
355 typedef std::vector
<QuicVersion
> QuicVersionVector
;
357 // Returns a vector of QUIC versions in kSupportedQuicVersions.
358 NET_EXPORT_PRIVATE QuicVersionVector
QuicSupportedVersions();
360 // QuicTag is written to and read from the wire, but we prefer to use
361 // the more readable QuicVersion at other levels.
362 // Helper function which translates from a QuicVersion to a QuicTag. Returns 0
363 // if QuicVersion is unsupported.
364 NET_EXPORT_PRIVATE QuicTag
QuicVersionToQuicTag(const QuicVersion version
);
366 // Returns appropriate QuicVersion from a QuicTag.
367 // Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood.
368 NET_EXPORT_PRIVATE QuicVersion
QuicTagToQuicVersion(const QuicTag version_tag
);
370 // Helper function which translates from a QuicVersion to a string.
371 // Returns strings corresponding to enum names (e.g. QUIC_VERSION_6).
372 NET_EXPORT_PRIVATE
std::string
QuicVersionToString(const QuicVersion version
);
374 // Returns comma separated list of string representations of QuicVersion enum
375 // values in the supplied |versions| vector.
376 NET_EXPORT_PRIVATE
std::string
QuicVersionVectorToString(
377 const QuicVersionVector
& versions
);
379 // Version and Crypto tags are written to the wire with a big-endian
380 // representation of the name of the tag. For example
381 // the client hello tag (CHLO) will be written as the
382 // following 4 bytes: 'C' 'H' 'L' 'O'. Since it is
383 // stored in memory as a little endian uint32, we need
384 // to reverse the order of the bytes.
386 // MakeQuicTag returns a value given the four bytes. For example:
387 // MakeQuicTag('C', 'H', 'L', 'O');
388 NET_EXPORT_PRIVATE QuicTag
MakeQuicTag(char a
, char b
, char c
, char d
);
390 // Returns true if the tag vector contains the specified tag.
391 NET_EXPORT_PRIVATE
bool ContainsQuicTag(const QuicTagVector
& tag_vector
,
394 // Size in bytes of the data or fec packet header.
395 NET_EXPORT_PRIVATE
size_t GetPacketHeaderSize(const QuicPacketHeader
& header
);
397 NET_EXPORT_PRIVATE
size_t GetPacketHeaderSize(
398 QuicConnectionIdLength connection_id_length
,
399 bool include_version
,
400 QuicSequenceNumberLength sequence_number_length
,
401 InFecGroup is_in_fec_group
);
403 // Index of the first byte in a QUIC packet of FEC protected data.
404 NET_EXPORT_PRIVATE
size_t GetStartOfFecProtectedData(
405 QuicConnectionIdLength connection_id_length
,
406 bool include_version
,
407 QuicSequenceNumberLength sequence_number_length
);
408 // Index of the first byte in a QUIC packet of encrypted data.
409 NET_EXPORT_PRIVATE
size_t GetStartOfEncryptedData(
410 QuicConnectionIdLength connection_id_length
,
411 bool include_version
,
412 QuicSequenceNumberLength sequence_number_length
);
414 enum QuicRstStreamErrorCode
{
415 QUIC_STREAM_NO_ERROR
= 0,
417 // There was some error which halted stream processing.
418 QUIC_ERROR_PROCESSING_STREAM
,
419 // We got two fin or reset offsets which did not match.
420 QUIC_MULTIPLE_TERMINATION_OFFSETS
,
421 // We got bad payload and can not respond to it at the protocol level.
422 QUIC_BAD_APPLICATION_PAYLOAD
,
423 // Stream closed due to connection error. No reset frame is sent when this
425 QUIC_STREAM_CONNECTION_ERROR
,
426 // GoAway frame sent. No more stream can be created.
427 QUIC_STREAM_PEER_GOING_AWAY
,
428 // The stream has been cancelled.
429 QUIC_STREAM_CANCELLED
,
430 // Closing stream locally, sending a RST to allow for proper flow control
431 // accounting. Sent in response to a RST from the peer.
432 QUIC_RST_ACKNOWLEDGEMENT
,
434 // No error. Used as bound while iterating.
435 QUIC_STREAM_LAST_ERROR
,
438 // Because receiving an unknown QuicRstStreamErrorCode results in connection
439 // teardown, we use this to make sure any errors predating a given version are
440 // downgraded to the most appropriate existing error.
441 NET_EXPORT_PRIVATE QuicRstStreamErrorCode
AdjustErrorForVersion(
442 QuicRstStreamErrorCode error_code
,
443 QuicVersion version
);
445 // These values must remain stable as they are uploaded to UMA histograms.
446 // To add a new error code, use the current value of QUIC_LAST_ERROR and
447 // increment QUIC_LAST_ERROR.
451 // Connection has reached an invalid state.
452 QUIC_INTERNAL_ERROR
= 1,
453 // There were data frames after the a fin or reset.
454 QUIC_STREAM_DATA_AFTER_TERMINATION
= 2,
455 // Control frame is malformed.
456 QUIC_INVALID_PACKET_HEADER
= 3,
457 // Frame data is malformed.
458 QUIC_INVALID_FRAME_DATA
= 4,
459 // The packet contained no payload.
460 QUIC_MISSING_PAYLOAD
= 48,
461 // FEC data is malformed.
462 QUIC_INVALID_FEC_DATA
= 5,
463 // STREAM frame data is malformed.
464 QUIC_INVALID_STREAM_DATA
= 46,
465 // STREAM frame data is not encrypted.
466 QUIC_UNENCRYPTED_STREAM_DATA
= 61,
467 // RST_STREAM frame data is malformed.
468 QUIC_INVALID_RST_STREAM_DATA
= 6,
469 // CONNECTION_CLOSE frame data is malformed.
470 QUIC_INVALID_CONNECTION_CLOSE_DATA
= 7,
471 // GOAWAY frame data is malformed.
472 QUIC_INVALID_GOAWAY_DATA
= 8,
473 // WINDOW_UPDATE frame data is malformed.
474 QUIC_INVALID_WINDOW_UPDATE_DATA
= 57,
475 // BLOCKED frame data is malformed.
476 QUIC_INVALID_BLOCKED_DATA
= 58,
477 // STOP_WAITING frame data is malformed.
478 QUIC_INVALID_STOP_WAITING_DATA
= 60,
479 // ACK frame data is malformed.
480 QUIC_INVALID_ACK_DATA
= 9,
482 // deprecated: QUIC_INVALID_CONGESTION_FEEDBACK_DATA = 47,
484 // Version negotiation packet is malformed.
485 QUIC_INVALID_VERSION_NEGOTIATION_PACKET
= 10,
486 // Public RST packet is malformed.
487 QUIC_INVALID_PUBLIC_RST_PACKET
= 11,
488 // There was an error decrypting.
489 QUIC_DECRYPTION_FAILURE
= 12,
490 // There was an error encrypting.
491 QUIC_ENCRYPTION_FAILURE
= 13,
492 // The packet exceeded kMaxPacketSize.
493 QUIC_PACKET_TOO_LARGE
= 14,
494 // Data was sent for a stream which did not exist.
495 QUIC_PACKET_FOR_NONEXISTENT_STREAM
= 15,
496 // The peer is going away. May be a client or server.
497 QUIC_PEER_GOING_AWAY
= 16,
498 // A stream ID was invalid.
499 QUIC_INVALID_STREAM_ID
= 17,
500 // A priority was invalid.
501 QUIC_INVALID_PRIORITY
= 49,
502 // Too many streams already open.
503 QUIC_TOO_MANY_OPEN_STREAMS
= 18,
504 // The peer must send a FIN/RST for each stream, and has not been doing so.
505 QUIC_TOO_MANY_UNFINISHED_STREAMS
= 66,
506 // Received public reset for this connection.
507 QUIC_PUBLIC_RESET
= 19,
508 // Invalid protocol version.
509 QUIC_INVALID_VERSION
= 20,
511 // deprecated: QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED = 21
513 // The Header ID for a stream was too far from the previous.
514 QUIC_INVALID_HEADER_ID
= 22,
515 // Negotiable parameter received during handshake had invalid value.
516 QUIC_INVALID_NEGOTIATED_VALUE
= 23,
517 // There was an error decompressing data.
518 QUIC_DECOMPRESSION_FAILURE
= 24,
519 // We hit our prenegotiated (or default) timeout
520 QUIC_CONNECTION_TIMED_OUT
= 25,
521 // We hit our overall connection timeout
522 QUIC_CONNECTION_OVERALL_TIMED_OUT
= 67,
523 // There was an error encountered migrating addresses
524 QUIC_ERROR_MIGRATING_ADDRESS
= 26,
525 // There was an error while writing to the socket.
526 QUIC_PACKET_WRITE_ERROR
= 27,
527 // There was an error while reading from the socket.
528 QUIC_PACKET_READ_ERROR
= 51,
529 // We received a STREAM_FRAME with no data and no fin flag set.
530 QUIC_INVALID_STREAM_FRAME
= 50,
531 // We received invalid data on the headers stream.
532 QUIC_INVALID_HEADERS_STREAM_DATA
= 56,
533 // The peer received too much data, violating flow control.
534 QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA
= 59,
535 // The peer sent too much data, violating flow control.
536 QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA
= 63,
537 // The peer received an invalid flow control window.
538 QUIC_FLOW_CONTROL_INVALID_WINDOW
= 64,
539 // The connection has been IP pooled into an existing connection.
540 QUIC_CONNECTION_IP_POOLED
= 62,
541 // The connection has too many outstanding sent packets.
542 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS
= 68,
543 // The connection has too many outstanding received packets.
544 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS
= 69,
545 // The quic connection job to load server config is cancelled.
546 QUIC_CONNECTION_CANCELLED
= 70,
547 // Disabled QUIC because of high packet loss rate.
548 QUIC_BAD_PACKET_LOSS_RATE
= 71,
549 // Disabled QUIC because of too many PUBLIC_RESETs post handshake.
550 QUIC_PUBLIC_RESETS_POST_HANDSHAKE
= 73,
551 // Disabled QUIC because of too many timeouts with streams open.
552 QUIC_TIMEOUTS_WITH_OPEN_STREAMS
= 74,
553 // Closed because we failed to serialize a packet.
554 QUIC_FAILED_TO_SERIALIZE_PACKET
= 75,
559 QUIC_HANDSHAKE_FAILED
= 28,
560 // Handshake message contained out of order tags.
561 QUIC_CRYPTO_TAGS_OUT_OF_ORDER
= 29,
562 // Handshake message contained too many entries.
563 QUIC_CRYPTO_TOO_MANY_ENTRIES
= 30,
564 // Handshake message contained an invalid value length.
565 QUIC_CRYPTO_INVALID_VALUE_LENGTH
= 31,
566 // A crypto message was received after the handshake was complete.
567 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE
= 32,
568 // A crypto message was received with an illegal message tag.
569 QUIC_INVALID_CRYPTO_MESSAGE_TYPE
= 33,
570 // A crypto message was received with an illegal parameter.
571 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER
= 34,
572 // An invalid channel id signature was supplied.
573 QUIC_INVALID_CHANNEL_ID_SIGNATURE
= 52,
574 // A crypto message was received with a mandatory parameter missing.
575 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND
= 35,
576 // A crypto message was received with a parameter that has no overlap
577 // with the local parameter.
578 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP
= 36,
579 // A crypto message was received that contained a parameter with too few
581 QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND
= 37,
582 // An internal error occured in crypto processing.
583 QUIC_CRYPTO_INTERNAL_ERROR
= 38,
584 // A crypto handshake message specified an unsupported version.
585 QUIC_CRYPTO_VERSION_NOT_SUPPORTED
= 39,
586 // A crypto handshake message resulted in a stateless reject.
587 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT
= 72,
588 // There was no intersection between the crypto primitives supported by the
589 // peer and ourselves.
590 QUIC_CRYPTO_NO_SUPPORT
= 40,
591 // The server rejected our client hello messages too many times.
592 QUIC_CRYPTO_TOO_MANY_REJECTS
= 41,
593 // The client rejected the server's certificate chain or signature.
594 QUIC_PROOF_INVALID
= 42,
595 // A crypto message was received with a duplicate tag.
596 QUIC_CRYPTO_DUPLICATE_TAG
= 43,
597 // A crypto message was received with the wrong encryption level (i.e. it
598 // should have been encrypted but was not.)
599 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT
= 44,
600 // The server config for a server has expired.
601 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED
= 45,
602 // We failed to setup the symmetric keys for a connection.
603 QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED
= 53,
604 // A handshake message arrived, but we are still validating the
605 // previous handshake message.
606 QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO
= 54,
607 // A server config update arrived before the handshake is complete.
608 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE
= 65,
609 // This connection involved a version negotiation which appears to have been
611 QUIC_VERSION_NEGOTIATION_MISMATCH
= 55,
613 // No error. Used as bound while iterating.
614 QUIC_LAST_ERROR
= 76,
617 struct NET_EXPORT_PRIVATE QuicPacketPublicHeader
{
618 QuicPacketPublicHeader();
619 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader
& other
);
620 ~QuicPacketPublicHeader();
622 // Universal header. All QuicPacket headers will have a connection_id and
624 QuicConnectionId connection_id
;
625 QuicConnectionIdLength connection_id_length
;
628 QuicSequenceNumberLength sequence_number_length
;
629 QuicVersionVector versions
;
632 // An integer which cannot be a packet sequence number.
633 const QuicPacketSequenceNumber kInvalidPacketSequenceNumber
= 0;
635 // Header for Data or FEC packets.
636 struct NET_EXPORT_PRIVATE QuicPacketHeader
{
638 explicit QuicPacketHeader(const QuicPacketPublicHeader
& header
);
640 NET_EXPORT_PRIVATE
friend std::ostream
& operator<<(
641 std::ostream
& os
, const QuicPacketHeader
& s
);
643 QuicPacketPublicHeader public_header
;
644 QuicPacketSequenceNumber packet_sequence_number
;
647 QuicPacketEntropyHash entropy_hash
;
648 InFecGroup is_in_fec_group
;
649 QuicFecGroupNumber fec_group
;
652 struct NET_EXPORT_PRIVATE QuicPublicResetPacket
{
653 QuicPublicResetPacket();
654 explicit QuicPublicResetPacket(const QuicPacketPublicHeader
& header
);
656 QuicPacketPublicHeader public_header
;
657 QuicPublicResetNonceProof nonce_proof
;
658 QuicPacketSequenceNumber rejected_sequence_number
;
659 IPEndPoint client_address
;
662 enum QuicVersionNegotiationState
{
663 START_NEGOTIATION
= 0,
664 // Server-side this implies we've sent a version negotiation packet and are
665 // waiting on the client to select a compatible version. Client-side this
666 // implies we've gotten a version negotiation packet, are retransmitting the
667 // initial packets with a supported version and are waiting for our first
668 // packet from the server.
669 NEGOTIATION_IN_PROGRESS
,
670 // This indicates this endpoint has received a packet from the peer with a
671 // version this endpoint supports. Version negotiation is complete, and the
672 // version number will no longer be sent with future packets.
676 typedef QuicPacketPublicHeader QuicVersionNegotiationPacket
;
678 // A padding frame contains no payload.
679 struct NET_EXPORT_PRIVATE QuicPaddingFrame
{
682 // A ping frame contains no payload, though it is retransmittable,
683 // and ACK'd just like other normal frames.
684 struct NET_EXPORT_PRIVATE QuicPingFrame
{
687 // A path MTU discovery frame contains no payload and is serialized as a ping
689 struct NET_EXPORT_PRIVATE QuicMtuDiscoveryFrame
{};
691 struct NET_EXPORT_PRIVATE QuicStreamFrame
{
693 QuicStreamFrame(const QuicStreamFrame
& frame
);
694 QuicStreamFrame(QuicStreamId stream_id
,
696 QuicStreamOffset offset
,
697 base::StringPiece data
);
699 NET_EXPORT_PRIVATE
friend std::ostream
& operator<<(
700 std::ostream
& os
, const QuicStreamFrame
& s
);
702 QuicStreamId stream_id
;
704 QuicStreamOffset offset
; // Location of this data in the stream.
705 base::StringPiece data
;
708 // TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
710 typedef std::set
<QuicPacketSequenceNumber
> SequenceNumberSet
;
711 typedef std::list
<QuicPacketSequenceNumber
> SequenceNumberList
;
714 std::pair
<QuicPacketSequenceNumber
, QuicTime
> > PacketTimeList
;
716 struct NET_EXPORT_PRIVATE QuicStopWaitingFrame
{
717 QuicStopWaitingFrame();
718 ~QuicStopWaitingFrame();
720 NET_EXPORT_PRIVATE
friend std::ostream
& operator<<(
721 std::ostream
& os
, const QuicStopWaitingFrame
& s
);
722 // Entropy hash of all packets up to, but not including, the least unacked
724 QuicPacketEntropyHash entropy_hash
;
725 // The lowest packet we've sent which is unacked, and we expect an ack for.
726 QuicPacketSequenceNumber least_unacked
;
729 struct NET_EXPORT_PRIVATE QuicAckFrame
{
733 NET_EXPORT_PRIVATE
friend std::ostream
& operator<<(
734 std::ostream
& os
, const QuicAckFrame
& s
);
736 // Entropy hash of all packets up to largest observed not including missing
738 QuicPacketEntropyHash entropy_hash
;
740 // The highest packet sequence number we've observed from the peer.
742 // In general, this should be the largest packet number we've received. In
743 // the case of truncated acks, we may have to advertise a lower "upper bound"
744 // than largest received, to avoid implicitly acking missing packets that
745 // don't fit in the missing packet list due to size limitations. In this
746 // case, largest_observed may be a packet which is also in the missing packets
748 QuicPacketSequenceNumber largest_observed
;
750 // Time elapsed since largest_observed was received until this Ack frame was
752 QuicTime::Delta delta_time_largest_observed
;
754 // TODO(satyamshekhar): Can be optimized using an interval set like data
756 // The set of packets which we're expecting and have not received.
757 SequenceNumberSet missing_packets
;
759 // Whether the ack had to be truncated when sent.
762 // Packets which have been revived via FEC.
763 // All of these must also be in missing_packets.
764 SequenceNumberSet revived_packets
;
766 // List of <sequence_number, time> for when packets arrived.
767 PacketTimeList received_packet_times
;
770 // True if the sequence number is greater than largest_observed or is listed
772 // Always returns false for sequence numbers less than least_unacked.
773 bool NET_EXPORT_PRIVATE
IsAwaitingPacket(
774 const QuicAckFrame
& ack_frame
,
775 QuicPacketSequenceNumber sequence_number
);
777 // Inserts missing packets between [lower, higher).
778 void NET_EXPORT_PRIVATE
InsertMissingPacketsBetween(
779 QuicAckFrame
* ack_frame
,
780 QuicPacketSequenceNumber lower
,
781 QuicPacketSequenceNumber higher
);
783 // Defines for all types of congestion control algorithms that can be used in
784 // QUIC. Note that this is separate from the congestion feedback type -
785 // some congestion control algorithms may use the same feedback type
786 // (Reno and Cubic are the classic example for that).
787 enum CongestionControlType
{
795 enum LossDetectionType
{
796 kNack
, // Used to mimic TCP's loss detection.
797 kTime
, // Time based loss detection.
800 struct NET_EXPORT_PRIVATE QuicRstStreamFrame
{
801 QuicRstStreamFrame();
802 QuicRstStreamFrame(QuicStreamId stream_id
,
803 QuicRstStreamErrorCode error_code
,
804 QuicStreamOffset bytes_written
);
806 NET_EXPORT_PRIVATE
friend std::ostream
& operator<<(
807 std::ostream
& os
, const QuicRstStreamFrame
& r
);
809 QuicStreamId stream_id
;
810 QuicRstStreamErrorCode error_code
;
811 // Only used in versions <= QUIC_VERSION_24.
812 std::string error_details
;
814 // Used to update flow control windows. On termination of a stream, both
815 // endpoints must inform the peer of the number of bytes they have sent on
816 // that stream. This can be done through normal termination (data packet with
817 // FIN) or through a RST.
818 QuicStreamOffset byte_offset
;
821 struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame
{
822 QuicConnectionCloseFrame();
824 NET_EXPORT_PRIVATE
friend std::ostream
& operator<<(
825 std::ostream
& os
, const QuicConnectionCloseFrame
& c
);
827 QuicErrorCode error_code
;
828 std::string error_details
;
831 struct NET_EXPORT_PRIVATE QuicGoAwayFrame
{
833 QuicGoAwayFrame(QuicErrorCode error_code
,
834 QuicStreamId last_good_stream_id
,
835 const std::string
& reason
);
837 NET_EXPORT_PRIVATE
friend std::ostream
& operator<<(
838 std::ostream
& os
, const QuicGoAwayFrame
& g
);
840 QuicErrorCode error_code
;
841 QuicStreamId last_good_stream_id
;
842 std::string reason_phrase
;
845 // Flow control updates per-stream and at the connection levoel.
846 // Based on SPDY's WINDOW_UPDATE frame, but uses an absolute byte offset rather
847 // than a window delta.
848 // TODO(rjshade): A possible future optimization is to make stream_id and
849 // byte_offset variable length, similar to stream frames.
850 struct NET_EXPORT_PRIVATE QuicWindowUpdateFrame
{
851 QuicWindowUpdateFrame() {}
852 QuicWindowUpdateFrame(QuicStreamId stream_id
, QuicStreamOffset byte_offset
);
854 NET_EXPORT_PRIVATE
friend std::ostream
& operator<<(
855 std::ostream
& os
, const QuicWindowUpdateFrame
& w
);
857 // The stream this frame applies to. 0 is a special case meaning the overall
858 // connection rather than a specific stream.
859 QuicStreamId stream_id
;
861 // Byte offset in the stream or connection. The receiver of this frame must
862 // not send data which would result in this offset being exceeded.
863 QuicStreamOffset byte_offset
;
866 // The BLOCKED frame is used to indicate to the remote endpoint that this
867 // endpoint believes itself to be flow-control blocked but otherwise ready to
868 // send data. The BLOCKED frame is purely advisory and optional.
869 // Based on SPDY's BLOCKED frame (undocumented as of 2014-01-28).
870 struct NET_EXPORT_PRIVATE QuicBlockedFrame
{
871 QuicBlockedFrame() {}
872 explicit QuicBlockedFrame(QuicStreamId stream_id
);
874 NET_EXPORT_PRIVATE
friend std::ostream
& operator<<(
875 std::ostream
& os
, const QuicBlockedFrame
& b
);
877 // The stream this frame applies to. 0 is a special case meaning the overall
878 // connection rather than a specific stream.
879 QuicStreamId stream_id
;
882 // EncryptionLevel enumerates the stages of encryption that a QUIC connection
883 // progresses through. When retransmitting a packet, the encryption level needs
884 // to be specified so that it is retransmitted at a level which the peer can
886 enum EncryptionLevel
{
888 ENCRYPTION_INITIAL
= 1,
889 ENCRYPTION_FORWARD_SECURE
= 2,
891 NUM_ENCRYPTION_LEVELS
,
894 struct NET_EXPORT_PRIVATE QuicFrame
{
896 explicit QuicFrame(QuicPaddingFrame
* padding_frame
);
897 explicit QuicFrame(QuicStreamFrame
* stream_frame
);
898 explicit QuicFrame(QuicAckFrame
* frame
);
899 explicit QuicFrame(QuicMtuDiscoveryFrame
* frame
);
901 explicit QuicFrame(QuicRstStreamFrame
* frame
);
902 explicit QuicFrame(QuicConnectionCloseFrame
* frame
);
903 explicit QuicFrame(QuicStopWaitingFrame
* frame
);
904 explicit QuicFrame(QuicPingFrame
* frame
);
905 explicit QuicFrame(QuicGoAwayFrame
* frame
);
906 explicit QuicFrame(QuicWindowUpdateFrame
* frame
);
907 explicit QuicFrame(QuicBlockedFrame
* frame
);
909 NET_EXPORT_PRIVATE
friend std::ostream
& operator<<(
910 std::ostream
& os
, const QuicFrame
& frame
);
914 QuicPaddingFrame
* padding_frame
;
915 QuicStreamFrame
* stream_frame
;
916 QuicAckFrame
* ack_frame
;
917 QuicMtuDiscoveryFrame
* mtu_discovery_frame
;
919 QuicStopWaitingFrame
* stop_waiting_frame
;
921 QuicPingFrame
* ping_frame
;
922 QuicRstStreamFrame
* rst_stream_frame
;
923 QuicConnectionCloseFrame
* connection_close_frame
;
924 QuicGoAwayFrame
* goaway_frame
;
925 QuicWindowUpdateFrame
* window_update_frame
;
926 QuicBlockedFrame
* blocked_frame
;
930 typedef std::vector
<QuicFrame
> QuicFrames
;
932 struct NET_EXPORT_PRIVATE QuicFecData
{
935 // The FEC group number is also the sequence number of the first
936 // FEC protected packet. The last protected packet's sequence number will
937 // be one less than the sequence number of the FEC packet.
938 QuicFecGroupNumber fec_group
;
939 base::StringPiece redundancy
;
942 class NET_EXPORT_PRIVATE QuicData
{
944 QuicData(const char* buffer
, size_t length
);
945 QuicData(char* buffer
, size_t length
, bool owns_buffer
);
948 base::StringPiece
AsStringPiece() const {
949 return base::StringPiece(data(), length());
952 const char* data() const { return buffer_
; }
953 size_t length() const { return length_
; }
954 bool owns_buffer() const { return owns_buffer_
; }
961 DISALLOW_COPY_AND_ASSIGN(QuicData
);
964 class NET_EXPORT_PRIVATE QuicPacket
: public QuicData
{
966 QuicPacket(char* buffer
,
969 QuicConnectionIdLength connection_id_length
,
970 bool includes_version
,
971 QuicSequenceNumberLength sequence_number_length
);
973 base::StringPiece
FecProtectedData() const;
974 base::StringPiece
AssociatedData() const;
975 base::StringPiece
BeforePlaintext() const;
976 base::StringPiece
Plaintext() const;
978 char* mutable_data() { return buffer_
; }
982 const QuicConnectionIdLength connection_id_length_
;
983 const bool includes_version_
;
984 const QuicSequenceNumberLength sequence_number_length_
;
986 DISALLOW_COPY_AND_ASSIGN(QuicPacket
);
989 class NET_EXPORT_PRIVATE QuicEncryptedPacket
: public QuicData
{
991 QuicEncryptedPacket(const char* buffer
, size_t length
);
992 QuicEncryptedPacket(char* buffer
, size_t length
, bool owns_buffer
);
994 // Clones the packet into a new packet which owns the buffer.
995 QuicEncryptedPacket
* Clone() const;
997 // By default, gtest prints the raw bytes of an object. The bool data
998 // member (in the base class QuicData) causes this object to have padding
999 // bytes, which causes the default gtest object printer to read
1000 // uninitialize memory. So we need to teach gtest how to print this object.
1001 NET_EXPORT_PRIVATE
friend std::ostream
& operator<<(
1002 std::ostream
& os
, const QuicEncryptedPacket
& s
);
1005 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket
);
1008 class NET_EXPORT_PRIVATE RetransmittableFrames
{
1010 explicit RetransmittableFrames(EncryptionLevel level
);
1011 ~RetransmittableFrames();
1013 // Takes ownership of the frame inside |frame|.
1014 const QuicFrame
& AddFrame(const QuicFrame
& frame
);
1015 // Takes ownership of the frame inside |frame| and |buffer|.
1016 const QuicFrame
& AddFrame(const QuicFrame
& frame
, char* buffer
);
1017 // Removes all stream frames associated with |stream_id|.
1018 void RemoveFramesForStream(QuicStreamId stream_id
);
1020 const QuicFrames
& frames() const { return frames_
; }
1022 IsHandshake
HasCryptoHandshake() const {
1023 return has_crypto_handshake_
;
1026 EncryptionLevel
encryption_level() const {
1027 return encryption_level_
;
1030 bool needs_padding() const { return needs_padding_
; }
1032 void set_needs_padding(bool needs_padding
) { needs_padding_
= needs_padding
; }
1036 const EncryptionLevel encryption_level_
;
1037 IsHandshake has_crypto_handshake_
;
1038 bool needs_padding_
;
1039 // Data referenced by the StringPiece of a QuicStreamFrame.
1040 std::vector
<const char*> stream_data_
;
1042 DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames
);
1045 struct NET_EXPORT_PRIVATE SerializedPacket
{
1046 SerializedPacket(QuicPacketSequenceNumber sequence_number
,
1047 QuicSequenceNumberLength sequence_number_length
,
1048 QuicEncryptedPacket
* packet
,
1049 QuicPacketEntropyHash entropy_hash
,
1050 RetransmittableFrames
* retransmittable_frames
);
1051 ~SerializedPacket();
1053 QuicEncryptedPacket
* packet
;
1054 RetransmittableFrames
* retransmittable_frames
;
1055 QuicPacketSequenceNumber sequence_number
;
1056 QuicSequenceNumberLength sequence_number_length
;
1057 QuicPacketEntropyHash entropy_hash
;
1060 // Optional notifiers which will be informed when this packet has been ACKed.
1061 std::list
<QuicAckNotifier
*> notifiers
;
1064 struct NET_EXPORT_PRIVATE TransmissionInfo
{
1065 // Used by STL when assigning into a map.
1068 // Constructs a Transmission with a new all_tranmissions set
1069 // containing |sequence_number|.
1070 TransmissionInfo(RetransmittableFrames
* retransmittable_frames
,
1071 QuicSequenceNumberLength sequence_number_length
,
1072 TransmissionType transmission_type
,
1074 QuicByteCount bytes_sent
,
1075 bool is_fec_packet
);
1077 RetransmittableFrames
* retransmittable_frames
;
1078 QuicSequenceNumberLength sequence_number_length
;
1080 QuicByteCount bytes_sent
;
1081 QuicPacketCount nack_count
;
1082 // Reason why this packet was transmitted.
1083 TransmissionType transmission_type
;
1084 // Stores the sequence numbers of all transmissions of this packet.
1085 // Must always be nullptr or have multiple elements.
1086 SequenceNumberList
* all_transmissions
;
1087 // In flight packets have not been abandoned or lost.
1089 // True if the packet can never be acked, so it can be removed.
1091 // True if the packet is an FEC packet.
1095 // Convenience wrapper to wrap an iovec array and the total length, which must
1096 // be less than or equal to the actual total length of the iovecs.
1097 struct NET_EXPORT_PRIVATE QuicIOVector
{
1098 QuicIOVector(const struct iovec
* iov
, int iov_count
, size_t total_length
)
1099 : iov(iov
), iov_count(iov_count
), total_length(total_length
) {}
1101 const struct iovec
* iov
;
1102 const int iov_count
;
1103 const size_t total_length
;
1108 #endif // NET_QUIC_QUIC_PROTOCOL_H_