blob: 76b31f49f20f61df2a32f35f798e733e3ac5ce2f [file] [log] [blame]
[email protected]8b37a092012-10-18 21:53:491// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_QUIC_QUIC_PROTOCOL_H_
6#define NET_QUIC_QUIC_PROTOCOL_H_
7
[email protected]e537f742012-12-07 15:33:538#include <stddef.h>
[email protected]8b37a092012-10-18 21:53:499#include <limits>
[email protected]a674b4c2012-12-05 03:44:3010#include <map>
[email protected]5640d0a2012-10-22 18:17:0211#include <ostream>
[email protected]e537f742012-12-07 15:33:5312#include <set>
13#include <string>
[email protected]8b37a092012-10-18 21:53:4914#include <utility>
15#include <vector>
16
17#include "base/basictypes.h"
[email protected]14c1c232013-06-11 17:52:4418#include "base/containers/hash_tables.h"
[email protected]8b37a092012-10-18 21:53:4919#include "base/logging.h"
[email protected]d069c11a2013-04-13 00:01:5520#include "base/strings/string_piece.h"
[email protected]165e0752012-11-16 07:49:4421#include "net/base/int128.h"
[email protected]79d13dcb2014-02-05 07:23:1322#include "net/base/ip_endpoint.h"
[email protected]8b37a092012-10-18 21:53:4923#include "net/base/net_export.h"
[email protected]5dafdb62013-11-14 01:24:2624#include "net/quic/iovector.h"
[email protected]fee17f72013-02-03 07:47:4125#include "net/quic/quic_bandwidth.h"
[email protected]2a960e02012-11-11 14:48:1026#include "net/quic/quic_time.h"
[email protected]8b37a092012-10-18 21:53:4927
28namespace net {
29
[email protected]f1e97e92012-12-16 04:53:2530using ::operator<<;
31
[email protected]97cf3022013-09-05 14:30:1632class QuicAckNotifier;
[email protected]8b37a092012-10-18 21:53:4933class QuicPacket;
[email protected]b064310782013-05-30 21:12:1734struct QuicPacketHeader;
[email protected]8b37a092012-10-18 21:53:4935
[email protected]3aa9ca72014-02-27 19:39:4336typedef uint64 QuicConnectionId;
[email protected]8b37a092012-10-18 21:53:4937typedef uint32 QuicStreamId;
38typedef uint64 QuicStreamOffset;
39typedef uint64 QuicPacketSequenceNumber;
[email protected]c995c572013-01-18 05:43:2040typedef QuicPacketSequenceNumber QuicFecGroupNumber;
[email protected]86a318d2013-01-23 21:16:0441typedef uint64 QuicPublicResetNonceProof;
[email protected]9db443912013-02-25 05:27:0342typedef uint8 QuicPacketEntropyHash;
[email protected]c244c5a12013-05-07 20:55:0443typedef uint32 QuicHeaderId;
[email protected]2532de12013-05-09 12:29:3344// QuicTag is the type of a tag in the wire protocol.
45typedef uint32 QuicTag;
46typedef std::vector<QuicTag> QuicTagVector;
[email protected]79d13dcb2014-02-05 07:23:1347typedef std::map<QuicTag, std::string> QuicTagValueMap;
[email protected]497bfb22014-01-08 01:28:0348// TODO(rtenneti): Didn't use SpdyPriority because SpdyPriority is uint8 and
49// QuicPriority is uint32. Use SpdyPriority when we change the QUIC_VERSION.
[email protected]8edeb8d2013-08-28 06:11:4350typedef uint32 QuicPriority;
[email protected]cff7b7b2013-01-11 08:49:0751
[email protected]8b37a092012-10-18 21:53:4952// TODO(rch): Consider Quic specific names for these constants.
[email protected]8e01c062013-10-31 07:35:3153// Default and initial maximum size in bytes of a QUIC packet.
54const QuicByteCount kDefaultMaxPacketSize = 1200;
55// The maximum packet size of any QUIC packet, based on ethernet's max size,
[email protected]41fb6372013-12-10 05:26:4056// 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.
59const QuicByteCount kMaxPacketSize = 1452;
[email protected]ce7bb1412014-05-17 15:51:3360// Default maximum packet size used in Linux TCP implementations.
61const QuicByteCount kDefaultTCPMSS = 1460;
[email protected]8e01c062013-10-31 07:35:3162
63// Maximum size of the initial congestion window in packets.
64const size_t kDefaultInitialWindow = 10;
[email protected]2d43c40122014-04-21 14:51:2765const uint32 kMaxInitialWindow = 100;
[email protected]8e01c062013-10-31 07:35:3166
[email protected]9bb57c72014-03-31 20:36:0467// Default size of initial flow control window.
68const uint32 kDefaultFlowControlSendWindow = 16 * 1024; // 16 KB
69
[email protected]0ac0c5b2013-11-20 05:55:5870// Maximum size of the congestion window, in packets, for TCP congestion control
71// algorithms.
72const size_t kMaxTcpCongestionWindow = 200;
73
[email protected]8e01c062013-10-31 07:35:3174// Don't allow a client to suggest an RTT longer than 15 seconds.
[email protected]2d43c40122014-04-21 14:51:2775const uint32 kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond;
[email protected]8b37a092012-10-18 21:53:4976
77// Maximum number of open streams per connection.
78const size_t kDefaultMaxStreamsPerConnection = 100;
79
[email protected]af806e62013-05-22 14:47:5080// Number of bytes reserved for public flags in the packet header.
81const size_t kPublicFlagsSize = 1;
[email protected]5351cc4b2013-03-03 07:22:4182// Number of bytes reserved for version number in the packet header.
83const size_t kQuicVersionSize = 4;
[email protected]c995c572013-01-18 05:43:2084// Number of bytes reserved for private flags in the packet header.
85const size_t kPrivateFlagsSize = 1;
86// Number of bytes reserved for FEC group in the packet header.
87const size_t kFecGroupSize = 1;
[email protected]5351cc4b2013-03-03 07:22:4188
89// Signifies that the QuicPacket will contain version of the protocol.
90const bool kIncludeVersion = true;
[email protected]c995c572013-01-18 05:43:2091
[email protected]5351cc4b2013-03-03 07:22:4192// Index of the first byte in a QUIC packet which is used in hash calculation.
93const size_t kStartOfHashData = 0;
[email protected]8b37a092012-10-18 21:53:4994
95// Limit on the delta between stream IDs.
[email protected]c5cc9bd2014-03-31 23:17:1496const QuicStreamId kMaxStreamIdDelta = 200;
[email protected]c244c5a12013-05-07 20:55:0497// Limit on the delta between header IDs.
[email protected]c5cc9bd2014-03-31 23:17:1498const QuicHeaderId kMaxHeaderIdDelta = 200;
[email protected]8b37a092012-10-18 21:53:4999
100// Reserved ID for the crypto stream.
[email protected]8b37a092012-10-18 21:53:49101const QuicStreamId kCryptoStreamId = 1;
102
[email protected]4d640792013-12-18 22:21:08103// Reserved ID for the headers stream.
104const QuicStreamId kHeadersStreamId = 3;
105
[email protected]899951652013-05-16 12:52:39106// This is the default network timeout a for connection till the crypto
107// handshake succeeds and the negotiated timeout from the handshake is received.
[email protected]b064310782013-05-30 21:12:17108const int64 kDefaultInitialTimeoutSecs = 120; // 2 mins.
[email protected]899951652013-05-16 12:52:39109const int64 kDefaultTimeoutSecs = 60 * 10; // 10 minutes.
[email protected]b064310782013-05-30 21:12:17110const int64 kDefaultMaxTimeForCryptoHandshakeSecs = 5; // 5 secs.
[email protected]8b37a092012-10-18 21:53:49111
[email protected]525948df2014-04-21 06:26:58112// Default ping timeout.
113const int64 kPingTimeoutSecs = 15; // 15 secs.
114
[email protected]b007e632013-10-28 08:39:25115// We define an unsigned 16-bit floating point value, inspired by IEEE floats
116// (http://en.wikipedia.org/wiki/Half_precision_floating-point_format),
117// with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden
118// bit) and denormals, but without signs, transfinites or fractions. Wire format
119// 16 bits (little-endian byte order) are split into exponent (high 5) and
120// mantissa (low 11) and decoded as:
121// uint64 value;
122// if (exponent == 0) value = mantissa;
123// else value = (mantissa | 1 << 11) << (exponent - 1)
124const int kUFloat16ExponentBits = 5;
125const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30
126const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11
127const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12
128const uint64 kUFloat16MaxValue = // 0x3FFC0000000
129 ((GG_UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1) <<
130 kUFloat16MaxExponent;
131
[email protected]c67a82cb2013-09-24 02:53:21132enum TransmissionType {
[email protected]2532de12013-05-09 12:29:33133 NOT_RETRANSMISSION,
[email protected]b9475b582014-03-20 20:04:33134 FIRST_TRANSMISSION_TYPE = NOT_RETRANSMISSION,
135 HANDSHAKE_RETRANSMISSION, // Retransmits due to handshake timeouts.
136 ALL_UNACKED_RETRANSMISSION, // Retransmits of all unacked packets.
137 LOSS_RETRANSMISSION, // Retransmits due to loss detection.
138 RTO_RETRANSMISSION, // Retransmits due to retransmit time out.
139 TLP_RETRANSMISSION, // Tail loss probes.
140 LAST_TRANSMISSION_TYPE = TLP_RETRANSMISSION,
[email protected]74bda142013-03-31 02:49:11141};
142
[email protected]41fb6372013-12-10 05:26:40143enum RetransmissionType {
144 INITIAL_ENCRYPTION_ONLY,
145 ALL_PACKETS
146};
147
[email protected]74bda142013-03-31 02:49:11148enum HasRetransmittableData {
[email protected]2532de12013-05-09 12:29:33149 NO_RETRANSMITTABLE_DATA,
150 HAS_RETRANSMITTABLE_DATA,
[email protected]74bda142013-03-31 02:49:11151};
152
[email protected]575cce62013-08-03 02:06:43153enum IsHandshake {
154 NOT_HANDSHAKE,
155 IS_HANDSHAKE
156};
157
[email protected]be24ab22012-10-22 03:01:52158enum QuicFrameType {
[email protected]6ae6e342014-02-06 02:21:42159 // Regular frame types. The values set here cannot change without the
160 // introduction of a new QUIC version.
[email protected]c995c572013-01-18 05:43:20161 PADDING_FRAME = 0,
[email protected]6ae6e342014-02-06 02:21:42162 RST_STREAM_FRAME = 1,
163 CONNECTION_CLOSE_FRAME = 2,
164 GOAWAY_FRAME = 3,
165 WINDOW_UPDATE_FRAME = 4,
166 BLOCKED_FRAME = 5,
[email protected]93dd91f2014-02-27 00:09:03167 STOP_WAITING_FRAME = 6,
[email protected]d8c522112014-04-23 09:23:25168 PING_FRAME = 7,
[email protected]6ae6e342014-02-06 02:21:42169
170 // STREAM, ACK, and CONGESTION_FEEDBACK frames are special frames. They are
171 // encoded differently on the wire and their values do not need to be stable.
[email protected]97cf3022013-09-05 14:30:16172 STREAM_FRAME,
173 ACK_FRAME,
174 CONGESTION_FEEDBACK_FRAME,
[email protected]be24ab22012-10-22 03:01:52175 NUM_FRAME_TYPES
[email protected]8b37a092012-10-18 21:53:49176};
177
[email protected]3aa9ca72014-02-27 19:39:43178enum QuicConnectionIdLength {
179 PACKET_0BYTE_CONNECTION_ID = 0,
180 PACKET_1BYTE_CONNECTION_ID = 1,
181 PACKET_4BYTE_CONNECTION_ID = 4,
182 PACKET_8BYTE_CONNECTION_ID = 8
[email protected]b064310782013-05-30 21:12:17183};
184
185enum InFecGroup {
186 NOT_IN_FEC_GROUP,
187 IN_FEC_GROUP,
188};
189
[email protected]25c31dc2013-06-05 17:56:04190enum QuicSequenceNumberLength {
191 PACKET_1BYTE_SEQUENCE_NUMBER = 1,
192 PACKET_2BYTE_SEQUENCE_NUMBER = 2,
193 PACKET_4BYTE_SEQUENCE_NUMBER = 4,
194 PACKET_6BYTE_SEQUENCE_NUMBER = 6
195};
196
[email protected]8e01c062013-10-31 07:35:31197// Used to indicate a QuicSequenceNumberLength using two flag bits.
198enum QuicSequenceNumberLengthFlags {
199 PACKET_FLAGS_1BYTE_SEQUENCE = 0, // 00
200 PACKET_FLAGS_2BYTE_SEQUENCE = 1, // 01
201 PACKET_FLAGS_4BYTE_SEQUENCE = 1 << 1, // 10
202 PACKET_FLAGS_6BYTE_SEQUENCE = 1 << 1 | 1, // 11
203};
204
[email protected]f62262b2013-07-05 20:57:30205// The public flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20206enum QuicPacketPublicFlags {
207 PACKET_PUBLIC_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30208
209 // Bit 0: Does the packet header contains version info?
210 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0,
211
212 // Bit 1: Is this packet a public reset packet?
213 PACKET_PUBLIC_FLAGS_RST = 1 << 1,
214
[email protected]3aa9ca72014-02-27 19:39:43215 // Bits 2 and 3 specify the length of the ConnectionId as follows:
[email protected]f62262b2013-07-05 20:57:30216 // ----00--: 0 bytes
217 // ----01--: 1 byte
218 // ----10--: 4 bytes
219 // ----11--: 8 bytes
[email protected]3aa9ca72014-02-27 19:39:43220 PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID = 0,
221 PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID = 1 << 2,
222 PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID = 1 << 3,
223 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID = 1 << 3 | 1 << 2,
[email protected]f62262b2013-07-05 20:57:30224
225 // Bits 4 and 5 describe the packet sequence number length as follows:
226 // --00----: 1 byte
227 // --01----: 2 bytes
228 // --10----: 4 bytes
229 // --11----: 6 bytes
[email protected]8e01c062013-10-31 07:35:31230 PACKET_PUBLIC_FLAGS_1BYTE_SEQUENCE = PACKET_FLAGS_1BYTE_SEQUENCE << 4,
231 PACKET_PUBLIC_FLAGS_2BYTE_SEQUENCE = PACKET_FLAGS_2BYTE_SEQUENCE << 4,
232 PACKET_PUBLIC_FLAGS_4BYTE_SEQUENCE = PACKET_FLAGS_4BYTE_SEQUENCE << 4,
233 PACKET_PUBLIC_FLAGS_6BYTE_SEQUENCE = PACKET_FLAGS_6BYTE_SEQUENCE << 4,
[email protected]f62262b2013-07-05 20:57:30234
235 // All bits set (bits 6 and 7 are not currently used): 00111111
236 PACKET_PUBLIC_FLAGS_MAX = (1 << 6) - 1
[email protected]c995c572013-01-18 05:43:20237};
[email protected]8b37a092012-10-18 21:53:49238
[email protected]f62262b2013-07-05 20:57:30239// The private flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20240enum QuicPacketPrivateFlags {
241 PACKET_PRIVATE_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30242
243 // Bit 0: Does this packet contain an entropy bit?
[email protected]b064310782013-05-30 21:12:17244 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0,
[email protected]f62262b2013-07-05 20:57:30245
246 // Bit 1: Payload is part of an FEC group?
247 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1,
248
249 // Bit 2: Payload is FEC as opposed to frames?
250 PACKET_PRIVATE_FLAGS_FEC = 1 << 2,
251
252 // All bits set (bits 3-7 are not currently used): 00000111
253 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1
[email protected]c995c572013-01-18 05:43:20254};
255
[email protected]48878092013-07-26 14:51:56256// The available versions of QUIC. Guaranteed that the integer value of the enum
257// will match the version number.
258// When adding a new version to this enum you should add it to
[email protected]8bbfaeb72013-08-09 06:38:26259// kSupportedQuicVersions (if appropriate), and also add a new case to the
260// helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and
261// QuicVersionToString.
[email protected]48878092013-07-26 14:51:56262enum QuicVersion {
263 // Special case to indicate unknown/unsupported QUIC version.
264 QUIC_VERSION_UNSUPPORTED = 0,
265
[email protected]93dd91f2014-02-27 00:09:03266 QUIC_VERSION_15 = 15,
[email protected]9bb57c72014-03-31 20:36:04267 QUIC_VERSION_16 = 16,
[email protected]d8c522112014-04-23 09:23:25268 QUIC_VERSION_17 = 17,
[email protected]77b5d50b2014-05-07 22:48:48269 QUIC_VERSION_18 = 18,
270 QUIC_VERSION_19 = 19, // Current version.
[email protected]48878092013-07-26 14:51:56271};
272
273// This vector contains QUIC versions which we currently support.
274// This should be ordered such that the highest supported version is the first
275// element, with subsequent elements in descending order (versions can be
276// skipped as necessary).
[email protected]31ae854842013-11-27 00:05:46277//
278// IMPORTANT: if you are addding to this list, follow the instructions at
279// http://sites/quic/adding-and-removing-versions
[email protected]ce7bb1412014-05-17 15:51:33280static const QuicVersion kSupportedQuicVersions[] = {QUIC_VERSION_19,
281 QUIC_VERSION_18,
[email protected]d8c522112014-04-23 09:23:25282 QUIC_VERSION_17,
[email protected]9bb57c72014-03-31 20:36:04283 QUIC_VERSION_16,
[email protected]08da9adb2014-04-24 08:33:31284 QUIC_VERSION_15};
[email protected]48878092013-07-26 14:51:56285
286typedef std::vector<QuicVersion> QuicVersionVector;
287
[email protected]b007e632013-10-28 08:39:25288// Returns a vector of QUIC versions in kSupportedQuicVersions.
289NET_EXPORT_PRIVATE QuicVersionVector QuicSupportedVersions();
[email protected]ea2ab47b2013-08-13 00:44:11290
[email protected]48878092013-07-26 14:51:56291// QuicTag is written to and read from the wire, but we prefer to use
292// the more readable QuicVersion at other levels.
293// Helper function which translates from a QuicVersion to a QuicTag. Returns 0
294// if QuicVersion is unsupported.
295NET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version);
296
297// Returns appropriate QuicVersion from a QuicTag.
298// Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood.
299NET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag);
300
301// Helper function which translates from a QuicVersion to a string.
302// Returns strings corresponding to enum names (e.g. QUIC_VERSION_6).
303NET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version);
304
305// Returns comma separated list of string representations of QuicVersion enum
[email protected]b007e632013-10-28 08:39:25306// values in the supplied |versions| vector.
307NET_EXPORT_PRIVATE std::string QuicVersionVectorToString(
308 const QuicVersionVector& versions);
[email protected]48878092013-07-26 14:51:56309
310// Version and Crypto tags are written to the wire with a big-endian
311// representation of the name of the tag. For example
312// the client hello tag (CHLO) will be written as the
313// following 4 bytes: 'C' 'H' 'L' 'O'. Since it is
314// stored in memory as a little endian uint32, we need
315// to reverse the order of the bytes.
316
317// MakeQuicTag returns a value given the four bytes. For example:
318// MakeQuicTag('C', 'H', 'L', 'O');
319NET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d);
320
[email protected]9cda5fd2014-06-03 10:20:28321// Returns true if the tag vector contains the specified tag.
[email protected]730b35d72014-06-05 03:23:22322bool ContainsQuicTag(const QuicTagVector& tag_vector, QuicTag tag);
[email protected]9cda5fd2014-06-03 10:20:28323
[email protected]b064310782013-05-30 21:12:17324// Size in bytes of the data or fec packet header.
[email protected]79d13dcb2014-02-05 07:23:13325NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(const QuicPacketHeader& header);
[email protected]b064310782013-05-30 21:12:17326
[email protected]25c31dc2013-06-05 17:56:04327NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(
[email protected]3aa9ca72014-02-27 19:39:43328 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04329 bool include_version,
330 QuicSequenceNumberLength sequence_number_length,
331 InFecGroup is_in_fec_group);
[email protected]b064310782013-05-30 21:12:17332
[email protected]b064310782013-05-30 21:12:17333// Index of the first byte in a QUIC packet of FEC protected data.
[email protected]25c31dc2013-06-05 17:56:04334NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(
[email protected]3aa9ca72014-02-27 19:39:43335 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04336 bool include_version,
337 QuicSequenceNumberLength sequence_number_length);
[email protected]b064310782013-05-30 21:12:17338// Index of the first byte in a QUIC packet of encrypted data.
[email protected]25c31dc2013-06-05 17:56:04339NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(
[email protected]3aa9ca72014-02-27 19:39:43340 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04341 bool include_version,
342 QuicSequenceNumberLength sequence_number_length);
[email protected]b064310782013-05-30 21:12:17343
[email protected]74bda142013-03-31 02:49:11344enum QuicRstStreamErrorCode {
345 QUIC_STREAM_NO_ERROR = 0,
[email protected]8b37a092012-10-18 21:53:49346
[email protected]24e5bc52013-09-18 15:36:58347 // There was some error which halted stream processing.
348 QUIC_ERROR_PROCESSING_STREAM,
[email protected]8b37a092012-10-18 21:53:49349 // We got two fin or reset offsets which did not match.
350 QUIC_MULTIPLE_TERMINATION_OFFSETS,
351 // We got bad payload and can not respond to it at the protocol level.
352 QUIC_BAD_APPLICATION_PAYLOAD,
[email protected]74bda142013-03-31 02:49:11353 // Stream closed due to connection error. No reset frame is sent when this
354 // happens.
355 QUIC_STREAM_CONNECTION_ERROR,
356 // GoAway frame sent. No more stream can be created.
357 QUIC_STREAM_PEER_GOING_AWAY,
[email protected]06ff5152013-08-29 01:03:05358 // The stream has been cancelled.
359 QUIC_STREAM_CANCELLED,
[email protected]51cc1342014-04-18 23:44:37360 // Sending a RST to allow for proper flow control accounting.
361 QUIC_RST_FLOW_CONTROL_ACCOUNTING,
[email protected]8b37a092012-10-18 21:53:49362
[email protected]74bda142013-03-31 02:49:11363 // No error. Used as bound while iterating.
364 QUIC_STREAM_LAST_ERROR,
365};
[email protected]8b37a092012-10-18 21:53:49366
[email protected]51cc1342014-04-18 23:44:37367// Because receiving an unknown QuicRstStreamErrorCode results in connection
368// teardown, we use this to make sure any errors predating a given version are
369// downgraded to the most appropriate existing error.
370NET_EXPORT_PRIVATE QuicRstStreamErrorCode AdjustErrorForVersion(
371 QuicRstStreamErrorCode error_code,
372 QuicVersion version);
373
[email protected]89264042013-08-21 07:35:24374// These values must remain stable as they are uploaded to UMA histograms.
375// To add a new error code, use the current value of QUIC_LAST_ERROR and
376// increment QUIC_LAST_ERROR.
[email protected]74bda142013-03-31 02:49:11377enum QuicErrorCode {
378 QUIC_NO_ERROR = 0,
379
380 // Connection has reached an invalid state.
[email protected]89264042013-08-21 07:35:24381 QUIC_INTERNAL_ERROR = 1,
[email protected]74bda142013-03-31 02:49:11382 // There were data frames after the a fin or reset.
[email protected]89264042013-08-21 07:35:24383 QUIC_STREAM_DATA_AFTER_TERMINATION = 2,
[email protected]8b37a092012-10-18 21:53:49384 // Control frame is malformed.
[email protected]89264042013-08-21 07:35:24385 QUIC_INVALID_PACKET_HEADER = 3,
[email protected]be24ab22012-10-22 03:01:52386 // Frame data is malformed.
[email protected]89264042013-08-21 07:35:24387 QUIC_INVALID_FRAME_DATA = 4,
388 // The packet contained no payload.
389 QUIC_MISSING_PAYLOAD = 48,
[email protected]8b37a092012-10-18 21:53:49390 // FEC data is malformed.
[email protected]89264042013-08-21 07:35:24391 QUIC_INVALID_FEC_DATA = 5,
392 // STREAM frame data is malformed.
393 QUIC_INVALID_STREAM_DATA = 46,
[email protected]42a3eba2014-04-30 10:52:55394 // STREAM frame data is not encrypted.
395 QUIC_UNENCRYPTED_STREAM_DATA = 61,
[email protected]89264042013-08-21 07:35:24396 // RST_STREAM frame data is malformed.
397 QUIC_INVALID_RST_STREAM_DATA = 6,
398 // CONNECTION_CLOSE frame data is malformed.
399 QUIC_INVALID_CONNECTION_CLOSE_DATA = 7,
400 // GOAWAY frame data is malformed.
401 QUIC_INVALID_GOAWAY_DATA = 8,
[email protected]6ae6e342014-02-06 02:21:42402 // WINDOW_UPDATE frame data is malformed.
403 QUIC_INVALID_WINDOW_UPDATE_DATA = 57,
404 // BLOCKED frame data is malformed.
405 QUIC_INVALID_BLOCKED_DATA = 58,
[email protected]93dd91f2014-02-27 00:09:03406 // STOP_WAITING frame data is malformed.
407 QUIC_INVALID_STOP_WAITING_DATA = 60,
[email protected]89264042013-08-21 07:35:24408 // ACK frame data is malformed.
409 QUIC_INVALID_ACK_DATA = 9,
410 // CONGESTION_FEEDBACK frame data is malformed.
411 QUIC_INVALID_CONGESTION_FEEDBACK_DATA = 47,
[email protected]14e8106c2013-03-14 16:25:33412 // Version negotiation packet is malformed.
[email protected]89264042013-08-21 07:35:24413 QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10,
[email protected]899951652013-05-16 12:52:39414 // Public RST packet is malformed.
[email protected]89264042013-08-21 07:35:24415 QUIC_INVALID_PUBLIC_RST_PACKET = 11,
[email protected]8b37a092012-10-18 21:53:49416 // There was an error decrypting.
[email protected]89264042013-08-21 07:35:24417 QUIC_DECRYPTION_FAILURE = 12,
[email protected]8b37a092012-10-18 21:53:49418 // There was an error encrypting.
[email protected]89264042013-08-21 07:35:24419 QUIC_ENCRYPTION_FAILURE = 13,
[email protected]8b37a092012-10-18 21:53:49420 // The packet exceeded kMaxPacketSize.
[email protected]89264042013-08-21 07:35:24421 QUIC_PACKET_TOO_LARGE = 14,
[email protected]8b37a092012-10-18 21:53:49422 // Data was sent for a stream which did not exist.
[email protected]89264042013-08-21 07:35:24423 QUIC_PACKET_FOR_NONEXISTENT_STREAM = 15,
[email protected]9db443912013-02-25 05:27:03424 // The peer is going away. May be a client or server.
[email protected]89264042013-08-21 07:35:24425 QUIC_PEER_GOING_AWAY = 16,
[email protected]8b37a092012-10-18 21:53:49426 // A stream ID was invalid.
[email protected]89264042013-08-21 07:35:24427 QUIC_INVALID_STREAM_ID = 17,
[email protected]24e5bc52013-09-18 15:36:58428 // A priority was invalid.
429 QUIC_INVALID_PRIORITY = 49,
[email protected]8b37a092012-10-18 21:53:49430 // Too many streams already open.
[email protected]89264042013-08-21 07:35:24431 QUIC_TOO_MANY_OPEN_STREAMS = 18,
[email protected]86a318d2013-01-23 21:16:04432 // Received public reset for this connection.
[email protected]89264042013-08-21 07:35:24433 QUIC_PUBLIC_RESET = 19,
[email protected]c244c5a12013-05-07 20:55:04434 // Invalid protocol version.
[email protected]89264042013-08-21 07:35:24435 QUIC_INVALID_VERSION = 20,
[email protected]92bf17c2014-03-03 21:14:03436
437 // deprecated: QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED = 21
438
[email protected]c244c5a12013-05-07 20:55:04439 // The Header ID for a stream was too far from the previous.
[email protected]89264042013-08-21 07:35:24440 QUIC_INVALID_HEADER_ID = 22,
[email protected]899951652013-05-16 12:52:39441 // Negotiable parameter received during handshake had invalid value.
[email protected]89264042013-08-21 07:35:24442 QUIC_INVALID_NEGOTIATED_VALUE = 23,
[email protected]899951652013-05-16 12:52:39443 // There was an error decompressing data.
[email protected]89264042013-08-21 07:35:24444 QUIC_DECOMPRESSION_FAILURE = 24,
[email protected]8b37a092012-10-18 21:53:49445 // We hit our prenegotiated (or default) timeout
[email protected]89264042013-08-21 07:35:24446 QUIC_CONNECTION_TIMED_OUT = 25,
[email protected]899951652013-05-16 12:52:39447 // There was an error encountered migrating addresses
[email protected]89264042013-08-21 07:35:24448 QUIC_ERROR_MIGRATING_ADDRESS = 26,
[email protected]1505a512013-09-04 22:59:35449 // There was an error while writing to the socket.
[email protected]89264042013-08-21 07:35:24450 QUIC_PACKET_WRITE_ERROR = 27,
[email protected]1505a512013-09-04 22:59:35451 // There was an error while reading from the socket.
452 QUIC_PACKET_READ_ERROR = 51,
[email protected]24e5bc52013-09-18 15:36:58453 // We received a STREAM_FRAME with no data and no fin flag set.
454 QUIC_INVALID_STREAM_FRAME = 50,
[email protected]4d640792013-12-18 22:21:08455 // We received invalid data on the headers stream.
456 QUIC_INVALID_HEADERS_STREAM_DATA = 56,
[email protected]730b35d72014-06-05 03:23:22457 // The peer received too much data, violating flow control.
458 QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA = 59,
459 // The peer sent too much data, violating flow control.
460 QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA = 63,
461 // The peer received an invalid flow control window.
462 QUIC_FLOW_CONTROL_INVALID_WINDOW = 64,
[email protected]71c84e592014-05-28 23:39:29463 // The connection has been IP pooled into an existing connection.
464 QUIC_CONNECTION_IP_POOLED = 62,
[email protected]8b37a092012-10-18 21:53:49465
466 // Crypto errors.
467
[email protected]1354bf62013-05-23 23:17:18468 // Hanshake failed.
[email protected]89264042013-08-21 07:35:24469 QUIC_HANDSHAKE_FAILED = 28,
[email protected]8b37a092012-10-18 21:53:49470 // Handshake message contained out of order tags.
[email protected]89264042013-08-21 07:35:24471 QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29,
[email protected]701bc892013-01-17 04:51:54472 // Handshake message contained too many entries.
[email protected]89264042013-08-21 07:35:24473 QUIC_CRYPTO_TOO_MANY_ENTRIES = 30,
[email protected]8b37a092012-10-18 21:53:49474 // Handshake message contained an invalid value length.
[email protected]89264042013-08-21 07:35:24475 QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31,
[email protected]8b37a092012-10-18 21:53:49476 // A crypto message was received after the handshake was complete.
[email protected]89264042013-08-21 07:35:24477 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32,
[email protected]d3d15bf2013-01-30 02:51:54478 // A crypto message was received with an illegal message tag.
[email protected]89264042013-08-21 07:35:24479 QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33,
[email protected]d3d15bf2013-01-30 02:51:54480 // A crypto message was received with an illegal parameter.
[email protected]89264042013-08-21 07:35:24481 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34,
[email protected]752fbe52013-10-14 08:35:32482 // An invalid channel id signature was supplied.
483 QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52,
[email protected]d3d15bf2013-01-30 02:51:54484 // A crypto message was received with a mandatory parameter missing.
[email protected]89264042013-08-21 07:35:24485 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35,
[email protected]d3d15bf2013-01-30 02:51:54486 // A crypto message was received with a parameter that has no overlap
487 // with the local parameter.
[email protected]89264042013-08-21 07:35:24488 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36,
[email protected]ed3fc15d2013-03-08 18:37:44489 // A crypto message was received that contained a parameter with too few
490 // values.
[email protected]89264042013-08-21 07:35:24491 QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37,
[email protected]ccc66e8a2013-03-26 08:26:14492 // An internal error occured in crypto processing.
[email protected]89264042013-08-21 07:35:24493 QUIC_CRYPTO_INTERNAL_ERROR = 38,
[email protected]ccc66e8a2013-03-26 08:26:14494 // A crypto handshake message specified an unsupported version.
[email protected]89264042013-08-21 07:35:24495 QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39,
[email protected]ccc66e8a2013-03-26 08:26:14496 // There was no intersection between the crypto primitives supported by the
497 // peer and ourselves.
[email protected]89264042013-08-21 07:35:24498 QUIC_CRYPTO_NO_SUPPORT = 40,
[email protected]ef95114d2013-04-17 17:57:01499 // The server rejected our client hello messages too many times.
[email protected]89264042013-08-21 07:35:24500 QUIC_CRYPTO_TOO_MANY_REJECTS = 41,
[email protected]a57e0272013-04-26 07:31:47501 // The client rejected the server's certificate chain or signature.
[email protected]89264042013-08-21 07:35:24502 QUIC_PROOF_INVALID = 42,
[email protected]8ba81212013-05-03 13:11:48503 // A crypto message was received with a duplicate tag.
[email protected]89264042013-08-21 07:35:24504 QUIC_CRYPTO_DUPLICATE_TAG = 43,
[email protected]2532de12013-05-09 12:29:33505 // A crypto message was received with the wrong encryption level (i.e. it
506 // should have been encrypted but was not.)
[email protected]89264042013-08-21 07:35:24507 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44,
[email protected]2532de12013-05-09 12:29:33508 // The server config for a server has expired.
[email protected]89264042013-08-21 07:35:24509 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45,
[email protected]752fbe52013-10-14 08:35:32510 // We failed to setup the symmetric keys for a connection.
511 QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53,
[email protected]691f45a982013-11-19 10:52:04512 // A handshake message arrived, but we are still validating the
513 // previous handshake message.
514 QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54,
[email protected]d89f1862013-11-26 21:21:27515 // This connection involved a version negotiation which appears to have been
516 // tampered with.
517 QUIC_VERSION_NEGOTIATION_MISMATCH = 55,
[email protected]ccc66e8a2013-03-26 08:26:14518
[email protected]74bda142013-03-31 02:49:11519 // No error. Used as bound while iterating.
[email protected]730b35d72014-06-05 03:23:22520 QUIC_LAST_ERROR = 65,
[email protected]8b37a092012-10-18 21:53:49521};
522
[email protected]c995c572013-01-18 05:43:20523struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
[email protected]14e8106c2013-03-14 16:25:33524 QuicPacketPublicHeader();
525 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
526 ~QuicPacketPublicHeader();
527
[email protected]3aa9ca72014-02-27 19:39:43528 // Universal header. All QuicPacket headers will have a connection_id and
529 // public flags.
530 QuicConnectionId connection_id;
531 QuicConnectionIdLength connection_id_length;
[email protected]9db443912013-02-25 05:27:03532 bool reset_flag;
533 bool version_flag;
[email protected]25c31dc2013-06-05 17:56:04534 QuicSequenceNumberLength sequence_number_length;
[email protected]48878092013-07-26 14:51:56535 QuicVersionVector versions;
[email protected]c995c572013-01-18 05:43:20536};
537
538// Header for Data or FEC packets.
[email protected]74bda142013-03-31 02:49:11539struct NET_EXPORT_PRIVATE QuicPacketHeader {
540 QuicPacketHeader();
541 explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
[email protected]9db443912013-02-25 05:27:03542
543 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
544 std::ostream& os, const QuicPacketHeader& s);
545
[email protected]c995c572013-01-18 05:43:20546 QuicPacketPublicHeader public_header;
[email protected]9db443912013-02-25 05:27:03547 bool fec_flag;
[email protected]9db443912013-02-25 05:27:03548 bool entropy_flag;
549 QuicPacketEntropyHash entropy_hash;
[email protected]8b37a092012-10-18 21:53:49550 QuicPacketSequenceNumber packet_sequence_number;
[email protected]b064310782013-05-30 21:12:17551 InFecGroup is_in_fec_group;
[email protected]8b37a092012-10-18 21:53:49552 QuicFecGroupNumber fec_group;
553};
554
[email protected]74bda142013-03-31 02:49:11555struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
[email protected]6ae6e342014-02-06 02:21:42556 QuicPublicResetPacket();
557 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header);
558
[email protected]86a318d2013-01-23 21:16:04559 QuicPacketPublicHeader public_header;
[email protected]86a318d2013-01-23 21:16:04560 QuicPublicResetNonceProof nonce_proof;
[email protected]300ccd52014-01-25 08:00:19561 QuicPacketSequenceNumber rejected_sequence_number;
[email protected]79d13dcb2014-02-05 07:23:13562 IPEndPoint client_address;
[email protected]86a318d2013-01-23 21:16:04563};
564
[email protected]14e8106c2013-03-14 16:25:33565enum QuicVersionNegotiationState {
566 START_NEGOTIATION = 0,
[email protected]ec640112013-08-09 03:56:18567 // Server-side this implies we've sent a version negotiation packet and are
568 // waiting on the client to select a compatible version. Client-side this
569 // implies we've gotten a version negotiation packet, are retransmitting the
570 // initial packets with a supported version and are waiting for our first
571 // packet from the server.
572 NEGOTIATION_IN_PROGRESS,
573 // This indicates this endpoint has received a packet from the peer with a
574 // version this endpoint supports. Version negotiation is complete, and the
575 // version number will no longer be sent with future packets.
[email protected]14e8106c2013-03-14 16:25:33576 NEGOTIATED_VERSION
577};
578
579typedef QuicPacketPublicHeader QuicVersionNegotiationPacket;
580
[email protected]c995c572013-01-18 05:43:20581// A padding frame contains no payload.
582struct NET_EXPORT_PRIVATE QuicPaddingFrame {
583};
584
[email protected]d8c522112014-04-23 09:23:25585// A ping frame contains no payload, though it is retransmittable,
586// and ACK'd just like other normal frames.
587struct NET_EXPORT_PRIVATE QuicPingFrame {
588};
589
[email protected]be24ab22012-10-22 03:01:52590struct NET_EXPORT_PRIVATE QuicStreamFrame {
591 QuicStreamFrame();
[email protected]5dafdb62013-11-14 01:24:26592 QuicStreamFrame(const QuicStreamFrame& frame);
[email protected]be24ab22012-10-22 03:01:52593 QuicStreamFrame(QuicStreamId stream_id,
[email protected]a5061242012-10-23 23:29:37594 bool fin,
[email protected]701bc892013-01-17 04:51:54595 QuicStreamOffset offset,
[email protected]5dafdb62013-11-14 01:24:26596 IOVector data);
597
[email protected]c5e1aca2014-01-30 04:03:04598 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
599 std::ostream& os, const QuicStreamFrame& s);
600
[email protected]5dafdb62013-11-14 01:24:26601 // Returns a copy of the IOVector |data| as a heap-allocated string.
602 // Caller must take ownership of the returned string.
603 std::string* GetDataAsString() const;
[email protected]8b37a092012-10-18 21:53:49604
605 QuicStreamId stream_id;
606 bool fin;
[email protected]701bc892013-01-17 04:51:54607 QuicStreamOffset offset; // Location of this data in the stream.
[email protected]5dafdb62013-11-14 01:24:26608 IOVector data;
[email protected]97cf3022013-09-05 14:30:16609
610 // If this is set, then when this packet is ACKed the AckNotifier will be
611 // informed.
612 QuicAckNotifier* notifier;
[email protected]8b37a092012-10-18 21:53:49613};
614
[email protected]e537f742012-12-07 15:33:53615// TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
616// is finalized.
[email protected]9db443912013-02-25 05:27:03617typedef std::set<QuicPacketSequenceNumber> SequenceNumberSet;
[email protected]3c5f4a732013-01-12 16:45:34618// TODO(pwestin): Add a way to enforce the max size of this map.
[email protected]e537f742012-12-07 15:33:53619typedef std::map<QuicPacketSequenceNumber, QuicTime> TimeMap;
[email protected]044ac2b2012-11-13 21:41:06620
[email protected]8b37a092012-10-18 21:53:49621struct NET_EXPORT_PRIVATE ReceivedPacketInfo {
622 ReceivedPacketInfo();
623 ~ReceivedPacketInfo();
[email protected]6ae6e342014-02-06 02:21:42624
[email protected]26f3f8e2012-12-13 21:07:19625 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
626 std::ostream& os, const ReceivedPacketInfo& s);
[email protected]a674b4c2012-12-05 03:44:30627
[email protected]9db443912013-02-25 05:27:03628 // Entropy hash of all packets up to largest observed not including missing
629 // packets.
630 QuicPacketEntropyHash entropy_hash;
[email protected]e537f742012-12-07 15:33:53631
[email protected]48697d8a2013-01-15 19:42:24632 // The highest packet sequence number we've observed from the peer.
633 //
634 // In general, this should be the largest packet number we've received. In
635 // the case of truncated acks, we may have to advertise a lower "upper bound"
636 // than largest received, to avoid implicitly acking missing packets that
637 // don't fit in the missing packet list due to size limitations. In this
638 // case, largest_observed may be a packet which is also in the missing packets
639 // list.
640 QuicPacketSequenceNumber largest_observed;
[email protected]a674b4c2012-12-05 03:44:30641
[email protected]14e8106c2013-03-14 16:25:33642 // Time elapsed since largest_observed was received until this Ack frame was
643 // sent.
644 QuicTime::Delta delta_time_largest_observed;
645
[email protected]9db443912013-02-25 05:27:03646 // TODO(satyamshekhar): Can be optimized using an interval set like data
647 // structure.
[email protected]e537f742012-12-07 15:33:53648 // The set of packets which we're expecting and have not received.
[email protected]9db443912013-02-25 05:27:03649 SequenceNumberSet missing_packets;
[email protected]8e01c062013-10-31 07:35:31650
651 // Whether the ack had to be truncated when sent.
652 bool is_truncated;
[email protected]bdf2d432014-02-09 10:45:41653
654 // Packets which have been revived via FEC.
655 // All of these must also be in missing_packets.
656 SequenceNumberSet revived_packets;
[email protected]8b37a092012-10-18 21:53:49657};
658
[email protected]9db443912013-02-25 05:27:03659// True if the sequence number is greater than largest_observed or is listed
660// as missing.
661// Always returns false for sequence numbers less than least_unacked.
662bool NET_EXPORT_PRIVATE IsAwaitingPacket(
663 const ReceivedPacketInfo& received_info,
664 QuicPacketSequenceNumber sequence_number);
665
666// Inserts missing packets between [lower, higher).
667void NET_EXPORT_PRIVATE InsertMissingPacketsBetween(
668 ReceivedPacketInfo* received_info,
669 QuicPacketSequenceNumber lower,
670 QuicPacketSequenceNumber higher);
671
[email protected]93dd91f2014-02-27 00:09:03672struct NET_EXPORT_PRIVATE QuicStopWaitingFrame {
673 QuicStopWaitingFrame();
674 ~QuicStopWaitingFrame();
[email protected]6ae6e342014-02-06 02:21:42675
[email protected]26f3f8e2012-12-13 21:07:19676 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
[email protected]93dd91f2014-02-27 00:09:03677 std::ostream& os, const QuicStopWaitingFrame& s);
678
[email protected]9db443912013-02-25 05:27:03679 // Entropy hash of all packets up to, but not including, the least unacked
680 // packet.
681 QuicPacketEntropyHash entropy_hash;
[email protected]8b37a092012-10-18 21:53:49682 // The lowest packet we've sent which is unacked, and we expect an ack for.
683 QuicPacketSequenceNumber least_unacked;
[email protected]8b37a092012-10-18 21:53:49684};
685
[email protected]26f3f8e2012-12-13 21:07:19686struct NET_EXPORT_PRIVATE QuicAckFrame {
[email protected]6ae6e342014-02-06 02:21:42687 QuicAckFrame();
[email protected]26f3f8e2012-12-13 21:07:19688
689 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
690 std::ostream& os, const QuicAckFrame& s);
691
[email protected]93dd91f2014-02-27 00:09:03692 QuicStopWaitingFrame sent_info;
[email protected]26f3f8e2012-12-13 21:07:19693 ReceivedPacketInfo received_info;
694};
695
[email protected]8b37a092012-10-18 21:53:49696// Defines for all types of congestion feedback that will be negotiated in QUIC,
[email protected]f62262b2013-07-05 20:57:30697// kTCP MUST be supported by all QUIC implementations to guarantee 100%
[email protected]8b37a092012-10-18 21:53:49698// compatibility.
699enum CongestionFeedbackType {
[email protected]8b37a092012-10-18 21:53:49700 kTCP, // Used to mimic TCP.
701 kInterArrival, // Use additional inter arrival information.
702 kFixRate, // Provided for testing.
[email protected]ce7bb1412014-05-17 15:51:33703 kTCPBBR, // BBR implementation based on TCP congestion feedback.
[email protected]8b37a092012-10-18 21:53:49704};
705
[email protected]c5cc9bd2014-03-31 23:17:14706enum LossDetectionType {
707 kNack, // Used to mimic TCP's loss detection.
708 kTime, // Time based loss detection.
709};
710
[email protected]8b37a092012-10-18 21:53:49711struct NET_EXPORT_PRIVATE CongestionFeedbackMessageTCP {
[email protected]6ae6e342014-02-06 02:21:42712 CongestionFeedbackMessageTCP();
713
[email protected]fee17f72013-02-03 07:47:41714 QuicByteCount receive_window;
[email protected]8b37a092012-10-18 21:53:49715};
716
717struct NET_EXPORT_PRIVATE CongestionFeedbackMessageInterArrival {
[email protected]7884ecad2012-12-14 22:55:15718 CongestionFeedbackMessageInterArrival();
719 ~CongestionFeedbackMessageInterArrival();
[email protected]6ae6e342014-02-06 02:21:42720
[email protected]7884ecad2012-12-14 22:55:15721 // The set of received packets since the last feedback was sent, along with
722 // their arrival times.
723 TimeMap received_packet_times;
[email protected]8b37a092012-10-18 21:53:49724};
725
[email protected]8b37a092012-10-18 21:53:49726struct NET_EXPORT_PRIVATE CongestionFeedbackMessageFixRate {
[email protected]fee17f72013-02-03 07:47:41727 CongestionFeedbackMessageFixRate();
728 QuicBandwidth bitrate;
[email protected]8b37a092012-10-18 21:53:49729};
730
[email protected]26f3f8e2012-12-13 21:07:19731struct NET_EXPORT_PRIVATE QuicCongestionFeedbackFrame {
[email protected]7884ecad2012-12-14 22:55:15732 QuicCongestionFeedbackFrame();
733 ~QuicCongestionFeedbackFrame();
734
[email protected]26f3f8e2012-12-13 21:07:19735 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
736 std::ostream& os, const QuicCongestionFeedbackFrame& c);
737
[email protected]7884ecad2012-12-14 22:55:15738 CongestionFeedbackType type;
739 // This should really be a union, but since the inter arrival struct
740 // is non-trivial, C++ prohibits it.
741 CongestionFeedbackMessageTCP tcp;
742 CongestionFeedbackMessageInterArrival inter_arrival;
743 CongestionFeedbackMessageFixRate fix_rate;
[email protected]8b37a092012-10-18 21:53:49744};
745
[email protected]be24ab22012-10-22 03:01:52746struct NET_EXPORT_PRIVATE QuicRstStreamFrame {
[email protected]6ae6e342014-02-06 02:21:42747 QuicRstStreamFrame();
748 QuicRstStreamFrame(QuicStreamId stream_id,
749 QuicRstStreamErrorCode error_code,
750 QuicStreamOffset bytes_written);
[email protected]8b37a092012-10-18 21:53:49751
[email protected]c5e1aca2014-01-30 04:03:04752 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
753 std::ostream& os, const QuicRstStreamFrame& r);
754
[email protected]8b37a092012-10-18 21:53:49755 QuicStreamId stream_id;
[email protected]74bda142013-03-31 02:49:11756 QuicRstStreamErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09757 std::string error_details;
[email protected]6ae6e342014-02-06 02:21:42758
759 // Used to update flow control windows. On termination of a stream, both
760 // endpoints must inform the peer of the number of bytes they have sent on
761 // that stream. This can be done through normal termination (data packet with
762 // FIN) or through a RST.
763 QuicStreamOffset byte_offset;
[email protected]8b37a092012-10-18 21:53:49764};
765
[email protected]be24ab22012-10-22 03:01:52766struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame {
[email protected]6ae6e342014-02-06 02:21:42767 QuicConnectionCloseFrame();
768
[email protected]c5e1aca2014-01-30 04:03:04769 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
770 std::ostream& os, const QuicConnectionCloseFrame& c);
771
[email protected]431bb4fd2012-10-19 17:46:09772 QuicErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09773 std::string error_details;
[email protected]8b37a092012-10-18 21:53:49774};
775
[email protected]9db443912013-02-25 05:27:03776struct NET_EXPORT_PRIVATE QuicGoAwayFrame {
[email protected]6ae6e342014-02-06 02:21:42777 QuicGoAwayFrame();
[email protected]9db443912013-02-25 05:27:03778 QuicGoAwayFrame(QuicErrorCode error_code,
779 QuicStreamId last_good_stream_id,
780 const std::string& reason);
781
[email protected]c5e1aca2014-01-30 04:03:04782 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
783 std::ostream& os, const QuicGoAwayFrame& g);
784
[email protected]9db443912013-02-25 05:27:03785 QuicErrorCode error_code;
786 QuicStreamId last_good_stream_id;
787 std::string reason_phrase;
788};
789
[email protected]6ae6e342014-02-06 02:21:42790// Flow control updates per-stream and at the connection levoel.
791// Based on SPDY's WINDOW_UPDATE frame, but uses an absolute byte offset rather
792// than a window delta.
793// TODO(rjshade): A possible future optimization is to make stream_id and
794// byte_offset variable length, similar to stream frames.
795struct NET_EXPORT_PRIVATE QuicWindowUpdateFrame {
796 QuicWindowUpdateFrame() {}
797 QuicWindowUpdateFrame(QuicStreamId stream_id, QuicStreamOffset byte_offset);
798
799 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
800 std::ostream& os, const QuicWindowUpdateFrame& w);
801
802 // The stream this frame applies to. 0 is a special case meaning the overall
803 // connection rather than a specific stream.
804 QuicStreamId stream_id;
805
806 // Byte offset in the stream or connection. The receiver of this frame must
807 // not send data which would result in this offset being exceeded.
808 QuicStreamOffset byte_offset;
809};
810
811// The BLOCKED frame is used to indicate to the remote endpoint that this
812// endpoint believes itself to be flow-control blocked but otherwise ready to
813// send data. The BLOCKED frame is purely advisory and optional.
814// Based on SPDY's BLOCKED frame (undocumented as of 2014-01-28).
815struct NET_EXPORT_PRIVATE QuicBlockedFrame {
816 QuicBlockedFrame() {}
817 explicit QuicBlockedFrame(QuicStreamId stream_id);
818
819 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
820 std::ostream& os, const QuicBlockedFrame& b);
821
822 // The stream this frame applies to. 0 is a special case meaning the overall
823 // connection rather than a specific stream.
824 QuicStreamId stream_id;
825};
826
[email protected]8ba81212013-05-03 13:11:48827// EncryptionLevel enumerates the stages of encryption that a QUIC connection
828// progresses through. When retransmitting a packet, the encryption level needs
829// to be specified so that it is retransmitted at a level which the peer can
830// understand.
831enum EncryptionLevel {
832 ENCRYPTION_NONE = 0,
833 ENCRYPTION_INITIAL = 1,
834 ENCRYPTION_FORWARD_SECURE = 2,
835
836 NUM_ENCRYPTION_LEVELS,
837};
838
[email protected]be24ab22012-10-22 03:01:52839struct NET_EXPORT_PRIVATE QuicFrame {
[email protected]6ae6e342014-02-06 02:21:42840 QuicFrame();
841 explicit QuicFrame(QuicPaddingFrame* padding_frame);
842 explicit QuicFrame(QuicStreamFrame* stream_frame);
843 explicit QuicFrame(QuicAckFrame* frame);
844 explicit QuicFrame(QuicCongestionFeedbackFrame* frame);
845 explicit QuicFrame(QuicRstStreamFrame* frame);
846 explicit QuicFrame(QuicConnectionCloseFrame* frame);
[email protected]93dd91f2014-02-27 00:09:03847 explicit QuicFrame(QuicStopWaitingFrame* frame);
[email protected]d8c522112014-04-23 09:23:25848 explicit QuicFrame(QuicPingFrame* frame);
[email protected]6ae6e342014-02-06 02:21:42849 explicit QuicFrame(QuicGoAwayFrame* frame);
850 explicit QuicFrame(QuicWindowUpdateFrame* frame);
851 explicit QuicFrame(QuicBlockedFrame* frame);
[email protected]8b37a092012-10-18 21:53:49852
[email protected]c5e1aca2014-01-30 04:03:04853 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
854 std::ostream& os, const QuicFrame& frame);
855
[email protected]be24ab22012-10-22 03:01:52856 QuicFrameType type;
[email protected]8b37a092012-10-18 21:53:49857 union {
[email protected]c995c572013-01-18 05:43:20858 QuicPaddingFrame* padding_frame;
[email protected]be24ab22012-10-22 03:01:52859 QuicStreamFrame* stream_frame;
860 QuicAckFrame* ack_frame;
[email protected]26f3f8e2012-12-13 21:07:19861 QuicCongestionFeedbackFrame* congestion_feedback_frame;
[email protected]93dd91f2014-02-27 00:09:03862 QuicStopWaitingFrame* stop_waiting_frame;
[email protected]d8c522112014-04-23 09:23:25863 QuicPingFrame* ping_frame;
[email protected]be24ab22012-10-22 03:01:52864 QuicRstStreamFrame* rst_stream_frame;
865 QuicConnectionCloseFrame* connection_close_frame;
[email protected]9db443912013-02-25 05:27:03866 QuicGoAwayFrame* goaway_frame;
[email protected]6ae6e342014-02-06 02:21:42867 QuicWindowUpdateFrame* window_update_frame;
868 QuicBlockedFrame* blocked_frame;
[email protected]8b37a092012-10-18 21:53:49869 };
870};
871
[email protected]be24ab22012-10-22 03:01:52872typedef std::vector<QuicFrame> QuicFrames;
[email protected]8b37a092012-10-18 21:53:49873
874struct NET_EXPORT_PRIVATE QuicFecData {
875 QuicFecData();
[email protected]a5061242012-10-23 23:29:37876
[email protected]c995c572013-01-18 05:43:20877 // The FEC group number is also the sequence number of the first
878 // FEC protected packet. The last protected packet's sequence number will
879 // be one less than the sequence number of the FEC packet.
[email protected]8b37a092012-10-18 21:53:49880 QuicFecGroupNumber fec_group;
[email protected]8b37a092012-10-18 21:53:49881 base::StringPiece redundancy;
[email protected]8b37a092012-10-18 21:53:49882};
883
[email protected]8b37a092012-10-18 21:53:49884class NET_EXPORT_PRIVATE QuicData {
885 public:
[email protected]6ae6e342014-02-06 02:21:42886 QuicData(const char* buffer, size_t length);
887 QuicData(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:49888 virtual ~QuicData();
889
890 base::StringPiece AsStringPiece() const {
891 return base::StringPiece(data(), length());
892 }
893
894 const char* data() const { return buffer_; }
895 size_t length() const { return length_; }
896
897 private:
898 const char* buffer_;
899 size_t length_;
900 bool owns_buffer_;
901
902 DISALLOW_COPY_AND_ASSIGN(QuicData);
903};
904
905class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
906 public:
[email protected]25c31dc2013-06-05 17:56:04907 static QuicPacket* NewDataPacket(
908 char* buffer,
909 size_t length,
910 bool owns_buffer,
[email protected]3aa9ca72014-02-27 19:39:43911 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04912 bool includes_version,
913 QuicSequenceNumberLength sequence_number_length) {
[email protected]3aa9ca72014-02-27 19:39:43914 return new QuicPacket(buffer, length, owns_buffer, connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04915 includes_version, sequence_number_length, false);
[email protected]c995c572013-01-18 05:43:20916 }
917
[email protected]25c31dc2013-06-05 17:56:04918 static QuicPacket* NewFecPacket(
919 char* buffer,
920 size_t length,
921 bool owns_buffer,
[email protected]3aa9ca72014-02-27 19:39:43922 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04923 bool includes_version,
924 QuicSequenceNumberLength sequence_number_length) {
[email protected]3aa9ca72014-02-27 19:39:43925 return new QuicPacket(buffer, length, owns_buffer, connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04926 includes_version, sequence_number_length, true);
[email protected]c995c572013-01-18 05:43:20927 }
[email protected]8b37a092012-10-18 21:53:49928
[email protected]5351cc4b2013-03-03 07:22:41929 base::StringPiece FecProtectedData() const;
930 base::StringPiece AssociatedData() const;
931 base::StringPiece BeforePlaintext() const;
932 base::StringPiece Plaintext() const;
[email protected]082b65b2012-11-10 19:11:31933
[email protected]c995c572013-01-18 05:43:20934 bool is_fec_packet() const { return is_fec_packet_; }
[email protected]082b65b2012-11-10 19:11:31935
[email protected]8b37a092012-10-18 21:53:49936 char* mutable_data() { return buffer_; }
937
938 private:
[email protected]5351cc4b2013-03-03 07:22:41939 QuicPacket(char* buffer,
940 size_t length,
941 bool owns_buffer,
[email protected]3aa9ca72014-02-27 19:39:43942 QuicConnectionIdLength connection_id_length,
[email protected]5351cc4b2013-03-03 07:22:41943 bool includes_version,
[email protected]25c31dc2013-06-05 17:56:04944 QuicSequenceNumberLength sequence_number_length,
[email protected]6ae6e342014-02-06 02:21:42945 bool is_fec_packet);
[email protected]c995c572013-01-18 05:43:20946
[email protected]8b37a092012-10-18 21:53:49947 char* buffer_;
[email protected]c995c572013-01-18 05:43:20948 const bool is_fec_packet_;
[email protected]3aa9ca72014-02-27 19:39:43949 const QuicConnectionIdLength connection_id_length_;
[email protected]5351cc4b2013-03-03 07:22:41950 const bool includes_version_;
[email protected]25c31dc2013-06-05 17:56:04951 const QuicSequenceNumberLength sequence_number_length_;
[email protected]8b37a092012-10-18 21:53:49952
[email protected]2e740db2012-10-20 19:35:19953 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
[email protected]8b37a092012-10-18 21:53:49954};
955
956class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
957 public:
[email protected]6ae6e342014-02-06 02:21:42958 QuicEncryptedPacket(const char* buffer, size_t length);
959 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:49960
[email protected]ec86d5462013-11-17 16:04:49961 // Clones the packet into a new packet which owns the buffer.
962 QuicEncryptedPacket* Clone() const;
963
[email protected]c1b32c62013-01-20 02:49:10964 // By default, gtest prints the raw bytes of an object. The bool data
965 // member (in the base class QuicData) causes this object to have padding
966 // bytes, which causes the default gtest object printer to read
967 // uninitialize memory. So we need to teach gtest how to print this object.
968 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
969 std::ostream& os, const QuicEncryptedPacket& s);
970
[email protected]2e740db2012-10-20 19:35:19971 private:
972 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
[email protected]8b37a092012-10-18 21:53:49973};
974
[email protected]9db443912013-02-25 05:27:03975class NET_EXPORT_PRIVATE RetransmittableFrames {
976 public:
977 RetransmittableFrames();
978 ~RetransmittableFrames();
979
980 // Allocates a local copy of the referenced StringPiece has QuicStreamFrame
981 // use it.
982 // Takes ownership of |stream_frame|.
983 const QuicFrame& AddStreamFrame(QuicStreamFrame* stream_frame);
984 // Takes ownership of the frame inside |frame|.
985 const QuicFrame& AddNonStreamFrame(const QuicFrame& frame);
986 const QuicFrames& frames() const { return frames_; }
987
[email protected]2115d33ba2014-01-02 21:53:52988 IsHandshake HasCryptoHandshake() const;
989
[email protected]8ba81212013-05-03 13:11:48990 void set_encryption_level(EncryptionLevel level);
991 EncryptionLevel encryption_level() const {
992 return encryption_level_;
993 }
994
[email protected]9db443912013-02-25 05:27:03995 private:
996 QuicFrames frames_;
[email protected]8ba81212013-05-03 13:11:48997 EncryptionLevel encryption_level_;
[email protected]9db443912013-02-25 05:27:03998 // Data referenced by the StringPiece of a QuicStreamFrame.
999 std::vector<std::string*> stream_data_;
1000
1001 DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames);
1002};
1003
1004struct NET_EXPORT_PRIVATE SerializedPacket {
1005 SerializedPacket(QuicPacketSequenceNumber sequence_number,
[email protected]ea825e02013-08-21 18:12:451006 QuicSequenceNumberLength sequence_number_length,
[email protected]9db443912013-02-25 05:27:031007 QuicPacket* packet,
1008 QuicPacketEntropyHash entropy_hash,
[email protected]97cf3022013-09-05 14:30:161009 RetransmittableFrames* retransmittable_frames);
1010 ~SerializedPacket();
[email protected]9db443912013-02-25 05:27:031011
1012 QuicPacketSequenceNumber sequence_number;
[email protected]ea825e02013-08-21 18:12:451013 QuicSequenceNumberLength sequence_number_length;
[email protected]9db443912013-02-25 05:27:031014 QuicPacket* packet;
1015 QuicPacketEntropyHash entropy_hash;
1016 RetransmittableFrames* retransmittable_frames;
[email protected]97cf3022013-09-05 14:30:161017
1018 // If set, these will be called when this packet is ACKed by the peer.
1019 std::set<QuicAckNotifier*> notifiers;
[email protected]9db443912013-02-25 05:27:031020};
1021
[email protected]77b5d50b2014-05-07 22:48:481022struct NET_EXPORT_PRIVATE TransmissionInfo {
1023 // Used by STL when assigning into a map.
1024 TransmissionInfo();
1025
1026 // Constructs a Transmission with a new all_tranmissions set
1027 // containing |sequence_number|.
1028 TransmissionInfo(RetransmittableFrames* retransmittable_frames,
1029 QuicPacketSequenceNumber sequence_number,
1030 QuicSequenceNumberLength sequence_number_length);
1031
1032 // Constructs a Transmission with the specified |all_tranmissions| set
1033 // and inserts |sequence_number| into it.
1034 TransmissionInfo(RetransmittableFrames* retransmittable_frames,
1035 QuicPacketSequenceNumber sequence_number,
1036 QuicSequenceNumberLength sequence_number_length,
[email protected]730b35d72014-06-05 03:23:221037 TransmissionType transmission_type,
[email protected]77b5d50b2014-05-07 22:48:481038 SequenceNumberSet* all_transmissions);
1039
1040 RetransmittableFrames* retransmittable_frames;
1041 QuicSequenceNumberLength sequence_number_length;
1042 // Zero when the packet is serialized, non-zero once it's sent.
1043 QuicTime sent_time;
1044 // Zero when the packet is serialized, non-zero once it's sent.
1045 QuicByteCount bytes_sent;
1046 size_t nack_count;
[email protected]730b35d72014-06-05 03:23:221047 // Reason why this packet was transmitted.
1048 TransmissionType transmission_type;
[email protected]77b5d50b2014-05-07 22:48:481049 // Stores the sequence numbers of all transmissions of this packet.
1050 // Can never be null.
1051 SequenceNumberSet* all_transmissions;
[email protected]aa7e4ef2014-05-28 03:53:151052 // In flight packets have not been abandoned or lost.
1053 bool in_flight;
[email protected]77b5d50b2014-05-07 22:48:481054};
1055
[email protected]8b37a092012-10-18 21:53:491056} // namespace net
1057
1058#endif // NET_QUIC_QUIC_PROTOCOL_H_