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