blob: 7677c53dc236f5772e554f3e3d2c8fb8f19bb9e4 [file] [log] [blame]
[email protected]8b37a092012-10-18 21:53:491// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_QUIC_QUIC_PROTOCOL_H_
6#define NET_QUIC_QUIC_PROTOCOL_H_
7
[email protected]e537f742012-12-07 15:33:538#include <stddef.h>
[email protected]8b37a092012-10-18 21:53:499#include <limits>
rtenneti4b06ae72014-08-26 03:43:4310#include <list>
[email protected]a674b4c2012-12-05 03:44:3011#include <map>
[email protected]5640d0a2012-10-22 18:17:0212#include <ostream>
[email protected]e537f742012-12-07 15:33:5313#include <set>
14#include <string>
[email protected]8b37a092012-10-18 21:53:4915#include <utility>
16#include <vector>
17
18#include "base/basictypes.h"
[email protected]14c1c232013-06-11 17:52:4419#include "base/containers/hash_tables.h"
[email protected]8b37a092012-10-18 21:53:4920#include "base/logging.h"
[email protected]d069c11a2013-04-13 00:01:5521#include "base/strings/string_piece.h"
[email protected]165e0752012-11-16 07:49:4422#include "net/base/int128.h"
[email protected]79d13dcb2014-02-05 07:23:1323#include "net/base/ip_endpoint.h"
[email protected]8b37a092012-10-18 21:53:4924#include "net/base/net_export.h"
[email protected]5dafdb62013-11-14 01:24:2625#include "net/quic/iovector.h"
[email protected]fee17f72013-02-03 07:47:4126#include "net/quic/quic_bandwidth.h"
[email protected]2a960e02012-11-11 14:48:1027#include "net/quic/quic_time.h"
[email protected]8b37a092012-10-18 21:53:4928
29namespace net {
30
[email protected]97cf3022013-09-05 14:30:1631class QuicAckNotifier;
[email protected]8b37a092012-10-18 21:53:4932class QuicPacket;
[email protected]b064310782013-05-30 21:12:1733struct QuicPacketHeader;
[email protected]8b37a092012-10-18 21:53:4934
[email protected]3aa9ca72014-02-27 19:39:4335typedef uint64 QuicConnectionId;
[email protected]8b37a092012-10-18 21:53:4936typedef uint32 QuicStreamId;
37typedef uint64 QuicStreamOffset;
38typedef uint64 QuicPacketSequenceNumber;
[email protected]c995c572013-01-18 05:43:2039typedef QuicPacketSequenceNumber QuicFecGroupNumber;
[email protected]86a318d2013-01-23 21:16:0440typedef uint64 QuicPublicResetNonceProof;
[email protected]9db443912013-02-25 05:27:0341typedef uint8 QuicPacketEntropyHash;
[email protected]c244c5a12013-05-07 20:55:0442typedef uint32 QuicHeaderId;
[email protected]2532de12013-05-09 12:29:3343// QuicTag is the type of a tag in the wire protocol.
44typedef uint32 QuicTag;
45typedef std::vector<QuicTag> QuicTagVector;
[email protected]79d13dcb2014-02-05 07:23:1346typedef std::map<QuicTag, std::string> QuicTagValueMap;
[email protected]497bfb22014-01-08 01:28:0347// TODO(rtenneti): Didn't use SpdyPriority because SpdyPriority is uint8 and
48// QuicPriority is uint32. Use SpdyPriority when we change the QUIC_VERSION.
[email protected]8edeb8d2013-08-28 06:11:4349typedef uint32 QuicPriority;
[email protected]cff7b7b2013-01-11 08:49:0750
[email protected]8e01c062013-10-31 07:35:3151// Default and initial maximum size in bytes of a QUIC packet.
[email protected]310d37b2014-08-02 06:15:3752const QuicByteCount kDefaultMaxPacketSize = 1350;
rtenneti16a20772015-02-17 18:58:4853// Default initial maximum size in bytes of a QUIC packet for servers.
54const QuicByteCount kDefaultServerMaxPacketSize = 1000;
[email protected]8e01c062013-10-31 07:35:3155// The maximum packet size of any QUIC packet, based on ethernet's max size,
[email protected]41fb6372013-12-10 05:26:4056// minus the IP and UDP headers. IPv6 has a 40 byte header, UPD adds an
57// additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's
58// max packet size is 1500 bytes, 1500 - 48 = 1452.
59const QuicByteCount kMaxPacketSize = 1452;
rtenneti9e0fb502015-03-08 06:07:1660// Default maximum packet size used in the Linux TCP implementation.
61// Used in QUIC for congestion window computations in bytes.
[email protected]ce7bb1412014-05-17 15:51:3362const QuicByteCount kDefaultTCPMSS = 1460;
[email protected]8e01c062013-10-31 07:35:3163
rtenneti3fe4ebbc2014-11-16 16:43:4764// We match SPDY's use of 32 when secure (since we'd compete with SPDY).
65const QuicPacketCount kInitialCongestionWindowSecure = 32;
66// Be conservative, and just use double a typical TCP ICWND for HTTP.
67const QuicPacketCount kInitialCongestionWindowInsecure = 20;
[email protected]8e01c062013-10-31 07:35:3168
rtenneti7652bf32015-01-05 18:51:0769// Minimum size of initial flow control window, for both stream and session.
70const uint32 kMinimumFlowControlSendWindow = 16 * 1024; // 16 KB
[email protected]9bb57c72014-03-31 20:36:0471
rtennetifb3fa6c2015-03-16 23:04:5572// Minimum size of the CWND, in packets, when doing bandwidth resumption.
rtenneti8d2a808d2014-11-26 01:10:0973const QuicPacketCount kMinCongestionWindowForBandwidthResumption = 10;
rtenneti8d2a808d2014-11-26 01:10:0974
rtennetifb3fa6c2015-03-16 23:04:5575// Maximum size of the CWND, in packets, for TCP congestion control algorithms.
76const QuicPacketCount kMaxTcpCongestionWindow = 200;
[email protected]0ac0c5b2013-11-20 05:55:5877
rtenneti23186682014-10-30 01:49:3378// Default size of the socket receive buffer in bytes.
[email protected]648f81142014-08-15 21:38:4679const QuicByteCount kDefaultSocketReceiveBuffer = 256 * 1024;
rtenneti23186682014-10-30 01:49:3380// Minimum size of the socket receive buffer in bytes.
81// Smaller values are ignored.
82const QuicByteCount kMinSocketReceiveBuffer = 16 * 1024;
[email protected]a97b3182014-08-08 08:10:1883
rtenneti95293802015-03-27 18:59:2384// Fraction of the receive buffer that can be used for encrypted bytes.
85// Allows a 5% overhead for IP and UDP framing, as well as ack only packets.
86static const float kUsableRecieveBufferFraction = 0.95f;
87
rtennetifc97ab62014-11-11 22:17:4988// Don't allow a client to suggest an RTT shorter than 10ms.
89const uint32 kMinInitialRoundTripTimeUs = 10 * kNumMicrosPerMilli;
90
[email protected]8e01c062013-10-31 07:35:3191// Don't allow a client to suggest an RTT longer than 15 seconds.
[email protected]2d43c40122014-04-21 14:51:2792const uint32 kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond;
[email protected]8b37a092012-10-18 21:53:4993
94// Maximum number of open streams per connection.
95const size_t kDefaultMaxStreamsPerConnection = 100;
96
[email protected]af806e62013-05-22 14:47:5097// Number of bytes reserved for public flags in the packet header.
98const size_t kPublicFlagsSize = 1;
[email protected]5351cc4b2013-03-03 07:22:4199// Number of bytes reserved for version number in the packet header.
100const size_t kQuicVersionSize = 4;
[email protected]c995c572013-01-18 05:43:20101// Number of bytes reserved for private flags in the packet header.
102const size_t kPrivateFlagsSize = 1;
103// Number of bytes reserved for FEC group in the packet header.
104const size_t kFecGroupSize = 1;
[email protected]5351cc4b2013-03-03 07:22:41105
106// Signifies that the QuicPacket will contain version of the protocol.
107const bool kIncludeVersion = true;
[email protected]c995c572013-01-18 05:43:20108
[email protected]5351cc4b2013-03-03 07:22:41109// Index of the first byte in a QUIC packet which is used in hash calculation.
110const size_t kStartOfHashData = 0;
[email protected]8b37a092012-10-18 21:53:49111
112// Limit on the delta between stream IDs.
[email protected]c5cc9bd2014-03-31 23:17:14113const QuicStreamId kMaxStreamIdDelta = 200;
[email protected]8b37a092012-10-18 21:53:49114
115// Reserved ID for the crypto stream.
[email protected]8b37a092012-10-18 21:53:49116const QuicStreamId kCryptoStreamId = 1;
117
[email protected]4d640792013-12-18 22:21:08118// Reserved ID for the headers stream.
119const QuicStreamId kHeadersStreamId = 3;
120
[email protected]648f81142014-08-15 21:38:46121// Maximum delayed ack time, in ms.
pkastingacec86f2014-10-14 23:08:55122const int64 kMaxDelayedAckTimeMs = 25;
[email protected]648f81142014-08-15 21:38:46123
rtennetib5512bb2014-09-29 19:17:15124// The timeout before the handshake succeeds.
125const int64 kInitialIdleTimeoutSecs = 5;
126// The default idle timeout.
127const int64 kDefaultIdleTimeoutSecs = 30;
rtenneti31e9fd62014-09-16 05:22:15128// The maximum idle timeout that can be negotiated.
129const int64 kMaximumIdleTimeoutSecs = 60 * 10; // 10 minutes.
130// The default timeout for a connection until the crypto handshake succeeds.
rtennetib5512bb2014-09-29 19:17:15131const int64 kMaxTimeForCryptoHandshakeSecs = 10; // 10 secs.
[email protected]8b37a092012-10-18 21:53:49132
rtenneti93bce7ece2014-10-13 22:38:41133// Default limit on the number of undecryptable packets the connection buffers
134// before the CHLO/SHLO arrive.
135const size_t kDefaultMaxUndecryptablePackets = 10;
136
[email protected]525948df2014-04-21 06:26:58137// Default ping timeout.
138const int64 kPingTimeoutSecs = 15; // 15 secs.
139
[email protected]ca4e0d92014-08-22 16:33:22140// Minimum number of RTTs between Server Config Updates (SCUP) sent to client.
141const int kMinIntervalBetweenServerConfigUpdatesRTTs = 10;
142
143// Minimum time between Server Config Updates (SCUP) sent to client.
144const int kMinIntervalBetweenServerConfigUpdatesMs = 1000;
145
rtenneti33da8ab2014-11-04 04:17:00146// Minimum number of packets between Server Config Updates (SCUP).
147const int kMinPacketsBetweenServerConfigUpdates = 100;
148
rtennetib5512bb2014-09-29 19:17:15149// The number of open streams that a server will accept is set to be slightly
150// larger than the negotiated limit. Immediately closing the connection if the
151// client opens slightly too many streams is not ideal: the client may have sent
152// a FIN that was lost, and simultaneously opened a new stream. The number of
153// streams a server accepts is a fixed increment over the negotiated limit, or a
154// percentage increase, whichever is larger.
rtenneti31e9fd62014-09-16 05:22:15155const float kMaxStreamsMultiplier = 1.1f;
rtennetib5512bb2014-09-29 19:17:15156const int kMaxStreamsMinimumIncrement = 10;
rtenneti31e9fd62014-09-16 05:22:15157
[email protected]b007e632013-10-28 08:39:25158// We define an unsigned 16-bit floating point value, inspired by IEEE floats
159// (http://en.wikipedia.org/wiki/Half_precision_floating-point_format),
160// with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden
161// bit) and denormals, but without signs, transfinites or fractions. Wire format
162// 16 bits (little-endian byte order) are split into exponent (high 5) and
163// mantissa (low 11) and decoded as:
164// uint64 value;
165// if (exponent == 0) value = mantissa;
166// else value = (mantissa | 1 << 11) << (exponent - 1)
167const int kUFloat16ExponentBits = 5;
168const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30
169const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11
170const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12
171const uint64 kUFloat16MaxValue = // 0x3FFC0000000
172 ((GG_UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1) <<
173 kUFloat16MaxExponent;
174
[email protected]c67a82cb2013-09-24 02:53:21175enum TransmissionType {
[email protected]2532de12013-05-09 12:29:33176 NOT_RETRANSMISSION,
[email protected]b9475b582014-03-20 20:04:33177 FIRST_TRANSMISSION_TYPE = NOT_RETRANSMISSION,
178 HANDSHAKE_RETRANSMISSION, // Retransmits due to handshake timeouts.
rtenneti31e9fd62014-09-16 05:22:15179 ALL_UNACKED_RETRANSMISSION, // Retransmits all unacked packets.
180 ALL_INITIAL_RETRANSMISSION, // Retransmits all initially encrypted packets.
[email protected]b9475b582014-03-20 20:04:33181 LOSS_RETRANSMISSION, // Retransmits due to loss detection.
182 RTO_RETRANSMISSION, // Retransmits due to retransmit time out.
183 TLP_RETRANSMISSION, // Tail loss probes.
184 LAST_TRANSMISSION_TYPE = TLP_RETRANSMISSION,
[email protected]74bda142013-03-31 02:49:11185};
186
187enum HasRetransmittableData {
[email protected]2532de12013-05-09 12:29:33188 NO_RETRANSMITTABLE_DATA,
189 HAS_RETRANSMITTABLE_DATA,
[email protected]74bda142013-03-31 02:49:11190};
191
[email protected]575cce62013-08-03 02:06:43192enum IsHandshake {
193 NOT_HANDSHAKE,
194 IS_HANDSHAKE
195};
196
rtenneti6f48aa92015-03-16 02:18:48197enum class Perspective { IS_SERVER, IS_CLIENT };
198
199NET_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
200 const Perspective& s);
201
[email protected]bbb10072014-06-13 07:41:59202// Indicates FEC protection level for data being written.
203enum FecProtection {
204 MUST_FEC_PROTECT, // Callee must FEC protect this data.
[email protected]a5b98172014-06-18 07:01:59205 MAY_FEC_PROTECT // Callee does not have to but may FEC protect this data.
206};
207
[email protected]bc356fe2014-06-19 11:14:14208// Indicates FEC policy.
[email protected]a5b98172014-06-18 07:01:59209enum FecPolicy {
210 FEC_PROTECT_ALWAYS, // All data in the stream should be FEC protected.
211 FEC_PROTECT_OPTIONAL // Data in the stream does not need FEC protection.
[email protected]bbb10072014-06-13 07:41:59212};
213
[email protected]be24ab22012-10-22 03:01:52214enum QuicFrameType {
[email protected]6ae6e342014-02-06 02:21:42215 // Regular frame types. The values set here cannot change without the
216 // introduction of a new QUIC version.
[email protected]c995c572013-01-18 05:43:20217 PADDING_FRAME = 0,
[email protected]6ae6e342014-02-06 02:21:42218 RST_STREAM_FRAME = 1,
219 CONNECTION_CLOSE_FRAME = 2,
220 GOAWAY_FRAME = 3,
221 WINDOW_UPDATE_FRAME = 4,
222 BLOCKED_FRAME = 5,
[email protected]93dd91f2014-02-27 00:09:03223 STOP_WAITING_FRAME = 6,
[email protected]d8c522112014-04-23 09:23:25224 PING_FRAME = 7,
[email protected]6ae6e342014-02-06 02:21:42225
rtennetif4bdb542015-01-21 14:33:05226 // STREAM and ACK frames are special frames. They are encoded differently on
227 // the wire and their values do not need to be stable.
[email protected]97cf3022013-09-05 14:30:16228 STREAM_FRAME,
229 ACK_FRAME,
[email protected]be24ab22012-10-22 03:01:52230 NUM_FRAME_TYPES
[email protected]8b37a092012-10-18 21:53:49231};
232
[email protected]3aa9ca72014-02-27 19:39:43233enum QuicConnectionIdLength {
234 PACKET_0BYTE_CONNECTION_ID = 0,
235 PACKET_1BYTE_CONNECTION_ID = 1,
236 PACKET_4BYTE_CONNECTION_ID = 4,
237 PACKET_8BYTE_CONNECTION_ID = 8
[email protected]b064310782013-05-30 21:12:17238};
239
240enum InFecGroup {
241 NOT_IN_FEC_GROUP,
242 IN_FEC_GROUP,
243};
244
[email protected]25c31dc2013-06-05 17:56:04245enum QuicSequenceNumberLength {
246 PACKET_1BYTE_SEQUENCE_NUMBER = 1,
247 PACKET_2BYTE_SEQUENCE_NUMBER = 2,
248 PACKET_4BYTE_SEQUENCE_NUMBER = 4,
249 PACKET_6BYTE_SEQUENCE_NUMBER = 6
250};
251
[email protected]8e01c062013-10-31 07:35:31252// Used to indicate a QuicSequenceNumberLength using two flag bits.
253enum QuicSequenceNumberLengthFlags {
254 PACKET_FLAGS_1BYTE_SEQUENCE = 0, // 00
255 PACKET_FLAGS_2BYTE_SEQUENCE = 1, // 01
256 PACKET_FLAGS_4BYTE_SEQUENCE = 1 << 1, // 10
257 PACKET_FLAGS_6BYTE_SEQUENCE = 1 << 1 | 1, // 11
258};
259
[email protected]f62262b2013-07-05 20:57:30260// The public flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20261enum QuicPacketPublicFlags {
262 PACKET_PUBLIC_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30263
264 // Bit 0: Does the packet header contains version info?
265 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0,
266
267 // Bit 1: Is this packet a public reset packet?
268 PACKET_PUBLIC_FLAGS_RST = 1 << 1,
269
[email protected]3aa9ca72014-02-27 19:39:43270 // Bits 2 and 3 specify the length of the ConnectionId as follows:
[email protected]f62262b2013-07-05 20:57:30271 // ----00--: 0 bytes
272 // ----01--: 1 byte
273 // ----10--: 4 bytes
274 // ----11--: 8 bytes
[email protected]3aa9ca72014-02-27 19:39:43275 PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID = 0,
276 PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID = 1 << 2,
277 PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID = 1 << 3,
278 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID = 1 << 3 | 1 << 2,
[email protected]f62262b2013-07-05 20:57:30279
280 // Bits 4 and 5 describe the packet sequence number length as follows:
281 // --00----: 1 byte
282 // --01----: 2 bytes
283 // --10----: 4 bytes
284 // --11----: 6 bytes
[email protected]8e01c062013-10-31 07:35:31285 PACKET_PUBLIC_FLAGS_1BYTE_SEQUENCE = PACKET_FLAGS_1BYTE_SEQUENCE << 4,
286 PACKET_PUBLIC_FLAGS_2BYTE_SEQUENCE = PACKET_FLAGS_2BYTE_SEQUENCE << 4,
287 PACKET_PUBLIC_FLAGS_4BYTE_SEQUENCE = PACKET_FLAGS_4BYTE_SEQUENCE << 4,
288 PACKET_PUBLIC_FLAGS_6BYTE_SEQUENCE = PACKET_FLAGS_6BYTE_SEQUENCE << 4,
[email protected]f62262b2013-07-05 20:57:30289
290 // All bits set (bits 6 and 7 are not currently used): 00111111
291 PACKET_PUBLIC_FLAGS_MAX = (1 << 6) - 1
[email protected]c995c572013-01-18 05:43:20292};
[email protected]8b37a092012-10-18 21:53:49293
[email protected]f62262b2013-07-05 20:57:30294// The private flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20295enum QuicPacketPrivateFlags {
296 PACKET_PRIVATE_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30297
298 // Bit 0: Does this packet contain an entropy bit?
[email protected]b064310782013-05-30 21:12:17299 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0,
[email protected]f62262b2013-07-05 20:57:30300
301 // Bit 1: Payload is part of an FEC group?
302 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1,
303
304 // Bit 2: Payload is FEC as opposed to frames?
305 PACKET_PRIVATE_FLAGS_FEC = 1 << 2,
306
307 // All bits set (bits 3-7 are not currently used): 00000111
308 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1
[email protected]c995c572013-01-18 05:43:20309};
310
[email protected]48878092013-07-26 14:51:56311// The available versions of QUIC. Guaranteed that the integer value of the enum
312// will match the version number.
313// When adding a new version to this enum you should add it to
[email protected]8bbfaeb72013-08-09 06:38:26314// kSupportedQuicVersions (if appropriate), and also add a new case to the
315// helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and
316// QuicVersionToString.
[email protected]48878092013-07-26 14:51:56317enum QuicVersion {
318 // Special case to indicate unknown/unsupported QUIC version.
319 QUIC_VERSION_UNSUPPORTED = 0,
320
rtenneti4b06ae72014-08-26 03:43:43321 QUIC_VERSION_23 = 23, // Timestamp in the ack frame.
rtenneti501f0a92015-01-17 01:55:40322 QUIC_VERSION_24 = 24, // SPDY/4 header compression.
[email protected]48878092013-07-26 14:51:56323};
324
325// This vector contains QUIC versions which we currently support.
326// This should be ordered such that the highest supported version is the first
327// element, with subsequent elements in descending order (versions can be
328// skipped as necessary).
[email protected]31ae854842013-11-27 00:05:46329//
[email protected]310d37b2014-08-02 06:15:37330// IMPORTANT: if you are adding to this list, follow the instructions at
[email protected]31ae854842013-11-27 00:05:46331// http://sites/quic/adding-and-removing-versions
rtenneti501f0a92015-01-17 01:55:40332static const QuicVersion kSupportedQuicVersions[] = {QUIC_VERSION_24,
rtennetif4bdb542015-01-21 14:33:05333 QUIC_VERSION_23};
[email protected]48878092013-07-26 14:51:56334
335typedef std::vector<QuicVersion> QuicVersionVector;
336
[email protected]b007e632013-10-28 08:39:25337// Returns a vector of QUIC versions in kSupportedQuicVersions.
338NET_EXPORT_PRIVATE QuicVersionVector QuicSupportedVersions();
[email protected]ea2ab47b2013-08-13 00:44:11339
[email protected]48878092013-07-26 14:51:56340// QuicTag is written to and read from the wire, but we prefer to use
341// the more readable QuicVersion at other levels.
342// Helper function which translates from a QuicVersion to a QuicTag. Returns 0
343// if QuicVersion is unsupported.
344NET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version);
345
346// Returns appropriate QuicVersion from a QuicTag.
347// Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood.
348NET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag);
349
350// Helper function which translates from a QuicVersion to a string.
351// Returns strings corresponding to enum names (e.g. QUIC_VERSION_6).
352NET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version);
353
354// Returns comma separated list of string representations of QuicVersion enum
[email protected]b007e632013-10-28 08:39:25355// values in the supplied |versions| vector.
356NET_EXPORT_PRIVATE std::string QuicVersionVectorToString(
357 const QuicVersionVector& versions);
[email protected]48878092013-07-26 14:51:56358
359// Version and Crypto tags are written to the wire with a big-endian
360// representation of the name of the tag. For example
361// the client hello tag (CHLO) will be written as the
362// following 4 bytes: 'C' 'H' 'L' 'O'. Since it is
363// stored in memory as a little endian uint32, we need
364// to reverse the order of the bytes.
365
366// MakeQuicTag returns a value given the four bytes. For example:
367// MakeQuicTag('C', 'H', 'L', 'O');
368NET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d);
369
[email protected]9cda5fd2014-06-03 10:20:28370// Returns true if the tag vector contains the specified tag.
[email protected]cc1aa272014-06-30 19:48:22371NET_EXPORT_PRIVATE bool ContainsQuicTag(const QuicTagVector& tag_vector,
372 QuicTag tag);
[email protected]9cda5fd2014-06-03 10:20:28373
[email protected]b064310782013-05-30 21:12:17374// Size in bytes of the data or fec packet header.
[email protected]79d13dcb2014-02-05 07:23:13375NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(const QuicPacketHeader& header);
[email protected]b064310782013-05-30 21:12:17376
[email protected]25c31dc2013-06-05 17:56:04377NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(
[email protected]3aa9ca72014-02-27 19:39:43378 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04379 bool include_version,
380 QuicSequenceNumberLength sequence_number_length,
381 InFecGroup is_in_fec_group);
[email protected]b064310782013-05-30 21:12:17382
[email protected]b064310782013-05-30 21:12:17383// Index of the first byte in a QUIC packet of FEC protected data.
[email protected]25c31dc2013-06-05 17:56:04384NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(
[email protected]3aa9ca72014-02-27 19:39:43385 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04386 bool include_version,
387 QuicSequenceNumberLength sequence_number_length);
[email protected]b064310782013-05-30 21:12:17388// Index of the first byte in a QUIC packet of encrypted data.
[email protected]25c31dc2013-06-05 17:56:04389NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(
[email protected]3aa9ca72014-02-27 19:39:43390 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04391 bool include_version,
392 QuicSequenceNumberLength sequence_number_length);
[email protected]b064310782013-05-30 21:12:17393
[email protected]74bda142013-03-31 02:49:11394enum QuicRstStreamErrorCode {
395 QUIC_STREAM_NO_ERROR = 0,
[email protected]8b37a092012-10-18 21:53:49396
[email protected]24e5bc52013-09-18 15:36:58397 // There was some error which halted stream processing.
398 QUIC_ERROR_PROCESSING_STREAM,
[email protected]8b37a092012-10-18 21:53:49399 // We got two fin or reset offsets which did not match.
400 QUIC_MULTIPLE_TERMINATION_OFFSETS,
401 // We got bad payload and can not respond to it at the protocol level.
402 QUIC_BAD_APPLICATION_PAYLOAD,
[email protected]74bda142013-03-31 02:49:11403 // Stream closed due to connection error. No reset frame is sent when this
404 // happens.
405 QUIC_STREAM_CONNECTION_ERROR,
406 // GoAway frame sent. No more stream can be created.
407 QUIC_STREAM_PEER_GOING_AWAY,
[email protected]06ff5152013-08-29 01:03:05408 // The stream has been cancelled.
409 QUIC_STREAM_CANCELLED,
rtenneti4a5df262014-11-07 00:43:58410 // Closing stream locally, sending a RST to allow for proper flow control
411 // accounting. Sent in response to a RST from the peer.
412 QUIC_RST_ACKNOWLEDGEMENT,
[email protected]8b37a092012-10-18 21:53:49413
[email protected]74bda142013-03-31 02:49:11414 // No error. Used as bound while iterating.
415 QUIC_STREAM_LAST_ERROR,
416};
[email protected]8b37a092012-10-18 21:53:49417
[email protected]51cc1342014-04-18 23:44:37418// Because receiving an unknown QuicRstStreamErrorCode results in connection
419// teardown, we use this to make sure any errors predating a given version are
420// downgraded to the most appropriate existing error.
421NET_EXPORT_PRIVATE QuicRstStreamErrorCode AdjustErrorForVersion(
422 QuicRstStreamErrorCode error_code,
423 QuicVersion version);
424
[email protected]89264042013-08-21 07:35:24425// These values must remain stable as they are uploaded to UMA histograms.
426// To add a new error code, use the current value of QUIC_LAST_ERROR and
427// increment QUIC_LAST_ERROR.
[email protected]74bda142013-03-31 02:49:11428enum QuicErrorCode {
429 QUIC_NO_ERROR = 0,
430
431 // Connection has reached an invalid state.
[email protected]89264042013-08-21 07:35:24432 QUIC_INTERNAL_ERROR = 1,
[email protected]74bda142013-03-31 02:49:11433 // There were data frames after the a fin or reset.
[email protected]89264042013-08-21 07:35:24434 QUIC_STREAM_DATA_AFTER_TERMINATION = 2,
[email protected]8b37a092012-10-18 21:53:49435 // Control frame is malformed.
[email protected]89264042013-08-21 07:35:24436 QUIC_INVALID_PACKET_HEADER = 3,
[email protected]be24ab22012-10-22 03:01:52437 // Frame data is malformed.
[email protected]89264042013-08-21 07:35:24438 QUIC_INVALID_FRAME_DATA = 4,
439 // The packet contained no payload.
440 QUIC_MISSING_PAYLOAD = 48,
[email protected]8b37a092012-10-18 21:53:49441 // FEC data is malformed.
[email protected]89264042013-08-21 07:35:24442 QUIC_INVALID_FEC_DATA = 5,
443 // STREAM frame data is malformed.
444 QUIC_INVALID_STREAM_DATA = 46,
[email protected]42a3eba2014-04-30 10:52:55445 // STREAM frame data is not encrypted.
446 QUIC_UNENCRYPTED_STREAM_DATA = 61,
[email protected]89264042013-08-21 07:35:24447 // RST_STREAM frame data is malformed.
448 QUIC_INVALID_RST_STREAM_DATA = 6,
449 // CONNECTION_CLOSE frame data is malformed.
450 QUIC_INVALID_CONNECTION_CLOSE_DATA = 7,
451 // GOAWAY frame data is malformed.
452 QUIC_INVALID_GOAWAY_DATA = 8,
[email protected]6ae6e342014-02-06 02:21:42453 // WINDOW_UPDATE frame data is malformed.
454 QUIC_INVALID_WINDOW_UPDATE_DATA = 57,
455 // BLOCKED frame data is malformed.
456 QUIC_INVALID_BLOCKED_DATA = 58,
[email protected]93dd91f2014-02-27 00:09:03457 // STOP_WAITING frame data is malformed.
458 QUIC_INVALID_STOP_WAITING_DATA = 60,
[email protected]89264042013-08-21 07:35:24459 // ACK frame data is malformed.
460 QUIC_INVALID_ACK_DATA = 9,
rtennetif4bdb542015-01-21 14:33:05461
462 // deprecated: QUIC_INVALID_CONGESTION_FEEDBACK_DATA = 47,
463
[email protected]14e8106c2013-03-14 16:25:33464 // Version negotiation packet is malformed.
[email protected]89264042013-08-21 07:35:24465 QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10,
[email protected]899951652013-05-16 12:52:39466 // Public RST packet is malformed.
[email protected]89264042013-08-21 07:35:24467 QUIC_INVALID_PUBLIC_RST_PACKET = 11,
[email protected]8b37a092012-10-18 21:53:49468 // There was an error decrypting.
[email protected]89264042013-08-21 07:35:24469 QUIC_DECRYPTION_FAILURE = 12,
[email protected]8b37a092012-10-18 21:53:49470 // There was an error encrypting.
[email protected]89264042013-08-21 07:35:24471 QUIC_ENCRYPTION_FAILURE = 13,
[email protected]8b37a092012-10-18 21:53:49472 // The packet exceeded kMaxPacketSize.
[email protected]89264042013-08-21 07:35:24473 QUIC_PACKET_TOO_LARGE = 14,
[email protected]8b37a092012-10-18 21:53:49474 // Data was sent for a stream which did not exist.
[email protected]89264042013-08-21 07:35:24475 QUIC_PACKET_FOR_NONEXISTENT_STREAM = 15,
[email protected]9db443912013-02-25 05:27:03476 // The peer is going away. May be a client or server.
[email protected]89264042013-08-21 07:35:24477 QUIC_PEER_GOING_AWAY = 16,
[email protected]8b37a092012-10-18 21:53:49478 // A stream ID was invalid.
[email protected]89264042013-08-21 07:35:24479 QUIC_INVALID_STREAM_ID = 17,
[email protected]24e5bc52013-09-18 15:36:58480 // A priority was invalid.
481 QUIC_INVALID_PRIORITY = 49,
[email protected]8b37a092012-10-18 21:53:49482 // Too many streams already open.
[email protected]89264042013-08-21 07:35:24483 QUIC_TOO_MANY_OPEN_STREAMS = 18,
[email protected]9693157b2014-08-08 11:13:49484 // The peer must send a FIN/RST for each stream, and has not been doing so.
485 QUIC_TOO_MANY_UNFINISHED_STREAMS = 66,
[email protected]86a318d2013-01-23 21:16:04486 // Received public reset for this connection.
[email protected]89264042013-08-21 07:35:24487 QUIC_PUBLIC_RESET = 19,
[email protected]c244c5a12013-05-07 20:55:04488 // Invalid protocol version.
[email protected]89264042013-08-21 07:35:24489 QUIC_INVALID_VERSION = 20,
[email protected]92bf17c2014-03-03 21:14:03490
491 // deprecated: QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED = 21
492
[email protected]c244c5a12013-05-07 20:55:04493 // The Header ID for a stream was too far from the previous.
[email protected]89264042013-08-21 07:35:24494 QUIC_INVALID_HEADER_ID = 22,
[email protected]899951652013-05-16 12:52:39495 // Negotiable parameter received during handshake had invalid value.
[email protected]89264042013-08-21 07:35:24496 QUIC_INVALID_NEGOTIATED_VALUE = 23,
[email protected]899951652013-05-16 12:52:39497 // There was an error decompressing data.
[email protected]89264042013-08-21 07:35:24498 QUIC_DECOMPRESSION_FAILURE = 24,
[email protected]8b37a092012-10-18 21:53:49499 // We hit our prenegotiated (or default) timeout
[email protected]89264042013-08-21 07:35:24500 QUIC_CONNECTION_TIMED_OUT = 25,
rtenneti31e9fd62014-09-16 05:22:15501 // We hit our overall connection timeout
502 QUIC_CONNECTION_OVERALL_TIMED_OUT = 67,
[email protected]899951652013-05-16 12:52:39503 // There was an error encountered migrating addresses
[email protected]89264042013-08-21 07:35:24504 QUIC_ERROR_MIGRATING_ADDRESS = 26,
[email protected]1505a512013-09-04 22:59:35505 // There was an error while writing to the socket.
[email protected]89264042013-08-21 07:35:24506 QUIC_PACKET_WRITE_ERROR = 27,
[email protected]1505a512013-09-04 22:59:35507 // There was an error while reading from the socket.
508 QUIC_PACKET_READ_ERROR = 51,
[email protected]24e5bc52013-09-18 15:36:58509 // We received a STREAM_FRAME with no data and no fin flag set.
510 QUIC_INVALID_STREAM_FRAME = 50,
[email protected]4d640792013-12-18 22:21:08511 // We received invalid data on the headers stream.
512 QUIC_INVALID_HEADERS_STREAM_DATA = 56,
[email protected]730b35d72014-06-05 03:23:22513 // The peer received too much data, violating flow control.
514 QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA = 59,
515 // The peer sent too much data, violating flow control.
516 QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA = 63,
517 // The peer received an invalid flow control window.
518 QUIC_FLOW_CONTROL_INVALID_WINDOW = 64,
[email protected]71c84e592014-05-28 23:39:29519 // The connection has been IP pooled into an existing connection.
520 QUIC_CONNECTION_IP_POOLED = 62,
rtenneti23186682014-10-30 01:49:33521 // The connection has too many outstanding sent packets.
522 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS = 68,
523 // The connection has too many outstanding received packets.
524 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS = 69,
rtenneti14abd312015-02-06 21:56:01525 // The quic connection job to load server config is cancelled.
526 QUIC_CONNECTION_CANCELLED = 70,
[email protected]8b37a092012-10-18 21:53:49527
528 // Crypto errors.
529
[email protected]1354bf62013-05-23 23:17:18530 // Hanshake failed.
[email protected]89264042013-08-21 07:35:24531 QUIC_HANDSHAKE_FAILED = 28,
[email protected]8b37a092012-10-18 21:53:49532 // Handshake message contained out of order tags.
[email protected]89264042013-08-21 07:35:24533 QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29,
[email protected]701bc892013-01-17 04:51:54534 // Handshake message contained too many entries.
[email protected]89264042013-08-21 07:35:24535 QUIC_CRYPTO_TOO_MANY_ENTRIES = 30,
[email protected]8b37a092012-10-18 21:53:49536 // Handshake message contained an invalid value length.
[email protected]89264042013-08-21 07:35:24537 QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31,
[email protected]8b37a092012-10-18 21:53:49538 // A crypto message was received after the handshake was complete.
[email protected]89264042013-08-21 07:35:24539 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32,
[email protected]d3d15bf2013-01-30 02:51:54540 // A crypto message was received with an illegal message tag.
[email protected]89264042013-08-21 07:35:24541 QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33,
[email protected]d3d15bf2013-01-30 02:51:54542 // A crypto message was received with an illegal parameter.
[email protected]89264042013-08-21 07:35:24543 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34,
[email protected]752fbe52013-10-14 08:35:32544 // An invalid channel id signature was supplied.
545 QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52,
[email protected]d3d15bf2013-01-30 02:51:54546 // A crypto message was received with a mandatory parameter missing.
[email protected]89264042013-08-21 07:35:24547 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35,
[email protected]d3d15bf2013-01-30 02:51:54548 // A crypto message was received with a parameter that has no overlap
549 // with the local parameter.
[email protected]89264042013-08-21 07:35:24550 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36,
[email protected]ed3fc15d2013-03-08 18:37:44551 // A crypto message was received that contained a parameter with too few
552 // values.
[email protected]89264042013-08-21 07:35:24553 QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37,
[email protected]ccc66e8a2013-03-26 08:26:14554 // An internal error occured in crypto processing.
[email protected]89264042013-08-21 07:35:24555 QUIC_CRYPTO_INTERNAL_ERROR = 38,
[email protected]ccc66e8a2013-03-26 08:26:14556 // A crypto handshake message specified an unsupported version.
[email protected]89264042013-08-21 07:35:24557 QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39,
[email protected]ccc66e8a2013-03-26 08:26:14558 // There was no intersection between the crypto primitives supported by the
559 // peer and ourselves.
[email protected]89264042013-08-21 07:35:24560 QUIC_CRYPTO_NO_SUPPORT = 40,
[email protected]ef95114d2013-04-17 17:57:01561 // The server rejected our client hello messages too many times.
[email protected]89264042013-08-21 07:35:24562 QUIC_CRYPTO_TOO_MANY_REJECTS = 41,
[email protected]a57e0272013-04-26 07:31:47563 // The client rejected the server's certificate chain or signature.
[email protected]89264042013-08-21 07:35:24564 QUIC_PROOF_INVALID = 42,
[email protected]8ba81212013-05-03 13:11:48565 // A crypto message was received with a duplicate tag.
[email protected]89264042013-08-21 07:35:24566 QUIC_CRYPTO_DUPLICATE_TAG = 43,
[email protected]2532de12013-05-09 12:29:33567 // A crypto message was received with the wrong encryption level (i.e. it
568 // should have been encrypted but was not.)
[email protected]89264042013-08-21 07:35:24569 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44,
[email protected]2532de12013-05-09 12:29:33570 // The server config for a server has expired.
[email protected]89264042013-08-21 07:35:24571 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45,
[email protected]752fbe52013-10-14 08:35:32572 // We failed to setup the symmetric keys for a connection.
573 QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53,
[email protected]691f45a982013-11-19 10:52:04574 // A handshake message arrived, but we are still validating the
575 // previous handshake message.
576 QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54,
[email protected]ccb34212014-07-18 09:27:50577 // A server config update arrived before the handshake is complete.
578 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE = 65,
[email protected]d89f1862013-11-26 21:21:27579 // This connection involved a version negotiation which appears to have been
580 // tampered with.
581 QUIC_VERSION_NEGOTIATION_MISMATCH = 55,
[email protected]ccc66e8a2013-03-26 08:26:14582
[email protected]74bda142013-03-31 02:49:11583 // No error. Used as bound while iterating.
rtenneti14abd312015-02-06 21:56:01584 QUIC_LAST_ERROR = 71,
[email protected]8b37a092012-10-18 21:53:49585};
586
[email protected]c995c572013-01-18 05:43:20587struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
[email protected]14e8106c2013-03-14 16:25:33588 QuicPacketPublicHeader();
589 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
590 ~QuicPacketPublicHeader();
591
[email protected]3aa9ca72014-02-27 19:39:43592 // Universal header. All QuicPacket headers will have a connection_id and
593 // public flags.
594 QuicConnectionId connection_id;
595 QuicConnectionIdLength connection_id_length;
[email protected]9db443912013-02-25 05:27:03596 bool reset_flag;
597 bool version_flag;
[email protected]25c31dc2013-06-05 17:56:04598 QuicSequenceNumberLength sequence_number_length;
[email protected]48878092013-07-26 14:51:56599 QuicVersionVector versions;
[email protected]c995c572013-01-18 05:43:20600};
601
rtenneti9e0fb502015-03-08 06:07:16602// An integer which cannot be a packet sequence number.
603const QuicPacketSequenceNumber kInvalidPacketSequenceNumber = 0;
604
[email protected]c995c572013-01-18 05:43:20605// Header for Data or FEC packets.
[email protected]74bda142013-03-31 02:49:11606struct NET_EXPORT_PRIVATE QuicPacketHeader {
607 QuicPacketHeader();
608 explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
[email protected]9db443912013-02-25 05:27:03609
610 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
611 std::ostream& os, const QuicPacketHeader& s);
612
[email protected]c995c572013-01-18 05:43:20613 QuicPacketPublicHeader public_header;
[email protected]9db443912013-02-25 05:27:03614 bool fec_flag;
[email protected]9db443912013-02-25 05:27:03615 bool entropy_flag;
616 QuicPacketEntropyHash entropy_hash;
[email protected]8b37a092012-10-18 21:53:49617 QuicPacketSequenceNumber packet_sequence_number;
[email protected]b064310782013-05-30 21:12:17618 InFecGroup is_in_fec_group;
[email protected]8b37a092012-10-18 21:53:49619 QuicFecGroupNumber fec_group;
620};
621
[email protected]74bda142013-03-31 02:49:11622struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
[email protected]6ae6e342014-02-06 02:21:42623 QuicPublicResetPacket();
624 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header);
625
[email protected]86a318d2013-01-23 21:16:04626 QuicPacketPublicHeader public_header;
[email protected]86a318d2013-01-23 21:16:04627 QuicPublicResetNonceProof nonce_proof;
[email protected]300ccd52014-01-25 08:00:19628 QuicPacketSequenceNumber rejected_sequence_number;
[email protected]79d13dcb2014-02-05 07:23:13629 IPEndPoint client_address;
[email protected]86a318d2013-01-23 21:16:04630};
631
[email protected]14e8106c2013-03-14 16:25:33632enum QuicVersionNegotiationState {
633 START_NEGOTIATION = 0,
[email protected]ec640112013-08-09 03:56:18634 // Server-side this implies we've sent a version negotiation packet and are
635 // waiting on the client to select a compatible version. Client-side this
636 // implies we've gotten a version negotiation packet, are retransmitting the
637 // initial packets with a supported version and are waiting for our first
638 // packet from the server.
639 NEGOTIATION_IN_PROGRESS,
640 // This indicates this endpoint has received a packet from the peer with a
641 // version this endpoint supports. Version negotiation is complete, and the
642 // version number will no longer be sent with future packets.
[email protected]14e8106c2013-03-14 16:25:33643 NEGOTIATED_VERSION
644};
645
646typedef QuicPacketPublicHeader QuicVersionNegotiationPacket;
647
[email protected]c995c572013-01-18 05:43:20648// A padding frame contains no payload.
649struct NET_EXPORT_PRIVATE QuicPaddingFrame {
650};
651
[email protected]d8c522112014-04-23 09:23:25652// A ping frame contains no payload, though it is retransmittable,
653// and ACK'd just like other normal frames.
654struct NET_EXPORT_PRIVATE QuicPingFrame {
655};
656
[email protected]be24ab22012-10-22 03:01:52657struct NET_EXPORT_PRIVATE QuicStreamFrame {
658 QuicStreamFrame();
[email protected]5dafdb62013-11-14 01:24:26659 QuicStreamFrame(const QuicStreamFrame& frame);
[email protected]be24ab22012-10-22 03:01:52660 QuicStreamFrame(QuicStreamId stream_id,
[email protected]a5061242012-10-23 23:29:37661 bool fin,
[email protected]701bc892013-01-17 04:51:54662 QuicStreamOffset offset,
[email protected]5dafdb62013-11-14 01:24:26663 IOVector data);
664
[email protected]c5e1aca2014-01-30 04:03:04665 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
666 std::ostream& os, const QuicStreamFrame& s);
667
[email protected]5dafdb62013-11-14 01:24:26668 // Returns a copy of the IOVector |data| as a heap-allocated string.
669 // Caller must take ownership of the returned string.
670 std::string* GetDataAsString() const;
[email protected]8b37a092012-10-18 21:53:49671
672 QuicStreamId stream_id;
673 bool fin;
[email protected]701bc892013-01-17 04:51:54674 QuicStreamOffset offset; // Location of this data in the stream.
[email protected]5dafdb62013-11-14 01:24:26675 IOVector data;
[email protected]8b37a092012-10-18 21:53:49676};
677
[email protected]e537f742012-12-07 15:33:53678// TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
679// is finalized.
[email protected]9db443912013-02-25 05:27:03680typedef std::set<QuicPacketSequenceNumber> SequenceNumberSet;
rtennetidd4bf8f2014-09-03 00:45:16681typedef std::list<QuicPacketSequenceNumber> SequenceNumberList;
rtenneti4b06ae72014-08-26 03:43:43682
mostynbdc40b80612014-09-10 03:45:42683typedef std::list<
684 std::pair<QuicPacketSequenceNumber, QuicTime> > PacketTimeList;
[email protected]044ac2b2012-11-13 21:41:06685
[email protected]310d37b2014-08-02 06:15:37686struct NET_EXPORT_PRIVATE QuicStopWaitingFrame {
687 QuicStopWaitingFrame();
688 ~QuicStopWaitingFrame();
[email protected]6ae6e342014-02-06 02:21:42689
[email protected]26f3f8e2012-12-13 21:07:19690 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
[email protected]310d37b2014-08-02 06:15:37691 std::ostream& os, const QuicStopWaitingFrame& s);
692 // Entropy hash of all packets up to, but not including, the least unacked
693 // packet.
694 QuicPacketEntropyHash entropy_hash;
695 // The lowest packet we've sent which is unacked, and we expect an ack for.
696 QuicPacketSequenceNumber least_unacked;
697};
698
699struct NET_EXPORT_PRIVATE QuicAckFrame {
700 QuicAckFrame();
701 ~QuicAckFrame();
702
703 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
704 std::ostream& os, const QuicAckFrame& s);
[email protected]a674b4c2012-12-05 03:44:30705
[email protected]9db443912013-02-25 05:27:03706 // Entropy hash of all packets up to largest observed not including missing
707 // packets.
708 QuicPacketEntropyHash entropy_hash;
[email protected]e537f742012-12-07 15:33:53709
[email protected]48697d8a2013-01-15 19:42:24710 // The highest packet sequence number we've observed from the peer.
711 //
712 // In general, this should be the largest packet number we've received. In
713 // the case of truncated acks, we may have to advertise a lower "upper bound"
714 // than largest received, to avoid implicitly acking missing packets that
715 // don't fit in the missing packet list due to size limitations. In this
716 // case, largest_observed may be a packet which is also in the missing packets
717 // list.
718 QuicPacketSequenceNumber largest_observed;
[email protected]a674b4c2012-12-05 03:44:30719
[email protected]14e8106c2013-03-14 16:25:33720 // Time elapsed since largest_observed was received until this Ack frame was
721 // sent.
722 QuicTime::Delta delta_time_largest_observed;
723
[email protected]9db443912013-02-25 05:27:03724 // TODO(satyamshekhar): Can be optimized using an interval set like data
725 // structure.
[email protected]e537f742012-12-07 15:33:53726 // The set of packets which we're expecting and have not received.
[email protected]9db443912013-02-25 05:27:03727 SequenceNumberSet missing_packets;
[email protected]8e01c062013-10-31 07:35:31728
729 // Whether the ack had to be truncated when sent.
730 bool is_truncated;
[email protected]bdf2d432014-02-09 10:45:41731
732 // Packets which have been revived via FEC.
733 // All of these must also be in missing_packets.
734 SequenceNumberSet revived_packets;
rtenneti4b06ae72014-08-26 03:43:43735
736 // List of <sequence_number, time> for when packets arrived.
737 PacketTimeList received_packet_times;
[email protected]8b37a092012-10-18 21:53:49738};
739
[email protected]9db443912013-02-25 05:27:03740// True if the sequence number is greater than largest_observed or is listed
741// as missing.
742// Always returns false for sequence numbers less than least_unacked.
743bool NET_EXPORT_PRIVATE IsAwaitingPacket(
[email protected]310d37b2014-08-02 06:15:37744 const QuicAckFrame& ack_frame,
[email protected]9db443912013-02-25 05:27:03745 QuicPacketSequenceNumber sequence_number);
746
747// Inserts missing packets between [lower, higher).
748void NET_EXPORT_PRIVATE InsertMissingPacketsBetween(
[email protected]310d37b2014-08-02 06:15:37749 QuicAckFrame* ack_frame,
[email protected]9db443912013-02-25 05:27:03750 QuicPacketSequenceNumber lower,
751 QuicPacketSequenceNumber higher);
752
[email protected]a692ad9d2014-07-18 21:35:24753// Defines for all types of congestion control algorithms that can be used in
754// QUIC. Note that this is separate from the congestion feedback type -
755// some congestion control algorithms may use the same feedback type
756// (Reno and Cubic are the classic example for that).
757enum CongestionControlType {
758 kCubic,
rtennetifb3fa6c2015-03-16 23:04:55759 kCubicBytes,
[email protected]a692ad9d2014-07-18 21:35:24760 kReno,
rtennetifb3fa6c2015-03-16 23:04:55761 kRenoBytes,
[email protected]a692ad9d2014-07-18 21:35:24762 kBBR,
[email protected]8b37a092012-10-18 21:53:49763};
764
[email protected]c5cc9bd2014-03-31 23:17:14765enum LossDetectionType {
766 kNack, // Used to mimic TCP's loss detection.
767 kTime, // Time based loss detection.
768};
769
[email protected]be24ab22012-10-22 03:01:52770struct NET_EXPORT_PRIVATE QuicRstStreamFrame {
[email protected]6ae6e342014-02-06 02:21:42771 QuicRstStreamFrame();
772 QuicRstStreamFrame(QuicStreamId stream_id,
773 QuicRstStreamErrorCode error_code,
774 QuicStreamOffset bytes_written);
[email protected]8b37a092012-10-18 21:53:49775
[email protected]c5e1aca2014-01-30 04:03:04776 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
777 std::ostream& os, const QuicRstStreamFrame& r);
778
[email protected]8b37a092012-10-18 21:53:49779 QuicStreamId stream_id;
[email protected]74bda142013-03-31 02:49:11780 QuicRstStreamErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09781 std::string error_details;
[email protected]6ae6e342014-02-06 02:21:42782
783 // Used to update flow control windows. On termination of a stream, both
784 // endpoints must inform the peer of the number of bytes they have sent on
785 // that stream. This can be done through normal termination (data packet with
786 // FIN) or through a RST.
787 QuicStreamOffset byte_offset;
[email protected]8b37a092012-10-18 21:53:49788};
789
[email protected]be24ab22012-10-22 03:01:52790struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame {
[email protected]6ae6e342014-02-06 02:21:42791 QuicConnectionCloseFrame();
792
[email protected]c5e1aca2014-01-30 04:03:04793 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
794 std::ostream& os, const QuicConnectionCloseFrame& c);
795
[email protected]431bb4fd2012-10-19 17:46:09796 QuicErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09797 std::string error_details;
[email protected]8b37a092012-10-18 21:53:49798};
799
[email protected]9db443912013-02-25 05:27:03800struct NET_EXPORT_PRIVATE QuicGoAwayFrame {
[email protected]6ae6e342014-02-06 02:21:42801 QuicGoAwayFrame();
[email protected]9db443912013-02-25 05:27:03802 QuicGoAwayFrame(QuicErrorCode error_code,
803 QuicStreamId last_good_stream_id,
804 const std::string& reason);
805
[email protected]c5e1aca2014-01-30 04:03:04806 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
807 std::ostream& os, const QuicGoAwayFrame& g);
808
[email protected]9db443912013-02-25 05:27:03809 QuicErrorCode error_code;
810 QuicStreamId last_good_stream_id;
811 std::string reason_phrase;
812};
813
[email protected]6ae6e342014-02-06 02:21:42814// Flow control updates per-stream and at the connection levoel.
815// Based on SPDY's WINDOW_UPDATE frame, but uses an absolute byte offset rather
816// than a window delta.
817// TODO(rjshade): A possible future optimization is to make stream_id and
818// byte_offset variable length, similar to stream frames.
819struct NET_EXPORT_PRIVATE QuicWindowUpdateFrame {
820 QuicWindowUpdateFrame() {}
821 QuicWindowUpdateFrame(QuicStreamId stream_id, QuicStreamOffset byte_offset);
822
823 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
824 std::ostream& os, const QuicWindowUpdateFrame& w);
825
826 // The stream this frame applies to. 0 is a special case meaning the overall
827 // connection rather than a specific stream.
828 QuicStreamId stream_id;
829
830 // Byte offset in the stream or connection. The receiver of this frame must
831 // not send data which would result in this offset being exceeded.
832 QuicStreamOffset byte_offset;
833};
834
835// The BLOCKED frame is used to indicate to the remote endpoint that this
836// endpoint believes itself to be flow-control blocked but otherwise ready to
837// send data. The BLOCKED frame is purely advisory and optional.
838// Based on SPDY's BLOCKED frame (undocumented as of 2014-01-28).
839struct NET_EXPORT_PRIVATE QuicBlockedFrame {
840 QuicBlockedFrame() {}
841 explicit QuicBlockedFrame(QuicStreamId stream_id);
842
843 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
844 std::ostream& os, const QuicBlockedFrame& b);
845
846 // The stream this frame applies to. 0 is a special case meaning the overall
847 // connection rather than a specific stream.
848 QuicStreamId stream_id;
849};
850
[email protected]8ba81212013-05-03 13:11:48851// EncryptionLevel enumerates the stages of encryption that a QUIC connection
852// progresses through. When retransmitting a packet, the encryption level needs
853// to be specified so that it is retransmitted at a level which the peer can
854// understand.
855enum EncryptionLevel {
856 ENCRYPTION_NONE = 0,
857 ENCRYPTION_INITIAL = 1,
858 ENCRYPTION_FORWARD_SECURE = 2,
859
860 NUM_ENCRYPTION_LEVELS,
861};
862
[email protected]be24ab22012-10-22 03:01:52863struct NET_EXPORT_PRIVATE QuicFrame {
[email protected]6ae6e342014-02-06 02:21:42864 QuicFrame();
865 explicit QuicFrame(QuicPaddingFrame* padding_frame);
866 explicit QuicFrame(QuicStreamFrame* stream_frame);
867 explicit QuicFrame(QuicAckFrame* frame);
rtenneti4b06ae72014-08-26 03:43:43868
[email protected]6ae6e342014-02-06 02:21:42869 explicit QuicFrame(QuicRstStreamFrame* frame);
870 explicit QuicFrame(QuicConnectionCloseFrame* frame);
[email protected]93dd91f2014-02-27 00:09:03871 explicit QuicFrame(QuicStopWaitingFrame* frame);
[email protected]d8c522112014-04-23 09:23:25872 explicit QuicFrame(QuicPingFrame* frame);
[email protected]6ae6e342014-02-06 02:21:42873 explicit QuicFrame(QuicGoAwayFrame* frame);
874 explicit QuicFrame(QuicWindowUpdateFrame* frame);
875 explicit QuicFrame(QuicBlockedFrame* frame);
[email protected]8b37a092012-10-18 21:53:49876
[email protected]c5e1aca2014-01-30 04:03:04877 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
878 std::ostream& os, const QuicFrame& frame);
879
[email protected]be24ab22012-10-22 03:01:52880 QuicFrameType type;
[email protected]8b37a092012-10-18 21:53:49881 union {
[email protected]c995c572013-01-18 05:43:20882 QuicPaddingFrame* padding_frame;
[email protected]be24ab22012-10-22 03:01:52883 QuicStreamFrame* stream_frame;
884 QuicAckFrame* ack_frame;
rtenneti4b06ae72014-08-26 03:43:43885
[email protected]93dd91f2014-02-27 00:09:03886 QuicStopWaitingFrame* stop_waiting_frame;
rtenneti4b06ae72014-08-26 03:43:43887
[email protected]d8c522112014-04-23 09:23:25888 QuicPingFrame* ping_frame;
[email protected]be24ab22012-10-22 03:01:52889 QuicRstStreamFrame* rst_stream_frame;
890 QuicConnectionCloseFrame* connection_close_frame;
[email protected]9db443912013-02-25 05:27:03891 QuicGoAwayFrame* goaway_frame;
[email protected]6ae6e342014-02-06 02:21:42892 QuicWindowUpdateFrame* window_update_frame;
893 QuicBlockedFrame* blocked_frame;
[email protected]8b37a092012-10-18 21:53:49894 };
895};
896
[email protected]be24ab22012-10-22 03:01:52897typedef std::vector<QuicFrame> QuicFrames;
[email protected]8b37a092012-10-18 21:53:49898
899struct NET_EXPORT_PRIVATE QuicFecData {
900 QuicFecData();
[email protected]a5061242012-10-23 23:29:37901
[email protected]c995c572013-01-18 05:43:20902 // The FEC group number is also the sequence number of the first
903 // FEC protected packet. The last protected packet's sequence number will
904 // be one less than the sequence number of the FEC packet.
[email protected]8b37a092012-10-18 21:53:49905 QuicFecGroupNumber fec_group;
[email protected]8b37a092012-10-18 21:53:49906 base::StringPiece redundancy;
[email protected]8b37a092012-10-18 21:53:49907};
908
[email protected]8b37a092012-10-18 21:53:49909class NET_EXPORT_PRIVATE QuicData {
910 public:
[email protected]6ae6e342014-02-06 02:21:42911 QuicData(const char* buffer, size_t length);
912 QuicData(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:49913 virtual ~QuicData();
914
915 base::StringPiece AsStringPiece() const {
916 return base::StringPiece(data(), length());
917 }
918
919 const char* data() const { return buffer_; }
920 size_t length() const { return length_; }
921
922 private:
923 const char* buffer_;
924 size_t length_;
925 bool owns_buffer_;
926
927 DISALLOW_COPY_AND_ASSIGN(QuicData);
928};
929
930class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
931 public:
rtennetica5ac272015-02-07 12:35:12932 QuicPacket(char* buffer,
933 size_t length,
934 bool owns_buffer,
935 QuicConnectionIdLength connection_id_length,
936 bool includes_version,
937 QuicSequenceNumberLength sequence_number_length);
[email protected]8b37a092012-10-18 21:53:49938
[email protected]5351cc4b2013-03-03 07:22:41939 base::StringPiece FecProtectedData() const;
940 base::StringPiece AssociatedData() const;
941 base::StringPiece BeforePlaintext() const;
942 base::StringPiece Plaintext() const;
[email protected]082b65b2012-11-10 19:11:31943
[email protected]8b37a092012-10-18 21:53:49944 char* mutable_data() { return buffer_; }
945
946 private:
947 char* buffer_;
[email protected]3aa9ca72014-02-27 19:39:43948 const QuicConnectionIdLength connection_id_length_;
[email protected]5351cc4b2013-03-03 07:22:41949 const bool includes_version_;
[email protected]25c31dc2013-06-05 17:56:04950 const QuicSequenceNumberLength sequence_number_length_;
[email protected]8b37a092012-10-18 21:53:49951
[email protected]2e740db2012-10-20 19:35:19952 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
[email protected]8b37a092012-10-18 21:53:49953};
954
955class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
956 public:
[email protected]6ae6e342014-02-06 02:21:42957 QuicEncryptedPacket(const char* buffer, size_t length);
958 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:49959
[email protected]ec86d5462013-11-17 16:04:49960 // Clones the packet into a new packet which owns the buffer.
961 QuicEncryptedPacket* Clone() const;
962
[email protected]c1b32c62013-01-20 02:49:10963 // By default, gtest prints the raw bytes of an object. The bool data
964 // member (in the base class QuicData) causes this object to have padding
965 // bytes, which causes the default gtest object printer to read
966 // uninitialize memory. So we need to teach gtest how to print this object.
967 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
968 std::ostream& os, const QuicEncryptedPacket& s);
969
[email protected]2e740db2012-10-20 19:35:19970 private:
971 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
[email protected]8b37a092012-10-18 21:53:49972};
973
[email protected]9db443912013-02-25 05:27:03974class NET_EXPORT_PRIVATE RetransmittableFrames {
975 public:
rtennetidc8e5a22015-02-25 01:38:52976 explicit RetransmittableFrames(EncryptionLevel level);
[email protected]9db443912013-02-25 05:27:03977 ~RetransmittableFrames();
978
979 // Allocates a local copy of the referenced StringPiece has QuicStreamFrame
980 // use it.
981 // Takes ownership of |stream_frame|.
982 const QuicFrame& AddStreamFrame(QuicStreamFrame* stream_frame);
983 // Takes ownership of the frame inside |frame|.
984 const QuicFrame& AddNonStreamFrame(const QuicFrame& frame);
rtenneti73e25c12015-03-16 06:12:43985 // Removes all stream frames associated with |stream_id|.
986 void RemoveFramesForStream(QuicStreamId stream_id);
987
[email protected]9db443912013-02-25 05:27:03988 const QuicFrames& frames() const { return frames_; }
989
[email protected]672631c2014-08-16 06:11:45990 IsHandshake HasCryptoHandshake() const {
991 return has_crypto_handshake_;
992 }
[email protected]2115d33ba2014-01-02 21:53:52993
[email protected]8ba81212013-05-03 13:11:48994 EncryptionLevel encryption_level() const {
995 return encryption_level_;
996 }
997
[email protected]9db443912013-02-25 05:27:03998 private:
999 QuicFrames frames_;
rtennetidc8e5a22015-02-25 01:38:521000 const EncryptionLevel encryption_level_;
[email protected]672631c2014-08-16 06:11:451001 IsHandshake has_crypto_handshake_;
[email protected]9db443912013-02-25 05:27:031002 // Data referenced by the StringPiece of a QuicStreamFrame.
1003 std::vector<std::string*> stream_data_;
1004
1005 DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames);
1006};
1007
1008struct NET_EXPORT_PRIVATE SerializedPacket {
1009 SerializedPacket(QuicPacketSequenceNumber sequence_number,
[email protected]ea825e02013-08-21 18:12:451010 QuicSequenceNumberLength sequence_number_length,
rtennetib6ac61a52015-02-11 20:20:521011 QuicEncryptedPacket* packet,
[email protected]9db443912013-02-25 05:27:031012 QuicPacketEntropyHash entropy_hash,
[email protected]97cf3022013-09-05 14:30:161013 RetransmittableFrames* retransmittable_frames);
1014 ~SerializedPacket();
[email protected]9db443912013-02-25 05:27:031015
1016 QuicPacketSequenceNumber sequence_number;
[email protected]ea825e02013-08-21 18:12:451017 QuicSequenceNumberLength sequence_number_length;
rtennetib6ac61a52015-02-11 20:20:521018 QuicEncryptedPacket* packet;
[email protected]9db443912013-02-25 05:27:031019 QuicPacketEntropyHash entropy_hash;
1020 RetransmittableFrames* retransmittable_frames;
rtennetica5ac272015-02-07 12:35:121021 bool is_fec_packet;
[email protected]97cf3022013-09-05 14:30:161022
rtenneti6b1c5b12015-01-13 20:08:351023 // Optional notifiers which will be informed when this packet has been ACKed.
rtenneticf54a52c2015-01-26 17:01:541024 std::list<QuicAckNotifier*> notifiers;
[email protected]9db443912013-02-25 05:27:031025};
1026
[email protected]77b5d50b2014-05-07 22:48:481027struct NET_EXPORT_PRIVATE TransmissionInfo {
1028 // Used by STL when assigning into a map.
1029 TransmissionInfo();
1030
1031 // Constructs a Transmission with a new all_tranmissions set
1032 // containing |sequence_number|.
1033 TransmissionInfo(RetransmittableFrames* retransmittable_frames,
[email protected]77b5d50b2014-05-07 22:48:481034 QuicSequenceNumberLength sequence_number_length,
[email protected]730b35d72014-06-05 03:23:221035 TransmissionType transmission_type,
rtenneti3183ac42015-02-28 03:39:411036 QuicTime sent_time,
1037 QuicByteCount bytes_sent,
1038 bool is_fec_packet);
[email protected]77b5d50b2014-05-07 22:48:481039
1040 RetransmittableFrames* retransmittable_frames;
1041 QuicSequenceNumberLength sequence_number_length;
[email protected]77b5d50b2014-05-07 22:48:481042 QuicTime sent_time;
[email protected]77b5d50b2014-05-07 22:48:481043 QuicByteCount bytes_sent;
pkastinga9f22d4e2014-12-01 22:43:461044 QuicPacketCount nack_count;
[email protected]730b35d72014-06-05 03:23:221045 // Reason why this packet was transmitted.
1046 TransmissionType transmission_type;
[email protected]77b5d50b2014-05-07 22:48:481047 // Stores the sequence numbers of all transmissions of this packet.
rtennetibe635732014-10-02 22:51:421048 // Must always be nullptr or have multiple elements.
rtennetidd4bf8f2014-09-03 00:45:161049 SequenceNumberList* all_transmissions;
[email protected]aa7e4ef2014-05-28 03:53:151050 // In flight packets have not been abandoned or lost.
1051 bool in_flight;
rtenneti31e9fd62014-09-16 05:22:151052 // True if the packet can never be acked, so it can be removed.
1053 bool is_unackable;
rtenneti85d89712014-11-20 03:32:241054 // True if the packet is an FEC packet.
1055 bool is_fec_packet;
[email protected]77b5d50b2014-05-07 22:48:481056};
1057
[email protected]8b37a092012-10-18 21:53:491058} // namespace net
1059
1060#endif // NET_QUIC_QUIC_PROTOCOL_H_