blob: 3f69ce3082485b6680818c2dcb9d7d37cb7434d3 [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>
[email protected]8b37a092012-10-18 21:53:4910#include <limits>
rtenneti4b06ae72014-08-26 03:43:4311#include <list>
[email protected]a674b4c2012-12-05 03:44:3012#include <map>
[email protected]5640d0a2012-10-22 18:17:0213#include <ostream>
[email protected]e537f742012-12-07 15:33:5314#include <set>
15#include <string>
[email protected]8b37a092012-10-18 21:53:4916#include <utility>
17#include <vector>
18
19#include "base/basictypes.h"
[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"
[email protected]d069c11a2013-04-13 00:01:5522#include "base/strings/string_piece.h"
[email protected]165e0752012-11-16 07:49:4423#include "net/base/int128.h"
[email protected]79d13dcb2014-02-05 07:23:1324#include "net/base/ip_endpoint.h"
[email protected]8b37a092012-10-18 21:53:4925#include "net/base/net_export.h"
[email protected]5dafdb62013-11-14 01:24:2626#include "net/quic/iovector.h"
[email protected]fee17f72013-02-03 07:47:4127#include "net/quic/quic_bandwidth.h"
[email protected]2a960e02012-11-11 14:48:1028#include "net/quic/quic_time.h"
[email protected]8b37a092012-10-18 21:53:4929
30namespace net {
31
[email protected]97cf3022013-09-05 14:30:1632class QuicAckNotifier;
[email protected]8b37a092012-10-18 21:53:4933class QuicPacket;
[email protected]b064310782013-05-30 21:12:1734struct QuicPacketHeader;
[email protected]8b37a092012-10-18 21:53:4935
[email protected]3aa9ca72014-02-27 19:39:4336typedef uint64 QuicConnectionId;
[email protected]8b37a092012-10-18 21:53:4937typedef uint32 QuicStreamId;
38typedef uint64 QuicStreamOffset;
39typedef uint64 QuicPacketSequenceNumber;
[email protected]c995c572013-01-18 05:43:2040typedef QuicPacketSequenceNumber QuicFecGroupNumber;
[email protected]86a318d2013-01-23 21:16:0441typedef uint64 QuicPublicResetNonceProof;
[email protected]9db443912013-02-25 05:27:0342typedef uint8 QuicPacketEntropyHash;
[email protected]c244c5a12013-05-07 20:55:0443typedef uint32 QuicHeaderId;
[email protected]2532de12013-05-09 12:29:3344// QuicTag is the type of a tag in the wire protocol.
45typedef uint32 QuicTag;
46typedef std::vector<QuicTag> QuicTagVector;
[email protected]79d13dcb2014-02-05 07:23:1347typedef std::map<QuicTag, std::string> QuicTagValueMap;
[email protected]497bfb22014-01-08 01:28:0348// TODO(rtenneti): Didn't use SpdyPriority because SpdyPriority is uint8 and
49// QuicPriority is uint32. Use SpdyPriority when we change the QUIC_VERSION.
[email protected]8edeb8d2013-08-28 06:11:4350typedef uint32 QuicPriority;
[email protected]cff7b7b2013-01-11 08:49:0751
[email protected]8e01c062013-10-31 07:35:3152// Default and initial maximum size in bytes of a QUIC packet.
[email protected]310d37b2014-08-02 06:15:3753const QuicByteCount kDefaultMaxPacketSize = 1350;
rtenneti16a20772015-02-17 18:58:4854// Default initial maximum size in bytes of a QUIC packet for servers.
55const QuicByteCount kDefaultServerMaxPacketSize = 1000;
[email protected]8e01c062013-10-31 07:35:3156// The maximum packet size of any QUIC packet, based on ethernet's max size,
[email protected]41fb6372013-12-10 05:26:4057// minus the IP and UDP headers. IPv6 has a 40 byte header, UPD adds an
58// additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's
59// max packet size is 1500 bytes, 1500 - 48 = 1452.
60const QuicByteCount kMaxPacketSize = 1452;
rtenneti9e0fb502015-03-08 06:07:1661// Default maximum packet size used in the Linux TCP implementation.
62// Used in QUIC for congestion window computations in bytes.
[email protected]ce7bb1412014-05-17 15:51:3363const QuicByteCount kDefaultTCPMSS = 1460;
[email protected]8e01c062013-10-31 07:35:3164
rtenneti3fe4ebbc2014-11-16 16:43:4765// We match SPDY's use of 32 when secure (since we'd compete with SPDY).
66const QuicPacketCount kInitialCongestionWindowSecure = 32;
67// Be conservative, and just use double a typical TCP ICWND for HTTP.
68const QuicPacketCount kInitialCongestionWindowInsecure = 20;
[email protected]8e01c062013-10-31 07:35:3169
rtenneti7652bf32015-01-05 18:51:0770// Minimum size of initial flow control window, for both stream and session.
71const uint32 kMinimumFlowControlSendWindow = 16 * 1024; // 16 KB
[email protected]9bb57c72014-03-31 20:36:0472
rtennetifb3fa6c2015-03-16 23:04:5573// Minimum size of the CWND, in packets, when doing bandwidth resumption.
rtenneti8d2a808d2014-11-26 01:10:0974const QuicPacketCount kMinCongestionWindowForBandwidthResumption = 10;
75
rtennetifb3fa6c2015-03-16 23:04:5576// Maximum size of the CWND, in packets, for TCP congestion control algorithms.
77const QuicPacketCount kMaxTcpCongestionWindow = 200;
[email protected]0ac0c5b2013-11-20 05:55:5878
rtenneti23186682014-10-30 01:49:3379// Default size of the socket receive buffer in bytes.
[email protected]648f81142014-08-15 21:38:4680const QuicByteCount kDefaultSocketReceiveBuffer = 256 * 1024;
rtenneti23186682014-10-30 01:49:3381// Minimum size of the socket receive buffer in bytes.
82// Smaller values are ignored.
83const QuicByteCount kMinSocketReceiveBuffer = 16 * 1024;
[email protected]a97b3182014-08-08 08:10:1884
rtenneti95293802015-03-27 18:59:2385// Fraction of the receive buffer that can be used for encrypted bytes.
86// Allows a 5% overhead for IP and UDP framing, as well as ack only packets.
87static const float kUsableRecieveBufferFraction = 0.95f;
88
rtennetifc97ab62014-11-11 22:17:4989// Don't allow a client to suggest an RTT shorter than 10ms.
90const uint32 kMinInitialRoundTripTimeUs = 10 * kNumMicrosPerMilli;
91
[email protected]8e01c062013-10-31 07:35:3192// Don't allow a client to suggest an RTT longer than 15 seconds.
[email protected]2d43c40122014-04-21 14:51:2793const uint32 kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond;
[email protected]8b37a092012-10-18 21:53:4994
95// Maximum number of open streams per connection.
96const size_t kDefaultMaxStreamsPerConnection = 100;
97
[email protected]af806e62013-05-22 14:47:5098// Number of bytes reserved for public flags in the packet header.
99const size_t kPublicFlagsSize = 1;
[email protected]5351cc4b2013-03-03 07:22:41100// Number of bytes reserved for version number in the packet header.
101const size_t kQuicVersionSize = 4;
[email protected]c995c572013-01-18 05:43:20102// Number of bytes reserved for private flags in the packet header.
103const size_t kPrivateFlagsSize = 1;
104// Number of bytes reserved for FEC group in the packet header.
105const size_t kFecGroupSize = 1;
[email protected]5351cc4b2013-03-03 07:22:41106
107// Signifies that the QuicPacket will contain version of the protocol.
108const bool kIncludeVersion = true;
[email protected]c995c572013-01-18 05:43:20109
[email protected]5351cc4b2013-03-03 07:22:41110// Index of the first byte in a QUIC packet which is used in hash calculation.
111const size_t kStartOfHashData = 0;
[email protected]8b37a092012-10-18 21:53:49112
113// Limit on the delta between stream IDs.
[email protected]c5cc9bd2014-03-31 23:17:14114const QuicStreamId kMaxStreamIdDelta = 200;
[email protected]8b37a092012-10-18 21:53:49115
116// Reserved ID for the crypto stream.
[email protected]8b37a092012-10-18 21:53:49117const QuicStreamId kCryptoStreamId = 1;
118
[email protected]4d640792013-12-18 22:21:08119// Reserved ID for the headers stream.
120const QuicStreamId kHeadersStreamId = 3;
121
[email protected]648f81142014-08-15 21:38:46122// Maximum delayed ack time, in ms.
pkastingacec86f2014-10-14 23:08:55123const int64 kMaxDelayedAckTimeMs = 25;
[email protected]648f81142014-08-15 21:38:46124
rtennetib5512bb2014-09-29 19:17:15125// The timeout before the handshake succeeds.
126const int64 kInitialIdleTimeoutSecs = 5;
127// The default idle timeout.
128const int64 kDefaultIdleTimeoutSecs = 30;
rtenneti31e9fd62014-09-16 05:22:15129// The maximum idle timeout that can be negotiated.
130const int64 kMaximumIdleTimeoutSecs = 60 * 10; // 10 minutes.
131// The default timeout for a connection until the crypto handshake succeeds.
rtennetib5512bb2014-09-29 19:17:15132const int64 kMaxTimeForCryptoHandshakeSecs = 10; // 10 secs.
[email protected]8b37a092012-10-18 21:53:49133
rtenneti93bce7ece2014-10-13 22:38:41134// Default limit on the number of undecryptable packets the connection buffers
135// before the CHLO/SHLO arrive.
136const size_t kDefaultMaxUndecryptablePackets = 10;
137
[email protected]525948df2014-04-21 06:26:58138// Default ping timeout.
139const int64 kPingTimeoutSecs = 15; // 15 secs.
140
[email protected]ca4e0d92014-08-22 16:33:22141// Minimum number of RTTs between Server Config Updates (SCUP) sent to client.
142const int kMinIntervalBetweenServerConfigUpdatesRTTs = 10;
143
144// Minimum time between Server Config Updates (SCUP) sent to client.
145const int kMinIntervalBetweenServerConfigUpdatesMs = 1000;
146
rtenneti33da8ab2014-11-04 04:17:00147// Minimum number of packets between Server Config Updates (SCUP).
148const int kMinPacketsBetweenServerConfigUpdates = 100;
149
rtennetib5512bb2014-09-29 19:17:15150// The number of open streams that a server will accept is set to be slightly
151// larger than the negotiated limit. Immediately closing the connection if the
152// client opens slightly too many streams is not ideal: the client may have sent
153// a FIN that was lost, and simultaneously opened a new stream. The number of
154// streams a server accepts is a fixed increment over the negotiated limit, or a
155// percentage increase, whichever is larger.
rtenneti31e9fd62014-09-16 05:22:15156const float kMaxStreamsMultiplier = 1.1f;
rtennetib5512bb2014-09-29 19:17:15157const int kMaxStreamsMinimumIncrement = 10;
rtenneti31e9fd62014-09-16 05:22:15158
[email protected]b007e632013-10-28 08:39:25159// We define an unsigned 16-bit floating point value, inspired by IEEE floats
160// (http://en.wikipedia.org/wiki/Half_precision_floating-point_format),
161// with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden
162// bit) and denormals, but without signs, transfinites or fractions. Wire format
163// 16 bits (little-endian byte order) are split into exponent (high 5) and
164// mantissa (low 11) and decoded as:
165// uint64 value;
166// if (exponent == 0) value = mantissa;
167// else value = (mantissa | 1 << 11) << (exponent - 1)
168const int kUFloat16ExponentBits = 5;
169const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30
170const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11
171const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12
172const uint64 kUFloat16MaxValue = // 0x3FFC0000000
tfarina3723da22015-06-03 21:39:30173 ((UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1) <<
[email protected]b007e632013-10-28 08:39:25174 kUFloat16MaxExponent;
175
[email protected]c67a82cb2013-09-24 02:53:21176enum TransmissionType {
[email protected]2532de12013-05-09 12:29:33177 NOT_RETRANSMISSION,
[email protected]b9475b582014-03-20 20:04:33178 FIRST_TRANSMISSION_TYPE = NOT_RETRANSMISSION,
179 HANDSHAKE_RETRANSMISSION, // Retransmits due to handshake timeouts.
rtenneti31e9fd62014-09-16 05:22:15180 ALL_UNACKED_RETRANSMISSION, // Retransmits all unacked packets.
181 ALL_INITIAL_RETRANSMISSION, // Retransmits all initially encrypted packets.
[email protected]b9475b582014-03-20 20:04:33182 LOSS_RETRANSMISSION, // Retransmits due to loss detection.
183 RTO_RETRANSMISSION, // Retransmits due to retransmit time out.
184 TLP_RETRANSMISSION, // Tail loss probes.
185 LAST_TRANSMISSION_TYPE = TLP_RETRANSMISSION,
[email protected]74bda142013-03-31 02:49:11186};
187
188enum HasRetransmittableData {
[email protected]2532de12013-05-09 12:29:33189 NO_RETRANSMITTABLE_DATA,
190 HAS_RETRANSMITTABLE_DATA,
[email protected]74bda142013-03-31 02:49:11191};
192
[email protected]575cce62013-08-03 02:06:43193enum IsHandshake {
194 NOT_HANDSHAKE,
195 IS_HANDSHAKE
196};
197
rtenneti6f48aa92015-03-16 02:18:48198enum class Perspective { IS_SERVER, IS_CLIENT };
199
200NET_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
201 const Perspective& s);
202
[email protected]bbb10072014-06-13 07:41:59203// Indicates FEC protection level for data being written.
204enum FecProtection {
205 MUST_FEC_PROTECT, // Callee must FEC protect this data.
[email protected]a5b98172014-06-18 07:01:59206 MAY_FEC_PROTECT // Callee does not have to but may FEC protect this data.
207};
208
[email protected]bc356fe2014-06-19 11:14:14209// Indicates FEC policy.
[email protected]a5b98172014-06-18 07:01:59210enum FecPolicy {
211 FEC_PROTECT_ALWAYS, // All data in the stream should be FEC protected.
212 FEC_PROTECT_OPTIONAL // Data in the stream does not need FEC protection.
[email protected]bbb10072014-06-13 07:41:59213};
214
rtennetia4228ea2015-06-04 02:31:44215// Indicates FEC policy about when to send FEC packet.
216enum FecSendPolicy {
217 // Send FEC packet when FEC group is full or when FEC alarm goes off.
218 FEC_ANY_TRIGGER,
219 // Send FEC packet only when FEC alarm goes off.
220 FEC_ALARM_TRIGGER
221};
222
[email protected]be24ab22012-10-22 03:01:52223enum QuicFrameType {
[email protected]6ae6e342014-02-06 02:21:42224 // Regular frame types. The values set here cannot change without the
225 // introduction of a new QUIC version.
[email protected]c995c572013-01-18 05:43:20226 PADDING_FRAME = 0,
[email protected]6ae6e342014-02-06 02:21:42227 RST_STREAM_FRAME = 1,
228 CONNECTION_CLOSE_FRAME = 2,
229 GOAWAY_FRAME = 3,
230 WINDOW_UPDATE_FRAME = 4,
231 BLOCKED_FRAME = 5,
[email protected]93dd91f2014-02-27 00:09:03232 STOP_WAITING_FRAME = 6,
[email protected]d8c522112014-04-23 09:23:25233 PING_FRAME = 7,
[email protected]6ae6e342014-02-06 02:21:42234
rtennetif4bdb542015-01-21 14:33:05235 // STREAM and ACK frames are special frames. They are encoded differently on
236 // the wire and their values do not need to be stable.
[email protected]97cf3022013-09-05 14:30:16237 STREAM_FRAME,
238 ACK_FRAME,
[email protected]be24ab22012-10-22 03:01:52239 NUM_FRAME_TYPES
[email protected]8b37a092012-10-18 21:53:49240};
241
[email protected]3aa9ca72014-02-27 19:39:43242enum QuicConnectionIdLength {
243 PACKET_0BYTE_CONNECTION_ID = 0,
244 PACKET_1BYTE_CONNECTION_ID = 1,
245 PACKET_4BYTE_CONNECTION_ID = 4,
246 PACKET_8BYTE_CONNECTION_ID = 8
[email protected]b064310782013-05-30 21:12:17247};
248
249enum InFecGroup {
250 NOT_IN_FEC_GROUP,
251 IN_FEC_GROUP,
252};
253
[email protected]25c31dc2013-06-05 17:56:04254enum QuicSequenceNumberLength {
255 PACKET_1BYTE_SEQUENCE_NUMBER = 1,
256 PACKET_2BYTE_SEQUENCE_NUMBER = 2,
257 PACKET_4BYTE_SEQUENCE_NUMBER = 4,
258 PACKET_6BYTE_SEQUENCE_NUMBER = 6
259};
260
[email protected]8e01c062013-10-31 07:35:31261// Used to indicate a QuicSequenceNumberLength using two flag bits.
262enum QuicSequenceNumberLengthFlags {
263 PACKET_FLAGS_1BYTE_SEQUENCE = 0, // 00
264 PACKET_FLAGS_2BYTE_SEQUENCE = 1, // 01
265 PACKET_FLAGS_4BYTE_SEQUENCE = 1 << 1, // 10
266 PACKET_FLAGS_6BYTE_SEQUENCE = 1 << 1 | 1, // 11
267};
268
[email protected]f62262b2013-07-05 20:57:30269// The public flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20270enum QuicPacketPublicFlags {
271 PACKET_PUBLIC_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30272
273 // Bit 0: Does the packet header contains version info?
274 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0,
275
276 // Bit 1: Is this packet a public reset packet?
277 PACKET_PUBLIC_FLAGS_RST = 1 << 1,
278
[email protected]3aa9ca72014-02-27 19:39:43279 // Bits 2 and 3 specify the length of the ConnectionId as follows:
[email protected]f62262b2013-07-05 20:57:30280 // ----00--: 0 bytes
281 // ----01--: 1 byte
282 // ----10--: 4 bytes
283 // ----11--: 8 bytes
[email protected]3aa9ca72014-02-27 19:39:43284 PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID = 0,
285 PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID = 1 << 2,
286 PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID = 1 << 3,
287 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID = 1 << 3 | 1 << 2,
[email protected]f62262b2013-07-05 20:57:30288
289 // Bits 4 and 5 describe the packet sequence number length as follows:
290 // --00----: 1 byte
291 // --01----: 2 bytes
292 // --10----: 4 bytes
293 // --11----: 6 bytes
[email protected]8e01c062013-10-31 07:35:31294 PACKET_PUBLIC_FLAGS_1BYTE_SEQUENCE = PACKET_FLAGS_1BYTE_SEQUENCE << 4,
295 PACKET_PUBLIC_FLAGS_2BYTE_SEQUENCE = PACKET_FLAGS_2BYTE_SEQUENCE << 4,
296 PACKET_PUBLIC_FLAGS_4BYTE_SEQUENCE = PACKET_FLAGS_4BYTE_SEQUENCE << 4,
297 PACKET_PUBLIC_FLAGS_6BYTE_SEQUENCE = PACKET_FLAGS_6BYTE_SEQUENCE << 4,
[email protected]f62262b2013-07-05 20:57:30298
299 // All bits set (bits 6 and 7 are not currently used): 00111111
300 PACKET_PUBLIC_FLAGS_MAX = (1 << 6) - 1
[email protected]c995c572013-01-18 05:43:20301};
[email protected]8b37a092012-10-18 21:53:49302
[email protected]f62262b2013-07-05 20:57:30303// The private flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20304enum QuicPacketPrivateFlags {
305 PACKET_PRIVATE_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30306
307 // Bit 0: Does this packet contain an entropy bit?
[email protected]b064310782013-05-30 21:12:17308 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0,
[email protected]f62262b2013-07-05 20:57:30309
310 // Bit 1: Payload is part of an FEC group?
311 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1,
312
313 // Bit 2: Payload is FEC as opposed to frames?
314 PACKET_PRIVATE_FLAGS_FEC = 1 << 2,
315
316 // All bits set (bits 3-7 are not currently used): 00000111
317 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1
[email protected]c995c572013-01-18 05:43:20318};
319
[email protected]48878092013-07-26 14:51:56320// The available versions of QUIC. Guaranteed that the integer value of the enum
321// will match the version number.
322// When adding a new version to this enum you should add it to
[email protected]8bbfaeb72013-08-09 06:38:26323// kSupportedQuicVersions (if appropriate), and also add a new case to the
324// helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and
325// QuicVersionToString.
[email protected]48878092013-07-26 14:51:56326enum QuicVersion {
327 // Special case to indicate unknown/unsupported QUIC version.
328 QUIC_VERSION_UNSUPPORTED = 0,
329
rtenneti501f0a92015-01-17 01:55:40330 QUIC_VERSION_24 = 24, // SPDY/4 header compression.
rchc0815442015-04-18 13:29:46331 QUIC_VERSION_25 = 25, // SPDY/4 header keys, and removal of error_details
332 // from QuicRstStreamFrame
[email protected]48878092013-07-26 14:51:56333};
334
335// This vector contains QUIC versions which we currently support.
336// This should be ordered such that the highest supported version is the first
337// element, with subsequent elements in descending order (versions can be
338// skipped as necessary).
[email protected]31ae854842013-11-27 00:05:46339//
[email protected]310d37b2014-08-02 06:15:37340// IMPORTANT: if you are adding to this list, follow the instructions at
[email protected]31ae854842013-11-27 00:05:46341// http://sites/quic/adding-and-removing-versions
rchc0815442015-04-18 13:29:46342static const QuicVersion kSupportedQuicVersions[] = {QUIC_VERSION_25,
rtennetie0ee6eb2015-05-01 00:55:09343 QUIC_VERSION_24};
[email protected]48878092013-07-26 14:51:56344
345typedef std::vector<QuicVersion> QuicVersionVector;
346
[email protected]b007e632013-10-28 08:39:25347// Returns a vector of QUIC versions in kSupportedQuicVersions.
348NET_EXPORT_PRIVATE QuicVersionVector QuicSupportedVersions();
[email protected]ea2ab47b2013-08-13 00:44:11349
[email protected]48878092013-07-26 14:51:56350// QuicTag is written to and read from the wire, but we prefer to use
351// the more readable QuicVersion at other levels.
352// Helper function which translates from a QuicVersion to a QuicTag. Returns 0
353// if QuicVersion is unsupported.
354NET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version);
355
356// Returns appropriate QuicVersion from a QuicTag.
357// Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood.
358NET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag);
359
360// Helper function which translates from a QuicVersion to a string.
361// Returns strings corresponding to enum names (e.g. QUIC_VERSION_6).
362NET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version);
363
364// Returns comma separated list of string representations of QuicVersion enum
[email protected]b007e632013-10-28 08:39:25365// values in the supplied |versions| vector.
366NET_EXPORT_PRIVATE std::string QuicVersionVectorToString(
367 const QuicVersionVector& versions);
[email protected]48878092013-07-26 14:51:56368
369// Version and Crypto tags are written to the wire with a big-endian
370// representation of the name of the tag. For example
371// the client hello tag (CHLO) will be written as the
372// following 4 bytes: 'C' 'H' 'L' 'O'. Since it is
373// stored in memory as a little endian uint32, we need
374// to reverse the order of the bytes.
375
376// MakeQuicTag returns a value given the four bytes. For example:
377// MakeQuicTag('C', 'H', 'L', 'O');
378NET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d);
379
[email protected]9cda5fd2014-06-03 10:20:28380// Returns true if the tag vector contains the specified tag.
[email protected]cc1aa272014-06-30 19:48:22381NET_EXPORT_PRIVATE bool ContainsQuicTag(const QuicTagVector& tag_vector,
382 QuicTag tag);
[email protected]9cda5fd2014-06-03 10:20:28383
[email protected]b064310782013-05-30 21:12:17384// Size in bytes of the data or fec packet header.
[email protected]79d13dcb2014-02-05 07:23:13385NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(const QuicPacketHeader& header);
[email protected]b064310782013-05-30 21:12:17386
[email protected]25c31dc2013-06-05 17:56:04387NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(
[email protected]3aa9ca72014-02-27 19:39:43388 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04389 bool include_version,
390 QuicSequenceNumberLength sequence_number_length,
391 InFecGroup is_in_fec_group);
[email protected]b064310782013-05-30 21:12:17392
[email protected]b064310782013-05-30 21:12:17393// Index of the first byte in a QUIC packet of FEC protected data.
[email protected]25c31dc2013-06-05 17:56:04394NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(
[email protected]3aa9ca72014-02-27 19:39:43395 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04396 bool include_version,
397 QuicSequenceNumberLength sequence_number_length);
[email protected]b064310782013-05-30 21:12:17398// Index of the first byte in a QUIC packet of encrypted data.
[email protected]25c31dc2013-06-05 17:56:04399NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(
[email protected]3aa9ca72014-02-27 19:39:43400 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04401 bool include_version,
402 QuicSequenceNumberLength sequence_number_length);
[email protected]b064310782013-05-30 21:12:17403
[email protected]74bda142013-03-31 02:49:11404enum QuicRstStreamErrorCode {
405 QUIC_STREAM_NO_ERROR = 0,
[email protected]8b37a092012-10-18 21:53:49406
[email protected]24e5bc52013-09-18 15:36:58407 // There was some error which halted stream processing.
408 QUIC_ERROR_PROCESSING_STREAM,
[email protected]8b37a092012-10-18 21:53:49409 // We got two fin or reset offsets which did not match.
410 QUIC_MULTIPLE_TERMINATION_OFFSETS,
411 // We got bad payload and can not respond to it at the protocol level.
412 QUIC_BAD_APPLICATION_PAYLOAD,
[email protected]74bda142013-03-31 02:49:11413 // Stream closed due to connection error. No reset frame is sent when this
414 // happens.
415 QUIC_STREAM_CONNECTION_ERROR,
416 // GoAway frame sent. No more stream can be created.
417 QUIC_STREAM_PEER_GOING_AWAY,
[email protected]06ff5152013-08-29 01:03:05418 // The stream has been cancelled.
419 QUIC_STREAM_CANCELLED,
rtenneti4a5df262014-11-07 00:43:58420 // Closing stream locally, sending a RST to allow for proper flow control
421 // accounting. Sent in response to a RST from the peer.
422 QUIC_RST_ACKNOWLEDGEMENT,
[email protected]8b37a092012-10-18 21:53:49423
[email protected]74bda142013-03-31 02:49:11424 // No error. Used as bound while iterating.
425 QUIC_STREAM_LAST_ERROR,
426};
[email protected]8b37a092012-10-18 21:53:49427
[email protected]51cc1342014-04-18 23:44:37428// Because receiving an unknown QuicRstStreamErrorCode results in connection
429// teardown, we use this to make sure any errors predating a given version are
430// downgraded to the most appropriate existing error.
431NET_EXPORT_PRIVATE QuicRstStreamErrorCode AdjustErrorForVersion(
432 QuicRstStreamErrorCode error_code,
433 QuicVersion version);
434
[email protected]89264042013-08-21 07:35:24435// These values must remain stable as they are uploaded to UMA histograms.
436// To add a new error code, use the current value of QUIC_LAST_ERROR and
437// increment QUIC_LAST_ERROR.
[email protected]74bda142013-03-31 02:49:11438enum QuicErrorCode {
439 QUIC_NO_ERROR = 0,
440
441 // Connection has reached an invalid state.
[email protected]89264042013-08-21 07:35:24442 QUIC_INTERNAL_ERROR = 1,
[email protected]74bda142013-03-31 02:49:11443 // There were data frames after the a fin or reset.
[email protected]89264042013-08-21 07:35:24444 QUIC_STREAM_DATA_AFTER_TERMINATION = 2,
[email protected]8b37a092012-10-18 21:53:49445 // Control frame is malformed.
[email protected]89264042013-08-21 07:35:24446 QUIC_INVALID_PACKET_HEADER = 3,
[email protected]be24ab22012-10-22 03:01:52447 // Frame data is malformed.
[email protected]89264042013-08-21 07:35:24448 QUIC_INVALID_FRAME_DATA = 4,
449 // The packet contained no payload.
450 QUIC_MISSING_PAYLOAD = 48,
[email protected]8b37a092012-10-18 21:53:49451 // FEC data is malformed.
[email protected]89264042013-08-21 07:35:24452 QUIC_INVALID_FEC_DATA = 5,
453 // STREAM frame data is malformed.
454 QUIC_INVALID_STREAM_DATA = 46,
[email protected]42a3eba2014-04-30 10:52:55455 // STREAM frame data is not encrypted.
456 QUIC_UNENCRYPTED_STREAM_DATA = 61,
[email protected]89264042013-08-21 07:35:24457 // RST_STREAM frame data is malformed.
458 QUIC_INVALID_RST_STREAM_DATA = 6,
459 // CONNECTION_CLOSE frame data is malformed.
460 QUIC_INVALID_CONNECTION_CLOSE_DATA = 7,
461 // GOAWAY frame data is malformed.
462 QUIC_INVALID_GOAWAY_DATA = 8,
[email protected]6ae6e342014-02-06 02:21:42463 // WINDOW_UPDATE frame data is malformed.
464 QUIC_INVALID_WINDOW_UPDATE_DATA = 57,
465 // BLOCKED frame data is malformed.
466 QUIC_INVALID_BLOCKED_DATA = 58,
[email protected]93dd91f2014-02-27 00:09:03467 // STOP_WAITING frame data is malformed.
468 QUIC_INVALID_STOP_WAITING_DATA = 60,
[email protected]89264042013-08-21 07:35:24469 // ACK frame data is malformed.
470 QUIC_INVALID_ACK_DATA = 9,
rtennetif4bdb542015-01-21 14:33:05471
472 // deprecated: QUIC_INVALID_CONGESTION_FEEDBACK_DATA = 47,
473
[email protected]14e8106c2013-03-14 16:25:33474 // Version negotiation packet is malformed.
[email protected]89264042013-08-21 07:35:24475 QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10,
[email protected]899951652013-05-16 12:52:39476 // Public RST packet is malformed.
[email protected]89264042013-08-21 07:35:24477 QUIC_INVALID_PUBLIC_RST_PACKET = 11,
[email protected]8b37a092012-10-18 21:53:49478 // There was an error decrypting.
[email protected]89264042013-08-21 07:35:24479 QUIC_DECRYPTION_FAILURE = 12,
[email protected]8b37a092012-10-18 21:53:49480 // There was an error encrypting.
[email protected]89264042013-08-21 07:35:24481 QUIC_ENCRYPTION_FAILURE = 13,
[email protected]8b37a092012-10-18 21:53:49482 // The packet exceeded kMaxPacketSize.
[email protected]89264042013-08-21 07:35:24483 QUIC_PACKET_TOO_LARGE = 14,
[email protected]8b37a092012-10-18 21:53:49484 // Data was sent for a stream which did not exist.
[email protected]89264042013-08-21 07:35:24485 QUIC_PACKET_FOR_NONEXISTENT_STREAM = 15,
[email protected]9db443912013-02-25 05:27:03486 // The peer is going away. May be a client or server.
[email protected]89264042013-08-21 07:35:24487 QUIC_PEER_GOING_AWAY = 16,
[email protected]8b37a092012-10-18 21:53:49488 // A stream ID was invalid.
[email protected]89264042013-08-21 07:35:24489 QUIC_INVALID_STREAM_ID = 17,
[email protected]24e5bc52013-09-18 15:36:58490 // A priority was invalid.
491 QUIC_INVALID_PRIORITY = 49,
[email protected]8b37a092012-10-18 21:53:49492 // Too many streams already open.
[email protected]89264042013-08-21 07:35:24493 QUIC_TOO_MANY_OPEN_STREAMS = 18,
[email protected]9693157b2014-08-08 11:13:49494 // The peer must send a FIN/RST for each stream, and has not been doing so.
495 QUIC_TOO_MANY_UNFINISHED_STREAMS = 66,
[email protected]86a318d2013-01-23 21:16:04496 // Received public reset for this connection.
[email protected]89264042013-08-21 07:35:24497 QUIC_PUBLIC_RESET = 19,
[email protected]c244c5a12013-05-07 20:55:04498 // Invalid protocol version.
[email protected]89264042013-08-21 07:35:24499 QUIC_INVALID_VERSION = 20,
[email protected]92bf17c2014-03-03 21:14:03500
501 // deprecated: QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED = 21
502
[email protected]c244c5a12013-05-07 20:55:04503 // The Header ID for a stream was too far from the previous.
[email protected]89264042013-08-21 07:35:24504 QUIC_INVALID_HEADER_ID = 22,
[email protected]899951652013-05-16 12:52:39505 // Negotiable parameter received during handshake had invalid value.
[email protected]89264042013-08-21 07:35:24506 QUIC_INVALID_NEGOTIATED_VALUE = 23,
[email protected]899951652013-05-16 12:52:39507 // There was an error decompressing data.
[email protected]89264042013-08-21 07:35:24508 QUIC_DECOMPRESSION_FAILURE = 24,
[email protected]8b37a092012-10-18 21:53:49509 // We hit our prenegotiated (or default) timeout
[email protected]89264042013-08-21 07:35:24510 QUIC_CONNECTION_TIMED_OUT = 25,
rtenneti31e9fd62014-09-16 05:22:15511 // We hit our overall connection timeout
512 QUIC_CONNECTION_OVERALL_TIMED_OUT = 67,
[email protected]899951652013-05-16 12:52:39513 // There was an error encountered migrating addresses
[email protected]89264042013-08-21 07:35:24514 QUIC_ERROR_MIGRATING_ADDRESS = 26,
[email protected]1505a512013-09-04 22:59:35515 // There was an error while writing to the socket.
[email protected]89264042013-08-21 07:35:24516 QUIC_PACKET_WRITE_ERROR = 27,
[email protected]1505a512013-09-04 22:59:35517 // There was an error while reading from the socket.
518 QUIC_PACKET_READ_ERROR = 51,
[email protected]24e5bc52013-09-18 15:36:58519 // We received a STREAM_FRAME with no data and no fin flag set.
520 QUIC_INVALID_STREAM_FRAME = 50,
[email protected]4d640792013-12-18 22:21:08521 // We received invalid data on the headers stream.
522 QUIC_INVALID_HEADERS_STREAM_DATA = 56,
[email protected]730b35d72014-06-05 03:23:22523 // The peer received too much data, violating flow control.
524 QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA = 59,
525 // The peer sent too much data, violating flow control.
526 QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA = 63,
527 // The peer received an invalid flow control window.
528 QUIC_FLOW_CONTROL_INVALID_WINDOW = 64,
[email protected]71c84e592014-05-28 23:39:29529 // The connection has been IP pooled into an existing connection.
530 QUIC_CONNECTION_IP_POOLED = 62,
rtenneti23186682014-10-30 01:49:33531 // The connection has too many outstanding sent packets.
532 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS = 68,
533 // The connection has too many outstanding received packets.
534 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS = 69,
rtenneti14abd312015-02-06 21:56:01535 // The quic connection job to load server config is cancelled.
536 QUIC_CONNECTION_CANCELLED = 70,
rtenneti85dcfac22015-03-27 20:22:19537 // Disabled QUIC because of high packet loss rate.
538 QUIC_BAD_PACKET_LOSS_RATE = 71,
[email protected]8b37a092012-10-18 21:53:49539
540 // Crypto errors.
541
[email protected]1354bf62013-05-23 23:17:18542 // Hanshake failed.
[email protected]89264042013-08-21 07:35:24543 QUIC_HANDSHAKE_FAILED = 28,
[email protected]8b37a092012-10-18 21:53:49544 // Handshake message contained out of order tags.
[email protected]89264042013-08-21 07:35:24545 QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29,
[email protected]701bc892013-01-17 04:51:54546 // Handshake message contained too many entries.
[email protected]89264042013-08-21 07:35:24547 QUIC_CRYPTO_TOO_MANY_ENTRIES = 30,
[email protected]8b37a092012-10-18 21:53:49548 // Handshake message contained an invalid value length.
[email protected]89264042013-08-21 07:35:24549 QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31,
[email protected]8b37a092012-10-18 21:53:49550 // A crypto message was received after the handshake was complete.
[email protected]89264042013-08-21 07:35:24551 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32,
[email protected]d3d15bf2013-01-30 02:51:54552 // A crypto message was received with an illegal message tag.
[email protected]89264042013-08-21 07:35:24553 QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33,
[email protected]d3d15bf2013-01-30 02:51:54554 // A crypto message was received with an illegal parameter.
[email protected]89264042013-08-21 07:35:24555 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34,
[email protected]752fbe52013-10-14 08:35:32556 // An invalid channel id signature was supplied.
557 QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52,
[email protected]d3d15bf2013-01-30 02:51:54558 // A crypto message was received with a mandatory parameter missing.
[email protected]89264042013-08-21 07:35:24559 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35,
[email protected]d3d15bf2013-01-30 02:51:54560 // A crypto message was received with a parameter that has no overlap
561 // with the local parameter.
[email protected]89264042013-08-21 07:35:24562 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36,
[email protected]ed3fc15d2013-03-08 18:37:44563 // A crypto message was received that contained a parameter with too few
564 // values.
[email protected]89264042013-08-21 07:35:24565 QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37,
[email protected]ccc66e8a2013-03-26 08:26:14566 // An internal error occured in crypto processing.
[email protected]89264042013-08-21 07:35:24567 QUIC_CRYPTO_INTERNAL_ERROR = 38,
[email protected]ccc66e8a2013-03-26 08:26:14568 // A crypto handshake message specified an unsupported version.
[email protected]89264042013-08-21 07:35:24569 QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39,
rtennetie0ee6eb2015-05-01 00:55:09570 // A crypto handshake message resulted in a stateless reject.
571 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT = 72,
[email protected]ccc66e8a2013-03-26 08:26:14572 // There was no intersection between the crypto primitives supported by the
573 // peer and ourselves.
[email protected]89264042013-08-21 07:35:24574 QUIC_CRYPTO_NO_SUPPORT = 40,
[email protected]ef95114d2013-04-17 17:57:01575 // The server rejected our client hello messages too many times.
[email protected]89264042013-08-21 07:35:24576 QUIC_CRYPTO_TOO_MANY_REJECTS = 41,
[email protected]a57e0272013-04-26 07:31:47577 // The client rejected the server's certificate chain or signature.
[email protected]89264042013-08-21 07:35:24578 QUIC_PROOF_INVALID = 42,
[email protected]8ba81212013-05-03 13:11:48579 // A crypto message was received with a duplicate tag.
[email protected]89264042013-08-21 07:35:24580 QUIC_CRYPTO_DUPLICATE_TAG = 43,
[email protected]2532de12013-05-09 12:29:33581 // A crypto message was received with the wrong encryption level (i.e. it
582 // should have been encrypted but was not.)
[email protected]89264042013-08-21 07:35:24583 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44,
[email protected]2532de12013-05-09 12:29:33584 // The server config for a server has expired.
[email protected]89264042013-08-21 07:35:24585 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45,
[email protected]752fbe52013-10-14 08:35:32586 // We failed to setup the symmetric keys for a connection.
587 QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53,
[email protected]691f45a982013-11-19 10:52:04588 // A handshake message arrived, but we are still validating the
589 // previous handshake message.
590 QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54,
[email protected]ccb34212014-07-18 09:27:50591 // A server config update arrived before the handshake is complete.
592 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE = 65,
[email protected]d89f1862013-11-26 21:21:27593 // This connection involved a version negotiation which appears to have been
594 // tampered with.
595 QUIC_VERSION_NEGOTIATION_MISMATCH = 55,
[email protected]ccc66e8a2013-03-26 08:26:14596
[email protected]74bda142013-03-31 02:49:11597 // No error. Used as bound while iterating.
rtennetie0ee6eb2015-05-01 00:55:09598 QUIC_LAST_ERROR = 73,
[email protected]8b37a092012-10-18 21:53:49599};
600
[email protected]c995c572013-01-18 05:43:20601struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
[email protected]14e8106c2013-03-14 16:25:33602 QuicPacketPublicHeader();
603 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
604 ~QuicPacketPublicHeader();
605
[email protected]3aa9ca72014-02-27 19:39:43606 // Universal header. All QuicPacket headers will have a connection_id and
607 // public flags.
608 QuicConnectionId connection_id;
609 QuicConnectionIdLength connection_id_length;
[email protected]9db443912013-02-25 05:27:03610 bool reset_flag;
611 bool version_flag;
[email protected]25c31dc2013-06-05 17:56:04612 QuicSequenceNumberLength sequence_number_length;
[email protected]48878092013-07-26 14:51:56613 QuicVersionVector versions;
[email protected]c995c572013-01-18 05:43:20614};
615
rtenneti9e0fb502015-03-08 06:07:16616// An integer which cannot be a packet sequence number.
617const QuicPacketSequenceNumber kInvalidPacketSequenceNumber = 0;
618
[email protected]c995c572013-01-18 05:43:20619// Header for Data or FEC packets.
[email protected]74bda142013-03-31 02:49:11620struct NET_EXPORT_PRIVATE QuicPacketHeader {
621 QuicPacketHeader();
622 explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
[email protected]9db443912013-02-25 05:27:03623
624 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
625 std::ostream& os, const QuicPacketHeader& s);
626
[email protected]c995c572013-01-18 05:43:20627 QuicPacketPublicHeader public_header;
[email protected]9db443912013-02-25 05:27:03628 bool fec_flag;
[email protected]9db443912013-02-25 05:27:03629 bool entropy_flag;
630 QuicPacketEntropyHash entropy_hash;
[email protected]8b37a092012-10-18 21:53:49631 QuicPacketSequenceNumber packet_sequence_number;
[email protected]b064310782013-05-30 21:12:17632 InFecGroup is_in_fec_group;
[email protected]8b37a092012-10-18 21:53:49633 QuicFecGroupNumber fec_group;
634};
635
[email protected]74bda142013-03-31 02:49:11636struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
[email protected]6ae6e342014-02-06 02:21:42637 QuicPublicResetPacket();
638 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header);
639
[email protected]86a318d2013-01-23 21:16:04640 QuicPacketPublicHeader public_header;
[email protected]86a318d2013-01-23 21:16:04641 QuicPublicResetNonceProof nonce_proof;
[email protected]300ccd52014-01-25 08:00:19642 QuicPacketSequenceNumber rejected_sequence_number;
[email protected]79d13dcb2014-02-05 07:23:13643 IPEndPoint client_address;
[email protected]86a318d2013-01-23 21:16:04644};
645
[email protected]14e8106c2013-03-14 16:25:33646enum QuicVersionNegotiationState {
647 START_NEGOTIATION = 0,
[email protected]ec640112013-08-09 03:56:18648 // Server-side this implies we've sent a version negotiation packet and are
649 // waiting on the client to select a compatible version. Client-side this
650 // implies we've gotten a version negotiation packet, are retransmitting the
651 // initial packets with a supported version and are waiting for our first
652 // packet from the server.
653 NEGOTIATION_IN_PROGRESS,
654 // This indicates this endpoint has received a packet from the peer with a
655 // version this endpoint supports. Version negotiation is complete, and the
656 // version number will no longer be sent with future packets.
[email protected]14e8106c2013-03-14 16:25:33657 NEGOTIATED_VERSION
658};
659
660typedef QuicPacketPublicHeader QuicVersionNegotiationPacket;
661
[email protected]c995c572013-01-18 05:43:20662// A padding frame contains no payload.
663struct NET_EXPORT_PRIVATE QuicPaddingFrame {
664};
665
[email protected]d8c522112014-04-23 09:23:25666// A ping frame contains no payload, though it is retransmittable,
667// and ACK'd just like other normal frames.
668struct NET_EXPORT_PRIVATE QuicPingFrame {
669};
670
[email protected]be24ab22012-10-22 03:01:52671struct NET_EXPORT_PRIVATE QuicStreamFrame {
672 QuicStreamFrame();
[email protected]5dafdb62013-11-14 01:24:26673 QuicStreamFrame(const QuicStreamFrame& frame);
[email protected]be24ab22012-10-22 03:01:52674 QuicStreamFrame(QuicStreamId stream_id,
[email protected]a5061242012-10-23 23:29:37675 bool fin,
[email protected]701bc892013-01-17 04:51:54676 QuicStreamOffset offset,
rtennetia4228ea2015-06-04 02:31:44677 base::StringPiece data);
[email protected]5dafdb62013-11-14 01:24:26678
[email protected]c5e1aca2014-01-30 04:03:04679 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
680 std::ostream& os, const QuicStreamFrame& s);
681
[email protected]8b37a092012-10-18 21:53:49682 QuicStreamId stream_id;
683 bool fin;
[email protected]701bc892013-01-17 04:51:54684 QuicStreamOffset offset; // Location of this data in the stream.
rtennetia4228ea2015-06-04 02:31:44685 base::StringPiece data;
[email protected]8b37a092012-10-18 21:53:49686};
687
[email protected]e537f742012-12-07 15:33:53688// TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
689// is finalized.
[email protected]9db443912013-02-25 05:27:03690typedef std::set<QuicPacketSequenceNumber> SequenceNumberSet;
rtennetidd4bf8f2014-09-03 00:45:16691typedef std::list<QuicPacketSequenceNumber> SequenceNumberList;
rtenneti4b06ae72014-08-26 03:43:43692
mostynbdc40b80612014-09-10 03:45:42693typedef std::list<
694 std::pair<QuicPacketSequenceNumber, QuicTime> > PacketTimeList;
[email protected]044ac2b2012-11-13 21:41:06695
[email protected]310d37b2014-08-02 06:15:37696struct NET_EXPORT_PRIVATE QuicStopWaitingFrame {
697 QuicStopWaitingFrame();
698 ~QuicStopWaitingFrame();
[email protected]6ae6e342014-02-06 02:21:42699
[email protected]26f3f8e2012-12-13 21:07:19700 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
[email protected]310d37b2014-08-02 06:15:37701 std::ostream& os, const QuicStopWaitingFrame& s);
702 // Entropy hash of all packets up to, but not including, the least unacked
703 // packet.
704 QuicPacketEntropyHash entropy_hash;
705 // The lowest packet we've sent which is unacked, and we expect an ack for.
706 QuicPacketSequenceNumber least_unacked;
707};
708
709struct NET_EXPORT_PRIVATE QuicAckFrame {
710 QuicAckFrame();
711 ~QuicAckFrame();
712
713 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
714 std::ostream& os, const QuicAckFrame& s);
[email protected]a674b4c2012-12-05 03:44:30715
[email protected]9db443912013-02-25 05:27:03716 // Entropy hash of all packets up to largest observed not including missing
717 // packets.
718 QuicPacketEntropyHash entropy_hash;
[email protected]e537f742012-12-07 15:33:53719
[email protected]48697d8a2013-01-15 19:42:24720 // The highest packet sequence number we've observed from the peer.
721 //
722 // In general, this should be the largest packet number we've received. In
723 // the case of truncated acks, we may have to advertise a lower "upper bound"
724 // than largest received, to avoid implicitly acking missing packets that
725 // don't fit in the missing packet list due to size limitations. In this
726 // case, largest_observed may be a packet which is also in the missing packets
727 // list.
728 QuicPacketSequenceNumber largest_observed;
[email protected]a674b4c2012-12-05 03:44:30729
[email protected]14e8106c2013-03-14 16:25:33730 // Time elapsed since largest_observed was received until this Ack frame was
731 // sent.
732 QuicTime::Delta delta_time_largest_observed;
733
[email protected]9db443912013-02-25 05:27:03734 // TODO(satyamshekhar): Can be optimized using an interval set like data
735 // structure.
[email protected]e537f742012-12-07 15:33:53736 // The set of packets which we're expecting and have not received.
[email protected]9db443912013-02-25 05:27:03737 SequenceNumberSet missing_packets;
[email protected]8e01c062013-10-31 07:35:31738
739 // Whether the ack had to be truncated when sent.
740 bool is_truncated;
[email protected]bdf2d432014-02-09 10:45:41741
742 // Packets which have been revived via FEC.
743 // All of these must also be in missing_packets.
744 SequenceNumberSet revived_packets;
rtenneti4b06ae72014-08-26 03:43:43745
746 // List of <sequence_number, time> for when packets arrived.
747 PacketTimeList received_packet_times;
[email protected]8b37a092012-10-18 21:53:49748};
749
[email protected]9db443912013-02-25 05:27:03750// True if the sequence number is greater than largest_observed or is listed
751// as missing.
752// Always returns false for sequence numbers less than least_unacked.
753bool NET_EXPORT_PRIVATE IsAwaitingPacket(
[email protected]310d37b2014-08-02 06:15:37754 const QuicAckFrame& ack_frame,
[email protected]9db443912013-02-25 05:27:03755 QuicPacketSequenceNumber sequence_number);
756
757// Inserts missing packets between [lower, higher).
758void NET_EXPORT_PRIVATE InsertMissingPacketsBetween(
[email protected]310d37b2014-08-02 06:15:37759 QuicAckFrame* ack_frame,
[email protected]9db443912013-02-25 05:27:03760 QuicPacketSequenceNumber lower,
761 QuicPacketSequenceNumber higher);
762
[email protected]a692ad9d2014-07-18 21:35:24763// Defines for all types of congestion control algorithms that can be used in
764// QUIC. Note that this is separate from the congestion feedback type -
765// some congestion control algorithms may use the same feedback type
766// (Reno and Cubic are the classic example for that).
767enum CongestionControlType {
768 kCubic,
rtennetifb3fa6c2015-03-16 23:04:55769 kCubicBytes,
[email protected]a692ad9d2014-07-18 21:35:24770 kReno,
rtennetifb3fa6c2015-03-16 23:04:55771 kRenoBytes,
[email protected]a692ad9d2014-07-18 21:35:24772 kBBR,
[email protected]8b37a092012-10-18 21:53:49773};
774
[email protected]c5cc9bd2014-03-31 23:17:14775enum LossDetectionType {
776 kNack, // Used to mimic TCP's loss detection.
777 kTime, // Time based loss detection.
778};
779
[email protected]be24ab22012-10-22 03:01:52780struct NET_EXPORT_PRIVATE QuicRstStreamFrame {
[email protected]6ae6e342014-02-06 02:21:42781 QuicRstStreamFrame();
782 QuicRstStreamFrame(QuicStreamId stream_id,
783 QuicRstStreamErrorCode error_code,
784 QuicStreamOffset bytes_written);
[email protected]8b37a092012-10-18 21:53:49785
[email protected]c5e1aca2014-01-30 04:03:04786 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
787 std::ostream& os, const QuicRstStreamFrame& r);
788
[email protected]8b37a092012-10-18 21:53:49789 QuicStreamId stream_id;
[email protected]74bda142013-03-31 02:49:11790 QuicRstStreamErrorCode error_code;
rchc0815442015-04-18 13:29:46791 // Only used in versions <= QUIC_VERSION_24.
[email protected]431bb4fd2012-10-19 17:46:09792 std::string error_details;
[email protected]6ae6e342014-02-06 02:21:42793
794 // Used to update flow control windows. On termination of a stream, both
795 // endpoints must inform the peer of the number of bytes they have sent on
796 // that stream. This can be done through normal termination (data packet with
797 // FIN) or through a RST.
798 QuicStreamOffset byte_offset;
[email protected]8b37a092012-10-18 21:53:49799};
800
[email protected]be24ab22012-10-22 03:01:52801struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame {
[email protected]6ae6e342014-02-06 02:21:42802 QuicConnectionCloseFrame();
803
[email protected]c5e1aca2014-01-30 04:03:04804 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
805 std::ostream& os, const QuicConnectionCloseFrame& c);
806
[email protected]431bb4fd2012-10-19 17:46:09807 QuicErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09808 std::string error_details;
[email protected]8b37a092012-10-18 21:53:49809};
810
[email protected]9db443912013-02-25 05:27:03811struct NET_EXPORT_PRIVATE QuicGoAwayFrame {
[email protected]6ae6e342014-02-06 02:21:42812 QuicGoAwayFrame();
[email protected]9db443912013-02-25 05:27:03813 QuicGoAwayFrame(QuicErrorCode error_code,
814 QuicStreamId last_good_stream_id,
815 const std::string& reason);
816
[email protected]c5e1aca2014-01-30 04:03:04817 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
818 std::ostream& os, const QuicGoAwayFrame& g);
819
[email protected]9db443912013-02-25 05:27:03820 QuicErrorCode error_code;
821 QuicStreamId last_good_stream_id;
822 std::string reason_phrase;
823};
824
[email protected]6ae6e342014-02-06 02:21:42825// Flow control updates per-stream and at the connection levoel.
826// Based on SPDY's WINDOW_UPDATE frame, but uses an absolute byte offset rather
827// than a window delta.
828// TODO(rjshade): A possible future optimization is to make stream_id and
829// byte_offset variable length, similar to stream frames.
830struct NET_EXPORT_PRIVATE QuicWindowUpdateFrame {
831 QuicWindowUpdateFrame() {}
832 QuicWindowUpdateFrame(QuicStreamId stream_id, QuicStreamOffset byte_offset);
833
834 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
835 std::ostream& os, const QuicWindowUpdateFrame& w);
836
837 // The stream this frame applies to. 0 is a special case meaning the overall
838 // connection rather than a specific stream.
839 QuicStreamId stream_id;
840
841 // Byte offset in the stream or connection. The receiver of this frame must
842 // not send data which would result in this offset being exceeded.
843 QuicStreamOffset byte_offset;
844};
845
846// The BLOCKED frame is used to indicate to the remote endpoint that this
847// endpoint believes itself to be flow-control blocked but otherwise ready to
848// send data. The BLOCKED frame is purely advisory and optional.
849// Based on SPDY's BLOCKED frame (undocumented as of 2014-01-28).
850struct NET_EXPORT_PRIVATE QuicBlockedFrame {
851 QuicBlockedFrame() {}
852 explicit QuicBlockedFrame(QuicStreamId stream_id);
853
854 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
855 std::ostream& os, const QuicBlockedFrame& b);
856
857 // The stream this frame applies to. 0 is a special case meaning the overall
858 // connection rather than a specific stream.
859 QuicStreamId stream_id;
860};
861
[email protected]8ba81212013-05-03 13:11:48862// EncryptionLevel enumerates the stages of encryption that a QUIC connection
863// progresses through. When retransmitting a packet, the encryption level needs
864// to be specified so that it is retransmitted at a level which the peer can
865// understand.
866enum EncryptionLevel {
867 ENCRYPTION_NONE = 0,
868 ENCRYPTION_INITIAL = 1,
869 ENCRYPTION_FORWARD_SECURE = 2,
870
871 NUM_ENCRYPTION_LEVELS,
872};
873
[email protected]be24ab22012-10-22 03:01:52874struct NET_EXPORT_PRIVATE QuicFrame {
[email protected]6ae6e342014-02-06 02:21:42875 QuicFrame();
876 explicit QuicFrame(QuicPaddingFrame* padding_frame);
877 explicit QuicFrame(QuicStreamFrame* stream_frame);
878 explicit QuicFrame(QuicAckFrame* frame);
rtenneti4b06ae72014-08-26 03:43:43879
[email protected]6ae6e342014-02-06 02:21:42880 explicit QuicFrame(QuicRstStreamFrame* frame);
881 explicit QuicFrame(QuicConnectionCloseFrame* frame);
[email protected]93dd91f2014-02-27 00:09:03882 explicit QuicFrame(QuicStopWaitingFrame* frame);
[email protected]d8c522112014-04-23 09:23:25883 explicit QuicFrame(QuicPingFrame* frame);
[email protected]6ae6e342014-02-06 02:21:42884 explicit QuicFrame(QuicGoAwayFrame* frame);
885 explicit QuicFrame(QuicWindowUpdateFrame* frame);
886 explicit QuicFrame(QuicBlockedFrame* frame);
[email protected]8b37a092012-10-18 21:53:49887
[email protected]c5e1aca2014-01-30 04:03:04888 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
889 std::ostream& os, const QuicFrame& frame);
890
[email protected]be24ab22012-10-22 03:01:52891 QuicFrameType type;
[email protected]8b37a092012-10-18 21:53:49892 union {
[email protected]c995c572013-01-18 05:43:20893 QuicPaddingFrame* padding_frame;
[email protected]be24ab22012-10-22 03:01:52894 QuicStreamFrame* stream_frame;
895 QuicAckFrame* ack_frame;
rtenneti4b06ae72014-08-26 03:43:43896
[email protected]93dd91f2014-02-27 00:09:03897 QuicStopWaitingFrame* stop_waiting_frame;
rtenneti4b06ae72014-08-26 03:43:43898
[email protected]d8c522112014-04-23 09:23:25899 QuicPingFrame* ping_frame;
[email protected]be24ab22012-10-22 03:01:52900 QuicRstStreamFrame* rst_stream_frame;
901 QuicConnectionCloseFrame* connection_close_frame;
[email protected]9db443912013-02-25 05:27:03902 QuicGoAwayFrame* goaway_frame;
[email protected]6ae6e342014-02-06 02:21:42903 QuicWindowUpdateFrame* window_update_frame;
904 QuicBlockedFrame* blocked_frame;
[email protected]8b37a092012-10-18 21:53:49905 };
906};
907
[email protected]be24ab22012-10-22 03:01:52908typedef std::vector<QuicFrame> QuicFrames;
[email protected]8b37a092012-10-18 21:53:49909
910struct NET_EXPORT_PRIVATE QuicFecData {
911 QuicFecData();
[email protected]a5061242012-10-23 23:29:37912
[email protected]c995c572013-01-18 05:43:20913 // The FEC group number is also the sequence number of the first
914 // FEC protected packet. The last protected packet's sequence number will
915 // be one less than the sequence number of the FEC packet.
[email protected]8b37a092012-10-18 21:53:49916 QuicFecGroupNumber fec_group;
[email protected]8b37a092012-10-18 21:53:49917 base::StringPiece redundancy;
[email protected]8b37a092012-10-18 21:53:49918};
919
[email protected]8b37a092012-10-18 21:53:49920class NET_EXPORT_PRIVATE QuicData {
921 public:
[email protected]6ae6e342014-02-06 02:21:42922 QuicData(const char* buffer, size_t length);
923 QuicData(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:49924 virtual ~QuicData();
925
926 base::StringPiece AsStringPiece() const {
927 return base::StringPiece(data(), length());
928 }
929
930 const char* data() const { return buffer_; }
931 size_t length() const { return length_; }
rtennetie0ee6eb2015-05-01 00:55:09932 bool owns_buffer() const { return owns_buffer_; }
[email protected]8b37a092012-10-18 21:53:49933
934 private:
935 const char* buffer_;
936 size_t length_;
937 bool owns_buffer_;
938
939 DISALLOW_COPY_AND_ASSIGN(QuicData);
940};
941
942class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
943 public:
rtennetica5ac272015-02-07 12:35:12944 QuicPacket(char* buffer,
945 size_t length,
946 bool owns_buffer,
947 QuicConnectionIdLength connection_id_length,
948 bool includes_version,
949 QuicSequenceNumberLength sequence_number_length);
[email protected]8b37a092012-10-18 21:53:49950
[email protected]5351cc4b2013-03-03 07:22:41951 base::StringPiece FecProtectedData() const;
952 base::StringPiece AssociatedData() const;
953 base::StringPiece BeforePlaintext() const;
954 base::StringPiece Plaintext() const;
[email protected]082b65b2012-11-10 19:11:31955
[email protected]8b37a092012-10-18 21:53:49956 char* mutable_data() { return buffer_; }
957
958 private:
959 char* buffer_;
[email protected]3aa9ca72014-02-27 19:39:43960 const QuicConnectionIdLength connection_id_length_;
[email protected]5351cc4b2013-03-03 07:22:41961 const bool includes_version_;
[email protected]25c31dc2013-06-05 17:56:04962 const QuicSequenceNumberLength sequence_number_length_;
[email protected]8b37a092012-10-18 21:53:49963
[email protected]2e740db2012-10-20 19:35:19964 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
[email protected]8b37a092012-10-18 21:53:49965};
966
967class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
968 public:
[email protected]6ae6e342014-02-06 02:21:42969 QuicEncryptedPacket(const char* buffer, size_t length);
970 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:49971
[email protected]ec86d5462013-11-17 16:04:49972 // Clones the packet into a new packet which owns the buffer.
973 QuicEncryptedPacket* Clone() const;
974
[email protected]c1b32c62013-01-20 02:49:10975 // By default, gtest prints the raw bytes of an object. The bool data
976 // member (in the base class QuicData) causes this object to have padding
977 // bytes, which causes the default gtest object printer to read
978 // uninitialize memory. So we need to teach gtest how to print this object.
979 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
980 std::ostream& os, const QuicEncryptedPacket& s);
981
[email protected]2e740db2012-10-20 19:35:19982 private:
983 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
[email protected]8b37a092012-10-18 21:53:49984};
985
[email protected]9db443912013-02-25 05:27:03986class NET_EXPORT_PRIVATE RetransmittableFrames {
987 public:
rtennetidc8e5a22015-02-25 01:38:52988 explicit RetransmittableFrames(EncryptionLevel level);
[email protected]9db443912013-02-25 05:27:03989 ~RetransmittableFrames();
990
[email protected]9db443912013-02-25 05:27:03991 // Takes ownership of the frame inside |frame|.
rtennetia4228ea2015-06-04 02:31:44992 const QuicFrame& AddFrame(const QuicFrame& frame);
993 // Takes ownership of the frame inside |frame| and |buffer|.
994 const QuicFrame& AddFrame(const QuicFrame& frame, char* buffer);
rtenneti73e25c12015-03-16 06:12:43995 // Removes all stream frames associated with |stream_id|.
996 void RemoveFramesForStream(QuicStreamId stream_id);
997
[email protected]9db443912013-02-25 05:27:03998 const QuicFrames& frames() const { return frames_; }
999
[email protected]672631c2014-08-16 06:11:451000 IsHandshake HasCryptoHandshake() const {
1001 return has_crypto_handshake_;
1002 }
[email protected]2115d33ba2014-01-02 21:53:521003
[email protected]8ba81212013-05-03 13:11:481004 EncryptionLevel encryption_level() const {
1005 return encryption_level_;
1006 }
1007
[email protected]9db443912013-02-25 05:27:031008 private:
1009 QuicFrames frames_;
rtennetidc8e5a22015-02-25 01:38:521010 const EncryptionLevel encryption_level_;
[email protected]672631c2014-08-16 06:11:451011 IsHandshake has_crypto_handshake_;
rtennetia4228ea2015-06-04 02:31:441012 // Data referenced by the IOVector of a QuicStreamFrame.
1013 std::vector<const char*> stream_data_;
[email protected]9db443912013-02-25 05:27:031014
1015 DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames);
1016};
1017
1018struct NET_EXPORT_PRIVATE SerializedPacket {
1019 SerializedPacket(QuicPacketSequenceNumber sequence_number,
[email protected]ea825e02013-08-21 18:12:451020 QuicSequenceNumberLength sequence_number_length,
rtennetib6ac61a52015-02-11 20:20:521021 QuicEncryptedPacket* packet,
[email protected]9db443912013-02-25 05:27:031022 QuicPacketEntropyHash entropy_hash,
[email protected]97cf3022013-09-05 14:30:161023 RetransmittableFrames* retransmittable_frames);
1024 ~SerializedPacket();
[email protected]9db443912013-02-25 05:27:031025
1026 QuicPacketSequenceNumber sequence_number;
[email protected]ea825e02013-08-21 18:12:451027 QuicSequenceNumberLength sequence_number_length;
rtennetib6ac61a52015-02-11 20:20:521028 QuicEncryptedPacket* packet;
[email protected]9db443912013-02-25 05:27:031029 QuicPacketEntropyHash entropy_hash;
1030 RetransmittableFrames* retransmittable_frames;
rtennetica5ac272015-02-07 12:35:121031 bool is_fec_packet;
[email protected]97cf3022013-09-05 14:30:161032
rtenneti6b1c5b12015-01-13 20:08:351033 // Optional notifiers which will be informed when this packet has been ACKed.
rtenneticf54a52c2015-01-26 17:01:541034 std::list<QuicAckNotifier*> notifiers;
[email protected]9db443912013-02-25 05:27:031035};
1036
[email protected]77b5d50b2014-05-07 22:48:481037struct NET_EXPORT_PRIVATE TransmissionInfo {
1038 // Used by STL when assigning into a map.
1039 TransmissionInfo();
1040
1041 // Constructs a Transmission with a new all_tranmissions set
1042 // containing |sequence_number|.
1043 TransmissionInfo(RetransmittableFrames* retransmittable_frames,
[email protected]77b5d50b2014-05-07 22:48:481044 QuicSequenceNumberLength sequence_number_length,
[email protected]730b35d72014-06-05 03:23:221045 TransmissionType transmission_type,
rtenneti3183ac42015-02-28 03:39:411046 QuicTime sent_time,
1047 QuicByteCount bytes_sent,
1048 bool is_fec_packet);
[email protected]77b5d50b2014-05-07 22:48:481049
1050 RetransmittableFrames* retransmittable_frames;
1051 QuicSequenceNumberLength sequence_number_length;
[email protected]77b5d50b2014-05-07 22:48:481052 QuicTime sent_time;
[email protected]77b5d50b2014-05-07 22:48:481053 QuicByteCount bytes_sent;
pkastinga9f22d4e2014-12-01 22:43:461054 QuicPacketCount nack_count;
[email protected]730b35d72014-06-05 03:23:221055 // Reason why this packet was transmitted.
1056 TransmissionType transmission_type;
[email protected]77b5d50b2014-05-07 22:48:481057 // Stores the sequence numbers of all transmissions of this packet.
rtennetibe635732014-10-02 22:51:421058 // Must always be nullptr or have multiple elements.
rtennetidd4bf8f2014-09-03 00:45:161059 SequenceNumberList* all_transmissions;
[email protected]aa7e4ef2014-05-28 03:53:151060 // In flight packets have not been abandoned or lost.
1061 bool in_flight;
rtenneti31e9fd62014-09-16 05:22:151062 // True if the packet can never be acked, so it can be removed.
1063 bool is_unackable;
rtenneti85d89712014-11-20 03:32:241064 // True if the packet is an FEC packet.
1065 bool is_fec_packet;
[email protected]77b5d50b2014-05-07 22:48:481066};
1067
[email protected]8b37a092012-10-18 21:53:491068} // namespace net
1069
1070#endif // NET_QUIC_QUIC_PROTOCOL_H_