blob: 25fa411ecff8ab98d57010257bb07f5a2ba65d74 [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>
[email protected]5640d0a2012-10-22 18:17:0214#include <ostream>
[email protected]e537f742012-12-07 15:33:5315#include <set>
16#include <string>
[email protected]8b37a092012-10-18 21:53:4917#include <utility>
18#include <vector>
19
[email protected]14c1c232013-06-11 17:52:4420#include "base/containers/hash_tables.h"
[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"
rtennetif60c32d82015-10-14 00:07:0024#include "base/memory/scoped_ptr.h"
[email protected]d069c11a2013-04-13 00:01:5525#include "base/strings/string_piece.h"
[email protected]165e0752012-11-16 07:49:4426#include "net/base/int128.h"
rtennetic14c8ab2015-06-18 05:47:4027#include "net/base/iovec.h"
[email protected]79d13dcb2014-02-05 07:23:1328#include "net/base/ip_endpoint.h"
[email protected]8b37a092012-10-18 21:53:4929#include "net/base/net_export.h"
rtenneti4efd55dd2015-09-18 01:12:0430#include "net/quic/interval_set.h"
[email protected]fee17f72013-02-03 07:47:4131#include "net/quic/quic_bandwidth.h"
[email protected]2a960e02012-11-11 14:48:1032#include "net/quic/quic_time.h"
rtennetic14c8ab2015-06-18 05:47:4033#include "net/quic/quic_types.h"
[email protected]8b37a092012-10-18 21:53:4934
35namespace net {
36
[email protected]8b37a092012-10-18 21:53:4937class QuicPacket;
[email protected]b064310782013-05-30 21:12:1738struct QuicPacketHeader;
jokulikc971baf92016-01-06 00:36:3939class QuicAckListenerInterface;
[email protected]8b37a092012-10-18 21:53:4940
Avi Drissman13fc8932015-12-20 04:40:4641typedef uint64_t QuicConnectionId;
42typedef uint32_t QuicStreamId;
43typedef uint64_t QuicStreamOffset;
44typedef uint64_t QuicPacketNumber;
45typedef uint8_t QuicPathId;
rtennetia004d332015-08-28 06:44:5746typedef QuicPacketNumber QuicFecGroupNumber;
Avi Drissman13fc8932015-12-20 04:40:4647typedef uint64_t QuicPublicResetNonceProof;
48typedef uint8_t QuicPacketEntropyHash;
49typedef uint32_t QuicHeaderId;
[email protected]2532de12013-05-09 12:29:3350// QuicTag is the type of a tag in the wire protocol.
Avi Drissman13fc8932015-12-20 04:40:4651typedef uint32_t QuicTag;
[email protected]2532de12013-05-09 12:29:3352typedef std::vector<QuicTag> QuicTagVector;
[email protected]79d13dcb2014-02-05 07:23:1353typedef std::map<QuicTag, std::string> QuicTagValueMap;
Avi Drissman13fc8932015-12-20 04:40:4654typedef uint16_t QuicPacketLength;
[email protected]cff7b7b2013-01-11 08:49:0755
rtennetibb2780c2015-07-22 19:16:0856// Default initial maximum size in bytes of a QUIC packet.
[email protected]310d37b2014-08-02 06:15:3757const QuicByteCount kDefaultMaxPacketSize = 1350;
rtenneti16a20772015-02-17 18:58:4858// Default initial maximum size in bytes of a QUIC packet for servers.
59const QuicByteCount kDefaultServerMaxPacketSize = 1000;
[email protected]8e01c062013-10-31 07:35:3160// The maximum packet size of any QUIC packet, based on ethernet's max size,
fayanga31a74b2015-12-28 17:27:1461// minus the IP and UDP headers. IPv6 has a 40 byte header, UDP adds an
[email protected]41fb6372013-12-10 05:26:4062// additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's
63// max packet size is 1500 bytes, 1500 - 48 = 1452.
64const QuicByteCount kMaxPacketSize = 1452;
rtenneti9e0fb502015-03-08 06:07:1665// Default maximum packet size used in the Linux TCP implementation.
66// Used in QUIC for congestion window computations in bytes.
[email protected]ce7bb1412014-05-17 15:51:3367const QuicByteCount kDefaultTCPMSS = 1460;
[email protected]8e01c062013-10-31 07:35:3168
rch1fe2eeb2015-10-26 14:45:5769// We match SPDY's use of 32 (since we'd compete with SPDY).
70const QuicPacketCount kInitialCongestionWindow = 32;
[email protected]8e01c062013-10-31 07:35:3171
rtenneti7652bf32015-01-05 18:51:0772// Minimum size of initial flow control window, for both stream and session.
Avi Drissman13fc8932015-12-20 04:40:4673const uint32_t kMinimumFlowControlSendWindow = 16 * 1024; // 16 KB
[email protected]9bb57c72014-03-31 20:36:0474
rjshadec86dbfa2015-11-12 20:16:2575// Maximum flow control receive window limits for connection and stream.
76const QuicByteCount kStreamReceiveWindowLimit = 16 * 1024 * 1024; // 16 MB
77const QuicByteCount kSessionReceiveWindowLimit = 24 * 1024 * 1024; // 24 MB
78
rtennetifb3fa6c2015-03-16 23:04:5579// Minimum size of the CWND, in packets, when doing bandwidth resumption.
rtenneti8d2a808d2014-11-26 01:10:0980const QuicPacketCount kMinCongestionWindowForBandwidthResumption = 10;
81
rtenneti581b6ae82015-07-20 20:48:0182// Maximum size of the CWND, in packets.
83const QuicPacketCount kMaxCongestionWindow = 200;
rtenneti69e64aa2015-06-26 04:25:3084
85// Maximum number of tracked packets.
86const QuicPacketCount kMaxTrackedPackets = 5000;
[email protected]0ac0c5b2013-11-20 05:55:5887
rtenneti23186682014-10-30 01:49:3388// Default size of the socket receive buffer in bytes.
[email protected]648f81142014-08-15 21:38:4689const QuicByteCount kDefaultSocketReceiveBuffer = 256 * 1024;
rtenneti23186682014-10-30 01:49:3390// Minimum size of the socket receive buffer in bytes.
91// Smaller values are ignored.
92const QuicByteCount kMinSocketReceiveBuffer = 16 * 1024;
[email protected]a97b3182014-08-08 08:10:1893
rtenneti95293802015-03-27 18:59:2394// Fraction of the receive buffer that can be used for encrypted bytes.
95// Allows a 5% overhead for IP and UDP framing, as well as ack only packets.
96static const float kUsableRecieveBufferFraction = 0.95f;
rtenneti581b6ae82015-07-20 20:48:0197// Fraction of the receive buffer that can be used, based on conservative
98// estimates and testing on Linux.
99// An alternative to kUsableRecieveBufferFraction.
100static const float kConservativeReceiveBufferFraction = 0.6f;
rtenneti95293802015-03-27 18:59:23101
rtennetifc97ab62014-11-11 22:17:49102// Don't allow a client to suggest an RTT shorter than 10ms.
Avi Drissman13fc8932015-12-20 04:40:46103const uint32_t kMinInitialRoundTripTimeUs = 10 * kNumMicrosPerMilli;
rtennetifc97ab62014-11-11 22:17:49104
[email protected]8e01c062013-10-31 07:35:31105// Don't allow a client to suggest an RTT longer than 15 seconds.
Avi Drissman13fc8932015-12-20 04:40:46106const uint32_t kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond;
[email protected]8b37a092012-10-18 21:53:49107
108// Maximum number of open streams per connection.
109const size_t kDefaultMaxStreamsPerConnection = 100;
110
[email protected]af806e62013-05-22 14:47:50111// Number of bytes reserved for public flags in the packet header.
112const size_t kPublicFlagsSize = 1;
[email protected]5351cc4b2013-03-03 07:22:41113// Number of bytes reserved for version number in the packet header.
114const size_t kQuicVersionSize = 4;
zhongyib8677022015-12-01 05:51:30115// Number of bytes reserved for path id in the packet header.
116const size_t kQuicPathIdSize = 1;
[email protected]c995c572013-01-18 05:43:20117// Number of bytes reserved for private flags in the packet header.
118const size_t kPrivateFlagsSize = 1;
119// Number of bytes reserved for FEC group in the packet header.
120const size_t kFecGroupSize = 1;
[email protected]5351cc4b2013-03-03 07:22:41121
122// Signifies that the QuicPacket will contain version of the protocol.
123const bool kIncludeVersion = true;
zhongyib8677022015-12-01 05:51:30124// Signifies that the QuicPacket will contain path id.
125const bool kIncludePathId = true;
[email protected]c995c572013-01-18 05:43:20126
zhongyi4a9d27b2016-01-12 20:08:31127// Stream ID is reserved to denote an invalid ID.
128const QuicStreamId kInvalidStreamId = 0;
129
[email protected]8b37a092012-10-18 21:53:49130// Reserved ID for the crypto stream.
[email protected]8b37a092012-10-18 21:53:49131const QuicStreamId kCryptoStreamId = 1;
132
[email protected]4d640792013-12-18 22:21:08133// Reserved ID for the headers stream.
134const QuicStreamId kHeadersStreamId = 3;
135
jri3285d93a2015-12-14 08:53:19136// Header key used to identify final offset on data stream when sending HTTP/2
137// trailing headers over QUIC.
138NET_EXPORT_PRIVATE extern const char* const kFinalOffsetHeaderKey;
139
[email protected]648f81142014-08-15 21:38:46140// Maximum delayed ack time, in ms.
Avi Drissman13fc8932015-12-20 04:40:46141const int64_t kMaxDelayedAckTimeMs = 25;
[email protected]648f81142014-08-15 21:38:46142
rjshaded069aaee2016-03-11 20:42:17143// Minimum tail loss probe time in ms.
144static const int64_t kMinTailLossProbeTimeoutMs = 10;
145
rtennetib5512bb2014-09-29 19:17:15146// The timeout before the handshake succeeds.
Avi Drissman13fc8932015-12-20 04:40:46147const int64_t kInitialIdleTimeoutSecs = 5;
rtennetib5512bb2014-09-29 19:17:15148// The default idle timeout.
Avi Drissman13fc8932015-12-20 04:40:46149const int64_t kDefaultIdleTimeoutSecs = 30;
rtenneti31e9fd62014-09-16 05:22:15150// The maximum idle timeout that can be negotiated.
Avi Drissman13fc8932015-12-20 04:40:46151const int64_t kMaximumIdleTimeoutSecs = 60 * 10; // 10 minutes.
rtenneti31e9fd62014-09-16 05:22:15152// The default timeout for a connection until the crypto handshake succeeds.
Avi Drissman13fc8932015-12-20 04:40:46153const int64_t kMaxTimeForCryptoHandshakeSecs = 10; // 10 secs.
[email protected]8b37a092012-10-18 21:53:49154
rtenneti93bce7ece2014-10-13 22:38:41155// Default limit on the number of undecryptable packets the connection buffers
156// before the CHLO/SHLO arrive.
157const size_t kDefaultMaxUndecryptablePackets = 10;
158
[email protected]525948df2014-04-21 06:26:58159// Default ping timeout.
Avi Drissman13fc8932015-12-20 04:40:46160const int64_t kPingTimeoutSecs = 15; // 15 secs.
[email protected]525948df2014-04-21 06:26:58161
[email protected]ca4e0d92014-08-22 16:33:22162// Minimum number of RTTs between Server Config Updates (SCUP) sent to client.
163const int kMinIntervalBetweenServerConfigUpdatesRTTs = 10;
164
165// Minimum time between Server Config Updates (SCUP) sent to client.
166const int kMinIntervalBetweenServerConfigUpdatesMs = 1000;
167
rtenneti33da8ab2014-11-04 04:17:00168// Minimum number of packets between Server Config Updates (SCUP).
169const int kMinPacketsBetweenServerConfigUpdates = 100;
170
rtennetib5512bb2014-09-29 19:17:15171// The number of open streams that a server will accept is set to be slightly
172// larger than the negotiated limit. Immediately closing the connection if the
173// client opens slightly too many streams is not ideal: the client may have sent
174// a FIN that was lost, and simultaneously opened a new stream. The number of
175// streams a server accepts is a fixed increment over the negotiated limit, or a
176// percentage increase, whichever is larger.
rtenneti31e9fd62014-09-16 05:22:15177const float kMaxStreamsMultiplier = 1.1f;
rtennetib5512bb2014-09-29 19:17:15178const int kMaxStreamsMinimumIncrement = 10;
rtenneti31e9fd62014-09-16 05:22:15179
rtenneti159828f2015-10-13 06:58:09180// Available streams are ones with IDs less than the highest stream that has
181// been opened which have neither been opened or reset. The limit on the number
182// of available streams is 10 times the limit on the number of open streams.
183const int kMaxAvailableStreamsMultiplier = 10;
184
jric533399b2016-01-29 07:36:01185// Track the number of promises that are not yet claimed by a
186// corresponding get. This must be smaller than
187// kMaxAvailableStreamsMultiplier, because RST on a promised stream my
188// create available streams entries.
189const int kMaxPromisedStreamsMultiplier = kMaxAvailableStreamsMultiplier - 1;
190
[email protected]b007e632013-10-28 08:39:25191// We define an unsigned 16-bit floating point value, inspired by IEEE floats
192// (http://en.wikipedia.org/wiki/Half_precision_floating-point_format),
193// with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden
194// bit) and denormals, but without signs, transfinites or fractions. Wire format
195// 16 bits (little-endian byte order) are split into exponent (high 5) and
196// mantissa (low 11) and decoded as:
Avi Drissman13fc8932015-12-20 04:40:46197// uint64_t value;
[email protected]b007e632013-10-28 08:39:25198// if (exponent == 0) value = mantissa;
199// else value = (mantissa | 1 << 11) << (exponent - 1)
200const int kUFloat16ExponentBits = 5;
rjshaded5ced072015-12-18 19:26:02201const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30
202const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11
[email protected]b007e632013-10-28 08:39:25203const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12
Avi Drissman13fc8932015-12-20 04:40:46204const uint64_t kUFloat16MaxValue = // 0x3FFC0000000
rjshaded5ced072015-12-18 19:26:02205 ((UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1)
206 << kUFloat16MaxExponent;
[email protected]b007e632013-10-28 08:39:25207
jri3285d93a2015-12-14 08:53:19208// Default path ID.
209const QuicPathId kDefaultPathId = 0;
fayanga31a74b2015-12-28 17:27:14210// Invalid path ID.
211const QuicPathId kInvalidPathId = 0xff;
jri3285d93a2015-12-14 08:53:19212
fayanga64c1a92016-02-13 01:55:58213enum TransmissionType : int8_t {
[email protected]2532de12013-05-09 12:29:33214 NOT_RETRANSMISSION,
[email protected]b9475b582014-03-20 20:04:33215 FIRST_TRANSMISSION_TYPE = NOT_RETRANSMISSION,
rjshaded5ced072015-12-18 19:26:02216 HANDSHAKE_RETRANSMISSION, // Retransmits due to handshake timeouts.
rtenneti31e9fd62014-09-16 05:22:15217 ALL_UNACKED_RETRANSMISSION, // Retransmits all unacked packets.
218 ALL_INITIAL_RETRANSMISSION, // Retransmits all initially encrypted packets.
rjshaded5ced072015-12-18 19:26:02219 LOSS_RETRANSMISSION, // Retransmits due to loss detection.
220 RTO_RETRANSMISSION, // Retransmits due to retransmit time out.
221 TLP_RETRANSMISSION, // Tail loss probes.
[email protected]b9475b582014-03-20 20:04:33222 LAST_TRANSMISSION_TYPE = TLP_RETRANSMISSION,
[email protected]74bda142013-03-31 02:49:11223};
224
fayanga64c1a92016-02-13 01:55:58225enum HasRetransmittableData : int8_t {
[email protected]2532de12013-05-09 12:29:33226 NO_RETRANSMITTABLE_DATA,
227 HAS_RETRANSMITTABLE_DATA,
[email protected]74bda142013-03-31 02:49:11228};
229
fayanga64c1a92016-02-13 01:55:58230enum IsHandshake : int8_t { NOT_HANDSHAKE, IS_HANDSHAKE };
[email protected]575cce62013-08-03 02:06:43231
rtenneti6f48aa92015-03-16 02:18:48232enum class Perspective { IS_SERVER, IS_CLIENT };
233
fayanga64c1a92016-02-13 01:55:58234// Describes whether a ConnectionClose was originated by the peer.
235enum class ConnectionCloseSource { FROM_PEER, FROM_SELF };
236
rtenneti6f48aa92015-03-16 02:18:48237NET_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
238 const Perspective& s);
239
[email protected]be24ab22012-10-22 03:01:52240enum QuicFrameType {
[email protected]6ae6e342014-02-06 02:21:42241 // Regular frame types. The values set here cannot change without the
242 // introduction of a new QUIC version.
[email protected]c995c572013-01-18 05:43:20243 PADDING_FRAME = 0,
[email protected]6ae6e342014-02-06 02:21:42244 RST_STREAM_FRAME = 1,
245 CONNECTION_CLOSE_FRAME = 2,
246 GOAWAY_FRAME = 3,
247 WINDOW_UPDATE_FRAME = 4,
248 BLOCKED_FRAME = 5,
[email protected]93dd91f2014-02-27 00:09:03249 STOP_WAITING_FRAME = 6,
[email protected]d8c522112014-04-23 09:23:25250 PING_FRAME = 7,
rchcaec4242016-01-22 20:49:52251 PATH_CLOSE_FRAME = 8,
[email protected]6ae6e342014-02-06 02:21:42252
rtennetif4bdb542015-01-21 14:33:05253 // STREAM and ACK frames are special frames. They are encoded differently on
254 // the wire and their values do not need to be stable.
[email protected]97cf3022013-09-05 14:30:16255 STREAM_FRAME,
256 ACK_FRAME,
rtenneti69e64aa2015-06-26 04:25:30257 // The path MTU discovery frame is encoded as a PING frame on the wire.
258 MTU_DISCOVERY_FRAME,
[email protected]be24ab22012-10-22 03:01:52259 NUM_FRAME_TYPES
[email protected]8b37a092012-10-18 21:53:49260};
261
[email protected]3aa9ca72014-02-27 19:39:43262enum QuicConnectionIdLength {
263 PACKET_0BYTE_CONNECTION_ID = 0,
264 PACKET_1BYTE_CONNECTION_ID = 1,
265 PACKET_4BYTE_CONNECTION_ID = 4,
266 PACKET_8BYTE_CONNECTION_ID = 8
[email protected]b064310782013-05-30 21:12:17267};
268
269enum InFecGroup {
270 NOT_IN_FEC_GROUP,
271 IN_FEC_GROUP,
272};
273
fayanga64c1a92016-02-13 01:55:58274enum QuicPacketNumberLength : int8_t {
rtennetia004d332015-08-28 06:44:57275 PACKET_1BYTE_PACKET_NUMBER = 1,
276 PACKET_2BYTE_PACKET_NUMBER = 2,
277 PACKET_4BYTE_PACKET_NUMBER = 4,
278 PACKET_6BYTE_PACKET_NUMBER = 6
[email protected]25c31dc2013-06-05 17:56:04279};
280
[email protected]8e01c062013-10-31 07:35:31281// Used to indicate a QuicSequenceNumberLength using two flag bits.
rtennetia004d332015-08-28 06:44:57282enum QuicPacketNumberLengthFlags {
283 PACKET_FLAGS_1BYTE_PACKET = 0, // 00
284 PACKET_FLAGS_2BYTE_PACKET = 1, // 01
285 PACKET_FLAGS_4BYTE_PACKET = 1 << 1, // 10
286 PACKET_FLAGS_6BYTE_PACKET = 1 << 1 | 1, // 11
[email protected]8e01c062013-10-31 07:35:31287};
288
[email protected]f62262b2013-07-05 20:57:30289// The public flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20290enum QuicPacketPublicFlags {
291 PACKET_PUBLIC_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30292
293 // Bit 0: Does the packet header contains version info?
294 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0,
295
296 // Bit 1: Is this packet a public reset packet?
297 PACKET_PUBLIC_FLAGS_RST = 1 << 1,
298
[email protected]3aa9ca72014-02-27 19:39:43299 // Bits 2 and 3 specify the length of the ConnectionId as follows:
[email protected]f62262b2013-07-05 20:57:30300 // ----00--: 0 bytes
301 // ----01--: 1 byte
302 // ----10--: 4 bytes
303 // ----11--: 8 bytes
[email protected]3aa9ca72014-02-27 19:39:43304 PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID = 0,
305 PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID = 1 << 2,
306 PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID = 1 << 3,
307 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID = 1 << 3 | 1 << 2,
[email protected]f62262b2013-07-05 20:57:30308
rtennetia004d332015-08-28 06:44:57309 // Bits 4 and 5 describe the packet number length as follows:
[email protected]f62262b2013-07-05 20:57:30310 // --00----: 1 byte
311 // --01----: 2 bytes
312 // --10----: 4 bytes
313 // --11----: 6 bytes
rtennetia004d332015-08-28 06:44:57314 PACKET_PUBLIC_FLAGS_1BYTE_PACKET = PACKET_FLAGS_1BYTE_PACKET << 4,
315 PACKET_PUBLIC_FLAGS_2BYTE_PACKET = PACKET_FLAGS_2BYTE_PACKET << 4,
316 PACKET_PUBLIC_FLAGS_4BYTE_PACKET = PACKET_FLAGS_4BYTE_PACKET << 4,
317 PACKET_PUBLIC_FLAGS_6BYTE_PACKET = PACKET_FLAGS_6BYTE_PACKET << 4,
[email protected]f62262b2013-07-05 20:57:30318
zhongyib8677022015-12-01 05:51:30319 // Bit 6: Does the packet header contain a path id?
320 PACKET_PUBLIC_FLAGS_MULTIPATH = 1 << 6,
321
jric533399b2016-01-29 07:36:01322 // All bits set (bit 7 is not currently used): 01111111
zhongyib8677022015-12-01 05:51:30323 PACKET_PUBLIC_FLAGS_MAX = (1 << 7) - 1,
[email protected]c995c572013-01-18 05:43:20324};
[email protected]8b37a092012-10-18 21:53:49325
[email protected]f62262b2013-07-05 20:57:30326// The private flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20327enum QuicPacketPrivateFlags {
328 PACKET_PRIVATE_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30329
330 // Bit 0: Does this packet contain an entropy bit?
[email protected]b064310782013-05-30 21:12:17331 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0,
[email protected]f62262b2013-07-05 20:57:30332
333 // Bit 1: Payload is part of an FEC group?
334 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1,
335
336 // Bit 2: Payload is FEC as opposed to frames?
337 PACKET_PRIVATE_FLAGS_FEC = 1 << 2,
338
339 // All bits set (bits 3-7 are not currently used): 00000111
340 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1
[email protected]c995c572013-01-18 05:43:20341};
342
[email protected]48878092013-07-26 14:51:56343// The available versions of QUIC. Guaranteed that the integer value of the enum
344// will match the version number.
345// When adding a new version to this enum you should add it to
[email protected]8bbfaeb72013-08-09 06:38:26346// kSupportedQuicVersions (if appropriate), and also add a new case to the
347// helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and
348// QuicVersionToString.
[email protected]48878092013-07-26 14:51:56349enum QuicVersion {
350 // Special case to indicate unknown/unsupported QUIC version.
351 QUIC_VERSION_UNSUPPORTED = 0,
352
rchc0815442015-04-18 13:29:46353 QUIC_VERSION_25 = 25, // SPDY/4 header keys, and removal of error_details
354 // from QuicRstStreamFrame
zhongyic92bc492015-09-22 19:14:36355 QUIC_VERSION_26 = 26, // In CHLO, send XLCT tag containing hash of leaf cert
rtenneti159828f2015-10-13 06:58:09356 QUIC_VERSION_27 = 27, // Sends a nonce in the SHLO.
rtenneti5ca6eee2015-10-15 21:54:30357 QUIC_VERSION_28 = 28, // Receiver can refuse to create a requested stream.
rch99b644c2015-11-04 05:25:28358 QUIC_VERSION_29 = 29, // Server and client honor QUIC_STREAM_NO_ERROR.
359 QUIC_VERSION_30 = 30, // Add server side support of cert transparency.
[email protected]48878092013-07-26 14:51:56360};
361
362// This vector contains QUIC versions which we currently support.
363// This should be ordered such that the highest supported version is the first
364// element, with subsequent elements in descending order (versions can be
365// skipped as necessary).
[email protected]31ae854842013-11-27 00:05:46366//
[email protected]310d37b2014-08-02 06:15:37367// IMPORTANT: if you are adding to this list, follow the instructions at
[email protected]31ae854842013-11-27 00:05:46368// http://sites/quic/adding-and-removing-versions
zhongyic92bc492015-09-22 19:14:36369static const QuicVersion kSupportedQuicVersions[] = {
rch99b644c2015-11-04 05:25:28370 QUIC_VERSION_30, QUIC_VERSION_29, QUIC_VERSION_28,
371 QUIC_VERSION_27, QUIC_VERSION_26, QUIC_VERSION_25};
[email protected]48878092013-07-26 14:51:56372
373typedef std::vector<QuicVersion> QuicVersionVector;
374
[email protected]b007e632013-10-28 08:39:25375// Returns a vector of QUIC versions in kSupportedQuicVersions.
376NET_EXPORT_PRIVATE QuicVersionVector QuicSupportedVersions();
[email protected]ea2ab47b2013-08-13 00:44:11377
[email protected]48878092013-07-26 14:51:56378// QuicTag is written to and read from the wire, but we prefer to use
379// the more readable QuicVersion at other levels.
380// Helper function which translates from a QuicVersion to a QuicTag. Returns 0
381// if QuicVersion is unsupported.
382NET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version);
383
384// Returns appropriate QuicVersion from a QuicTag.
385// Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood.
386NET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag);
387
388// Helper function which translates from a QuicVersion to a string.
389// Returns strings corresponding to enum names (e.g. QUIC_VERSION_6).
390NET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version);
391
392// Returns comma separated list of string representations of QuicVersion enum
[email protected]b007e632013-10-28 08:39:25393// values in the supplied |versions| vector.
394NET_EXPORT_PRIVATE std::string QuicVersionVectorToString(
395 const QuicVersionVector& versions);
[email protected]48878092013-07-26 14:51:56396
397// Version and Crypto tags are written to the wire with a big-endian
398// representation of the name of the tag. For example
399// the client hello tag (CHLO) will be written as the
400// following 4 bytes: 'C' 'H' 'L' 'O'. Since it is
Avi Drissman13fc8932015-12-20 04:40:46401// stored in memory as a little endian uint32_t, we need
[email protected]48878092013-07-26 14:51:56402// to reverse the order of the bytes.
403
404// MakeQuicTag returns a value given the four bytes. For example:
405// MakeQuicTag('C', 'H', 'L', 'O');
406NET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d);
407
[email protected]9cda5fd2014-06-03 10:20:28408// Returns true if the tag vector contains the specified tag.
[email protected]cc1aa272014-06-30 19:48:22409NET_EXPORT_PRIVATE bool ContainsQuicTag(const QuicTagVector& tag_vector,
410 QuicTag tag);
[email protected]9cda5fd2014-06-03 10:20:28411
rjshaded069aaee2016-03-11 20:42:17412// Size in bytes of the data packet header.
[email protected]79d13dcb2014-02-05 07:23:13413NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(const QuicPacketHeader& header);
[email protected]b064310782013-05-30 21:12:17414
rtennetia004d332015-08-28 06:44:57415NET_EXPORT_PRIVATE size_t
416GetPacketHeaderSize(QuicConnectionIdLength connection_id_length,
417 bool include_version,
zhongyib8677022015-12-01 05:51:30418 bool include_path_id,
rjshaded069aaee2016-03-11 20:42:17419 QuicPacketNumberLength packet_number_length);
rchcaec4242016-01-22 20:49:52420
[email protected]b064310782013-05-30 21:12:17421// Index of the first byte in a QUIC packet of encrypted data.
rtennetia004d332015-08-28 06:44:57422NET_EXPORT_PRIVATE size_t
rjshaded069aaee2016-03-11 20:42:17423GetStartOfEncryptedData(const QuicPacketHeader& header);
424
425NET_EXPORT_PRIVATE size_t
rtennetia004d332015-08-28 06:44:57426GetStartOfEncryptedData(QuicConnectionIdLength connection_id_length,
427 bool include_version,
rchcaec4242016-01-22 20:49:52428 bool include_path_id,
rtennetia004d332015-08-28 06:44:57429 QuicPacketNumberLength packet_number_length);
[email protected]b064310782013-05-30 21:12:17430
[email protected]74bda142013-03-31 02:49:11431enum QuicRstStreamErrorCode {
rch99b644c2015-11-04 05:25:28432 // Complete response has been sent, sending a RST to ask the other endpoint
433 // to stop sending request data without discarding the response.
[email protected]74bda142013-03-31 02:49:11434 QUIC_STREAM_NO_ERROR = 0,
[email protected]8b37a092012-10-18 21:53:49435
[email protected]24e5bc52013-09-18 15:36:58436 // There was some error which halted stream processing.
437 QUIC_ERROR_PROCESSING_STREAM,
[email protected]8b37a092012-10-18 21:53:49438 // We got two fin or reset offsets which did not match.
439 QUIC_MULTIPLE_TERMINATION_OFFSETS,
440 // We got bad payload and can not respond to it at the protocol level.
441 QUIC_BAD_APPLICATION_PAYLOAD,
[email protected]74bda142013-03-31 02:49:11442 // Stream closed due to connection error. No reset frame is sent when this
443 // happens.
444 QUIC_STREAM_CONNECTION_ERROR,
445 // GoAway frame sent. No more stream can be created.
446 QUIC_STREAM_PEER_GOING_AWAY,
[email protected]06ff5152013-08-29 01:03:05447 // The stream has been cancelled.
448 QUIC_STREAM_CANCELLED,
rtenneti4a5df262014-11-07 00:43:58449 // Closing stream locally, sending a RST to allow for proper flow control
450 // accounting. Sent in response to a RST from the peer.
451 QUIC_RST_ACKNOWLEDGEMENT,
rtenneti5ca6eee2015-10-15 21:54:30452 // Receiver refused to create the stream (because its limit on open streams
453 // has been reached). The sender should retry the request later (using
454 // another stream).
455 QUIC_REFUSED_STREAM,
jric533399b2016-01-29 07:36:01456 // Invalid URL in PUSH_PROMISE request header.
457 QUIC_INVALID_PROMISE_URL,
458 // Server is not authoritative for this URL.
459 QUIC_UNAUTHORIZED_PROMISE_URL,
460 // Can't have more than one active PUSH_PROMISE per URL.
461 QUIC_DUPLICATE_PROMISE_URL,
ckrasic244375a32016-02-04 21:21:22462 // Vary check failed.
463 QUIC_PROMISE_VARY_MISMATCH,
ckrasic171ef13e2016-02-26 01:20:16464 // Only GET and HEAD methods allowed.
465 QUIC_INVALID_PROMISE_METHOD,
[email protected]74bda142013-03-31 02:49:11466 // No error. Used as bound while iterating.
467 QUIC_STREAM_LAST_ERROR,
468};
[email protected]8b37a092012-10-18 21:53:49469
[email protected]51cc1342014-04-18 23:44:37470// Because receiving an unknown QuicRstStreamErrorCode results in connection
471// teardown, we use this to make sure any errors predating a given version are
472// downgraded to the most appropriate existing error.
rjshaded5ced072015-12-18 19:26:02473NET_EXPORT_PRIVATE QuicRstStreamErrorCode
474AdjustErrorForVersion(QuicRstStreamErrorCode error_code, QuicVersion version);
[email protected]51cc1342014-04-18 23:44:37475
[email protected]89264042013-08-21 07:35:24476// These values must remain stable as they are uploaded to UMA histograms.
477// To add a new error code, use the current value of QUIC_LAST_ERROR and
478// increment QUIC_LAST_ERROR.
[email protected]74bda142013-03-31 02:49:11479enum QuicErrorCode {
480 QUIC_NO_ERROR = 0,
481
482 // Connection has reached an invalid state.
[email protected]89264042013-08-21 07:35:24483 QUIC_INTERNAL_ERROR = 1,
[email protected]74bda142013-03-31 02:49:11484 // There were data frames after the a fin or reset.
[email protected]89264042013-08-21 07:35:24485 QUIC_STREAM_DATA_AFTER_TERMINATION = 2,
[email protected]8b37a092012-10-18 21:53:49486 // Control frame is malformed.
[email protected]89264042013-08-21 07:35:24487 QUIC_INVALID_PACKET_HEADER = 3,
[email protected]be24ab22012-10-22 03:01:52488 // Frame data is malformed.
[email protected]89264042013-08-21 07:35:24489 QUIC_INVALID_FRAME_DATA = 4,
490 // The packet contained no payload.
491 QUIC_MISSING_PAYLOAD = 48,
[email protected]8b37a092012-10-18 21:53:49492 // FEC data is malformed.
[email protected]89264042013-08-21 07:35:24493 QUIC_INVALID_FEC_DATA = 5,
494 // STREAM frame data is malformed.
495 QUIC_INVALID_STREAM_DATA = 46,
[email protected]42a3eba2014-04-30 10:52:55496 // STREAM frame data is not encrypted.
497 QUIC_UNENCRYPTED_STREAM_DATA = 61,
zhongyi4a9d27b2016-01-12 20:08:31498 // FEC frame data is not encrypted.
499 QUIC_UNENCRYPTED_FEC_DATA = 77,
[email protected]89264042013-08-21 07:35:24500 // RST_STREAM frame data is malformed.
501 QUIC_INVALID_RST_STREAM_DATA = 6,
502 // CONNECTION_CLOSE frame data is malformed.
503 QUIC_INVALID_CONNECTION_CLOSE_DATA = 7,
504 // GOAWAY frame data is malformed.
505 QUIC_INVALID_GOAWAY_DATA = 8,
[email protected]6ae6e342014-02-06 02:21:42506 // WINDOW_UPDATE frame data is malformed.
507 QUIC_INVALID_WINDOW_UPDATE_DATA = 57,
508 // BLOCKED frame data is malformed.
509 QUIC_INVALID_BLOCKED_DATA = 58,
[email protected]93dd91f2014-02-27 00:09:03510 // STOP_WAITING frame data is malformed.
511 QUIC_INVALID_STOP_WAITING_DATA = 60,
rchcaec4242016-01-22 20:49:52512 // PATH_CLOSE frame data is malformed.
513 QUIC_INVALID_PATH_CLOSE_DATA = 78,
[email protected]89264042013-08-21 07:35:24514 // ACK frame data is malformed.
515 QUIC_INVALID_ACK_DATA = 9,
rtennetif4bdb542015-01-21 14:33:05516
[email protected]14e8106c2013-03-14 16:25:33517 // Version negotiation packet is malformed.
[email protected]89264042013-08-21 07:35:24518 QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10,
[email protected]899951652013-05-16 12:52:39519 // Public RST packet is malformed.
[email protected]89264042013-08-21 07:35:24520 QUIC_INVALID_PUBLIC_RST_PACKET = 11,
[email protected]8b37a092012-10-18 21:53:49521 // There was an error decrypting.
[email protected]89264042013-08-21 07:35:24522 QUIC_DECRYPTION_FAILURE = 12,
[email protected]8b37a092012-10-18 21:53:49523 // There was an error encrypting.
[email protected]89264042013-08-21 07:35:24524 QUIC_ENCRYPTION_FAILURE = 13,
[email protected]8b37a092012-10-18 21:53:49525 // The packet exceeded kMaxPacketSize.
[email protected]89264042013-08-21 07:35:24526 QUIC_PACKET_TOO_LARGE = 14,
[email protected]9db443912013-02-25 05:27:03527 // The peer is going away. May be a client or server.
[email protected]89264042013-08-21 07:35:24528 QUIC_PEER_GOING_AWAY = 16,
[email protected]8b37a092012-10-18 21:53:49529 // A stream ID was invalid.
[email protected]89264042013-08-21 07:35:24530 QUIC_INVALID_STREAM_ID = 17,
[email protected]24e5bc52013-09-18 15:36:58531 // A priority was invalid.
532 QUIC_INVALID_PRIORITY = 49,
[email protected]8b37a092012-10-18 21:53:49533 // Too many streams already open.
[email protected]89264042013-08-21 07:35:24534 QUIC_TOO_MANY_OPEN_STREAMS = 18,
rtenneti159828f2015-10-13 06:58:09535 // The peer created too many available streams.
536 QUIC_TOO_MANY_AVAILABLE_STREAMS = 76,
[email protected]86a318d2013-01-23 21:16:04537 // Received public reset for this connection.
[email protected]89264042013-08-21 07:35:24538 QUIC_PUBLIC_RESET = 19,
[email protected]c244c5a12013-05-07 20:55:04539 // Invalid protocol version.
[email protected]89264042013-08-21 07:35:24540 QUIC_INVALID_VERSION = 20,
[email protected]92bf17c2014-03-03 21:14:03541
[email protected]c244c5a12013-05-07 20:55:04542 // The Header ID for a stream was too far from the previous.
[email protected]89264042013-08-21 07:35:24543 QUIC_INVALID_HEADER_ID = 22,
[email protected]899951652013-05-16 12:52:39544 // Negotiable parameter received during handshake had invalid value.
[email protected]89264042013-08-21 07:35:24545 QUIC_INVALID_NEGOTIATED_VALUE = 23,
[email protected]899951652013-05-16 12:52:39546 // There was an error decompressing data.
[email protected]89264042013-08-21 07:35:24547 QUIC_DECOMPRESSION_FAILURE = 24,
rtenneti2cae2072016-02-05 02:21:33548 // The connection timed out due to no network activity.
549 QUIC_NETWORK_IDLE_TIMEOUT = 25,
550 // The connection timed out waiting for the handshake to complete.
551 QUIC_HANDSHAKE_TIMEOUT = 67,
zhongyi2341cda2016-03-10 04:09:34552 // There was an error encountered migrating addresses.
[email protected]89264042013-08-21 07:35:24553 QUIC_ERROR_MIGRATING_ADDRESS = 26,
zhongyi2341cda2016-03-10 04:09:34554 // There was an error encountered migrating port only.
555 QUIC_ERROR_MIGRATING_PORT = 86,
[email protected]1505a512013-09-04 22:59:35556 // There was an error while writing to the socket.
[email protected]89264042013-08-21 07:35:24557 QUIC_PACKET_WRITE_ERROR = 27,
[email protected]1505a512013-09-04 22:59:35558 // There was an error while reading from the socket.
559 QUIC_PACKET_READ_ERROR = 51,
[email protected]24e5bc52013-09-18 15:36:58560 // We received a STREAM_FRAME with no data and no fin flag set.
561 QUIC_INVALID_STREAM_FRAME = 50,
[email protected]4d640792013-12-18 22:21:08562 // We received invalid data on the headers stream.
563 QUIC_INVALID_HEADERS_STREAM_DATA = 56,
[email protected]730b35d72014-06-05 03:23:22564 // The peer received too much data, violating flow control.
565 QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA = 59,
566 // The peer sent too much data, violating flow control.
567 QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA = 63,
568 // The peer received an invalid flow control window.
569 QUIC_FLOW_CONTROL_INVALID_WINDOW = 64,
[email protected]71c84e592014-05-28 23:39:29570 // The connection has been IP pooled into an existing connection.
571 QUIC_CONNECTION_IP_POOLED = 62,
rtenneti23186682014-10-30 01:49:33572 // The connection has too many outstanding sent packets.
573 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS = 68,
574 // The connection has too many outstanding received packets.
575 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS = 69,
fayanga64c1a92016-02-13 01:55:58576 // The quic connection has been cancelled.
rtenneti14abd312015-02-06 21:56:01577 QUIC_CONNECTION_CANCELLED = 70,
rtenneti85dcfac22015-03-27 20:22:19578 // Disabled QUIC because of high packet loss rate.
579 QUIC_BAD_PACKET_LOSS_RATE = 71,
ckrasic1e53b642015-07-08 22:39:35580 // Disabled QUIC because of too many PUBLIC_RESETs post handshake.
581 QUIC_PUBLIC_RESETS_POST_HANDSHAKE = 73,
582 // Disabled QUIC because of too many timeouts with streams open.
583 QUIC_TIMEOUTS_WITH_OPEN_STREAMS = 74,
rtenneti8811fdb2015-07-22 00:17:07584 // Closed because we failed to serialize a packet.
585 QUIC_FAILED_TO_SERIALIZE_PACKET = 75,
zhongyi2341cda2016-03-10 04:09:34586 // QUIC timed out after too many RTOs.
587 QUIC_TOO_MANY_RTOS = 85,
[email protected]8b37a092012-10-18 21:53:49588
589 // Crypto errors.
590
[email protected]1354bf62013-05-23 23:17:18591 // Hanshake failed.
[email protected]89264042013-08-21 07:35:24592 QUIC_HANDSHAKE_FAILED = 28,
[email protected]8b37a092012-10-18 21:53:49593 // Handshake message contained out of order tags.
[email protected]89264042013-08-21 07:35:24594 QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29,
[email protected]701bc892013-01-17 04:51:54595 // Handshake message contained too many entries.
[email protected]89264042013-08-21 07:35:24596 QUIC_CRYPTO_TOO_MANY_ENTRIES = 30,
[email protected]8b37a092012-10-18 21:53:49597 // Handshake message contained an invalid value length.
[email protected]89264042013-08-21 07:35:24598 QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31,
[email protected]8b37a092012-10-18 21:53:49599 // A crypto message was received after the handshake was complete.
[email protected]89264042013-08-21 07:35:24600 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32,
[email protected]d3d15bf2013-01-30 02:51:54601 // A crypto message was received with an illegal message tag.
[email protected]89264042013-08-21 07:35:24602 QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33,
[email protected]d3d15bf2013-01-30 02:51:54603 // A crypto message was received with an illegal parameter.
[email protected]89264042013-08-21 07:35:24604 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34,
[email protected]752fbe52013-10-14 08:35:32605 // An invalid channel id signature was supplied.
606 QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52,
[email protected]d3d15bf2013-01-30 02:51:54607 // A crypto message was received with a mandatory parameter missing.
[email protected]89264042013-08-21 07:35:24608 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35,
[email protected]d3d15bf2013-01-30 02:51:54609 // A crypto message was received with a parameter that has no overlap
610 // with the local parameter.
[email protected]89264042013-08-21 07:35:24611 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36,
[email protected]ed3fc15d2013-03-08 18:37:44612 // A crypto message was received that contained a parameter with too few
613 // values.
[email protected]89264042013-08-21 07:35:24614 QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37,
[email protected]ccc66e8a2013-03-26 08:26:14615 // An internal error occured in crypto processing.
[email protected]89264042013-08-21 07:35:24616 QUIC_CRYPTO_INTERNAL_ERROR = 38,
[email protected]ccc66e8a2013-03-26 08:26:14617 // A crypto handshake message specified an unsupported version.
[email protected]89264042013-08-21 07:35:24618 QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39,
rtennetie0ee6eb2015-05-01 00:55:09619 // A crypto handshake message resulted in a stateless reject.
620 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT = 72,
[email protected]ccc66e8a2013-03-26 08:26:14621 // There was no intersection between the crypto primitives supported by the
622 // peer and ourselves.
[email protected]89264042013-08-21 07:35:24623 QUIC_CRYPTO_NO_SUPPORT = 40,
[email protected]ef95114d2013-04-17 17:57:01624 // The server rejected our client hello messages too many times.
[email protected]89264042013-08-21 07:35:24625 QUIC_CRYPTO_TOO_MANY_REJECTS = 41,
[email protected]a57e0272013-04-26 07:31:47626 // The client rejected the server's certificate chain or signature.
[email protected]89264042013-08-21 07:35:24627 QUIC_PROOF_INVALID = 42,
[email protected]8ba81212013-05-03 13:11:48628 // A crypto message was received with a duplicate tag.
[email protected]89264042013-08-21 07:35:24629 QUIC_CRYPTO_DUPLICATE_TAG = 43,
[email protected]2532de12013-05-09 12:29:33630 // A crypto message was received with the wrong encryption level (i.e. it
631 // should have been encrypted but was not.)
[email protected]89264042013-08-21 07:35:24632 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44,
[email protected]2532de12013-05-09 12:29:33633 // The server config for a server has expired.
[email protected]89264042013-08-21 07:35:24634 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45,
[email protected]752fbe52013-10-14 08:35:32635 // We failed to setup the symmetric keys for a connection.
636 QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53,
[email protected]691f45a982013-11-19 10:52:04637 // A handshake message arrived, but we are still validating the
638 // previous handshake message.
639 QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54,
[email protected]ccb34212014-07-18 09:27:50640 // A server config update arrived before the handshake is complete.
641 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE = 65,
[email protected]d89f1862013-11-26 21:21:27642 // This connection involved a version negotiation which appears to have been
643 // tampered with.
644 QUIC_VERSION_NEGOTIATION_MISMATCH = 55,
[email protected]ccc66e8a2013-03-26 08:26:14645
rchcaec4242016-01-22 20:49:52646 // Multipath is not enabled, but a packet with multipath flag on is received.
647 QUIC_BAD_MULTIPATH_FLAG = 79,
648
jri7e636642016-01-14 06:57:08649 // IP address changed causing connection close.
rchcaec4242016-01-22 20:49:52650 QUIC_IP_ADDRESS_CHANGED = 80,
jri7e636642016-01-14 06:57:08651
652 // Connection migration errors.
653 // Network changed, but connection had no migratable streams.
rchcaec4242016-01-22 20:49:52654 QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS = 81,
jri7e636642016-01-14 06:57:08655 // Connection changed networks too many times.
rchcaec4242016-01-22 20:49:52656 QUIC_CONNECTION_MIGRATION_TOO_MANY_CHANGES = 82,
jri7e636642016-01-14 06:57:08657 // Connection migration was attempted, but there was no new network to
658 // migrate to.
rchcaec4242016-01-22 20:49:52659 QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK = 83,
jri231c2972016-03-08 19:50:11660 // Network changed, but connection had one or more non-migratable streams.
661 QUIC_CONNECTION_MIGRATION_NON_MIGRATABLE_STREAM = 84,
jri7e636642016-01-14 06:57:08662
[email protected]74bda142013-03-31 02:49:11663 // No error. Used as bound while iterating.
zhongyi2341cda2016-03-10 04:09:34664 QUIC_LAST_ERROR = 87,
[email protected]8b37a092012-10-18 21:53:49665};
666
zhongyi291d0302015-12-14 07:06:25667// Must be updated any time a QuicErrorCode is deprecated.
668const int kDeprecatedQuicErrorCount = 4;
669const int kActiveQuicErrorCount = QUIC_LAST_ERROR - kDeprecatedQuicErrorCount;
670
[email protected]c995c572013-01-18 05:43:20671struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
[email protected]14e8106c2013-03-14 16:25:33672 QuicPacketPublicHeader();
673 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
674 ~QuicPacketPublicHeader();
675
[email protected]3aa9ca72014-02-27 19:39:43676 // Universal header. All QuicPacket headers will have a connection_id and
677 // public flags.
678 QuicConnectionId connection_id;
679 QuicConnectionIdLength connection_id_length;
zhongyib8677022015-12-01 05:51:30680 bool multipath_flag;
[email protected]9db443912013-02-25 05:27:03681 bool reset_flag;
682 bool version_flag;
rtennetia004d332015-08-28 06:44:57683 QuicPacketNumberLength packet_number_length;
[email protected]48878092013-07-26 14:51:56684 QuicVersionVector versions;
[email protected]c995c572013-01-18 05:43:20685};
686
rtennetia004d332015-08-28 06:44:57687// An integer which cannot be a packet number.
688const QuicPacketNumber kInvalidPacketNumber = 0;
rtenneti9e0fb502015-03-08 06:07:16689
rjshaded069aaee2016-03-11 20:42:17690// Header for Data packets.
[email protected]74bda142013-03-31 02:49:11691struct NET_EXPORT_PRIVATE QuicPacketHeader {
692 QuicPacketHeader();
693 explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
vmpstracd23b72016-02-26 21:08:55694 QuicPacketHeader(const QuicPacketHeader& other);
[email protected]9db443912013-02-25 05:27:03695
rjshaded5ced072015-12-18 19:26:02696 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
697 const QuicPacketHeader& s);
[email protected]9db443912013-02-25 05:27:03698
[email protected]c995c572013-01-18 05:43:20699 QuicPacketPublicHeader public_header;
rtenneti8dd12b22015-10-21 01:26:38700 QuicPacketNumber packet_number;
fayanga64c1a92016-02-13 01:55:58701 QuicPathId path_id;
[email protected]9db443912013-02-25 05:27:03702 bool entropy_flag;
703 QuicPacketEntropyHash entropy_hash;
fayanga64c1a92016-02-13 01:55:58704 bool fec_flag;
[email protected]b064310782013-05-30 21:12:17705 InFecGroup is_in_fec_group;
[email protected]8b37a092012-10-18 21:53:49706 QuicFecGroupNumber fec_group;
707};
708
[email protected]74bda142013-03-31 02:49:11709struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
[email protected]6ae6e342014-02-06 02:21:42710 QuicPublicResetPacket();
711 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header);
712
[email protected]86a318d2013-01-23 21:16:04713 QuicPacketPublicHeader public_header;
[email protected]86a318d2013-01-23 21:16:04714 QuicPublicResetNonceProof nonce_proof;
rtennetia004d332015-08-28 06:44:57715 QuicPacketNumber rejected_packet_number;
[email protected]79d13dcb2014-02-05 07:23:13716 IPEndPoint client_address;
[email protected]86a318d2013-01-23 21:16:04717};
718
[email protected]14e8106c2013-03-14 16:25:33719enum QuicVersionNegotiationState {
720 START_NEGOTIATION = 0,
[email protected]ec640112013-08-09 03:56:18721 // Server-side this implies we've sent a version negotiation packet and are
722 // waiting on the client to select a compatible version. Client-side this
723 // implies we've gotten a version negotiation packet, are retransmitting the
724 // initial packets with a supported version and are waiting for our first
725 // packet from the server.
726 NEGOTIATION_IN_PROGRESS,
727 // This indicates this endpoint has received a packet from the peer with a
728 // version this endpoint supports. Version negotiation is complete, and the
729 // version number will no longer be sent with future packets.
[email protected]14e8106c2013-03-14 16:25:33730 NEGOTIATED_VERSION
731};
732
733typedef QuicPacketPublicHeader QuicVersionNegotiationPacket;
734
[email protected]c995c572013-01-18 05:43:20735// A padding frame contains no payload.
rtenneti5ca6eee2015-10-15 21:54:30736struct NET_EXPORT_PRIVATE QuicPaddingFrame {};
[email protected]c995c572013-01-18 05:43:20737
[email protected]d8c522112014-04-23 09:23:25738// A ping frame contains no payload, though it is retransmittable,
739// and ACK'd just like other normal frames.
rtenneti5ca6eee2015-10-15 21:54:30740struct NET_EXPORT_PRIVATE QuicPingFrame {};
[email protected]d8c522112014-04-23 09:23:25741
rtenneti69e64aa2015-06-26 04:25:30742// A path MTU discovery frame contains no payload and is serialized as a ping
743// frame.
744struct NET_EXPORT_PRIVATE QuicMtuDiscoveryFrame {};
745
jdorfman5a606722016-01-04 17:41:29746class NET_EXPORT_PRIVATE QuicBufferAllocator {
747 public:
748 virtual ~QuicBufferAllocator();
749
750 // Returns or allocates a new buffer of |size|. Never returns null.
751 virtual char* New(size_t size) = 0;
752
rcha00232242016-01-22 21:07:51753 // Returns or allocates a new buffer of |size| if |flag_enable| is true.
754 // Otherwise, returns a buffer that is compatible with this class directly
755 // with operator new. Never returns null.
756 virtual char* New(size_t size, bool flag_enable) = 0;
757
jdorfman5a606722016-01-04 17:41:29758 // Releases a buffer.
759 virtual void Delete(char* buffer) = 0;
rcha00232242016-01-22 21:07:51760
761 // Marks the allocator as being idle. Serves as a hint to notify the allocator
762 // that it should release any resources it's still holding on to.
763 virtual void MarkAllocatorIdle() {}
jdorfman5a606722016-01-04 17:41:29764};
765
766// Deleter for stream buffers. Copyable to support platforms where the deleter
767// of a unique_ptr must be copyable. Otherwise it would be nice for this to be
768// move-only.
zhongyi2f5f40c2015-12-08 02:13:02769class NET_EXPORT_PRIVATE StreamBufferDeleter {
770 public:
jdorfman5a606722016-01-04 17:41:29771 StreamBufferDeleter() : allocator_(nullptr) {}
772 explicit StreamBufferDeleter(QuicBufferAllocator* allocator)
773 : allocator_(allocator) {}
774
775 // Deletes |buffer| using |allocator_|.
776 void operator()(char* buffer) const;
777
778 private:
779 // Not owned; must be valid so long as the buffer stored in the unique_ptr
780 // that owns |this| is valid.
781 QuicBufferAllocator* allocator_;
zhongyi2f5f40c2015-12-08 02:13:02782};
783
784using UniqueStreamBuffer = std::unique_ptr<char[], StreamBufferDeleter>;
rtennetif60c32d82015-10-14 00:07:00785
jdorfman5a606722016-01-04 17:41:29786// Allocates memory of size |size| using |allocator| for a QUIC stream buffer.
787NET_EXPORT_PRIVATE UniqueStreamBuffer
788NewStreamBuffer(QuicBufferAllocator* allocator, size_t size);
rtennetif60c32d82015-10-14 00:07:00789
[email protected]be24ab22012-10-22 03:01:52790struct NET_EXPORT_PRIVATE QuicStreamFrame {
791 QuicStreamFrame();
[email protected]be24ab22012-10-22 03:01:52792 QuicStreamFrame(QuicStreamId stream_id,
[email protected]a5061242012-10-23 23:29:37793 bool fin,
[email protected]701bc892013-01-17 04:51:54794 QuicStreamOffset offset,
rtennetia4228ea2015-06-04 02:31:44795 base::StringPiece data);
zhongyi36727b82015-12-03 00:42:23796 QuicStreamFrame(QuicStreamId stream_id,
797 bool fin,
798 QuicStreamOffset offset,
jokulik2324d282015-12-08 21:42:57799 QuicPacketLength frame_length,
zhongyi36727b82015-12-03 00:42:23800 UniqueStreamBuffer buffer);
801 ~QuicStreamFrame();
[email protected]5dafdb62013-11-14 01:24:26802
rjshaded5ced072015-12-18 19:26:02803 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
804 const QuicStreamFrame& s);
[email protected]c5e1aca2014-01-30 04:03:04805
[email protected]8b37a092012-10-18 21:53:49806 QuicStreamId stream_id;
807 bool fin;
jokulik2324d282015-12-08 21:42:57808 QuicPacketLength frame_length;
809 const char* frame_buffer;
[email protected]701bc892013-01-17 04:51:54810 QuicStreamOffset offset; // Location of this data in the stream.
zhongyi36727b82015-12-03 00:42:23811 // nullptr when the QuicStreamFrame is received, and non-null when sent.
812 UniqueStreamBuffer buffer;
zhongyi4249f9b02015-12-02 20:26:30813
zhongyi36727b82015-12-03 00:42:23814 private:
jokulik2324d282015-12-08 21:42:57815 QuicStreamFrame(QuicStreamId stream_id,
816 bool fin,
817 QuicStreamOffset offset,
818 const char* frame_buffer,
819 QuicPacketLength frame_length,
820 UniqueStreamBuffer buffer);
821
zhongyi36727b82015-12-03 00:42:23822 DISALLOW_COPY_AND_ASSIGN(QuicStreamFrame);
823};
824static_assert(sizeof(QuicStreamFrame) <= 64,
825 "Keep the QuicStreamFrame size to a cacheline.");
[email protected]e537f742012-12-07 15:33:53826// TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
827// is finalized.
rtennetia004d332015-08-28 06:44:57828typedef std::set<QuicPacketNumber> PacketNumberSet;
829typedef std::list<QuicPacketNumber> PacketNumberList;
rtenneti4b06ae72014-08-26 03:43:43830
ckrasicea295fe2015-10-31 05:03:27831typedef std::vector<std::pair<QuicPacketNumber, QuicTime>> PacketTimeVector;
[email protected]044ac2b2012-11-13 21:41:06832
[email protected]310d37b2014-08-02 06:15:37833struct NET_EXPORT_PRIVATE QuicStopWaitingFrame {
834 QuicStopWaitingFrame();
835 ~QuicStopWaitingFrame();
[email protected]6ae6e342014-02-06 02:21:42836
[email protected]26f3f8e2012-12-13 21:07:19837 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:02838 std::ostream& os,
839 const QuicStopWaitingFrame& s);
jri3285d93a2015-12-14 08:53:19840 // Path which this stop waiting frame belongs to.
841 QuicPathId path_id;
[email protected]310d37b2014-08-02 06:15:37842 // Entropy hash of all packets up to, but not including, the least unacked
843 // packet.
844 QuicPacketEntropyHash entropy_hash;
845 // The lowest packet we've sent which is unacked, and we expect an ack for.
rtennetia004d332015-08-28 06:44:57846 QuicPacketNumber least_unacked;
[email protected]310d37b2014-08-02 06:15:37847};
848
rtenneti493d90ef2015-09-14 04:43:11849// A sequence of packet numbers where each number is unique. Intended to be used
850// in a sliding window fashion, where smaller old packet numbers are removed and
851// larger new packet numbers are added, with the occasional random access.
852class NET_EXPORT_PRIVATE PacketNumberQueue {
853 public:
rtenneti55a807c2016-02-05 03:05:54854 // TODO(jdorfman): remove const_iterator and change the callers to iterate
855 // over the intervals.
rtenneti4efd55dd2015-09-18 01:12:04856 class NET_EXPORT_PRIVATE const_iterator
857 : public std::iterator<std::input_iterator_tag,
858 QuicPacketNumber,
859 std::ptrdiff_t,
860 const QuicPacketNumber*,
861 const QuicPacketNumber&> {
862 public:
863 explicit const_iterator(PacketNumberSet::const_iterator set_iter);
864 const_iterator(
865 IntervalSet<QuicPacketNumber>::const_iterator interval_set_iter,
866 QuicPacketNumber first,
867 QuicPacketNumber last);
868 const_iterator(const const_iterator& other);
869 const_iterator& operator=(const const_iterator& other);
870 // TODO(rtenneti): on windows RValue reference gives errors.
871 // const_iterator(const_iterator&& other);
872 ~const_iterator();
873
874 // TODO(rtenneti): on windows RValue reference gives errors.
875 // const_iterator& operator=(const_iterator&& other);
876 bool operator!=(const const_iterator& other) const;
877 bool operator==(const const_iterator& other) const;
878 value_type operator*() const;
879 const_iterator& operator++();
880 const_iterator operator++(int /* postincrement */);
881
882 private:
rtenneti4efd55dd2015-09-18 01:12:04883 IntervalSet<QuicPacketNumber>::const_iterator interval_set_iter_;
884 QuicPacketNumber current_;
885 QuicPacketNumber last_;
886 };
887
rtenneti493d90ef2015-09-14 04:43:11888 PacketNumberQueue();
rtenneti4efd55dd2015-09-18 01:12:04889 PacketNumberQueue(const PacketNumberQueue& other);
rtenneti4efd55dd2015-09-18 01:12:04890 // TODO(rtenneti): on windows RValue reference gives errors.
891 // PacketNumberQueue(PacketNumberQueue&& other);
rtenneti93209a02015-09-19 01:51:18892 ~PacketNumberQueue();
893
894 PacketNumberQueue& operator=(const PacketNumberQueue& other);
rtenneti4efd55dd2015-09-18 01:12:04895 // PacketNumberQueue& operator=(PacketNumberQueue&& other);
rtenneti493d90ef2015-09-14 04:43:11896
897 // Adds |packet_number| to the set of packets in the queue.
898 void Add(QuicPacketNumber packet_number);
899
rtenneti4efd55dd2015-09-18 01:12:04900 // Adds packets between [lower, higher) to the set of packets in the queue. It
901 // is undefined behavior to call this with |higher| < |lower|.
rtenneti493d90ef2015-09-14 04:43:11902 void Add(QuicPacketNumber lower, QuicPacketNumber higher);
903
904 // Removes |packet_number| from the set of packets in the queue.
905 void Remove(QuicPacketNumber packet_number);
906
907 // Removes packets with values less than |higher| from the set of packets in
908 // the queue. Returns true if packets were removed.
909 bool RemoveUpTo(QuicPacketNumber higher);
910
911 // Returns true if the queue contains |packet_number|.
912 bool Contains(QuicPacketNumber packet_number) const;
913
914 // Returns true if the queue is empty.
915 bool Empty() const;
916
917 // Returns the minimum packet number stored in the queue. It is undefined
918 // behavior to call this if the queue is empty.
919 QuicPacketNumber Min() const;
920
921 // Returns the maximum packet number stored in the queue. It is undefined
922 // behavior to call this if the queue is empty.
923 QuicPacketNumber Max() const;
924
rtenneti4efd55dd2015-09-18 01:12:04925 // Returns the number of unique packets stored in the queue. Inefficient; only
926 // exposed for testing.
927 size_t NumPacketsSlow() const;
rtenneti493d90ef2015-09-14 04:43:11928
rtenneti4efd55dd2015-09-18 01:12:04929 // Returns iterators over the individual packet numbers.
930 const_iterator begin() const;
931 const_iterator end() const;
rtenneti493d90ef2015-09-14 04:43:11932 const_iterator lower_bound(QuicPacketNumber packet_number) const;
rtenneti493d90ef2015-09-14 04:43:11933
934 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
935 std::ostream& os,
936 const PacketNumberQueue& q);
937
938 private:
rtenneti4efd55dd2015-09-18 01:12:04939 IntervalSet<QuicPacketNumber> packet_number_intervals_;
rtenneti493d90ef2015-09-14 04:43:11940};
941
[email protected]310d37b2014-08-02 06:15:37942struct NET_EXPORT_PRIVATE QuicAckFrame {
943 QuicAckFrame();
vmpstracd23b72016-02-26 21:08:55944 QuicAckFrame(const QuicAckFrame& other);
[email protected]310d37b2014-08-02 06:15:37945 ~QuicAckFrame();
946
rjshaded5ced072015-12-18 19:26:02947 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
948 const QuicAckFrame& s);
[email protected]a674b4c2012-12-05 03:44:30949
jri3285d93a2015-12-14 08:53:19950 // Path which this ack belongs to.
951 QuicPathId path_id;
952
[email protected]9db443912013-02-25 05:27:03953 // Entropy hash of all packets up to largest observed not including missing
954 // packets.
955 QuicPacketEntropyHash entropy_hash;
[email protected]e537f742012-12-07 15:33:53956
ckrasicea295fe2015-10-31 05:03:27957 // Whether the ack had to be truncated when sent.
958 bool is_truncated;
959
rtennetia004d332015-08-28 06:44:57960 // The highest packet number we've observed from the peer.
[email protected]48697d8a2013-01-15 19:42:24961 //
962 // In general, this should be the largest packet number we've received. In
963 // the case of truncated acks, we may have to advertise a lower "upper bound"
964 // than largest received, to avoid implicitly acking missing packets that
965 // don't fit in the missing packet list due to size limitations. In this
966 // case, largest_observed may be a packet which is also in the missing packets
967 // list.
rtennetia004d332015-08-28 06:44:57968 QuicPacketNumber largest_observed;
[email protected]a674b4c2012-12-05 03:44:30969
[email protected]14e8106c2013-03-14 16:25:33970 // Time elapsed since largest_observed was received until this Ack frame was
971 // sent.
rchcaec4242016-01-22 20:49:52972 QuicTime::Delta ack_delay_time;
[email protected]14e8106c2013-03-14 16:25:33973
ckrasicea295fe2015-10-31 05:03:27974 // Vector of <packet_number, time> for when packets arrived.
975 PacketTimeVector received_packet_times;
976
[email protected]e537f742012-12-07 15:33:53977 // The set of packets which we're expecting and have not received.
rtenneti493d90ef2015-09-14 04:43:11978 PacketNumberQueue missing_packets;
[email protected]8b37a092012-10-18 21:53:49979};
980
rtennetia004d332015-08-28 06:44:57981// True if the packet number is greater than largest_observed or is listed
[email protected]9db443912013-02-25 05:27:03982// as missing.
rtennetia004d332015-08-28 06:44:57983// Always returns false for packet numbers less than least_unacked.
984bool NET_EXPORT_PRIVATE IsAwaitingPacket(const QuicAckFrame& ack_frame,
985 QuicPacketNumber packet_number);
[email protected]9db443912013-02-25 05:27:03986
[email protected]a692ad9d2014-07-18 21:35:24987// Defines for all types of congestion control algorithms that can be used in
988// QUIC. Note that this is separate from the congestion feedback type -
989// some congestion control algorithms may use the same feedback type
990// (Reno and Cubic are the classic example for that).
991enum CongestionControlType {
992 kCubic,
rtennetifb3fa6c2015-03-16 23:04:55993 kCubicBytes,
[email protected]a692ad9d2014-07-18 21:35:24994 kReno,
rtennetifb3fa6c2015-03-16 23:04:55995 kRenoBytes,
[email protected]a692ad9d2014-07-18 21:35:24996 kBBR,
[email protected]8b37a092012-10-18 21:53:49997};
998
[email protected]c5cc9bd2014-03-31 23:17:14999enum LossDetectionType {
1000 kNack, // Used to mimic TCP's loss detection.
1001 kTime, // Time based loss detection.
1002};
1003
[email protected]be24ab22012-10-22 03:01:521004struct NET_EXPORT_PRIVATE QuicRstStreamFrame {
[email protected]6ae6e342014-02-06 02:21:421005 QuicRstStreamFrame();
1006 QuicRstStreamFrame(QuicStreamId stream_id,
1007 QuicRstStreamErrorCode error_code,
1008 QuicStreamOffset bytes_written);
[email protected]8b37a092012-10-18 21:53:491009
[email protected]c5e1aca2014-01-30 04:03:041010 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:021011 std::ostream& os,
1012 const QuicRstStreamFrame& r);
[email protected]c5e1aca2014-01-30 04:03:041013
[email protected]8b37a092012-10-18 21:53:491014 QuicStreamId stream_id;
[email protected]74bda142013-03-31 02:49:111015 QuicRstStreamErrorCode error_code;
[email protected]6ae6e342014-02-06 02:21:421016
1017 // Used to update flow control windows. On termination of a stream, both
1018 // endpoints must inform the peer of the number of bytes they have sent on
1019 // that stream. This can be done through normal termination (data packet with
1020 // FIN) or through a RST.
1021 QuicStreamOffset byte_offset;
[email protected]8b37a092012-10-18 21:53:491022};
1023
[email protected]be24ab22012-10-22 03:01:521024struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame {
[email protected]6ae6e342014-02-06 02:21:421025 QuicConnectionCloseFrame();
1026
[email protected]c5e1aca2014-01-30 04:03:041027 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:021028 std::ostream& os,
1029 const QuicConnectionCloseFrame& c);
[email protected]c5e1aca2014-01-30 04:03:041030
[email protected]431bb4fd2012-10-19 17:46:091031 QuicErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:091032 std::string error_details;
[email protected]8b37a092012-10-18 21:53:491033};
1034
[email protected]9db443912013-02-25 05:27:031035struct NET_EXPORT_PRIVATE QuicGoAwayFrame {
[email protected]6ae6e342014-02-06 02:21:421036 QuicGoAwayFrame();
[email protected]9db443912013-02-25 05:27:031037 QuicGoAwayFrame(QuicErrorCode error_code,
1038 QuicStreamId last_good_stream_id,
1039 const std::string& reason);
1040
rjshaded5ced072015-12-18 19:26:021041 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
1042 const QuicGoAwayFrame& g);
[email protected]c5e1aca2014-01-30 04:03:041043
[email protected]9db443912013-02-25 05:27:031044 QuicErrorCode error_code;
1045 QuicStreamId last_good_stream_id;
1046 std::string reason_phrase;
1047};
1048
[email protected]6ae6e342014-02-06 02:21:421049// Flow control updates per-stream and at the connection levoel.
1050// Based on SPDY's WINDOW_UPDATE frame, but uses an absolute byte offset rather
1051// than a window delta.
1052// TODO(rjshade): A possible future optimization is to make stream_id and
1053// byte_offset variable length, similar to stream frames.
1054struct NET_EXPORT_PRIVATE QuicWindowUpdateFrame {
1055 QuicWindowUpdateFrame() {}
1056 QuicWindowUpdateFrame(QuicStreamId stream_id, QuicStreamOffset byte_offset);
1057
1058 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:021059 std::ostream& os,
1060 const QuicWindowUpdateFrame& w);
[email protected]6ae6e342014-02-06 02:21:421061
1062 // The stream this frame applies to. 0 is a special case meaning the overall
1063 // connection rather than a specific stream.
1064 QuicStreamId stream_id;
1065
1066 // Byte offset in the stream or connection. The receiver of this frame must
1067 // not send data which would result in this offset being exceeded.
1068 QuicStreamOffset byte_offset;
1069};
1070
1071// The BLOCKED frame is used to indicate to the remote endpoint that this
1072// endpoint believes itself to be flow-control blocked but otherwise ready to
1073// send data. The BLOCKED frame is purely advisory and optional.
1074// Based on SPDY's BLOCKED frame (undocumented as of 2014-01-28).
1075struct NET_EXPORT_PRIVATE QuicBlockedFrame {
1076 QuicBlockedFrame() {}
1077 explicit QuicBlockedFrame(QuicStreamId stream_id);
1078
rjshaded5ced072015-12-18 19:26:021079 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
1080 const QuicBlockedFrame& b);
[email protected]6ae6e342014-02-06 02:21:421081
1082 // The stream this frame applies to. 0 is a special case meaning the overall
1083 // connection rather than a specific stream.
1084 QuicStreamId stream_id;
1085};
1086
rchcaec4242016-01-22 20:49:521087// The PATH_CLOSE frame is used to explicitly close a path. Both endpoints can
1088// send a PATH_CLOSE frame to initiate a path termination. A path is considered
1089// to be closed either a PATH_CLOSE frame is sent or received. An endpoint drops
1090// receive side of a closed path, and packets with retransmittable frames on a
1091// closed path are marked as retransmissions which will be transmitted on other
1092// paths.
1093struct NET_EXPORT_PRIVATE QuicPathCloseFrame {
1094 QuicPathCloseFrame() {}
1095 explicit QuicPathCloseFrame(QuicPathId path_id);
1096
1097 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
1098 std::ostream& os,
1099 const QuicPathCloseFrame& p);
1100
1101 QuicPathId path_id;
1102};
1103
[email protected]8ba81212013-05-03 13:11:481104// EncryptionLevel enumerates the stages of encryption that a QUIC connection
1105// progresses through. When retransmitting a packet, the encryption level needs
1106// to be specified so that it is retransmitted at a level which the peer can
1107// understand.
fayanga64c1a92016-02-13 01:55:581108enum EncryptionLevel : int8_t {
[email protected]8ba81212013-05-03 13:11:481109 ENCRYPTION_NONE = 0,
1110 ENCRYPTION_INITIAL = 1,
1111 ENCRYPTION_FORWARD_SECURE = 2,
1112
1113 NUM_ENCRYPTION_LEVELS,
1114};
1115
rch99b644c2015-11-04 05:25:281116enum PeerAddressChangeType {
jric533399b2016-01-29 07:36:011117 // IP address and port remain unchanged.
rch99b644c2015-11-04 05:25:281118 NO_CHANGE,
jric533399b2016-01-29 07:36:011119 // Port changed, but IP address remains unchanged.
1120 PORT_CHANGE,
1121 // IPv4 address changed, but within the /24 subnet (port may have changed.)
1122 IPV4_SUBNET_CHANGE,
1123 // IP address change from an IPv4 to an IPv6 address (port may have changed.)
1124 IPV4_TO_IPV6_CHANGE,
1125 // IP address change from an IPv6 to an IPv4 address (port may have changed.)
1126 IPV6_TO_IPV4_CHANGE,
1127 // IP address change from an IPv6 to an IPv6 address (port may have changed.)
1128 IPV6_TO_IPV6_CHANGE,
1129 // All other peer address changes.
1130 UNSPECIFIED_CHANGE,
rch99b644c2015-11-04 05:25:281131};
1132
[email protected]be24ab22012-10-22 03:01:521133struct NET_EXPORT_PRIVATE QuicFrame {
[email protected]6ae6e342014-02-06 02:21:421134 QuicFrame();
rtenneti5ca6eee2015-10-15 21:54:301135 explicit QuicFrame(QuicPaddingFrame padding_frame);
1136 explicit QuicFrame(QuicMtuDiscoveryFrame frame);
1137 explicit QuicFrame(QuicPingFrame frame);
1138
[email protected]6ae6e342014-02-06 02:21:421139 explicit QuicFrame(QuicStreamFrame* stream_frame);
1140 explicit QuicFrame(QuicAckFrame* frame);
[email protected]6ae6e342014-02-06 02:21:421141 explicit QuicFrame(QuicRstStreamFrame* frame);
1142 explicit QuicFrame(QuicConnectionCloseFrame* frame);
[email protected]93dd91f2014-02-27 00:09:031143 explicit QuicFrame(QuicStopWaitingFrame* frame);
[email protected]6ae6e342014-02-06 02:21:421144 explicit QuicFrame(QuicGoAwayFrame* frame);
1145 explicit QuicFrame(QuicWindowUpdateFrame* frame);
1146 explicit QuicFrame(QuicBlockedFrame* frame);
rchcaec4242016-01-22 20:49:521147 explicit QuicFrame(QuicPathCloseFrame* frame);
[email protected]8b37a092012-10-18 21:53:491148
rjshaded5ced072015-12-18 19:26:021149 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
1150 const QuicFrame& frame);
[email protected]c5e1aca2014-01-30 04:03:041151
[email protected]be24ab22012-10-22 03:01:521152 QuicFrameType type;
[email protected]8b37a092012-10-18 21:53:491153 union {
rtenneti5ca6eee2015-10-15 21:54:301154 // Frames smaller than a pointer are inline.
1155 QuicPaddingFrame padding_frame;
1156 QuicMtuDiscoveryFrame mtu_discovery_frame;
1157 QuicPingFrame ping_frame;
1158
1159 // Frames larger than a pointer.
[email protected]be24ab22012-10-22 03:01:521160 QuicStreamFrame* stream_frame;
1161 QuicAckFrame* ack_frame;
[email protected]93dd91f2014-02-27 00:09:031162 QuicStopWaitingFrame* stop_waiting_frame;
[email protected]be24ab22012-10-22 03:01:521163 QuicRstStreamFrame* rst_stream_frame;
1164 QuicConnectionCloseFrame* connection_close_frame;
[email protected]9db443912013-02-25 05:27:031165 QuicGoAwayFrame* goaway_frame;
[email protected]6ae6e342014-02-06 02:21:421166 QuicWindowUpdateFrame* window_update_frame;
1167 QuicBlockedFrame* blocked_frame;
rchcaec4242016-01-22 20:49:521168 QuicPathCloseFrame* path_close_frame;
[email protected]8b37a092012-10-18 21:53:491169 };
1170};
rtenneti5ca6eee2015-10-15 21:54:301171// QuicFrameType consumes 8 bytes with padding.
1172static_assert(sizeof(QuicFrame) <= 16,
1173 "Frames larger than 8 bytes should be referenced by pointer.");
[email protected]8b37a092012-10-18 21:53:491174
[email protected]be24ab22012-10-22 03:01:521175typedef std::vector<QuicFrame> QuicFrames;
[email protected]8b37a092012-10-18 21:53:491176
[email protected]8b37a092012-10-18 21:53:491177class NET_EXPORT_PRIVATE QuicData {
1178 public:
[email protected]6ae6e342014-02-06 02:21:421179 QuicData(const char* buffer, size_t length);
1180 QuicData(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:491181 virtual ~QuicData();
1182
1183 base::StringPiece AsStringPiece() const {
1184 return base::StringPiece(data(), length());
1185 }
1186
1187 const char* data() const { return buffer_; }
1188 size_t length() const { return length_; }
rtennetie0ee6eb2015-05-01 00:55:091189 bool owns_buffer() const { return owns_buffer_; }
[email protected]8b37a092012-10-18 21:53:491190
1191 private:
1192 const char* buffer_;
1193 size_t length_;
1194 bool owns_buffer_;
1195
1196 DISALLOW_COPY_AND_ASSIGN(QuicData);
1197};
1198
1199class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
1200 public:
rchcaec4242016-01-22 20:49:521201 // TODO(fayang): 4 fields from public header are passed in as arguments.
1202 // Consider to add a convenience method which directly accepts the entire
1203 // public header.
rtennetica5ac272015-02-07 12:35:121204 QuicPacket(char* buffer,
1205 size_t length,
1206 bool owns_buffer,
1207 QuicConnectionIdLength connection_id_length,
1208 bool includes_version,
rchcaec4242016-01-22 20:49:521209 bool includes_path_id,
rtennetia004d332015-08-28 06:44:571210 QuicPacketNumberLength packet_number_length);
[email protected]8b37a092012-10-18 21:53:491211
[email protected]5351cc4b2013-03-03 07:22:411212 base::StringPiece AssociatedData() const;
[email protected]5351cc4b2013-03-03 07:22:411213 base::StringPiece Plaintext() const;
[email protected]082b65b2012-11-10 19:11:311214
[email protected]8b37a092012-10-18 21:53:491215 char* mutable_data() { return buffer_; }
1216
1217 private:
1218 char* buffer_;
[email protected]3aa9ca72014-02-27 19:39:431219 const QuicConnectionIdLength connection_id_length_;
[email protected]5351cc4b2013-03-03 07:22:411220 const bool includes_version_;
rchcaec4242016-01-22 20:49:521221 const bool includes_path_id_;
rtennetia004d332015-08-28 06:44:571222 const QuicPacketNumberLength packet_number_length_;
[email protected]8b37a092012-10-18 21:53:491223
[email protected]2e740db2012-10-20 19:35:191224 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
[email protected]8b37a092012-10-18 21:53:491225};
1226
1227class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
1228 public:
[email protected]6ae6e342014-02-06 02:21:421229 QuicEncryptedPacket(const char* buffer, size_t length);
1230 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:491231
[email protected]ec86d5462013-11-17 16:04:491232 // Clones the packet into a new packet which owns the buffer.
1233 QuicEncryptedPacket* Clone() const;
1234
[email protected]c1b32c62013-01-20 02:49:101235 // By default, gtest prints the raw bytes of an object. The bool data
1236 // member (in the base class QuicData) causes this object to have padding
1237 // bytes, which causes the default gtest object printer to read
1238 // uninitialize memory. So we need to teach gtest how to print this object.
1239 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:021240 std::ostream& os,
1241 const QuicEncryptedPacket& s);
[email protected]c1b32c62013-01-20 02:49:101242
[email protected]2e740db2012-10-20 19:35:191243 private:
1244 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
[email protected]8b37a092012-10-18 21:53:491245};
1246
jric533399b2016-01-29 07:36:011247// Pure virtual class to listen for packet acknowledgements.
1248class NET_EXPORT_PRIVATE QuicAckListenerInterface
1249 : public base::RefCounted<QuicAckListenerInterface> {
[email protected]9db443912013-02-25 05:27:031250 public:
jric533399b2016-01-29 07:36:011251 QuicAckListenerInterface() {}
[email protected]9db443912013-02-25 05:27:031252
jric533399b2016-01-29 07:36:011253 // Called when a packet is acked. Called once per packet.
1254 // |acked_bytes| is the number of data bytes acked.
1255 virtual void OnPacketAcked(int acked_bytes,
1256 QuicTime::Delta ack_delay_time) = 0;
rtenneti73e25c12015-03-16 06:12:431257
jric533399b2016-01-29 07:36:011258 // Called when a packet is retransmitted. Called once per packet.
1259 // |retransmitted_bytes| is the number of data bytes retransmitted.
1260 virtual void OnPacketRetransmitted(int retransmitted_bytes) = 0;
[email protected]9db443912013-02-25 05:27:031261
jric533399b2016-01-29 07:36:011262 protected:
1263 friend class base::RefCounted<QuicAckListenerInterface>;
[email protected]2115d33ba2014-01-02 21:53:521264
jric533399b2016-01-29 07:36:011265 // Delegates are ref counted.
1266 virtual ~QuicAckListenerInterface() {}
[email protected]9db443912013-02-25 05:27:031267};
1268
rtenneti8dd12b22015-10-21 01:26:381269struct NET_EXPORT_PRIVATE AckListenerWrapper {
1270 AckListenerWrapper(QuicAckListenerInterface* listener,
1271 QuicPacketLength data_length);
vmpstracd23b72016-02-26 21:08:551272 AckListenerWrapper(const AckListenerWrapper& other);
rtenneti8dd12b22015-10-21 01:26:381273 ~AckListenerWrapper();
1274
1275 scoped_refptr<QuicAckListenerInterface> ack_listener;
1276 QuicPacketLength length;
1277};
1278
[email protected]9db443912013-02-25 05:27:031279struct NET_EXPORT_PRIVATE SerializedPacket {
fayanga31a74b2015-12-28 17:27:141280 SerializedPacket(QuicPathId path_id,
1281 QuicPacketNumber packet_number,
rtennetia004d332015-08-28 06:44:571282 QuicPacketNumberLength packet_number_length,
rtenneti2cae2072016-02-05 02:21:331283 const char* encrypted_buffer,
1284 QuicPacketLength encrypted_length,
[email protected]9db443912013-02-25 05:27:031285 QuicPacketEntropyHash entropy_hash,
rtenneti9bd5d4b2015-08-21 05:44:521286 bool has_ack,
1287 bool has_stop_waiting);
vmpstracd23b72016-02-26 21:08:551288 SerializedPacket(const SerializedPacket& other);
[email protected]97cf3022013-09-05 14:30:161289 ~SerializedPacket();
[email protected]9db443912013-02-25 05:27:031290
rtenneti2cae2072016-02-05 02:21:331291 // Not owned.
1292 const char* encrypted_buffer;
1293 QuicPacketLength encrypted_length;
rtennetif85706db2016-02-04 02:43:031294 QuicFrames retransmittable_frames;
jric533399b2016-01-29 07:36:011295 IsHandshake has_crypto_handshake;
1296 bool needs_padding;
fayanga31a74b2015-12-28 17:27:141297 QuicPathId path_id;
rtennetia004d332015-08-28 06:44:571298 QuicPacketNumber packet_number;
1299 QuicPacketNumberLength packet_number_length;
jokulik2324d282015-12-08 21:42:571300 EncryptionLevel encryption_level;
[email protected]9db443912013-02-25 05:27:031301 QuicPacketEntropyHash entropy_hash;
rtenneti9bd5d4b2015-08-21 05:44:521302 bool has_ack;
1303 bool has_stop_waiting;
zhongyi4a9d27b2016-01-12 20:08:311304 QuicPacketNumber original_packet_number;
1305 TransmissionType transmission_type;
[email protected]97cf3022013-09-05 14:30:161306
rtenneti6b1c5b12015-01-13 20:08:351307 // Optional notifiers which will be informed when this packet has been ACKed.
rtenneti8dd12b22015-10-21 01:26:381308 std::list<AckListenerWrapper> listeners;
[email protected]9db443912013-02-25 05:27:031309};
1310
[email protected]77b5d50b2014-05-07 22:48:481311struct NET_EXPORT_PRIVATE TransmissionInfo {
1312 // Used by STL when assigning into a map.
1313 TransmissionInfo();
1314
rchcaec4242016-01-22 20:49:521315 // Constructs a Transmission with a new all_transmissions set
rtennetia004d332015-08-28 06:44:571316 // containing |packet_number|.
rchcaec4242016-01-22 20:49:521317 TransmissionInfo(EncryptionLevel level,
rtennetia004d332015-08-28 06:44:571318 QuicPacketNumberLength packet_number_length,
[email protected]730b35d72014-06-05 03:23:221319 TransmissionType transmission_type,
rtenneti3183ac42015-02-28 03:39:411320 QuicTime sent_time,
rtenneti5ca6eee2015-10-15 21:54:301321 QuicPacketLength bytes_sent,
rchcaec4242016-01-22 20:49:521322 bool has_crypto_handshake,
1323 bool needs_padding);
[email protected]77b5d50b2014-05-07 22:48:481324
vmpstracd23b72016-02-26 21:08:551325 TransmissionInfo(const TransmissionInfo& other);
1326
rtenneti8dd12b22015-10-21 01:26:381327 ~TransmissionInfo();
1328
rchcaec4242016-01-22 20:49:521329 QuicFrames retransmittable_frames;
jokulik2324d282015-12-08 21:42:571330 EncryptionLevel encryption_level;
rtennetia004d332015-08-28 06:44:571331 QuicPacketNumberLength packet_number_length;
rtenneti5ca6eee2015-10-15 21:54:301332 QuicPacketLength bytes_sent;
Avi Drissman13fc8932015-12-20 04:40:461333 uint16_t nack_count;
[email protected]77b5d50b2014-05-07 22:48:481334 QuicTime sent_time;
[email protected]730b35d72014-06-05 03:23:221335 // Reason why this packet was transmitted.
1336 TransmissionType transmission_type;
[email protected]aa7e4ef2014-05-28 03:53:151337 // In flight packets have not been abandoned or lost.
1338 bool in_flight;
rtenneti31e9fd62014-09-16 05:22:151339 // True if the packet can never be acked, so it can be removed.
1340 bool is_unackable;
rchcaec4242016-01-22 20:49:521341 // True if the packet contains stream data from the crypto stream.
1342 bool has_crypto_handshake;
1343 // True if the packet needs padding if it's retransmitted.
1344 bool needs_padding;
zhongyi1fb9bc52015-11-24 23:09:421345 // Stores the packet number of the next retransmission of this packet.
1346 // Zero if the packet has not been retransmitted.
1347 QuicPacketNumber retransmission;
rtenneti8dd12b22015-10-21 01:26:381348 // Non-empty if there is a listener for this packet.
1349 std::list<AckListenerWrapper> ack_listeners;
[email protected]77b5d50b2014-05-07 22:48:481350};
fayanga64c1a92016-02-13 01:55:581351static_assert(sizeof(TransmissionInfo) <= 128,
1352 "TODO(ianswett): Keep the TransmissionInfo size to a cacheline.");
[email protected]77b5d50b2014-05-07 22:48:481353
rchcaec4242016-01-22 20:49:521354// Struct to store the pending retransmission information.
1355struct PendingRetransmission {
1356 PendingRetransmission(QuicPathId path_id,
1357 QuicPacketNumber packet_number,
1358 TransmissionType transmission_type,
1359 const QuicFrames& retransmittable_frames,
1360 bool has_crypto_handshake,
1361 bool needs_padding,
1362 EncryptionLevel encryption_level,
1363 QuicPacketNumberLength packet_number_length)
fayanga64c1a92016-02-13 01:55:581364 : packet_number(packet_number),
rchcaec4242016-01-22 20:49:521365 retransmittable_frames(retransmittable_frames),
fayanga64c1a92016-02-13 01:55:581366 transmission_type(transmission_type),
1367 path_id(path_id),
rchcaec4242016-01-22 20:49:521368 has_crypto_handshake(has_crypto_handshake),
1369 needs_padding(needs_padding),
1370 encryption_level(encryption_level),
1371 packet_number_length(packet_number_length) {}
1372
rchcaec4242016-01-22 20:49:521373 QuicPacketNumber packet_number;
rchcaec4242016-01-22 20:49:521374 const QuicFrames& retransmittable_frames;
fayanga64c1a92016-02-13 01:55:581375 TransmissionType transmission_type;
1376 QuicPathId path_id;
rchcaec4242016-01-22 20:49:521377 bool has_crypto_handshake;
1378 bool needs_padding;
1379 EncryptionLevel encryption_level;
1380 QuicPacketNumberLength packet_number_length;
1381};
1382
rtennetic14c8ab2015-06-18 05:47:401383// Convenience wrapper to wrap an iovec array and the total length, which must
1384// be less than or equal to the actual total length of the iovecs.
1385struct NET_EXPORT_PRIVATE QuicIOVector {
1386 QuicIOVector(const struct iovec* iov, int iov_count, size_t total_length)
1387 : iov(iov), iov_count(iov_count), total_length(total_length) {}
1388
1389 const struct iovec* iov;
1390 const int iov_count;
1391 const size_t total_length;
1392};
1393
[email protected]8b37a092012-10-18 21:53:491394} // namespace net
1395
1396#endif // NET_QUIC_QUIC_PROTOCOL_H_