blob: c586c1d20b9ab328ae62815093cd2ac3a17ce9d1 [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]8e01c062013-10-31 07:35:3160
61// Maximum size of the initial congestion window in packets.
62const size_t kDefaultInitialWindow = 10;
[email protected]93dd91f2014-02-27 00:09:0363const size_t kMaxInitialWindow = 100;
[email protected]8e01c062013-10-31 07:35:3164
[email protected]9bb57c72014-03-31 20:36:0465// Default size of initial flow control window.
66const uint32 kDefaultFlowControlSendWindow = 16 * 1024; // 16 KB
67
[email protected]0ac0c5b2013-11-20 05:55:5868// Maximum size of the congestion window, in packets, for TCP congestion control
69// algorithms.
70const size_t kMaxTcpCongestionWindow = 200;
71
[email protected]8e01c062013-10-31 07:35:3172// Don't allow a client to suggest an RTT longer than 15 seconds.
[email protected]e18e1072013-11-12 22:06:0773const size_t kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond;
[email protected]8b37a092012-10-18 21:53:4974
75// Maximum number of open streams per connection.
76const size_t kDefaultMaxStreamsPerConnection = 100;
77
[email protected]af806e62013-05-22 14:47:5078// Number of bytes reserved for public flags in the packet header.
79const size_t kPublicFlagsSize = 1;
[email protected]5351cc4b2013-03-03 07:22:4180// Number of bytes reserved for version number in the packet header.
81const size_t kQuicVersionSize = 4;
[email protected]c995c572013-01-18 05:43:2082// Number of bytes reserved for private flags in the packet header.
83const size_t kPrivateFlagsSize = 1;
84// Number of bytes reserved for FEC group in the packet header.
85const size_t kFecGroupSize = 1;
[email protected]79d13dcb2014-02-05 07:23:1386// TODO(wtc): remove this when we drop support for QUIC_VERSION_13.
[email protected]86a318d2013-01-23 21:16:0487// Number of bytes reserved for the nonce proof in public reset packet.
88const size_t kPublicResetNonceSize = 8;
[email protected]5351cc4b2013-03-03 07:22:4189
90// Signifies that the QuicPacket will contain version of the protocol.
91const bool kIncludeVersion = true;
[email protected]c995c572013-01-18 05:43:2092
[email protected]5351cc4b2013-03-03 07:22:4193// Index of the first byte in a QUIC packet which is used in hash calculation.
94const size_t kStartOfHashData = 0;
[email protected]8b37a092012-10-18 21:53:4995
96// Limit on the delta between stream IDs.
[email protected]c5cc9bd2014-03-31 23:17:1497const QuicStreamId kMaxStreamIdDelta = 200;
[email protected]c244c5a12013-05-07 20:55:0498// Limit on the delta between header IDs.
[email protected]c5cc9bd2014-03-31 23:17:1499const QuicHeaderId kMaxHeaderIdDelta = 200;
[email protected]8b37a092012-10-18 21:53:49100
101// Reserved ID for the crypto stream.
[email protected]8b37a092012-10-18 21:53:49102const QuicStreamId kCryptoStreamId = 1;
103
[email protected]4d640792013-12-18 22:21:08104// Reserved ID for the headers stream.
105const QuicStreamId kHeadersStreamId = 3;
106
[email protected]899951652013-05-16 12:52:39107// This is the default network timeout a for connection till the crypto
108// handshake succeeds and the negotiated timeout from the handshake is received.
[email protected]b064310782013-05-30 21:12:17109const int64 kDefaultInitialTimeoutSecs = 120; // 2 mins.
[email protected]899951652013-05-16 12:52:39110const int64 kDefaultTimeoutSecs = 60 * 10; // 10 minutes.
[email protected]b064310782013-05-30 21:12:17111const int64 kDefaultMaxTimeForCryptoHandshakeSecs = 5; // 5 secs.
[email protected]8b37a092012-10-18 21:53:49112
[email protected]b007e632013-10-28 08:39:25113// We define an unsigned 16-bit floating point value, inspired by IEEE floats
114// (http://en.wikipedia.org/wiki/Half_precision_floating-point_format),
115// with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden
116// bit) and denormals, but without signs, transfinites or fractions. Wire format
117// 16 bits (little-endian byte order) are split into exponent (high 5) and
118// mantissa (low 11) and decoded as:
119// uint64 value;
120// if (exponent == 0) value = mantissa;
121// else value = (mantissa | 1 << 11) << (exponent - 1)
122const int kUFloat16ExponentBits = 5;
123const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30
124const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11
125const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12
126const uint64 kUFloat16MaxValue = // 0x3FFC0000000
127 ((GG_UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1) <<
128 kUFloat16MaxExponent;
129
[email protected]c67a82cb2013-09-24 02:53:21130enum TransmissionType {
[email protected]2532de12013-05-09 12:29:33131 NOT_RETRANSMISSION,
[email protected]b9475b582014-03-20 20:04:33132 FIRST_TRANSMISSION_TYPE = NOT_RETRANSMISSION,
133 HANDSHAKE_RETRANSMISSION, // Retransmits due to handshake timeouts.
134 ALL_UNACKED_RETRANSMISSION, // Retransmits of all unacked packets.
135 LOSS_RETRANSMISSION, // Retransmits due to loss detection.
136 RTO_RETRANSMISSION, // Retransmits due to retransmit time out.
137 TLP_RETRANSMISSION, // Tail loss probes.
138 LAST_TRANSMISSION_TYPE = TLP_RETRANSMISSION,
[email protected]74bda142013-03-31 02:49:11139};
140
[email protected]41fb6372013-12-10 05:26:40141enum RetransmissionType {
142 INITIAL_ENCRYPTION_ONLY,
143 ALL_PACKETS
144};
145
[email protected]74bda142013-03-31 02:49:11146enum HasRetransmittableData {
[email protected]2532de12013-05-09 12:29:33147 NO_RETRANSMITTABLE_DATA,
148 HAS_RETRANSMITTABLE_DATA,
[email protected]74bda142013-03-31 02:49:11149};
150
[email protected]575cce62013-08-03 02:06:43151enum IsHandshake {
152 NOT_HANDSHAKE,
153 IS_HANDSHAKE
154};
155
[email protected]be24ab22012-10-22 03:01:52156enum QuicFrameType {
[email protected]6ae6e342014-02-06 02:21:42157 // Regular frame types. The values set here cannot change without the
158 // introduction of a new QUIC version.
[email protected]c995c572013-01-18 05:43:20159 PADDING_FRAME = 0,
[email protected]6ae6e342014-02-06 02:21:42160 RST_STREAM_FRAME = 1,
161 CONNECTION_CLOSE_FRAME = 2,
162 GOAWAY_FRAME = 3,
163 WINDOW_UPDATE_FRAME = 4,
164 BLOCKED_FRAME = 5,
[email protected]93dd91f2014-02-27 00:09:03165 STOP_WAITING_FRAME = 6,
[email protected]6ae6e342014-02-06 02:21:42166
167 // STREAM, ACK, and CONGESTION_FEEDBACK frames are special frames. They are
168 // encoded differently on the wire and their values do not need to be stable.
[email protected]97cf3022013-09-05 14:30:16169 STREAM_FRAME,
170 ACK_FRAME,
171 CONGESTION_FEEDBACK_FRAME,
[email protected]be24ab22012-10-22 03:01:52172 NUM_FRAME_TYPES
[email protected]8b37a092012-10-18 21:53:49173};
174
[email protected]3aa9ca72014-02-27 19:39:43175enum QuicConnectionIdLength {
176 PACKET_0BYTE_CONNECTION_ID = 0,
177 PACKET_1BYTE_CONNECTION_ID = 1,
178 PACKET_4BYTE_CONNECTION_ID = 4,
179 PACKET_8BYTE_CONNECTION_ID = 8
[email protected]b064310782013-05-30 21:12:17180};
181
182enum InFecGroup {
183 NOT_IN_FEC_GROUP,
184 IN_FEC_GROUP,
185};
186
[email protected]25c31dc2013-06-05 17:56:04187enum QuicSequenceNumberLength {
188 PACKET_1BYTE_SEQUENCE_NUMBER = 1,
189 PACKET_2BYTE_SEQUENCE_NUMBER = 2,
190 PACKET_4BYTE_SEQUENCE_NUMBER = 4,
191 PACKET_6BYTE_SEQUENCE_NUMBER = 6
192};
193
[email protected]8e01c062013-10-31 07:35:31194// Used to indicate a QuicSequenceNumberLength using two flag bits.
195enum QuicSequenceNumberLengthFlags {
196 PACKET_FLAGS_1BYTE_SEQUENCE = 0, // 00
197 PACKET_FLAGS_2BYTE_SEQUENCE = 1, // 01
198 PACKET_FLAGS_4BYTE_SEQUENCE = 1 << 1, // 10
199 PACKET_FLAGS_6BYTE_SEQUENCE = 1 << 1 | 1, // 11
200};
201
[email protected]f62262b2013-07-05 20:57:30202// The public flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20203enum QuicPacketPublicFlags {
204 PACKET_PUBLIC_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30205
206 // Bit 0: Does the packet header contains version info?
207 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0,
208
209 // Bit 1: Is this packet a public reset packet?
210 PACKET_PUBLIC_FLAGS_RST = 1 << 1,
211
[email protected]3aa9ca72014-02-27 19:39:43212 // Bits 2 and 3 specify the length of the ConnectionId as follows:
[email protected]f62262b2013-07-05 20:57:30213 // ----00--: 0 bytes
214 // ----01--: 1 byte
215 // ----10--: 4 bytes
216 // ----11--: 8 bytes
[email protected]3aa9ca72014-02-27 19:39:43217 PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID = 0,
218 PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID = 1 << 2,
219 PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID = 1 << 3,
220 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID = 1 << 3 | 1 << 2,
[email protected]f62262b2013-07-05 20:57:30221
222 // Bits 4 and 5 describe the packet sequence number length as follows:
223 // --00----: 1 byte
224 // --01----: 2 bytes
225 // --10----: 4 bytes
226 // --11----: 6 bytes
[email protected]8e01c062013-10-31 07:35:31227 PACKET_PUBLIC_FLAGS_1BYTE_SEQUENCE = PACKET_FLAGS_1BYTE_SEQUENCE << 4,
228 PACKET_PUBLIC_FLAGS_2BYTE_SEQUENCE = PACKET_FLAGS_2BYTE_SEQUENCE << 4,
229 PACKET_PUBLIC_FLAGS_4BYTE_SEQUENCE = PACKET_FLAGS_4BYTE_SEQUENCE << 4,
230 PACKET_PUBLIC_FLAGS_6BYTE_SEQUENCE = PACKET_FLAGS_6BYTE_SEQUENCE << 4,
[email protected]f62262b2013-07-05 20:57:30231
232 // All bits set (bits 6 and 7 are not currently used): 00111111
233 PACKET_PUBLIC_FLAGS_MAX = (1 << 6) - 1
[email protected]c995c572013-01-18 05:43:20234};
[email protected]8b37a092012-10-18 21:53:49235
[email protected]f62262b2013-07-05 20:57:30236// The private flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20237enum QuicPacketPrivateFlags {
238 PACKET_PRIVATE_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30239
240 // Bit 0: Does this packet contain an entropy bit?
[email protected]b064310782013-05-30 21:12:17241 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0,
[email protected]f62262b2013-07-05 20:57:30242
243 // Bit 1: Payload is part of an FEC group?
244 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1,
245
246 // Bit 2: Payload is FEC as opposed to frames?
247 PACKET_PRIVATE_FLAGS_FEC = 1 << 2,
248
249 // All bits set (bits 3-7 are not currently used): 00000111
250 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1
[email protected]c995c572013-01-18 05:43:20251};
252
[email protected]48878092013-07-26 14:51:56253// The available versions of QUIC. Guaranteed that the integer value of the enum
254// will match the version number.
255// When adding a new version to this enum you should add it to
[email protected]8bbfaeb72013-08-09 06:38:26256// kSupportedQuicVersions (if appropriate), and also add a new case to the
257// helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and
258// QuicVersionToString.
[email protected]48878092013-07-26 14:51:56259enum QuicVersion {
260 // Special case to indicate unknown/unsupported QUIC version.
261 QUIC_VERSION_UNSUPPORTED = 0,
262
[email protected]6ae6e342014-02-06 02:21:42263 QUIC_VERSION_13 = 13,
[email protected]93dd91f2014-02-27 00:09:03264 QUIC_VERSION_15 = 15,
[email protected]9bb57c72014-03-31 20:36:04265 QUIC_VERSION_16 = 16,
266 QUIC_VERSION_17 = 17, // Current version.
[email protected]48878092013-07-26 14:51:56267};
268
269// This vector contains QUIC versions which we currently support.
270// This should be ordered such that the highest supported version is the first
271// element, with subsequent elements in descending order (versions can be
272// skipped as necessary).
[email protected]31ae854842013-11-27 00:05:46273//
274// IMPORTANT: if you are addding to this list, follow the instructions at
275// http://sites/quic/adding-and-removing-versions
[email protected]9bb57c72014-03-31 20:36:04276static const QuicVersion kSupportedQuicVersions[] = {QUIC_VERSION_17,
277 QUIC_VERSION_16,
[email protected]93dd91f2014-02-27 00:09:03278 QUIC_VERSION_15,
[email protected]92bf17c2014-03-03 21:14:03279 QUIC_VERSION_13};
[email protected]48878092013-07-26 14:51:56280
281typedef std::vector<QuicVersion> QuicVersionVector;
282
[email protected]b007e632013-10-28 08:39:25283// Returns a vector of QUIC versions in kSupportedQuicVersions.
284NET_EXPORT_PRIVATE QuicVersionVector QuicSupportedVersions();
[email protected]ea2ab47b2013-08-13 00:44:11285
[email protected]48878092013-07-26 14:51:56286// QuicTag is written to and read from the wire, but we prefer to use
287// the more readable QuicVersion at other levels.
288// Helper function which translates from a QuicVersion to a QuicTag. Returns 0
289// if QuicVersion is unsupported.
290NET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version);
291
292// Returns appropriate QuicVersion from a QuicTag.
293// Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood.
294NET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag);
295
296// Helper function which translates from a QuicVersion to a string.
297// Returns strings corresponding to enum names (e.g. QUIC_VERSION_6).
298NET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version);
299
300// Returns comma separated list of string representations of QuicVersion enum
[email protected]b007e632013-10-28 08:39:25301// values in the supplied |versions| vector.
302NET_EXPORT_PRIVATE std::string QuicVersionVectorToString(
303 const QuicVersionVector& versions);
[email protected]48878092013-07-26 14:51:56304
305// Version and Crypto tags are written to the wire with a big-endian
306// representation of the name of the tag. For example
307// the client hello tag (CHLO) will be written as the
308// following 4 bytes: 'C' 'H' 'L' 'O'. Since it is
309// stored in memory as a little endian uint32, we need
310// to reverse the order of the bytes.
311
312// MakeQuicTag returns a value given the four bytes. For example:
313// MakeQuicTag('C', 'H', 'L', 'O');
314NET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d);
315
[email protected]b064310782013-05-30 21:12:17316// Size in bytes of the data or fec packet header.
[email protected]79d13dcb2014-02-05 07:23:13317NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(const QuicPacketHeader& header);
[email protected]b064310782013-05-30 21:12:17318
[email protected]25c31dc2013-06-05 17:56:04319NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(
[email protected]3aa9ca72014-02-27 19:39:43320 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04321 bool include_version,
322 QuicSequenceNumberLength sequence_number_length,
323 InFecGroup is_in_fec_group);
[email protected]b064310782013-05-30 21:12:17324
[email protected]b064310782013-05-30 21:12:17325// Index of the first byte in a QUIC packet of FEC protected data.
[email protected]25c31dc2013-06-05 17:56:04326NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(
[email protected]3aa9ca72014-02-27 19:39:43327 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04328 bool include_version,
329 QuicSequenceNumberLength sequence_number_length);
[email protected]b064310782013-05-30 21:12:17330// Index of the first byte in a QUIC packet of encrypted data.
[email protected]25c31dc2013-06-05 17:56:04331NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(
[email protected]3aa9ca72014-02-27 19:39:43332 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04333 bool include_version,
334 QuicSequenceNumberLength sequence_number_length);
[email protected]b064310782013-05-30 21:12:17335
[email protected]74bda142013-03-31 02:49:11336enum QuicRstStreamErrorCode {
337 QUIC_STREAM_NO_ERROR = 0,
[email protected]8b37a092012-10-18 21:53:49338
[email protected]24e5bc52013-09-18 15:36:58339 // There was some error which halted stream processing.
340 QUIC_ERROR_PROCESSING_STREAM,
[email protected]8b37a092012-10-18 21:53:49341 // We got two fin or reset offsets which did not match.
342 QUIC_MULTIPLE_TERMINATION_OFFSETS,
343 // We got bad payload and can not respond to it at the protocol level.
344 QUIC_BAD_APPLICATION_PAYLOAD,
[email protected]74bda142013-03-31 02:49:11345 // Stream closed due to connection error. No reset frame is sent when this
346 // happens.
347 QUIC_STREAM_CONNECTION_ERROR,
348 // GoAway frame sent. No more stream can be created.
349 QUIC_STREAM_PEER_GOING_AWAY,
[email protected]06ff5152013-08-29 01:03:05350 // The stream has been cancelled.
351 QUIC_STREAM_CANCELLED,
[email protected]51cc1342014-04-18 23:44:37352 // Sending a RST to allow for proper flow control accounting.
353 QUIC_RST_FLOW_CONTROL_ACCOUNTING,
[email protected]8b37a092012-10-18 21:53:49354
[email protected]74bda142013-03-31 02:49:11355 // No error. Used as bound while iterating.
356 QUIC_STREAM_LAST_ERROR,
357};
[email protected]8b37a092012-10-18 21:53:49358
[email protected]51cc1342014-04-18 23:44:37359// Because receiving an unknown QuicRstStreamErrorCode results in connection
360// teardown, we use this to make sure any errors predating a given version are
361// downgraded to the most appropriate existing error.
362NET_EXPORT_PRIVATE QuicRstStreamErrorCode AdjustErrorForVersion(
363 QuicRstStreamErrorCode error_code,
364 QuicVersion version);
365
[email protected]89264042013-08-21 07:35:24366// These values must remain stable as they are uploaded to UMA histograms.
367// To add a new error code, use the current value of QUIC_LAST_ERROR and
368// increment QUIC_LAST_ERROR.
[email protected]74bda142013-03-31 02:49:11369enum QuicErrorCode {
370 QUIC_NO_ERROR = 0,
371
372 // Connection has reached an invalid state.
[email protected]89264042013-08-21 07:35:24373 QUIC_INTERNAL_ERROR = 1,
[email protected]74bda142013-03-31 02:49:11374 // There were data frames after the a fin or reset.
[email protected]89264042013-08-21 07:35:24375 QUIC_STREAM_DATA_AFTER_TERMINATION = 2,
[email protected]8b37a092012-10-18 21:53:49376 // Control frame is malformed.
[email protected]89264042013-08-21 07:35:24377 QUIC_INVALID_PACKET_HEADER = 3,
[email protected]be24ab22012-10-22 03:01:52378 // Frame data is malformed.
[email protected]89264042013-08-21 07:35:24379 QUIC_INVALID_FRAME_DATA = 4,
380 // The packet contained no payload.
381 QUIC_MISSING_PAYLOAD = 48,
[email protected]8b37a092012-10-18 21:53:49382 // FEC data is malformed.
[email protected]89264042013-08-21 07:35:24383 QUIC_INVALID_FEC_DATA = 5,
384 // STREAM frame data is malformed.
385 QUIC_INVALID_STREAM_DATA = 46,
386 // RST_STREAM frame data is malformed.
387 QUIC_INVALID_RST_STREAM_DATA = 6,
388 // CONNECTION_CLOSE frame data is malformed.
389 QUIC_INVALID_CONNECTION_CLOSE_DATA = 7,
390 // GOAWAY frame data is malformed.
391 QUIC_INVALID_GOAWAY_DATA = 8,
[email protected]6ae6e342014-02-06 02:21:42392 // WINDOW_UPDATE frame data is malformed.
393 QUIC_INVALID_WINDOW_UPDATE_DATA = 57,
394 // BLOCKED frame data is malformed.
395 QUIC_INVALID_BLOCKED_DATA = 58,
[email protected]93dd91f2014-02-27 00:09:03396 // STOP_WAITING frame data is malformed.
397 QUIC_INVALID_STOP_WAITING_DATA = 60,
[email protected]89264042013-08-21 07:35:24398 // ACK frame data is malformed.
399 QUIC_INVALID_ACK_DATA = 9,
400 // CONGESTION_FEEDBACK frame data is malformed.
401 QUIC_INVALID_CONGESTION_FEEDBACK_DATA = 47,
[email protected]14e8106c2013-03-14 16:25:33402 // Version negotiation packet is malformed.
[email protected]89264042013-08-21 07:35:24403 QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10,
[email protected]899951652013-05-16 12:52:39404 // Public RST packet is malformed.
[email protected]89264042013-08-21 07:35:24405 QUIC_INVALID_PUBLIC_RST_PACKET = 11,
[email protected]8b37a092012-10-18 21:53:49406 // There was an error decrypting.
[email protected]89264042013-08-21 07:35:24407 QUIC_DECRYPTION_FAILURE = 12,
[email protected]8b37a092012-10-18 21:53:49408 // There was an error encrypting.
[email protected]89264042013-08-21 07:35:24409 QUIC_ENCRYPTION_FAILURE = 13,
[email protected]8b37a092012-10-18 21:53:49410 // The packet exceeded kMaxPacketSize.
[email protected]89264042013-08-21 07:35:24411 QUIC_PACKET_TOO_LARGE = 14,
[email protected]8b37a092012-10-18 21:53:49412 // Data was sent for a stream which did not exist.
[email protected]89264042013-08-21 07:35:24413 QUIC_PACKET_FOR_NONEXISTENT_STREAM = 15,
[email protected]9db443912013-02-25 05:27:03414 // The peer is going away. May be a client or server.
[email protected]89264042013-08-21 07:35:24415 QUIC_PEER_GOING_AWAY = 16,
[email protected]8b37a092012-10-18 21:53:49416 // A stream ID was invalid.
[email protected]89264042013-08-21 07:35:24417 QUIC_INVALID_STREAM_ID = 17,
[email protected]24e5bc52013-09-18 15:36:58418 // A priority was invalid.
419 QUIC_INVALID_PRIORITY = 49,
[email protected]8b37a092012-10-18 21:53:49420 // Too many streams already open.
[email protected]89264042013-08-21 07:35:24421 QUIC_TOO_MANY_OPEN_STREAMS = 18,
[email protected]86a318d2013-01-23 21:16:04422 // Received public reset for this connection.
[email protected]89264042013-08-21 07:35:24423 QUIC_PUBLIC_RESET = 19,
[email protected]c244c5a12013-05-07 20:55:04424 // Invalid protocol version.
[email protected]89264042013-08-21 07:35:24425 QUIC_INVALID_VERSION = 20,
[email protected]92bf17c2014-03-03 21:14:03426
427 // deprecated: QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED = 21
428
[email protected]c244c5a12013-05-07 20:55:04429 // The Header ID for a stream was too far from the previous.
[email protected]89264042013-08-21 07:35:24430 QUIC_INVALID_HEADER_ID = 22,
[email protected]899951652013-05-16 12:52:39431 // Negotiable parameter received during handshake had invalid value.
[email protected]89264042013-08-21 07:35:24432 QUIC_INVALID_NEGOTIATED_VALUE = 23,
[email protected]899951652013-05-16 12:52:39433 // There was an error decompressing data.
[email protected]89264042013-08-21 07:35:24434 QUIC_DECOMPRESSION_FAILURE = 24,
[email protected]8b37a092012-10-18 21:53:49435 // We hit our prenegotiated (or default) timeout
[email protected]89264042013-08-21 07:35:24436 QUIC_CONNECTION_TIMED_OUT = 25,
[email protected]899951652013-05-16 12:52:39437 // There was an error encountered migrating addresses
[email protected]89264042013-08-21 07:35:24438 QUIC_ERROR_MIGRATING_ADDRESS = 26,
[email protected]1505a512013-09-04 22:59:35439 // There was an error while writing to the socket.
[email protected]89264042013-08-21 07:35:24440 QUIC_PACKET_WRITE_ERROR = 27,
[email protected]1505a512013-09-04 22:59:35441 // There was an error while reading from the socket.
442 QUIC_PACKET_READ_ERROR = 51,
[email protected]24e5bc52013-09-18 15:36:58443 // We received a STREAM_FRAME with no data and no fin flag set.
444 QUIC_INVALID_STREAM_FRAME = 50,
[email protected]4d640792013-12-18 22:21:08445 // We received invalid data on the headers stream.
446 QUIC_INVALID_HEADERS_STREAM_DATA = 56,
[email protected]6ae6e342014-02-06 02:21:42447 // The peer violated the flow control protocol.
448 QUIC_FLOW_CONTROL_ERROR = 59,
[email protected]8b37a092012-10-18 21:53:49449
450 // Crypto errors.
451
[email protected]1354bf62013-05-23 23:17:18452 // Hanshake failed.
[email protected]89264042013-08-21 07:35:24453 QUIC_HANDSHAKE_FAILED = 28,
[email protected]8b37a092012-10-18 21:53:49454 // Handshake message contained out of order tags.
[email protected]89264042013-08-21 07:35:24455 QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29,
[email protected]701bc892013-01-17 04:51:54456 // Handshake message contained too many entries.
[email protected]89264042013-08-21 07:35:24457 QUIC_CRYPTO_TOO_MANY_ENTRIES = 30,
[email protected]8b37a092012-10-18 21:53:49458 // Handshake message contained an invalid value length.
[email protected]89264042013-08-21 07:35:24459 QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31,
[email protected]8b37a092012-10-18 21:53:49460 // A crypto message was received after the handshake was complete.
[email protected]89264042013-08-21 07:35:24461 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32,
[email protected]d3d15bf2013-01-30 02:51:54462 // A crypto message was received with an illegal message tag.
[email protected]89264042013-08-21 07:35:24463 QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33,
[email protected]d3d15bf2013-01-30 02:51:54464 // A crypto message was received with an illegal parameter.
[email protected]89264042013-08-21 07:35:24465 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34,
[email protected]752fbe52013-10-14 08:35:32466 // An invalid channel id signature was supplied.
467 QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52,
[email protected]d3d15bf2013-01-30 02:51:54468 // A crypto message was received with a mandatory parameter missing.
[email protected]89264042013-08-21 07:35:24469 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35,
[email protected]d3d15bf2013-01-30 02:51:54470 // A crypto message was received with a parameter that has no overlap
471 // with the local parameter.
[email protected]89264042013-08-21 07:35:24472 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36,
[email protected]ed3fc15d2013-03-08 18:37:44473 // A crypto message was received that contained a parameter with too few
474 // values.
[email protected]89264042013-08-21 07:35:24475 QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37,
[email protected]ccc66e8a2013-03-26 08:26:14476 // An internal error occured in crypto processing.
[email protected]89264042013-08-21 07:35:24477 QUIC_CRYPTO_INTERNAL_ERROR = 38,
[email protected]ccc66e8a2013-03-26 08:26:14478 // A crypto handshake message specified an unsupported version.
[email protected]89264042013-08-21 07:35:24479 QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39,
[email protected]ccc66e8a2013-03-26 08:26:14480 // There was no intersection between the crypto primitives supported by the
481 // peer and ourselves.
[email protected]89264042013-08-21 07:35:24482 QUIC_CRYPTO_NO_SUPPORT = 40,
[email protected]ef95114d2013-04-17 17:57:01483 // The server rejected our client hello messages too many times.
[email protected]89264042013-08-21 07:35:24484 QUIC_CRYPTO_TOO_MANY_REJECTS = 41,
[email protected]a57e0272013-04-26 07:31:47485 // The client rejected the server's certificate chain or signature.
[email protected]89264042013-08-21 07:35:24486 QUIC_PROOF_INVALID = 42,
[email protected]8ba81212013-05-03 13:11:48487 // A crypto message was received with a duplicate tag.
[email protected]89264042013-08-21 07:35:24488 QUIC_CRYPTO_DUPLICATE_TAG = 43,
[email protected]2532de12013-05-09 12:29:33489 // A crypto message was received with the wrong encryption level (i.e. it
490 // should have been encrypted but was not.)
[email protected]89264042013-08-21 07:35:24491 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44,
[email protected]2532de12013-05-09 12:29:33492 // The server config for a server has expired.
[email protected]89264042013-08-21 07:35:24493 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45,
[email protected]752fbe52013-10-14 08:35:32494 // We failed to setup the symmetric keys for a connection.
495 QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53,
[email protected]691f45a982013-11-19 10:52:04496 // A handshake message arrived, but we are still validating the
497 // previous handshake message.
498 QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54,
[email protected]d89f1862013-11-26 21:21:27499 // This connection involved a version negotiation which appears to have been
500 // tampered with.
501 QUIC_VERSION_NEGOTIATION_MISMATCH = 55,
[email protected]ccc66e8a2013-03-26 08:26:14502
[email protected]74bda142013-03-31 02:49:11503 // No error. Used as bound while iterating.
[email protected]93dd91f2014-02-27 00:09:03504 QUIC_LAST_ERROR = 61,
[email protected]8b37a092012-10-18 21:53:49505};
506
[email protected]c995c572013-01-18 05:43:20507struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
[email protected]14e8106c2013-03-14 16:25:33508 QuicPacketPublicHeader();
509 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
510 ~QuicPacketPublicHeader();
511
[email protected]3aa9ca72014-02-27 19:39:43512 // Universal header. All QuicPacket headers will have a connection_id and
513 // public flags.
514 QuicConnectionId connection_id;
515 QuicConnectionIdLength connection_id_length;
[email protected]9db443912013-02-25 05:27:03516 bool reset_flag;
517 bool version_flag;
[email protected]25c31dc2013-06-05 17:56:04518 QuicSequenceNumberLength sequence_number_length;
[email protected]48878092013-07-26 14:51:56519 QuicVersionVector versions;
[email protected]c995c572013-01-18 05:43:20520};
521
522// Header for Data or FEC packets.
[email protected]74bda142013-03-31 02:49:11523struct NET_EXPORT_PRIVATE QuicPacketHeader {
524 QuicPacketHeader();
525 explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
[email protected]9db443912013-02-25 05:27:03526
527 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
528 std::ostream& os, const QuicPacketHeader& s);
529
[email protected]c995c572013-01-18 05:43:20530 QuicPacketPublicHeader public_header;
[email protected]9db443912013-02-25 05:27:03531 bool fec_flag;
[email protected]9db443912013-02-25 05:27:03532 bool entropy_flag;
533 QuicPacketEntropyHash entropy_hash;
[email protected]8b37a092012-10-18 21:53:49534 QuicPacketSequenceNumber packet_sequence_number;
[email protected]b064310782013-05-30 21:12:17535 InFecGroup is_in_fec_group;
[email protected]8b37a092012-10-18 21:53:49536 QuicFecGroupNumber fec_group;
537};
538
[email protected]74bda142013-03-31 02:49:11539struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
[email protected]6ae6e342014-02-06 02:21:42540 QuicPublicResetPacket();
541 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header);
542
[email protected]86a318d2013-01-23 21:16:04543 QuicPacketPublicHeader public_header;
[email protected]86a318d2013-01-23 21:16:04544 QuicPublicResetNonceProof nonce_proof;
[email protected]300ccd52014-01-25 08:00:19545 QuicPacketSequenceNumber rejected_sequence_number;
[email protected]79d13dcb2014-02-05 07:23:13546 IPEndPoint client_address;
[email protected]86a318d2013-01-23 21:16:04547};
548
[email protected]14e8106c2013-03-14 16:25:33549enum QuicVersionNegotiationState {
550 START_NEGOTIATION = 0,
[email protected]ec640112013-08-09 03:56:18551 // Server-side this implies we've sent a version negotiation packet and are
552 // waiting on the client to select a compatible version. Client-side this
553 // implies we've gotten a version negotiation packet, are retransmitting the
554 // initial packets with a supported version and are waiting for our first
555 // packet from the server.
556 NEGOTIATION_IN_PROGRESS,
557 // This indicates this endpoint has received a packet from the peer with a
558 // version this endpoint supports. Version negotiation is complete, and the
559 // version number will no longer be sent with future packets.
[email protected]14e8106c2013-03-14 16:25:33560 NEGOTIATED_VERSION
561};
562
563typedef QuicPacketPublicHeader QuicVersionNegotiationPacket;
564
[email protected]c995c572013-01-18 05:43:20565// A padding frame contains no payload.
566struct NET_EXPORT_PRIVATE QuicPaddingFrame {
567};
568
[email protected]be24ab22012-10-22 03:01:52569struct NET_EXPORT_PRIVATE QuicStreamFrame {
570 QuicStreamFrame();
[email protected]5dafdb62013-11-14 01:24:26571 QuicStreamFrame(const QuicStreamFrame& frame);
[email protected]be24ab22012-10-22 03:01:52572 QuicStreamFrame(QuicStreamId stream_id,
[email protected]a5061242012-10-23 23:29:37573 bool fin,
[email protected]701bc892013-01-17 04:51:54574 QuicStreamOffset offset,
[email protected]5dafdb62013-11-14 01:24:26575 IOVector data);
576
[email protected]c5e1aca2014-01-30 04:03:04577 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
578 std::ostream& os, const QuicStreamFrame& s);
579
[email protected]5dafdb62013-11-14 01:24:26580 // Returns a copy of the IOVector |data| as a heap-allocated string.
581 // Caller must take ownership of the returned string.
582 std::string* GetDataAsString() const;
[email protected]8b37a092012-10-18 21:53:49583
584 QuicStreamId stream_id;
585 bool fin;
[email protected]701bc892013-01-17 04:51:54586 QuicStreamOffset offset; // Location of this data in the stream.
[email protected]5dafdb62013-11-14 01:24:26587 IOVector data;
[email protected]97cf3022013-09-05 14:30:16588
589 // If this is set, then when this packet is ACKed the AckNotifier will be
590 // informed.
591 QuicAckNotifier* notifier;
[email protected]8b37a092012-10-18 21:53:49592};
593
[email protected]e537f742012-12-07 15:33:53594// TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
595// is finalized.
[email protected]9db443912013-02-25 05:27:03596typedef std::set<QuicPacketSequenceNumber> SequenceNumberSet;
[email protected]3c5f4a732013-01-12 16:45:34597// TODO(pwestin): Add a way to enforce the max size of this map.
[email protected]e537f742012-12-07 15:33:53598typedef std::map<QuicPacketSequenceNumber, QuicTime> TimeMap;
[email protected]044ac2b2012-11-13 21:41:06599
[email protected]8b37a092012-10-18 21:53:49600struct NET_EXPORT_PRIVATE ReceivedPacketInfo {
601 ReceivedPacketInfo();
602 ~ReceivedPacketInfo();
[email protected]6ae6e342014-02-06 02:21:42603
[email protected]26f3f8e2012-12-13 21:07:19604 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
605 std::ostream& os, const ReceivedPacketInfo& s);
[email protected]a674b4c2012-12-05 03:44:30606
[email protected]9db443912013-02-25 05:27:03607 // Entropy hash of all packets up to largest observed not including missing
608 // packets.
609 QuicPacketEntropyHash entropy_hash;
[email protected]e537f742012-12-07 15:33:53610
[email protected]48697d8a2013-01-15 19:42:24611 // The highest packet sequence number we've observed from the peer.
612 //
613 // In general, this should be the largest packet number we've received. In
614 // the case of truncated acks, we may have to advertise a lower "upper bound"
615 // than largest received, to avoid implicitly acking missing packets that
616 // don't fit in the missing packet list due to size limitations. In this
617 // case, largest_observed may be a packet which is also in the missing packets
618 // list.
619 QuicPacketSequenceNumber largest_observed;
[email protected]a674b4c2012-12-05 03:44:30620
[email protected]14e8106c2013-03-14 16:25:33621 // Time elapsed since largest_observed was received until this Ack frame was
622 // sent.
623 QuicTime::Delta delta_time_largest_observed;
624
[email protected]9db443912013-02-25 05:27:03625 // TODO(satyamshekhar): Can be optimized using an interval set like data
626 // structure.
[email protected]e537f742012-12-07 15:33:53627 // The set of packets which we're expecting and have not received.
[email protected]9db443912013-02-25 05:27:03628 SequenceNumberSet missing_packets;
[email protected]8e01c062013-10-31 07:35:31629
630 // Whether the ack had to be truncated when sent.
631 bool is_truncated;
[email protected]bdf2d432014-02-09 10:45:41632
633 // Packets which have been revived via FEC.
634 // All of these must also be in missing_packets.
635 SequenceNumberSet revived_packets;
[email protected]8b37a092012-10-18 21:53:49636};
637
[email protected]9db443912013-02-25 05:27:03638// True if the sequence number is greater than largest_observed or is listed
639// as missing.
640// Always returns false for sequence numbers less than least_unacked.
641bool NET_EXPORT_PRIVATE IsAwaitingPacket(
642 const ReceivedPacketInfo& received_info,
643 QuicPacketSequenceNumber sequence_number);
644
645// Inserts missing packets between [lower, higher).
646void NET_EXPORT_PRIVATE InsertMissingPacketsBetween(
647 ReceivedPacketInfo* received_info,
648 QuicPacketSequenceNumber lower,
649 QuicPacketSequenceNumber higher);
650
[email protected]93dd91f2014-02-27 00:09:03651struct NET_EXPORT_PRIVATE QuicStopWaitingFrame {
652 QuicStopWaitingFrame();
653 ~QuicStopWaitingFrame();
[email protected]6ae6e342014-02-06 02:21:42654
[email protected]26f3f8e2012-12-13 21:07:19655 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
[email protected]93dd91f2014-02-27 00:09:03656 std::ostream& os, const QuicStopWaitingFrame& s);
657
[email protected]9db443912013-02-25 05:27:03658 // Entropy hash of all packets up to, but not including, the least unacked
659 // packet.
660 QuicPacketEntropyHash entropy_hash;
[email protected]8b37a092012-10-18 21:53:49661 // The lowest packet we've sent which is unacked, and we expect an ack for.
662 QuicPacketSequenceNumber least_unacked;
[email protected]8b37a092012-10-18 21:53:49663};
664
[email protected]26f3f8e2012-12-13 21:07:19665struct NET_EXPORT_PRIVATE QuicAckFrame {
[email protected]6ae6e342014-02-06 02:21:42666 QuicAckFrame();
[email protected]26f3f8e2012-12-13 21:07:19667
668 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
669 std::ostream& os, const QuicAckFrame& s);
670
[email protected]93dd91f2014-02-27 00:09:03671 QuicStopWaitingFrame sent_info;
[email protected]26f3f8e2012-12-13 21:07:19672 ReceivedPacketInfo received_info;
673};
674
[email protected]8b37a092012-10-18 21:53:49675// Defines for all types of congestion feedback that will be negotiated in QUIC,
[email protected]f62262b2013-07-05 20:57:30676// kTCP MUST be supported by all QUIC implementations to guarantee 100%
[email protected]8b37a092012-10-18 21:53:49677// compatibility.
678enum CongestionFeedbackType {
[email protected]8b37a092012-10-18 21:53:49679 kTCP, // Used to mimic TCP.
680 kInterArrival, // Use additional inter arrival information.
681 kFixRate, // Provided for testing.
682};
683
[email protected]c5cc9bd2014-03-31 23:17:14684enum LossDetectionType {
685 kNack, // Used to mimic TCP's loss detection.
686 kTime, // Time based loss detection.
687};
688
[email protected]8b37a092012-10-18 21:53:49689struct NET_EXPORT_PRIVATE CongestionFeedbackMessageTCP {
[email protected]6ae6e342014-02-06 02:21:42690 CongestionFeedbackMessageTCP();
691
[email protected]fee17f72013-02-03 07:47:41692 QuicByteCount receive_window;
[email protected]8b37a092012-10-18 21:53:49693};
694
695struct NET_EXPORT_PRIVATE CongestionFeedbackMessageInterArrival {
[email protected]7884ecad2012-12-14 22:55:15696 CongestionFeedbackMessageInterArrival();
697 ~CongestionFeedbackMessageInterArrival();
[email protected]6ae6e342014-02-06 02:21:42698
[email protected]7884ecad2012-12-14 22:55:15699 // The set of received packets since the last feedback was sent, along with
700 // their arrival times.
701 TimeMap received_packet_times;
[email protected]8b37a092012-10-18 21:53:49702};
703
[email protected]8b37a092012-10-18 21:53:49704struct NET_EXPORT_PRIVATE CongestionFeedbackMessageFixRate {
[email protected]fee17f72013-02-03 07:47:41705 CongestionFeedbackMessageFixRate();
706 QuicBandwidth bitrate;
[email protected]8b37a092012-10-18 21:53:49707};
708
[email protected]26f3f8e2012-12-13 21:07:19709struct NET_EXPORT_PRIVATE QuicCongestionFeedbackFrame {
[email protected]7884ecad2012-12-14 22:55:15710 QuicCongestionFeedbackFrame();
711 ~QuicCongestionFeedbackFrame();
712
[email protected]26f3f8e2012-12-13 21:07:19713 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
714 std::ostream& os, const QuicCongestionFeedbackFrame& c);
715
[email protected]7884ecad2012-12-14 22:55:15716 CongestionFeedbackType type;
717 // This should really be a union, but since the inter arrival struct
718 // is non-trivial, C++ prohibits it.
719 CongestionFeedbackMessageTCP tcp;
720 CongestionFeedbackMessageInterArrival inter_arrival;
721 CongestionFeedbackMessageFixRate fix_rate;
[email protected]8b37a092012-10-18 21:53:49722};
723
[email protected]be24ab22012-10-22 03:01:52724struct NET_EXPORT_PRIVATE QuicRstStreamFrame {
[email protected]6ae6e342014-02-06 02:21:42725 QuicRstStreamFrame();
726 QuicRstStreamFrame(QuicStreamId stream_id,
727 QuicRstStreamErrorCode error_code,
728 QuicStreamOffset bytes_written);
[email protected]8b37a092012-10-18 21:53:49729
[email protected]c5e1aca2014-01-30 04:03:04730 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
731 std::ostream& os, const QuicRstStreamFrame& r);
732
[email protected]8b37a092012-10-18 21:53:49733 QuicStreamId stream_id;
[email protected]74bda142013-03-31 02:49:11734 QuicRstStreamErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09735 std::string error_details;
[email protected]6ae6e342014-02-06 02:21:42736
737 // Used to update flow control windows. On termination of a stream, both
738 // endpoints must inform the peer of the number of bytes they have sent on
739 // that stream. This can be done through normal termination (data packet with
740 // FIN) or through a RST.
741 QuicStreamOffset byte_offset;
[email protected]8b37a092012-10-18 21:53:49742};
743
[email protected]be24ab22012-10-22 03:01:52744struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame {
[email protected]6ae6e342014-02-06 02:21:42745 QuicConnectionCloseFrame();
746
[email protected]c5e1aca2014-01-30 04:03:04747 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
748 std::ostream& os, const QuicConnectionCloseFrame& c);
749
[email protected]431bb4fd2012-10-19 17:46:09750 QuicErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09751 std::string error_details;
[email protected]8b37a092012-10-18 21:53:49752};
753
[email protected]9db443912013-02-25 05:27:03754struct NET_EXPORT_PRIVATE QuicGoAwayFrame {
[email protected]6ae6e342014-02-06 02:21:42755 QuicGoAwayFrame();
[email protected]9db443912013-02-25 05:27:03756 QuicGoAwayFrame(QuicErrorCode error_code,
757 QuicStreamId last_good_stream_id,
758 const std::string& reason);
759
[email protected]c5e1aca2014-01-30 04:03:04760 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
761 std::ostream& os, const QuicGoAwayFrame& g);
762
[email protected]9db443912013-02-25 05:27:03763 QuicErrorCode error_code;
764 QuicStreamId last_good_stream_id;
765 std::string reason_phrase;
766};
767
[email protected]6ae6e342014-02-06 02:21:42768// Flow control updates per-stream and at the connection levoel.
769// Based on SPDY's WINDOW_UPDATE frame, but uses an absolute byte offset rather
770// than a window delta.
771// TODO(rjshade): A possible future optimization is to make stream_id and
772// byte_offset variable length, similar to stream frames.
773struct NET_EXPORT_PRIVATE QuicWindowUpdateFrame {
774 QuicWindowUpdateFrame() {}
775 QuicWindowUpdateFrame(QuicStreamId stream_id, QuicStreamOffset byte_offset);
776
777 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
778 std::ostream& os, const QuicWindowUpdateFrame& w);
779
780 // The stream this frame applies to. 0 is a special case meaning the overall
781 // connection rather than a specific stream.
782 QuicStreamId stream_id;
783
784 // Byte offset in the stream or connection. The receiver of this frame must
785 // not send data which would result in this offset being exceeded.
786 QuicStreamOffset byte_offset;
787};
788
789// The BLOCKED frame is used to indicate to the remote endpoint that this
790// endpoint believes itself to be flow-control blocked but otherwise ready to
791// send data. The BLOCKED frame is purely advisory and optional.
792// Based on SPDY's BLOCKED frame (undocumented as of 2014-01-28).
793struct NET_EXPORT_PRIVATE QuicBlockedFrame {
794 QuicBlockedFrame() {}
795 explicit QuicBlockedFrame(QuicStreamId stream_id);
796
797 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
798 std::ostream& os, const QuicBlockedFrame& b);
799
800 // The stream this frame applies to. 0 is a special case meaning the overall
801 // connection rather than a specific stream.
802 QuicStreamId stream_id;
803};
804
[email protected]8ba81212013-05-03 13:11:48805// EncryptionLevel enumerates the stages of encryption that a QUIC connection
806// progresses through. When retransmitting a packet, the encryption level needs
807// to be specified so that it is retransmitted at a level which the peer can
808// understand.
809enum EncryptionLevel {
810 ENCRYPTION_NONE = 0,
811 ENCRYPTION_INITIAL = 1,
812 ENCRYPTION_FORWARD_SECURE = 2,
813
814 NUM_ENCRYPTION_LEVELS,
815};
816
[email protected]be24ab22012-10-22 03:01:52817struct NET_EXPORT_PRIVATE QuicFrame {
[email protected]6ae6e342014-02-06 02:21:42818 QuicFrame();
819 explicit QuicFrame(QuicPaddingFrame* padding_frame);
820 explicit QuicFrame(QuicStreamFrame* stream_frame);
821 explicit QuicFrame(QuicAckFrame* frame);
822 explicit QuicFrame(QuicCongestionFeedbackFrame* frame);
823 explicit QuicFrame(QuicRstStreamFrame* frame);
824 explicit QuicFrame(QuicConnectionCloseFrame* frame);
[email protected]93dd91f2014-02-27 00:09:03825 explicit QuicFrame(QuicStopWaitingFrame* frame);
[email protected]6ae6e342014-02-06 02:21:42826 explicit QuicFrame(QuicGoAwayFrame* frame);
827 explicit QuicFrame(QuicWindowUpdateFrame* frame);
828 explicit QuicFrame(QuicBlockedFrame* frame);
[email protected]8b37a092012-10-18 21:53:49829
[email protected]c5e1aca2014-01-30 04:03:04830 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
831 std::ostream& os, const QuicFrame& frame);
832
[email protected]be24ab22012-10-22 03:01:52833 QuicFrameType type;
[email protected]8b37a092012-10-18 21:53:49834 union {
[email protected]c995c572013-01-18 05:43:20835 QuicPaddingFrame* padding_frame;
[email protected]be24ab22012-10-22 03:01:52836 QuicStreamFrame* stream_frame;
837 QuicAckFrame* ack_frame;
[email protected]26f3f8e2012-12-13 21:07:19838 QuicCongestionFeedbackFrame* congestion_feedback_frame;
[email protected]93dd91f2014-02-27 00:09:03839 QuicStopWaitingFrame* stop_waiting_frame;
[email protected]be24ab22012-10-22 03:01:52840 QuicRstStreamFrame* rst_stream_frame;
841 QuicConnectionCloseFrame* connection_close_frame;
[email protected]9db443912013-02-25 05:27:03842 QuicGoAwayFrame* goaway_frame;
[email protected]6ae6e342014-02-06 02:21:42843 QuicWindowUpdateFrame* window_update_frame;
844 QuicBlockedFrame* blocked_frame;
[email protected]8b37a092012-10-18 21:53:49845 };
846};
847
[email protected]be24ab22012-10-22 03:01:52848typedef std::vector<QuicFrame> QuicFrames;
[email protected]8b37a092012-10-18 21:53:49849
850struct NET_EXPORT_PRIVATE QuicFecData {
851 QuicFecData();
[email protected]a5061242012-10-23 23:29:37852
[email protected]c995c572013-01-18 05:43:20853 // The FEC group number is also the sequence number of the first
854 // FEC protected packet. The last protected packet's sequence number will
855 // be one less than the sequence number of the FEC packet.
[email protected]8b37a092012-10-18 21:53:49856 QuicFecGroupNumber fec_group;
[email protected]8b37a092012-10-18 21:53:49857 base::StringPiece redundancy;
[email protected]8b37a092012-10-18 21:53:49858};
859
[email protected]8b37a092012-10-18 21:53:49860class NET_EXPORT_PRIVATE QuicData {
861 public:
[email protected]6ae6e342014-02-06 02:21:42862 QuicData(const char* buffer, size_t length);
863 QuicData(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:49864 virtual ~QuicData();
865
866 base::StringPiece AsStringPiece() const {
867 return base::StringPiece(data(), length());
868 }
869
870 const char* data() const { return buffer_; }
871 size_t length() const { return length_; }
872
873 private:
874 const char* buffer_;
875 size_t length_;
876 bool owns_buffer_;
877
878 DISALLOW_COPY_AND_ASSIGN(QuicData);
879};
880
881class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
882 public:
[email protected]25c31dc2013-06-05 17:56:04883 static QuicPacket* NewDataPacket(
884 char* buffer,
885 size_t length,
886 bool owns_buffer,
[email protected]3aa9ca72014-02-27 19:39:43887 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04888 bool includes_version,
889 QuicSequenceNumberLength sequence_number_length) {
[email protected]3aa9ca72014-02-27 19:39:43890 return new QuicPacket(buffer, length, owns_buffer, connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04891 includes_version, sequence_number_length, false);
[email protected]c995c572013-01-18 05:43:20892 }
893
[email protected]25c31dc2013-06-05 17:56:04894 static QuicPacket* NewFecPacket(
895 char* buffer,
896 size_t length,
897 bool owns_buffer,
[email protected]3aa9ca72014-02-27 19:39:43898 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04899 bool includes_version,
900 QuicSequenceNumberLength sequence_number_length) {
[email protected]3aa9ca72014-02-27 19:39:43901 return new QuicPacket(buffer, length, owns_buffer, connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04902 includes_version, sequence_number_length, true);
[email protected]c995c572013-01-18 05:43:20903 }
[email protected]8b37a092012-10-18 21:53:49904
[email protected]5351cc4b2013-03-03 07:22:41905 base::StringPiece FecProtectedData() const;
906 base::StringPiece AssociatedData() const;
907 base::StringPiece BeforePlaintext() const;
908 base::StringPiece Plaintext() const;
[email protected]082b65b2012-11-10 19:11:31909
[email protected]c995c572013-01-18 05:43:20910 bool is_fec_packet() const { return is_fec_packet_; }
[email protected]082b65b2012-11-10 19:11:31911
[email protected]8b37a092012-10-18 21:53:49912 char* mutable_data() { return buffer_; }
913
914 private:
[email protected]5351cc4b2013-03-03 07:22:41915 QuicPacket(char* buffer,
916 size_t length,
917 bool owns_buffer,
[email protected]3aa9ca72014-02-27 19:39:43918 QuicConnectionIdLength connection_id_length,
[email protected]5351cc4b2013-03-03 07:22:41919 bool includes_version,
[email protected]25c31dc2013-06-05 17:56:04920 QuicSequenceNumberLength sequence_number_length,
[email protected]6ae6e342014-02-06 02:21:42921 bool is_fec_packet);
[email protected]c995c572013-01-18 05:43:20922
[email protected]8b37a092012-10-18 21:53:49923 char* buffer_;
[email protected]c995c572013-01-18 05:43:20924 const bool is_fec_packet_;
[email protected]3aa9ca72014-02-27 19:39:43925 const QuicConnectionIdLength connection_id_length_;
[email protected]5351cc4b2013-03-03 07:22:41926 const bool includes_version_;
[email protected]25c31dc2013-06-05 17:56:04927 const QuicSequenceNumberLength sequence_number_length_;
[email protected]8b37a092012-10-18 21:53:49928
[email protected]2e740db2012-10-20 19:35:19929 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
[email protected]8b37a092012-10-18 21:53:49930};
931
932class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
933 public:
[email protected]6ae6e342014-02-06 02:21:42934 QuicEncryptedPacket(const char* buffer, size_t length);
935 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:49936
[email protected]ec86d5462013-11-17 16:04:49937 // Clones the packet into a new packet which owns the buffer.
938 QuicEncryptedPacket* Clone() const;
939
[email protected]c1b32c62013-01-20 02:49:10940 // By default, gtest prints the raw bytes of an object. The bool data
941 // member (in the base class QuicData) causes this object to have padding
942 // bytes, which causes the default gtest object printer to read
943 // uninitialize memory. So we need to teach gtest how to print this object.
944 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
945 std::ostream& os, const QuicEncryptedPacket& s);
946
[email protected]2e740db2012-10-20 19:35:19947 private:
948 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
[email protected]8b37a092012-10-18 21:53:49949};
950
[email protected]9db443912013-02-25 05:27:03951class NET_EXPORT_PRIVATE RetransmittableFrames {
952 public:
953 RetransmittableFrames();
954 ~RetransmittableFrames();
955
956 // Allocates a local copy of the referenced StringPiece has QuicStreamFrame
957 // use it.
958 // Takes ownership of |stream_frame|.
959 const QuicFrame& AddStreamFrame(QuicStreamFrame* stream_frame);
960 // Takes ownership of the frame inside |frame|.
961 const QuicFrame& AddNonStreamFrame(const QuicFrame& frame);
962 const QuicFrames& frames() const { return frames_; }
963
[email protected]2115d33ba2014-01-02 21:53:52964 IsHandshake HasCryptoHandshake() const;
965
[email protected]8ba81212013-05-03 13:11:48966 void set_encryption_level(EncryptionLevel level);
967 EncryptionLevel encryption_level() const {
968 return encryption_level_;
969 }
970
[email protected]9db443912013-02-25 05:27:03971 private:
972 QuicFrames frames_;
[email protected]8ba81212013-05-03 13:11:48973 EncryptionLevel encryption_level_;
[email protected]9db443912013-02-25 05:27:03974 // Data referenced by the StringPiece of a QuicStreamFrame.
975 std::vector<std::string*> stream_data_;
976
977 DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames);
978};
979
980struct NET_EXPORT_PRIVATE SerializedPacket {
981 SerializedPacket(QuicPacketSequenceNumber sequence_number,
[email protected]ea825e02013-08-21 18:12:45982 QuicSequenceNumberLength sequence_number_length,
[email protected]9db443912013-02-25 05:27:03983 QuicPacket* packet,
984 QuicPacketEntropyHash entropy_hash,
[email protected]97cf3022013-09-05 14:30:16985 RetransmittableFrames* retransmittable_frames);
986 ~SerializedPacket();
[email protected]9db443912013-02-25 05:27:03987
988 QuicPacketSequenceNumber sequence_number;
[email protected]ea825e02013-08-21 18:12:45989 QuicSequenceNumberLength sequence_number_length;
[email protected]9db443912013-02-25 05:27:03990 QuicPacket* packet;
991 QuicPacketEntropyHash entropy_hash;
992 RetransmittableFrames* retransmittable_frames;
[email protected]97cf3022013-09-05 14:30:16993
994 // If set, these will be called when this packet is ACKed by the peer.
995 std::set<QuicAckNotifier*> notifiers;
[email protected]9db443912013-02-25 05:27:03996};
997
[email protected]c995c572013-01-18 05:43:20998// A struct for functions which consume data payloads and fins.
[email protected]6ae6e342014-02-06 02:21:42999struct NET_EXPORT_PRIVATE QuicConsumedData {
1000 QuicConsumedData(size_t bytes_consumed, bool fin_consumed);
1001
[email protected]c1b32c62013-01-20 02:49:101002 // By default, gtest prints the raw bytes of an object. The bool data
1003 // member causes this object to have padding bytes, which causes the
1004 // default gtest object printer to read uninitialize memory. So we need
1005 // to teach gtest how to print this object.
1006 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
1007 std::ostream& os, const QuicConsumedData& s);
1008
[email protected]97cf3022013-09-05 14:30:161009 // How many bytes were consumed.
[email protected]c995c572013-01-18 05:43:201010 size_t bytes_consumed;
[email protected]97cf3022013-09-05 14:30:161011
1012 // True if an incoming fin was consumed.
[email protected]c995c572013-01-18 05:43:201013 bool fin_consumed;
1014};
1015
[email protected]752fbe52013-10-14 08:35:321016enum WriteStatus {
1017 WRITE_STATUS_OK,
1018 WRITE_STATUS_BLOCKED,
1019 WRITE_STATUS_ERROR,
1020};
1021
1022// A struct used to return the result of write calls including either the number
1023// of bytes written or the error code, depending upon the status.
1024struct NET_EXPORT_PRIVATE WriteResult {
[email protected]6ae6e342014-02-06 02:21:421025 WriteResult(WriteStatus status, int bytes_written_or_error_code);
[email protected]51cc1342014-04-18 23:44:371026 WriteResult();
[email protected]752fbe52013-10-14 08:35:321027
1028 WriteStatus status;
1029 union {
1030 int bytes_written; // only valid when status is OK
1031 int error_code; // only valid when status is ERROR
1032 };
1033};
1034
[email protected]8b37a092012-10-18 21:53:491035} // namespace net
1036
1037#endif // NET_QUIC_QUIC_PROTOCOL_H_