blob: 6a1bec59f0503916b16f1a629e59f7514a0ba3ea [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]8b37a092012-10-18 21:53:4951// TODO(rch): Consider Quic specific names for these constants.
[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;
[email protected]8e01c062013-10-31 07:35:3154// The maximum packet size of any QUIC packet, based on ethernet's max size,
[email protected]41fb6372013-12-10 05:26:4055// minus the IP and UDP headers. IPv6 has a 40 byte header, UPD adds an
56// additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's
57// max packet size is 1500 bytes, 1500 - 48 = 1452.
58const QuicByteCount kMaxPacketSize = 1452;
[email protected]ce7bb1412014-05-17 15:51:3359// Default maximum packet size used in Linux TCP implementations.
60const QuicByteCount kDefaultTCPMSS = 1460;
[email protected]8e01c062013-10-31 07:35:3161
62// Maximum size of the initial congestion window in packets.
63const size_t kDefaultInitialWindow = 10;
[email protected]2d43c40122014-04-21 14:51:2764const uint32 kMaxInitialWindow = 100;
[email protected]8e01c062013-10-31 07:35:3165
[email protected]7d561352014-06-20 09:09:2166// Default size of initial flow control window, for both stream and session.
[email protected]9bb57c72014-03-31 20:36:0467const uint32 kDefaultFlowControlSendWindow = 16 * 1024; // 16 KB
68
[email protected]0ac0c5b2013-11-20 05:55:5869// Maximum size of the congestion window, in packets, for TCP congestion control
70// algorithms.
71const size_t kMaxTcpCongestionWindow = 200;
72
[email protected]a97b3182014-08-08 08:10:1873// Size of the socket receive buffer in bytes.
[email protected]648f81142014-08-15 21:38:4674const QuicByteCount kDefaultSocketReceiveBuffer = 256 * 1024;
[email protected]a97b3182014-08-08 08:10:1875
[email protected]8e01c062013-10-31 07:35:3176// Don't allow a client to suggest an RTT longer than 15 seconds.
[email protected]2d43c40122014-04-21 14:51:2777const uint32 kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond;
[email protected]8b37a092012-10-18 21:53:4978
79// Maximum number of open streams per connection.
80const size_t kDefaultMaxStreamsPerConnection = 100;
81
[email protected]af806e62013-05-22 14:47:5082// Number of bytes reserved for public flags in the packet header.
83const size_t kPublicFlagsSize = 1;
[email protected]5351cc4b2013-03-03 07:22:4184// Number of bytes reserved for version number in the packet header.
85const size_t kQuicVersionSize = 4;
[email protected]c995c572013-01-18 05:43:2086// Number of bytes reserved for private flags in the packet header.
87const size_t kPrivateFlagsSize = 1;
88// Number of bytes reserved for FEC group in the packet header.
89const size_t kFecGroupSize = 1;
[email protected]5351cc4b2013-03-03 07:22:4190
91// Signifies that the QuicPacket will contain version of the protocol.
92const bool kIncludeVersion = true;
[email protected]c995c572013-01-18 05:43:2093
[email protected]5351cc4b2013-03-03 07:22:4194// Index of the first byte in a QUIC packet which is used in hash calculation.
95const size_t kStartOfHashData = 0;
[email protected]8b37a092012-10-18 21:53:4996
97// Limit on the delta between stream IDs.
[email protected]c5cc9bd2014-03-31 23:17:1498const QuicStreamId kMaxStreamIdDelta = 200;
[email protected]c244c5a12013-05-07 20:55:0499// Limit on the delta between header IDs.
[email protected]c5cc9bd2014-03-31 23:17:14100const QuicHeaderId kMaxHeaderIdDelta = 200;
[email protected]8b37a092012-10-18 21:53:49101
102// Reserved ID for the crypto stream.
[email protected]8b37a092012-10-18 21:53:49103const QuicStreamId kCryptoStreamId = 1;
104
[email protected]4d640792013-12-18 22:21:08105// Reserved ID for the headers stream.
106const QuicStreamId kHeadersStreamId = 3;
107
[email protected]648f81142014-08-15 21:38:46108// Maximum delayed ack time, in ms.
[email protected]2f9fb932014-08-20 19:42:44109const int kMaxDelayedAckTimeMs = 25;
[email protected]648f81142014-08-15 21:38:46110
rtennetib5512bb2014-09-29 19:17:15111// The timeout before the handshake succeeds.
112const int64 kInitialIdleTimeoutSecs = 5;
113// The default idle timeout.
114const int64 kDefaultIdleTimeoutSecs = 30;
rtenneti31e9fd62014-09-16 05:22:15115// The maximum idle timeout that can be negotiated.
116const int64 kMaximumIdleTimeoutSecs = 60 * 10; // 10 minutes.
117// The default timeout for a connection until the crypto handshake succeeds.
rtennetib5512bb2014-09-29 19:17:15118const int64 kMaxTimeForCryptoHandshakeSecs = 10; // 10 secs.
[email protected]8b37a092012-10-18 21:53:49119
[email protected]525948df2014-04-21 06:26:58120// Default ping timeout.
121const int64 kPingTimeoutSecs = 15; // 15 secs.
122
[email protected]ca4e0d92014-08-22 16:33:22123// Minimum number of RTTs between Server Config Updates (SCUP) sent to client.
124const int kMinIntervalBetweenServerConfigUpdatesRTTs = 10;
125
126// Minimum time between Server Config Updates (SCUP) sent to client.
127const int kMinIntervalBetweenServerConfigUpdatesMs = 1000;
128
rtennetib5512bb2014-09-29 19:17:15129// The number of open streams that a server will accept is set to be slightly
130// larger than the negotiated limit. Immediately closing the connection if the
131// client opens slightly too many streams is not ideal: the client may have sent
132// a FIN that was lost, and simultaneously opened a new stream. The number of
133// streams a server accepts is a fixed increment over the negotiated limit, or a
134// percentage increase, whichever is larger.
rtenneti31e9fd62014-09-16 05:22:15135const float kMaxStreamsMultiplier = 1.1f;
rtennetib5512bb2014-09-29 19:17:15136const int kMaxStreamsMinimumIncrement = 10;
rtenneti31e9fd62014-09-16 05:22:15137
[email protected]b007e632013-10-28 08:39:25138// We define an unsigned 16-bit floating point value, inspired by IEEE floats
139// (http://en.wikipedia.org/wiki/Half_precision_floating-point_format),
140// with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden
141// bit) and denormals, but without signs, transfinites or fractions. Wire format
142// 16 bits (little-endian byte order) are split into exponent (high 5) and
143// mantissa (low 11) and decoded as:
144// uint64 value;
145// if (exponent == 0) value = mantissa;
146// else value = (mantissa | 1 << 11) << (exponent - 1)
147const int kUFloat16ExponentBits = 5;
148const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30
149const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11
150const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12
151const uint64 kUFloat16MaxValue = // 0x3FFC0000000
152 ((GG_UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1) <<
153 kUFloat16MaxExponent;
154
[email protected]c67a82cb2013-09-24 02:53:21155enum TransmissionType {
[email protected]2532de12013-05-09 12:29:33156 NOT_RETRANSMISSION,
[email protected]b9475b582014-03-20 20:04:33157 FIRST_TRANSMISSION_TYPE = NOT_RETRANSMISSION,
158 HANDSHAKE_RETRANSMISSION, // Retransmits due to handshake timeouts.
rtenneti31e9fd62014-09-16 05:22:15159 ALL_UNACKED_RETRANSMISSION, // Retransmits all unacked packets.
160 ALL_INITIAL_RETRANSMISSION, // Retransmits all initially encrypted packets.
[email protected]b9475b582014-03-20 20:04:33161 LOSS_RETRANSMISSION, // Retransmits due to loss detection.
162 RTO_RETRANSMISSION, // Retransmits due to retransmit time out.
163 TLP_RETRANSMISSION, // Tail loss probes.
164 LAST_TRANSMISSION_TYPE = TLP_RETRANSMISSION,
[email protected]74bda142013-03-31 02:49:11165};
166
167enum HasRetransmittableData {
[email protected]2532de12013-05-09 12:29:33168 NO_RETRANSMITTABLE_DATA,
169 HAS_RETRANSMITTABLE_DATA,
[email protected]74bda142013-03-31 02:49:11170};
171
[email protected]575cce62013-08-03 02:06:43172enum IsHandshake {
173 NOT_HANDSHAKE,
174 IS_HANDSHAKE
175};
176
[email protected]bbb10072014-06-13 07:41:59177// Indicates FEC protection level for data being written.
178enum FecProtection {
179 MUST_FEC_PROTECT, // Callee must FEC protect this data.
[email protected]a5b98172014-06-18 07:01:59180 MAY_FEC_PROTECT // Callee does not have to but may FEC protect this data.
181};
182
[email protected]bc356fe2014-06-19 11:14:14183// Indicates FEC policy.
[email protected]a5b98172014-06-18 07:01:59184enum FecPolicy {
185 FEC_PROTECT_ALWAYS, // All data in the stream should be FEC protected.
186 FEC_PROTECT_OPTIONAL // Data in the stream does not need FEC protection.
[email protected]bbb10072014-06-13 07:41:59187};
188
[email protected]be24ab22012-10-22 03:01:52189enum QuicFrameType {
[email protected]6ae6e342014-02-06 02:21:42190 // Regular frame types. The values set here cannot change without the
191 // introduction of a new QUIC version.
[email protected]c995c572013-01-18 05:43:20192 PADDING_FRAME = 0,
[email protected]6ae6e342014-02-06 02:21:42193 RST_STREAM_FRAME = 1,
194 CONNECTION_CLOSE_FRAME = 2,
195 GOAWAY_FRAME = 3,
196 WINDOW_UPDATE_FRAME = 4,
197 BLOCKED_FRAME = 5,
[email protected]93dd91f2014-02-27 00:09:03198 STOP_WAITING_FRAME = 6,
[email protected]d8c522112014-04-23 09:23:25199 PING_FRAME = 7,
[email protected]6ae6e342014-02-06 02:21:42200
201 // STREAM, ACK, and CONGESTION_FEEDBACK frames are special frames. They are
202 // encoded differently on the wire and their values do not need to be stable.
[email protected]97cf3022013-09-05 14:30:16203 STREAM_FRAME,
204 ACK_FRAME,
205 CONGESTION_FEEDBACK_FRAME,
[email protected]be24ab22012-10-22 03:01:52206 NUM_FRAME_TYPES
[email protected]8b37a092012-10-18 21:53:49207};
208
[email protected]3aa9ca72014-02-27 19:39:43209enum QuicConnectionIdLength {
210 PACKET_0BYTE_CONNECTION_ID = 0,
211 PACKET_1BYTE_CONNECTION_ID = 1,
212 PACKET_4BYTE_CONNECTION_ID = 4,
213 PACKET_8BYTE_CONNECTION_ID = 8
[email protected]b064310782013-05-30 21:12:17214};
215
216enum InFecGroup {
217 NOT_IN_FEC_GROUP,
218 IN_FEC_GROUP,
219};
220
[email protected]25c31dc2013-06-05 17:56:04221enum QuicSequenceNumberLength {
222 PACKET_1BYTE_SEQUENCE_NUMBER = 1,
223 PACKET_2BYTE_SEQUENCE_NUMBER = 2,
224 PACKET_4BYTE_SEQUENCE_NUMBER = 4,
225 PACKET_6BYTE_SEQUENCE_NUMBER = 6
226};
227
[email protected]8e01c062013-10-31 07:35:31228// Used to indicate a QuicSequenceNumberLength using two flag bits.
229enum QuicSequenceNumberLengthFlags {
230 PACKET_FLAGS_1BYTE_SEQUENCE = 0, // 00
231 PACKET_FLAGS_2BYTE_SEQUENCE = 1, // 01
232 PACKET_FLAGS_4BYTE_SEQUENCE = 1 << 1, // 10
233 PACKET_FLAGS_6BYTE_SEQUENCE = 1 << 1 | 1, // 11
234};
235
[email protected]f62262b2013-07-05 20:57:30236// The public flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20237enum QuicPacketPublicFlags {
238 PACKET_PUBLIC_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30239
240 // Bit 0: Does the packet header contains version info?
241 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0,
242
243 // Bit 1: Is this packet a public reset packet?
244 PACKET_PUBLIC_FLAGS_RST = 1 << 1,
245
[email protected]3aa9ca72014-02-27 19:39:43246 // Bits 2 and 3 specify the length of the ConnectionId as follows:
[email protected]f62262b2013-07-05 20:57:30247 // ----00--: 0 bytes
248 // ----01--: 1 byte
249 // ----10--: 4 bytes
250 // ----11--: 8 bytes
[email protected]3aa9ca72014-02-27 19:39:43251 PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID = 0,
252 PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID = 1 << 2,
253 PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID = 1 << 3,
254 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID = 1 << 3 | 1 << 2,
[email protected]f62262b2013-07-05 20:57:30255
256 // Bits 4 and 5 describe the packet sequence number length as follows:
257 // --00----: 1 byte
258 // --01----: 2 bytes
259 // --10----: 4 bytes
260 // --11----: 6 bytes
[email protected]8e01c062013-10-31 07:35:31261 PACKET_PUBLIC_FLAGS_1BYTE_SEQUENCE = PACKET_FLAGS_1BYTE_SEQUENCE << 4,
262 PACKET_PUBLIC_FLAGS_2BYTE_SEQUENCE = PACKET_FLAGS_2BYTE_SEQUENCE << 4,
263 PACKET_PUBLIC_FLAGS_4BYTE_SEQUENCE = PACKET_FLAGS_4BYTE_SEQUENCE << 4,
264 PACKET_PUBLIC_FLAGS_6BYTE_SEQUENCE = PACKET_FLAGS_6BYTE_SEQUENCE << 4,
[email protected]f62262b2013-07-05 20:57:30265
266 // All bits set (bits 6 and 7 are not currently used): 00111111
267 PACKET_PUBLIC_FLAGS_MAX = (1 << 6) - 1
[email protected]c995c572013-01-18 05:43:20268};
[email protected]8b37a092012-10-18 21:53:49269
[email protected]f62262b2013-07-05 20:57:30270// The private flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20271enum QuicPacketPrivateFlags {
272 PACKET_PRIVATE_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30273
274 // Bit 0: Does this packet contain an entropy bit?
[email protected]b064310782013-05-30 21:12:17275 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0,
[email protected]f62262b2013-07-05 20:57:30276
277 // Bit 1: Payload is part of an FEC group?
278 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1,
279
280 // Bit 2: Payload is FEC as opposed to frames?
281 PACKET_PRIVATE_FLAGS_FEC = 1 << 2,
282
283 // All bits set (bits 3-7 are not currently used): 00000111
284 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1
[email protected]c995c572013-01-18 05:43:20285};
286
[email protected]48878092013-07-26 14:51:56287// The available versions of QUIC. Guaranteed that the integer value of the enum
288// will match the version number.
289// When adding a new version to this enum you should add it to
[email protected]8bbfaeb72013-08-09 06:38:26290// kSupportedQuicVersions (if appropriate), and also add a new case to the
291// helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and
292// QuicVersionToString.
[email protected]48878092013-07-26 14:51:56293enum QuicVersion {
294 // Special case to indicate unknown/unsupported QUIC version.
295 QUIC_VERSION_UNSUPPORTED = 0,
296
[email protected]0c6b10ad2014-07-02 19:47:00297 QUIC_VERSION_18 = 18, // PING frame.
[email protected]7afc2ebe2014-07-18 16:06:23298 QUIC_VERSION_19 = 19, // Connection level flow control.
[email protected]0c6b10ad2014-07-02 19:47:00299 QUIC_VERSION_21 = 21, // Headers/crypto streams are flow controlled.
[email protected]9693157b2014-08-08 11:13:49300 QUIC_VERSION_22 = 22, // Send Server Config Update messages on crypto stream.
rtenneti4b06ae72014-08-26 03:43:43301 QUIC_VERSION_23 = 23, // Timestamp in the ack frame.
[email protected]48878092013-07-26 14:51:56302};
303
304// This vector contains QUIC versions which we currently support.
305// This should be ordered such that the highest supported version is the first
306// element, with subsequent elements in descending order (versions can be
307// skipped as necessary).
[email protected]31ae854842013-11-27 00:05:46308//
[email protected]310d37b2014-08-02 06:15:37309// IMPORTANT: if you are adding to this list, follow the instructions at
[email protected]31ae854842013-11-27 00:05:46310// http://sites/quic/adding-and-removing-versions
rtenneti4b06ae72014-08-26 03:43:43311static const QuicVersion kSupportedQuicVersions[] = {QUIC_VERSION_23,
312 QUIC_VERSION_22,
[email protected]9693157b2014-08-08 11:13:49313 QUIC_VERSION_21,
[email protected]7d561352014-06-20 09:09:21314 QUIC_VERSION_19,
rtennetib5512bb2014-09-29 19:17:15315 QUIC_VERSION_18};
[email protected]48878092013-07-26 14:51:56316
317typedef std::vector<QuicVersion> QuicVersionVector;
318
[email protected]b007e632013-10-28 08:39:25319// Returns a vector of QUIC versions in kSupportedQuicVersions.
320NET_EXPORT_PRIVATE QuicVersionVector QuicSupportedVersions();
[email protected]ea2ab47b2013-08-13 00:44:11321
[email protected]48878092013-07-26 14:51:56322// QuicTag is written to and read from the wire, but we prefer to use
323// the more readable QuicVersion at other levels.
324// Helper function which translates from a QuicVersion to a QuicTag. Returns 0
325// if QuicVersion is unsupported.
326NET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version);
327
328// Returns appropriate QuicVersion from a QuicTag.
329// Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood.
330NET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag);
331
332// Helper function which translates from a QuicVersion to a string.
333// Returns strings corresponding to enum names (e.g. QUIC_VERSION_6).
334NET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version);
335
336// Returns comma separated list of string representations of QuicVersion enum
[email protected]b007e632013-10-28 08:39:25337// values in the supplied |versions| vector.
338NET_EXPORT_PRIVATE std::string QuicVersionVectorToString(
339 const QuicVersionVector& versions);
[email protected]48878092013-07-26 14:51:56340
341// Version and Crypto tags are written to the wire with a big-endian
342// representation of the name of the tag. For example
343// the client hello tag (CHLO) will be written as the
344// following 4 bytes: 'C' 'H' 'L' 'O'. Since it is
345// stored in memory as a little endian uint32, we need
346// to reverse the order of the bytes.
347
348// MakeQuicTag returns a value given the four bytes. For example:
349// MakeQuicTag('C', 'H', 'L', 'O');
350NET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d);
351
[email protected]9cda5fd2014-06-03 10:20:28352// Returns true if the tag vector contains the specified tag.
[email protected]cc1aa272014-06-30 19:48:22353NET_EXPORT_PRIVATE bool ContainsQuicTag(const QuicTagVector& tag_vector,
354 QuicTag tag);
[email protected]9cda5fd2014-06-03 10:20:28355
[email protected]b064310782013-05-30 21:12:17356// Size in bytes of the data or fec packet header.
[email protected]79d13dcb2014-02-05 07:23:13357NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(const QuicPacketHeader& header);
[email protected]b064310782013-05-30 21:12:17358
[email protected]25c31dc2013-06-05 17:56:04359NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(
[email protected]3aa9ca72014-02-27 19:39:43360 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04361 bool include_version,
362 QuicSequenceNumberLength sequence_number_length,
363 InFecGroup is_in_fec_group);
[email protected]b064310782013-05-30 21:12:17364
[email protected]b064310782013-05-30 21:12:17365// Index of the first byte in a QUIC packet of FEC protected data.
[email protected]25c31dc2013-06-05 17:56:04366NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(
[email protected]3aa9ca72014-02-27 19:39:43367 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04368 bool include_version,
369 QuicSequenceNumberLength sequence_number_length);
[email protected]b064310782013-05-30 21:12:17370// Index of the first byte in a QUIC packet of encrypted data.
[email protected]25c31dc2013-06-05 17:56:04371NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(
[email protected]3aa9ca72014-02-27 19:39:43372 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04373 bool include_version,
374 QuicSequenceNumberLength sequence_number_length);
[email protected]b064310782013-05-30 21:12:17375
[email protected]74bda142013-03-31 02:49:11376enum QuicRstStreamErrorCode {
377 QUIC_STREAM_NO_ERROR = 0,
[email protected]8b37a092012-10-18 21:53:49378
[email protected]24e5bc52013-09-18 15:36:58379 // There was some error which halted stream processing.
380 QUIC_ERROR_PROCESSING_STREAM,
[email protected]8b37a092012-10-18 21:53:49381 // We got two fin or reset offsets which did not match.
382 QUIC_MULTIPLE_TERMINATION_OFFSETS,
383 // We got bad payload and can not respond to it at the protocol level.
384 QUIC_BAD_APPLICATION_PAYLOAD,
[email protected]74bda142013-03-31 02:49:11385 // Stream closed due to connection error. No reset frame is sent when this
386 // happens.
387 QUIC_STREAM_CONNECTION_ERROR,
388 // GoAway frame sent. No more stream can be created.
389 QUIC_STREAM_PEER_GOING_AWAY,
[email protected]06ff5152013-08-29 01:03:05390 // The stream has been cancelled.
391 QUIC_STREAM_CANCELLED,
[email protected]51cc1342014-04-18 23:44:37392 // Sending a RST to allow for proper flow control accounting.
393 QUIC_RST_FLOW_CONTROL_ACCOUNTING,
[email protected]8b37a092012-10-18 21:53:49394
[email protected]74bda142013-03-31 02:49:11395 // No error. Used as bound while iterating.
396 QUIC_STREAM_LAST_ERROR,
397};
[email protected]8b37a092012-10-18 21:53:49398
[email protected]51cc1342014-04-18 23:44:37399// Because receiving an unknown QuicRstStreamErrorCode results in connection
400// teardown, we use this to make sure any errors predating a given version are
401// downgraded to the most appropriate existing error.
402NET_EXPORT_PRIVATE QuicRstStreamErrorCode AdjustErrorForVersion(
403 QuicRstStreamErrorCode error_code,
404 QuicVersion version);
405
[email protected]89264042013-08-21 07:35:24406// These values must remain stable as they are uploaded to UMA histograms.
407// To add a new error code, use the current value of QUIC_LAST_ERROR and
408// increment QUIC_LAST_ERROR.
[email protected]74bda142013-03-31 02:49:11409enum QuicErrorCode {
410 QUIC_NO_ERROR = 0,
411
412 // Connection has reached an invalid state.
[email protected]89264042013-08-21 07:35:24413 QUIC_INTERNAL_ERROR = 1,
[email protected]74bda142013-03-31 02:49:11414 // There were data frames after the a fin or reset.
[email protected]89264042013-08-21 07:35:24415 QUIC_STREAM_DATA_AFTER_TERMINATION = 2,
[email protected]8b37a092012-10-18 21:53:49416 // Control frame is malformed.
[email protected]89264042013-08-21 07:35:24417 QUIC_INVALID_PACKET_HEADER = 3,
[email protected]be24ab22012-10-22 03:01:52418 // Frame data is malformed.
[email protected]89264042013-08-21 07:35:24419 QUIC_INVALID_FRAME_DATA = 4,
420 // The packet contained no payload.
421 QUIC_MISSING_PAYLOAD = 48,
[email protected]8b37a092012-10-18 21:53:49422 // FEC data is malformed.
[email protected]89264042013-08-21 07:35:24423 QUIC_INVALID_FEC_DATA = 5,
424 // STREAM frame data is malformed.
425 QUIC_INVALID_STREAM_DATA = 46,
[email protected]42a3eba2014-04-30 10:52:55426 // STREAM frame data is not encrypted.
427 QUIC_UNENCRYPTED_STREAM_DATA = 61,
[email protected]89264042013-08-21 07:35:24428 // RST_STREAM frame data is malformed.
429 QUIC_INVALID_RST_STREAM_DATA = 6,
430 // CONNECTION_CLOSE frame data is malformed.
431 QUIC_INVALID_CONNECTION_CLOSE_DATA = 7,
432 // GOAWAY frame data is malformed.
433 QUIC_INVALID_GOAWAY_DATA = 8,
[email protected]6ae6e342014-02-06 02:21:42434 // WINDOW_UPDATE frame data is malformed.
435 QUIC_INVALID_WINDOW_UPDATE_DATA = 57,
436 // BLOCKED frame data is malformed.
437 QUIC_INVALID_BLOCKED_DATA = 58,
[email protected]93dd91f2014-02-27 00:09:03438 // STOP_WAITING frame data is malformed.
439 QUIC_INVALID_STOP_WAITING_DATA = 60,
[email protected]89264042013-08-21 07:35:24440 // ACK frame data is malformed.
441 QUIC_INVALID_ACK_DATA = 9,
442 // CONGESTION_FEEDBACK frame data is malformed.
443 QUIC_INVALID_CONGESTION_FEEDBACK_DATA = 47,
[email protected]14e8106c2013-03-14 16:25:33444 // Version negotiation packet is malformed.
[email protected]89264042013-08-21 07:35:24445 QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10,
[email protected]899951652013-05-16 12:52:39446 // Public RST packet is malformed.
[email protected]89264042013-08-21 07:35:24447 QUIC_INVALID_PUBLIC_RST_PACKET = 11,
[email protected]8b37a092012-10-18 21:53:49448 // There was an error decrypting.
[email protected]89264042013-08-21 07:35:24449 QUIC_DECRYPTION_FAILURE = 12,
[email protected]8b37a092012-10-18 21:53:49450 // There was an error encrypting.
[email protected]89264042013-08-21 07:35:24451 QUIC_ENCRYPTION_FAILURE = 13,
[email protected]8b37a092012-10-18 21:53:49452 // The packet exceeded kMaxPacketSize.
[email protected]89264042013-08-21 07:35:24453 QUIC_PACKET_TOO_LARGE = 14,
[email protected]8b37a092012-10-18 21:53:49454 // Data was sent for a stream which did not exist.
[email protected]89264042013-08-21 07:35:24455 QUIC_PACKET_FOR_NONEXISTENT_STREAM = 15,
[email protected]9db443912013-02-25 05:27:03456 // The peer is going away. May be a client or server.
[email protected]89264042013-08-21 07:35:24457 QUIC_PEER_GOING_AWAY = 16,
[email protected]8b37a092012-10-18 21:53:49458 // A stream ID was invalid.
[email protected]89264042013-08-21 07:35:24459 QUIC_INVALID_STREAM_ID = 17,
[email protected]24e5bc52013-09-18 15:36:58460 // A priority was invalid.
461 QUIC_INVALID_PRIORITY = 49,
[email protected]8b37a092012-10-18 21:53:49462 // Too many streams already open.
[email protected]89264042013-08-21 07:35:24463 QUIC_TOO_MANY_OPEN_STREAMS = 18,
[email protected]9693157b2014-08-08 11:13:49464 // The peer must send a FIN/RST for each stream, and has not been doing so.
465 QUIC_TOO_MANY_UNFINISHED_STREAMS = 66,
[email protected]86a318d2013-01-23 21:16:04466 // Received public reset for this connection.
[email protected]89264042013-08-21 07:35:24467 QUIC_PUBLIC_RESET = 19,
[email protected]c244c5a12013-05-07 20:55:04468 // Invalid protocol version.
[email protected]89264042013-08-21 07:35:24469 QUIC_INVALID_VERSION = 20,
[email protected]92bf17c2014-03-03 21:14:03470
471 // deprecated: QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED = 21
472
[email protected]c244c5a12013-05-07 20:55:04473 // The Header ID for a stream was too far from the previous.
[email protected]89264042013-08-21 07:35:24474 QUIC_INVALID_HEADER_ID = 22,
[email protected]899951652013-05-16 12:52:39475 // Negotiable parameter received during handshake had invalid value.
[email protected]89264042013-08-21 07:35:24476 QUIC_INVALID_NEGOTIATED_VALUE = 23,
[email protected]899951652013-05-16 12:52:39477 // There was an error decompressing data.
[email protected]89264042013-08-21 07:35:24478 QUIC_DECOMPRESSION_FAILURE = 24,
[email protected]8b37a092012-10-18 21:53:49479 // We hit our prenegotiated (or default) timeout
[email protected]89264042013-08-21 07:35:24480 QUIC_CONNECTION_TIMED_OUT = 25,
rtenneti31e9fd62014-09-16 05:22:15481 // We hit our overall connection timeout
482 QUIC_CONNECTION_OVERALL_TIMED_OUT = 67,
[email protected]899951652013-05-16 12:52:39483 // There was an error encountered migrating addresses
[email protected]89264042013-08-21 07:35:24484 QUIC_ERROR_MIGRATING_ADDRESS = 26,
[email protected]1505a512013-09-04 22:59:35485 // There was an error while writing to the socket.
[email protected]89264042013-08-21 07:35:24486 QUIC_PACKET_WRITE_ERROR = 27,
[email protected]1505a512013-09-04 22:59:35487 // There was an error while reading from the socket.
488 QUIC_PACKET_READ_ERROR = 51,
[email protected]24e5bc52013-09-18 15:36:58489 // We received a STREAM_FRAME with no data and no fin flag set.
490 QUIC_INVALID_STREAM_FRAME = 50,
[email protected]4d640792013-12-18 22:21:08491 // We received invalid data on the headers stream.
492 QUIC_INVALID_HEADERS_STREAM_DATA = 56,
[email protected]730b35d72014-06-05 03:23:22493 // The peer received too much data, violating flow control.
494 QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA = 59,
495 // The peer sent too much data, violating flow control.
496 QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA = 63,
497 // The peer received an invalid flow control window.
498 QUIC_FLOW_CONTROL_INVALID_WINDOW = 64,
[email protected]71c84e592014-05-28 23:39:29499 // The connection has been IP pooled into an existing connection.
500 QUIC_CONNECTION_IP_POOLED = 62,
[email protected]8b37a092012-10-18 21:53:49501
502 // Crypto errors.
503
[email protected]1354bf62013-05-23 23:17:18504 // Hanshake failed.
[email protected]89264042013-08-21 07:35:24505 QUIC_HANDSHAKE_FAILED = 28,
[email protected]8b37a092012-10-18 21:53:49506 // Handshake message contained out of order tags.
[email protected]89264042013-08-21 07:35:24507 QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29,
[email protected]701bc892013-01-17 04:51:54508 // Handshake message contained too many entries.
[email protected]89264042013-08-21 07:35:24509 QUIC_CRYPTO_TOO_MANY_ENTRIES = 30,
[email protected]8b37a092012-10-18 21:53:49510 // Handshake message contained an invalid value length.
[email protected]89264042013-08-21 07:35:24511 QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31,
[email protected]8b37a092012-10-18 21:53:49512 // A crypto message was received after the handshake was complete.
[email protected]89264042013-08-21 07:35:24513 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32,
[email protected]d3d15bf2013-01-30 02:51:54514 // A crypto message was received with an illegal message tag.
[email protected]89264042013-08-21 07:35:24515 QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33,
[email protected]d3d15bf2013-01-30 02:51:54516 // A crypto message was received with an illegal parameter.
[email protected]89264042013-08-21 07:35:24517 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34,
[email protected]752fbe52013-10-14 08:35:32518 // An invalid channel id signature was supplied.
519 QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52,
[email protected]d3d15bf2013-01-30 02:51:54520 // A crypto message was received with a mandatory parameter missing.
[email protected]89264042013-08-21 07:35:24521 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35,
[email protected]d3d15bf2013-01-30 02:51:54522 // A crypto message was received with a parameter that has no overlap
523 // with the local parameter.
[email protected]89264042013-08-21 07:35:24524 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36,
[email protected]ed3fc15d2013-03-08 18:37:44525 // A crypto message was received that contained a parameter with too few
526 // values.
[email protected]89264042013-08-21 07:35:24527 QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37,
[email protected]ccc66e8a2013-03-26 08:26:14528 // An internal error occured in crypto processing.
[email protected]89264042013-08-21 07:35:24529 QUIC_CRYPTO_INTERNAL_ERROR = 38,
[email protected]ccc66e8a2013-03-26 08:26:14530 // A crypto handshake message specified an unsupported version.
[email protected]89264042013-08-21 07:35:24531 QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39,
[email protected]ccc66e8a2013-03-26 08:26:14532 // There was no intersection between the crypto primitives supported by the
533 // peer and ourselves.
[email protected]89264042013-08-21 07:35:24534 QUIC_CRYPTO_NO_SUPPORT = 40,
[email protected]ef95114d2013-04-17 17:57:01535 // The server rejected our client hello messages too many times.
[email protected]89264042013-08-21 07:35:24536 QUIC_CRYPTO_TOO_MANY_REJECTS = 41,
[email protected]a57e0272013-04-26 07:31:47537 // The client rejected the server's certificate chain or signature.
[email protected]89264042013-08-21 07:35:24538 QUIC_PROOF_INVALID = 42,
[email protected]8ba81212013-05-03 13:11:48539 // A crypto message was received with a duplicate tag.
[email protected]89264042013-08-21 07:35:24540 QUIC_CRYPTO_DUPLICATE_TAG = 43,
[email protected]2532de12013-05-09 12:29:33541 // A crypto message was received with the wrong encryption level (i.e. it
542 // should have been encrypted but was not.)
[email protected]89264042013-08-21 07:35:24543 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44,
[email protected]2532de12013-05-09 12:29:33544 // The server config for a server has expired.
[email protected]89264042013-08-21 07:35:24545 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45,
[email protected]752fbe52013-10-14 08:35:32546 // We failed to setup the symmetric keys for a connection.
547 QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53,
[email protected]691f45a982013-11-19 10:52:04548 // A handshake message arrived, but we are still validating the
549 // previous handshake message.
550 QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54,
[email protected]ccb34212014-07-18 09:27:50551 // A server config update arrived before the handshake is complete.
552 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE = 65,
[email protected]d89f1862013-11-26 21:21:27553 // This connection involved a version negotiation which appears to have been
554 // tampered with.
555 QUIC_VERSION_NEGOTIATION_MISMATCH = 55,
[email protected]ccc66e8a2013-03-26 08:26:14556
[email protected]74bda142013-03-31 02:49:11557 // No error. Used as bound while iterating.
rtenneti31e9fd62014-09-16 05:22:15558 QUIC_LAST_ERROR = 68,
[email protected]8b37a092012-10-18 21:53:49559};
560
[email protected]c995c572013-01-18 05:43:20561struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
[email protected]14e8106c2013-03-14 16:25:33562 QuicPacketPublicHeader();
563 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
564 ~QuicPacketPublicHeader();
565
[email protected]3aa9ca72014-02-27 19:39:43566 // Universal header. All QuicPacket headers will have a connection_id and
567 // public flags.
568 QuicConnectionId connection_id;
569 QuicConnectionIdLength connection_id_length;
[email protected]9db443912013-02-25 05:27:03570 bool reset_flag;
571 bool version_flag;
[email protected]25c31dc2013-06-05 17:56:04572 QuicSequenceNumberLength sequence_number_length;
[email protected]48878092013-07-26 14:51:56573 QuicVersionVector versions;
[email protected]c995c572013-01-18 05:43:20574};
575
576// Header for Data or FEC packets.
[email protected]74bda142013-03-31 02:49:11577struct NET_EXPORT_PRIVATE QuicPacketHeader {
578 QuicPacketHeader();
579 explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
[email protected]9db443912013-02-25 05:27:03580
581 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
582 std::ostream& os, const QuicPacketHeader& s);
583
[email protected]c995c572013-01-18 05:43:20584 QuicPacketPublicHeader public_header;
[email protected]9db443912013-02-25 05:27:03585 bool fec_flag;
[email protected]9db443912013-02-25 05:27:03586 bool entropy_flag;
587 QuicPacketEntropyHash entropy_hash;
[email protected]8b37a092012-10-18 21:53:49588 QuicPacketSequenceNumber packet_sequence_number;
[email protected]b064310782013-05-30 21:12:17589 InFecGroup is_in_fec_group;
[email protected]8b37a092012-10-18 21:53:49590 QuicFecGroupNumber fec_group;
591};
592
[email protected]74bda142013-03-31 02:49:11593struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
[email protected]6ae6e342014-02-06 02:21:42594 QuicPublicResetPacket();
595 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header);
596
[email protected]86a318d2013-01-23 21:16:04597 QuicPacketPublicHeader public_header;
[email protected]86a318d2013-01-23 21:16:04598 QuicPublicResetNonceProof nonce_proof;
[email protected]300ccd52014-01-25 08:00:19599 QuicPacketSequenceNumber rejected_sequence_number;
[email protected]79d13dcb2014-02-05 07:23:13600 IPEndPoint client_address;
[email protected]86a318d2013-01-23 21:16:04601};
602
[email protected]14e8106c2013-03-14 16:25:33603enum QuicVersionNegotiationState {
604 START_NEGOTIATION = 0,
[email protected]ec640112013-08-09 03:56:18605 // Server-side this implies we've sent a version negotiation packet and are
606 // waiting on the client to select a compatible version. Client-side this
607 // implies we've gotten a version negotiation packet, are retransmitting the
608 // initial packets with a supported version and are waiting for our first
609 // packet from the server.
610 NEGOTIATION_IN_PROGRESS,
611 // This indicates this endpoint has received a packet from the peer with a
612 // version this endpoint supports. Version negotiation is complete, and the
613 // version number will no longer be sent with future packets.
[email protected]14e8106c2013-03-14 16:25:33614 NEGOTIATED_VERSION
615};
616
617typedef QuicPacketPublicHeader QuicVersionNegotiationPacket;
618
[email protected]c995c572013-01-18 05:43:20619// A padding frame contains no payload.
620struct NET_EXPORT_PRIVATE QuicPaddingFrame {
621};
622
[email protected]d8c522112014-04-23 09:23:25623// A ping frame contains no payload, though it is retransmittable,
624// and ACK'd just like other normal frames.
625struct NET_EXPORT_PRIVATE QuicPingFrame {
626};
627
[email protected]be24ab22012-10-22 03:01:52628struct NET_EXPORT_PRIVATE QuicStreamFrame {
629 QuicStreamFrame();
[email protected]5dafdb62013-11-14 01:24:26630 QuicStreamFrame(const QuicStreamFrame& frame);
[email protected]be24ab22012-10-22 03:01:52631 QuicStreamFrame(QuicStreamId stream_id,
[email protected]a5061242012-10-23 23:29:37632 bool fin,
[email protected]701bc892013-01-17 04:51:54633 QuicStreamOffset offset,
[email protected]5dafdb62013-11-14 01:24:26634 IOVector data);
635
[email protected]c5e1aca2014-01-30 04:03:04636 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
637 std::ostream& os, const QuicStreamFrame& s);
638
[email protected]5dafdb62013-11-14 01:24:26639 // Returns a copy of the IOVector |data| as a heap-allocated string.
640 // Caller must take ownership of the returned string.
641 std::string* GetDataAsString() const;
[email protected]8b37a092012-10-18 21:53:49642
643 QuicStreamId stream_id;
644 bool fin;
[email protected]701bc892013-01-17 04:51:54645 QuicStreamOffset offset; // Location of this data in the stream.
[email protected]5dafdb62013-11-14 01:24:26646 IOVector data;
[email protected]97cf3022013-09-05 14:30:16647
648 // If this is set, then when this packet is ACKed the AckNotifier will be
649 // informed.
650 QuicAckNotifier* notifier;
[email protected]8b37a092012-10-18 21:53:49651};
652
[email protected]e537f742012-12-07 15:33:53653// TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
654// is finalized.
[email protected]9db443912013-02-25 05:27:03655typedef std::set<QuicPacketSequenceNumber> SequenceNumberSet;
rtennetidd4bf8f2014-09-03 00:45:16656typedef std::list<QuicPacketSequenceNumber> SequenceNumberList;
rtenneti4b06ae72014-08-26 03:43:43657
mostynbdc40b80612014-09-10 03:45:42658typedef std::list<
659 std::pair<QuicPacketSequenceNumber, QuicTime> > PacketTimeList;
[email protected]044ac2b2012-11-13 21:41:06660
[email protected]310d37b2014-08-02 06:15:37661struct NET_EXPORT_PRIVATE QuicStopWaitingFrame {
662 QuicStopWaitingFrame();
663 ~QuicStopWaitingFrame();
[email protected]6ae6e342014-02-06 02:21:42664
[email protected]26f3f8e2012-12-13 21:07:19665 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
[email protected]310d37b2014-08-02 06:15:37666 std::ostream& os, const QuicStopWaitingFrame& s);
667 // Entropy hash of all packets up to, but not including, the least unacked
668 // packet.
669 QuicPacketEntropyHash entropy_hash;
670 // The lowest packet we've sent which is unacked, and we expect an ack for.
671 QuicPacketSequenceNumber least_unacked;
672};
673
674struct NET_EXPORT_PRIVATE QuicAckFrame {
675 QuicAckFrame();
676 ~QuicAckFrame();
677
678 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
679 std::ostream& os, const QuicAckFrame& s);
[email protected]a674b4c2012-12-05 03:44:30680
[email protected]9db443912013-02-25 05:27:03681 // Entropy hash of all packets up to largest observed not including missing
682 // packets.
683 QuicPacketEntropyHash entropy_hash;
[email protected]e537f742012-12-07 15:33:53684
[email protected]48697d8a2013-01-15 19:42:24685 // The highest packet sequence number we've observed from the peer.
686 //
687 // In general, this should be the largest packet number we've received. In
688 // the case of truncated acks, we may have to advertise a lower "upper bound"
689 // than largest received, to avoid implicitly acking missing packets that
690 // don't fit in the missing packet list due to size limitations. In this
691 // case, largest_observed may be a packet which is also in the missing packets
692 // list.
693 QuicPacketSequenceNumber largest_observed;
[email protected]a674b4c2012-12-05 03:44:30694
[email protected]14e8106c2013-03-14 16:25:33695 // Time elapsed since largest_observed was received until this Ack frame was
696 // sent.
697 QuicTime::Delta delta_time_largest_observed;
698
[email protected]9db443912013-02-25 05:27:03699 // TODO(satyamshekhar): Can be optimized using an interval set like data
700 // structure.
[email protected]e537f742012-12-07 15:33:53701 // The set of packets which we're expecting and have not received.
[email protected]9db443912013-02-25 05:27:03702 SequenceNumberSet missing_packets;
[email protected]8e01c062013-10-31 07:35:31703
704 // Whether the ack had to be truncated when sent.
705 bool is_truncated;
[email protected]bdf2d432014-02-09 10:45:41706
707 // Packets which have been revived via FEC.
708 // All of these must also be in missing_packets.
709 SequenceNumberSet revived_packets;
rtenneti4b06ae72014-08-26 03:43:43710
711 // List of <sequence_number, time> for when packets arrived.
712 PacketTimeList received_packet_times;
[email protected]8b37a092012-10-18 21:53:49713};
714
[email protected]9db443912013-02-25 05:27:03715// True if the sequence number is greater than largest_observed or is listed
716// as missing.
717// Always returns false for sequence numbers less than least_unacked.
718bool NET_EXPORT_PRIVATE IsAwaitingPacket(
[email protected]310d37b2014-08-02 06:15:37719 const QuicAckFrame& ack_frame,
[email protected]9db443912013-02-25 05:27:03720 QuicPacketSequenceNumber sequence_number);
721
722// Inserts missing packets between [lower, higher).
723void NET_EXPORT_PRIVATE InsertMissingPacketsBetween(
[email protected]310d37b2014-08-02 06:15:37724 QuicAckFrame* ack_frame,
[email protected]9db443912013-02-25 05:27:03725 QuicPacketSequenceNumber lower,
726 QuicPacketSequenceNumber higher);
727
[email protected]8b37a092012-10-18 21:53:49728// Defines for all types of congestion feedback that will be negotiated in QUIC,
[email protected]f62262b2013-07-05 20:57:30729// kTCP MUST be supported by all QUIC implementations to guarantee 100%
[email protected]8b37a092012-10-18 21:53:49730// compatibility.
rtenneti4b06ae72014-08-26 03:43:43731// TODO(cyr): Remove this when removing QUIC_VERSION_22.
[email protected]8b37a092012-10-18 21:53:49732enum CongestionFeedbackType {
[email protected]8b37a092012-10-18 21:53:49733 kTCP, // Used to mimic TCP.
[email protected]a692ad9d2014-07-18 21:35:24734};
735
736// Defines for all types of congestion control algorithms that can be used in
737// QUIC. Note that this is separate from the congestion feedback type -
738// some congestion control algorithms may use the same feedback type
739// (Reno and Cubic are the classic example for that).
740enum CongestionControlType {
741 kCubic,
742 kReno,
[email protected]a692ad9d2014-07-18 21:35:24743 kBBR,
[email protected]8b37a092012-10-18 21:53:49744};
745
[email protected]c5cc9bd2014-03-31 23:17:14746enum LossDetectionType {
747 kNack, // Used to mimic TCP's loss detection.
748 kTime, // Time based loss detection.
749};
750
rtenneti4b06ae72014-08-26 03:43:43751// TODO(cyr): Remove this when removing QUIC_VERSION_22.
[email protected]8b37a092012-10-18 21:53:49752struct NET_EXPORT_PRIVATE CongestionFeedbackMessageTCP {
[email protected]6ae6e342014-02-06 02:21:42753 CongestionFeedbackMessageTCP();
754
[email protected]fee17f72013-02-03 07:47:41755 QuicByteCount receive_window;
[email protected]8b37a092012-10-18 21:53:49756};
757
rtenneti4b06ae72014-08-26 03:43:43758// TODO(cyr): Remove this when removing QUIC_VERSION_22.
[email protected]26f3f8e2012-12-13 21:07:19759struct NET_EXPORT_PRIVATE QuicCongestionFeedbackFrame {
[email protected]7884ecad2012-12-14 22:55:15760 QuicCongestionFeedbackFrame();
761 ~QuicCongestionFeedbackFrame();
762
[email protected]26f3f8e2012-12-13 21:07:19763 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
764 std::ostream& os, const QuicCongestionFeedbackFrame& c);
765
[email protected]7884ecad2012-12-14 22:55:15766 CongestionFeedbackType type;
[email protected]a97b3182014-08-08 08:10:18767 // This should really be a union, but since the timestamp struct
[email protected]7884ecad2012-12-14 22:55:15768 // is non-trivial, C++ prohibits it.
769 CongestionFeedbackMessageTCP tcp;
[email protected]8b37a092012-10-18 21:53:49770};
771
[email protected]be24ab22012-10-22 03:01:52772struct NET_EXPORT_PRIVATE QuicRstStreamFrame {
[email protected]6ae6e342014-02-06 02:21:42773 QuicRstStreamFrame();
774 QuicRstStreamFrame(QuicStreamId stream_id,
775 QuicRstStreamErrorCode error_code,
776 QuicStreamOffset bytes_written);
[email protected]8b37a092012-10-18 21:53:49777
[email protected]c5e1aca2014-01-30 04:03:04778 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
779 std::ostream& os, const QuicRstStreamFrame& r);
780
[email protected]8b37a092012-10-18 21:53:49781 QuicStreamId stream_id;
[email protected]74bda142013-03-31 02:49:11782 QuicRstStreamErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09783 std::string error_details;
[email protected]6ae6e342014-02-06 02:21:42784
785 // Used to update flow control windows. On termination of a stream, both
786 // endpoints must inform the peer of the number of bytes they have sent on
787 // that stream. This can be done through normal termination (data packet with
788 // FIN) or through a RST.
789 QuicStreamOffset byte_offset;
[email protected]8b37a092012-10-18 21:53:49790};
791
[email protected]be24ab22012-10-22 03:01:52792struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame {
[email protected]6ae6e342014-02-06 02:21:42793 QuicConnectionCloseFrame();
794
[email protected]c5e1aca2014-01-30 04:03:04795 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
796 std::ostream& os, const QuicConnectionCloseFrame& c);
797
[email protected]431bb4fd2012-10-19 17:46:09798 QuicErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09799 std::string error_details;
[email protected]8b37a092012-10-18 21:53:49800};
801
[email protected]9db443912013-02-25 05:27:03802struct NET_EXPORT_PRIVATE QuicGoAwayFrame {
[email protected]6ae6e342014-02-06 02:21:42803 QuicGoAwayFrame();
[email protected]9db443912013-02-25 05:27:03804 QuicGoAwayFrame(QuicErrorCode error_code,
805 QuicStreamId last_good_stream_id,
806 const std::string& reason);
807
[email protected]c5e1aca2014-01-30 04:03:04808 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
809 std::ostream& os, const QuicGoAwayFrame& g);
810
[email protected]9db443912013-02-25 05:27:03811 QuicErrorCode error_code;
812 QuicStreamId last_good_stream_id;
813 std::string reason_phrase;
814};
815
[email protected]6ae6e342014-02-06 02:21:42816// Flow control updates per-stream and at the connection levoel.
817// Based on SPDY's WINDOW_UPDATE frame, but uses an absolute byte offset rather
818// than a window delta.
819// TODO(rjshade): A possible future optimization is to make stream_id and
820// byte_offset variable length, similar to stream frames.
821struct NET_EXPORT_PRIVATE QuicWindowUpdateFrame {
822 QuicWindowUpdateFrame() {}
823 QuicWindowUpdateFrame(QuicStreamId stream_id, QuicStreamOffset byte_offset);
824
825 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
826 std::ostream& os, const QuicWindowUpdateFrame& w);
827
828 // The stream this frame applies to. 0 is a special case meaning the overall
829 // connection rather than a specific stream.
830 QuicStreamId stream_id;
831
832 // Byte offset in the stream or connection. The receiver of this frame must
833 // not send data which would result in this offset being exceeded.
834 QuicStreamOffset byte_offset;
835};
836
837// The BLOCKED frame is used to indicate to the remote endpoint that this
838// endpoint believes itself to be flow-control blocked but otherwise ready to
839// send data. The BLOCKED frame is purely advisory and optional.
840// Based on SPDY's BLOCKED frame (undocumented as of 2014-01-28).
841struct NET_EXPORT_PRIVATE QuicBlockedFrame {
842 QuicBlockedFrame() {}
843 explicit QuicBlockedFrame(QuicStreamId stream_id);
844
845 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
846 std::ostream& os, const QuicBlockedFrame& b);
847
848 // The stream this frame applies to. 0 is a special case meaning the overall
849 // connection rather than a specific stream.
850 QuicStreamId stream_id;
851};
852
[email protected]8ba81212013-05-03 13:11:48853// EncryptionLevel enumerates the stages of encryption that a QUIC connection
854// progresses through. When retransmitting a packet, the encryption level needs
855// to be specified so that it is retransmitted at a level which the peer can
856// understand.
857enum EncryptionLevel {
858 ENCRYPTION_NONE = 0,
859 ENCRYPTION_INITIAL = 1,
860 ENCRYPTION_FORWARD_SECURE = 2,
861
862 NUM_ENCRYPTION_LEVELS,
863};
864
[email protected]be24ab22012-10-22 03:01:52865struct NET_EXPORT_PRIVATE QuicFrame {
[email protected]6ae6e342014-02-06 02:21:42866 QuicFrame();
867 explicit QuicFrame(QuicPaddingFrame* padding_frame);
868 explicit QuicFrame(QuicStreamFrame* stream_frame);
869 explicit QuicFrame(QuicAckFrame* frame);
rtenneti4b06ae72014-08-26 03:43:43870
871 // TODO(cyr): Remove this when removing QUIC_VERSION_22.
[email protected]6ae6e342014-02-06 02:21:42872 explicit QuicFrame(QuicCongestionFeedbackFrame* frame);
rtenneti4b06ae72014-08-26 03:43:43873
[email protected]6ae6e342014-02-06 02:21:42874 explicit QuicFrame(QuicRstStreamFrame* frame);
875 explicit QuicFrame(QuicConnectionCloseFrame* frame);
[email protected]93dd91f2014-02-27 00:09:03876 explicit QuicFrame(QuicStopWaitingFrame* frame);
[email protected]d8c522112014-04-23 09:23:25877 explicit QuicFrame(QuicPingFrame* frame);
[email protected]6ae6e342014-02-06 02:21:42878 explicit QuicFrame(QuicGoAwayFrame* frame);
879 explicit QuicFrame(QuicWindowUpdateFrame* frame);
880 explicit QuicFrame(QuicBlockedFrame* frame);
[email protected]8b37a092012-10-18 21:53:49881
[email protected]c5e1aca2014-01-30 04:03:04882 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
883 std::ostream& os, const QuicFrame& frame);
884
[email protected]be24ab22012-10-22 03:01:52885 QuicFrameType type;
[email protected]8b37a092012-10-18 21:53:49886 union {
[email protected]c995c572013-01-18 05:43:20887 QuicPaddingFrame* padding_frame;
[email protected]be24ab22012-10-22 03:01:52888 QuicStreamFrame* stream_frame;
889 QuicAckFrame* ack_frame;
rtenneti4b06ae72014-08-26 03:43:43890
891 // TODO(cyr): Remove this when removing QUIC_VERSION_22.
[email protected]26f3f8e2012-12-13 21:07:19892 QuicCongestionFeedbackFrame* congestion_feedback_frame;
[email protected]93dd91f2014-02-27 00:09:03893 QuicStopWaitingFrame* stop_waiting_frame;
rtenneti4b06ae72014-08-26 03:43:43894
[email protected]d8c522112014-04-23 09:23:25895 QuicPingFrame* ping_frame;
[email protected]be24ab22012-10-22 03:01:52896 QuicRstStreamFrame* rst_stream_frame;
897 QuicConnectionCloseFrame* connection_close_frame;
[email protected]9db443912013-02-25 05:27:03898 QuicGoAwayFrame* goaway_frame;
[email protected]6ae6e342014-02-06 02:21:42899 QuicWindowUpdateFrame* window_update_frame;
900 QuicBlockedFrame* blocked_frame;
[email protected]8b37a092012-10-18 21:53:49901 };
902};
903
[email protected]be24ab22012-10-22 03:01:52904typedef std::vector<QuicFrame> QuicFrames;
[email protected]8b37a092012-10-18 21:53:49905
906struct NET_EXPORT_PRIVATE QuicFecData {
907 QuicFecData();
[email protected]a5061242012-10-23 23:29:37908
[email protected]c995c572013-01-18 05:43:20909 // The FEC group number is also the sequence number of the first
910 // FEC protected packet. The last protected packet's sequence number will
911 // be one less than the sequence number of the FEC packet.
[email protected]8b37a092012-10-18 21:53:49912 QuicFecGroupNumber fec_group;
[email protected]8b37a092012-10-18 21:53:49913 base::StringPiece redundancy;
[email protected]8b37a092012-10-18 21:53:49914};
915
[email protected]8b37a092012-10-18 21:53:49916class NET_EXPORT_PRIVATE QuicData {
917 public:
[email protected]6ae6e342014-02-06 02:21:42918 QuicData(const char* buffer, size_t length);
919 QuicData(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:49920 virtual ~QuicData();
921
922 base::StringPiece AsStringPiece() const {
923 return base::StringPiece(data(), length());
924 }
925
926 const char* data() const { return buffer_; }
927 size_t length() const { return length_; }
928
929 private:
930 const char* buffer_;
931 size_t length_;
932 bool owns_buffer_;
933
934 DISALLOW_COPY_AND_ASSIGN(QuicData);
935};
936
937class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
938 public:
[email protected]25c31dc2013-06-05 17:56:04939 static QuicPacket* NewDataPacket(
940 char* buffer,
941 size_t length,
942 bool owns_buffer,
[email protected]3aa9ca72014-02-27 19:39:43943 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04944 bool includes_version,
945 QuicSequenceNumberLength sequence_number_length) {
[email protected]3aa9ca72014-02-27 19:39:43946 return new QuicPacket(buffer, length, owns_buffer, connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04947 includes_version, sequence_number_length, false);
[email protected]c995c572013-01-18 05:43:20948 }
949
[email protected]25c31dc2013-06-05 17:56:04950 static QuicPacket* NewFecPacket(
951 char* buffer,
952 size_t length,
953 bool owns_buffer,
[email protected]3aa9ca72014-02-27 19:39:43954 QuicConnectionIdLength connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04955 bool includes_version,
956 QuicSequenceNumberLength sequence_number_length) {
[email protected]3aa9ca72014-02-27 19:39:43957 return new QuicPacket(buffer, length, owns_buffer, connection_id_length,
[email protected]25c31dc2013-06-05 17:56:04958 includes_version, sequence_number_length, true);
[email protected]c995c572013-01-18 05:43:20959 }
[email protected]8b37a092012-10-18 21:53:49960
[email protected]5351cc4b2013-03-03 07:22:41961 base::StringPiece FecProtectedData() const;
962 base::StringPiece AssociatedData() const;
963 base::StringPiece BeforePlaintext() const;
964 base::StringPiece Plaintext() const;
[email protected]082b65b2012-11-10 19:11:31965
[email protected]c995c572013-01-18 05:43:20966 bool is_fec_packet() const { return is_fec_packet_; }
[email protected]082b65b2012-11-10 19:11:31967
[email protected]8b37a092012-10-18 21:53:49968 char* mutable_data() { return buffer_; }
969
970 private:
[email protected]5351cc4b2013-03-03 07:22:41971 QuicPacket(char* buffer,
972 size_t length,
973 bool owns_buffer,
[email protected]3aa9ca72014-02-27 19:39:43974 QuicConnectionIdLength connection_id_length,
[email protected]5351cc4b2013-03-03 07:22:41975 bool includes_version,
[email protected]25c31dc2013-06-05 17:56:04976 QuicSequenceNumberLength sequence_number_length,
[email protected]6ae6e342014-02-06 02:21:42977 bool is_fec_packet);
[email protected]c995c572013-01-18 05:43:20978
[email protected]8b37a092012-10-18 21:53:49979 char* buffer_;
[email protected]c995c572013-01-18 05:43:20980 const bool is_fec_packet_;
[email protected]3aa9ca72014-02-27 19:39:43981 const QuicConnectionIdLength connection_id_length_;
[email protected]5351cc4b2013-03-03 07:22:41982 const bool includes_version_;
[email protected]25c31dc2013-06-05 17:56:04983 const QuicSequenceNumberLength sequence_number_length_;
[email protected]8b37a092012-10-18 21:53:49984
[email protected]2e740db2012-10-20 19:35:19985 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
[email protected]8b37a092012-10-18 21:53:49986};
987
988class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
989 public:
[email protected]6ae6e342014-02-06 02:21:42990 QuicEncryptedPacket(const char* buffer, size_t length);
991 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:49992
[email protected]ec86d5462013-11-17 16:04:49993 // Clones the packet into a new packet which owns the buffer.
994 QuicEncryptedPacket* Clone() const;
995
[email protected]c1b32c62013-01-20 02:49:10996 // By default, gtest prints the raw bytes of an object. The bool data
997 // member (in the base class QuicData) causes this object to have padding
998 // bytes, which causes the default gtest object printer to read
999 // uninitialize memory. So we need to teach gtest how to print this object.
1000 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
1001 std::ostream& os, const QuicEncryptedPacket& s);
1002
[email protected]2e740db2012-10-20 19:35:191003 private:
1004 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
[email protected]8b37a092012-10-18 21:53:491005};
1006
[email protected]9db443912013-02-25 05:27:031007class NET_EXPORT_PRIVATE RetransmittableFrames {
1008 public:
1009 RetransmittableFrames();
1010 ~RetransmittableFrames();
1011
1012 // Allocates a local copy of the referenced StringPiece has QuicStreamFrame
1013 // use it.
1014 // Takes ownership of |stream_frame|.
1015 const QuicFrame& AddStreamFrame(QuicStreamFrame* stream_frame);
1016 // Takes ownership of the frame inside |frame|.
1017 const QuicFrame& AddNonStreamFrame(const QuicFrame& frame);
1018 const QuicFrames& frames() const { return frames_; }
1019
[email protected]672631c2014-08-16 06:11:451020 IsHandshake HasCryptoHandshake() const {
1021 return has_crypto_handshake_;
1022 }
[email protected]2115d33ba2014-01-02 21:53:521023
[email protected]8ba81212013-05-03 13:11:481024 void set_encryption_level(EncryptionLevel level);
1025 EncryptionLevel encryption_level() const {
1026 return encryption_level_;
1027 }
1028
[email protected]9db443912013-02-25 05:27:031029 private:
1030 QuicFrames frames_;
[email protected]8ba81212013-05-03 13:11:481031 EncryptionLevel encryption_level_;
[email protected]672631c2014-08-16 06:11:451032 IsHandshake has_crypto_handshake_;
[email protected]9db443912013-02-25 05:27:031033 // Data referenced by the StringPiece of a QuicStreamFrame.
1034 std::vector<std::string*> stream_data_;
1035
1036 DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames);
1037};
1038
1039struct NET_EXPORT_PRIVATE SerializedPacket {
1040 SerializedPacket(QuicPacketSequenceNumber sequence_number,
[email protected]ea825e02013-08-21 18:12:451041 QuicSequenceNumberLength sequence_number_length,
[email protected]9db443912013-02-25 05:27:031042 QuicPacket* packet,
1043 QuicPacketEntropyHash entropy_hash,
[email protected]97cf3022013-09-05 14:30:161044 RetransmittableFrames* retransmittable_frames);
1045 ~SerializedPacket();
[email protected]9db443912013-02-25 05:27:031046
1047 QuicPacketSequenceNumber sequence_number;
[email protected]ea825e02013-08-21 18:12:451048 QuicSequenceNumberLength sequence_number_length;
[email protected]9db443912013-02-25 05:27:031049 QuicPacket* packet;
1050 QuicPacketEntropyHash entropy_hash;
1051 RetransmittableFrames* retransmittable_frames;
[email protected]97cf3022013-09-05 14:30:161052
1053 // If set, these will be called when this packet is ACKed by the peer.
1054 std::set<QuicAckNotifier*> notifiers;
[email protected]9db443912013-02-25 05:27:031055};
1056
[email protected]77b5d50b2014-05-07 22:48:481057struct NET_EXPORT_PRIVATE TransmissionInfo {
1058 // Used by STL when assigning into a map.
1059 TransmissionInfo();
1060
1061 // Constructs a Transmission with a new all_tranmissions set
1062 // containing |sequence_number|.
1063 TransmissionInfo(RetransmittableFrames* retransmittable_frames,
[email protected]77b5d50b2014-05-07 22:48:481064 QuicSequenceNumberLength sequence_number_length);
1065
1066 // Constructs a Transmission with the specified |all_tranmissions| set
1067 // and inserts |sequence_number| into it.
1068 TransmissionInfo(RetransmittableFrames* retransmittable_frames,
[email protected]77b5d50b2014-05-07 22:48:481069 QuicSequenceNumberLength sequence_number_length,
[email protected]730b35d72014-06-05 03:23:221070 TransmissionType transmission_type,
rtennetidd4bf8f2014-09-03 00:45:161071 SequenceNumberList* all_transmissions);
[email protected]77b5d50b2014-05-07 22:48:481072
1073 RetransmittableFrames* retransmittable_frames;
1074 QuicSequenceNumberLength sequence_number_length;
1075 // Zero when the packet is serialized, non-zero once it's sent.
1076 QuicTime sent_time;
1077 // Zero when the packet is serialized, non-zero once it's sent.
1078 QuicByteCount bytes_sent;
1079 size_t nack_count;
[email protected]730b35d72014-06-05 03:23:221080 // Reason why this packet was transmitted.
1081 TransmissionType transmission_type;
[email protected]77b5d50b2014-05-07 22:48:481082 // Stores the sequence numbers of all transmissions of this packet.
rtennetibe635732014-10-02 22:51:421083 // Must always be nullptr or have multiple elements.
rtennetidd4bf8f2014-09-03 00:45:161084 SequenceNumberList* all_transmissions;
[email protected]aa7e4ef2014-05-28 03:53:151085 // In flight packets have not been abandoned or lost.
1086 bool in_flight;
rtenneti31e9fd62014-09-16 05:22:151087 // True if the packet can never be acked, so it can be removed.
1088 bool is_unackable;
[email protected]77b5d50b2014-05-07 22:48:481089};
1090
[email protected]8b37a092012-10-18 21:53:491091} // namespace net
1092
1093#endif // NET_QUIC_QUIC_PROTOCOL_H_