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