blob: 33f88469df119deb9bf99a76b145c03bef14a713 [file] [log] [blame]
[email protected]8b37a092012-10-18 21:53:491// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_QUIC_QUIC_PROTOCOL_H_
6#define NET_QUIC_QUIC_PROTOCOL_H_
7
[email protected]e537f742012-12-07 15:33:538#include <stddef.h>
tfarina3723da22015-06-03 21:39:309#include <stdint.h>
Avi Drissman13fc8932015-12-20 04:40:4610
[email protected]8b37a092012-10-18 21:53:4911#include <limits>
rtenneti4b06ae72014-08-26 03:43:4312#include <list>
[email protected]a674b4c2012-12-05 03:44:3013#include <map>
[email protected]5640d0a2012-10-22 18:17:0214#include <ostream>
[email protected]e537f742012-12-07 15:33:5315#include <set>
16#include <string>
[email protected]8b37a092012-10-18 21:53:4917#include <utility>
18#include <vector>
19
[email protected]14c1c232013-06-11 17:52:4420#include "base/containers/hash_tables.h"
[email protected]8b37a092012-10-18 21:53:4921#include "base/logging.h"
Avi Drissman13fc8932015-12-20 04:40:4622#include "base/macros.h"
rtenneti8dd12b22015-10-21 01:26:3823#include "base/memory/ref_counted.h"
rtennetif60c32d82015-10-14 00:07:0024#include "base/memory/scoped_ptr.h"
[email protected]d069c11a2013-04-13 00:01:5525#include "base/strings/string_piece.h"
[email protected]165e0752012-11-16 07:49:4426#include "net/base/int128.h"
rtennetic14c8ab2015-06-18 05:47:4027#include "net/base/iovec.h"
[email protected]79d13dcb2014-02-05 07:23:1328#include "net/base/ip_endpoint.h"
[email protected]8b37a092012-10-18 21:53:4929#include "net/base/net_export.h"
rtenneti4efd55dd2015-09-18 01:12:0430#include "net/quic/interval_set.h"
rtenneti8dd12b22015-10-21 01:26:3831#include "net/quic/quic_ack_listener_interface.h"
[email protected]fee17f72013-02-03 07:47:4132#include "net/quic/quic_bandwidth.h"
[email protected]2a960e02012-11-11 14:48:1033#include "net/quic/quic_time.h"
rtennetic14c8ab2015-06-18 05:47:4034#include "net/quic/quic_types.h"
[email protected]8b37a092012-10-18 21:53:4935
36namespace net {
37
[email protected]8b37a092012-10-18 21:53:4938class QuicPacket;
[email protected]b064310782013-05-30 21:12:1739struct QuicPacketHeader;
[email protected]8b37a092012-10-18 21:53:4940
Avi Drissman13fc8932015-12-20 04:40:4641typedef uint64_t QuicConnectionId;
42typedef uint32_t QuicStreamId;
43typedef uint64_t QuicStreamOffset;
44typedef uint64_t QuicPacketNumber;
45typedef uint8_t QuicPathId;
rtennetia004d332015-08-28 06:44:5746typedef QuicPacketNumber QuicFecGroupNumber;
Avi Drissman13fc8932015-12-20 04:40:4647typedef uint64_t QuicPublicResetNonceProof;
48typedef uint8_t QuicPacketEntropyHash;
49typedef uint32_t QuicHeaderId;
[email protected]2532de12013-05-09 12:29:3350// QuicTag is the type of a tag in the wire protocol.
Avi Drissman13fc8932015-12-20 04:40:4651typedef uint32_t QuicTag;
[email protected]2532de12013-05-09 12:29:3352typedef std::vector<QuicTag> QuicTagVector;
[email protected]79d13dcb2014-02-05 07:23:1353typedef std::map<QuicTag, std::string> QuicTagValueMap;
Avi Drissman13fc8932015-12-20 04:40:4654typedef uint16_t QuicPacketLength;
[email protected]cff7b7b2013-01-11 08:49:0755
rtennetibb2780c2015-07-22 19:16:0856// Default initial maximum size in bytes of a QUIC packet.
[email protected]310d37b2014-08-02 06:15:3757const QuicByteCount kDefaultMaxPacketSize = 1350;
rtenneti16a20772015-02-17 18:58:4858// Default initial maximum size in bytes of a QUIC packet for servers.
59const QuicByteCount kDefaultServerMaxPacketSize = 1000;
[email protected]8e01c062013-10-31 07:35:3160// The maximum packet size of any QUIC packet, based on ethernet's max size,
[email protected]41fb6372013-12-10 05:26:4061// minus the IP and UDP headers. IPv6 has a 40 byte header, UPD adds an
62// additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's
63// max packet size is 1500 bytes, 1500 - 48 = 1452.
64const QuicByteCount kMaxPacketSize = 1452;
rtenneti9e0fb502015-03-08 06:07:1665// Default maximum packet size used in the Linux TCP implementation.
66// Used in QUIC for congestion window computations in bytes.
[email protected]ce7bb1412014-05-17 15:51:3367const QuicByteCount kDefaultTCPMSS = 1460;
[email protected]8e01c062013-10-31 07:35:3168
rch1fe2eeb2015-10-26 14:45:5769// We match SPDY's use of 32 (since we'd compete with SPDY).
70const QuicPacketCount kInitialCongestionWindow = 32;
[email protected]8e01c062013-10-31 07:35:3171
rtenneti7652bf32015-01-05 18:51:0772// Minimum size of initial flow control window, for both stream and session.
Avi Drissman13fc8932015-12-20 04:40:4673const uint32_t kMinimumFlowControlSendWindow = 16 * 1024; // 16 KB
[email protected]9bb57c72014-03-31 20:36:0474
rjshadec86dbfa2015-11-12 20:16:2575// Maximum flow control receive window limits for connection and stream.
76const QuicByteCount kStreamReceiveWindowLimit = 16 * 1024 * 1024; // 16 MB
77const QuicByteCount kSessionReceiveWindowLimit = 24 * 1024 * 1024; // 24 MB
78
rtennetifb3fa6c2015-03-16 23:04:5579// Minimum size of the CWND, in packets, when doing bandwidth resumption.
rtenneti8d2a808d2014-11-26 01:10:0980const QuicPacketCount kMinCongestionWindowForBandwidthResumption = 10;
81
rtenneti581b6ae82015-07-20 20:48:0182// Maximum size of the CWND, in packets.
83const QuicPacketCount kMaxCongestionWindow = 200;
rtenneti69e64aa2015-06-26 04:25:3084
85// Maximum number of tracked packets.
86const QuicPacketCount kMaxTrackedPackets = 5000;
[email protected]0ac0c5b2013-11-20 05:55:5887
rtenneti23186682014-10-30 01:49:3388// Default size of the socket receive buffer in bytes.
[email protected]648f81142014-08-15 21:38:4689const QuicByteCount kDefaultSocketReceiveBuffer = 256 * 1024;
rtenneti23186682014-10-30 01:49:3390// Minimum size of the socket receive buffer in bytes.
91// Smaller values are ignored.
92const QuicByteCount kMinSocketReceiveBuffer = 16 * 1024;
[email protected]a97b3182014-08-08 08:10:1893
rtenneti95293802015-03-27 18:59:2394// Fraction of the receive buffer that can be used for encrypted bytes.
95// Allows a 5% overhead for IP and UDP framing, as well as ack only packets.
96static const float kUsableRecieveBufferFraction = 0.95f;
rtenneti581b6ae82015-07-20 20:48:0197// Fraction of the receive buffer that can be used, based on conservative
98// estimates and testing on Linux.
99// An alternative to kUsableRecieveBufferFraction.
100static const float kConservativeReceiveBufferFraction = 0.6f;
rtenneti95293802015-03-27 18:59:23101
rtennetifc97ab62014-11-11 22:17:49102// Don't allow a client to suggest an RTT shorter than 10ms.
Avi Drissman13fc8932015-12-20 04:40:46103const uint32_t kMinInitialRoundTripTimeUs = 10 * kNumMicrosPerMilli;
rtennetifc97ab62014-11-11 22:17:49104
[email protected]8e01c062013-10-31 07:35:31105// Don't allow a client to suggest an RTT longer than 15 seconds.
Avi Drissman13fc8932015-12-20 04:40:46106const uint32_t kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond;
[email protected]8b37a092012-10-18 21:53:49107
108// Maximum number of open streams per connection.
109const size_t kDefaultMaxStreamsPerConnection = 100;
110
[email protected]af806e62013-05-22 14:47:50111// Number of bytes reserved for public flags in the packet header.
112const size_t kPublicFlagsSize = 1;
[email protected]5351cc4b2013-03-03 07:22:41113// Number of bytes reserved for version number in the packet header.
114const size_t kQuicVersionSize = 4;
zhongyib8677022015-12-01 05:51:30115// Number of bytes reserved for path id in the packet header.
116const size_t kQuicPathIdSize = 1;
[email protected]c995c572013-01-18 05:43:20117// Number of bytes reserved for private flags in the packet header.
118const size_t kPrivateFlagsSize = 1;
119// Number of bytes reserved for FEC group in the packet header.
120const size_t kFecGroupSize = 1;
[email protected]5351cc4b2013-03-03 07:22:41121
122// Signifies that the QuicPacket will contain version of the protocol.
123const bool kIncludeVersion = true;
zhongyib8677022015-12-01 05:51:30124// Signifies that the QuicPacket will contain path id.
125const bool kIncludePathId = true;
[email protected]c995c572013-01-18 05:43:20126
[email protected]8b37a092012-10-18 21:53:49127// Reserved ID for the crypto stream.
[email protected]8b37a092012-10-18 21:53:49128const QuicStreamId kCryptoStreamId = 1;
129
[email protected]4d640792013-12-18 22:21:08130// Reserved ID for the headers stream.
131const QuicStreamId kHeadersStreamId = 3;
132
jri3285d93a2015-12-14 08:53:19133// Header key used to identify final offset on data stream when sending HTTP/2
134// trailing headers over QUIC.
135NET_EXPORT_PRIVATE extern const char* const kFinalOffsetHeaderKey;
136
[email protected]648f81142014-08-15 21:38:46137// Maximum delayed ack time, in ms.
Avi Drissman13fc8932015-12-20 04:40:46138const int64_t kMaxDelayedAckTimeMs = 25;
[email protected]648f81142014-08-15 21:38:46139
rtennetib5512bb2014-09-29 19:17:15140// The timeout before the handshake succeeds.
Avi Drissman13fc8932015-12-20 04:40:46141const int64_t kInitialIdleTimeoutSecs = 5;
rtennetib5512bb2014-09-29 19:17:15142// The default idle timeout.
Avi Drissman13fc8932015-12-20 04:40:46143const int64_t kDefaultIdleTimeoutSecs = 30;
rtenneti31e9fd62014-09-16 05:22:15144// The maximum idle timeout that can be negotiated.
Avi Drissman13fc8932015-12-20 04:40:46145const int64_t kMaximumIdleTimeoutSecs = 60 * 10; // 10 minutes.
rtenneti31e9fd62014-09-16 05:22:15146// The default timeout for a connection until the crypto handshake succeeds.
Avi Drissman13fc8932015-12-20 04:40:46147const int64_t kMaxTimeForCryptoHandshakeSecs = 10; // 10 secs.
[email protected]8b37a092012-10-18 21:53:49148
rtenneti93bce7ece2014-10-13 22:38:41149// Default limit on the number of undecryptable packets the connection buffers
150// before the CHLO/SHLO arrive.
151const size_t kDefaultMaxUndecryptablePackets = 10;
152
[email protected]525948df2014-04-21 06:26:58153// Default ping timeout.
Avi Drissman13fc8932015-12-20 04:40:46154const int64_t kPingTimeoutSecs = 15; // 15 secs.
[email protected]525948df2014-04-21 06:26:58155
[email protected]ca4e0d92014-08-22 16:33:22156// Minimum number of RTTs between Server Config Updates (SCUP) sent to client.
157const int kMinIntervalBetweenServerConfigUpdatesRTTs = 10;
158
159// Minimum time between Server Config Updates (SCUP) sent to client.
160const int kMinIntervalBetweenServerConfigUpdatesMs = 1000;
161
rtenneti33da8ab2014-11-04 04:17:00162// Minimum number of packets between Server Config Updates (SCUP).
163const int kMinPacketsBetweenServerConfigUpdates = 100;
164
rtennetib5512bb2014-09-29 19:17:15165// The number of open streams that a server will accept is set to be slightly
166// larger than the negotiated limit. Immediately closing the connection if the
167// client opens slightly too many streams is not ideal: the client may have sent
168// a FIN that was lost, and simultaneously opened a new stream. The number of
169// streams a server accepts is a fixed increment over the negotiated limit, or a
170// percentage increase, whichever is larger.
rtenneti31e9fd62014-09-16 05:22:15171const float kMaxStreamsMultiplier = 1.1f;
rtennetib5512bb2014-09-29 19:17:15172const int kMaxStreamsMinimumIncrement = 10;
rtenneti31e9fd62014-09-16 05:22:15173
rtenneti159828f2015-10-13 06:58:09174// Available streams are ones with IDs less than the highest stream that has
175// been opened which have neither been opened or reset. The limit on the number
176// of available streams is 10 times the limit on the number of open streams.
177const int kMaxAvailableStreamsMultiplier = 10;
178
[email protected]b007e632013-10-28 08:39:25179// We define an unsigned 16-bit floating point value, inspired by IEEE floats
180// (http://en.wikipedia.org/wiki/Half_precision_floating-point_format),
181// with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden
182// bit) and denormals, but without signs, transfinites or fractions. Wire format
183// 16 bits (little-endian byte order) are split into exponent (high 5) and
184// mantissa (low 11) and decoded as:
Avi Drissman13fc8932015-12-20 04:40:46185// uint64_t value;
[email protected]b007e632013-10-28 08:39:25186// if (exponent == 0) value = mantissa;
187// else value = (mantissa | 1 << 11) << (exponent - 1)
188const int kUFloat16ExponentBits = 5;
rjshaded5ced072015-12-18 19:26:02189const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30
190const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11
[email protected]b007e632013-10-28 08:39:25191const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12
Avi Drissman13fc8932015-12-20 04:40:46192const uint64_t kUFloat16MaxValue = // 0x3FFC0000000
rjshaded5ced072015-12-18 19:26:02193 ((UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1)
194 << kUFloat16MaxExponent;
[email protected]b007e632013-10-28 08:39:25195
jri3285d93a2015-12-14 08:53:19196// Default path ID.
197const QuicPathId kDefaultPathId = 0;
198
[email protected]c67a82cb2013-09-24 02:53:21199enum TransmissionType {
[email protected]2532de12013-05-09 12:29:33200 NOT_RETRANSMISSION,
[email protected]b9475b582014-03-20 20:04:33201 FIRST_TRANSMISSION_TYPE = NOT_RETRANSMISSION,
rjshaded5ced072015-12-18 19:26:02202 HANDSHAKE_RETRANSMISSION, // Retransmits due to handshake timeouts.
rtenneti31e9fd62014-09-16 05:22:15203 ALL_UNACKED_RETRANSMISSION, // Retransmits all unacked packets.
204 ALL_INITIAL_RETRANSMISSION, // Retransmits all initially encrypted packets.
rjshaded5ced072015-12-18 19:26:02205 LOSS_RETRANSMISSION, // Retransmits due to loss detection.
206 RTO_RETRANSMISSION, // Retransmits due to retransmit time out.
207 TLP_RETRANSMISSION, // Tail loss probes.
[email protected]b9475b582014-03-20 20:04:33208 LAST_TRANSMISSION_TYPE = TLP_RETRANSMISSION,
[email protected]74bda142013-03-31 02:49:11209};
210
211enum HasRetransmittableData {
[email protected]2532de12013-05-09 12:29:33212 NO_RETRANSMITTABLE_DATA,
213 HAS_RETRANSMITTABLE_DATA,
[email protected]74bda142013-03-31 02:49:11214};
215
rjshaded5ced072015-12-18 19:26:02216enum IsHandshake { NOT_HANDSHAKE, IS_HANDSHAKE };
[email protected]575cce62013-08-03 02:06:43217
rtenneti6f48aa92015-03-16 02:18:48218enum class Perspective { IS_SERVER, IS_CLIENT };
219
220NET_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
221 const Perspective& s);
222
[email protected]bbb10072014-06-13 07:41:59223// Indicates FEC protection level for data being written.
224enum FecProtection {
225 MUST_FEC_PROTECT, // Callee must FEC protect this data.
[email protected]a5b98172014-06-18 07:01:59226 MAY_FEC_PROTECT // Callee does not have to but may FEC protect this data.
227};
228
[email protected]bc356fe2014-06-19 11:14:14229// Indicates FEC policy.
[email protected]a5b98172014-06-18 07:01:59230enum FecPolicy {
231 FEC_PROTECT_ALWAYS, // All data in the stream should be FEC protected.
232 FEC_PROTECT_OPTIONAL // Data in the stream does not need FEC protection.
[email protected]bbb10072014-06-13 07:41:59233};
234
rtennetia4228ea2015-06-04 02:31:44235// Indicates FEC policy about when to send FEC packet.
236enum FecSendPolicy {
237 // Send FEC packet when FEC group is full or when FEC alarm goes off.
238 FEC_ANY_TRIGGER,
239 // Send FEC packet only when FEC alarm goes off.
240 FEC_ALARM_TRIGGER
241};
242
[email protected]be24ab22012-10-22 03:01:52243enum QuicFrameType {
[email protected]6ae6e342014-02-06 02:21:42244 // Regular frame types. The values set here cannot change without the
245 // introduction of a new QUIC version.
[email protected]c995c572013-01-18 05:43:20246 PADDING_FRAME = 0,
[email protected]6ae6e342014-02-06 02:21:42247 RST_STREAM_FRAME = 1,
248 CONNECTION_CLOSE_FRAME = 2,
249 GOAWAY_FRAME = 3,
250 WINDOW_UPDATE_FRAME = 4,
251 BLOCKED_FRAME = 5,
[email protected]93dd91f2014-02-27 00:09:03252 STOP_WAITING_FRAME = 6,
[email protected]d8c522112014-04-23 09:23:25253 PING_FRAME = 7,
[email protected]6ae6e342014-02-06 02:21:42254
rtennetif4bdb542015-01-21 14:33:05255 // STREAM and ACK frames are special frames. They are encoded differently on
256 // the wire and their values do not need to be stable.
[email protected]97cf3022013-09-05 14:30:16257 STREAM_FRAME,
258 ACK_FRAME,
rtenneti69e64aa2015-06-26 04:25:30259 // The path MTU discovery frame is encoded as a PING frame on the wire.
260 MTU_DISCOVERY_FRAME,
[email protected]be24ab22012-10-22 03:01:52261 NUM_FRAME_TYPES
[email protected]8b37a092012-10-18 21:53:49262};
263
[email protected]3aa9ca72014-02-27 19:39:43264enum QuicConnectionIdLength {
265 PACKET_0BYTE_CONNECTION_ID = 0,
266 PACKET_1BYTE_CONNECTION_ID = 1,
267 PACKET_4BYTE_CONNECTION_ID = 4,
268 PACKET_8BYTE_CONNECTION_ID = 8
[email protected]b064310782013-05-30 21:12:17269};
270
271enum InFecGroup {
272 NOT_IN_FEC_GROUP,
273 IN_FEC_GROUP,
274};
275
rtennetia004d332015-08-28 06:44:57276enum QuicPacketNumberLength {
277 PACKET_1BYTE_PACKET_NUMBER = 1,
278 PACKET_2BYTE_PACKET_NUMBER = 2,
279 PACKET_4BYTE_PACKET_NUMBER = 4,
280 PACKET_6BYTE_PACKET_NUMBER = 6
[email protected]25c31dc2013-06-05 17:56:04281};
282
[email protected]8e01c062013-10-31 07:35:31283// Used to indicate a QuicSequenceNumberLength using two flag bits.
rtennetia004d332015-08-28 06:44:57284enum QuicPacketNumberLengthFlags {
285 PACKET_FLAGS_1BYTE_PACKET = 0, // 00
286 PACKET_FLAGS_2BYTE_PACKET = 1, // 01
287 PACKET_FLAGS_4BYTE_PACKET = 1 << 1, // 10
288 PACKET_FLAGS_6BYTE_PACKET = 1 << 1 | 1, // 11
[email protected]8e01c062013-10-31 07:35:31289};
290
[email protected]f62262b2013-07-05 20:57:30291// The public flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20292enum QuicPacketPublicFlags {
293 PACKET_PUBLIC_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30294
295 // Bit 0: Does the packet header contains version info?
296 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0,
297
298 // Bit 1: Is this packet a public reset packet?
299 PACKET_PUBLIC_FLAGS_RST = 1 << 1,
300
[email protected]3aa9ca72014-02-27 19:39:43301 // Bits 2 and 3 specify the length of the ConnectionId as follows:
[email protected]f62262b2013-07-05 20:57:30302 // ----00--: 0 bytes
303 // ----01--: 1 byte
304 // ----10--: 4 bytes
305 // ----11--: 8 bytes
[email protected]3aa9ca72014-02-27 19:39:43306 PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID = 0,
307 PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID = 1 << 2,
308 PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID = 1 << 3,
309 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID = 1 << 3 | 1 << 2,
[email protected]f62262b2013-07-05 20:57:30310
rtennetia004d332015-08-28 06:44:57311 // Bits 4 and 5 describe the packet number length as follows:
[email protected]f62262b2013-07-05 20:57:30312 // --00----: 1 byte
313 // --01----: 2 bytes
314 // --10----: 4 bytes
315 // --11----: 6 bytes
rtennetia004d332015-08-28 06:44:57316 PACKET_PUBLIC_FLAGS_1BYTE_PACKET = PACKET_FLAGS_1BYTE_PACKET << 4,
317 PACKET_PUBLIC_FLAGS_2BYTE_PACKET = PACKET_FLAGS_2BYTE_PACKET << 4,
318 PACKET_PUBLIC_FLAGS_4BYTE_PACKET = PACKET_FLAGS_4BYTE_PACKET << 4,
319 PACKET_PUBLIC_FLAGS_6BYTE_PACKET = PACKET_FLAGS_6BYTE_PACKET << 4,
[email protected]f62262b2013-07-05 20:57:30320
zhongyib8677022015-12-01 05:51:30321 // Bit 6: Does the packet header contain a path id?
322 PACKET_PUBLIC_FLAGS_MULTIPATH = 1 << 6,
323
324 // All bits set (bit7 are not currently used): 01111111
325 PACKET_PUBLIC_FLAGS_MAX = (1 << 7) - 1,
[email protected]c995c572013-01-18 05:43:20326};
[email protected]8b37a092012-10-18 21:53:49327
[email protected]f62262b2013-07-05 20:57:30328// The private flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20329enum QuicPacketPrivateFlags {
330 PACKET_PRIVATE_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30331
332 // Bit 0: Does this packet contain an entropy bit?
[email protected]b064310782013-05-30 21:12:17333 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0,
[email protected]f62262b2013-07-05 20:57:30334
335 // Bit 1: Payload is part of an FEC group?
336 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1,
337
338 // Bit 2: Payload is FEC as opposed to frames?
339 PACKET_PRIVATE_FLAGS_FEC = 1 << 2,
340
341 // All bits set (bits 3-7 are not currently used): 00000111
342 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1
[email protected]c995c572013-01-18 05:43:20343};
344
[email protected]48878092013-07-26 14:51:56345// The available versions of QUIC. Guaranteed that the integer value of the enum
346// will match the version number.
347// When adding a new version to this enum you should add it to
[email protected]8bbfaeb72013-08-09 06:38:26348// kSupportedQuicVersions (if appropriate), and also add a new case to the
349// helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and
350// QuicVersionToString.
[email protected]48878092013-07-26 14:51:56351enum QuicVersion {
352 // Special case to indicate unknown/unsupported QUIC version.
353 QUIC_VERSION_UNSUPPORTED = 0,
354
rchc0815442015-04-18 13:29:46355 QUIC_VERSION_25 = 25, // SPDY/4 header keys, and removal of error_details
356 // from QuicRstStreamFrame
zhongyic92bc492015-09-22 19:14:36357 QUIC_VERSION_26 = 26, // In CHLO, send XLCT tag containing hash of leaf cert
rtenneti159828f2015-10-13 06:58:09358 QUIC_VERSION_27 = 27, // Sends a nonce in the SHLO.
rtenneti5ca6eee2015-10-15 21:54:30359 QUIC_VERSION_28 = 28, // Receiver can refuse to create a requested stream.
rch99b644c2015-11-04 05:25:28360 QUIC_VERSION_29 = 29, // Server and client honor QUIC_STREAM_NO_ERROR.
361 QUIC_VERSION_30 = 30, // Add server side support of cert transparency.
[email protected]48878092013-07-26 14:51:56362};
363
364// This vector contains QUIC versions which we currently support.
365// This should be ordered such that the highest supported version is the first
366// element, with subsequent elements in descending order (versions can be
367// skipped as necessary).
[email protected]31ae854842013-11-27 00:05:46368//
[email protected]310d37b2014-08-02 06:15:37369// IMPORTANT: if you are adding to this list, follow the instructions at
[email protected]31ae854842013-11-27 00:05:46370// http://sites/quic/adding-and-removing-versions
zhongyic92bc492015-09-22 19:14:36371static const QuicVersion kSupportedQuicVersions[] = {
rch99b644c2015-11-04 05:25:28372 QUIC_VERSION_30, QUIC_VERSION_29, QUIC_VERSION_28,
373 QUIC_VERSION_27, QUIC_VERSION_26, QUIC_VERSION_25};
[email protected]48878092013-07-26 14:51:56374
375typedef std::vector<QuicVersion> QuicVersionVector;
376
[email protected]b007e632013-10-28 08:39:25377// Returns a vector of QUIC versions in kSupportedQuicVersions.
378NET_EXPORT_PRIVATE QuicVersionVector QuicSupportedVersions();
[email protected]ea2ab47b2013-08-13 00:44:11379
[email protected]48878092013-07-26 14:51:56380// QuicTag is written to and read from the wire, but we prefer to use
381// the more readable QuicVersion at other levels.
382// Helper function which translates from a QuicVersion to a QuicTag. Returns 0
383// if QuicVersion is unsupported.
384NET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version);
385
386// Returns appropriate QuicVersion from a QuicTag.
387// Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood.
388NET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag);
389
390// Helper function which translates from a QuicVersion to a string.
391// Returns strings corresponding to enum names (e.g. QUIC_VERSION_6).
392NET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version);
393
394// Returns comma separated list of string representations of QuicVersion enum
[email protected]b007e632013-10-28 08:39:25395// values in the supplied |versions| vector.
396NET_EXPORT_PRIVATE std::string QuicVersionVectorToString(
397 const QuicVersionVector& versions);
[email protected]48878092013-07-26 14:51:56398
399// Version and Crypto tags are written to the wire with a big-endian
400// representation of the name of the tag. For example
401// the client hello tag (CHLO) will be written as the
402// following 4 bytes: 'C' 'H' 'L' 'O'. Since it is
Avi Drissman13fc8932015-12-20 04:40:46403// stored in memory as a little endian uint32_t, we need
[email protected]48878092013-07-26 14:51:56404// to reverse the order of the bytes.
405
406// MakeQuicTag returns a value given the four bytes. For example:
407// MakeQuicTag('C', 'H', 'L', 'O');
408NET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d);
409
[email protected]9cda5fd2014-06-03 10:20:28410// Returns true if the tag vector contains the specified tag.
[email protected]cc1aa272014-06-30 19:48:22411NET_EXPORT_PRIVATE bool ContainsQuicTag(const QuicTagVector& tag_vector,
412 QuicTag tag);
[email protected]9cda5fd2014-06-03 10:20:28413
[email protected]b064310782013-05-30 21:12:17414// Size in bytes of the data or fec packet header.
[email protected]79d13dcb2014-02-05 07:23:13415NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(const QuicPacketHeader& header);
[email protected]b064310782013-05-30 21:12:17416
rtennetia004d332015-08-28 06:44:57417NET_EXPORT_PRIVATE size_t
418GetPacketHeaderSize(QuicConnectionIdLength connection_id_length,
419 bool include_version,
zhongyib8677022015-12-01 05:51:30420 bool include_path_id,
rtennetia004d332015-08-28 06:44:57421 QuicPacketNumberLength packet_number_length,
422 InFecGroup is_in_fec_group);
[email protected]b064310782013-05-30 21:12:17423
[email protected]b064310782013-05-30 21:12:17424// Index of the first byte in a QUIC packet of FEC protected data.
rtennetia004d332015-08-28 06:44:57425NET_EXPORT_PRIVATE size_t
426GetStartOfFecProtectedData(QuicConnectionIdLength connection_id_length,
427 bool include_version,
428 QuicPacketNumberLength packet_number_length);
[email protected]b064310782013-05-30 21:12:17429// Index of the first byte in a QUIC packet of encrypted data.
rtennetia004d332015-08-28 06:44:57430NET_EXPORT_PRIVATE size_t
431GetStartOfEncryptedData(QuicConnectionIdLength connection_id_length,
432 bool include_version,
433 QuicPacketNumberLength packet_number_length);
[email protected]b064310782013-05-30 21:12:17434
[email protected]74bda142013-03-31 02:49:11435enum QuicRstStreamErrorCode {
rch99b644c2015-11-04 05:25:28436 // Complete response has been sent, sending a RST to ask the other endpoint
437 // to stop sending request data without discarding the response.
[email protected]74bda142013-03-31 02:49:11438 QUIC_STREAM_NO_ERROR = 0,
[email protected]8b37a092012-10-18 21:53:49439
[email protected]24e5bc52013-09-18 15:36:58440 // There was some error which halted stream processing.
441 QUIC_ERROR_PROCESSING_STREAM,
[email protected]8b37a092012-10-18 21:53:49442 // We got two fin or reset offsets which did not match.
443 QUIC_MULTIPLE_TERMINATION_OFFSETS,
444 // We got bad payload and can not respond to it at the protocol level.
445 QUIC_BAD_APPLICATION_PAYLOAD,
[email protected]74bda142013-03-31 02:49:11446 // Stream closed due to connection error. No reset frame is sent when this
447 // happens.
448 QUIC_STREAM_CONNECTION_ERROR,
449 // GoAway frame sent. No more stream can be created.
450 QUIC_STREAM_PEER_GOING_AWAY,
[email protected]06ff5152013-08-29 01:03:05451 // The stream has been cancelled.
452 QUIC_STREAM_CANCELLED,
rtenneti4a5df262014-11-07 00:43:58453 // Closing stream locally, sending a RST to allow for proper flow control
454 // accounting. Sent in response to a RST from the peer.
455 QUIC_RST_ACKNOWLEDGEMENT,
rtenneti5ca6eee2015-10-15 21:54:30456 // Receiver refused to create the stream (because its limit on open streams
457 // has been reached). The sender should retry the request later (using
458 // another stream).
459 QUIC_REFUSED_STREAM,
[email protected]8b37a092012-10-18 21:53:49460
[email protected]74bda142013-03-31 02:49:11461 // No error. Used as bound while iterating.
462 QUIC_STREAM_LAST_ERROR,
463};
[email protected]8b37a092012-10-18 21:53:49464
[email protected]51cc1342014-04-18 23:44:37465// Because receiving an unknown QuicRstStreamErrorCode results in connection
466// teardown, we use this to make sure any errors predating a given version are
467// downgraded to the most appropriate existing error.
rjshaded5ced072015-12-18 19:26:02468NET_EXPORT_PRIVATE QuicRstStreamErrorCode
469AdjustErrorForVersion(QuicRstStreamErrorCode error_code, QuicVersion version);
[email protected]51cc1342014-04-18 23:44:37470
[email protected]89264042013-08-21 07:35:24471// These values must remain stable as they are uploaded to UMA histograms.
472// To add a new error code, use the current value of QUIC_LAST_ERROR and
473// increment QUIC_LAST_ERROR.
rtenneti159828f2015-10-13 06:58:09474// last value = 77
[email protected]74bda142013-03-31 02:49:11475enum QuicErrorCode {
476 QUIC_NO_ERROR = 0,
477
478 // Connection has reached an invalid state.
[email protected]89264042013-08-21 07:35:24479 QUIC_INTERNAL_ERROR = 1,
[email protected]74bda142013-03-31 02:49:11480 // There were data frames after the a fin or reset.
[email protected]89264042013-08-21 07:35:24481 QUIC_STREAM_DATA_AFTER_TERMINATION = 2,
[email protected]8b37a092012-10-18 21:53:49482 // Control frame is malformed.
[email protected]89264042013-08-21 07:35:24483 QUIC_INVALID_PACKET_HEADER = 3,
[email protected]be24ab22012-10-22 03:01:52484 // Frame data is malformed.
[email protected]89264042013-08-21 07:35:24485 QUIC_INVALID_FRAME_DATA = 4,
486 // The packet contained no payload.
487 QUIC_MISSING_PAYLOAD = 48,
[email protected]8b37a092012-10-18 21:53:49488 // FEC data is malformed.
[email protected]89264042013-08-21 07:35:24489 QUIC_INVALID_FEC_DATA = 5,
490 // STREAM frame data is malformed.
491 QUIC_INVALID_STREAM_DATA = 46,
[email protected]42a3eba2014-04-30 10:52:55492 // STREAM frame data is not encrypted.
493 QUIC_UNENCRYPTED_STREAM_DATA = 61,
[email protected]89264042013-08-21 07:35:24494 // RST_STREAM frame data is malformed.
495 QUIC_INVALID_RST_STREAM_DATA = 6,
496 // CONNECTION_CLOSE frame data is malformed.
497 QUIC_INVALID_CONNECTION_CLOSE_DATA = 7,
498 // GOAWAY frame data is malformed.
499 QUIC_INVALID_GOAWAY_DATA = 8,
[email protected]6ae6e342014-02-06 02:21:42500 // WINDOW_UPDATE frame data is malformed.
501 QUIC_INVALID_WINDOW_UPDATE_DATA = 57,
502 // BLOCKED frame data is malformed.
503 QUIC_INVALID_BLOCKED_DATA = 58,
[email protected]93dd91f2014-02-27 00:09:03504 // STOP_WAITING frame data is malformed.
505 QUIC_INVALID_STOP_WAITING_DATA = 60,
[email protected]89264042013-08-21 07:35:24506 // ACK frame data is malformed.
507 QUIC_INVALID_ACK_DATA = 9,
rtennetif4bdb542015-01-21 14:33:05508
[email protected]14e8106c2013-03-14 16:25:33509 // Version negotiation packet is malformed.
[email protected]89264042013-08-21 07:35:24510 QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10,
[email protected]899951652013-05-16 12:52:39511 // Public RST packet is malformed.
[email protected]89264042013-08-21 07:35:24512 QUIC_INVALID_PUBLIC_RST_PACKET = 11,
[email protected]8b37a092012-10-18 21:53:49513 // There was an error decrypting.
[email protected]89264042013-08-21 07:35:24514 QUIC_DECRYPTION_FAILURE = 12,
[email protected]8b37a092012-10-18 21:53:49515 // There was an error encrypting.
[email protected]89264042013-08-21 07:35:24516 QUIC_ENCRYPTION_FAILURE = 13,
[email protected]8b37a092012-10-18 21:53:49517 // The packet exceeded kMaxPacketSize.
[email protected]89264042013-08-21 07:35:24518 QUIC_PACKET_TOO_LARGE = 14,
[email protected]9db443912013-02-25 05:27:03519 // The peer is going away. May be a client or server.
[email protected]89264042013-08-21 07:35:24520 QUIC_PEER_GOING_AWAY = 16,
[email protected]8b37a092012-10-18 21:53:49521 // A stream ID was invalid.
[email protected]89264042013-08-21 07:35:24522 QUIC_INVALID_STREAM_ID = 17,
[email protected]24e5bc52013-09-18 15:36:58523 // A priority was invalid.
524 QUIC_INVALID_PRIORITY = 49,
[email protected]8b37a092012-10-18 21:53:49525 // Too many streams already open.
[email protected]89264042013-08-21 07:35:24526 QUIC_TOO_MANY_OPEN_STREAMS = 18,
rtenneti159828f2015-10-13 06:58:09527 // The peer created too many available streams.
528 QUIC_TOO_MANY_AVAILABLE_STREAMS = 76,
[email protected]86a318d2013-01-23 21:16:04529 // Received public reset for this connection.
[email protected]89264042013-08-21 07:35:24530 QUIC_PUBLIC_RESET = 19,
[email protected]c244c5a12013-05-07 20:55:04531 // Invalid protocol version.
[email protected]89264042013-08-21 07:35:24532 QUIC_INVALID_VERSION = 20,
[email protected]92bf17c2014-03-03 21:14:03533
[email protected]c244c5a12013-05-07 20:55:04534 // The Header ID for a stream was too far from the previous.
[email protected]89264042013-08-21 07:35:24535 QUIC_INVALID_HEADER_ID = 22,
[email protected]899951652013-05-16 12:52:39536 // Negotiable parameter received during handshake had invalid value.
[email protected]89264042013-08-21 07:35:24537 QUIC_INVALID_NEGOTIATED_VALUE = 23,
[email protected]899951652013-05-16 12:52:39538 // There was an error decompressing data.
[email protected]89264042013-08-21 07:35:24539 QUIC_DECOMPRESSION_FAILURE = 24,
[email protected]8b37a092012-10-18 21:53:49540 // We hit our prenegotiated (or default) timeout
[email protected]89264042013-08-21 07:35:24541 QUIC_CONNECTION_TIMED_OUT = 25,
rtenneti31e9fd62014-09-16 05:22:15542 // We hit our overall connection timeout
543 QUIC_CONNECTION_OVERALL_TIMED_OUT = 67,
[email protected]899951652013-05-16 12:52:39544 // There was an error encountered migrating addresses
[email protected]89264042013-08-21 07:35:24545 QUIC_ERROR_MIGRATING_ADDRESS = 26,
[email protected]1505a512013-09-04 22:59:35546 // There was an error while writing to the socket.
[email protected]89264042013-08-21 07:35:24547 QUIC_PACKET_WRITE_ERROR = 27,
[email protected]1505a512013-09-04 22:59:35548 // There was an error while reading from the socket.
549 QUIC_PACKET_READ_ERROR = 51,
[email protected]24e5bc52013-09-18 15:36:58550 // We received a STREAM_FRAME with no data and no fin flag set.
551 QUIC_INVALID_STREAM_FRAME = 50,
[email protected]4d640792013-12-18 22:21:08552 // We received invalid data on the headers stream.
553 QUIC_INVALID_HEADERS_STREAM_DATA = 56,
[email protected]730b35d72014-06-05 03:23:22554 // The peer received too much data, violating flow control.
555 QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA = 59,
556 // The peer sent too much data, violating flow control.
557 QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA = 63,
558 // The peer received an invalid flow control window.
559 QUIC_FLOW_CONTROL_INVALID_WINDOW = 64,
[email protected]71c84e592014-05-28 23:39:29560 // The connection has been IP pooled into an existing connection.
561 QUIC_CONNECTION_IP_POOLED = 62,
rtenneti23186682014-10-30 01:49:33562 // The connection has too many outstanding sent packets.
563 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS = 68,
564 // The connection has too many outstanding received packets.
565 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS = 69,
rtenneti14abd312015-02-06 21:56:01566 // The quic connection job to load server config is cancelled.
567 QUIC_CONNECTION_CANCELLED = 70,
rtenneti85dcfac22015-03-27 20:22:19568 // Disabled QUIC because of high packet loss rate.
569 QUIC_BAD_PACKET_LOSS_RATE = 71,
ckrasic1e53b642015-07-08 22:39:35570 // Disabled QUIC because of too many PUBLIC_RESETs post handshake.
571 QUIC_PUBLIC_RESETS_POST_HANDSHAKE = 73,
572 // Disabled QUIC because of too many timeouts with streams open.
573 QUIC_TIMEOUTS_WITH_OPEN_STREAMS = 74,
rtenneti8811fdb2015-07-22 00:17:07574 // Closed because we failed to serialize a packet.
575 QUIC_FAILED_TO_SERIALIZE_PACKET = 75,
[email protected]8b37a092012-10-18 21:53:49576
577 // Crypto errors.
578
[email protected]1354bf62013-05-23 23:17:18579 // Hanshake failed.
[email protected]89264042013-08-21 07:35:24580 QUIC_HANDSHAKE_FAILED = 28,
[email protected]8b37a092012-10-18 21:53:49581 // Handshake message contained out of order tags.
[email protected]89264042013-08-21 07:35:24582 QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29,
[email protected]701bc892013-01-17 04:51:54583 // Handshake message contained too many entries.
[email protected]89264042013-08-21 07:35:24584 QUIC_CRYPTO_TOO_MANY_ENTRIES = 30,
[email protected]8b37a092012-10-18 21:53:49585 // Handshake message contained an invalid value length.
[email protected]89264042013-08-21 07:35:24586 QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31,
[email protected]8b37a092012-10-18 21:53:49587 // A crypto message was received after the handshake was complete.
[email protected]89264042013-08-21 07:35:24588 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32,
[email protected]d3d15bf2013-01-30 02:51:54589 // A crypto message was received with an illegal message tag.
[email protected]89264042013-08-21 07:35:24590 QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33,
[email protected]d3d15bf2013-01-30 02:51:54591 // A crypto message was received with an illegal parameter.
[email protected]89264042013-08-21 07:35:24592 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34,
[email protected]752fbe52013-10-14 08:35:32593 // An invalid channel id signature was supplied.
594 QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52,
[email protected]d3d15bf2013-01-30 02:51:54595 // A crypto message was received with a mandatory parameter missing.
[email protected]89264042013-08-21 07:35:24596 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35,
[email protected]d3d15bf2013-01-30 02:51:54597 // A crypto message was received with a parameter that has no overlap
598 // with the local parameter.
[email protected]89264042013-08-21 07:35:24599 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36,
[email protected]ed3fc15d2013-03-08 18:37:44600 // A crypto message was received that contained a parameter with too few
601 // values.
[email protected]89264042013-08-21 07:35:24602 QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37,
[email protected]ccc66e8a2013-03-26 08:26:14603 // An internal error occured in crypto processing.
[email protected]89264042013-08-21 07:35:24604 QUIC_CRYPTO_INTERNAL_ERROR = 38,
[email protected]ccc66e8a2013-03-26 08:26:14605 // A crypto handshake message specified an unsupported version.
[email protected]89264042013-08-21 07:35:24606 QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39,
rtennetie0ee6eb2015-05-01 00:55:09607 // A crypto handshake message resulted in a stateless reject.
608 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT = 72,
[email protected]ccc66e8a2013-03-26 08:26:14609 // There was no intersection between the crypto primitives supported by the
610 // peer and ourselves.
[email protected]89264042013-08-21 07:35:24611 QUIC_CRYPTO_NO_SUPPORT = 40,
[email protected]ef95114d2013-04-17 17:57:01612 // The server rejected our client hello messages too many times.
[email protected]89264042013-08-21 07:35:24613 QUIC_CRYPTO_TOO_MANY_REJECTS = 41,
[email protected]a57e0272013-04-26 07:31:47614 // The client rejected the server's certificate chain or signature.
[email protected]89264042013-08-21 07:35:24615 QUIC_PROOF_INVALID = 42,
[email protected]8ba81212013-05-03 13:11:48616 // A crypto message was received with a duplicate tag.
[email protected]89264042013-08-21 07:35:24617 QUIC_CRYPTO_DUPLICATE_TAG = 43,
[email protected]2532de12013-05-09 12:29:33618 // A crypto message was received with the wrong encryption level (i.e. it
619 // should have been encrypted but was not.)
[email protected]89264042013-08-21 07:35:24620 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44,
[email protected]2532de12013-05-09 12:29:33621 // The server config for a server has expired.
[email protected]89264042013-08-21 07:35:24622 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45,
[email protected]752fbe52013-10-14 08:35:32623 // We failed to setup the symmetric keys for a connection.
624 QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53,
[email protected]691f45a982013-11-19 10:52:04625 // A handshake message arrived, but we are still validating the
626 // previous handshake message.
627 QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54,
[email protected]ccb34212014-07-18 09:27:50628 // A server config update arrived before the handshake is complete.
629 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE = 65,
[email protected]d89f1862013-11-26 21:21:27630 // This connection involved a version negotiation which appears to have been
631 // tampered with.
632 QUIC_VERSION_NEGOTIATION_MISMATCH = 55,
[email protected]ccc66e8a2013-03-26 08:26:14633
[email protected]74bda142013-03-31 02:49:11634 // No error. Used as bound while iterating.
rtenneti159828f2015-10-13 06:58:09635 QUIC_LAST_ERROR = 77,
[email protected]8b37a092012-10-18 21:53:49636};
637
zhongyi291d0302015-12-14 07:06:25638// Must be updated any time a QuicErrorCode is deprecated.
639const int kDeprecatedQuicErrorCount = 4;
640const int kActiveQuicErrorCount = QUIC_LAST_ERROR - kDeprecatedQuicErrorCount;
641
[email protected]c995c572013-01-18 05:43:20642struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
[email protected]14e8106c2013-03-14 16:25:33643 QuicPacketPublicHeader();
644 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
645 ~QuicPacketPublicHeader();
646
[email protected]3aa9ca72014-02-27 19:39:43647 // Universal header. All QuicPacket headers will have a connection_id and
648 // public flags.
649 QuicConnectionId connection_id;
650 QuicConnectionIdLength connection_id_length;
zhongyib8677022015-12-01 05:51:30651 bool multipath_flag;
[email protected]9db443912013-02-25 05:27:03652 bool reset_flag;
653 bool version_flag;
rtennetia004d332015-08-28 06:44:57654 QuicPacketNumberLength packet_number_length;
[email protected]48878092013-07-26 14:51:56655 QuicVersionVector versions;
[email protected]c995c572013-01-18 05:43:20656};
657
rtennetia004d332015-08-28 06:44:57658// An integer which cannot be a packet number.
659const QuicPacketNumber kInvalidPacketNumber = 0;
rtenneti9e0fb502015-03-08 06:07:16660
[email protected]c995c572013-01-18 05:43:20661// Header for Data or FEC packets.
[email protected]74bda142013-03-31 02:49:11662struct NET_EXPORT_PRIVATE QuicPacketHeader {
663 QuicPacketHeader();
664 explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
[email protected]9db443912013-02-25 05:27:03665
rjshaded5ced072015-12-18 19:26:02666 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
667 const QuicPacketHeader& s);
[email protected]9db443912013-02-25 05:27:03668
[email protected]c995c572013-01-18 05:43:20669 QuicPacketPublicHeader public_header;
zhongyib8677022015-12-01 05:51:30670 QuicPathId path_id;
rtenneti8dd12b22015-10-21 01:26:38671 QuicPacketNumber packet_number;
[email protected]9db443912013-02-25 05:27:03672 bool fec_flag;
[email protected]9db443912013-02-25 05:27:03673 bool entropy_flag;
674 QuicPacketEntropyHash entropy_hash;
[email protected]b064310782013-05-30 21:12:17675 InFecGroup is_in_fec_group;
[email protected]8b37a092012-10-18 21:53:49676 QuicFecGroupNumber fec_group;
677};
678
[email protected]74bda142013-03-31 02:49:11679struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
[email protected]6ae6e342014-02-06 02:21:42680 QuicPublicResetPacket();
681 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header);
682
[email protected]86a318d2013-01-23 21:16:04683 QuicPacketPublicHeader public_header;
[email protected]86a318d2013-01-23 21:16:04684 QuicPublicResetNonceProof nonce_proof;
rtennetia004d332015-08-28 06:44:57685 QuicPacketNumber rejected_packet_number;
[email protected]79d13dcb2014-02-05 07:23:13686 IPEndPoint client_address;
[email protected]86a318d2013-01-23 21:16:04687};
688
[email protected]14e8106c2013-03-14 16:25:33689enum QuicVersionNegotiationState {
690 START_NEGOTIATION = 0,
[email protected]ec640112013-08-09 03:56:18691 // Server-side this implies we've sent a version negotiation packet and are
692 // waiting on the client to select a compatible version. Client-side this
693 // implies we've gotten a version negotiation packet, are retransmitting the
694 // initial packets with a supported version and are waiting for our first
695 // packet from the server.
696 NEGOTIATION_IN_PROGRESS,
697 // This indicates this endpoint has received a packet from the peer with a
698 // version this endpoint supports. Version negotiation is complete, and the
699 // version number will no longer be sent with future packets.
[email protected]14e8106c2013-03-14 16:25:33700 NEGOTIATED_VERSION
701};
702
703typedef QuicPacketPublicHeader QuicVersionNegotiationPacket;
704
[email protected]c995c572013-01-18 05:43:20705// A padding frame contains no payload.
rtenneti5ca6eee2015-10-15 21:54:30706struct NET_EXPORT_PRIVATE QuicPaddingFrame {};
[email protected]c995c572013-01-18 05:43:20707
[email protected]d8c522112014-04-23 09:23:25708// A ping frame contains no payload, though it is retransmittable,
709// and ACK'd just like other normal frames.
rtenneti5ca6eee2015-10-15 21:54:30710struct NET_EXPORT_PRIVATE QuicPingFrame {};
[email protected]d8c522112014-04-23 09:23:25711
rtenneti69e64aa2015-06-26 04:25:30712// A path MTU discovery frame contains no payload and is serialized as a ping
713// frame.
714struct NET_EXPORT_PRIVATE QuicMtuDiscoveryFrame {};
715
zhongyi2f5f40c2015-12-08 02:13:02716// Deleter for stream buffers.
717class NET_EXPORT_PRIVATE StreamBufferDeleter {
718 public:
719 void operator()(char* buf) const;
720};
721
722using UniqueStreamBuffer = std::unique_ptr<char[], StreamBufferDeleter>;
rtennetif60c32d82015-10-14 00:07:00723
724// Allocates memory of size |size| for a QUIC stream buffer.
725UniqueStreamBuffer NewStreamBuffer(size_t size);
726
[email protected]be24ab22012-10-22 03:01:52727struct NET_EXPORT_PRIVATE QuicStreamFrame {
728 QuicStreamFrame();
[email protected]be24ab22012-10-22 03:01:52729 QuicStreamFrame(QuicStreamId stream_id,
[email protected]a5061242012-10-23 23:29:37730 bool fin,
[email protected]701bc892013-01-17 04:51:54731 QuicStreamOffset offset,
rtennetia4228ea2015-06-04 02:31:44732 base::StringPiece data);
zhongyi36727b82015-12-03 00:42:23733 QuicStreamFrame(QuicStreamId stream_id,
734 bool fin,
735 QuicStreamOffset offset,
jokulik2324d282015-12-08 21:42:57736 QuicPacketLength frame_length,
zhongyi36727b82015-12-03 00:42:23737 UniqueStreamBuffer buffer);
738 ~QuicStreamFrame();
[email protected]5dafdb62013-11-14 01:24:26739
rjshaded5ced072015-12-18 19:26:02740 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
741 const QuicStreamFrame& s);
[email protected]c5e1aca2014-01-30 04:03:04742
[email protected]8b37a092012-10-18 21:53:49743 QuicStreamId stream_id;
744 bool fin;
jokulik2324d282015-12-08 21:42:57745 QuicPacketLength frame_length;
746 const char* frame_buffer;
[email protected]701bc892013-01-17 04:51:54747 QuicStreamOffset offset; // Location of this data in the stream.
zhongyi36727b82015-12-03 00:42:23748 // nullptr when the QuicStreamFrame is received, and non-null when sent.
749 UniqueStreamBuffer buffer;
zhongyi4249f9b02015-12-02 20:26:30750
zhongyi36727b82015-12-03 00:42:23751 private:
jokulik2324d282015-12-08 21:42:57752 QuicStreamFrame(QuicStreamId stream_id,
753 bool fin,
754 QuicStreamOffset offset,
755 const char* frame_buffer,
756 QuicPacketLength frame_length,
757 UniqueStreamBuffer buffer);
758
zhongyi36727b82015-12-03 00:42:23759 DISALLOW_COPY_AND_ASSIGN(QuicStreamFrame);
760};
761static_assert(sizeof(QuicStreamFrame) <= 64,
762 "Keep the QuicStreamFrame size to a cacheline.");
[email protected]e537f742012-12-07 15:33:53763// TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
764// is finalized.
rtennetia004d332015-08-28 06:44:57765typedef std::set<QuicPacketNumber> PacketNumberSet;
766typedef std::list<QuicPacketNumber> PacketNumberList;
rtenneti4b06ae72014-08-26 03:43:43767
ckrasicea295fe2015-10-31 05:03:27768typedef std::vector<std::pair<QuicPacketNumber, QuicTime>> PacketTimeVector;
[email protected]044ac2b2012-11-13 21:41:06769
[email protected]310d37b2014-08-02 06:15:37770struct NET_EXPORT_PRIVATE QuicStopWaitingFrame {
771 QuicStopWaitingFrame();
772 ~QuicStopWaitingFrame();
[email protected]6ae6e342014-02-06 02:21:42773
[email protected]26f3f8e2012-12-13 21:07:19774 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:02775 std::ostream& os,
776 const QuicStopWaitingFrame& s);
jri3285d93a2015-12-14 08:53:19777 // Path which this stop waiting frame belongs to.
778 QuicPathId path_id;
[email protected]310d37b2014-08-02 06:15:37779 // Entropy hash of all packets up to, but not including, the least unacked
780 // packet.
781 QuicPacketEntropyHash entropy_hash;
782 // The lowest packet we've sent which is unacked, and we expect an ack for.
rtennetia004d332015-08-28 06:44:57783 QuicPacketNumber least_unacked;
[email protected]310d37b2014-08-02 06:15:37784};
785
rtenneti493d90ef2015-09-14 04:43:11786// A sequence of packet numbers where each number is unique. Intended to be used
787// in a sliding window fashion, where smaller old packet numbers are removed and
788// larger new packet numbers are added, with the occasional random access.
789class NET_EXPORT_PRIVATE PacketNumberQueue {
790 public:
ckrasicea295fe2015-10-31 05:03:27791 // TODO(jdorfman): remove const_iterator and change the callers to
792 // iterate over the intervals.
rtenneti4efd55dd2015-09-18 01:12:04793 class NET_EXPORT_PRIVATE const_iterator
794 : public std::iterator<std::input_iterator_tag,
795 QuicPacketNumber,
796 std::ptrdiff_t,
797 const QuicPacketNumber*,
798 const QuicPacketNumber&> {
799 public:
800 explicit const_iterator(PacketNumberSet::const_iterator set_iter);
801 const_iterator(
802 IntervalSet<QuicPacketNumber>::const_iterator interval_set_iter,
803 QuicPacketNumber first,
804 QuicPacketNumber last);
805 const_iterator(const const_iterator& other);
806 const_iterator& operator=(const const_iterator& other);
807 // TODO(rtenneti): on windows RValue reference gives errors.
808 // const_iterator(const_iterator&& other);
809 ~const_iterator();
810
811 // TODO(rtenneti): on windows RValue reference gives errors.
812 // const_iterator& operator=(const_iterator&& other);
813 bool operator!=(const const_iterator& other) const;
814 bool operator==(const const_iterator& other) const;
815 value_type operator*() const;
816 const_iterator& operator++();
817 const_iterator operator++(int /* postincrement */);
818
819 private:
rtenneti4efd55dd2015-09-18 01:12:04820 IntervalSet<QuicPacketNumber>::const_iterator interval_set_iter_;
821 QuicPacketNumber current_;
822 QuicPacketNumber last_;
823 };
824
rtenneti493d90ef2015-09-14 04:43:11825 PacketNumberQueue();
rtenneti4efd55dd2015-09-18 01:12:04826 PacketNumberQueue(const PacketNumberQueue& other);
rtenneti4efd55dd2015-09-18 01:12:04827 // TODO(rtenneti): on windows RValue reference gives errors.
828 // PacketNumberQueue(PacketNumberQueue&& other);
rtenneti93209a02015-09-19 01:51:18829 ~PacketNumberQueue();
830
831 PacketNumberQueue& operator=(const PacketNumberQueue& other);
rtenneti4efd55dd2015-09-18 01:12:04832 // PacketNumberQueue& operator=(PacketNumberQueue&& other);
rtenneti493d90ef2015-09-14 04:43:11833
834 // Adds |packet_number| to the set of packets in the queue.
835 void Add(QuicPacketNumber packet_number);
836
rtenneti4efd55dd2015-09-18 01:12:04837 // Adds packets between [lower, higher) to the set of packets in the queue. It
838 // is undefined behavior to call this with |higher| < |lower|.
rtenneti493d90ef2015-09-14 04:43:11839 void Add(QuicPacketNumber lower, QuicPacketNumber higher);
840
841 // Removes |packet_number| from the set of packets in the queue.
842 void Remove(QuicPacketNumber packet_number);
843
844 // Removes packets with values less than |higher| from the set of packets in
845 // the queue. Returns true if packets were removed.
846 bool RemoveUpTo(QuicPacketNumber higher);
847
848 // Returns true if the queue contains |packet_number|.
849 bool Contains(QuicPacketNumber packet_number) const;
850
851 // Returns true if the queue is empty.
852 bool Empty() const;
853
854 // Returns the minimum packet number stored in the queue. It is undefined
855 // behavior to call this if the queue is empty.
856 QuicPacketNumber Min() const;
857
858 // Returns the maximum packet number stored in the queue. It is undefined
859 // behavior to call this if the queue is empty.
860 QuicPacketNumber Max() const;
861
rtenneti4efd55dd2015-09-18 01:12:04862 // Returns the number of unique packets stored in the queue. Inefficient; only
863 // exposed for testing.
864 size_t NumPacketsSlow() const;
rtenneti493d90ef2015-09-14 04:43:11865
rtenneti4efd55dd2015-09-18 01:12:04866 // Returns iterators over the individual packet numbers.
867 const_iterator begin() const;
868 const_iterator end() const;
rtenneti493d90ef2015-09-14 04:43:11869 const_iterator lower_bound(QuicPacketNumber packet_number) const;
rtenneti493d90ef2015-09-14 04:43:11870
871 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
872 std::ostream& os,
873 const PacketNumberQueue& q);
874
875 private:
rtenneti4efd55dd2015-09-18 01:12:04876 IntervalSet<QuicPacketNumber> packet_number_intervals_;
rtenneti493d90ef2015-09-14 04:43:11877};
878
[email protected]310d37b2014-08-02 06:15:37879struct NET_EXPORT_PRIVATE QuicAckFrame {
880 QuicAckFrame();
881 ~QuicAckFrame();
882
rjshaded5ced072015-12-18 19:26:02883 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
884 const QuicAckFrame& s);
[email protected]a674b4c2012-12-05 03:44:30885
jri3285d93a2015-12-14 08:53:19886 // Path which this ack belongs to.
887 QuicPathId path_id;
888
[email protected]9db443912013-02-25 05:27:03889 // Entropy hash of all packets up to largest observed not including missing
890 // packets.
891 QuicPacketEntropyHash entropy_hash;
[email protected]e537f742012-12-07 15:33:53892
ckrasicea295fe2015-10-31 05:03:27893 // Whether the ack had to be truncated when sent.
894 bool is_truncated;
895
rtennetia004d332015-08-28 06:44:57896 // The highest packet number we've observed from the peer.
[email protected]48697d8a2013-01-15 19:42:24897 //
898 // In general, this should be the largest packet number we've received. In
899 // the case of truncated acks, we may have to advertise a lower "upper bound"
900 // than largest received, to avoid implicitly acking missing packets that
901 // don't fit in the missing packet list due to size limitations. In this
902 // case, largest_observed may be a packet which is also in the missing packets
903 // list.
rtennetia004d332015-08-28 06:44:57904 QuicPacketNumber largest_observed;
[email protected]a674b4c2012-12-05 03:44:30905
[email protected]14e8106c2013-03-14 16:25:33906 // Time elapsed since largest_observed was received until this Ack frame was
907 // sent.
908 QuicTime::Delta delta_time_largest_observed;
909
ckrasicea295fe2015-10-31 05:03:27910 // Vector of <packet_number, time> for when packets arrived.
911 PacketTimeVector received_packet_times;
912
[email protected]e537f742012-12-07 15:33:53913 // The set of packets which we're expecting and have not received.
rtenneti493d90ef2015-09-14 04:43:11914 PacketNumberQueue missing_packets;
[email protected]8e01c062013-10-31 07:35:31915
rch99b644c2015-11-04 05:25:28916 // Packet most recently revived via FEC, 0 if no packet was revived by FEC.
917 // If non-zero, must be present in missing_packets.
918 QuicPacketNumber latest_revived_packet;
[email protected]8b37a092012-10-18 21:53:49919};
920
rtennetia004d332015-08-28 06:44:57921// True if the packet number is greater than largest_observed or is listed
[email protected]9db443912013-02-25 05:27:03922// as missing.
rtennetia004d332015-08-28 06:44:57923// Always returns false for packet numbers less than least_unacked.
924bool NET_EXPORT_PRIVATE IsAwaitingPacket(const QuicAckFrame& ack_frame,
925 QuicPacketNumber packet_number);
[email protected]9db443912013-02-25 05:27:03926
[email protected]a692ad9d2014-07-18 21:35:24927// Defines for all types of congestion control algorithms that can be used in
928// QUIC. Note that this is separate from the congestion feedback type -
929// some congestion control algorithms may use the same feedback type
930// (Reno and Cubic are the classic example for that).
931enum CongestionControlType {
932 kCubic,
rtennetifb3fa6c2015-03-16 23:04:55933 kCubicBytes,
[email protected]a692ad9d2014-07-18 21:35:24934 kReno,
rtennetifb3fa6c2015-03-16 23:04:55935 kRenoBytes,
[email protected]a692ad9d2014-07-18 21:35:24936 kBBR,
[email protected]8b37a092012-10-18 21:53:49937};
938
[email protected]c5cc9bd2014-03-31 23:17:14939enum LossDetectionType {
940 kNack, // Used to mimic TCP's loss detection.
941 kTime, // Time based loss detection.
942};
943
[email protected]be24ab22012-10-22 03:01:52944struct NET_EXPORT_PRIVATE QuicRstStreamFrame {
[email protected]6ae6e342014-02-06 02:21:42945 QuicRstStreamFrame();
946 QuicRstStreamFrame(QuicStreamId stream_id,
947 QuicRstStreamErrorCode error_code,
948 QuicStreamOffset bytes_written);
[email protected]8b37a092012-10-18 21:53:49949
[email protected]c5e1aca2014-01-30 04:03:04950 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:02951 std::ostream& os,
952 const QuicRstStreamFrame& r);
[email protected]c5e1aca2014-01-30 04:03:04953
[email protected]8b37a092012-10-18 21:53:49954 QuicStreamId stream_id;
[email protected]74bda142013-03-31 02:49:11955 QuicRstStreamErrorCode error_code;
[email protected]6ae6e342014-02-06 02:21:42956
957 // Used to update flow control windows. On termination of a stream, both
958 // endpoints must inform the peer of the number of bytes they have sent on
959 // that stream. This can be done through normal termination (data packet with
960 // FIN) or through a RST.
961 QuicStreamOffset byte_offset;
[email protected]8b37a092012-10-18 21:53:49962};
963
[email protected]be24ab22012-10-22 03:01:52964struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame {
[email protected]6ae6e342014-02-06 02:21:42965 QuicConnectionCloseFrame();
966
[email protected]c5e1aca2014-01-30 04:03:04967 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:02968 std::ostream& os,
969 const QuicConnectionCloseFrame& c);
[email protected]c5e1aca2014-01-30 04:03:04970
[email protected]431bb4fd2012-10-19 17:46:09971 QuicErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09972 std::string error_details;
[email protected]8b37a092012-10-18 21:53:49973};
974
[email protected]9db443912013-02-25 05:27:03975struct NET_EXPORT_PRIVATE QuicGoAwayFrame {
[email protected]6ae6e342014-02-06 02:21:42976 QuicGoAwayFrame();
[email protected]9db443912013-02-25 05:27:03977 QuicGoAwayFrame(QuicErrorCode error_code,
978 QuicStreamId last_good_stream_id,
979 const std::string& reason);
980
rjshaded5ced072015-12-18 19:26:02981 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
982 const QuicGoAwayFrame& g);
[email protected]c5e1aca2014-01-30 04:03:04983
[email protected]9db443912013-02-25 05:27:03984 QuicErrorCode error_code;
985 QuicStreamId last_good_stream_id;
986 std::string reason_phrase;
987};
988
[email protected]6ae6e342014-02-06 02:21:42989// Flow control updates per-stream and at the connection levoel.
990// Based on SPDY's WINDOW_UPDATE frame, but uses an absolute byte offset rather
991// than a window delta.
992// TODO(rjshade): A possible future optimization is to make stream_id and
993// byte_offset variable length, similar to stream frames.
994struct NET_EXPORT_PRIVATE QuicWindowUpdateFrame {
995 QuicWindowUpdateFrame() {}
996 QuicWindowUpdateFrame(QuicStreamId stream_id, QuicStreamOffset byte_offset);
997
998 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:02999 std::ostream& os,
1000 const QuicWindowUpdateFrame& w);
[email protected]6ae6e342014-02-06 02:21:421001
1002 // The stream this frame applies to. 0 is a special case meaning the overall
1003 // connection rather than a specific stream.
1004 QuicStreamId stream_id;
1005
1006 // Byte offset in the stream or connection. The receiver of this frame must
1007 // not send data which would result in this offset being exceeded.
1008 QuicStreamOffset byte_offset;
1009};
1010
1011// The BLOCKED frame is used to indicate to the remote endpoint that this
1012// endpoint believes itself to be flow-control blocked but otherwise ready to
1013// send data. The BLOCKED frame is purely advisory and optional.
1014// Based on SPDY's BLOCKED frame (undocumented as of 2014-01-28).
1015struct NET_EXPORT_PRIVATE QuicBlockedFrame {
1016 QuicBlockedFrame() {}
1017 explicit QuicBlockedFrame(QuicStreamId stream_id);
1018
rjshaded5ced072015-12-18 19:26:021019 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
1020 const QuicBlockedFrame& b);
[email protected]6ae6e342014-02-06 02:21:421021
1022 // The stream this frame applies to. 0 is a special case meaning the overall
1023 // connection rather than a specific stream.
1024 QuicStreamId stream_id;
1025};
1026
[email protected]8ba81212013-05-03 13:11:481027// EncryptionLevel enumerates the stages of encryption that a QUIC connection
1028// progresses through. When retransmitting a packet, the encryption level needs
1029// to be specified so that it is retransmitted at a level which the peer can
1030// understand.
1031enum EncryptionLevel {
1032 ENCRYPTION_NONE = 0,
1033 ENCRYPTION_INITIAL = 1,
1034 ENCRYPTION_FORWARD_SECURE = 2,
1035
1036 NUM_ENCRYPTION_LEVELS,
1037};
1038
rch99b644c2015-11-04 05:25:281039enum PeerAddressChangeType {
1040 NO_CHANGE,
1041 // Peer address changes which are considered to be cause by NATs. Currently,
1042 // IPv4 address change with /24 does not change is considered to be cause by
1043 // NATs.
1044 NAT_PORT_REBINDING,
1045 IPV4_SUBNET_REBINDING,
1046 // IPv6 related address changes.
1047 IPV4_TO_IPV6,
1048 IPV6_TO_IPV4,
1049 IPV6_TO_IPV6,
1050 // This type is used when we always allow peer address changes.
1051 UNKNOWN,
1052 // All other peer address change types.
1053 UNSPECIFIED,
1054};
1055
[email protected]be24ab22012-10-22 03:01:521056struct NET_EXPORT_PRIVATE QuicFrame {
[email protected]6ae6e342014-02-06 02:21:421057 QuicFrame();
rtenneti5ca6eee2015-10-15 21:54:301058 explicit QuicFrame(QuicPaddingFrame padding_frame);
1059 explicit QuicFrame(QuicMtuDiscoveryFrame frame);
1060 explicit QuicFrame(QuicPingFrame frame);
1061
[email protected]6ae6e342014-02-06 02:21:421062 explicit QuicFrame(QuicStreamFrame* stream_frame);
1063 explicit QuicFrame(QuicAckFrame* frame);
[email protected]6ae6e342014-02-06 02:21:421064 explicit QuicFrame(QuicRstStreamFrame* frame);
1065 explicit QuicFrame(QuicConnectionCloseFrame* frame);
[email protected]93dd91f2014-02-27 00:09:031066 explicit QuicFrame(QuicStopWaitingFrame* frame);
[email protected]6ae6e342014-02-06 02:21:421067 explicit QuicFrame(QuicGoAwayFrame* frame);
1068 explicit QuicFrame(QuicWindowUpdateFrame* frame);
1069 explicit QuicFrame(QuicBlockedFrame* frame);
[email protected]8b37a092012-10-18 21:53:491070
rjshaded5ced072015-12-18 19:26:021071 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os,
1072 const QuicFrame& frame);
[email protected]c5e1aca2014-01-30 04:03:041073
[email protected]be24ab22012-10-22 03:01:521074 QuicFrameType type;
[email protected]8b37a092012-10-18 21:53:491075 union {
rtenneti5ca6eee2015-10-15 21:54:301076 // Frames smaller than a pointer are inline.
1077 QuicPaddingFrame padding_frame;
1078 QuicMtuDiscoveryFrame mtu_discovery_frame;
1079 QuicPingFrame ping_frame;
1080
1081 // Frames larger than a pointer.
[email protected]be24ab22012-10-22 03:01:521082 QuicStreamFrame* stream_frame;
1083 QuicAckFrame* ack_frame;
[email protected]93dd91f2014-02-27 00:09:031084 QuicStopWaitingFrame* stop_waiting_frame;
[email protected]be24ab22012-10-22 03:01:521085 QuicRstStreamFrame* rst_stream_frame;
1086 QuicConnectionCloseFrame* connection_close_frame;
[email protected]9db443912013-02-25 05:27:031087 QuicGoAwayFrame* goaway_frame;
[email protected]6ae6e342014-02-06 02:21:421088 QuicWindowUpdateFrame* window_update_frame;
1089 QuicBlockedFrame* blocked_frame;
[email protected]8b37a092012-10-18 21:53:491090 };
1091};
rtenneti5ca6eee2015-10-15 21:54:301092// QuicFrameType consumes 8 bytes with padding.
1093static_assert(sizeof(QuicFrame) <= 16,
1094 "Frames larger than 8 bytes should be referenced by pointer.");
[email protected]8b37a092012-10-18 21:53:491095
[email protected]be24ab22012-10-22 03:01:521096typedef std::vector<QuicFrame> QuicFrames;
[email protected]8b37a092012-10-18 21:53:491097
[email protected]8b37a092012-10-18 21:53:491098class NET_EXPORT_PRIVATE QuicData {
1099 public:
[email protected]6ae6e342014-02-06 02:21:421100 QuicData(const char* buffer, size_t length);
1101 QuicData(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:491102 virtual ~QuicData();
1103
1104 base::StringPiece AsStringPiece() const {
1105 return base::StringPiece(data(), length());
1106 }
1107
1108 const char* data() const { return buffer_; }
1109 size_t length() const { return length_; }
rtennetie0ee6eb2015-05-01 00:55:091110 bool owns_buffer() const { return owns_buffer_; }
[email protected]8b37a092012-10-18 21:53:491111
1112 private:
1113 const char* buffer_;
1114 size_t length_;
1115 bool owns_buffer_;
1116
1117 DISALLOW_COPY_AND_ASSIGN(QuicData);
1118};
1119
1120class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
1121 public:
rtennetica5ac272015-02-07 12:35:121122 QuicPacket(char* buffer,
1123 size_t length,
1124 bool owns_buffer,
1125 QuicConnectionIdLength connection_id_length,
1126 bool includes_version,
rtennetia004d332015-08-28 06:44:571127 QuicPacketNumberLength packet_number_length);
[email protected]8b37a092012-10-18 21:53:491128
[email protected]5351cc4b2013-03-03 07:22:411129 base::StringPiece FecProtectedData() const;
1130 base::StringPiece AssociatedData() const;
[email protected]5351cc4b2013-03-03 07:22:411131 base::StringPiece Plaintext() const;
[email protected]082b65b2012-11-10 19:11:311132
[email protected]8b37a092012-10-18 21:53:491133 char* mutable_data() { return buffer_; }
1134
1135 private:
1136 char* buffer_;
[email protected]3aa9ca72014-02-27 19:39:431137 const QuicConnectionIdLength connection_id_length_;
[email protected]5351cc4b2013-03-03 07:22:411138 const bool includes_version_;
rtennetia004d332015-08-28 06:44:571139 const QuicPacketNumberLength packet_number_length_;
[email protected]8b37a092012-10-18 21:53:491140
[email protected]2e740db2012-10-20 19:35:191141 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
[email protected]8b37a092012-10-18 21:53:491142};
1143
1144class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
1145 public:
[email protected]6ae6e342014-02-06 02:21:421146 QuicEncryptedPacket(const char* buffer, size_t length);
1147 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:491148
[email protected]ec86d5462013-11-17 16:04:491149 // Clones the packet into a new packet which owns the buffer.
1150 QuicEncryptedPacket* Clone() const;
1151
[email protected]c1b32c62013-01-20 02:49:101152 // By default, gtest prints the raw bytes of an object. The bool data
1153 // member (in the base class QuicData) causes this object to have padding
1154 // bytes, which causes the default gtest object printer to read
1155 // uninitialize memory. So we need to teach gtest how to print this object.
1156 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
rjshaded5ced072015-12-18 19:26:021157 std::ostream& os,
1158 const QuicEncryptedPacket& s);
[email protected]c1b32c62013-01-20 02:49:101159
[email protected]2e740db2012-10-20 19:35:191160 private:
1161 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
[email protected]8b37a092012-10-18 21:53:491162};
1163
[email protected]9db443912013-02-25 05:27:031164class NET_EXPORT_PRIVATE RetransmittableFrames {
1165 public:
jokulik2324d282015-12-08 21:42:571166 RetransmittableFrames();
[email protected]9db443912013-02-25 05:27:031167 ~RetransmittableFrames();
1168
[email protected]9db443912013-02-25 05:27:031169 // Takes ownership of the frame inside |frame|.
rtennetia4228ea2015-06-04 02:31:441170 const QuicFrame& AddFrame(const QuicFrame& frame);
rtenneti73e25c12015-03-16 06:12:431171 // Removes all stream frames associated with |stream_id|.
1172 void RemoveFramesForStream(QuicStreamId stream_id);
1173
[email protected]9db443912013-02-25 05:27:031174 const QuicFrames& frames() const { return frames_; }
1175
rjshaded5ced072015-12-18 19:26:021176 IsHandshake HasCryptoHandshake() const { return has_crypto_handshake_; }
[email protected]2115d33ba2014-01-02 21:53:521177
rtennetid7d78b02015-06-17 16:54:341178 bool needs_padding() const { return needs_padding_; }
1179
1180 void set_needs_padding(bool needs_padding) { needs_padding_ = needs_padding; }
1181
[email protected]9db443912013-02-25 05:27:031182 private:
1183 QuicFrames frames_;
[email protected]672631c2014-08-16 06:11:451184 IsHandshake has_crypto_handshake_;
rtennetid7d78b02015-06-17 16:54:341185 bool needs_padding_;
[email protected]9db443912013-02-25 05:27:031186
1187 DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames);
1188};
1189
rtenneti8dd12b22015-10-21 01:26:381190struct NET_EXPORT_PRIVATE AckListenerWrapper {
1191 AckListenerWrapper(QuicAckListenerInterface* listener,
1192 QuicPacketLength data_length);
1193 ~AckListenerWrapper();
1194
1195 scoped_refptr<QuicAckListenerInterface> ack_listener;
1196 QuicPacketLength length;
1197};
1198
[email protected]9db443912013-02-25 05:27:031199struct NET_EXPORT_PRIVATE SerializedPacket {
rtennetia004d332015-08-28 06:44:571200 SerializedPacket(QuicPacketNumber packet_number,
1201 QuicPacketNumberLength packet_number_length,
rtennetib6ac61a52015-02-11 20:20:521202 QuicEncryptedPacket* packet,
[email protected]9db443912013-02-25 05:27:031203 QuicPacketEntropyHash entropy_hash,
rtenneti9bd5d4b2015-08-21 05:44:521204 RetransmittableFrames* retransmittable_frames,
1205 bool has_ack,
1206 bool has_stop_waiting);
rch99b644c2015-11-04 05:25:281207 SerializedPacket(QuicPacketNumber packet_number,
1208 QuicPacketNumberLength packet_number_length,
1209 char* encrypted_buffer,
1210 size_t encrypted_length,
1211 bool owns_buffer,
1212 QuicPacketEntropyHash entropy_hash,
1213 RetransmittableFrames* retransmittable_frames,
1214 bool has_ack,
jokulik2324d282015-12-08 21:42:571215 bool has_stop_waiting,
1216 EncryptionLevel level);
[email protected]97cf3022013-09-05 14:30:161217 ~SerializedPacket();
[email protected]9db443912013-02-25 05:27:031218
rtennetid39bd762015-06-12 01:05:521219 QuicEncryptedPacket* packet;
1220 RetransmittableFrames* retransmittable_frames;
rtennetia004d332015-08-28 06:44:571221 QuicPacketNumber packet_number;
1222 QuicPacketNumberLength packet_number_length;
jokulik2324d282015-12-08 21:42:571223 EncryptionLevel encryption_level;
[email protected]9db443912013-02-25 05:27:031224 QuicPacketEntropyHash entropy_hash;
rtennetica5ac272015-02-07 12:35:121225 bool is_fec_packet;
rtenneti9bd5d4b2015-08-21 05:44:521226 bool has_ack;
1227 bool has_stop_waiting;
[email protected]97cf3022013-09-05 14:30:161228
rtenneti6b1c5b12015-01-13 20:08:351229 // Optional notifiers which will be informed when this packet has been ACKed.
rtenneti8dd12b22015-10-21 01:26:381230 std::list<AckListenerWrapper> listeners;
[email protected]9db443912013-02-25 05:27:031231};
1232
[email protected]77b5d50b2014-05-07 22:48:481233struct NET_EXPORT_PRIVATE TransmissionInfo {
1234 // Used by STL when assigning into a map.
1235 TransmissionInfo();
1236
1237 // Constructs a Transmission with a new all_tranmissions set
rtennetia004d332015-08-28 06:44:571238 // containing |packet_number|.
[email protected]77b5d50b2014-05-07 22:48:481239 TransmissionInfo(RetransmittableFrames* retransmittable_frames,
jokulik2324d282015-12-08 21:42:571240 EncryptionLevel level,
rtennetia004d332015-08-28 06:44:571241 QuicPacketNumberLength packet_number_length,
[email protected]730b35d72014-06-05 03:23:221242 TransmissionType transmission_type,
rtenneti3183ac42015-02-28 03:39:411243 QuicTime sent_time,
rtenneti5ca6eee2015-10-15 21:54:301244 QuicPacketLength bytes_sent,
rtenneti3183ac42015-02-28 03:39:411245 bool is_fec_packet);
[email protected]77b5d50b2014-05-07 22:48:481246
rtenneti8dd12b22015-10-21 01:26:381247 ~TransmissionInfo();
1248
[email protected]77b5d50b2014-05-07 22:48:481249 RetransmittableFrames* retransmittable_frames;
jokulik2324d282015-12-08 21:42:571250 EncryptionLevel encryption_level;
rtennetia004d332015-08-28 06:44:571251 QuicPacketNumberLength packet_number_length;
rtenneti5ca6eee2015-10-15 21:54:301252 QuicPacketLength bytes_sent;
Avi Drissman13fc8932015-12-20 04:40:461253 uint16_t nack_count;
[email protected]77b5d50b2014-05-07 22:48:481254 QuicTime sent_time;
[email protected]730b35d72014-06-05 03:23:221255 // Reason why this packet was transmitted.
1256 TransmissionType transmission_type;
[email protected]aa7e4ef2014-05-28 03:53:151257 // In flight packets have not been abandoned or lost.
1258 bool in_flight;
rtenneti31e9fd62014-09-16 05:22:151259 // True if the packet can never be acked, so it can be removed.
1260 bool is_unackable;
rtenneti85d89712014-11-20 03:32:241261 // True if the packet is an FEC packet.
1262 bool is_fec_packet;
rtenneti5ca6eee2015-10-15 21:54:301263 // Stores the packet numbers of all transmissions of this packet.
1264 // Must always be nullptr or have multiple elements.
zhongyi1fb9bc52015-11-24 23:09:421265 // TODO(ianswett): Deprecate with quic_track_single_retransmission.
rtenneti5ca6eee2015-10-15 21:54:301266 PacketNumberList* all_transmissions;
zhongyi1fb9bc52015-11-24 23:09:421267 // Stores the packet number of the next retransmission of this packet.
1268 // Zero if the packet has not been retransmitted.
1269 QuicPacketNumber retransmission;
rtenneti8dd12b22015-10-21 01:26:381270 // Non-empty if there is a listener for this packet.
1271 std::list<AckListenerWrapper> ack_listeners;
[email protected]77b5d50b2014-05-07 22:48:481272};
rtenneti8dd12b22015-10-21 01:26:381273static_assert(sizeof(QuicFrame) <= 64,
1274 "Keep the TransmissionInfo size to a cacheline.");
[email protected]77b5d50b2014-05-07 22:48:481275
rtennetic14c8ab2015-06-18 05:47:401276// Convenience wrapper to wrap an iovec array and the total length, which must
1277// be less than or equal to the actual total length of the iovecs.
1278struct NET_EXPORT_PRIVATE QuicIOVector {
1279 QuicIOVector(const struct iovec* iov, int iov_count, size_t total_length)
1280 : iov(iov), iov_count(iov_count), total_length(total_length) {}
1281
1282 const struct iovec* iov;
1283 const int iov_count;
1284 const size_t total_length;
1285};
1286
[email protected]8b37a092012-10-18 21:53:491287} // namespace net
1288
1289#endif // NET_QUIC_QUIC_PROTOCOL_H_