blob: 008be2b740efeb52138b8ea7dfbabbb1c2f9bd47 [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"
rtenneti8dd12b22015-10-21 01:26:3831#include "net/quic/quic_ack_listener_interface.h"
[email protected]fee17f72013-02-03 07:47:4132#include "net/quic/quic_bandwidth.h"
[email protected]2a960e02012-11-11 14:48:1033#include "net/quic/quic_time.h"
rtennetic14c8ab2015-06-18 05:47:4034#include "net/quic/quic_types.h"
[email protected]8b37a092012-10-18 21:53:4935
36namespace net {
37
[email protected]8b37a092012-10-18 21:53:4938class QuicPacket;
[email protected]b064310782013-05-30 21:12:1739struct QuicPacketHeader;
jokulikc971baf92016-01-06 00:36:3940class QuicAckListenerInterface;
[email protected]8b37a092012-10-18 21:53:4941
Avi Drissman13fc8932015-12-20 04:40:4642typedef uint64_t QuicConnectionId;
43typedef uint32_t QuicStreamId;
44typedef uint64_t QuicStreamOffset;
45typedef uint64_t QuicPacketNumber;
46typedef uint8_t QuicPathId;
rtennetia004d332015-08-28 06:44:5747typedef QuicPacketNumber QuicFecGroupNumber;
Avi Drissman13fc8932015-12-20 04:40:4648typedef uint64_t QuicPublicResetNonceProof;
49typedef uint8_t QuicPacketEntropyHash;
50typedef uint32_t QuicHeaderId;
[email protected]2532de12013-05-09 12:29:3351// QuicTag is the type of a tag in the wire protocol.
Avi Drissman13fc8932015-12-20 04:40:4652typedef uint32_t QuicTag;
[email protected]2532de12013-05-09 12:29:3353typedef std::vector<QuicTag> QuicTagVector;
[email protected]79d13dcb2014-02-05 07:23:1354typedef std::map<QuicTag, std::string> QuicTagValueMap;
Avi Drissman13fc8932015-12-20 04:40:4655typedef uint16_t QuicPacketLength;
[email protected]cff7b7b2013-01-11 08:49:0756
rtennetibb2780c2015-07-22 19:16:0857// Default initial maximum size in bytes of a QUIC packet.
[email protected]310d37b2014-08-02 06:15:3758const QuicByteCount kDefaultMaxPacketSize = 1350;
rtenneti16a20772015-02-17 18:58:4859// Default initial maximum size in bytes of a QUIC packet for servers.
60const QuicByteCount kDefaultServerMaxPacketSize = 1000;
[email protected]8e01c062013-10-31 07:35:3161// The maximum packet size of any QUIC packet, based on ethernet's max size,
fayanga31a74b2015-12-28 17:27:1462// minus the IP and UDP headers. IPv6 has a 40 byte header, UDP adds an
[email protected]41fb6372013-12-10 05:26:4063// additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's
64// max packet size is 1500 bytes, 1500 - 48 = 1452.
65const QuicByteCount kMaxPacketSize = 1452;
rtenneti9e0fb502015-03-08 06:07:1666// Default maximum packet size used in the Linux TCP implementation.
67// Used in QUIC for congestion window computations in bytes.
[email protected]ce7bb1412014-05-17 15:51:3368const QuicByteCount kDefaultTCPMSS = 1460;
[email protected]8e01c062013-10-31 07:35:3169
rch1fe2eeb2015-10-26 14:45:5770// We match SPDY's use of 32 (since we'd compete with SPDY).
71const QuicPacketCount kInitialCongestionWindow = 32;
[email protected]8e01c062013-10-31 07:35:3172
rtenneti7652bf32015-01-05 18:51:0773// Minimum size of initial flow control window, for both stream and session.
Avi Drissman13fc8932015-12-20 04:40:4674const uint32_t kMinimumFlowControlSendWindow = 16 * 1024; // 16 KB
[email protected]9bb57c72014-03-31 20:36:0475
rjshadec86dbfa2015-11-12 20:16:2576// Maximum flow control receive window limits for connection and stream.
77const QuicByteCount kStreamReceiveWindowLimit = 16 * 1024 * 1024; // 16 MB
78const QuicByteCount kSessionReceiveWindowLimit = 24 * 1024 * 1024; // 24 MB
79
rtennetifb3fa6c2015-03-16 23:04:5580// Minimum size of the CWND, in packets, when doing bandwidth resumption.
rtenneti8d2a808d2014-11-26 01:10:0981const QuicPacketCount kMinCongestionWindowForBandwidthResumption = 10;
82
rtenneti581b6ae82015-07-20 20:48:0183// Maximum size of the CWND, in packets.
84const QuicPacketCount kMaxCongestionWindow = 200;
rtenneti69e64aa2015-06-26 04:25:3085
86// Maximum number of tracked packets.
87const QuicPacketCount kMaxTrackedPackets = 5000;
[email protected]0ac0c5b2013-11-20 05:55:5888
rtenneti23186682014-10-30 01:49:3389// Default size of the socket receive buffer in bytes.
[email protected]648f81142014-08-15 21:38:4690const QuicByteCount kDefaultSocketReceiveBuffer = 256 * 1024;
rtenneti23186682014-10-30 01:49:3391// Minimum size of the socket receive buffer in bytes.
92// Smaller values are ignored.
93const QuicByteCount kMinSocketReceiveBuffer = 16 * 1024;
[email protected]a97b3182014-08-08 08:10:1894
rtenneti95293802015-03-27 18:59:2395// Fraction of the receive buffer that can be used for encrypted bytes.
96// Allows a 5% overhead for IP and UDP framing, as well as ack only packets.
97static const float kUsableRecieveBufferFraction = 0.95f;
rtenneti581b6ae82015-07-20 20:48:0198// Fraction of the receive buffer that can be used, based on conservative
99// estimates and testing on Linux.
100// An alternative to kUsableRecieveBufferFraction.
101static const float kConservativeReceiveBufferFraction = 0.6f;
rtenneti95293802015-03-27 18:59:23102
rtennetifc97ab62014-11-11 22:17:49103// Don't allow a client to suggest an RTT shorter than 10ms.
Avi Drissman13fc8932015-12-20 04:40:46104const uint32_t kMinInitialRoundTripTimeUs = 10 * kNumMicrosPerMilli;
rtennetifc97ab62014-11-11 22:17:49105
[email protected]8e01c062013-10-31 07:35:31106// Don't allow a client to suggest an RTT longer than 15 seconds.
Avi Drissman13fc8932015-12-20 04:40:46107const uint32_t kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond;
[email protected]8b37a092012-10-18 21:53:49108
109// Maximum number of open streams per connection.
110const size_t kDefaultMaxStreamsPerConnection = 100;
111
[email protected]af806e62013-05-22 14:47:50112// Number of bytes reserved for public flags in the packet header.
113const size_t kPublicFlagsSize = 1;
[email protected]5351cc4b2013-03-03 07:22:41114// Number of bytes reserved for version number in the packet header.
115const size_t kQuicVersionSize = 4;
zhongyib8677022015-12-01 05:51:30116// Number of bytes reserved for path id in the packet header.
117const size_t kQuicPathIdSize = 1;
[email protected]c995c572013-01-18 05:43:20118// Number of bytes reserved for private flags in the packet header.
119const size_t kPrivateFlagsSize = 1;
120// Number of bytes reserved for FEC group in the packet header.
121const size_t kFecGroupSize = 1;
[email protected]5351cc4b2013-03-03 07:22:41122
123// Signifies that the QuicPacket will contain version of the protocol.
124const bool kIncludeVersion = true;
zhongyib8677022015-12-01 05:51:30125// Signifies that the QuicPacket will contain path id.
126const bool kIncludePathId = true;
[email protected]c995c572013-01-18 05:43:20127
zhongyi4a9d27b2016-01-12 20:08:31128// Stream ID is reserved to denote an invalid ID.
129const QuicStreamId kInvalidStreamId = 0;
130
[email protected]8b37a092012-10-18 21:53:49131// Reserved ID for the crypto stream.
[email protected]8b37a092012-10-18 21:53:49132const QuicStreamId kCryptoStreamId = 1;
133
[email protected]4d640792013-12-18 22:21:08134// Reserved ID for the headers stream.
135const QuicStreamId kHeadersStreamId = 3;
136
jri3285d93a2015-12-14 08:53:19137// Header key used to identify final offset on data stream when sending HTTP/2
138// trailing headers over QUIC.
139NET_EXPORT_PRIVATE extern const char* const kFinalOffsetHeaderKey;
140
[email protected]648f81142014-08-15 21:38:46141// Maximum delayed ack time, in ms.
Avi Drissman13fc8932015-12-20 04:40:46142const int64_t kMaxDelayedAckTimeMs = 25;
[email protected]648f81142014-08-15 21:38:46143
rtennetib5512bb2014-09-29 19:17:15144// The timeout before the handshake succeeds.
Avi Drissman13fc8932015-12-20 04:40:46145const int64_t kInitialIdleTimeoutSecs = 5;
rtennetib5512bb2014-09-29 19:17:15146// The default idle timeout.
Avi Drissman13fc8932015-12-20 04:40:46147const int64_t kDefaultIdleTimeoutSecs = 30;
rtenneti31e9fd62014-09-16 05:22:15148// The maximum idle timeout that can be negotiated.
Avi Drissman13fc8932015-12-20 04:40:46149const int64_t kMaximumIdleTimeoutSecs = 60 * 10; // 10 minutes.
rtenneti31e9fd62014-09-16 05:22:15150// The default timeout for a connection until the crypto handshake succeeds.
Avi Drissman13fc8932015-12-20 04:40:46151const int64_t kMaxTimeForCryptoHandshakeSecs = 10; // 10 secs.
[email protected]8b37a092012-10-18 21:53:49152
rtenneti93bce7ece2014-10-13 22:38:41153// Default limit on the number of undecryptable packets the connection buffers
154// before the CHLO/SHLO arrive.
155const size_t kDefaultMaxUndecryptablePackets = 10;
156
[email protected]525948df2014-04-21 06:26:58157// Default ping timeout.
Avi Drissman13fc8932015-12-20 04:40:46158const int64_t kPingTimeoutSecs = 15; // 15 secs.
[email protected]525948df2014-04-21 06:26:58159
[email protected]ca4e0d92014-08-22 16:33:22160// Minimum number of RTTs between Server Config Updates (SCUP) sent to client.
161const int kMinIntervalBetweenServerConfigUpdatesRTTs = 10;
162
163// Minimum time between Server Config Updates (SCUP) sent to client.
164const int kMinIntervalBetweenServerConfigUpdatesMs = 1000;
165
rtenneti33da8ab2014-11-04 04:17:00166// Minimum number of packets between Server Config Updates (SCUP).
167const int kMinPacketsBetweenServerConfigUpdates = 100;
168
rtennetib5512bb2014-09-29 19:17:15169// The number of open streams that a server will accept is set to be slightly
170// larger than the negotiated limit. Immediately closing the connection if the
171// client opens slightly too many streams is not ideal: the client may have sent
172// a FIN that was lost, and simultaneously opened a new stream. The number of
173// streams a server accepts is a fixed increment over the negotiated limit, or a
174// percentage increase, whichever is larger.
rtenneti31e9fd62014-09-16 05:22:15175const float kMaxStreamsMultiplier = 1.1f;
rtennetib5512bb2014-09-29 19:17:15176const int kMaxStreamsMinimumIncrement = 10;
rtenneti31e9fd62014-09-16 05:22:15177
rtenneti159828f2015-10-13 06:58:09178// Available streams are ones with IDs less than the highest stream that has
179// been opened which have neither been opened or reset. The limit on the number
180// of available streams is 10 times the limit on the number of open streams.
181const int kMaxAvailableStreamsMultiplier = 10;
182
[email protected]b007e632013-10-28 08:39:25183// We define an unsigned 16-bit floating point value, inspired by IEEE floats
184// (http://en.wikipedia.org/wiki/Half_precision_floating-point_format),
185// with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden
186// bit) and denormals, but without signs, transfinites or fractions. Wire format
187// 16 bits (little-endian byte order) are split into exponent (high 5) and
188// mantissa (low 11) and decoded as:
Avi Drissman13fc8932015-12-20 04:40:46189// uint64_t value;
[email protected]b007e632013-10-28 08:39:25190// if (exponent == 0) value = mantissa;
191// else value = (mantissa | 1 << 11) << (exponent - 1)
192const int kUFloat16ExponentBits = 5;
rjshaded5ced072015-12-18 19:26:02193const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30
194const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11
[email protected]b007e632013-10-28 08:39:25195const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12
Avi Drissman13fc8932015-12-20 04:40:46196const uint64_t kUFloat16MaxValue = // 0x3FFC0000000
rjshaded5ced072015-12-18 19:26:02197 ((UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1)
198 << kUFloat16MaxExponent;
[email protected]b007e632013-10-28 08:39:25199
jri3285d93a2015-12-14 08:53:19200// Default path ID.
201const QuicPathId kDefaultPathId = 0;
fayanga31a74b2015-12-28 17:27:14202// Invalid path ID.
203const QuicPathId kInvalidPathId = 0xff;
jri3285d93a2015-12-14 08:53:19204
[email protected]c67a82cb2013-09-24 02:53:21205enum TransmissionType {
[email protected]2532de12013-05-09 12:29:33206 NOT_RETRANSMISSION,
[email protected]b9475b582014-03-20 20:04:33207 FIRST_TRANSMISSION_TYPE = NOT_RETRANSMISSION,
rjshaded5ced072015-12-18 19:26:02208 HANDSHAKE_RETRANSMISSION, // Retransmits due to handshake timeouts.
rtenneti31e9fd62014-09-16 05:22:15209 ALL_UNACKED_RETRANSMISSION, // Retransmits all unacked packets.
210 ALL_INITIAL_RETRANSMISSION, // Retransmits all initially encrypted packets.
rjshaded5ced072015-12-18 19:26:02211 LOSS_RETRANSMISSION, // Retransmits due to loss detection.
212 RTO_RETRANSMISSION, // Retransmits due to retransmit time out.
213 TLP_RETRANSMISSION, // Tail loss probes.
[email protected]b9475b582014-03-20 20:04:33214 LAST_TRANSMISSION_TYPE = TLP_RETRANSMISSION,
[email protected]74bda142013-03-31 02:49:11215};
216
217enum HasRetransmittableData {
[email protected]2532de12013-05-09 12:29:33218 NO_RETRANSMITTABLE_DATA,
219 HAS_RETRANSMITTABLE_DATA,
[email protected]74bda142013-03-31 02:49:11220};
221
rjshaded5ced072015-12-18 19:26:02222enum IsHandshake { NOT_HANDSHAKE, IS_HANDSHAKE };
[email protected]575cce62013-08-03 02:06:43223
rtenneti6f48aa92015-03-16 02:18:48224enum class Perspective { IS_SERVER, IS_CLIENT };
225
226NET_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
227 const Perspective& s);
228
[email protected]bbb10072014-06-13 07:41:59229// Indicates FEC protection level for data being written.
230enum FecProtection {
231 MUST_FEC_PROTECT, // Callee must FEC protect this data.
[email protected]a5b98172014-06-18 07:01:59232 MAY_FEC_PROTECT // Callee does not have to but may FEC protect this data.
233};
234
[email protected]bc356fe2014-06-19 11:14:14235// Indicates FEC policy.
[email protected]a5b98172014-06-18 07:01:59236enum FecPolicy {
237 FEC_PROTECT_ALWAYS, // All data in the stream should be FEC protected.
238 FEC_PROTECT_OPTIONAL // Data in the stream does not need FEC protection.
[email protected]bbb10072014-06-13 07:41:59239};
240
rtennetia4228ea2015-06-04 02:31:44241// Indicates FEC policy about when to send FEC packet.
242enum FecSendPolicy {
243 // Send FEC packet when FEC group is full or when FEC alarm goes off.
244 FEC_ANY_TRIGGER,
245 // Send FEC packet only when FEC alarm goes off.
246 FEC_ALARM_TRIGGER
247};
248
[email protected]be24ab22012-10-22 03:01:52249enum QuicFrameType {
[email protected]6ae6e342014-02-06 02:21:42250 // Regular frame types. The values set here cannot change without the
251 // introduction of a new QUIC version.
[email protected]c995c572013-01-18 05:43:20252 PADDING_FRAME = 0,
[email protected]6ae6e342014-02-06 02:21:42253 RST_STREAM_FRAME = 1,
254 CONNECTION_CLOSE_FRAME = 2,
255 GOAWAY_FRAME = 3,
256 WINDOW_UPDATE_FRAME = 4,
257 BLOCKED_FRAME = 5,
[email protected]93dd91f2014-02-27 00:09:03258 STOP_WAITING_FRAME = 6,
[email protected]d8c522112014-04-23 09:23:25259 PING_FRAME = 7,
rchcaec4242016-01-22 20:49:52260 PATH_CLOSE_FRAME = 8,
[email protected]6ae6e342014-02-06 02:21:42261
rtennetif4bdb542015-01-21 14:33:05262 // STREAM and ACK frames are special frames. They are encoded differently on
263 // the wire and their values do not need to be stable.
[email protected]97cf3022013-09-05 14:30:16264 STREAM_FRAME,
265 ACK_FRAME,
rtenneti69e64aa2015-06-26 04:25:30266 // The path MTU discovery frame is encoded as a PING frame on the wire.
267 MTU_DISCOVERY_FRAME,
[email protected]be24ab22012-10-22 03:01:52268 NUM_FRAME_TYPES
[email protected]8b37a092012-10-18 21:53:49269};
270
[email protected]3aa9ca72014-02-27 19:39:43271enum QuicConnectionIdLength {
272 PACKET_0BYTE_CONNECTION_ID = 0,
273 PACKET_1BYTE_CONNECTION_ID = 1,
274 PACKET_4BYTE_CONNECTION_ID = 4,
275 PACKET_8BYTE_CONNECTION_ID = 8
[email protected]b064310782013-05-30 21:12:17276};
277
278enum InFecGroup {
279 NOT_IN_FEC_GROUP,
280 IN_FEC_GROUP,
281};
282
rtennetia004d332015-08-28 06:44:57283enum QuicPacketNumberLength {
284 PACKET_1BYTE_PACKET_NUMBER = 1,
285 PACKET_2BYTE_PACKET_NUMBER = 2,
286 PACKET_4BYTE_PACKET_NUMBER = 4,
287 PACKET_6BYTE_PACKET_NUMBER = 6
[email protected]25c31dc2013-06-05 17:56:04288};
289
[email protected]8e01c062013-10-31 07:35:31290// Used to indicate a QuicSequenceNumberLength using two flag bits.
rtennetia004d332015-08-28 06:44:57291enum QuicPacketNumberLengthFlags {
292 PACKET_FLAGS_1BYTE_PACKET = 0, // 00
293 PACKET_FLAGS_2BYTE_PACKET = 1, // 01
294 PACKET_FLAGS_4BYTE_PACKET = 1 << 1, // 10
295 PACKET_FLAGS_6BYTE_PACKET = 1 << 1 | 1, // 11
[email protected]8e01c062013-10-31 07:35:31296};
297
[email protected]f62262b2013-07-05 20:57:30298// The public flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20299enum QuicPacketPublicFlags {
300 PACKET_PUBLIC_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30301
302 // Bit 0: Does the packet header contains version info?
303 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0,
304
305 // Bit 1: Is this packet a public reset packet?
306 PACKET_PUBLIC_FLAGS_RST = 1 << 1,
307
[email protected]3aa9ca72014-02-27 19:39:43308 // Bits 2 and 3 specify the length of the ConnectionId as follows:
[email protected]f62262b2013-07-05 20:57:30309 // ----00--: 0 bytes
310 // ----01--: 1 byte
311 // ----10--: 4 bytes
312 // ----11--: 8 bytes
[email protected]3aa9ca72014-02-27 19:39:43313 PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID = 0,
314 PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID = 1 << 2,
315 PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID = 1 << 3,
316 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID = 1 << 3 | 1 << 2,
[email protected]f62262b2013-07-05 20:57:30317
rtennetia004d332015-08-28 06:44:57318 // Bits 4 and 5 describe the packet number length as follows:
[email protected]f62262b2013-07-05 20:57:30319 // --00----: 1 byte
320 // --01----: 2 bytes
321 // --10----: 4 bytes
322 // --11----: 6 bytes
rtennetia004d332015-08-28 06:44:57323 PACKET_PUBLIC_FLAGS_1BYTE_PACKET = PACKET_FLAGS_1BYTE_PACKET << 4,
324 PACKET_PUBLIC_FLAGS_2BYTE_PACKET = PACKET_FLAGS_2BYTE_PACKET << 4,
325 PACKET_PUBLIC_FLAGS_4BYTE_PACKET = PACKET_FLAGS_4BYTE_PACKET << 4,
326 PACKET_PUBLIC_FLAGS_6BYTE_PACKET = PACKET_FLAGS_6BYTE_PACKET << 4,
[email protected]f62262b2013-07-05 20:57:30327
zhongyib8677022015-12-01 05:51:30328 // Bit 6: Does the packet header contain a path id?
329 PACKET_PUBLIC_FLAGS_MULTIPATH = 1 << 6,
330
331 // All bits set (bit7 are not currently used): 01111111
332 PACKET_PUBLIC_FLAGS_MAX = (1 << 7) - 1,
[email protected]c995c572013-01-18 05:43:20333};
[email protected]8b37a092012-10-18 21:53:49334
[email protected]f62262b2013-07-05 20:57:30335// The private flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20336enum QuicPacketPrivateFlags {
337 PACKET_PRIVATE_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30338
339 // Bit 0: Does this packet contain an entropy bit?
[email protected]b064310782013-05-30 21:12:17340 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0,
[email protected]f62262b2013-07-05 20:57:30341
342 // Bit 1: Payload is part of an FEC group?
343 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1,
344
345 // Bit 2: Payload is FEC as opposed to frames?
346 PACKET_PRIVATE_FLAGS_FEC = 1 << 2,
347
348 // All bits set (bits 3-7 are not currently used): 00000111
349 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1
[email protected]c995c572013-01-18 05:43:20350};
351
[email protected]48878092013-07-26 14:51:56352// The available versions of QUIC. Guaranteed that the integer value of the enum
353// will match the version number.
354// When adding a new version to this enum you should add it to
[email protected]8bbfaeb72013-08-09 06:38:26355// kSupportedQuicVersions (if appropriate), and also add a new case to the
356// helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and
357// QuicVersionToString.
[email protected]48878092013-07-26 14:51:56358enum QuicVersion {
359 // Special case to indicate unknown/unsupported QUIC version.
360 QUIC_VERSION_UNSUPPORTED = 0,
361
rchc0815442015-04-18 13:29:46362 QUIC_VERSION_25 = 25, // SPDY/4 header keys, and removal of error_details
363 // from QuicRstStreamFrame
zhongyic92bc492015-09-22 19:14:36364 QUIC_VERSION_26 = 26, // In CHLO, send XLCT tag containing hash of leaf cert
rtenneti159828f2015-10-13 06:58:09365 QUIC_VERSION_27 = 27, // Sends a nonce in the SHLO.
rtenneti5ca6eee2015-10-15 21:54:30366 QUIC_VERSION_28 = 28, // Receiver can refuse to create a requested stream.
rch99b644c2015-11-04 05:25:28367 QUIC_VERSION_29 = 29, // Server and client honor QUIC_STREAM_NO_ERROR.
368 QUIC_VERSION_30 = 30, // Add server side support of cert transparency.
[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[] = {
rch99b644c2015-11-04 05:25:28379 QUIC_VERSION_30, QUIC_VERSION_29, QUIC_VERSION_28,
380 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
[email protected]b064310782013-05-30 21:12:17421// Size in bytes of the data or fec 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,
rtennetia004d332015-08-28 06:44:57428 QuicPacketNumberLength packet_number_length,
429 InFecGroup is_in_fec_group);
[email protected]b064310782013-05-30 21:12:17430
[email protected]b064310782013-05-30 21:12:17431// Index of the first byte in a QUIC packet of FEC protected data.
rtennetia004d332015-08-28 06:44:57432NET_EXPORT_PRIVATE size_t
433GetStartOfFecProtectedData(QuicConnectionIdLength connection_id_length,
434 bool include_version,
rchcaec4242016-01-22 20:49:52435 bool include_path_id,
rtennetia004d332015-08-28 06:44:57436 QuicPacketNumberLength packet_number_length);
rchcaec4242016-01-22 20:49:52437
[email protected]b064310782013-05-30 21:12:17438// Index of the first byte in a QUIC packet of encrypted data.
rtennetia004d332015-08-28 06:44:57439NET_EXPORT_PRIVATE size_t
440GetStartOfEncryptedData(QuicConnectionIdLength connection_id_length,
441 bool include_version,
rchcaec4242016-01-22 20:49:52442 bool include_path_id,
rtennetia004d332015-08-28 06:44:57443 QuicPacketNumberLength packet_number_length);
[email protected]b064310782013-05-30 21:12:17444
[email protected]74bda142013-03-31 02:49:11445enum QuicRstStreamErrorCode {
rch99b644c2015-11-04 05:25:28446 // Complete response has been sent, sending a RST to ask the other endpoint
447 // to stop sending request data without discarding the response.
[email protected]74bda142013-03-31 02:49:11448 QUIC_STREAM_NO_ERROR = 0,
[email protected]8b37a092012-10-18 21:53:49449
[email protected]24e5bc52013-09-18 15:36:58450 // There was some error which halted stream processing.
451 QUIC_ERROR_PROCESSING_STREAM,
[email protected]8b37a092012-10-18 21:53:49452 // We got two fin or reset offsets which did not match.
453 QUIC_MULTIPLE_TERMINATION_OFFSETS,
454 // We got bad payload and can not respond to it at the protocol level.
455 QUIC_BAD_APPLICATION_PAYLOAD,
[email protected]74bda142013-03-31 02:49:11456 // Stream closed due to connection error. No reset frame is sent when this
457 // happens.
458 QUIC_STREAM_CONNECTION_ERROR,
459 // GoAway frame sent. No more stream can be created.
460 QUIC_STREAM_PEER_GOING_AWAY,
[email protected]06ff5152013-08-29 01:03:05461 // The stream has been cancelled.
462 QUIC_STREAM_CANCELLED,
rtenneti4a5df262014-11-07 00:43:58463 // Closing stream locally, sending a RST to allow for proper flow control
464 // accounting. Sent in response to a RST from the peer.
465 QUIC_RST_ACKNOWLEDGEMENT,
rtenneti5ca6eee2015-10-15 21:54:30466 // Receiver refused to create the stream (because its limit on open streams
467 // has been reached). The sender should retry the request later (using
468 // another stream).
469 QUIC_REFUSED_STREAM,
[email protected]8b37a092012-10-18 21:53:49470
[email protected]74bda142013-03-31 02:49:11471 // No error. Used as bound while iterating.
472 QUIC_STREAM_LAST_ERROR,
473};
[email protected]8b37a092012-10-18 21:53:49474
[email protected]51cc1342014-04-18 23:44:37475// Because receiving an unknown QuicRstStreamErrorCode results in connection
476// teardown, we use this to make sure any errors predating a given version are
477// downgraded to the most appropriate existing error.
rjshaded5ced072015-12-18 19:26:02478NET_EXPORT_PRIVATE QuicRstStreamErrorCode
479AdjustErrorForVersion(QuicRstStreamErrorCode error_code, QuicVersion version);
[email protected]51cc1342014-04-18 23:44:37480
[email protected]89264042013-08-21 07:35:24481// These values must remain stable as they are uploaded to UMA histograms.
482// To add a new error code, use the current value of QUIC_LAST_ERROR and
483// increment QUIC_LAST_ERROR.
rchcaec4242016-01-22 20:49:52484// last value = 80
[email protected]74bda142013-03-31 02:49:11485enum QuicErrorCode {
486 QUIC_NO_ERROR = 0,
487
488 // Connection has reached an invalid state.
[email protected]89264042013-08-21 07:35:24489 QUIC_INTERNAL_ERROR = 1,
[email protected]74bda142013-03-31 02:49:11490 // There were data frames after the a fin or reset.
[email protected]89264042013-08-21 07:35:24491 QUIC_STREAM_DATA_AFTER_TERMINATION = 2,
[email protected]8b37a092012-10-18 21:53:49492 // Control frame is malformed.
[email protected]89264042013-08-21 07:35:24493 QUIC_INVALID_PACKET_HEADER = 3,
[email protected]be24ab22012-10-22 03:01:52494 // Frame data is malformed.
[email protected]89264042013-08-21 07:35:24495 QUIC_INVALID_FRAME_DATA = 4,
496 // The packet contained no payload.
497 QUIC_MISSING_PAYLOAD = 48,
[email protected]8b37a092012-10-18 21:53:49498 // FEC data is malformed.
[email protected]89264042013-08-21 07:35:24499 QUIC_INVALID_FEC_DATA = 5,
500 // STREAM frame data is malformed.
501 QUIC_INVALID_STREAM_DATA = 46,
[email protected]42a3eba2014-04-30 10:52:55502 // STREAM frame data is not encrypted.
503 QUIC_UNENCRYPTED_STREAM_DATA = 61,
zhongyi4a9d27b2016-01-12 20:08:31504 // FEC frame data is not encrypted.
505 QUIC_UNENCRYPTED_FEC_DATA = 77,
[email protected]89264042013-08-21 07:35:24506 // RST_STREAM frame data is malformed.
507 QUIC_INVALID_RST_STREAM_DATA = 6,
508 // CONNECTION_CLOSE frame data is malformed.
509 QUIC_INVALID_CONNECTION_CLOSE_DATA = 7,
510 // GOAWAY frame data is malformed.
511 QUIC_INVALID_GOAWAY_DATA = 8,
[email protected]6ae6e342014-02-06 02:21:42512 // WINDOW_UPDATE frame data is malformed.
513 QUIC_INVALID_WINDOW_UPDATE_DATA = 57,
514 // BLOCKED frame data is malformed.
515 QUIC_INVALID_BLOCKED_DATA = 58,
[email protected]93dd91f2014-02-27 00:09:03516 // STOP_WAITING frame data is malformed.
517 QUIC_INVALID_STOP_WAITING_DATA = 60,
rchcaec4242016-01-22 20:49:52518 // PATH_CLOSE frame data is malformed.
519 QUIC_INVALID_PATH_CLOSE_DATA = 78,
[email protected]89264042013-08-21 07:35:24520 // ACK frame data is malformed.
521 QUIC_INVALID_ACK_DATA = 9,
rtennetif4bdb542015-01-21 14:33:05522
[email protected]14e8106c2013-03-14 16:25:33523 // Version negotiation packet is malformed.
[email protected]89264042013-08-21 07:35:24524 QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10,
[email protected]899951652013-05-16 12:52:39525 // Public RST packet is malformed.
[email protected]89264042013-08-21 07:35:24526 QUIC_INVALID_PUBLIC_RST_PACKET = 11,
[email protected]8b37a092012-10-18 21:53:49527 // There was an error decrypting.
[email protected]89264042013-08-21 07:35:24528 QUIC_DECRYPTION_FAILURE = 12,
[email protected]8b37a092012-10-18 21:53:49529 // There was an error encrypting.
[email protected]89264042013-08-21 07:35:24530 QUIC_ENCRYPTION_FAILURE = 13,
[email protected]8b37a092012-10-18 21:53:49531 // The packet exceeded kMaxPacketSize.
[email protected]89264042013-08-21 07:35:24532 QUIC_PACKET_TOO_LARGE = 14,
[email protected]9db443912013-02-25 05:27:03533 // The peer is going away. May be a client or server.
[email protected]89264042013-08-21 07:35:24534 QUIC_PEER_GOING_AWAY = 16,
[email protected]8b37a092012-10-18 21:53:49535 // A stream ID was invalid.
[email protected]89264042013-08-21 07:35:24536 QUIC_INVALID_STREAM_ID = 17,
[email protected]24e5bc52013-09-18 15:36:58537 // A priority was invalid.
538 QUIC_INVALID_PRIORITY = 49,
[email protected]8b37a092012-10-18 21:53:49539 // Too many streams already open.
[email protected]89264042013-08-21 07:35:24540 QUIC_TOO_MANY_OPEN_STREAMS = 18,
rtenneti159828f2015-10-13 06:58:09541 // The peer created too many available streams.
542 QUIC_TOO_MANY_AVAILABLE_STREAMS = 76,
[email protected]86a318d2013-01-23 21:16:04543 // Received public reset for this connection.
[email protected]89264042013-08-21 07:35:24544 QUIC_PUBLIC_RESET = 19,
[email protected]c244c5a12013-05-07 20:55:04545 // Invalid protocol version.
[email protected]89264042013-08-21 07:35:24546 QUIC_INVALID_VERSION = 20,
[email protected]92bf17c2014-03-03 21:14:03547
[email protected]c244c5a12013-05-07 20:55:04548 // The Header ID for a stream was too far from the previous.
[email protected]89264042013-08-21 07:35:24549 QUIC_INVALID_HEADER_ID = 22,
[email protected]899951652013-05-16 12:52:39550 // Negotiable parameter received during handshake had invalid value.
[email protected]89264042013-08-21 07:35:24551 QUIC_INVALID_NEGOTIATED_VALUE = 23,
[email protected]899951652013-05-16 12:52:39552 // There was an error decompressing data.
[email protected]89264042013-08-21 07:35:24553 QUIC_DECOMPRESSION_FAILURE = 24,
[email protected]8b37a092012-10-18 21:53:49554 // We hit our prenegotiated (or default) timeout
[email protected]89264042013-08-21 07:35:24555 QUIC_CONNECTION_TIMED_OUT = 25,
rtenneti31e9fd62014-09-16 05:22:15556 // We hit our overall connection timeout
557 QUIC_CONNECTION_OVERALL_TIMED_OUT = 67,
[email protected]899951652013-05-16 12:52:39558 // There was an error encountered migrating addresses
[email protected]89264042013-08-21 07:35:24559 QUIC_ERROR_MIGRATING_ADDRESS = 26,
[email protected]1505a512013-09-04 22:59:35560 // There was an error while writing to the socket.
[email protected]89264042013-08-21 07:35:24561 QUIC_PACKET_WRITE_ERROR = 27,
[email protected]1505a512013-09-04 22:59:35562 // There was an error while reading from the socket.
563 QUIC_PACKET_READ_ERROR = 51,
[email protected]24e5bc52013-09-18 15:36:58564 // We received a STREAM_FRAME with no data and no fin flag set.
565 QUIC_INVALID_STREAM_FRAME = 50,
[email protected]4d640792013-12-18 22:21:08566 // We received invalid data on the headers stream.
567 QUIC_INVALID_HEADERS_STREAM_DATA = 56,
[email protected]730b35d72014-06-05 03:23:22568 // The peer received too much data, violating flow control.
569 QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA = 59,
570 // The peer sent too much data, violating flow control.
571 QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA = 63,
572 // The peer received an invalid flow control window.
573 QUIC_FLOW_CONTROL_INVALID_WINDOW = 64,
[email protected]71c84e592014-05-28 23:39:29574 // The connection has been IP pooled into an existing connection.
575 QUIC_CONNECTION_IP_POOLED = 62,
rtenneti23186682014-10-30 01:49:33576 // The connection has too many outstanding sent packets.
577 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS = 68,
578 // The connection has too many outstanding received packets.
579 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS = 69,
rtenneti14abd312015-02-06 21:56:01580 // The quic connection job to load server config is cancelled.
581 QUIC_CONNECTION_CANCELLED = 70,
rtenneti85dcfac22015-03-27 20:22:19582 // Disabled QUIC because of high packet loss rate.
583 QUIC_BAD_PACKET_LOSS_RATE = 71,
ckrasic1e53b642015-07-08 22:39:35584 // Disabled QUIC because of too many PUBLIC_RESETs post handshake.
585 QUIC_PUBLIC_RESETS_POST_HANDSHAKE = 73,
586 // Disabled QUIC because of too many timeouts with streams open.
587 QUIC_TIMEOUTS_WITH_OPEN_STREAMS = 74,
rtenneti8811fdb2015-07-22 00:17:07588 // Closed because we failed to serialize a packet.
589 QUIC_FAILED_TO_SERIALIZE_PACKET = 75,
[email protected]8b37a092012-10-18 21:53:49590
591 // Crypto errors.
592
[email protected]1354bf62013-05-23 23:17:18593 // Hanshake failed.
[email protected]89264042013-08-21 07:35:24594 QUIC_HANDSHAKE_FAILED = 28,
[email protected]8b37a092012-10-18 21:53:49595 // Handshake message contained out of order tags.
[email protected]89264042013-08-21 07:35:24596 QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29,
[email protected]701bc892013-01-17 04:51:54597 // Handshake message contained too many entries.
[email protected]89264042013-08-21 07:35:24598 QUIC_CRYPTO_TOO_MANY_ENTRIES = 30,
[email protected]8b37a092012-10-18 21:53:49599 // Handshake message contained an invalid value length.
[email protected]89264042013-08-21 07:35:24600 QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31,
[email protected]8b37a092012-10-18 21:53:49601 // A crypto message was received after the handshake was complete.
[email protected]89264042013-08-21 07:35:24602 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32,
[email protected]d3d15bf2013-01-30 02:51:54603 // A crypto message was received with an illegal message tag.
[email protected]89264042013-08-21 07:35:24604 QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33,
[email protected]d3d15bf2013-01-30 02:51:54605 // A crypto message was received with an illegal parameter.
[email protected]89264042013-08-21 07:35:24606 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34,
[email protected]752fbe52013-10-14 08:35:32607 // An invalid channel id signature was supplied.
608 QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52,
[email protected]d3d15bf2013-01-30 02:51:54609 // A crypto message was received with a mandatory parameter missing.
[email protected]89264042013-08-21 07:35:24610 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35,
[email protected]d3d15bf2013-01-30 02:51:54611 // A crypto message was received with a parameter that has no overlap
612 // with the local parameter.
[email protected]89264042013-08-21 07:35:24613 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36,
[email protected]ed3fc15d2013-03-08 18:37:44614 // A crypto message was received that contained a parameter with too few
615 // values.
[email protected]89264042013-08-21 07:35:24616 QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37,
[email protected]ccc66e8a2013-03-26 08:26:14617 // An internal error occured in crypto processing.
[email protected]89264042013-08-21 07:35:24618 QUIC_CRYPTO_INTERNAL_ERROR = 38,
[email protected]ccc66e8a2013-03-26 08:26:14619 // A crypto handshake message specified an unsupported version.
[email protected]89264042013-08-21 07:35:24620 QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39,
rtennetie0ee6eb2015-05-01 00:55:09621 // A crypto handshake message resulted in a stateless reject.
622 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT = 72,
[email protected]ccc66e8a2013-03-26 08:26:14623 // There was no intersection between the crypto primitives supported by the
624 // peer and ourselves.
[email protected]89264042013-08-21 07:35:24625 QUIC_CRYPTO_NO_SUPPORT = 40,
[email protected]ef95114d2013-04-17 17:57:01626 // The server rejected our client hello messages too many times.
[email protected]89264042013-08-21 07:35:24627 QUIC_CRYPTO_TOO_MANY_REJECTS = 41,
[email protected]a57e0272013-04-26 07:31:47628 // The client rejected the server's certificate chain or signature.
[email protected]89264042013-08-21 07:35:24629 QUIC_PROOF_INVALID = 42,
[email protected]8ba81212013-05-03 13:11:48630 // A crypto message was received with a duplicate tag.
[email protected]89264042013-08-21 07:35:24631 QUIC_CRYPTO_DUPLICATE_TAG = 43,
[email protected]2532de12013-05-09 12:29:33632 // A crypto message was received with the wrong encryption level (i.e. it
633 // should have been encrypted but was not.)
[email protected]89264042013-08-21 07:35:24634 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44,
[email protected]2532de12013-05-09 12:29:33635 // The server config for a server has expired.
[email protected]89264042013-08-21 07:35:24636 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45,
[email protected]752fbe52013-10-14 08:35:32637 // We failed to setup the symmetric keys for a connection.
638 QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53,
[email protected]691f45a982013-11-19 10:52:04639 // A handshake message arrived, but we are still validating the
640 // previous handshake message.
641 QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54,
[email protected]ccb34212014-07-18 09:27:50642 // A server config update arrived before the handshake is complete.
643 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE = 65,
[email protected]d89f1862013-11-26 21:21:27644 // This connection involved a version negotiation which appears to have been
645 // tampered with.
646 QUIC_VERSION_NEGOTIATION_MISMATCH = 55,
[email protected]ccc66e8a2013-03-26 08:26:14647
rchcaec4242016-01-22 20:49:52648 // Multipath is not enabled, but a packet with multipath flag on is received.
649 QUIC_BAD_MULTIPATH_FLAG = 79,
650
jri7e636642016-01-14 06:57:08651 // IP address changed causing connection close.
rchcaec4242016-01-22 20:49:52652 QUIC_IP_ADDRESS_CHANGED = 80,
jri7e636642016-01-14 06:57:08653
654 // Connection migration errors.
655 // Network changed, but connection had no migratable streams.
rchcaec4242016-01-22 20:49:52656 QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS = 81,
jri7e636642016-01-14 06:57:08657 // Connection changed networks too many times.
rchcaec4242016-01-22 20:49:52658 QUIC_CONNECTION_MIGRATION_TOO_MANY_CHANGES = 82,
jri7e636642016-01-14 06:57:08659 // Connection migration was attempted, but there was no new network to
660 // migrate to.
rchcaec4242016-01-22 20:49:52661 QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK = 83,
jri7e636642016-01-14 06:57:08662
[email protected]74bda142013-03-31 02:49:11663 // No error. Used as bound while iterating.
rchcaec4242016-01-22 20:49:52664 QUIC_LAST_ERROR = 84,
[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
[email protected]c995c572013-01-18 05:43:20690// Header for Data or FEC packets.
[email protected]74bda142013-03-31 02:49:11691struct NET_EXPORT_PRIVATE QuicPacketHeader {
692 QuicPacketHeader();
693 explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
[email protected]9db443912013-02-25 05:27:03694
rjshaded5ced072015-12-18 19:26:02695 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
696 const QuicPacketHeader& s);
[email protected]9db443912013-02-25 05:27:03697
[email protected]c995c572013-01-18 05:43:20698 QuicPacketPublicHeader public_header;
zhongyib8677022015-12-01 05:51:30699 QuicPathId path_id;
rtenneti8dd12b22015-10-21 01:26:38700 QuicPacketNumber packet_number;
[email protected]9db443912013-02-25 05:27:03701 bool fec_flag;
[email protected]9db443912013-02-25 05:27:03702 bool entropy_flag;
703 QuicPacketEntropyHash entropy_hash;
[email protected]b064310782013-05-30 21:12:17704 InFecGroup is_in_fec_group;
[email protected]8b37a092012-10-18 21:53:49705 QuicFecGroupNumber fec_group;
706};
707
[email protected]74bda142013-03-31 02:49:11708struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
[email protected]6ae6e342014-02-06 02:21:42709 QuicPublicResetPacket();
710 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header);
711
[email protected]86a318d2013-01-23 21:16:04712 QuicPacketPublicHeader public_header;
[email protected]86a318d2013-01-23 21:16:04713 QuicPublicResetNonceProof nonce_proof;
rtennetia004d332015-08-28 06:44:57714 QuicPacketNumber rejected_packet_number;
[email protected]79d13dcb2014-02-05 07:23:13715 IPEndPoint client_address;
[email protected]86a318d2013-01-23 21:16:04716};
717
[email protected]14e8106c2013-03-14 16:25:33718enum QuicVersionNegotiationState {
719 START_NEGOTIATION = 0,
[email protected]ec640112013-08-09 03:56:18720 // Server-side this implies we've sent a version negotiation packet and are
721 // waiting on the client to select a compatible version. Client-side this
722 // implies we've gotten a version negotiation packet, are retransmitting the
723 // initial packets with a supported version and are waiting for our first
724 // packet from the server.
725 NEGOTIATION_IN_PROGRESS,
726 // This indicates this endpoint has received a packet from the peer with a
727 // version this endpoint supports. Version negotiation is complete, and the
728 // version number will no longer be sent with future packets.
[email protected]14e8106c2013-03-14 16:25:33729 NEGOTIATED_VERSION
730};
731
732typedef QuicPacketPublicHeader QuicVersionNegotiationPacket;
733
[email protected]c995c572013-01-18 05:43:20734// A padding frame contains no payload.
rtenneti5ca6eee2015-10-15 21:54:30735struct NET_EXPORT_PRIVATE QuicPaddingFrame {};
[email protected]c995c572013-01-18 05:43:20736
[email protected]d8c522112014-04-23 09:23:25737// A ping frame contains no payload, though it is retransmittable,
738// and ACK'd just like other normal frames.
rtenneti5ca6eee2015-10-15 21:54:30739struct NET_EXPORT_PRIVATE QuicPingFrame {};
[email protected]d8c522112014-04-23 09:23:25740
rtenneti69e64aa2015-06-26 04:25:30741// A path MTU discovery frame contains no payload and is serialized as a ping
742// frame.
743struct NET_EXPORT_PRIVATE QuicMtuDiscoveryFrame {};
744
jdorfman5a606722016-01-04 17:41:29745class NET_EXPORT_PRIVATE QuicBufferAllocator {
746 public:
747 virtual ~QuicBufferAllocator();
748
749 // Returns or allocates a new buffer of |size|. Never returns null.
750 virtual char* New(size_t size) = 0;
751
rcha00232242016-01-22 21:07:51752 // Returns or allocates a new buffer of |size| if |flag_enable| is true.
753 // Otherwise, returns a buffer that is compatible with this class directly
754 // with operator new. Never returns null.
755 virtual char* New(size_t size, bool flag_enable) = 0;
756
jdorfman5a606722016-01-04 17:41:29757 // Releases a buffer.
758 virtual void Delete(char* buffer) = 0;
rcha00232242016-01-22 21:07:51759
760 // Marks the allocator as being idle. Serves as a hint to notify the allocator
761 // that it should release any resources it's still holding on to.
762 virtual void MarkAllocatorIdle() {}
jdorfman5a606722016-01-04 17:41:29763};
764
765// Deleter for stream buffers. Copyable to support platforms where the deleter
766// of a unique_ptr must be copyable. Otherwise it would be nice for this to be
767// move-only.
zhongyi2f5f40c2015-12-08 02:13:02768class NET_EXPORT_PRIVATE StreamBufferDeleter {
769 public:
jdorfman5a606722016-01-04 17:41:29770 StreamBufferDeleter() : allocator_(nullptr) {}
771 explicit StreamBufferDeleter(QuicBufferAllocator* allocator)
772 : allocator_(allocator) {}
773
774 // Deletes |buffer| using |allocator_|.
775 void operator()(char* buffer) const;
776
777 private:
778 // Not owned; must be valid so long as the buffer stored in the unique_ptr
779 // that owns |this| is valid.
780 QuicBufferAllocator* allocator_;
zhongyi2f5f40c2015-12-08 02:13:02781};
782
783using UniqueStreamBuffer = std::unique_ptr<char[], StreamBufferDeleter>;
rtennetif60c32d82015-10-14 00:07:00784
jdorfman5a606722016-01-04 17:41:29785// Allocates memory of size |size| using |allocator| for a QUIC stream buffer.
786NET_EXPORT_PRIVATE UniqueStreamBuffer
787NewStreamBuffer(QuicBufferAllocator* allocator, size_t size);
rtennetif60c32d82015-10-14 00:07:00788
[email protected]be24ab22012-10-22 03:01:52789struct NET_EXPORT_PRIVATE QuicStreamFrame {
790 QuicStreamFrame();
[email protected]be24ab22012-10-22 03:01:52791 QuicStreamFrame(QuicStreamId stream_id,
[email protected]a5061242012-10-23 23:29:37792 bool fin,
[email protected]701bc892013-01-17 04:51:54793 QuicStreamOffset offset,
rtennetia4228ea2015-06-04 02:31:44794 base::StringPiece data);
zhongyi36727b82015-12-03 00:42:23795 QuicStreamFrame(QuicStreamId stream_id,
796 bool fin,
797 QuicStreamOffset offset,
jokulik2324d282015-12-08 21:42:57798 QuicPacketLength frame_length,
zhongyi36727b82015-12-03 00:42:23799 UniqueStreamBuffer buffer);
800 ~QuicStreamFrame();
[email protected]5dafdb62013-11-14 01:24:26801
rjshaded5ced072015-12-18 19:26:02802 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
803 const QuicStreamFrame& s);
[email protected]c5e1aca2014-01-30 04:03:04804
[email protected]8b37a092012-10-18 21:53:49805 QuicStreamId stream_id;
806 bool fin;
jokulik2324d282015-12-08 21:42:57807 QuicPacketLength frame_length;
808 const char* frame_buffer;
[email protected]701bc892013-01-17 04:51:54809 QuicStreamOffset offset; // Location of this data in the stream.
zhongyi36727b82015-12-03 00:42:23810 // nullptr when the QuicStreamFrame is received, and non-null when sent.
811 UniqueStreamBuffer buffer;
zhongyi4249f9b02015-12-02 20:26:30812
zhongyi36727b82015-12-03 00:42:23813 private:
jokulik2324d282015-12-08 21:42:57814 QuicStreamFrame(QuicStreamId stream_id,
815 bool fin,
816 QuicStreamOffset offset,
817 const char* frame_buffer,
818 QuicPacketLength frame_length,
819 UniqueStreamBuffer buffer);
820
zhongyi36727b82015-12-03 00:42:23821 DISALLOW_COPY_AND_ASSIGN(QuicStreamFrame);
822};
823static_assert(sizeof(QuicStreamFrame) <= 64,
824 "Keep the QuicStreamFrame size to a cacheline.");
[email protected]e537f742012-12-07 15:33:53825// TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
826// is finalized.
rtennetia004d332015-08-28 06:44:57827typedef std::set<QuicPacketNumber> PacketNumberSet;
828typedef std::list<QuicPacketNumber> PacketNumberList;
rtenneti4b06ae72014-08-26 03:43:43829
ckrasicea295fe2015-10-31 05:03:27830typedef std::vector<std::pair<QuicPacketNumber, QuicTime>> PacketTimeVector;
[email protected]044ac2b2012-11-13 21:41:06831
[email protected]310d37b2014-08-02 06:15:37832struct NET_EXPORT_PRIVATE QuicStopWaitingFrame {
833 QuicStopWaitingFrame();
834 ~QuicStopWaitingFrame();
[email protected]6ae6e342014-02-06 02:21:42835
[email protected]26f3f8e2012-12-13 21:07:19836 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:02837 std::ostream& os,
838 const QuicStopWaitingFrame& s);
jri3285d93a2015-12-14 08:53:19839 // Path which this stop waiting frame belongs to.
840 QuicPathId path_id;
[email protected]310d37b2014-08-02 06:15:37841 // Entropy hash of all packets up to, but not including, the least unacked
842 // packet.
843 QuicPacketEntropyHash entropy_hash;
844 // The lowest packet we've sent which is unacked, and we expect an ack for.
rtennetia004d332015-08-28 06:44:57845 QuicPacketNumber least_unacked;
[email protected]310d37b2014-08-02 06:15:37846};
847
rtenneti493d90ef2015-09-14 04:43:11848// A sequence of packet numbers where each number is unique. Intended to be used
849// in a sliding window fashion, where smaller old packet numbers are removed and
850// larger new packet numbers are added, with the occasional random access.
851class NET_EXPORT_PRIVATE PacketNumberQueue {
852 public:
ckrasicea295fe2015-10-31 05:03:27853 // TODO(jdorfman): remove const_iterator and change the callers to
854 // iterate over the intervals.
rtenneti4efd55dd2015-09-18 01:12:04855 class NET_EXPORT_PRIVATE const_iterator
856 : public std::iterator<std::input_iterator_tag,
857 QuicPacketNumber,
858 std::ptrdiff_t,
859 const QuicPacketNumber*,
860 const QuicPacketNumber&> {
861 public:
862 explicit const_iterator(PacketNumberSet::const_iterator set_iter);
863 const_iterator(
864 IntervalSet<QuicPacketNumber>::const_iterator interval_set_iter,
865 QuicPacketNumber first,
866 QuicPacketNumber last);
867 const_iterator(const const_iterator& other);
868 const_iterator& operator=(const const_iterator& other);
869 // TODO(rtenneti): on windows RValue reference gives errors.
870 // const_iterator(const_iterator&& other);
871 ~const_iterator();
872
873 // TODO(rtenneti): on windows RValue reference gives errors.
874 // const_iterator& operator=(const_iterator&& other);
875 bool operator!=(const const_iterator& other) const;
876 bool operator==(const const_iterator& other) const;
877 value_type operator*() const;
878 const_iterator& operator++();
879 const_iterator operator++(int /* postincrement */);
880
881 private:
rtenneti4efd55dd2015-09-18 01:12:04882 IntervalSet<QuicPacketNumber>::const_iterator interval_set_iter_;
883 QuicPacketNumber current_;
884 QuicPacketNumber last_;
885 };
886
rtenneti493d90ef2015-09-14 04:43:11887 PacketNumberQueue();
rtenneti4efd55dd2015-09-18 01:12:04888 PacketNumberQueue(const PacketNumberQueue& other);
rtenneti4efd55dd2015-09-18 01:12:04889 // TODO(rtenneti): on windows RValue reference gives errors.
890 // PacketNumberQueue(PacketNumberQueue&& other);
rtenneti93209a02015-09-19 01:51:18891 ~PacketNumberQueue();
892
893 PacketNumberQueue& operator=(const PacketNumberQueue& other);
rtenneti4efd55dd2015-09-18 01:12:04894 // PacketNumberQueue& operator=(PacketNumberQueue&& other);
rtenneti493d90ef2015-09-14 04:43:11895
896 // Adds |packet_number| to the set of packets in the queue.
897 void Add(QuicPacketNumber packet_number);
898
rtenneti4efd55dd2015-09-18 01:12:04899 // Adds packets between [lower, higher) to the set of packets in the queue. It
900 // is undefined behavior to call this with |higher| < |lower|.
rtenneti493d90ef2015-09-14 04:43:11901 void Add(QuicPacketNumber lower, QuicPacketNumber higher);
902
903 // Removes |packet_number| from the set of packets in the queue.
904 void Remove(QuicPacketNumber packet_number);
905
906 // Removes packets with values less than |higher| from the set of packets in
907 // the queue. Returns true if packets were removed.
908 bool RemoveUpTo(QuicPacketNumber higher);
909
910 // Returns true if the queue contains |packet_number|.
911 bool Contains(QuicPacketNumber packet_number) const;
912
913 // Returns true if the queue is empty.
914 bool Empty() const;
915
916 // Returns the minimum packet number stored in the queue. It is undefined
917 // behavior to call this if the queue is empty.
918 QuicPacketNumber Min() const;
919
920 // Returns the maximum packet number stored in the queue. It is undefined
921 // behavior to call this if the queue is empty.
922 QuicPacketNumber Max() const;
923
rtenneti4efd55dd2015-09-18 01:12:04924 // Returns the number of unique packets stored in the queue. Inefficient; only
925 // exposed for testing.
926 size_t NumPacketsSlow() const;
rtenneti493d90ef2015-09-14 04:43:11927
rtenneti4efd55dd2015-09-18 01:12:04928 // Returns iterators over the individual packet numbers.
929 const_iterator begin() const;
930 const_iterator end() const;
rtenneti493d90ef2015-09-14 04:43:11931 const_iterator lower_bound(QuicPacketNumber packet_number) const;
rtenneti493d90ef2015-09-14 04:43:11932
933 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
934 std::ostream& os,
935 const PacketNumberQueue& q);
936
937 private:
rtenneti4efd55dd2015-09-18 01:12:04938 IntervalSet<QuicPacketNumber> packet_number_intervals_;
rtenneti493d90ef2015-09-14 04:43:11939};
940
[email protected]310d37b2014-08-02 06:15:37941struct NET_EXPORT_PRIVATE QuicAckFrame {
942 QuicAckFrame();
943 ~QuicAckFrame();
944
rjshaded5ced072015-12-18 19:26:02945 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
946 const QuicAckFrame& s);
[email protected]a674b4c2012-12-05 03:44:30947
jri3285d93a2015-12-14 08:53:19948 // Path which this ack belongs to.
949 QuicPathId path_id;
950
[email protected]9db443912013-02-25 05:27:03951 // Entropy hash of all packets up to largest observed not including missing
952 // packets.
953 QuicPacketEntropyHash entropy_hash;
[email protected]e537f742012-12-07 15:33:53954
ckrasicea295fe2015-10-31 05:03:27955 // Whether the ack had to be truncated when sent.
956 bool is_truncated;
957
rtennetia004d332015-08-28 06:44:57958 // The highest packet number we've observed from the peer.
[email protected]48697d8a2013-01-15 19:42:24959 //
960 // In general, this should be the largest packet number we've received. In
961 // the case of truncated acks, we may have to advertise a lower "upper bound"
962 // than largest received, to avoid implicitly acking missing packets that
963 // don't fit in the missing packet list due to size limitations. In this
964 // case, largest_observed may be a packet which is also in the missing packets
965 // list.
rtennetia004d332015-08-28 06:44:57966 QuicPacketNumber largest_observed;
[email protected]a674b4c2012-12-05 03:44:30967
[email protected]14e8106c2013-03-14 16:25:33968 // Time elapsed since largest_observed was received until this Ack frame was
969 // sent.
rchcaec4242016-01-22 20:49:52970 QuicTime::Delta ack_delay_time;
[email protected]14e8106c2013-03-14 16:25:33971
ckrasicea295fe2015-10-31 05:03:27972 // Vector of <packet_number, time> for when packets arrived.
973 PacketTimeVector received_packet_times;
974
[email protected]e537f742012-12-07 15:33:53975 // The set of packets which we're expecting and have not received.
rtenneti493d90ef2015-09-14 04:43:11976 PacketNumberQueue missing_packets;
[email protected]8e01c062013-10-31 07:35:31977
rch99b644c2015-11-04 05:25:28978 // Packet most recently revived via FEC, 0 if no packet was revived by FEC.
979 // If non-zero, must be present in missing_packets.
980 QuicPacketNumber latest_revived_packet;
[email protected]8b37a092012-10-18 21:53:49981};
982
rtennetia004d332015-08-28 06:44:57983// True if the packet number is greater than largest_observed or is listed
[email protected]9db443912013-02-25 05:27:03984// as missing.
rtennetia004d332015-08-28 06:44:57985// Always returns false for packet numbers less than least_unacked.
986bool NET_EXPORT_PRIVATE IsAwaitingPacket(const QuicAckFrame& ack_frame,
987 QuicPacketNumber packet_number);
[email protected]9db443912013-02-25 05:27:03988
[email protected]a692ad9d2014-07-18 21:35:24989// Defines for all types of congestion control algorithms that can be used in
990// QUIC. Note that this is separate from the congestion feedback type -
991// some congestion control algorithms may use the same feedback type
992// (Reno and Cubic are the classic example for that).
993enum CongestionControlType {
994 kCubic,
rtennetifb3fa6c2015-03-16 23:04:55995 kCubicBytes,
[email protected]a692ad9d2014-07-18 21:35:24996 kReno,
rtennetifb3fa6c2015-03-16 23:04:55997 kRenoBytes,
[email protected]a692ad9d2014-07-18 21:35:24998 kBBR,
[email protected]8b37a092012-10-18 21:53:49999};
1000
[email protected]c5cc9bd2014-03-31 23:17:141001enum LossDetectionType {
1002 kNack, // Used to mimic TCP's loss detection.
1003 kTime, // Time based loss detection.
1004};
1005
[email protected]be24ab22012-10-22 03:01:521006struct NET_EXPORT_PRIVATE QuicRstStreamFrame {
[email protected]6ae6e342014-02-06 02:21:421007 QuicRstStreamFrame();
1008 QuicRstStreamFrame(QuicStreamId stream_id,
1009 QuicRstStreamErrorCode error_code,
1010 QuicStreamOffset bytes_written);
[email protected]8b37a092012-10-18 21:53:491011
[email protected]c5e1aca2014-01-30 04:03:041012 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:021013 std::ostream& os,
1014 const QuicRstStreamFrame& r);
[email protected]c5e1aca2014-01-30 04:03:041015
[email protected]8b37a092012-10-18 21:53:491016 QuicStreamId stream_id;
[email protected]74bda142013-03-31 02:49:111017 QuicRstStreamErrorCode error_code;
[email protected]6ae6e342014-02-06 02:21:421018
1019 // Used to update flow control windows. On termination of a stream, both
1020 // endpoints must inform the peer of the number of bytes they have sent on
1021 // that stream. This can be done through normal termination (data packet with
1022 // FIN) or through a RST.
1023 QuicStreamOffset byte_offset;
[email protected]8b37a092012-10-18 21:53:491024};
1025
[email protected]be24ab22012-10-22 03:01:521026struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame {
[email protected]6ae6e342014-02-06 02:21:421027 QuicConnectionCloseFrame();
1028
[email protected]c5e1aca2014-01-30 04:03:041029 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:021030 std::ostream& os,
1031 const QuicConnectionCloseFrame& c);
[email protected]c5e1aca2014-01-30 04:03:041032
[email protected]431bb4fd2012-10-19 17:46:091033 QuicErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:091034 std::string error_details;
[email protected]8b37a092012-10-18 21:53:491035};
1036
[email protected]9db443912013-02-25 05:27:031037struct NET_EXPORT_PRIVATE QuicGoAwayFrame {
[email protected]6ae6e342014-02-06 02:21:421038 QuicGoAwayFrame();
[email protected]9db443912013-02-25 05:27:031039 QuicGoAwayFrame(QuicErrorCode error_code,
1040 QuicStreamId last_good_stream_id,
1041 const std::string& reason);
1042
rjshaded5ced072015-12-18 19:26:021043 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
1044 const QuicGoAwayFrame& g);
[email protected]c5e1aca2014-01-30 04:03:041045
[email protected]9db443912013-02-25 05:27:031046 QuicErrorCode error_code;
1047 QuicStreamId last_good_stream_id;
1048 std::string reason_phrase;
1049};
1050
[email protected]6ae6e342014-02-06 02:21:421051// Flow control updates per-stream and at the connection levoel.
1052// Based on SPDY's WINDOW_UPDATE frame, but uses an absolute byte offset rather
1053// than a window delta.
1054// TODO(rjshade): A possible future optimization is to make stream_id and
1055// byte_offset variable length, similar to stream frames.
1056struct NET_EXPORT_PRIVATE QuicWindowUpdateFrame {
1057 QuicWindowUpdateFrame() {}
1058 QuicWindowUpdateFrame(QuicStreamId stream_id, QuicStreamOffset byte_offset);
1059
1060 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:021061 std::ostream& os,
1062 const QuicWindowUpdateFrame& w);
[email protected]6ae6e342014-02-06 02:21:421063
1064 // The stream this frame applies to. 0 is a special case meaning the overall
1065 // connection rather than a specific stream.
1066 QuicStreamId stream_id;
1067
1068 // Byte offset in the stream or connection. The receiver of this frame must
1069 // not send data which would result in this offset being exceeded.
1070 QuicStreamOffset byte_offset;
1071};
1072
1073// The BLOCKED frame is used to indicate to the remote endpoint that this
1074// endpoint believes itself to be flow-control blocked but otherwise ready to
1075// send data. The BLOCKED frame is purely advisory and optional.
1076// Based on SPDY's BLOCKED frame (undocumented as of 2014-01-28).
1077struct NET_EXPORT_PRIVATE QuicBlockedFrame {
1078 QuicBlockedFrame() {}
1079 explicit QuicBlockedFrame(QuicStreamId stream_id);
1080
rjshaded5ced072015-12-18 19:26:021081 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
1082 const QuicBlockedFrame& b);
[email protected]6ae6e342014-02-06 02:21:421083
1084 // The stream this frame applies to. 0 is a special case meaning the overall
1085 // connection rather than a specific stream.
1086 QuicStreamId stream_id;
1087};
1088
rchcaec4242016-01-22 20:49:521089// The PATH_CLOSE frame is used to explicitly close a path. Both endpoints can
1090// send a PATH_CLOSE frame to initiate a path termination. A path is considered
1091// to be closed either a PATH_CLOSE frame is sent or received. An endpoint drops
1092// receive side of a closed path, and packets with retransmittable frames on a
1093// closed path are marked as retransmissions which will be transmitted on other
1094// paths.
1095struct NET_EXPORT_PRIVATE QuicPathCloseFrame {
1096 QuicPathCloseFrame() {}
1097 explicit QuicPathCloseFrame(QuicPathId path_id);
1098
1099 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
1100 std::ostream& os,
1101 const QuicPathCloseFrame& p);
1102
1103 QuicPathId path_id;
1104};
1105
[email protected]8ba81212013-05-03 13:11:481106// EncryptionLevel enumerates the stages of encryption that a QUIC connection
1107// progresses through. When retransmitting a packet, the encryption level needs
1108// to be specified so that it is retransmitted at a level which the peer can
1109// understand.
1110enum EncryptionLevel {
1111 ENCRYPTION_NONE = 0,
1112 ENCRYPTION_INITIAL = 1,
1113 ENCRYPTION_FORWARD_SECURE = 2,
1114
1115 NUM_ENCRYPTION_LEVELS,
1116};
1117
rch99b644c2015-11-04 05:25:281118enum PeerAddressChangeType {
1119 NO_CHANGE,
1120 // Peer address changes which are considered to be cause by NATs. Currently,
1121 // IPv4 address change with /24 does not change is considered to be cause by
1122 // NATs.
1123 NAT_PORT_REBINDING,
1124 IPV4_SUBNET_REBINDING,
1125 // IPv6 related address changes.
1126 IPV4_TO_IPV6,
1127 IPV6_TO_IPV4,
1128 IPV6_TO_IPV6,
1129 // This type is used when we always allow peer address changes.
1130 UNKNOWN,
1131 // All other peer address change types.
1132 UNSPECIFIED,
1133};
1134
[email protected]be24ab22012-10-22 03:01:521135struct NET_EXPORT_PRIVATE QuicFrame {
[email protected]6ae6e342014-02-06 02:21:421136 QuicFrame();
rtenneti5ca6eee2015-10-15 21:54:301137 explicit QuicFrame(QuicPaddingFrame padding_frame);
1138 explicit QuicFrame(QuicMtuDiscoveryFrame frame);
1139 explicit QuicFrame(QuicPingFrame frame);
1140
[email protected]6ae6e342014-02-06 02:21:421141 explicit QuicFrame(QuicStreamFrame* stream_frame);
1142 explicit QuicFrame(QuicAckFrame* frame);
[email protected]6ae6e342014-02-06 02:21:421143 explicit QuicFrame(QuicRstStreamFrame* frame);
1144 explicit QuicFrame(QuicConnectionCloseFrame* frame);
[email protected]93dd91f2014-02-27 00:09:031145 explicit QuicFrame(QuicStopWaitingFrame* frame);
[email protected]6ae6e342014-02-06 02:21:421146 explicit QuicFrame(QuicGoAwayFrame* frame);
1147 explicit QuicFrame(QuicWindowUpdateFrame* frame);
1148 explicit QuicFrame(QuicBlockedFrame* frame);
rchcaec4242016-01-22 20:49:521149 explicit QuicFrame(QuicPathCloseFrame* frame);
[email protected]8b37a092012-10-18 21:53:491150
rjshaded5ced072015-12-18 19:26:021151 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
1152 const QuicFrame& frame);
[email protected]c5e1aca2014-01-30 04:03:041153
[email protected]be24ab22012-10-22 03:01:521154 QuicFrameType type;
[email protected]8b37a092012-10-18 21:53:491155 union {
rtenneti5ca6eee2015-10-15 21:54:301156 // Frames smaller than a pointer are inline.
1157 QuicPaddingFrame padding_frame;
1158 QuicMtuDiscoveryFrame mtu_discovery_frame;
1159 QuicPingFrame ping_frame;
1160
1161 // Frames larger than a pointer.
[email protected]be24ab22012-10-22 03:01:521162 QuicStreamFrame* stream_frame;
1163 QuicAckFrame* ack_frame;
[email protected]93dd91f2014-02-27 00:09:031164 QuicStopWaitingFrame* stop_waiting_frame;
[email protected]be24ab22012-10-22 03:01:521165 QuicRstStreamFrame* rst_stream_frame;
1166 QuicConnectionCloseFrame* connection_close_frame;
[email protected]9db443912013-02-25 05:27:031167 QuicGoAwayFrame* goaway_frame;
[email protected]6ae6e342014-02-06 02:21:421168 QuicWindowUpdateFrame* window_update_frame;
1169 QuicBlockedFrame* blocked_frame;
rchcaec4242016-01-22 20:49:521170 QuicPathCloseFrame* path_close_frame;
[email protected]8b37a092012-10-18 21:53:491171 };
1172};
rtenneti5ca6eee2015-10-15 21:54:301173// QuicFrameType consumes 8 bytes with padding.
1174static_assert(sizeof(QuicFrame) <= 16,
1175 "Frames larger than 8 bytes should be referenced by pointer.");
[email protected]8b37a092012-10-18 21:53:491176
[email protected]be24ab22012-10-22 03:01:521177typedef std::vector<QuicFrame> QuicFrames;
[email protected]8b37a092012-10-18 21:53:491178
[email protected]8b37a092012-10-18 21:53:491179class NET_EXPORT_PRIVATE QuicData {
1180 public:
[email protected]6ae6e342014-02-06 02:21:421181 QuicData(const char* buffer, size_t length);
1182 QuicData(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:491183 virtual ~QuicData();
1184
1185 base::StringPiece AsStringPiece() const {
1186 return base::StringPiece(data(), length());
1187 }
1188
1189 const char* data() const { return buffer_; }
1190 size_t length() const { return length_; }
rtennetie0ee6eb2015-05-01 00:55:091191 bool owns_buffer() const { return owns_buffer_; }
[email protected]8b37a092012-10-18 21:53:491192
1193 private:
1194 const char* buffer_;
1195 size_t length_;
1196 bool owns_buffer_;
1197
1198 DISALLOW_COPY_AND_ASSIGN(QuicData);
1199};
1200
1201class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
1202 public:
rchcaec4242016-01-22 20:49:521203 // TODO(fayang): 4 fields from public header are passed in as arguments.
1204 // Consider to add a convenience method which directly accepts the entire
1205 // public header.
rtennetica5ac272015-02-07 12:35:121206 QuicPacket(char* buffer,
1207 size_t length,
1208 bool owns_buffer,
1209 QuicConnectionIdLength connection_id_length,
1210 bool includes_version,
rchcaec4242016-01-22 20:49:521211 bool includes_path_id,
rtennetia004d332015-08-28 06:44:571212 QuicPacketNumberLength packet_number_length);
[email protected]8b37a092012-10-18 21:53:491213
[email protected]5351cc4b2013-03-03 07:22:411214 base::StringPiece FecProtectedData() const;
1215 base::StringPiece AssociatedData() const;
[email protected]5351cc4b2013-03-03 07:22:411216 base::StringPiece Plaintext() const;
[email protected]082b65b2012-11-10 19:11:311217
[email protected]8b37a092012-10-18 21:53:491218 char* mutable_data() { return buffer_; }
1219
1220 private:
1221 char* buffer_;
[email protected]3aa9ca72014-02-27 19:39:431222 const QuicConnectionIdLength connection_id_length_;
[email protected]5351cc4b2013-03-03 07:22:411223 const bool includes_version_;
rchcaec4242016-01-22 20:49:521224 const bool includes_path_id_;
rtennetia004d332015-08-28 06:44:571225 const QuicPacketNumberLength packet_number_length_;
[email protected]8b37a092012-10-18 21:53:491226
[email protected]2e740db2012-10-20 19:35:191227 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
[email protected]8b37a092012-10-18 21:53:491228};
1229
1230class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
1231 public:
[email protected]6ae6e342014-02-06 02:21:421232 QuicEncryptedPacket(const char* buffer, size_t length);
1233 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:491234
[email protected]ec86d5462013-11-17 16:04:491235 // Clones the packet into a new packet which owns the buffer.
1236 QuicEncryptedPacket* Clone() const;
1237
[email protected]c1b32c62013-01-20 02:49:101238 // By default, gtest prints the raw bytes of an object. The bool data
1239 // member (in the base class QuicData) causes this object to have padding
1240 // bytes, which causes the default gtest object printer to read
1241 // uninitialize memory. So we need to teach gtest how to print this object.
1242 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:021243 std::ostream& os,
1244 const QuicEncryptedPacket& s);
[email protected]c1b32c62013-01-20 02:49:101245
[email protected]2e740db2012-10-20 19:35:191246 private:
1247 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
[email protected]8b37a092012-10-18 21:53:491248};
1249
[email protected]9db443912013-02-25 05:27:031250class NET_EXPORT_PRIVATE RetransmittableFrames {
1251 public:
jokulik2324d282015-12-08 21:42:571252 RetransmittableFrames();
[email protected]9db443912013-02-25 05:27:031253 ~RetransmittableFrames();
1254
[email protected]9db443912013-02-25 05:27:031255 // Takes ownership of the frame inside |frame|.
rtennetia4228ea2015-06-04 02:31:441256 const QuicFrame& AddFrame(const QuicFrame& frame);
rtenneti73e25c12015-03-16 06:12:431257 // Removes all stream frames associated with |stream_id|.
1258 void RemoveFramesForStream(QuicStreamId stream_id);
rchcaec4242016-01-22 20:49:521259 // Swaps the frames from RetransmittableFrames into |destination_frames|.
1260 void SwapFrames(QuicFrames* destination_frames);
rtenneti73e25c12015-03-16 06:12:431261
[email protected]9db443912013-02-25 05:27:031262 const QuicFrames& frames() const { return frames_; }
1263
rjshaded5ced072015-12-18 19:26:021264 IsHandshake HasCryptoHandshake() const { return has_crypto_handshake_; }
[email protected]2115d33ba2014-01-02 21:53:521265
rtennetid7d78b02015-06-17 16:54:341266 bool needs_padding() const { return needs_padding_; }
1267
1268 void set_needs_padding(bool needs_padding) { needs_padding_ = needs_padding; }
1269
[email protected]9db443912013-02-25 05:27:031270 private:
1271 QuicFrames frames_;
[email protected]672631c2014-08-16 06:11:451272 IsHandshake has_crypto_handshake_;
rtennetid7d78b02015-06-17 16:54:341273 bool needs_padding_;
[email protected]9db443912013-02-25 05:27:031274
1275 DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames);
1276};
1277
rtenneti8dd12b22015-10-21 01:26:381278struct NET_EXPORT_PRIVATE AckListenerWrapper {
1279 AckListenerWrapper(QuicAckListenerInterface* listener,
1280 QuicPacketLength data_length);
1281 ~AckListenerWrapper();
1282
1283 scoped_refptr<QuicAckListenerInterface> ack_listener;
1284 QuicPacketLength length;
1285};
1286
[email protected]9db443912013-02-25 05:27:031287struct NET_EXPORT_PRIVATE SerializedPacket {
fayanga31a74b2015-12-28 17:27:141288 SerializedPacket(QuicPathId path_id,
1289 QuicPacketNumber packet_number,
rtennetia004d332015-08-28 06:44:571290 QuicPacketNumberLength packet_number_length,
rtennetib6ac61a52015-02-11 20:20:521291 QuicEncryptedPacket* packet,
[email protected]9db443912013-02-25 05:27:031292 QuicPacketEntropyHash entropy_hash,
rtenneti9bd5d4b2015-08-21 05:44:521293 RetransmittableFrames* retransmittable_frames,
1294 bool has_ack,
1295 bool has_stop_waiting);
fayanga31a74b2015-12-28 17:27:141296 SerializedPacket(QuicPathId path_id,
1297 QuicPacketNumber packet_number,
rch99b644c2015-11-04 05:25:281298 QuicPacketNumberLength packet_number_length,
1299 char* encrypted_buffer,
1300 size_t encrypted_length,
1301 bool owns_buffer,
1302 QuicPacketEntropyHash entropy_hash,
1303 RetransmittableFrames* retransmittable_frames,
1304 bool has_ack,
jokulik2324d282015-12-08 21:42:571305 bool has_stop_waiting,
1306 EncryptionLevel level);
[email protected]97cf3022013-09-05 14:30:161307 ~SerializedPacket();
[email protected]9db443912013-02-25 05:27:031308
rtennetid39bd762015-06-12 01:05:521309 QuicEncryptedPacket* packet;
1310 RetransmittableFrames* retransmittable_frames;
fayanga31a74b2015-12-28 17:27:141311 QuicPathId path_id;
rtennetia004d332015-08-28 06:44:571312 QuicPacketNumber packet_number;
1313 QuicPacketNumberLength packet_number_length;
jokulik2324d282015-12-08 21:42:571314 EncryptionLevel encryption_level;
[email protected]9db443912013-02-25 05:27:031315 QuicPacketEntropyHash entropy_hash;
rtennetica5ac272015-02-07 12:35:121316 bool is_fec_packet;
rtenneti9bd5d4b2015-08-21 05:44:521317 bool has_ack;
1318 bool has_stop_waiting;
zhongyi4a9d27b2016-01-12 20:08:311319 QuicPacketNumber original_packet_number;
1320 TransmissionType transmission_type;
[email protected]97cf3022013-09-05 14:30:161321
rtenneti6b1c5b12015-01-13 20:08:351322 // Optional notifiers which will be informed when this packet has been ACKed.
rtenneti8dd12b22015-10-21 01:26:381323 std::list<AckListenerWrapper> listeners;
[email protected]9db443912013-02-25 05:27:031324};
1325
[email protected]77b5d50b2014-05-07 22:48:481326struct NET_EXPORT_PRIVATE TransmissionInfo {
1327 // Used by STL when assigning into a map.
1328 TransmissionInfo();
1329
rchcaec4242016-01-22 20:49:521330 // Constructs a Transmission with a new all_transmissions set
rtennetia004d332015-08-28 06:44:571331 // containing |packet_number|.
rchcaec4242016-01-22 20:49:521332 TransmissionInfo(EncryptionLevel level,
rtennetia004d332015-08-28 06:44:571333 QuicPacketNumberLength packet_number_length,
[email protected]730b35d72014-06-05 03:23:221334 TransmissionType transmission_type,
rtenneti3183ac42015-02-28 03:39:411335 QuicTime sent_time,
rtenneti5ca6eee2015-10-15 21:54:301336 QuicPacketLength bytes_sent,
rchcaec4242016-01-22 20:49:521337 bool is_fec_packet,
1338 bool has_crypto_handshake,
1339 bool needs_padding);
[email protected]77b5d50b2014-05-07 22:48:481340
rtenneti8dd12b22015-10-21 01:26:381341 ~TransmissionInfo();
1342
rchcaec4242016-01-22 20:49:521343 QuicFrames retransmittable_frames;
jokulik2324d282015-12-08 21:42:571344 EncryptionLevel encryption_level;
rtennetia004d332015-08-28 06:44:571345 QuicPacketNumberLength packet_number_length;
rtenneti5ca6eee2015-10-15 21:54:301346 QuicPacketLength bytes_sent;
Avi Drissman13fc8932015-12-20 04:40:461347 uint16_t nack_count;
[email protected]77b5d50b2014-05-07 22:48:481348 QuicTime sent_time;
[email protected]730b35d72014-06-05 03:23:221349 // Reason why this packet was transmitted.
1350 TransmissionType transmission_type;
[email protected]aa7e4ef2014-05-28 03:53:151351 // In flight packets have not been abandoned or lost.
1352 bool in_flight;
rtenneti31e9fd62014-09-16 05:22:151353 // True if the packet can never be acked, so it can be removed.
1354 bool is_unackable;
rtenneti85d89712014-11-20 03:32:241355 // True if the packet is an FEC packet.
1356 bool is_fec_packet;
rchcaec4242016-01-22 20:49:521357 // True if the packet contains stream data from the crypto stream.
1358 bool has_crypto_handshake;
1359 // True if the packet needs padding if it's retransmitted.
1360 bool needs_padding;
rtenneti5ca6eee2015-10-15 21:54:301361 // Stores the packet numbers of all transmissions of this packet.
1362 // Must always be nullptr or have multiple elements.
zhongyi1fb9bc52015-11-24 23:09:421363 // TODO(ianswett): Deprecate with quic_track_single_retransmission.
rtenneti5ca6eee2015-10-15 21:54:301364 PacketNumberList* all_transmissions;
zhongyi1fb9bc52015-11-24 23:09:421365 // Stores the packet number of the next retransmission of this packet.
1366 // Zero if the packet has not been retransmitted.
1367 QuicPacketNumber retransmission;
rtenneti8dd12b22015-10-21 01:26:381368 // Non-empty if there is a listener for this packet.
1369 std::list<AckListenerWrapper> ack_listeners;
[email protected]77b5d50b2014-05-07 22:48:481370};
rtenneti8dd12b22015-10-21 01:26:381371static_assert(sizeof(QuicFrame) <= 64,
1372 "Keep the TransmissionInfo size to a cacheline.");
[email protected]77b5d50b2014-05-07 22:48:481373
rchcaec4242016-01-22 20:49:521374// Struct to store the pending retransmission information.
1375struct PendingRetransmission {
1376 PendingRetransmission(QuicPathId path_id,
1377 QuicPacketNumber packet_number,
1378 TransmissionType transmission_type,
1379 const QuicFrames& retransmittable_frames,
1380 bool has_crypto_handshake,
1381 bool needs_padding,
1382 EncryptionLevel encryption_level,
1383 QuicPacketNumberLength packet_number_length)
1384 : path_id(path_id),
1385 packet_number(packet_number),
1386 transmission_type(transmission_type),
1387 retransmittable_frames(retransmittable_frames),
1388 has_crypto_handshake(has_crypto_handshake),
1389 needs_padding(needs_padding),
1390 encryption_level(encryption_level),
1391 packet_number_length(packet_number_length) {}
1392
1393 QuicPathId path_id;
1394 QuicPacketNumber packet_number;
1395 TransmissionType transmission_type;
1396 const QuicFrames& retransmittable_frames;
1397 bool has_crypto_handshake;
1398 bool needs_padding;
1399 EncryptionLevel encryption_level;
1400 QuicPacketNumberLength packet_number_length;
1401};
1402
rtennetic14c8ab2015-06-18 05:47:401403// Convenience wrapper to wrap an iovec array and the total length, which must
1404// be less than or equal to the actual total length of the iovecs.
1405struct NET_EXPORT_PRIVATE QuicIOVector {
1406 QuicIOVector(const struct iovec* iov, int iov_count, size_t total_length)
1407 : iov(iov), iov_count(iov_count), total_length(total_length) {}
1408
1409 const struct iovec* iov;
1410 const int iov_count;
1411 const size_t total_length;
1412};
1413
[email protected]8b37a092012-10-18 21:53:491414} // namespace net
1415
1416#endif // NET_QUIC_QUIC_PROTOCOL_H_