blob: d39e36dab2be2b29360258f02a82cc241f67f666 [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>
tfarina3723da22015-06-03 21:39:309#include <stdint.h>
Avi Drissman13fc8932015-12-20 04:40:4610
[email protected]8b37a092012-10-18 21:53:4911#include <limits>
rtenneti4b06ae72014-08-26 03:43:4312#include <list>
[email protected]a674b4c2012-12-05 03:44:3013#include <map>
danakjad1777e2016-04-16 00:56:4214#include <memory>
[email protected]5640d0a2012-10-22 18:17:0215#include <ostream>
[email protected]e537f742012-12-07 15:33:5316#include <set>
17#include <string>
[email protected]8b37a092012-10-18 21:53:4918#include <utility>
19#include <vector>
20
[email protected]8b37a092012-10-18 21:53:4921#include "base/logging.h"
Avi Drissman13fc8932015-12-20 04:40:4622#include "base/macros.h"
rtenneti8dd12b22015-10-21 01:26:3823#include "base/memory/ref_counted.h"
[email protected]d069c11a2013-04-13 00:01:5524#include "base/strings/string_piece.h"
[email protected]165e0752012-11-16 07:49:4425#include "net/base/int128.h"
rtennetic14c8ab2015-06-18 05:47:4026#include "net/base/iovec.h"
[email protected]79d13dcb2014-02-05 07:23:1327#include "net/base/ip_endpoint.h"
[email protected]8b37a092012-10-18 21:53:4928#include "net/base/net_export.h"
rtenneti4efd55dd2015-09-18 01:12:0429#include "net/quic/interval_set.h"
[email protected]fee17f72013-02-03 07:47:4130#include "net/quic/quic_bandwidth.h"
[email protected]2a960e02012-11-11 14:48:1031#include "net/quic/quic_time.h"
rtennetic14c8ab2015-06-18 05:47:4032#include "net/quic/quic_types.h"
[email protected]8b37a092012-10-18 21:53:4933
34namespace net {
35
[email protected]8b37a092012-10-18 21:53:4936class QuicPacket;
[email protected]b064310782013-05-30 21:12:1737struct QuicPacketHeader;
jokulikc971baf92016-01-06 00:36:3938class QuicAckListenerInterface;
[email protected]8b37a092012-10-18 21:53:4939
Avi Drissman13fc8932015-12-20 04:40:4640typedef uint64_t QuicConnectionId;
41typedef uint32_t QuicStreamId;
42typedef uint64_t QuicStreamOffset;
43typedef uint64_t QuicPacketNumber;
44typedef uint8_t QuicPathId;
rtennetia004d332015-08-28 06:44:5745typedef QuicPacketNumber QuicFecGroupNumber;
Avi Drissman13fc8932015-12-20 04:40:4646typedef uint64_t QuicPublicResetNonceProof;
47typedef uint8_t QuicPacketEntropyHash;
48typedef uint32_t QuicHeaderId;
[email protected]2532de12013-05-09 12:29:3349// QuicTag is the type of a tag in the wire protocol.
Avi Drissman13fc8932015-12-20 04:40:4650typedef uint32_t QuicTag;
[email protected]2532de12013-05-09 12:29:3351typedef std::vector<QuicTag> QuicTagVector;
[email protected]79d13dcb2014-02-05 07:23:1352typedef std::map<QuicTag, std::string> QuicTagValueMap;
Avi Drissman13fc8932015-12-20 04:40:4653typedef uint16_t QuicPacketLength;
[email protected]cff7b7b2013-01-11 08:49:0754
rtennetibb2780c2015-07-22 19:16:0855// Default initial maximum size in bytes of a QUIC packet.
[email protected]310d37b2014-08-02 06:15:3756const QuicByteCount kDefaultMaxPacketSize = 1350;
rtenneti16a20772015-02-17 18:58:4857// Default initial maximum size in bytes of a QUIC packet for servers.
58const QuicByteCount kDefaultServerMaxPacketSize = 1000;
[email protected]8e01c062013-10-31 07:35:3159// The maximum packet size of any QUIC packet, based on ethernet's max size,
fayanga31a74b2015-12-28 17:27:1460// minus the IP and UDP headers. IPv6 has a 40 byte header, UDP adds an
[email protected]41fb6372013-12-10 05:26:4061// additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's
62// max packet size is 1500 bytes, 1500 - 48 = 1452.
63const QuicByteCount kMaxPacketSize = 1452;
rtenneti9e0fb502015-03-08 06:07:1664// Default maximum packet size used in the Linux TCP implementation.
65// Used in QUIC for congestion window computations in bytes.
[email protected]ce7bb1412014-05-17 15:51:3366const QuicByteCount kDefaultTCPMSS = 1460;
[email protected]8e01c062013-10-31 07:35:3167
rch1fe2eeb2015-10-26 14:45:5768// We match SPDY's use of 32 (since we'd compete with SPDY).
69const QuicPacketCount kInitialCongestionWindow = 32;
[email protected]8e01c062013-10-31 07:35:3170
rtenneti7652bf32015-01-05 18:51:0771// Minimum size of initial flow control window, for both stream and session.
Avi Drissman13fc8932015-12-20 04:40:4672const uint32_t kMinimumFlowControlSendWindow = 16 * 1024; // 16 KB
[email protected]9bb57c72014-03-31 20:36:0473
rjshadec86dbfa2015-11-12 20:16:2574// Maximum flow control receive window limits for connection and stream.
75const QuicByteCount kStreamReceiveWindowLimit = 16 * 1024 * 1024; // 16 MB
76const QuicByteCount kSessionReceiveWindowLimit = 24 * 1024 * 1024; // 24 MB
77
rtennetifb3fa6c2015-03-16 23:04:5578// Minimum size of the CWND, in packets, when doing bandwidth resumption.
rtenneti8d2a808d2014-11-26 01:10:0979const QuicPacketCount kMinCongestionWindowForBandwidthResumption = 10;
80
rtenneti581b6ae82015-07-20 20:48:0181// Maximum size of the CWND, in packets.
82const QuicPacketCount kMaxCongestionWindow = 200;
rtenneti69e64aa2015-06-26 04:25:3083
84// Maximum number of tracked packets.
85const QuicPacketCount kMaxTrackedPackets = 5000;
[email protected]0ac0c5b2013-11-20 05:55:5886
rtenneti23186682014-10-30 01:49:3387// Default size of the socket receive buffer in bytes.
[email protected]648f81142014-08-15 21:38:4688const QuicByteCount kDefaultSocketReceiveBuffer = 256 * 1024;
rtenneti23186682014-10-30 01:49:3389// Minimum size of the socket receive buffer in bytes.
90// Smaller values are ignored.
91const QuicByteCount kMinSocketReceiveBuffer = 16 * 1024;
[email protected]a97b3182014-08-08 08:10:1892
rtenneti95293802015-03-27 18:59:2393// Fraction of the receive buffer that can be used for encrypted bytes.
94// Allows a 5% overhead for IP and UDP framing, as well as ack only packets.
95static const float kUsableRecieveBufferFraction = 0.95f;
rtenneti581b6ae82015-07-20 20:48:0196// Fraction of the receive buffer that can be used, based on conservative
97// estimates and testing on Linux.
98// An alternative to kUsableRecieveBufferFraction.
99static const float kConservativeReceiveBufferFraction = 0.6f;
rtenneti95293802015-03-27 18:59:23100
rtennetifc97ab62014-11-11 22:17:49101// Don't allow a client to suggest an RTT shorter than 10ms.
Avi Drissman13fc8932015-12-20 04:40:46102const uint32_t kMinInitialRoundTripTimeUs = 10 * kNumMicrosPerMilli;
rtennetifc97ab62014-11-11 22:17:49103
[email protected]8e01c062013-10-31 07:35:31104// Don't allow a client to suggest an RTT longer than 15 seconds.
Avi Drissman13fc8932015-12-20 04:40:46105const uint32_t kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond;
[email protected]8b37a092012-10-18 21:53:49106
107// Maximum number of open streams per connection.
108const size_t kDefaultMaxStreamsPerConnection = 100;
109
[email protected]af806e62013-05-22 14:47:50110// Number of bytes reserved for public flags in the packet header.
111const size_t kPublicFlagsSize = 1;
[email protected]5351cc4b2013-03-03 07:22:41112// Number of bytes reserved for version number in the packet header.
113const size_t kQuicVersionSize = 4;
zhongyib8677022015-12-01 05:51:30114// Number of bytes reserved for path id in the packet header.
115const size_t kQuicPathIdSize = 1;
[email protected]c995c572013-01-18 05:43:20116// Number of bytes reserved for private flags in the packet header.
117const size_t kPrivateFlagsSize = 1;
118// Number of bytes reserved for FEC group in the packet header.
119const size_t kFecGroupSize = 1;
[email protected]5351cc4b2013-03-03 07:22:41120
121// Signifies that the QuicPacket will contain version of the protocol.
122const bool kIncludeVersion = true;
zhongyib8677022015-12-01 05:51:30123// Signifies that the QuicPacket will contain path id.
124const bool kIncludePathId = true;
[email protected]c995c572013-01-18 05:43:20125
zhongyi4a9d27b2016-01-12 20:08:31126// Stream ID is reserved to denote an invalid ID.
127const QuicStreamId kInvalidStreamId = 0;
128
[email protected]8b37a092012-10-18 21:53:49129// Reserved ID for the crypto stream.
[email protected]8b37a092012-10-18 21:53:49130const QuicStreamId kCryptoStreamId = 1;
131
[email protected]4d640792013-12-18 22:21:08132// Reserved ID for the headers stream.
133const QuicStreamId kHeadersStreamId = 3;
134
jri3285d93a2015-12-14 08:53:19135// Header key used to identify final offset on data stream when sending HTTP/2
136// trailing headers over QUIC.
137NET_EXPORT_PRIVATE extern const char* const kFinalOffsetHeaderKey;
138
[email protected]648f81142014-08-15 21:38:46139// Maximum delayed ack time, in ms.
Avi Drissman13fc8932015-12-20 04:40:46140const int64_t kMaxDelayedAckTimeMs = 25;
[email protected]648f81142014-08-15 21:38:46141
rjshaded069aaee2016-03-11 20:42:17142// Minimum tail loss probe time in ms.
143static const int64_t kMinTailLossProbeTimeoutMs = 10;
144
rtennetib5512bb2014-09-29 19:17:15145// The timeout before the handshake succeeds.
Avi Drissman13fc8932015-12-20 04:40:46146const int64_t kInitialIdleTimeoutSecs = 5;
rtennetib5512bb2014-09-29 19:17:15147// The default idle timeout.
Avi Drissman13fc8932015-12-20 04:40:46148const int64_t kDefaultIdleTimeoutSecs = 30;
rtenneti31e9fd62014-09-16 05:22:15149// The maximum idle timeout that can be negotiated.
Avi Drissman13fc8932015-12-20 04:40:46150const int64_t kMaximumIdleTimeoutSecs = 60 * 10; // 10 minutes.
rtenneti31e9fd62014-09-16 05:22:15151// The default timeout for a connection until the crypto handshake succeeds.
Avi Drissman13fc8932015-12-20 04:40:46152const int64_t kMaxTimeForCryptoHandshakeSecs = 10; // 10 secs.
[email protected]8b37a092012-10-18 21:53:49153
rtenneti93bce7ece2014-10-13 22:38:41154// Default limit on the number of undecryptable packets the connection buffers
155// before the CHLO/SHLO arrive.
156const size_t kDefaultMaxUndecryptablePackets = 10;
157
[email protected]525948df2014-04-21 06:26:58158// Default ping timeout.
Avi Drissman13fc8932015-12-20 04:40:46159const int64_t kPingTimeoutSecs = 15; // 15 secs.
[email protected]525948df2014-04-21 06:26:58160
[email protected]ca4e0d92014-08-22 16:33:22161// Minimum number of RTTs between Server Config Updates (SCUP) sent to client.
162const int kMinIntervalBetweenServerConfigUpdatesRTTs = 10;
163
164// Minimum time between Server Config Updates (SCUP) sent to client.
165const int kMinIntervalBetweenServerConfigUpdatesMs = 1000;
166
rtenneti33da8ab2014-11-04 04:17:00167// Minimum number of packets between Server Config Updates (SCUP).
168const int kMinPacketsBetweenServerConfigUpdates = 100;
169
rtennetib5512bb2014-09-29 19:17:15170// The number of open streams that a server will accept is set to be slightly
171// larger than the negotiated limit. Immediately closing the connection if the
172// client opens slightly too many streams is not ideal: the client may have sent
173// a FIN that was lost, and simultaneously opened a new stream. The number of
174// streams a server accepts is a fixed increment over the negotiated limit, or a
175// percentage increase, whichever is larger.
rtenneti31e9fd62014-09-16 05:22:15176const float kMaxStreamsMultiplier = 1.1f;
rtennetib5512bb2014-09-29 19:17:15177const int kMaxStreamsMinimumIncrement = 10;
rtenneti31e9fd62014-09-16 05:22:15178
rtenneti159828f2015-10-13 06:58:09179// Available streams are ones with IDs less than the highest stream that has
180// been opened which have neither been opened or reset. The limit on the number
181// of available streams is 10 times the limit on the number of open streams.
182const int kMaxAvailableStreamsMultiplier = 10;
183
jric533399b2016-01-29 07:36:01184// Track the number of promises that are not yet claimed by a
185// corresponding get. This must be smaller than
186// kMaxAvailableStreamsMultiplier, because RST on a promised stream my
187// create available streams entries.
188const int kMaxPromisedStreamsMultiplier = kMaxAvailableStreamsMultiplier - 1;
189
[email protected]b007e632013-10-28 08:39:25190// We define an unsigned 16-bit floating point value, inspired by IEEE floats
191// (http://en.wikipedia.org/wiki/Half_precision_floating-point_format),
192// with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden
193// bit) and denormals, but without signs, transfinites or fractions. Wire format
194// 16 bits (little-endian byte order) are split into exponent (high 5) and
195// mantissa (low 11) and decoded as:
Avi Drissman13fc8932015-12-20 04:40:46196// uint64_t value;
[email protected]b007e632013-10-28 08:39:25197// if (exponent == 0) value = mantissa;
198// else value = (mantissa | 1 << 11) << (exponent - 1)
199const int kUFloat16ExponentBits = 5;
rjshaded5ced072015-12-18 19:26:02200const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30
201const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11
[email protected]b007e632013-10-28 08:39:25202const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12
Avi Drissman13fc8932015-12-20 04:40:46203const uint64_t kUFloat16MaxValue = // 0x3FFC0000000
rjshaded5ced072015-12-18 19:26:02204 ((UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1)
205 << kUFloat16MaxExponent;
[email protected]b007e632013-10-28 08:39:25206
jri3285d93a2015-12-14 08:53:19207// Default path ID.
208const QuicPathId kDefaultPathId = 0;
fayanga31a74b2015-12-28 17:27:14209// Invalid path ID.
210const QuicPathId kInvalidPathId = 0xff;
jri3285d93a2015-12-14 08:53:19211
fayanga64c1a92016-02-13 01:55:58212enum TransmissionType : int8_t {
[email protected]2532de12013-05-09 12:29:33213 NOT_RETRANSMISSION,
[email protected]b9475b582014-03-20 20:04:33214 FIRST_TRANSMISSION_TYPE = NOT_RETRANSMISSION,
rjshaded5ced072015-12-18 19:26:02215 HANDSHAKE_RETRANSMISSION, // Retransmits due to handshake timeouts.
rtenneti31e9fd62014-09-16 05:22:15216 ALL_UNACKED_RETRANSMISSION, // Retransmits all unacked packets.
217 ALL_INITIAL_RETRANSMISSION, // Retransmits all initially encrypted packets.
rjshaded5ced072015-12-18 19:26:02218 LOSS_RETRANSMISSION, // Retransmits due to loss detection.
219 RTO_RETRANSMISSION, // Retransmits due to retransmit time out.
220 TLP_RETRANSMISSION, // Tail loss probes.
[email protected]b9475b582014-03-20 20:04:33221 LAST_TRANSMISSION_TYPE = TLP_RETRANSMISSION,
[email protected]74bda142013-03-31 02:49:11222};
223
fayanga64c1a92016-02-13 01:55:58224enum HasRetransmittableData : int8_t {
[email protected]2532de12013-05-09 12:29:33225 NO_RETRANSMITTABLE_DATA,
226 HAS_RETRANSMITTABLE_DATA,
[email protected]74bda142013-03-31 02:49:11227};
228
fayanga64c1a92016-02-13 01:55:58229enum IsHandshake : int8_t { NOT_HANDSHAKE, IS_HANDSHAKE };
[email protected]575cce62013-08-03 02:06:43230
rtenneti6f48aa92015-03-16 02:18:48231enum class Perspective { IS_SERVER, IS_CLIENT };
232
fayanga64c1a92016-02-13 01:55:58233// Describes whether a ConnectionClose was originated by the peer.
234enum class ConnectionCloseSource { FROM_PEER, FROM_SELF };
235
jri78ec06a2016-03-31 18:19:40236// Should a connection be closed silently or not.
237enum class ConnectionCloseBehavior {
238 SILENT_CLOSE,
239 SEND_CONNECTION_CLOSE_PACKET
240};
241
rtenneti6f48aa92015-03-16 02:18:48242NET_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
243 const Perspective& s);
[email protected]be24ab22012-10-22 03:01:52244enum QuicFrameType {
[email protected]6ae6e342014-02-06 02:21:42245 // Regular frame types. The values set here cannot change without the
246 // introduction of a new QUIC version.
[email protected]c995c572013-01-18 05:43:20247 PADDING_FRAME = 0,
[email protected]6ae6e342014-02-06 02:21:42248 RST_STREAM_FRAME = 1,
249 CONNECTION_CLOSE_FRAME = 2,
250 GOAWAY_FRAME = 3,
251 WINDOW_UPDATE_FRAME = 4,
252 BLOCKED_FRAME = 5,
[email protected]93dd91f2014-02-27 00:09:03253 STOP_WAITING_FRAME = 6,
[email protected]d8c522112014-04-23 09:23:25254 PING_FRAME = 7,
rchcaec4242016-01-22 20:49:52255 PATH_CLOSE_FRAME = 8,
[email protected]6ae6e342014-02-06 02:21:42256
rtennetif4bdb542015-01-21 14:33:05257 // STREAM and ACK frames are special frames. They are encoded differently on
258 // the wire and their values do not need to be stable.
[email protected]97cf3022013-09-05 14:30:16259 STREAM_FRAME,
260 ACK_FRAME,
rtenneti69e64aa2015-06-26 04:25:30261 // The path MTU discovery frame is encoded as a PING frame on the wire.
262 MTU_DISCOVERY_FRAME,
[email protected]be24ab22012-10-22 03:01:52263 NUM_FRAME_TYPES
[email protected]8b37a092012-10-18 21:53:49264};
265
[email protected]3aa9ca72014-02-27 19:39:43266enum QuicConnectionIdLength {
267 PACKET_0BYTE_CONNECTION_ID = 0,
268 PACKET_1BYTE_CONNECTION_ID = 1,
269 PACKET_4BYTE_CONNECTION_ID = 4,
270 PACKET_8BYTE_CONNECTION_ID = 8
[email protected]b064310782013-05-30 21:12:17271};
272
273enum InFecGroup {
274 NOT_IN_FEC_GROUP,
275 IN_FEC_GROUP,
276};
277
fayanga64c1a92016-02-13 01:55:58278enum QuicPacketNumberLength : int8_t {
rtennetia004d332015-08-28 06:44:57279 PACKET_1BYTE_PACKET_NUMBER = 1,
280 PACKET_2BYTE_PACKET_NUMBER = 2,
281 PACKET_4BYTE_PACKET_NUMBER = 4,
282 PACKET_6BYTE_PACKET_NUMBER = 6
[email protected]25c31dc2013-06-05 17:56:04283};
284
[email protected]8e01c062013-10-31 07:35:31285// Used to indicate a QuicSequenceNumberLength using two flag bits.
rtennetia004d332015-08-28 06:44:57286enum QuicPacketNumberLengthFlags {
287 PACKET_FLAGS_1BYTE_PACKET = 0, // 00
288 PACKET_FLAGS_2BYTE_PACKET = 1, // 01
289 PACKET_FLAGS_4BYTE_PACKET = 1 << 1, // 10
290 PACKET_FLAGS_6BYTE_PACKET = 1 << 1 | 1, // 11
[email protected]8e01c062013-10-31 07:35:31291};
292
[email protected]f62262b2013-07-05 20:57:30293// The public flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20294enum QuicPacketPublicFlags {
295 PACKET_PUBLIC_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30296
297 // Bit 0: Does the packet header contains version info?
298 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0,
299
300 // Bit 1: Is this packet a public reset packet?
301 PACKET_PUBLIC_FLAGS_RST = 1 << 1,
302
[email protected]3aa9ca72014-02-27 19:39:43303 // Bits 2 and 3 specify the length of the ConnectionId as follows:
[email protected]f62262b2013-07-05 20:57:30304 // ----00--: 0 bytes
305 // ----01--: 1 byte
306 // ----10--: 4 bytes
307 // ----11--: 8 bytes
[email protected]3aa9ca72014-02-27 19:39:43308 PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID = 0,
309 PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID = 1 << 2,
310 PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID = 1 << 3,
311 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID = 1 << 3 | 1 << 2,
[email protected]f62262b2013-07-05 20:57:30312
rtennetia004d332015-08-28 06:44:57313 // Bits 4 and 5 describe the packet number length as follows:
[email protected]f62262b2013-07-05 20:57:30314 // --00----: 1 byte
315 // --01----: 2 bytes
316 // --10----: 4 bytes
317 // --11----: 6 bytes
rtennetia004d332015-08-28 06:44:57318 PACKET_PUBLIC_FLAGS_1BYTE_PACKET = PACKET_FLAGS_1BYTE_PACKET << 4,
319 PACKET_PUBLIC_FLAGS_2BYTE_PACKET = PACKET_FLAGS_2BYTE_PACKET << 4,
320 PACKET_PUBLIC_FLAGS_4BYTE_PACKET = PACKET_FLAGS_4BYTE_PACKET << 4,
321 PACKET_PUBLIC_FLAGS_6BYTE_PACKET = PACKET_FLAGS_6BYTE_PACKET << 4,
[email protected]f62262b2013-07-05 20:57:30322
zhongyib8677022015-12-01 05:51:30323 // Bit 6: Does the packet header contain a path id?
324 PACKET_PUBLIC_FLAGS_MULTIPATH = 1 << 6,
325
jric533399b2016-01-29 07:36:01326 // All bits set (bit 7 is not currently used): 01111111
zhongyib8677022015-12-01 05:51:30327 PACKET_PUBLIC_FLAGS_MAX = (1 << 7) - 1,
[email protected]c995c572013-01-18 05:43:20328};
[email protected]8b37a092012-10-18 21:53:49329
[email protected]f62262b2013-07-05 20:57:30330// The private flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20331enum QuicPacketPrivateFlags {
332 PACKET_PRIVATE_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30333
334 // Bit 0: Does this packet contain an entropy bit?
[email protected]b064310782013-05-30 21:12:17335 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0,
[email protected]f62262b2013-07-05 20:57:30336
337 // Bit 1: Payload is part of an FEC group?
338 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1,
339
340 // Bit 2: Payload is FEC as opposed to frames?
341 PACKET_PRIVATE_FLAGS_FEC = 1 << 2,
342
343 // All bits set (bits 3-7 are not currently used): 00000111
jokulikf2bd55c52016-03-24 22:35:30344 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1,
345
346 // For version 32 (bits 1-7 are not used): 00000001
347 PACKET_PRIVATE_FLAGS_MAX_VERSION_32 = (1 << 1) - 1
[email protected]c995c572013-01-18 05:43:20348};
349
[email protected]48878092013-07-26 14:51:56350// The available versions of QUIC. Guaranteed that the integer value of the enum
351// will match the version number.
352// When adding a new version to this enum you should add it to
[email protected]8bbfaeb72013-08-09 06:38:26353// kSupportedQuicVersions (if appropriate), and also add a new case to the
354// helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and
355// QuicVersionToString.
[email protected]48878092013-07-26 14:51:56356enum QuicVersion {
357 // Special case to indicate unknown/unsupported QUIC version.
358 QUIC_VERSION_UNSUPPORTED = 0,
359
rchc0815442015-04-18 13:29:46360 QUIC_VERSION_25 = 25, // SPDY/4 header keys, and removal of error_details
361 // from QuicRstStreamFrame
zhongyic92bc492015-09-22 19:14:36362 QUIC_VERSION_26 = 26, // In CHLO, send XLCT tag containing hash of leaf cert
rtenneti159828f2015-10-13 06:58:09363 QUIC_VERSION_27 = 27, // Sends a nonce in the SHLO.
rtenneti5ca6eee2015-10-15 21:54:30364 QUIC_VERSION_28 = 28, // Receiver can refuse to create a requested stream.
rch99b644c2015-11-04 05:25:28365 QUIC_VERSION_29 = 29, // Server and client honor QUIC_STREAM_NO_ERROR.
366 QUIC_VERSION_30 = 30, // Add server side support of cert transparency.
rch28f6469d2016-03-13 21:13:08367 QUIC_VERSION_31 = 31, // Adds a hash of the client hello to crypto proof.
jokulikf2bd55c52016-03-24 22:35:30368 QUIC_VERSION_32 = 32, // FEC related fields are removed from wire format.
[email protected]48878092013-07-26 14:51:56369};
370
371// This vector contains QUIC versions which we currently support.
372// This should be ordered such that the highest supported version is the first
373// element, with subsequent elements in descending order (versions can be
374// skipped as necessary).
[email protected]31ae854842013-11-27 00:05:46375//
[email protected]310d37b2014-08-02 06:15:37376// IMPORTANT: if you are adding to this list, follow the instructions at
[email protected]31ae854842013-11-27 00:05:46377// http://sites/quic/adding-and-removing-versions
zhongyic92bc492015-09-22 19:14:36378static const QuicVersion kSupportedQuicVersions[] = {
jokulikf2bd55c52016-03-24 22:35:30379 QUIC_VERSION_32, QUIC_VERSION_31, QUIC_VERSION_30, QUIC_VERSION_29,
380 QUIC_VERSION_28, QUIC_VERSION_27, QUIC_VERSION_26, QUIC_VERSION_25};
[email protected]48878092013-07-26 14:51:56381
382typedef std::vector<QuicVersion> QuicVersionVector;
383
[email protected]b007e632013-10-28 08:39:25384// Returns a vector of QUIC versions in kSupportedQuicVersions.
385NET_EXPORT_PRIVATE QuicVersionVector QuicSupportedVersions();
[email protected]ea2ab47b2013-08-13 00:44:11386
[email protected]48878092013-07-26 14:51:56387// QuicTag is written to and read from the wire, but we prefer to use
388// the more readable QuicVersion at other levels.
389// Helper function which translates from a QuicVersion to a QuicTag. Returns 0
390// if QuicVersion is unsupported.
391NET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version);
392
393// Returns appropriate QuicVersion from a QuicTag.
394// Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood.
395NET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag);
396
397// Helper function which translates from a QuicVersion to a string.
398// Returns strings corresponding to enum names (e.g. QUIC_VERSION_6).
399NET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version);
400
401// Returns comma separated list of string representations of QuicVersion enum
[email protected]b007e632013-10-28 08:39:25402// values in the supplied |versions| vector.
403NET_EXPORT_PRIVATE std::string QuicVersionVectorToString(
404 const QuicVersionVector& versions);
[email protected]48878092013-07-26 14:51:56405
406// Version and Crypto tags are written to the wire with a big-endian
407// representation of the name of the tag. For example
408// the client hello tag (CHLO) will be written as the
409// following 4 bytes: 'C' 'H' 'L' 'O'. Since it is
Avi Drissman13fc8932015-12-20 04:40:46410// stored in memory as a little endian uint32_t, we need
[email protected]48878092013-07-26 14:51:56411// to reverse the order of the bytes.
412
413// MakeQuicTag returns a value given the four bytes. For example:
414// MakeQuicTag('C', 'H', 'L', 'O');
415NET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d);
416
[email protected]9cda5fd2014-06-03 10:20:28417// Returns true if the tag vector contains the specified tag.
[email protected]cc1aa272014-06-30 19:48:22418NET_EXPORT_PRIVATE bool ContainsQuicTag(const QuicTagVector& tag_vector,
419 QuicTag tag);
[email protected]9cda5fd2014-06-03 10:20:28420
rjshaded069aaee2016-03-11 20:42:17421// Size in bytes of the data packet header.
[email protected]79d13dcb2014-02-05 07:23:13422NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(const QuicPacketHeader& header);
[email protected]b064310782013-05-30 21:12:17423
rtennetia004d332015-08-28 06:44:57424NET_EXPORT_PRIVATE size_t
425GetPacketHeaderSize(QuicConnectionIdLength connection_id_length,
426 bool include_version,
zhongyib8677022015-12-01 05:51:30427 bool include_path_id,
rjshaded069aaee2016-03-11 20:42:17428 QuicPacketNumberLength packet_number_length);
rchcaec4242016-01-22 20:49:52429
[email protected]b064310782013-05-30 21:12:17430// Index of the first byte in a QUIC packet of encrypted data.
rtennetia004d332015-08-28 06:44:57431NET_EXPORT_PRIVATE size_t
rjshaded069aaee2016-03-11 20:42:17432GetStartOfEncryptedData(const QuicPacketHeader& header);
433
434NET_EXPORT_PRIVATE size_t
rtennetia004d332015-08-28 06:44:57435GetStartOfEncryptedData(QuicConnectionIdLength connection_id_length,
436 bool include_version,
rchcaec4242016-01-22 20:49:52437 bool include_path_id,
rtennetia004d332015-08-28 06:44:57438 QuicPacketNumberLength packet_number_length);
[email protected]b064310782013-05-30 21:12:17439
[email protected]74bda142013-03-31 02:49:11440enum QuicRstStreamErrorCode {
rch99b644c2015-11-04 05:25:28441 // Complete response has been sent, sending a RST to ask the other endpoint
442 // to stop sending request data without discarding the response.
[email protected]74bda142013-03-31 02:49:11443 QUIC_STREAM_NO_ERROR = 0,
[email protected]8b37a092012-10-18 21:53:49444
[email protected]24e5bc52013-09-18 15:36:58445 // There was some error which halted stream processing.
446 QUIC_ERROR_PROCESSING_STREAM,
[email protected]8b37a092012-10-18 21:53:49447 // We got two fin or reset offsets which did not match.
448 QUIC_MULTIPLE_TERMINATION_OFFSETS,
449 // We got bad payload and can not respond to it at the protocol level.
450 QUIC_BAD_APPLICATION_PAYLOAD,
[email protected]74bda142013-03-31 02:49:11451 // Stream closed due to connection error. No reset frame is sent when this
452 // happens.
453 QUIC_STREAM_CONNECTION_ERROR,
454 // GoAway frame sent. No more stream can be created.
455 QUIC_STREAM_PEER_GOING_AWAY,
[email protected]06ff5152013-08-29 01:03:05456 // The stream has been cancelled.
457 QUIC_STREAM_CANCELLED,
rtenneti4a5df262014-11-07 00:43:58458 // Closing stream locally, sending a RST to allow for proper flow control
459 // accounting. Sent in response to a RST from the peer.
460 QUIC_RST_ACKNOWLEDGEMENT,
rtenneti5ca6eee2015-10-15 21:54:30461 // Receiver refused to create the stream (because its limit on open streams
462 // has been reached). The sender should retry the request later (using
463 // another stream).
464 QUIC_REFUSED_STREAM,
jric533399b2016-01-29 07:36:01465 // Invalid URL in PUSH_PROMISE request header.
466 QUIC_INVALID_PROMISE_URL,
467 // Server is not authoritative for this URL.
468 QUIC_UNAUTHORIZED_PROMISE_URL,
469 // Can't have more than one active PUSH_PROMISE per URL.
470 QUIC_DUPLICATE_PROMISE_URL,
ckrasic244375a32016-02-04 21:21:22471 // Vary check failed.
472 QUIC_PROMISE_VARY_MISMATCH,
ckrasic171ef13e2016-02-26 01:20:16473 // Only GET and HEAD methods allowed.
474 QUIC_INVALID_PROMISE_METHOD,
[email protected]74bda142013-03-31 02:49:11475 // No error. Used as bound while iterating.
476 QUIC_STREAM_LAST_ERROR,
477};
[email protected]8b37a092012-10-18 21:53:49478
[email protected]51cc1342014-04-18 23:44:37479// Because receiving an unknown QuicRstStreamErrorCode results in connection
480// teardown, we use this to make sure any errors predating a given version are
481// downgraded to the most appropriate existing error.
rjshaded5ced072015-12-18 19:26:02482NET_EXPORT_PRIVATE QuicRstStreamErrorCode
483AdjustErrorForVersion(QuicRstStreamErrorCode error_code, QuicVersion version);
[email protected]51cc1342014-04-18 23:44:37484
[email protected]89264042013-08-21 07:35:24485// These values must remain stable as they are uploaded to UMA histograms.
486// To add a new error code, use the current value of QUIC_LAST_ERROR and
487// increment QUIC_LAST_ERROR.
[email protected]74bda142013-03-31 02:49:11488enum QuicErrorCode {
489 QUIC_NO_ERROR = 0,
490
491 // Connection has reached an invalid state.
[email protected]89264042013-08-21 07:35:24492 QUIC_INTERNAL_ERROR = 1,
[email protected]74bda142013-03-31 02:49:11493 // There were data frames after the a fin or reset.
[email protected]89264042013-08-21 07:35:24494 QUIC_STREAM_DATA_AFTER_TERMINATION = 2,
[email protected]8b37a092012-10-18 21:53:49495 // Control frame is malformed.
[email protected]89264042013-08-21 07:35:24496 QUIC_INVALID_PACKET_HEADER = 3,
[email protected]be24ab22012-10-22 03:01:52497 // Frame data is malformed.
[email protected]89264042013-08-21 07:35:24498 QUIC_INVALID_FRAME_DATA = 4,
499 // The packet contained no payload.
500 QUIC_MISSING_PAYLOAD = 48,
[email protected]8b37a092012-10-18 21:53:49501 // FEC data is malformed.
[email protected]89264042013-08-21 07:35:24502 QUIC_INVALID_FEC_DATA = 5,
503 // STREAM frame data is malformed.
504 QUIC_INVALID_STREAM_DATA = 46,
jokulikf2bd55c52016-03-24 22:35:30505 // STREAM frame data overlaps with buffered data.
506 QUIC_OVERLAPPING_STREAM_DATA = 87,
jri78ec06a2016-03-31 18:19:40507 // Received STREAM frame data is not encrypted.
[email protected]42a3eba2014-04-30 10:52:55508 QUIC_UNENCRYPTED_STREAM_DATA = 61,
jri78ec06a2016-03-31 18:19:40509 // Attempt to send unencrypted STREAM frame.
510 QUIC_ATTEMPT_TO_SEND_UNENCRYPTED_STREAM_DATA = 88,
zhongyi4a9d27b2016-01-12 20:08:31511 // FEC frame data is not encrypted.
512 QUIC_UNENCRYPTED_FEC_DATA = 77,
[email protected]89264042013-08-21 07:35:24513 // RST_STREAM frame data is malformed.
514 QUIC_INVALID_RST_STREAM_DATA = 6,
515 // CONNECTION_CLOSE frame data is malformed.
516 QUIC_INVALID_CONNECTION_CLOSE_DATA = 7,
517 // GOAWAY frame data is malformed.
518 QUIC_INVALID_GOAWAY_DATA = 8,
[email protected]6ae6e342014-02-06 02:21:42519 // WINDOW_UPDATE frame data is malformed.
520 QUIC_INVALID_WINDOW_UPDATE_DATA = 57,
521 // BLOCKED frame data is malformed.
522 QUIC_INVALID_BLOCKED_DATA = 58,
[email protected]93dd91f2014-02-27 00:09:03523 // STOP_WAITING frame data is malformed.
524 QUIC_INVALID_STOP_WAITING_DATA = 60,
rchcaec4242016-01-22 20:49:52525 // PATH_CLOSE frame data is malformed.
526 QUIC_INVALID_PATH_CLOSE_DATA = 78,
[email protected]89264042013-08-21 07:35:24527 // ACK frame data is malformed.
528 QUIC_INVALID_ACK_DATA = 9,
rtennetif4bdb542015-01-21 14:33:05529
[email protected]14e8106c2013-03-14 16:25:33530 // Version negotiation packet is malformed.
[email protected]89264042013-08-21 07:35:24531 QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10,
[email protected]899951652013-05-16 12:52:39532 // Public RST packet is malformed.
[email protected]89264042013-08-21 07:35:24533 QUIC_INVALID_PUBLIC_RST_PACKET = 11,
[email protected]8b37a092012-10-18 21:53:49534 // There was an error decrypting.
[email protected]89264042013-08-21 07:35:24535 QUIC_DECRYPTION_FAILURE = 12,
[email protected]8b37a092012-10-18 21:53:49536 // There was an error encrypting.
[email protected]89264042013-08-21 07:35:24537 QUIC_ENCRYPTION_FAILURE = 13,
[email protected]8b37a092012-10-18 21:53:49538 // The packet exceeded kMaxPacketSize.
[email protected]89264042013-08-21 07:35:24539 QUIC_PACKET_TOO_LARGE = 14,
[email protected]9db443912013-02-25 05:27:03540 // The peer is going away. May be a client or server.
[email protected]89264042013-08-21 07:35:24541 QUIC_PEER_GOING_AWAY = 16,
[email protected]8b37a092012-10-18 21:53:49542 // A stream ID was invalid.
[email protected]89264042013-08-21 07:35:24543 QUIC_INVALID_STREAM_ID = 17,
[email protected]24e5bc52013-09-18 15:36:58544 // A priority was invalid.
545 QUIC_INVALID_PRIORITY = 49,
[email protected]8b37a092012-10-18 21:53:49546 // Too many streams already open.
[email protected]89264042013-08-21 07:35:24547 QUIC_TOO_MANY_OPEN_STREAMS = 18,
rtenneti159828f2015-10-13 06:58:09548 // The peer created too many available streams.
549 QUIC_TOO_MANY_AVAILABLE_STREAMS = 76,
[email protected]86a318d2013-01-23 21:16:04550 // Received public reset for this connection.
[email protected]89264042013-08-21 07:35:24551 QUIC_PUBLIC_RESET = 19,
[email protected]c244c5a12013-05-07 20:55:04552 // Invalid protocol version.
[email protected]89264042013-08-21 07:35:24553 QUIC_INVALID_VERSION = 20,
[email protected]92bf17c2014-03-03 21:14:03554
[email protected]c244c5a12013-05-07 20:55:04555 // The Header ID for a stream was too far from the previous.
[email protected]89264042013-08-21 07:35:24556 QUIC_INVALID_HEADER_ID = 22,
[email protected]899951652013-05-16 12:52:39557 // Negotiable parameter received during handshake had invalid value.
[email protected]89264042013-08-21 07:35:24558 QUIC_INVALID_NEGOTIATED_VALUE = 23,
[email protected]899951652013-05-16 12:52:39559 // There was an error decompressing data.
[email protected]89264042013-08-21 07:35:24560 QUIC_DECOMPRESSION_FAILURE = 24,
rtenneti2cae2072016-02-05 02:21:33561 // The connection timed out due to no network activity.
562 QUIC_NETWORK_IDLE_TIMEOUT = 25,
563 // The connection timed out waiting for the handshake to complete.
564 QUIC_HANDSHAKE_TIMEOUT = 67,
zhongyi2341cda2016-03-10 04:09:34565 // There was an error encountered migrating addresses.
[email protected]89264042013-08-21 07:35:24566 QUIC_ERROR_MIGRATING_ADDRESS = 26,
zhongyi2341cda2016-03-10 04:09:34567 // There was an error encountered migrating port only.
568 QUIC_ERROR_MIGRATING_PORT = 86,
[email protected]1505a512013-09-04 22:59:35569 // There was an error while writing to the socket.
[email protected]89264042013-08-21 07:35:24570 QUIC_PACKET_WRITE_ERROR = 27,
[email protected]1505a512013-09-04 22:59:35571 // There was an error while reading from the socket.
572 QUIC_PACKET_READ_ERROR = 51,
[email protected]24e5bc52013-09-18 15:36:58573 // We received a STREAM_FRAME with no data and no fin flag set.
jokulikf2bd55c52016-03-24 22:35:30574 QUIC_EMPTY_STREAM_FRAME_NO_FIN = 50,
[email protected]4d640792013-12-18 22:21:08575 // We received invalid data on the headers stream.
576 QUIC_INVALID_HEADERS_STREAM_DATA = 56,
[email protected]730b35d72014-06-05 03:23:22577 // The peer received too much data, violating flow control.
578 QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA = 59,
579 // The peer sent too much data, violating flow control.
580 QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA = 63,
581 // The peer received an invalid flow control window.
582 QUIC_FLOW_CONTROL_INVALID_WINDOW = 64,
[email protected]71c84e592014-05-28 23:39:29583 // The connection has been IP pooled into an existing connection.
584 QUIC_CONNECTION_IP_POOLED = 62,
rtenneti23186682014-10-30 01:49:33585 // The connection has too many outstanding sent packets.
586 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS = 68,
587 // The connection has too many outstanding received packets.
588 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS = 69,
fayanga64c1a92016-02-13 01:55:58589 // The quic connection has been cancelled.
rtenneti14abd312015-02-06 21:56:01590 QUIC_CONNECTION_CANCELLED = 70,
rtenneti85dcfac22015-03-27 20:22:19591 // Disabled QUIC because of high packet loss rate.
592 QUIC_BAD_PACKET_LOSS_RATE = 71,
ckrasic1e53b642015-07-08 22:39:35593 // Disabled QUIC because of too many PUBLIC_RESETs post handshake.
594 QUIC_PUBLIC_RESETS_POST_HANDSHAKE = 73,
595 // Disabled QUIC because of too many timeouts with streams open.
596 QUIC_TIMEOUTS_WITH_OPEN_STREAMS = 74,
rtenneti8811fdb2015-07-22 00:17:07597 // Closed because we failed to serialize a packet.
598 QUIC_FAILED_TO_SERIALIZE_PACKET = 75,
zhongyi2341cda2016-03-10 04:09:34599 // QUIC timed out after too many RTOs.
600 QUIC_TOO_MANY_RTOS = 85,
[email protected]8b37a092012-10-18 21:53:49601
602 // Crypto errors.
603
[email protected]1354bf62013-05-23 23:17:18604 // Hanshake failed.
[email protected]89264042013-08-21 07:35:24605 QUIC_HANDSHAKE_FAILED = 28,
[email protected]8b37a092012-10-18 21:53:49606 // Handshake message contained out of order tags.
[email protected]89264042013-08-21 07:35:24607 QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29,
[email protected]701bc892013-01-17 04:51:54608 // Handshake message contained too many entries.
[email protected]89264042013-08-21 07:35:24609 QUIC_CRYPTO_TOO_MANY_ENTRIES = 30,
[email protected]8b37a092012-10-18 21:53:49610 // Handshake message contained an invalid value length.
[email protected]89264042013-08-21 07:35:24611 QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31,
[email protected]8b37a092012-10-18 21:53:49612 // A crypto message was received after the handshake was complete.
[email protected]89264042013-08-21 07:35:24613 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32,
[email protected]d3d15bf2013-01-30 02:51:54614 // A crypto message was received with an illegal message tag.
[email protected]89264042013-08-21 07:35:24615 QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33,
[email protected]d3d15bf2013-01-30 02:51:54616 // A crypto message was received with an illegal parameter.
[email protected]89264042013-08-21 07:35:24617 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34,
[email protected]752fbe52013-10-14 08:35:32618 // An invalid channel id signature was supplied.
619 QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52,
[email protected]d3d15bf2013-01-30 02:51:54620 // A crypto message was received with a mandatory parameter missing.
[email protected]89264042013-08-21 07:35:24621 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35,
[email protected]d3d15bf2013-01-30 02:51:54622 // A crypto message was received with a parameter that has no overlap
623 // with the local parameter.
[email protected]89264042013-08-21 07:35:24624 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36,
[email protected]ed3fc15d2013-03-08 18:37:44625 // A crypto message was received that contained a parameter with too few
626 // values.
[email protected]89264042013-08-21 07:35:24627 QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37,
[email protected]ccc66e8a2013-03-26 08:26:14628 // An internal error occured in crypto processing.
[email protected]89264042013-08-21 07:35:24629 QUIC_CRYPTO_INTERNAL_ERROR = 38,
[email protected]ccc66e8a2013-03-26 08:26:14630 // A crypto handshake message specified an unsupported version.
[email protected]89264042013-08-21 07:35:24631 QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39,
rtennetie0ee6eb2015-05-01 00:55:09632 // A crypto handshake message resulted in a stateless reject.
633 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT = 72,
[email protected]ccc66e8a2013-03-26 08:26:14634 // There was no intersection between the crypto primitives supported by the
635 // peer and ourselves.
[email protected]89264042013-08-21 07:35:24636 QUIC_CRYPTO_NO_SUPPORT = 40,
[email protected]ef95114d2013-04-17 17:57:01637 // The server rejected our client hello messages too many times.
[email protected]89264042013-08-21 07:35:24638 QUIC_CRYPTO_TOO_MANY_REJECTS = 41,
[email protected]a57e0272013-04-26 07:31:47639 // The client rejected the server's certificate chain or signature.
[email protected]89264042013-08-21 07:35:24640 QUIC_PROOF_INVALID = 42,
[email protected]8ba81212013-05-03 13:11:48641 // A crypto message was received with a duplicate tag.
[email protected]89264042013-08-21 07:35:24642 QUIC_CRYPTO_DUPLICATE_TAG = 43,
[email protected]2532de12013-05-09 12:29:33643 // A crypto message was received with the wrong encryption level (i.e. it
644 // should have been encrypted but was not.)
[email protected]89264042013-08-21 07:35:24645 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44,
[email protected]2532de12013-05-09 12:29:33646 // The server config for a server has expired.
[email protected]89264042013-08-21 07:35:24647 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45,
[email protected]752fbe52013-10-14 08:35:32648 // We failed to setup the symmetric keys for a connection.
649 QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53,
[email protected]691f45a982013-11-19 10:52:04650 // A handshake message arrived, but we are still validating the
651 // previous handshake message.
652 QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54,
[email protected]ccb34212014-07-18 09:27:50653 // A server config update arrived before the handshake is complete.
654 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE = 65,
[email protected]d89f1862013-11-26 21:21:27655 // This connection involved a version negotiation which appears to have been
656 // tampered with.
657 QUIC_VERSION_NEGOTIATION_MISMATCH = 55,
[email protected]ccc66e8a2013-03-26 08:26:14658
rchcaec4242016-01-22 20:49:52659 // Multipath is not enabled, but a packet with multipath flag on is received.
660 QUIC_BAD_MULTIPATH_FLAG = 79,
661
jri7e636642016-01-14 06:57:08662 // IP address changed causing connection close.
rchcaec4242016-01-22 20:49:52663 QUIC_IP_ADDRESS_CHANGED = 80,
jri7e636642016-01-14 06:57:08664
665 // Connection migration errors.
666 // Network changed, but connection had no migratable streams.
rchcaec4242016-01-22 20:49:52667 QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS = 81,
jri7e636642016-01-14 06:57:08668 // Connection changed networks too many times.
rchcaec4242016-01-22 20:49:52669 QUIC_CONNECTION_MIGRATION_TOO_MANY_CHANGES = 82,
jri7e636642016-01-14 06:57:08670 // Connection migration was attempted, but there was no new network to
671 // migrate to.
rchcaec4242016-01-22 20:49:52672 QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK = 83,
jri231c2972016-03-08 19:50:11673 // Network changed, but connection had one or more non-migratable streams.
674 QUIC_CONNECTION_MIGRATION_NON_MIGRATABLE_STREAM = 84,
jri7e636642016-01-14 06:57:08675
[email protected]74bda142013-03-31 02:49:11676 // No error. Used as bound while iterating.
jri78ec06a2016-03-31 18:19:40677 QUIC_LAST_ERROR = 89,
[email protected]8b37a092012-10-18 21:53:49678};
679
zhongyi291d0302015-12-14 07:06:25680// Must be updated any time a QuicErrorCode is deprecated.
681const int kDeprecatedQuicErrorCount = 4;
682const int kActiveQuicErrorCount = QUIC_LAST_ERROR - kDeprecatedQuicErrorCount;
683
[email protected]c995c572013-01-18 05:43:20684struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
[email protected]14e8106c2013-03-14 16:25:33685 QuicPacketPublicHeader();
686 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
687 ~QuicPacketPublicHeader();
688
[email protected]3aa9ca72014-02-27 19:39:43689 // Universal header. All QuicPacket headers will have a connection_id and
690 // public flags.
691 QuicConnectionId connection_id;
692 QuicConnectionIdLength connection_id_length;
zhongyib8677022015-12-01 05:51:30693 bool multipath_flag;
[email protected]9db443912013-02-25 05:27:03694 bool reset_flag;
695 bool version_flag;
rtennetia004d332015-08-28 06:44:57696 QuicPacketNumberLength packet_number_length;
[email protected]48878092013-07-26 14:51:56697 QuicVersionVector versions;
[email protected]c995c572013-01-18 05:43:20698};
699
rtennetia004d332015-08-28 06:44:57700// An integer which cannot be a packet number.
701const QuicPacketNumber kInvalidPacketNumber = 0;
rtenneti9e0fb502015-03-08 06:07:16702
rjshaded069aaee2016-03-11 20:42:17703// Header for Data packets.
[email protected]74bda142013-03-31 02:49:11704struct NET_EXPORT_PRIVATE QuicPacketHeader {
705 QuicPacketHeader();
706 explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
vmpstracd23b72016-02-26 21:08:55707 QuicPacketHeader(const QuicPacketHeader& other);
[email protected]9db443912013-02-25 05:27:03708
rjshaded5ced072015-12-18 19:26:02709 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
710 const QuicPacketHeader& s);
[email protected]9db443912013-02-25 05:27:03711
[email protected]c995c572013-01-18 05:43:20712 QuicPacketPublicHeader public_header;
rtenneti8dd12b22015-10-21 01:26:38713 QuicPacketNumber packet_number;
fayanga64c1a92016-02-13 01:55:58714 QuicPathId path_id;
[email protected]9db443912013-02-25 05:27:03715 bool entropy_flag;
716 QuicPacketEntropyHash entropy_hash;
fayanga64c1a92016-02-13 01:55:58717 bool fec_flag;
[email protected]b064310782013-05-30 21:12:17718 InFecGroup is_in_fec_group;
[email protected]8b37a092012-10-18 21:53:49719 QuicFecGroupNumber fec_group;
720};
721
[email protected]74bda142013-03-31 02:49:11722struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
[email protected]6ae6e342014-02-06 02:21:42723 QuicPublicResetPacket();
724 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header);
725
[email protected]86a318d2013-01-23 21:16:04726 QuicPacketPublicHeader public_header;
[email protected]86a318d2013-01-23 21:16:04727 QuicPublicResetNonceProof nonce_proof;
rtennetia004d332015-08-28 06:44:57728 QuicPacketNumber rejected_packet_number;
[email protected]79d13dcb2014-02-05 07:23:13729 IPEndPoint client_address;
[email protected]86a318d2013-01-23 21:16:04730};
731
[email protected]14e8106c2013-03-14 16:25:33732enum QuicVersionNegotiationState {
733 START_NEGOTIATION = 0,
[email protected]ec640112013-08-09 03:56:18734 // Server-side this implies we've sent a version negotiation packet and are
735 // waiting on the client to select a compatible version. Client-side this
736 // implies we've gotten a version negotiation packet, are retransmitting the
737 // initial packets with a supported version and are waiting for our first
738 // packet from the server.
739 NEGOTIATION_IN_PROGRESS,
740 // This indicates this endpoint has received a packet from the peer with a
741 // version this endpoint supports. Version negotiation is complete, and the
742 // version number will no longer be sent with future packets.
[email protected]14e8106c2013-03-14 16:25:33743 NEGOTIATED_VERSION
744};
745
746typedef QuicPacketPublicHeader QuicVersionNegotiationPacket;
747
[email protected]c995c572013-01-18 05:43:20748// A padding frame contains no payload.
rtenneti5ca6eee2015-10-15 21:54:30749struct NET_EXPORT_PRIVATE QuicPaddingFrame {};
[email protected]c995c572013-01-18 05:43:20750
[email protected]d8c522112014-04-23 09:23:25751// A ping frame contains no payload, though it is retransmittable,
752// and ACK'd just like other normal frames.
rtenneti5ca6eee2015-10-15 21:54:30753struct NET_EXPORT_PRIVATE QuicPingFrame {};
[email protected]d8c522112014-04-23 09:23:25754
rtenneti69e64aa2015-06-26 04:25:30755// A path MTU discovery frame contains no payload and is serialized as a ping
756// frame.
757struct NET_EXPORT_PRIVATE QuicMtuDiscoveryFrame {};
758
jdorfman5a606722016-01-04 17:41:29759class NET_EXPORT_PRIVATE QuicBufferAllocator {
760 public:
761 virtual ~QuicBufferAllocator();
762
763 // Returns or allocates a new buffer of |size|. Never returns null.
764 virtual char* New(size_t size) = 0;
765
rcha00232242016-01-22 21:07:51766 // Returns or allocates a new buffer of |size| if |flag_enable| is true.
767 // Otherwise, returns a buffer that is compatible with this class directly
768 // with operator new. Never returns null.
769 virtual char* New(size_t size, bool flag_enable) = 0;
770
jdorfman5a606722016-01-04 17:41:29771 // Releases a buffer.
772 virtual void Delete(char* buffer) = 0;
rcha00232242016-01-22 21:07:51773
774 // Marks the allocator as being idle. Serves as a hint to notify the allocator
775 // that it should release any resources it's still holding on to.
776 virtual void MarkAllocatorIdle() {}
jdorfman5a606722016-01-04 17:41:29777};
778
779// Deleter for stream buffers. Copyable to support platforms where the deleter
780// of a unique_ptr must be copyable. Otherwise it would be nice for this to be
781// move-only.
zhongyi2f5f40c2015-12-08 02:13:02782class NET_EXPORT_PRIVATE StreamBufferDeleter {
783 public:
jdorfman5a606722016-01-04 17:41:29784 StreamBufferDeleter() : allocator_(nullptr) {}
785 explicit StreamBufferDeleter(QuicBufferAllocator* allocator)
786 : allocator_(allocator) {}
787
788 // Deletes |buffer| using |allocator_|.
789 void operator()(char* buffer) const;
790
791 private:
792 // Not owned; must be valid so long as the buffer stored in the unique_ptr
793 // that owns |this| is valid.
794 QuicBufferAllocator* allocator_;
zhongyi2f5f40c2015-12-08 02:13:02795};
796
797using UniqueStreamBuffer = std::unique_ptr<char[], StreamBufferDeleter>;
rtennetif60c32d82015-10-14 00:07:00798
jdorfman5a606722016-01-04 17:41:29799// Allocates memory of size |size| using |allocator| for a QUIC stream buffer.
800NET_EXPORT_PRIVATE UniqueStreamBuffer
801NewStreamBuffer(QuicBufferAllocator* allocator, size_t size);
rtennetif60c32d82015-10-14 00:07:00802
[email protected]be24ab22012-10-22 03:01:52803struct NET_EXPORT_PRIVATE QuicStreamFrame {
804 QuicStreamFrame();
[email protected]be24ab22012-10-22 03:01:52805 QuicStreamFrame(QuicStreamId stream_id,
[email protected]a5061242012-10-23 23:29:37806 bool fin,
[email protected]701bc892013-01-17 04:51:54807 QuicStreamOffset offset,
rtennetia4228ea2015-06-04 02:31:44808 base::StringPiece data);
zhongyi36727b82015-12-03 00:42:23809 QuicStreamFrame(QuicStreamId stream_id,
810 bool fin,
811 QuicStreamOffset offset,
jokulik2324d282015-12-08 21:42:57812 QuicPacketLength frame_length,
zhongyi36727b82015-12-03 00:42:23813 UniqueStreamBuffer buffer);
814 ~QuicStreamFrame();
[email protected]5dafdb62013-11-14 01:24:26815
rjshaded5ced072015-12-18 19:26:02816 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
817 const QuicStreamFrame& s);
[email protected]c5e1aca2014-01-30 04:03:04818
[email protected]8b37a092012-10-18 21:53:49819 QuicStreamId stream_id;
820 bool fin;
jokulik2324d282015-12-08 21:42:57821 QuicPacketLength frame_length;
822 const char* frame_buffer;
[email protected]701bc892013-01-17 04:51:54823 QuicStreamOffset offset; // Location of this data in the stream.
zhongyi36727b82015-12-03 00:42:23824 // nullptr when the QuicStreamFrame is received, and non-null when sent.
825 UniqueStreamBuffer buffer;
zhongyi4249f9b02015-12-02 20:26:30826
zhongyi36727b82015-12-03 00:42:23827 private:
jokulik2324d282015-12-08 21:42:57828 QuicStreamFrame(QuicStreamId stream_id,
829 bool fin,
830 QuicStreamOffset offset,
831 const char* frame_buffer,
832 QuicPacketLength frame_length,
833 UniqueStreamBuffer buffer);
834
zhongyi36727b82015-12-03 00:42:23835 DISALLOW_COPY_AND_ASSIGN(QuicStreamFrame);
836};
837static_assert(sizeof(QuicStreamFrame) <= 64,
838 "Keep the QuicStreamFrame size to a cacheline.");
[email protected]e537f742012-12-07 15:33:53839// TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
840// is finalized.
rtennetia004d332015-08-28 06:44:57841typedef std::set<QuicPacketNumber> PacketNumberSet;
842typedef std::list<QuicPacketNumber> PacketNumberList;
rtenneti4b06ae72014-08-26 03:43:43843
ckrasicea295fe2015-10-31 05:03:27844typedef std::vector<std::pair<QuicPacketNumber, QuicTime>> PacketTimeVector;
[email protected]044ac2b2012-11-13 21:41:06845
[email protected]310d37b2014-08-02 06:15:37846struct NET_EXPORT_PRIVATE QuicStopWaitingFrame {
847 QuicStopWaitingFrame();
848 ~QuicStopWaitingFrame();
[email protected]6ae6e342014-02-06 02:21:42849
[email protected]26f3f8e2012-12-13 21:07:19850 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:02851 std::ostream& os,
852 const QuicStopWaitingFrame& s);
jri3285d93a2015-12-14 08:53:19853 // Path which this stop waiting frame belongs to.
854 QuicPathId path_id;
[email protected]310d37b2014-08-02 06:15:37855 // Entropy hash of all packets up to, but not including, the least unacked
856 // packet.
857 QuicPacketEntropyHash entropy_hash;
858 // The lowest packet we've sent which is unacked, and we expect an ack for.
rtennetia004d332015-08-28 06:44:57859 QuicPacketNumber least_unacked;
[email protected]310d37b2014-08-02 06:15:37860};
861
rtenneti493d90ef2015-09-14 04:43:11862// A sequence of packet numbers where each number is unique. Intended to be used
863// in a sliding window fashion, where smaller old packet numbers are removed and
864// larger new packet numbers are added, with the occasional random access.
865class NET_EXPORT_PRIVATE PacketNumberQueue {
866 public:
rtenneti55a807c2016-02-05 03:05:54867 // TODO(jdorfman): remove const_iterator and change the callers to iterate
868 // over the intervals.
rtenneti4efd55dd2015-09-18 01:12:04869 class NET_EXPORT_PRIVATE const_iterator
870 : public std::iterator<std::input_iterator_tag,
871 QuicPacketNumber,
872 std::ptrdiff_t,
873 const QuicPacketNumber*,
874 const QuicPacketNumber&> {
875 public:
876 explicit const_iterator(PacketNumberSet::const_iterator set_iter);
877 const_iterator(
878 IntervalSet<QuicPacketNumber>::const_iterator interval_set_iter,
879 QuicPacketNumber first,
880 QuicPacketNumber last);
881 const_iterator(const const_iterator& other);
882 const_iterator& operator=(const const_iterator& other);
883 // TODO(rtenneti): on windows RValue reference gives errors.
884 // const_iterator(const_iterator&& other);
885 ~const_iterator();
886
887 // TODO(rtenneti): on windows RValue reference gives errors.
888 // const_iterator& operator=(const_iterator&& other);
889 bool operator!=(const const_iterator& other) const;
890 bool operator==(const const_iterator& other) const;
891 value_type operator*() const;
892 const_iterator& operator++();
893 const_iterator operator++(int /* postincrement */);
894
895 private:
rtenneti4efd55dd2015-09-18 01:12:04896 IntervalSet<QuicPacketNumber>::const_iterator interval_set_iter_;
897 QuicPacketNumber current_;
898 QuicPacketNumber last_;
899 };
900
rtenneti493d90ef2015-09-14 04:43:11901 PacketNumberQueue();
rtenneti4efd55dd2015-09-18 01:12:04902 PacketNumberQueue(const PacketNumberQueue& other);
rtenneti4efd55dd2015-09-18 01:12:04903 // TODO(rtenneti): on windows RValue reference gives errors.
904 // PacketNumberQueue(PacketNumberQueue&& other);
rtenneti93209a02015-09-19 01:51:18905 ~PacketNumberQueue();
906
907 PacketNumberQueue& operator=(const PacketNumberQueue& other);
rtenneti4efd55dd2015-09-18 01:12:04908 // PacketNumberQueue& operator=(PacketNumberQueue&& other);
rtenneti493d90ef2015-09-14 04:43:11909
910 // Adds |packet_number| to the set of packets in the queue.
911 void Add(QuicPacketNumber packet_number);
912
rtenneti4efd55dd2015-09-18 01:12:04913 // Adds packets between [lower, higher) to the set of packets in the queue. It
914 // is undefined behavior to call this with |higher| < |lower|.
rtenneti493d90ef2015-09-14 04:43:11915 void Add(QuicPacketNumber lower, QuicPacketNumber higher);
916
917 // Removes |packet_number| from the set of packets in the queue.
918 void Remove(QuicPacketNumber packet_number);
919
920 // Removes packets with values less than |higher| from the set of packets in
921 // the queue. Returns true if packets were removed.
922 bool RemoveUpTo(QuicPacketNumber higher);
923
924 // Returns true if the queue contains |packet_number|.
925 bool Contains(QuicPacketNumber packet_number) const;
926
927 // Returns true if the queue is empty.
928 bool Empty() const;
929
930 // Returns the minimum packet number stored in the queue. It is undefined
931 // behavior to call this if the queue is empty.
932 QuicPacketNumber Min() const;
933
934 // Returns the maximum packet number stored in the queue. It is undefined
935 // behavior to call this if the queue is empty.
936 QuicPacketNumber Max() const;
937
rtenneti4efd55dd2015-09-18 01:12:04938 // Returns the number of unique packets stored in the queue. Inefficient; only
939 // exposed for testing.
940 size_t NumPacketsSlow() const;
rtenneti493d90ef2015-09-14 04:43:11941
rtenneti4efd55dd2015-09-18 01:12:04942 // Returns iterators over the individual packet numbers.
943 const_iterator begin() const;
944 const_iterator end() const;
rtenneti493d90ef2015-09-14 04:43:11945 const_iterator lower_bound(QuicPacketNumber packet_number) const;
rtenneti493d90ef2015-09-14 04:43:11946
947 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
948 std::ostream& os,
949 const PacketNumberQueue& q);
950
951 private:
rtenneti4efd55dd2015-09-18 01:12:04952 IntervalSet<QuicPacketNumber> packet_number_intervals_;
rtenneti493d90ef2015-09-14 04:43:11953};
954
[email protected]310d37b2014-08-02 06:15:37955struct NET_EXPORT_PRIVATE QuicAckFrame {
956 QuicAckFrame();
vmpstracd23b72016-02-26 21:08:55957 QuicAckFrame(const QuicAckFrame& other);
[email protected]310d37b2014-08-02 06:15:37958 ~QuicAckFrame();
959
rjshaded5ced072015-12-18 19:26:02960 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
961 const QuicAckFrame& s);
[email protected]a674b4c2012-12-05 03:44:30962
jri3285d93a2015-12-14 08:53:19963 // Path which this ack belongs to.
964 QuicPathId path_id;
965
[email protected]9db443912013-02-25 05:27:03966 // Entropy hash of all packets up to largest observed not including missing
967 // packets.
968 QuicPacketEntropyHash entropy_hash;
[email protected]e537f742012-12-07 15:33:53969
ckrasicea295fe2015-10-31 05:03:27970 // Whether the ack had to be truncated when sent.
971 bool is_truncated;
972
rtennetia004d332015-08-28 06:44:57973 // The highest packet number we've observed from the peer.
[email protected]48697d8a2013-01-15 19:42:24974 //
975 // In general, this should be the largest packet number we've received. In
976 // the case of truncated acks, we may have to advertise a lower "upper bound"
977 // than largest received, to avoid implicitly acking missing packets that
978 // don't fit in the missing packet list due to size limitations. In this
979 // case, largest_observed may be a packet which is also in the missing packets
980 // list.
rtennetia004d332015-08-28 06:44:57981 QuicPacketNumber largest_observed;
[email protected]a674b4c2012-12-05 03:44:30982
[email protected]14e8106c2013-03-14 16:25:33983 // Time elapsed since largest_observed was received until this Ack frame was
984 // sent.
rchcaec4242016-01-22 20:49:52985 QuicTime::Delta ack_delay_time;
[email protected]14e8106c2013-03-14 16:25:33986
ckrasicea295fe2015-10-31 05:03:27987 // Vector of <packet_number, time> for when packets arrived.
988 PacketTimeVector received_packet_times;
989
[email protected]e537f742012-12-07 15:33:53990 // The set of packets which we're expecting and have not received.
rtenneti493d90ef2015-09-14 04:43:11991 PacketNumberQueue missing_packets;
[email protected]8b37a092012-10-18 21:53:49992};
993
rtennetia004d332015-08-28 06:44:57994// True if the packet number is greater than largest_observed or is listed
[email protected]9db443912013-02-25 05:27:03995// as missing.
rtennetia004d332015-08-28 06:44:57996// Always returns false for packet numbers less than least_unacked.
997bool NET_EXPORT_PRIVATE IsAwaitingPacket(const QuicAckFrame& ack_frame,
998 QuicPacketNumber packet_number);
[email protected]9db443912013-02-25 05:27:03999
[email protected]a692ad9d2014-07-18 21:35:241000// Defines for all types of congestion control algorithms that can be used in
1001// QUIC. Note that this is separate from the congestion feedback type -
1002// some congestion control algorithms may use the same feedback type
1003// (Reno and Cubic are the classic example for that).
1004enum CongestionControlType {
1005 kCubic,
rtennetifb3fa6c2015-03-16 23:04:551006 kCubicBytes,
[email protected]a692ad9d2014-07-18 21:35:241007 kReno,
rtennetifb3fa6c2015-03-16 23:04:551008 kRenoBytes,
[email protected]a692ad9d2014-07-18 21:35:241009 kBBR,
[email protected]8b37a092012-10-18 21:53:491010};
1011
[email protected]c5cc9bd2014-03-31 23:17:141012enum LossDetectionType {
1013 kNack, // Used to mimic TCP's loss detection.
1014 kTime, // Time based loss detection.
1015};
1016
[email protected]be24ab22012-10-22 03:01:521017struct NET_EXPORT_PRIVATE QuicRstStreamFrame {
[email protected]6ae6e342014-02-06 02:21:421018 QuicRstStreamFrame();
1019 QuicRstStreamFrame(QuicStreamId stream_id,
1020 QuicRstStreamErrorCode error_code,
1021 QuicStreamOffset bytes_written);
[email protected]8b37a092012-10-18 21:53:491022
[email protected]c5e1aca2014-01-30 04:03:041023 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:021024 std::ostream& os,
1025 const QuicRstStreamFrame& r);
[email protected]c5e1aca2014-01-30 04:03:041026
[email protected]8b37a092012-10-18 21:53:491027 QuicStreamId stream_id;
[email protected]74bda142013-03-31 02:49:111028 QuicRstStreamErrorCode error_code;
[email protected]6ae6e342014-02-06 02:21:421029
1030 // Used to update flow control windows. On termination of a stream, both
1031 // endpoints must inform the peer of the number of bytes they have sent on
1032 // that stream. This can be done through normal termination (data packet with
1033 // FIN) or through a RST.
1034 QuicStreamOffset byte_offset;
[email protected]8b37a092012-10-18 21:53:491035};
1036
[email protected]be24ab22012-10-22 03:01:521037struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame {
[email protected]6ae6e342014-02-06 02:21:421038 QuicConnectionCloseFrame();
1039
[email protected]c5e1aca2014-01-30 04:03:041040 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:021041 std::ostream& os,
1042 const QuicConnectionCloseFrame& c);
[email protected]c5e1aca2014-01-30 04:03:041043
[email protected]431bb4fd2012-10-19 17:46:091044 QuicErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:091045 std::string error_details;
[email protected]8b37a092012-10-18 21:53:491046};
1047
[email protected]9db443912013-02-25 05:27:031048struct NET_EXPORT_PRIVATE QuicGoAwayFrame {
[email protected]6ae6e342014-02-06 02:21:421049 QuicGoAwayFrame();
[email protected]9db443912013-02-25 05:27:031050 QuicGoAwayFrame(QuicErrorCode error_code,
1051 QuicStreamId last_good_stream_id,
1052 const std::string& reason);
1053
rjshaded5ced072015-12-18 19:26:021054 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
1055 const QuicGoAwayFrame& g);
[email protected]c5e1aca2014-01-30 04:03:041056
[email protected]9db443912013-02-25 05:27:031057 QuicErrorCode error_code;
1058 QuicStreamId last_good_stream_id;
1059 std::string reason_phrase;
1060};
1061
[email protected]6ae6e342014-02-06 02:21:421062// Flow control updates per-stream and at the connection levoel.
1063// Based on SPDY's WINDOW_UPDATE frame, but uses an absolute byte offset rather
1064// than a window delta.
1065// TODO(rjshade): A possible future optimization is to make stream_id and
1066// byte_offset variable length, similar to stream frames.
1067struct NET_EXPORT_PRIVATE QuicWindowUpdateFrame {
1068 QuicWindowUpdateFrame() {}
1069 QuicWindowUpdateFrame(QuicStreamId stream_id, QuicStreamOffset byte_offset);
1070
1071 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:021072 std::ostream& os,
1073 const QuicWindowUpdateFrame& w);
[email protected]6ae6e342014-02-06 02:21:421074
1075 // The stream this frame applies to. 0 is a special case meaning the overall
1076 // connection rather than a specific stream.
1077 QuicStreamId stream_id;
1078
1079 // Byte offset in the stream or connection. The receiver of this frame must
1080 // not send data which would result in this offset being exceeded.
1081 QuicStreamOffset byte_offset;
1082};
1083
1084// The BLOCKED frame is used to indicate to the remote endpoint that this
1085// endpoint believes itself to be flow-control blocked but otherwise ready to
1086// send data. The BLOCKED frame is purely advisory and optional.
1087// Based on SPDY's BLOCKED frame (undocumented as of 2014-01-28).
1088struct NET_EXPORT_PRIVATE QuicBlockedFrame {
1089 QuicBlockedFrame() {}
1090 explicit QuicBlockedFrame(QuicStreamId stream_id);
1091
rjshaded5ced072015-12-18 19:26:021092 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
1093 const QuicBlockedFrame& b);
[email protected]6ae6e342014-02-06 02:21:421094
1095 // The stream this frame applies to. 0 is a special case meaning the overall
1096 // connection rather than a specific stream.
1097 QuicStreamId stream_id;
1098};
1099
rchcaec4242016-01-22 20:49:521100// The PATH_CLOSE frame is used to explicitly close a path. Both endpoints can
1101// send a PATH_CLOSE frame to initiate a path termination. A path is considered
1102// to be closed either a PATH_CLOSE frame is sent or received. An endpoint drops
1103// receive side of a closed path, and packets with retransmittable frames on a
1104// closed path are marked as retransmissions which will be transmitted on other
1105// paths.
1106struct NET_EXPORT_PRIVATE QuicPathCloseFrame {
1107 QuicPathCloseFrame() {}
1108 explicit QuicPathCloseFrame(QuicPathId path_id);
1109
1110 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
1111 std::ostream& os,
1112 const QuicPathCloseFrame& p);
1113
1114 QuicPathId path_id;
1115};
1116
[email protected]8ba81212013-05-03 13:11:481117// EncryptionLevel enumerates the stages of encryption that a QUIC connection
1118// progresses through. When retransmitting a packet, the encryption level needs
1119// to be specified so that it is retransmitted at a level which the peer can
1120// understand.
fayanga64c1a92016-02-13 01:55:581121enum EncryptionLevel : int8_t {
[email protected]8ba81212013-05-03 13:11:481122 ENCRYPTION_NONE = 0,
1123 ENCRYPTION_INITIAL = 1,
1124 ENCRYPTION_FORWARD_SECURE = 2,
1125
1126 NUM_ENCRYPTION_LEVELS,
1127};
1128
rch99b644c2015-11-04 05:25:281129enum PeerAddressChangeType {
jric533399b2016-01-29 07:36:011130 // IP address and port remain unchanged.
rch99b644c2015-11-04 05:25:281131 NO_CHANGE,
jric533399b2016-01-29 07:36:011132 // Port changed, but IP address remains unchanged.
1133 PORT_CHANGE,
1134 // IPv4 address changed, but within the /24 subnet (port may have changed.)
1135 IPV4_SUBNET_CHANGE,
1136 // IP address change from an IPv4 to an IPv6 address (port may have changed.)
1137 IPV4_TO_IPV6_CHANGE,
1138 // IP address change from an IPv6 to an IPv4 address (port may have changed.)
1139 IPV6_TO_IPV4_CHANGE,
1140 // IP address change from an IPv6 to an IPv6 address (port may have changed.)
1141 IPV6_TO_IPV6_CHANGE,
1142 // All other peer address changes.
1143 UNSPECIFIED_CHANGE,
rch99b644c2015-11-04 05:25:281144};
1145
[email protected]be24ab22012-10-22 03:01:521146struct NET_EXPORT_PRIVATE QuicFrame {
[email protected]6ae6e342014-02-06 02:21:421147 QuicFrame();
rtenneti5ca6eee2015-10-15 21:54:301148 explicit QuicFrame(QuicPaddingFrame padding_frame);
1149 explicit QuicFrame(QuicMtuDiscoveryFrame frame);
1150 explicit QuicFrame(QuicPingFrame frame);
1151
[email protected]6ae6e342014-02-06 02:21:421152 explicit QuicFrame(QuicStreamFrame* stream_frame);
1153 explicit QuicFrame(QuicAckFrame* frame);
[email protected]6ae6e342014-02-06 02:21:421154 explicit QuicFrame(QuicRstStreamFrame* frame);
1155 explicit QuicFrame(QuicConnectionCloseFrame* frame);
[email protected]93dd91f2014-02-27 00:09:031156 explicit QuicFrame(QuicStopWaitingFrame* frame);
[email protected]6ae6e342014-02-06 02:21:421157 explicit QuicFrame(QuicGoAwayFrame* frame);
1158 explicit QuicFrame(QuicWindowUpdateFrame* frame);
1159 explicit QuicFrame(QuicBlockedFrame* frame);
rchcaec4242016-01-22 20:49:521160 explicit QuicFrame(QuicPathCloseFrame* frame);
[email protected]8b37a092012-10-18 21:53:491161
rjshaded5ced072015-12-18 19:26:021162 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
1163 const QuicFrame& frame);
[email protected]c5e1aca2014-01-30 04:03:041164
[email protected]be24ab22012-10-22 03:01:521165 QuicFrameType type;
[email protected]8b37a092012-10-18 21:53:491166 union {
rtenneti5ca6eee2015-10-15 21:54:301167 // Frames smaller than a pointer are inline.
1168 QuicPaddingFrame padding_frame;
1169 QuicMtuDiscoveryFrame mtu_discovery_frame;
1170 QuicPingFrame ping_frame;
1171
1172 // Frames larger than a pointer.
[email protected]be24ab22012-10-22 03:01:521173 QuicStreamFrame* stream_frame;
1174 QuicAckFrame* ack_frame;
[email protected]93dd91f2014-02-27 00:09:031175 QuicStopWaitingFrame* stop_waiting_frame;
[email protected]be24ab22012-10-22 03:01:521176 QuicRstStreamFrame* rst_stream_frame;
1177 QuicConnectionCloseFrame* connection_close_frame;
[email protected]9db443912013-02-25 05:27:031178 QuicGoAwayFrame* goaway_frame;
[email protected]6ae6e342014-02-06 02:21:421179 QuicWindowUpdateFrame* window_update_frame;
1180 QuicBlockedFrame* blocked_frame;
rchcaec4242016-01-22 20:49:521181 QuicPathCloseFrame* path_close_frame;
[email protected]8b37a092012-10-18 21:53:491182 };
1183};
rtenneti5ca6eee2015-10-15 21:54:301184// QuicFrameType consumes 8 bytes with padding.
1185static_assert(sizeof(QuicFrame) <= 16,
1186 "Frames larger than 8 bytes should be referenced by pointer.");
[email protected]8b37a092012-10-18 21:53:491187
[email protected]be24ab22012-10-22 03:01:521188typedef std::vector<QuicFrame> QuicFrames;
[email protected]8b37a092012-10-18 21:53:491189
[email protected]8b37a092012-10-18 21:53:491190class NET_EXPORT_PRIVATE QuicData {
1191 public:
[email protected]6ae6e342014-02-06 02:21:421192 QuicData(const char* buffer, size_t length);
1193 QuicData(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:491194 virtual ~QuicData();
1195
1196 base::StringPiece AsStringPiece() const {
1197 return base::StringPiece(data(), length());
1198 }
1199
1200 const char* data() const { return buffer_; }
1201 size_t length() const { return length_; }
rtennetie0ee6eb2015-05-01 00:55:091202 bool owns_buffer() const { return owns_buffer_; }
[email protected]8b37a092012-10-18 21:53:491203
1204 private:
1205 const char* buffer_;
1206 size_t length_;
1207 bool owns_buffer_;
1208
1209 DISALLOW_COPY_AND_ASSIGN(QuicData);
1210};
1211
1212class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
1213 public:
rchcaec4242016-01-22 20:49:521214 // TODO(fayang): 4 fields from public header are passed in as arguments.
1215 // Consider to add a convenience method which directly accepts the entire
1216 // public header.
rtennetica5ac272015-02-07 12:35:121217 QuicPacket(char* buffer,
1218 size_t length,
1219 bool owns_buffer,
1220 QuicConnectionIdLength connection_id_length,
1221 bool includes_version,
rchcaec4242016-01-22 20:49:521222 bool includes_path_id,
rtennetia004d332015-08-28 06:44:571223 QuicPacketNumberLength packet_number_length);
[email protected]8b37a092012-10-18 21:53:491224
[email protected]5351cc4b2013-03-03 07:22:411225 base::StringPiece AssociatedData() const;
[email protected]5351cc4b2013-03-03 07:22:411226 base::StringPiece Plaintext() const;
[email protected]082b65b2012-11-10 19:11:311227
[email protected]8b37a092012-10-18 21:53:491228 char* mutable_data() { return buffer_; }
1229
1230 private:
1231 char* buffer_;
[email protected]3aa9ca72014-02-27 19:39:431232 const QuicConnectionIdLength connection_id_length_;
[email protected]5351cc4b2013-03-03 07:22:411233 const bool includes_version_;
rchcaec4242016-01-22 20:49:521234 const bool includes_path_id_;
rtennetia004d332015-08-28 06:44:571235 const QuicPacketNumberLength packet_number_length_;
[email protected]8b37a092012-10-18 21:53:491236
[email protected]2e740db2012-10-20 19:35:191237 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
[email protected]8b37a092012-10-18 21:53:491238};
1239
1240class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
1241 public:
[email protected]6ae6e342014-02-06 02:21:421242 QuicEncryptedPacket(const char* buffer, size_t length);
1243 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:491244
[email protected]ec86d5462013-11-17 16:04:491245 // Clones the packet into a new packet which owns the buffer.
1246 QuicEncryptedPacket* Clone() const;
1247
[email protected]c1b32c62013-01-20 02:49:101248 // By default, gtest prints the raw bytes of an object. The bool data
1249 // member (in the base class QuicData) causes this object to have padding
1250 // bytes, which causes the default gtest object printer to read
1251 // uninitialize memory. So we need to teach gtest how to print this object.
1252 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:021253 std::ostream& os,
1254 const QuicEncryptedPacket& s);
[email protected]c1b32c62013-01-20 02:49:101255
[email protected]2e740db2012-10-20 19:35:191256 private:
1257 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
[email protected]8b37a092012-10-18 21:53:491258};
1259
jokulikf2bd55c52016-03-24 22:35:301260// A received encrypted QUIC packet, with a recorded time of receipt.
1261class NET_EXPORT_PRIVATE QuicReceivedPacket : public QuicEncryptedPacket {
1262 public:
1263 QuicReceivedPacket(const char* buffer, size_t length, QuicTime receipt_time);
1264 QuicReceivedPacket(char* buffer,
1265 size_t length,
1266 QuicTime receipt_time,
1267 bool owns_buffer);
1268
1269 // Clones the packet into a new packet which owns the buffer.
1270 QuicReceivedPacket* Clone() const;
1271
1272 // Returns the time at which the packet was received.
1273 QuicTime receipt_time() const { return receipt_time_; }
1274
1275 // By default, gtest prints the raw bytes of an object. The bool data
1276 // member (in the base class QuicData) causes this object to have padding
1277 // bytes, which causes the default gtest object printer to read
1278 // uninitialize memory. So we need to teach gtest how to print this object.
1279 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
1280 std::ostream& os,
1281 const QuicReceivedPacket& s);
1282
1283 private:
1284 const QuicTime receipt_time_;
1285
1286 DISALLOW_COPY_AND_ASSIGN(QuicReceivedPacket);
1287};
1288
jric533399b2016-01-29 07:36:011289// Pure virtual class to listen for packet acknowledgements.
1290class NET_EXPORT_PRIVATE QuicAckListenerInterface
1291 : public base::RefCounted<QuicAckListenerInterface> {
[email protected]9db443912013-02-25 05:27:031292 public:
jric533399b2016-01-29 07:36:011293 QuicAckListenerInterface() {}
[email protected]9db443912013-02-25 05:27:031294
jric533399b2016-01-29 07:36:011295 // Called when a packet is acked. Called once per packet.
1296 // |acked_bytes| is the number of data bytes acked.
1297 virtual void OnPacketAcked(int acked_bytes,
1298 QuicTime::Delta ack_delay_time) = 0;
rtenneti73e25c12015-03-16 06:12:431299
jric533399b2016-01-29 07:36:011300 // Called when a packet is retransmitted. Called once per packet.
1301 // |retransmitted_bytes| is the number of data bytes retransmitted.
1302 virtual void OnPacketRetransmitted(int retransmitted_bytes) = 0;
[email protected]9db443912013-02-25 05:27:031303
jric533399b2016-01-29 07:36:011304 protected:
1305 friend class base::RefCounted<QuicAckListenerInterface>;
[email protected]2115d33ba2014-01-02 21:53:521306
jric533399b2016-01-29 07:36:011307 // Delegates are ref counted.
1308 virtual ~QuicAckListenerInterface() {}
[email protected]9db443912013-02-25 05:27:031309};
1310
rtenneti8dd12b22015-10-21 01:26:381311struct NET_EXPORT_PRIVATE AckListenerWrapper {
1312 AckListenerWrapper(QuicAckListenerInterface* listener,
1313 QuicPacketLength data_length);
vmpstracd23b72016-02-26 21:08:551314 AckListenerWrapper(const AckListenerWrapper& other);
rtenneti8dd12b22015-10-21 01:26:381315 ~AckListenerWrapper();
1316
1317 scoped_refptr<QuicAckListenerInterface> ack_listener;
1318 QuicPacketLength length;
1319};
1320
[email protected]9db443912013-02-25 05:27:031321struct NET_EXPORT_PRIVATE SerializedPacket {
fayanga31a74b2015-12-28 17:27:141322 SerializedPacket(QuicPathId path_id,
1323 QuicPacketNumber packet_number,
rtennetia004d332015-08-28 06:44:571324 QuicPacketNumberLength packet_number_length,
rtenneti2cae2072016-02-05 02:21:331325 const char* encrypted_buffer,
1326 QuicPacketLength encrypted_length,
[email protected]9db443912013-02-25 05:27:031327 QuicPacketEntropyHash entropy_hash,
rtenneti9bd5d4b2015-08-21 05:44:521328 bool has_ack,
1329 bool has_stop_waiting);
vmpstracd23b72016-02-26 21:08:551330 SerializedPacket(const SerializedPacket& other);
[email protected]97cf3022013-09-05 14:30:161331 ~SerializedPacket();
[email protected]9db443912013-02-25 05:27:031332
rtenneti2cae2072016-02-05 02:21:331333 // Not owned.
1334 const char* encrypted_buffer;
1335 QuicPacketLength encrypted_length;
rtennetif85706db2016-02-04 02:43:031336 QuicFrames retransmittable_frames;
jric533399b2016-01-29 07:36:011337 IsHandshake has_crypto_handshake;
1338 bool needs_padding;
fayanga31a74b2015-12-28 17:27:141339 QuicPathId path_id;
rtennetia004d332015-08-28 06:44:571340 QuicPacketNumber packet_number;
1341 QuicPacketNumberLength packet_number_length;
jokulik2324d282015-12-08 21:42:571342 EncryptionLevel encryption_level;
[email protected]9db443912013-02-25 05:27:031343 QuicPacketEntropyHash entropy_hash;
rtenneti9bd5d4b2015-08-21 05:44:521344 bool has_ack;
1345 bool has_stop_waiting;
zhongyi4a9d27b2016-01-12 20:08:311346 QuicPacketNumber original_packet_number;
1347 TransmissionType transmission_type;
[email protected]97cf3022013-09-05 14:30:161348
rtenneti6b1c5b12015-01-13 20:08:351349 // Optional notifiers which will be informed when this packet has been ACKed.
rtenneti8dd12b22015-10-21 01:26:381350 std::list<AckListenerWrapper> listeners;
[email protected]9db443912013-02-25 05:27:031351};
1352
[email protected]77b5d50b2014-05-07 22:48:481353struct NET_EXPORT_PRIVATE TransmissionInfo {
1354 // Used by STL when assigning into a map.
1355 TransmissionInfo();
1356
rchcaec4242016-01-22 20:49:521357 // Constructs a Transmission with a new all_transmissions set
rtennetia004d332015-08-28 06:44:571358 // containing |packet_number|.
rchcaec4242016-01-22 20:49:521359 TransmissionInfo(EncryptionLevel level,
rtennetia004d332015-08-28 06:44:571360 QuicPacketNumberLength packet_number_length,
[email protected]730b35d72014-06-05 03:23:221361 TransmissionType transmission_type,
rtenneti3183ac42015-02-28 03:39:411362 QuicTime sent_time,
rtenneti5ca6eee2015-10-15 21:54:301363 QuicPacketLength bytes_sent,
rchcaec4242016-01-22 20:49:521364 bool has_crypto_handshake,
1365 bool needs_padding);
[email protected]77b5d50b2014-05-07 22:48:481366
vmpstracd23b72016-02-26 21:08:551367 TransmissionInfo(const TransmissionInfo& other);
1368
rtenneti8dd12b22015-10-21 01:26:381369 ~TransmissionInfo();
1370
rchcaec4242016-01-22 20:49:521371 QuicFrames retransmittable_frames;
jokulik2324d282015-12-08 21:42:571372 EncryptionLevel encryption_level;
rtennetia004d332015-08-28 06:44:571373 QuicPacketNumberLength packet_number_length;
rtenneti5ca6eee2015-10-15 21:54:301374 QuicPacketLength bytes_sent;
Avi Drissman13fc8932015-12-20 04:40:461375 uint16_t nack_count;
[email protected]77b5d50b2014-05-07 22:48:481376 QuicTime sent_time;
[email protected]730b35d72014-06-05 03:23:221377 // Reason why this packet was transmitted.
1378 TransmissionType transmission_type;
[email protected]aa7e4ef2014-05-28 03:53:151379 // In flight packets have not been abandoned or lost.
1380 bool in_flight;
rtenneti31e9fd62014-09-16 05:22:151381 // True if the packet can never be acked, so it can be removed.
1382 bool is_unackable;
rchcaec4242016-01-22 20:49:521383 // True if the packet contains stream data from the crypto stream.
1384 bool has_crypto_handshake;
1385 // True if the packet needs padding if it's retransmitted.
1386 bool needs_padding;
zhongyi1fb9bc52015-11-24 23:09:421387 // Stores the packet number of the next retransmission of this packet.
1388 // Zero if the packet has not been retransmitted.
1389 QuicPacketNumber retransmission;
rtenneti8dd12b22015-10-21 01:26:381390 // Non-empty if there is a listener for this packet.
1391 std::list<AckListenerWrapper> ack_listeners;
[email protected]77b5d50b2014-05-07 22:48:481392};
fayanga64c1a92016-02-13 01:55:581393static_assert(sizeof(TransmissionInfo) <= 128,
1394 "TODO(ianswett): Keep the TransmissionInfo size to a cacheline.");
[email protected]77b5d50b2014-05-07 22:48:481395
rchcaec4242016-01-22 20:49:521396// Struct to store the pending retransmission information.
1397struct PendingRetransmission {
1398 PendingRetransmission(QuicPathId path_id,
1399 QuicPacketNumber packet_number,
1400 TransmissionType transmission_type,
1401 const QuicFrames& retransmittable_frames,
1402 bool has_crypto_handshake,
1403 bool needs_padding,
1404 EncryptionLevel encryption_level,
1405 QuicPacketNumberLength packet_number_length)
fayanga64c1a92016-02-13 01:55:581406 : packet_number(packet_number),
rchcaec4242016-01-22 20:49:521407 retransmittable_frames(retransmittable_frames),
fayanga64c1a92016-02-13 01:55:581408 transmission_type(transmission_type),
1409 path_id(path_id),
rchcaec4242016-01-22 20:49:521410 has_crypto_handshake(has_crypto_handshake),
1411 needs_padding(needs_padding),
1412 encryption_level(encryption_level),
1413 packet_number_length(packet_number_length) {}
1414
rchcaec4242016-01-22 20:49:521415 QuicPacketNumber packet_number;
rchcaec4242016-01-22 20:49:521416 const QuicFrames& retransmittable_frames;
fayanga64c1a92016-02-13 01:55:581417 TransmissionType transmission_type;
1418 QuicPathId path_id;
rchcaec4242016-01-22 20:49:521419 bool has_crypto_handshake;
1420 bool needs_padding;
1421 EncryptionLevel encryption_level;
1422 QuicPacketNumberLength packet_number_length;
1423};
1424
rtennetic14c8ab2015-06-18 05:47:401425// Convenience wrapper to wrap an iovec array and the total length, which must
1426// be less than or equal to the actual total length of the iovecs.
1427struct NET_EXPORT_PRIVATE QuicIOVector {
1428 QuicIOVector(const struct iovec* iov, int iov_count, size_t total_length)
1429 : iov(iov), iov_count(iov_count), total_length(total_length) {}
1430
1431 const struct iovec* iov;
1432 const int iov_count;
1433 const size_t total_length;
1434};
1435
[email protected]8b37a092012-10-18 21:53:491436} // namespace net
1437
1438#endif // NET_QUIC_QUIC_PROTOCOL_H_