blob: 100a663cff4779b5058c9c85cd14465afb93df76 [file] [log] [blame]
[email protected]8b37a092012-10-18 21:53:491// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_QUIC_QUIC_PROTOCOL_H_
6#define NET_QUIC_QUIC_PROTOCOL_H_
7
[email protected]e537f742012-12-07 15:33:538#include <stddef.h>
tfarina3723da22015-06-03 21:39:309#include <stdint.h>
[email protected]8b37a092012-10-18 21:53:4910#include <limits>
rtenneti4b06ae72014-08-26 03:43:4311#include <list>
[email protected]a674b4c2012-12-05 03:44:3012#include <map>
[email protected]5640d0a2012-10-22 18:17:0213#include <ostream>
[email protected]e537f742012-12-07 15:33:5314#include <set>
15#include <string>
[email protected]8b37a092012-10-18 21:53:4916#include <utility>
17#include <vector>
18
19#include "base/basictypes.h"
[email protected]14c1c232013-06-11 17:52:4420#include "base/containers/hash_tables.h"
[email protected]8b37a092012-10-18 21:53:4921#include "base/logging.h"
rtenneti8dd12b22015-10-21 01:26:3822#include "base/memory/ref_counted.h"
rtennetif60c32d82015-10-14 00:07:0023#include "base/memory/scoped_ptr.h"
[email protected]d069c11a2013-04-13 00:01:5524#include "base/strings/string_piece.h"
[email protected]165e0752012-11-16 07:49:4425#include "net/base/int128.h"
rtennetic14c8ab2015-06-18 05:47:4026#include "net/base/iovec.h"
[email protected]79d13dcb2014-02-05 07:23:1327#include "net/base/ip_endpoint.h"
[email protected]8b37a092012-10-18 21:53:4928#include "net/base/net_export.h"
rtenneti4efd55dd2015-09-18 01:12:0429#include "net/quic/interval_set.h"
rtenneti8dd12b22015-10-21 01:26:3830#include "net/quic/quic_ack_listener_interface.h"
[email protected]fee17f72013-02-03 07:47:4131#include "net/quic/quic_bandwidth.h"
[email protected]2a960e02012-11-11 14:48:1032#include "net/quic/quic_time.h"
rtennetic14c8ab2015-06-18 05:47:4033#include "net/quic/quic_types.h"
[email protected]8b37a092012-10-18 21:53:4934
35namespace net {
36
[email protected]8b37a092012-10-18 21:53:4937class QuicPacket;
[email protected]b064310782013-05-30 21:12:1738struct QuicPacketHeader;
[email protected]8b37a092012-10-18 21:53:4939
[email protected]3aa9ca72014-02-27 19:39:4340typedef uint64 QuicConnectionId;
[email protected]8b37a092012-10-18 21:53:4941typedef uint32 QuicStreamId;
42typedef uint64 QuicStreamOffset;
rtennetia004d332015-08-28 06:44:5743typedef uint64 QuicPacketNumber;
rjshadec86dbfa2015-11-12 20:16:2544typedef uint8 QuicPathId;
rtennetia004d332015-08-28 06:44:5745typedef QuicPacketNumber QuicFecGroupNumber;
[email protected]86a318d2013-01-23 21:16:0446typedef uint64 QuicPublicResetNonceProof;
[email protected]9db443912013-02-25 05:27:0347typedef uint8 QuicPacketEntropyHash;
[email protected]c244c5a12013-05-07 20:55:0448typedef uint32 QuicHeaderId;
[email protected]2532de12013-05-09 12:29:3349// QuicTag is the type of a tag in the wire protocol.
50typedef uint32 QuicTag;
51typedef std::vector<QuicTag> QuicTagVector;
[email protected]79d13dcb2014-02-05 07:23:1352typedef std::map<QuicTag, std::string> QuicTagValueMap;
rtenneti5ca6eee2015-10-15 21:54:3053typedef uint16 QuicPacketLength;
[email protected]cff7b7b2013-01-11 08:49:0754
rtennetibb2780c2015-07-22 19:16:0855// Default initial maximum size in bytes of a QUIC packet.
[email protected]310d37b2014-08-02 06:15:3756const QuicByteCount kDefaultMaxPacketSize = 1350;
rtenneti16a20772015-02-17 18:58:4857// Default initial maximum size in bytes of a QUIC packet for servers.
58const QuicByteCount kDefaultServerMaxPacketSize = 1000;
[email protected]8e01c062013-10-31 07:35:3159// The maximum packet size of any QUIC packet, based on ethernet's max size,
[email protected]41fb6372013-12-10 05:26:4060// minus the IP and UDP headers. IPv6 has a 40 byte header, UPD adds an
61// additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's
62// max packet size is 1500 bytes, 1500 - 48 = 1452.
63const QuicByteCount kMaxPacketSize = 1452;
rtenneti9e0fb502015-03-08 06:07:1664// Default maximum packet size used in the Linux TCP implementation.
65// Used in QUIC for congestion window computations in bytes.
[email protected]ce7bb1412014-05-17 15:51:3366const QuicByteCount kDefaultTCPMSS = 1460;
[email protected]8e01c062013-10-31 07:35:3167
rch1fe2eeb2015-10-26 14:45:5768// We match SPDY's use of 32 (since we'd compete with SPDY).
69const QuicPacketCount kInitialCongestionWindow = 32;
[email protected]8e01c062013-10-31 07:35:3170
rtenneti7652bf32015-01-05 18:51:0771// Minimum size of initial flow control window, for both stream and session.
72const uint32 kMinimumFlowControlSendWindow = 16 * 1024; // 16 KB
[email protected]9bb57c72014-03-31 20:36:0473
rjshadec86dbfa2015-11-12 20:16:2574// Maximum flow control receive window limits for connection and stream.
75const QuicByteCount kStreamReceiveWindowLimit = 16 * 1024 * 1024; // 16 MB
76const QuicByteCount kSessionReceiveWindowLimit = 24 * 1024 * 1024; // 24 MB
77
rtennetifb3fa6c2015-03-16 23:04:5578// Minimum size of the CWND, in packets, when doing bandwidth resumption.
rtenneti8d2a808d2014-11-26 01:10:0979const QuicPacketCount kMinCongestionWindowForBandwidthResumption = 10;
80
rtenneti581b6ae82015-07-20 20:48:0181// Maximum size of the CWND, in packets.
82const QuicPacketCount kMaxCongestionWindow = 200;
rtenneti69e64aa2015-06-26 04:25:3083
84// Maximum number of tracked packets.
85const QuicPacketCount kMaxTrackedPackets = 5000;
[email protected]0ac0c5b2013-11-20 05:55:5886
rtenneti23186682014-10-30 01:49:3387// Default size of the socket receive buffer in bytes.
[email protected]648f81142014-08-15 21:38:4688const QuicByteCount kDefaultSocketReceiveBuffer = 256 * 1024;
rtenneti23186682014-10-30 01:49:3389// Minimum size of the socket receive buffer in bytes.
90// Smaller values are ignored.
91const QuicByteCount kMinSocketReceiveBuffer = 16 * 1024;
[email protected]a97b3182014-08-08 08:10:1892
rtenneti95293802015-03-27 18:59:2393// Fraction of the receive buffer that can be used for encrypted bytes.
94// Allows a 5% overhead for IP and UDP framing, as well as ack only packets.
95static const float kUsableRecieveBufferFraction = 0.95f;
rtenneti581b6ae82015-07-20 20:48:0196// Fraction of the receive buffer that can be used, based on conservative
97// estimates and testing on Linux.
98// An alternative to kUsableRecieveBufferFraction.
99static const float kConservativeReceiveBufferFraction = 0.6f;
rtenneti95293802015-03-27 18:59:23100
rtennetifc97ab62014-11-11 22:17:49101// Don't allow a client to suggest an RTT shorter than 10ms.
102const uint32 kMinInitialRoundTripTimeUs = 10 * kNumMicrosPerMilli;
103
[email protected]8e01c062013-10-31 07:35:31104// Don't allow a client to suggest an RTT longer than 15 seconds.
[email protected]2d43c40122014-04-21 14:51:27105const uint32 kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond;
[email protected]8b37a092012-10-18 21:53:49106
107// Maximum number of open streams per connection.
108const size_t kDefaultMaxStreamsPerConnection = 100;
109
[email protected]af806e62013-05-22 14:47:50110// Number of bytes reserved for public flags in the packet header.
111const size_t kPublicFlagsSize = 1;
[email protected]5351cc4b2013-03-03 07:22:41112// Number of bytes reserved for version number in the packet header.
113const size_t kQuicVersionSize = 4;
zhongyib8677022015-12-01 05:51:30114// Number of bytes reserved for path id in the packet header.
115const size_t kQuicPathIdSize = 1;
[email protected]c995c572013-01-18 05:43:20116// Number of bytes reserved for private flags in the packet header.
117const size_t kPrivateFlagsSize = 1;
118// Number of bytes reserved for FEC group in the packet header.
119const size_t kFecGroupSize = 1;
[email protected]5351cc4b2013-03-03 07:22:41120
121// Signifies that the QuicPacket will contain version of the protocol.
122const bool kIncludeVersion = true;
zhongyib8677022015-12-01 05:51:30123// Signifies that the QuicPacket will contain path id.
124const bool kIncludePathId = true;
[email protected]c995c572013-01-18 05:43:20125
[email protected]5351cc4b2013-03-03 07:22:41126// Index of the first byte in a QUIC packet which is used in hash calculation.
127const size_t kStartOfHashData = 0;
[email protected]8b37a092012-10-18 21:53:49128
[email protected]8b37a092012-10-18 21:53:49129// Reserved ID for the crypto stream.
[email protected]8b37a092012-10-18 21:53:49130const QuicStreamId kCryptoStreamId = 1;
131
[email protected]4d640792013-12-18 22:21:08132// Reserved ID for the headers stream.
133const QuicStreamId kHeadersStreamId = 3;
134
[email protected]648f81142014-08-15 21:38:46135// Maximum delayed ack time, in ms.
pkastingacec86f2014-10-14 23:08:55136const int64 kMaxDelayedAckTimeMs = 25;
[email protected]648f81142014-08-15 21:38:46137
rtennetib5512bb2014-09-29 19:17:15138// The timeout before the handshake succeeds.
139const int64 kInitialIdleTimeoutSecs = 5;
140// The default idle timeout.
141const int64 kDefaultIdleTimeoutSecs = 30;
rtenneti31e9fd62014-09-16 05:22:15142// The maximum idle timeout that can be negotiated.
143const int64 kMaximumIdleTimeoutSecs = 60 * 10; // 10 minutes.
144// The default timeout for a connection until the crypto handshake succeeds.
rtennetib5512bb2014-09-29 19:17:15145const int64 kMaxTimeForCryptoHandshakeSecs = 10; // 10 secs.
[email protected]8b37a092012-10-18 21:53:49146
rtenneti93bce7ece2014-10-13 22:38:41147// Default limit on the number of undecryptable packets the connection buffers
148// before the CHLO/SHLO arrive.
149const size_t kDefaultMaxUndecryptablePackets = 10;
150
[email protected]525948df2014-04-21 06:26:58151// Default ping timeout.
152const int64 kPingTimeoutSecs = 15; // 15 secs.
153
[email protected]ca4e0d92014-08-22 16:33:22154// Minimum number of RTTs between Server Config Updates (SCUP) sent to client.
155const int kMinIntervalBetweenServerConfigUpdatesRTTs = 10;
156
157// Minimum time between Server Config Updates (SCUP) sent to client.
158const int kMinIntervalBetweenServerConfigUpdatesMs = 1000;
159
rtenneti33da8ab2014-11-04 04:17:00160// Minimum number of packets between Server Config Updates (SCUP).
161const int kMinPacketsBetweenServerConfigUpdates = 100;
162
rtennetib5512bb2014-09-29 19:17:15163// The number of open streams that a server will accept is set to be slightly
164// larger than the negotiated limit. Immediately closing the connection if the
165// client opens slightly too many streams is not ideal: the client may have sent
166// a FIN that was lost, and simultaneously opened a new stream. The number of
167// streams a server accepts is a fixed increment over the negotiated limit, or a
168// percentage increase, whichever is larger.
rtenneti31e9fd62014-09-16 05:22:15169const float kMaxStreamsMultiplier = 1.1f;
rtennetib5512bb2014-09-29 19:17:15170const int kMaxStreamsMinimumIncrement = 10;
rtenneti31e9fd62014-09-16 05:22:15171
rtenneti159828f2015-10-13 06:58:09172// Available streams are ones with IDs less than the highest stream that has
173// been opened which have neither been opened or reset. The limit on the number
174// of available streams is 10 times the limit on the number of open streams.
175const int kMaxAvailableStreamsMultiplier = 10;
176
[email protected]b007e632013-10-28 08:39:25177// We define an unsigned 16-bit floating point value, inspired by IEEE floats
178// (http://en.wikipedia.org/wiki/Half_precision_floating-point_format),
179// with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden
180// bit) and denormals, but without signs, transfinites or fractions. Wire format
181// 16 bits (little-endian byte order) are split into exponent (high 5) and
182// mantissa (low 11) and decoded as:
183// uint64 value;
184// if (exponent == 0) value = mantissa;
185// else value = (mantissa | 1 << 11) << (exponent - 1)
186const int kUFloat16ExponentBits = 5;
187const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30
188const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11
189const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12
190const uint64 kUFloat16MaxValue = // 0x3FFC0000000
tfarina3723da22015-06-03 21:39:30191 ((UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1) <<
[email protected]b007e632013-10-28 08:39:25192 kUFloat16MaxExponent;
193
[email protected]c67a82cb2013-09-24 02:53:21194enum TransmissionType {
[email protected]2532de12013-05-09 12:29:33195 NOT_RETRANSMISSION,
[email protected]b9475b582014-03-20 20:04:33196 FIRST_TRANSMISSION_TYPE = NOT_RETRANSMISSION,
197 HANDSHAKE_RETRANSMISSION, // Retransmits due to handshake timeouts.
rtenneti31e9fd62014-09-16 05:22:15198 ALL_UNACKED_RETRANSMISSION, // Retransmits all unacked packets.
199 ALL_INITIAL_RETRANSMISSION, // Retransmits all initially encrypted packets.
[email protected]b9475b582014-03-20 20:04:33200 LOSS_RETRANSMISSION, // Retransmits due to loss detection.
201 RTO_RETRANSMISSION, // Retransmits due to retransmit time out.
202 TLP_RETRANSMISSION, // Tail loss probes.
203 LAST_TRANSMISSION_TYPE = TLP_RETRANSMISSION,
[email protected]74bda142013-03-31 02:49:11204};
205
206enum HasRetransmittableData {
[email protected]2532de12013-05-09 12:29:33207 NO_RETRANSMITTABLE_DATA,
208 HAS_RETRANSMITTABLE_DATA,
[email protected]74bda142013-03-31 02:49:11209};
210
[email protected]575cce62013-08-03 02:06:43211enum IsHandshake {
212 NOT_HANDSHAKE,
213 IS_HANDSHAKE
214};
215
rtenneti6f48aa92015-03-16 02:18:48216enum class Perspective { IS_SERVER, IS_CLIENT };
217
218NET_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
219 const Perspective& s);
220
[email protected]bbb10072014-06-13 07:41:59221// Indicates FEC protection level for data being written.
222enum FecProtection {
223 MUST_FEC_PROTECT, // Callee must FEC protect this data.
[email protected]a5b98172014-06-18 07:01:59224 MAY_FEC_PROTECT // Callee does not have to but may FEC protect this data.
225};
226
[email protected]bc356fe2014-06-19 11:14:14227// Indicates FEC policy.
[email protected]a5b98172014-06-18 07:01:59228enum FecPolicy {
229 FEC_PROTECT_ALWAYS, // All data in the stream should be FEC protected.
230 FEC_PROTECT_OPTIONAL // Data in the stream does not need FEC protection.
[email protected]bbb10072014-06-13 07:41:59231};
232
rtennetia4228ea2015-06-04 02:31:44233// Indicates FEC policy about when to send FEC packet.
234enum FecSendPolicy {
235 // Send FEC packet when FEC group is full or when FEC alarm goes off.
236 FEC_ANY_TRIGGER,
237 // Send FEC packet only when FEC alarm goes off.
238 FEC_ALARM_TRIGGER
239};
240
[email protected]be24ab22012-10-22 03:01:52241enum QuicFrameType {
[email protected]6ae6e342014-02-06 02:21:42242 // Regular frame types. The values set here cannot change without the
243 // introduction of a new QUIC version.
[email protected]c995c572013-01-18 05:43:20244 PADDING_FRAME = 0,
[email protected]6ae6e342014-02-06 02:21:42245 RST_STREAM_FRAME = 1,
246 CONNECTION_CLOSE_FRAME = 2,
247 GOAWAY_FRAME = 3,
248 WINDOW_UPDATE_FRAME = 4,
249 BLOCKED_FRAME = 5,
[email protected]93dd91f2014-02-27 00:09:03250 STOP_WAITING_FRAME = 6,
[email protected]d8c522112014-04-23 09:23:25251 PING_FRAME = 7,
[email protected]6ae6e342014-02-06 02:21:42252
rtennetif4bdb542015-01-21 14:33:05253 // STREAM and ACK frames are special frames. They are encoded differently on
254 // the wire and their values do not need to be stable.
[email protected]97cf3022013-09-05 14:30:16255 STREAM_FRAME,
256 ACK_FRAME,
rtenneti69e64aa2015-06-26 04:25:30257 // The path MTU discovery frame is encoded as a PING frame on the wire.
258 MTU_DISCOVERY_FRAME,
[email protected]be24ab22012-10-22 03:01:52259 NUM_FRAME_TYPES
[email protected]8b37a092012-10-18 21:53:49260};
261
[email protected]3aa9ca72014-02-27 19:39:43262enum QuicConnectionIdLength {
263 PACKET_0BYTE_CONNECTION_ID = 0,
264 PACKET_1BYTE_CONNECTION_ID = 1,
265 PACKET_4BYTE_CONNECTION_ID = 4,
266 PACKET_8BYTE_CONNECTION_ID = 8
[email protected]b064310782013-05-30 21:12:17267};
268
269enum InFecGroup {
270 NOT_IN_FEC_GROUP,
271 IN_FEC_GROUP,
272};
273
rtennetia004d332015-08-28 06:44:57274enum QuicPacketNumberLength {
275 PACKET_1BYTE_PACKET_NUMBER = 1,
276 PACKET_2BYTE_PACKET_NUMBER = 2,
277 PACKET_4BYTE_PACKET_NUMBER = 4,
278 PACKET_6BYTE_PACKET_NUMBER = 6
[email protected]25c31dc2013-06-05 17:56:04279};
280
[email protected]8e01c062013-10-31 07:35:31281// Used to indicate a QuicSequenceNumberLength using two flag bits.
rtennetia004d332015-08-28 06:44:57282enum QuicPacketNumberLengthFlags {
283 PACKET_FLAGS_1BYTE_PACKET = 0, // 00
284 PACKET_FLAGS_2BYTE_PACKET = 1, // 01
285 PACKET_FLAGS_4BYTE_PACKET = 1 << 1, // 10
286 PACKET_FLAGS_6BYTE_PACKET = 1 << 1 | 1, // 11
[email protected]8e01c062013-10-31 07:35:31287};
288
[email protected]f62262b2013-07-05 20:57:30289// The public flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20290enum QuicPacketPublicFlags {
291 PACKET_PUBLIC_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30292
293 // Bit 0: Does the packet header contains version info?
294 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0,
295
296 // Bit 1: Is this packet a public reset packet?
297 PACKET_PUBLIC_FLAGS_RST = 1 << 1,
298
[email protected]3aa9ca72014-02-27 19:39:43299 // Bits 2 and 3 specify the length of the ConnectionId as follows:
[email protected]f62262b2013-07-05 20:57:30300 // ----00--: 0 bytes
301 // ----01--: 1 byte
302 // ----10--: 4 bytes
303 // ----11--: 8 bytes
[email protected]3aa9ca72014-02-27 19:39:43304 PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID = 0,
305 PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID = 1 << 2,
306 PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID = 1 << 3,
307 PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID = 1 << 3 | 1 << 2,
[email protected]f62262b2013-07-05 20:57:30308
rtennetia004d332015-08-28 06:44:57309 // Bits 4 and 5 describe the packet number length as follows:
[email protected]f62262b2013-07-05 20:57:30310 // --00----: 1 byte
311 // --01----: 2 bytes
312 // --10----: 4 bytes
313 // --11----: 6 bytes
rtennetia004d332015-08-28 06:44:57314 PACKET_PUBLIC_FLAGS_1BYTE_PACKET = PACKET_FLAGS_1BYTE_PACKET << 4,
315 PACKET_PUBLIC_FLAGS_2BYTE_PACKET = PACKET_FLAGS_2BYTE_PACKET << 4,
316 PACKET_PUBLIC_FLAGS_4BYTE_PACKET = PACKET_FLAGS_4BYTE_PACKET << 4,
317 PACKET_PUBLIC_FLAGS_6BYTE_PACKET = PACKET_FLAGS_6BYTE_PACKET << 4,
[email protected]f62262b2013-07-05 20:57:30318
zhongyib8677022015-12-01 05:51:30319 // Bit 6: Does the packet header contain a path id?
320 PACKET_PUBLIC_FLAGS_MULTIPATH = 1 << 6,
321
322 // All bits set (bit7 are not currently used): 01111111
323 PACKET_PUBLIC_FLAGS_MAX = (1 << 7) - 1,
[email protected]c995c572013-01-18 05:43:20324};
[email protected]8b37a092012-10-18 21:53:49325
[email protected]f62262b2013-07-05 20:57:30326// The private flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20327enum QuicPacketPrivateFlags {
328 PACKET_PRIVATE_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30329
330 // Bit 0: Does this packet contain an entropy bit?
[email protected]b064310782013-05-30 21:12:17331 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0,
[email protected]f62262b2013-07-05 20:57:30332
333 // Bit 1: Payload is part of an FEC group?
334 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1,
335
336 // Bit 2: Payload is FEC as opposed to frames?
337 PACKET_PRIVATE_FLAGS_FEC = 1 << 2,
338
339 // All bits set (bits 3-7 are not currently used): 00000111
340 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1
[email protected]c995c572013-01-18 05:43:20341};
342
[email protected]48878092013-07-26 14:51:56343// The available versions of QUIC. Guaranteed that the integer value of the enum
344// will match the version number.
345// When adding a new version to this enum you should add it to
[email protected]8bbfaeb72013-08-09 06:38:26346// kSupportedQuicVersions (if appropriate), and also add a new case to the
347// helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and
348// QuicVersionToString.
[email protected]48878092013-07-26 14:51:56349enum QuicVersion {
350 // Special case to indicate unknown/unsupported QUIC version.
351 QUIC_VERSION_UNSUPPORTED = 0,
352
rchc0815442015-04-18 13:29:46353 QUIC_VERSION_25 = 25, // SPDY/4 header keys, and removal of error_details
354 // from QuicRstStreamFrame
zhongyic92bc492015-09-22 19:14:36355 QUIC_VERSION_26 = 26, // In CHLO, send XLCT tag containing hash of leaf cert
rtenneti159828f2015-10-13 06:58:09356 QUIC_VERSION_27 = 27, // Sends a nonce in the SHLO.
rtenneti5ca6eee2015-10-15 21:54:30357 QUIC_VERSION_28 = 28, // Receiver can refuse to create a requested stream.
rch99b644c2015-11-04 05:25:28358 QUIC_VERSION_29 = 29, // Server and client honor QUIC_STREAM_NO_ERROR.
359 QUIC_VERSION_30 = 30, // Add server side support of cert transparency.
[email protected]48878092013-07-26 14:51:56360};
361
362// This vector contains QUIC versions which we currently support.
363// This should be ordered such that the highest supported version is the first
364// element, with subsequent elements in descending order (versions can be
365// skipped as necessary).
[email protected]31ae854842013-11-27 00:05:46366//
[email protected]310d37b2014-08-02 06:15:37367// IMPORTANT: if you are adding to this list, follow the instructions at
[email protected]31ae854842013-11-27 00:05:46368// http://sites/quic/adding-and-removing-versions
zhongyic92bc492015-09-22 19:14:36369static const QuicVersion kSupportedQuicVersions[] = {
rch99b644c2015-11-04 05:25:28370 QUIC_VERSION_30, QUIC_VERSION_29, QUIC_VERSION_28,
371 QUIC_VERSION_27, QUIC_VERSION_26, QUIC_VERSION_25};
[email protected]48878092013-07-26 14:51:56372
373typedef std::vector<QuicVersion> QuicVersionVector;
374
[email protected]b007e632013-10-28 08:39:25375// Returns a vector of QUIC versions in kSupportedQuicVersions.
376NET_EXPORT_PRIVATE QuicVersionVector QuicSupportedVersions();
[email protected]ea2ab47b2013-08-13 00:44:11377
[email protected]48878092013-07-26 14:51:56378// QuicTag is written to and read from the wire, but we prefer to use
379// the more readable QuicVersion at other levels.
380// Helper function which translates from a QuicVersion to a QuicTag. Returns 0
381// if QuicVersion is unsupported.
382NET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version);
383
384// Returns appropriate QuicVersion from a QuicTag.
385// Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood.
386NET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag);
387
388// Helper function which translates from a QuicVersion to a string.
389// Returns strings corresponding to enum names (e.g. QUIC_VERSION_6).
390NET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version);
391
392// Returns comma separated list of string representations of QuicVersion enum
[email protected]b007e632013-10-28 08:39:25393// values in the supplied |versions| vector.
394NET_EXPORT_PRIVATE std::string QuicVersionVectorToString(
395 const QuicVersionVector& versions);
[email protected]48878092013-07-26 14:51:56396
397// Version and Crypto tags are written to the wire with a big-endian
398// representation of the name of the tag. For example
399// the client hello tag (CHLO) will be written as the
400// following 4 bytes: 'C' 'H' 'L' 'O'. Since it is
401// stored in memory as a little endian uint32, we need
402// to reverse the order of the bytes.
403
404// MakeQuicTag returns a value given the four bytes. For example:
405// MakeQuicTag('C', 'H', 'L', 'O');
406NET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d);
407
[email protected]9cda5fd2014-06-03 10:20:28408// Returns true if the tag vector contains the specified tag.
[email protected]cc1aa272014-06-30 19:48:22409NET_EXPORT_PRIVATE bool ContainsQuicTag(const QuicTagVector& tag_vector,
410 QuicTag tag);
[email protected]9cda5fd2014-06-03 10:20:28411
[email protected]b064310782013-05-30 21:12:17412// Size in bytes of the data or fec packet header.
[email protected]79d13dcb2014-02-05 07:23:13413NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(const QuicPacketHeader& header);
[email protected]b064310782013-05-30 21:12:17414
rtennetia004d332015-08-28 06:44:57415NET_EXPORT_PRIVATE size_t
416GetPacketHeaderSize(QuicConnectionIdLength connection_id_length,
417 bool include_version,
zhongyib8677022015-12-01 05:51:30418 bool include_path_id,
rtennetia004d332015-08-28 06:44:57419 QuicPacketNumberLength packet_number_length,
420 InFecGroup is_in_fec_group);
[email protected]b064310782013-05-30 21:12:17421
[email protected]b064310782013-05-30 21:12:17422// Index of the first byte in a QUIC packet of FEC protected data.
rtennetia004d332015-08-28 06:44:57423NET_EXPORT_PRIVATE size_t
424GetStartOfFecProtectedData(QuicConnectionIdLength connection_id_length,
425 bool include_version,
426 QuicPacketNumberLength packet_number_length);
[email protected]b064310782013-05-30 21:12:17427// Index of the first byte in a QUIC packet of encrypted data.
rtennetia004d332015-08-28 06:44:57428NET_EXPORT_PRIVATE size_t
429GetStartOfEncryptedData(QuicConnectionIdLength connection_id_length,
430 bool include_version,
431 QuicPacketNumberLength packet_number_length);
[email protected]b064310782013-05-30 21:12:17432
[email protected]74bda142013-03-31 02:49:11433enum QuicRstStreamErrorCode {
rch99b644c2015-11-04 05:25:28434 // Complete response has been sent, sending a RST to ask the other endpoint
435 // to stop sending request data without discarding the response.
[email protected]74bda142013-03-31 02:49:11436 QUIC_STREAM_NO_ERROR = 0,
[email protected]8b37a092012-10-18 21:53:49437
[email protected]24e5bc52013-09-18 15:36:58438 // There was some error which halted stream processing.
439 QUIC_ERROR_PROCESSING_STREAM,
[email protected]8b37a092012-10-18 21:53:49440 // We got two fin or reset offsets which did not match.
441 QUIC_MULTIPLE_TERMINATION_OFFSETS,
442 // We got bad payload and can not respond to it at the protocol level.
443 QUIC_BAD_APPLICATION_PAYLOAD,
[email protected]74bda142013-03-31 02:49:11444 // Stream closed due to connection error. No reset frame is sent when this
445 // happens.
446 QUIC_STREAM_CONNECTION_ERROR,
447 // GoAway frame sent. No more stream can be created.
448 QUIC_STREAM_PEER_GOING_AWAY,
[email protected]06ff5152013-08-29 01:03:05449 // The stream has been cancelled.
450 QUIC_STREAM_CANCELLED,
rtenneti4a5df262014-11-07 00:43:58451 // Closing stream locally, sending a RST to allow for proper flow control
452 // accounting. Sent in response to a RST from the peer.
453 QUIC_RST_ACKNOWLEDGEMENT,
rtenneti5ca6eee2015-10-15 21:54:30454 // Receiver refused to create the stream (because its limit on open streams
455 // has been reached). The sender should retry the request later (using
456 // another stream).
457 QUIC_REFUSED_STREAM,
[email protected]8b37a092012-10-18 21:53:49458
[email protected]74bda142013-03-31 02:49:11459 // No error. Used as bound while iterating.
460 QUIC_STREAM_LAST_ERROR,
461};
[email protected]8b37a092012-10-18 21:53:49462
[email protected]51cc1342014-04-18 23:44:37463// Because receiving an unknown QuicRstStreamErrorCode results in connection
464// teardown, we use this to make sure any errors predating a given version are
465// downgraded to the most appropriate existing error.
466NET_EXPORT_PRIVATE QuicRstStreamErrorCode AdjustErrorForVersion(
467 QuicRstStreamErrorCode error_code,
468 QuicVersion version);
469
[email protected]89264042013-08-21 07:35:24470// These values must remain stable as they are uploaded to UMA histograms.
471// To add a new error code, use the current value of QUIC_LAST_ERROR and
472// increment QUIC_LAST_ERROR.
rtenneti159828f2015-10-13 06:58:09473// last value = 77
[email protected]74bda142013-03-31 02:49:11474enum QuicErrorCode {
475 QUIC_NO_ERROR = 0,
476
477 // Connection has reached an invalid state.
[email protected]89264042013-08-21 07:35:24478 QUIC_INTERNAL_ERROR = 1,
[email protected]74bda142013-03-31 02:49:11479 // There were data frames after the a fin or reset.
[email protected]89264042013-08-21 07:35:24480 QUIC_STREAM_DATA_AFTER_TERMINATION = 2,
[email protected]8b37a092012-10-18 21:53:49481 // Control frame is malformed.
[email protected]89264042013-08-21 07:35:24482 QUIC_INVALID_PACKET_HEADER = 3,
[email protected]be24ab22012-10-22 03:01:52483 // Frame data is malformed.
[email protected]89264042013-08-21 07:35:24484 QUIC_INVALID_FRAME_DATA = 4,
485 // The packet contained no payload.
486 QUIC_MISSING_PAYLOAD = 48,
[email protected]8b37a092012-10-18 21:53:49487 // FEC data is malformed.
[email protected]89264042013-08-21 07:35:24488 QUIC_INVALID_FEC_DATA = 5,
489 // STREAM frame data is malformed.
490 QUIC_INVALID_STREAM_DATA = 46,
[email protected]42a3eba2014-04-30 10:52:55491 // STREAM frame data is not encrypted.
492 QUIC_UNENCRYPTED_STREAM_DATA = 61,
[email protected]89264042013-08-21 07:35:24493 // RST_STREAM frame data is malformed.
494 QUIC_INVALID_RST_STREAM_DATA = 6,
495 // CONNECTION_CLOSE frame data is malformed.
496 QUIC_INVALID_CONNECTION_CLOSE_DATA = 7,
497 // GOAWAY frame data is malformed.
498 QUIC_INVALID_GOAWAY_DATA = 8,
[email protected]6ae6e342014-02-06 02:21:42499 // WINDOW_UPDATE frame data is malformed.
500 QUIC_INVALID_WINDOW_UPDATE_DATA = 57,
501 // BLOCKED frame data is malformed.
502 QUIC_INVALID_BLOCKED_DATA = 58,
[email protected]93dd91f2014-02-27 00:09:03503 // STOP_WAITING frame data is malformed.
504 QUIC_INVALID_STOP_WAITING_DATA = 60,
[email protected]89264042013-08-21 07:35:24505 // ACK frame data is malformed.
506 QUIC_INVALID_ACK_DATA = 9,
rtennetif4bdb542015-01-21 14:33:05507
[email protected]14e8106c2013-03-14 16:25:33508 // Version negotiation packet is malformed.
[email protected]89264042013-08-21 07:35:24509 QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10,
[email protected]899951652013-05-16 12:52:39510 // Public RST packet is malformed.
[email protected]89264042013-08-21 07:35:24511 QUIC_INVALID_PUBLIC_RST_PACKET = 11,
[email protected]8b37a092012-10-18 21:53:49512 // There was an error decrypting.
[email protected]89264042013-08-21 07:35:24513 QUIC_DECRYPTION_FAILURE = 12,
[email protected]8b37a092012-10-18 21:53:49514 // There was an error encrypting.
[email protected]89264042013-08-21 07:35:24515 QUIC_ENCRYPTION_FAILURE = 13,
[email protected]8b37a092012-10-18 21:53:49516 // The packet exceeded kMaxPacketSize.
[email protected]89264042013-08-21 07:35:24517 QUIC_PACKET_TOO_LARGE = 14,
[email protected]9db443912013-02-25 05:27:03518 // The peer is going away. May be a client or server.
[email protected]89264042013-08-21 07:35:24519 QUIC_PEER_GOING_AWAY = 16,
[email protected]8b37a092012-10-18 21:53:49520 // A stream ID was invalid.
[email protected]89264042013-08-21 07:35:24521 QUIC_INVALID_STREAM_ID = 17,
[email protected]24e5bc52013-09-18 15:36:58522 // A priority was invalid.
523 QUIC_INVALID_PRIORITY = 49,
[email protected]8b37a092012-10-18 21:53:49524 // Too many streams already open.
[email protected]89264042013-08-21 07:35:24525 QUIC_TOO_MANY_OPEN_STREAMS = 18,
rtenneti159828f2015-10-13 06:58:09526 // The peer created too many available streams.
527 QUIC_TOO_MANY_AVAILABLE_STREAMS = 76,
[email protected]86a318d2013-01-23 21:16:04528 // Received public reset for this connection.
[email protected]89264042013-08-21 07:35:24529 QUIC_PUBLIC_RESET = 19,
[email protected]c244c5a12013-05-07 20:55:04530 // Invalid protocol version.
[email protected]89264042013-08-21 07:35:24531 QUIC_INVALID_VERSION = 20,
[email protected]92bf17c2014-03-03 21:14:03532
[email protected]c244c5a12013-05-07 20:55:04533 // The Header ID for a stream was too far from the previous.
[email protected]89264042013-08-21 07:35:24534 QUIC_INVALID_HEADER_ID = 22,
[email protected]899951652013-05-16 12:52:39535 // Negotiable parameter received during handshake had invalid value.
[email protected]89264042013-08-21 07:35:24536 QUIC_INVALID_NEGOTIATED_VALUE = 23,
[email protected]899951652013-05-16 12:52:39537 // There was an error decompressing data.
[email protected]89264042013-08-21 07:35:24538 QUIC_DECOMPRESSION_FAILURE = 24,
[email protected]8b37a092012-10-18 21:53:49539 // We hit our prenegotiated (or default) timeout
[email protected]89264042013-08-21 07:35:24540 QUIC_CONNECTION_TIMED_OUT = 25,
rtenneti31e9fd62014-09-16 05:22:15541 // We hit our overall connection timeout
542 QUIC_CONNECTION_OVERALL_TIMED_OUT = 67,
[email protected]899951652013-05-16 12:52:39543 // There was an error encountered migrating addresses
[email protected]89264042013-08-21 07:35:24544 QUIC_ERROR_MIGRATING_ADDRESS = 26,
[email protected]1505a512013-09-04 22:59:35545 // There was an error while writing to the socket.
[email protected]89264042013-08-21 07:35:24546 QUIC_PACKET_WRITE_ERROR = 27,
[email protected]1505a512013-09-04 22:59:35547 // There was an error while reading from the socket.
548 QUIC_PACKET_READ_ERROR = 51,
[email protected]24e5bc52013-09-18 15:36:58549 // We received a STREAM_FRAME with no data and no fin flag set.
550 QUIC_INVALID_STREAM_FRAME = 50,
[email protected]4d640792013-12-18 22:21:08551 // We received invalid data on the headers stream.
552 QUIC_INVALID_HEADERS_STREAM_DATA = 56,
[email protected]730b35d72014-06-05 03:23:22553 // The peer received too much data, violating flow control.
554 QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA = 59,
555 // The peer sent too much data, violating flow control.
556 QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA = 63,
557 // The peer received an invalid flow control window.
558 QUIC_FLOW_CONTROL_INVALID_WINDOW = 64,
[email protected]71c84e592014-05-28 23:39:29559 // The connection has been IP pooled into an existing connection.
560 QUIC_CONNECTION_IP_POOLED = 62,
rtenneti23186682014-10-30 01:49:33561 // The connection has too many outstanding sent packets.
562 QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS = 68,
563 // The connection has too many outstanding received packets.
564 QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS = 69,
rtenneti14abd312015-02-06 21:56:01565 // The quic connection job to load server config is cancelled.
566 QUIC_CONNECTION_CANCELLED = 70,
rtenneti85dcfac22015-03-27 20:22:19567 // Disabled QUIC because of high packet loss rate.
568 QUIC_BAD_PACKET_LOSS_RATE = 71,
ckrasic1e53b642015-07-08 22:39:35569 // Disabled QUIC because of too many PUBLIC_RESETs post handshake.
570 QUIC_PUBLIC_RESETS_POST_HANDSHAKE = 73,
571 // Disabled QUIC because of too many timeouts with streams open.
572 QUIC_TIMEOUTS_WITH_OPEN_STREAMS = 74,
rtenneti8811fdb2015-07-22 00:17:07573 // Closed because we failed to serialize a packet.
574 QUIC_FAILED_TO_SERIALIZE_PACKET = 75,
[email protected]8b37a092012-10-18 21:53:49575
576 // Crypto errors.
577
[email protected]1354bf62013-05-23 23:17:18578 // Hanshake failed.
[email protected]89264042013-08-21 07:35:24579 QUIC_HANDSHAKE_FAILED = 28,
[email protected]8b37a092012-10-18 21:53:49580 // Handshake message contained out of order tags.
[email protected]89264042013-08-21 07:35:24581 QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29,
[email protected]701bc892013-01-17 04:51:54582 // Handshake message contained too many entries.
[email protected]89264042013-08-21 07:35:24583 QUIC_CRYPTO_TOO_MANY_ENTRIES = 30,
[email protected]8b37a092012-10-18 21:53:49584 // Handshake message contained an invalid value length.
[email protected]89264042013-08-21 07:35:24585 QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31,
[email protected]8b37a092012-10-18 21:53:49586 // A crypto message was received after the handshake was complete.
[email protected]89264042013-08-21 07:35:24587 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32,
[email protected]d3d15bf2013-01-30 02:51:54588 // A crypto message was received with an illegal message tag.
[email protected]89264042013-08-21 07:35:24589 QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33,
[email protected]d3d15bf2013-01-30 02:51:54590 // A crypto message was received with an illegal parameter.
[email protected]89264042013-08-21 07:35:24591 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34,
[email protected]752fbe52013-10-14 08:35:32592 // An invalid channel id signature was supplied.
593 QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52,
[email protected]d3d15bf2013-01-30 02:51:54594 // A crypto message was received with a mandatory parameter missing.
[email protected]89264042013-08-21 07:35:24595 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35,
[email protected]d3d15bf2013-01-30 02:51:54596 // A crypto message was received with a parameter that has no overlap
597 // with the local parameter.
[email protected]89264042013-08-21 07:35:24598 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36,
[email protected]ed3fc15d2013-03-08 18:37:44599 // A crypto message was received that contained a parameter with too few
600 // values.
[email protected]89264042013-08-21 07:35:24601 QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37,
[email protected]ccc66e8a2013-03-26 08:26:14602 // An internal error occured in crypto processing.
[email protected]89264042013-08-21 07:35:24603 QUIC_CRYPTO_INTERNAL_ERROR = 38,
[email protected]ccc66e8a2013-03-26 08:26:14604 // A crypto handshake message specified an unsupported version.
[email protected]89264042013-08-21 07:35:24605 QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39,
rtennetie0ee6eb2015-05-01 00:55:09606 // A crypto handshake message resulted in a stateless reject.
607 QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT = 72,
[email protected]ccc66e8a2013-03-26 08:26:14608 // There was no intersection between the crypto primitives supported by the
609 // peer and ourselves.
[email protected]89264042013-08-21 07:35:24610 QUIC_CRYPTO_NO_SUPPORT = 40,
[email protected]ef95114d2013-04-17 17:57:01611 // The server rejected our client hello messages too many times.
[email protected]89264042013-08-21 07:35:24612 QUIC_CRYPTO_TOO_MANY_REJECTS = 41,
[email protected]a57e0272013-04-26 07:31:47613 // The client rejected the server's certificate chain or signature.
[email protected]89264042013-08-21 07:35:24614 QUIC_PROOF_INVALID = 42,
[email protected]8ba81212013-05-03 13:11:48615 // A crypto message was received with a duplicate tag.
[email protected]89264042013-08-21 07:35:24616 QUIC_CRYPTO_DUPLICATE_TAG = 43,
[email protected]2532de12013-05-09 12:29:33617 // A crypto message was received with the wrong encryption level (i.e. it
618 // should have been encrypted but was not.)
[email protected]89264042013-08-21 07:35:24619 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44,
[email protected]2532de12013-05-09 12:29:33620 // The server config for a server has expired.
[email protected]89264042013-08-21 07:35:24621 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45,
[email protected]752fbe52013-10-14 08:35:32622 // We failed to setup the symmetric keys for a connection.
623 QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53,
[email protected]691f45a982013-11-19 10:52:04624 // A handshake message arrived, but we are still validating the
625 // previous handshake message.
626 QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54,
[email protected]ccb34212014-07-18 09:27:50627 // A server config update arrived before the handshake is complete.
628 QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE = 65,
[email protected]d89f1862013-11-26 21:21:27629 // This connection involved a version negotiation which appears to have been
630 // tampered with.
631 QUIC_VERSION_NEGOTIATION_MISMATCH = 55,
[email protected]ccc66e8a2013-03-26 08:26:14632
[email protected]74bda142013-03-31 02:49:11633 // No error. Used as bound while iterating.
rtenneti159828f2015-10-13 06:58:09634 QUIC_LAST_ERROR = 77,
[email protected]8b37a092012-10-18 21:53:49635};
636
[email protected]c995c572013-01-18 05:43:20637struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
[email protected]14e8106c2013-03-14 16:25:33638 QuicPacketPublicHeader();
639 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
640 ~QuicPacketPublicHeader();
641
[email protected]3aa9ca72014-02-27 19:39:43642 // Universal header. All QuicPacket headers will have a connection_id and
643 // public flags.
644 QuicConnectionId connection_id;
645 QuicConnectionIdLength connection_id_length;
zhongyib8677022015-12-01 05:51:30646 bool multipath_flag;
[email protected]9db443912013-02-25 05:27:03647 bool reset_flag;
648 bool version_flag;
rtennetia004d332015-08-28 06:44:57649 QuicPacketNumberLength packet_number_length;
[email protected]48878092013-07-26 14:51:56650 QuicVersionVector versions;
[email protected]c995c572013-01-18 05:43:20651};
652
rtennetia004d332015-08-28 06:44:57653// An integer which cannot be a packet number.
654const QuicPacketNumber kInvalidPacketNumber = 0;
rtenneti9e0fb502015-03-08 06:07:16655
[email protected]c995c572013-01-18 05:43:20656// Header for Data or FEC packets.
[email protected]74bda142013-03-31 02:49:11657struct NET_EXPORT_PRIVATE QuicPacketHeader {
658 QuicPacketHeader();
659 explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
[email protected]9db443912013-02-25 05:27:03660
661 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
662 std::ostream& os, const QuicPacketHeader& s);
663
[email protected]c995c572013-01-18 05:43:20664 QuicPacketPublicHeader public_header;
zhongyib8677022015-12-01 05:51:30665 QuicPathId path_id;
rtenneti8dd12b22015-10-21 01:26:38666 QuicPacketNumber packet_number;
[email protected]9db443912013-02-25 05:27:03667 bool fec_flag;
[email protected]9db443912013-02-25 05:27:03668 bool entropy_flag;
669 QuicPacketEntropyHash entropy_hash;
[email protected]b064310782013-05-30 21:12:17670 InFecGroup is_in_fec_group;
[email protected]8b37a092012-10-18 21:53:49671 QuicFecGroupNumber fec_group;
672};
673
[email protected]74bda142013-03-31 02:49:11674struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
[email protected]6ae6e342014-02-06 02:21:42675 QuicPublicResetPacket();
676 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header);
677
[email protected]86a318d2013-01-23 21:16:04678 QuicPacketPublicHeader public_header;
[email protected]86a318d2013-01-23 21:16:04679 QuicPublicResetNonceProof nonce_proof;
rtennetia004d332015-08-28 06:44:57680 QuicPacketNumber rejected_packet_number;
[email protected]79d13dcb2014-02-05 07:23:13681 IPEndPoint client_address;
[email protected]86a318d2013-01-23 21:16:04682};
683
[email protected]14e8106c2013-03-14 16:25:33684enum QuicVersionNegotiationState {
685 START_NEGOTIATION = 0,
[email protected]ec640112013-08-09 03:56:18686 // Server-side this implies we've sent a version negotiation packet and are
687 // waiting on the client to select a compatible version. Client-side this
688 // implies we've gotten a version negotiation packet, are retransmitting the
689 // initial packets with a supported version and are waiting for our first
690 // packet from the server.
691 NEGOTIATION_IN_PROGRESS,
692 // This indicates this endpoint has received a packet from the peer with a
693 // version this endpoint supports. Version negotiation is complete, and the
694 // version number will no longer be sent with future packets.
[email protected]14e8106c2013-03-14 16:25:33695 NEGOTIATED_VERSION
696};
697
698typedef QuicPacketPublicHeader QuicVersionNegotiationPacket;
699
[email protected]c995c572013-01-18 05:43:20700// A padding frame contains no payload.
rtenneti5ca6eee2015-10-15 21:54:30701struct NET_EXPORT_PRIVATE QuicPaddingFrame {};
[email protected]c995c572013-01-18 05:43:20702
[email protected]d8c522112014-04-23 09:23:25703// A ping frame contains no payload, though it is retransmittable,
704// and ACK'd just like other normal frames.
rtenneti5ca6eee2015-10-15 21:54:30705struct NET_EXPORT_PRIVATE QuicPingFrame {};
[email protected]d8c522112014-04-23 09:23:25706
rtenneti69e64aa2015-06-26 04:25:30707// A path MTU discovery frame contains no payload and is serialized as a ping
708// frame.
709struct NET_EXPORT_PRIVATE QuicMtuDiscoveryFrame {};
710
rtennetif60c32d82015-10-14 00:07:00711typedef scoped_ptr<char[]> UniqueStreamBuffer;
712
713// Allocates memory of size |size| for a QUIC stream buffer.
714UniqueStreamBuffer NewStreamBuffer(size_t size);
715
[email protected]be24ab22012-10-22 03:01:52716struct NET_EXPORT_PRIVATE QuicStreamFrame {
717 QuicStreamFrame();
[email protected]5dafdb62013-11-14 01:24:26718 QuicStreamFrame(const QuicStreamFrame& frame);
[email protected]be24ab22012-10-22 03:01:52719 QuicStreamFrame(QuicStreamId stream_id,
[email protected]a5061242012-10-23 23:29:37720 bool fin,
[email protected]701bc892013-01-17 04:51:54721 QuicStreamOffset offset,
rtennetia4228ea2015-06-04 02:31:44722 base::StringPiece data);
[email protected]5dafdb62013-11-14 01:24:26723
[email protected]c5e1aca2014-01-30 04:03:04724 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
725 std::ostream& os, const QuicStreamFrame& s);
726
[email protected]8b37a092012-10-18 21:53:49727 QuicStreamId stream_id;
728 bool fin;
[email protected]701bc892013-01-17 04:51:54729 QuicStreamOffset offset; // Location of this data in the stream.
rtennetia4228ea2015-06-04 02:31:44730 base::StringPiece data;
[email protected]8b37a092012-10-18 21:53:49731};
732
[email protected]e537f742012-12-07 15:33:53733// TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
734// is finalized.
rtennetia004d332015-08-28 06:44:57735typedef std::set<QuicPacketNumber> PacketNumberSet;
736typedef std::list<QuicPacketNumber> PacketNumberList;
rtenneti4b06ae72014-08-26 03:43:43737
ckrasicea295fe2015-10-31 05:03:27738typedef std::vector<std::pair<QuicPacketNumber, QuicTime>> PacketTimeVector;
[email protected]044ac2b2012-11-13 21:41:06739
[email protected]310d37b2014-08-02 06:15:37740struct NET_EXPORT_PRIVATE QuicStopWaitingFrame {
741 QuicStopWaitingFrame();
742 ~QuicStopWaitingFrame();
[email protected]6ae6e342014-02-06 02:21:42743
[email protected]26f3f8e2012-12-13 21:07:19744 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
[email protected]310d37b2014-08-02 06:15:37745 std::ostream& os, const QuicStopWaitingFrame& s);
746 // Entropy hash of all packets up to, but not including, the least unacked
747 // packet.
748 QuicPacketEntropyHash entropy_hash;
749 // The lowest packet we've sent which is unacked, and we expect an ack for.
rtennetia004d332015-08-28 06:44:57750 QuicPacketNumber least_unacked;
[email protected]310d37b2014-08-02 06:15:37751};
752
rtenneti493d90ef2015-09-14 04:43:11753// A sequence of packet numbers where each number is unique. Intended to be used
754// in a sliding window fashion, where smaller old packet numbers are removed and
755// larger new packet numbers are added, with the occasional random access.
756class NET_EXPORT_PRIVATE PacketNumberQueue {
757 public:
ckrasicea295fe2015-10-31 05:03:27758 // TODO(jdorfman): remove const_iterator and change the callers to
759 // iterate over the intervals.
rtenneti4efd55dd2015-09-18 01:12:04760 class NET_EXPORT_PRIVATE const_iterator
761 : public std::iterator<std::input_iterator_tag,
762 QuicPacketNumber,
763 std::ptrdiff_t,
764 const QuicPacketNumber*,
765 const QuicPacketNumber&> {
766 public:
767 explicit const_iterator(PacketNumberSet::const_iterator set_iter);
768 const_iterator(
769 IntervalSet<QuicPacketNumber>::const_iterator interval_set_iter,
770 QuicPacketNumber first,
771 QuicPacketNumber last);
772 const_iterator(const const_iterator& other);
773 const_iterator& operator=(const const_iterator& other);
774 // TODO(rtenneti): on windows RValue reference gives errors.
775 // const_iterator(const_iterator&& other);
776 ~const_iterator();
777
778 // TODO(rtenneti): on windows RValue reference gives errors.
779 // const_iterator& operator=(const_iterator&& other);
780 bool operator!=(const const_iterator& other) const;
781 bool operator==(const const_iterator& other) const;
782 value_type operator*() const;
783 const_iterator& operator++();
784 const_iterator operator++(int /* postincrement */);
785
786 private:
rtenneti4efd55dd2015-09-18 01:12:04787 IntervalSet<QuicPacketNumber>::const_iterator interval_set_iter_;
788 QuicPacketNumber current_;
789 QuicPacketNumber last_;
790 };
791
rtenneti493d90ef2015-09-14 04:43:11792 PacketNumberQueue();
rtenneti4efd55dd2015-09-18 01:12:04793 PacketNumberQueue(const PacketNumberQueue& other);
rtenneti4efd55dd2015-09-18 01:12:04794 // TODO(rtenneti): on windows RValue reference gives errors.
795 // PacketNumberQueue(PacketNumberQueue&& other);
rtenneti93209a02015-09-19 01:51:18796 ~PacketNumberQueue();
797
798 PacketNumberQueue& operator=(const PacketNumberQueue& other);
rtenneti4efd55dd2015-09-18 01:12:04799 // PacketNumberQueue& operator=(PacketNumberQueue&& other);
rtenneti493d90ef2015-09-14 04:43:11800
801 // Adds |packet_number| to the set of packets in the queue.
802 void Add(QuicPacketNumber packet_number);
803
rtenneti4efd55dd2015-09-18 01:12:04804 // Adds packets between [lower, higher) to the set of packets in the queue. It
805 // is undefined behavior to call this with |higher| < |lower|.
rtenneti493d90ef2015-09-14 04:43:11806 void Add(QuicPacketNumber lower, QuicPacketNumber higher);
807
808 // Removes |packet_number| from the set of packets in the queue.
809 void Remove(QuicPacketNumber packet_number);
810
811 // Removes packets with values less than |higher| from the set of packets in
812 // the queue. Returns true if packets were removed.
813 bool RemoveUpTo(QuicPacketNumber higher);
814
815 // Returns true if the queue contains |packet_number|.
816 bool Contains(QuicPacketNumber packet_number) const;
817
818 // Returns true if the queue is empty.
819 bool Empty() const;
820
821 // Returns the minimum packet number stored in the queue. It is undefined
822 // behavior to call this if the queue is empty.
823 QuicPacketNumber Min() const;
824
825 // Returns the maximum packet number stored in the queue. It is undefined
826 // behavior to call this if the queue is empty.
827 QuicPacketNumber Max() const;
828
rtenneti4efd55dd2015-09-18 01:12:04829 // Returns the number of unique packets stored in the queue. Inefficient; only
830 // exposed for testing.
831 size_t NumPacketsSlow() const;
rtenneti493d90ef2015-09-14 04:43:11832
rtenneti4efd55dd2015-09-18 01:12:04833 // Returns iterators over the individual packet numbers.
834 const_iterator begin() const;
835 const_iterator end() const;
rtenneti493d90ef2015-09-14 04:43:11836 const_iterator lower_bound(QuicPacketNumber packet_number) const;
rtenneti493d90ef2015-09-14 04:43:11837
838 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
839 std::ostream& os,
840 const PacketNumberQueue& q);
841
842 private:
rtenneti4efd55dd2015-09-18 01:12:04843 IntervalSet<QuicPacketNumber> packet_number_intervals_;
rtenneti493d90ef2015-09-14 04:43:11844};
845
[email protected]310d37b2014-08-02 06:15:37846struct NET_EXPORT_PRIVATE QuicAckFrame {
847 QuicAckFrame();
848 ~QuicAckFrame();
849
850 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
851 std::ostream& os, const QuicAckFrame& s);
[email protected]a674b4c2012-12-05 03:44:30852
[email protected]9db443912013-02-25 05:27:03853 // Entropy hash of all packets up to largest observed not including missing
854 // packets.
855 QuicPacketEntropyHash entropy_hash;
[email protected]e537f742012-12-07 15:33:53856
ckrasicea295fe2015-10-31 05:03:27857 // Whether the ack had to be truncated when sent.
858 bool is_truncated;
859
rtennetia004d332015-08-28 06:44:57860 // The highest packet number we've observed from the peer.
[email protected]48697d8a2013-01-15 19:42:24861 //
862 // In general, this should be the largest packet number we've received. In
863 // the case of truncated acks, we may have to advertise a lower "upper bound"
864 // than largest received, to avoid implicitly acking missing packets that
865 // don't fit in the missing packet list due to size limitations. In this
866 // case, largest_observed may be a packet which is also in the missing packets
867 // list.
rtennetia004d332015-08-28 06:44:57868 QuicPacketNumber largest_observed;
[email protected]a674b4c2012-12-05 03:44:30869
[email protected]14e8106c2013-03-14 16:25:33870 // Time elapsed since largest_observed was received until this Ack frame was
871 // sent.
872 QuicTime::Delta delta_time_largest_observed;
873
ckrasicea295fe2015-10-31 05:03:27874 // Vector of <packet_number, time> for when packets arrived.
875 PacketTimeVector received_packet_times;
876
[email protected]e537f742012-12-07 15:33:53877 // The set of packets which we're expecting and have not received.
rtenneti493d90ef2015-09-14 04:43:11878 PacketNumberQueue missing_packets;
[email protected]8e01c062013-10-31 07:35:31879
rch99b644c2015-11-04 05:25:28880 // Packet most recently revived via FEC, 0 if no packet was revived by FEC.
881 // If non-zero, must be present in missing_packets.
882 QuicPacketNumber latest_revived_packet;
[email protected]8b37a092012-10-18 21:53:49883};
884
rtennetia004d332015-08-28 06:44:57885// True if the packet number is greater than largest_observed or is listed
[email protected]9db443912013-02-25 05:27:03886// as missing.
rtennetia004d332015-08-28 06:44:57887// Always returns false for packet numbers less than least_unacked.
888bool NET_EXPORT_PRIVATE IsAwaitingPacket(const QuicAckFrame& ack_frame,
889 QuicPacketNumber packet_number);
[email protected]9db443912013-02-25 05:27:03890
[email protected]a692ad9d2014-07-18 21:35:24891// Defines for all types of congestion control algorithms that can be used in
892// QUIC. Note that this is separate from the congestion feedback type -
893// some congestion control algorithms may use the same feedback type
894// (Reno and Cubic are the classic example for that).
895enum CongestionControlType {
896 kCubic,
rtennetifb3fa6c2015-03-16 23:04:55897 kCubicBytes,
[email protected]a692ad9d2014-07-18 21:35:24898 kReno,
rtennetifb3fa6c2015-03-16 23:04:55899 kRenoBytes,
[email protected]a692ad9d2014-07-18 21:35:24900 kBBR,
[email protected]8b37a092012-10-18 21:53:49901};
902
[email protected]c5cc9bd2014-03-31 23:17:14903enum LossDetectionType {
904 kNack, // Used to mimic TCP's loss detection.
905 kTime, // Time based loss detection.
906};
907
[email protected]be24ab22012-10-22 03:01:52908struct NET_EXPORT_PRIVATE QuicRstStreamFrame {
[email protected]6ae6e342014-02-06 02:21:42909 QuicRstStreamFrame();
910 QuicRstStreamFrame(QuicStreamId stream_id,
911 QuicRstStreamErrorCode error_code,
912 QuicStreamOffset bytes_written);
[email protected]8b37a092012-10-18 21:53:49913
[email protected]c5e1aca2014-01-30 04:03:04914 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
915 std::ostream& os, const QuicRstStreamFrame& r);
916
[email protected]8b37a092012-10-18 21:53:49917 QuicStreamId stream_id;
[email protected]74bda142013-03-31 02:49:11918 QuicRstStreamErrorCode error_code;
[email protected]6ae6e342014-02-06 02:21:42919
920 // Used to update flow control windows. On termination of a stream, both
921 // endpoints must inform the peer of the number of bytes they have sent on
922 // that stream. This can be done through normal termination (data packet with
923 // FIN) or through a RST.
924 QuicStreamOffset byte_offset;
[email protected]8b37a092012-10-18 21:53:49925};
926
[email protected]be24ab22012-10-22 03:01:52927struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame {
[email protected]6ae6e342014-02-06 02:21:42928 QuicConnectionCloseFrame();
929
[email protected]c5e1aca2014-01-30 04:03:04930 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
931 std::ostream& os, const QuicConnectionCloseFrame& c);
932
[email protected]431bb4fd2012-10-19 17:46:09933 QuicErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09934 std::string error_details;
[email protected]8b37a092012-10-18 21:53:49935};
936
[email protected]9db443912013-02-25 05:27:03937struct NET_EXPORT_PRIVATE QuicGoAwayFrame {
[email protected]6ae6e342014-02-06 02:21:42938 QuicGoAwayFrame();
[email protected]9db443912013-02-25 05:27:03939 QuicGoAwayFrame(QuicErrorCode error_code,
940 QuicStreamId last_good_stream_id,
941 const std::string& reason);
942
[email protected]c5e1aca2014-01-30 04:03:04943 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
944 std::ostream& os, const QuicGoAwayFrame& g);
945
[email protected]9db443912013-02-25 05:27:03946 QuicErrorCode error_code;
947 QuicStreamId last_good_stream_id;
948 std::string reason_phrase;
949};
950
[email protected]6ae6e342014-02-06 02:21:42951// Flow control updates per-stream and at the connection levoel.
952// Based on SPDY's WINDOW_UPDATE frame, but uses an absolute byte offset rather
953// than a window delta.
954// TODO(rjshade): A possible future optimization is to make stream_id and
955// byte_offset variable length, similar to stream frames.
956struct NET_EXPORT_PRIVATE QuicWindowUpdateFrame {
957 QuicWindowUpdateFrame() {}
958 QuicWindowUpdateFrame(QuicStreamId stream_id, QuicStreamOffset byte_offset);
959
960 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
961 std::ostream& os, const QuicWindowUpdateFrame& w);
962
963 // The stream this frame applies to. 0 is a special case meaning the overall
964 // connection rather than a specific stream.
965 QuicStreamId stream_id;
966
967 // Byte offset in the stream or connection. The receiver of this frame must
968 // not send data which would result in this offset being exceeded.
969 QuicStreamOffset byte_offset;
970};
971
972// The BLOCKED frame is used to indicate to the remote endpoint that this
973// endpoint believes itself to be flow-control blocked but otherwise ready to
974// send data. The BLOCKED frame is purely advisory and optional.
975// Based on SPDY's BLOCKED frame (undocumented as of 2014-01-28).
976struct NET_EXPORT_PRIVATE QuicBlockedFrame {
977 QuicBlockedFrame() {}
978 explicit QuicBlockedFrame(QuicStreamId stream_id);
979
980 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
981 std::ostream& os, const QuicBlockedFrame& b);
982
983 // The stream this frame applies to. 0 is a special case meaning the overall
984 // connection rather than a specific stream.
985 QuicStreamId stream_id;
986};
987
[email protected]8ba81212013-05-03 13:11:48988// EncryptionLevel enumerates the stages of encryption that a QUIC connection
989// progresses through. When retransmitting a packet, the encryption level needs
990// to be specified so that it is retransmitted at a level which the peer can
991// understand.
992enum EncryptionLevel {
993 ENCRYPTION_NONE = 0,
994 ENCRYPTION_INITIAL = 1,
995 ENCRYPTION_FORWARD_SECURE = 2,
996
997 NUM_ENCRYPTION_LEVELS,
998};
999
rch99b644c2015-11-04 05:25:281000enum PeerAddressChangeType {
1001 NO_CHANGE,
1002 // Peer address changes which are considered to be cause by NATs. Currently,
1003 // IPv4 address change with /24 does not change is considered to be cause by
1004 // NATs.
1005 NAT_PORT_REBINDING,
1006 IPV4_SUBNET_REBINDING,
1007 // IPv6 related address changes.
1008 IPV4_TO_IPV6,
1009 IPV6_TO_IPV4,
1010 IPV6_TO_IPV6,
1011 // This type is used when we always allow peer address changes.
1012 UNKNOWN,
1013 // All other peer address change types.
1014 UNSPECIFIED,
1015};
1016
[email protected]be24ab22012-10-22 03:01:521017struct NET_EXPORT_PRIVATE QuicFrame {
[email protected]6ae6e342014-02-06 02:21:421018 QuicFrame();
rtenneti5ca6eee2015-10-15 21:54:301019 explicit QuicFrame(QuicPaddingFrame padding_frame);
1020 explicit QuicFrame(QuicMtuDiscoveryFrame frame);
1021 explicit QuicFrame(QuicPingFrame frame);
1022
[email protected]6ae6e342014-02-06 02:21:421023 explicit QuicFrame(QuicStreamFrame* stream_frame);
1024 explicit QuicFrame(QuicAckFrame* frame);
[email protected]6ae6e342014-02-06 02:21:421025 explicit QuicFrame(QuicRstStreamFrame* frame);
1026 explicit QuicFrame(QuicConnectionCloseFrame* frame);
[email protected]93dd91f2014-02-27 00:09:031027 explicit QuicFrame(QuicStopWaitingFrame* frame);
[email protected]6ae6e342014-02-06 02:21:421028 explicit QuicFrame(QuicGoAwayFrame* frame);
1029 explicit QuicFrame(QuicWindowUpdateFrame* frame);
1030 explicit QuicFrame(QuicBlockedFrame* frame);
[email protected]8b37a092012-10-18 21:53:491031
[email protected]c5e1aca2014-01-30 04:03:041032 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
1033 std::ostream& os, const QuicFrame& frame);
1034
[email protected]be24ab22012-10-22 03:01:521035 QuicFrameType type;
[email protected]8b37a092012-10-18 21:53:491036 union {
rtenneti5ca6eee2015-10-15 21:54:301037 // Frames smaller than a pointer are inline.
1038 QuicPaddingFrame padding_frame;
1039 QuicMtuDiscoveryFrame mtu_discovery_frame;
1040 QuicPingFrame ping_frame;
1041
1042 // Frames larger than a pointer.
[email protected]be24ab22012-10-22 03:01:521043 QuicStreamFrame* stream_frame;
1044 QuicAckFrame* ack_frame;
[email protected]93dd91f2014-02-27 00:09:031045 QuicStopWaitingFrame* stop_waiting_frame;
[email protected]be24ab22012-10-22 03:01:521046 QuicRstStreamFrame* rst_stream_frame;
1047 QuicConnectionCloseFrame* connection_close_frame;
[email protected]9db443912013-02-25 05:27:031048 QuicGoAwayFrame* goaway_frame;
[email protected]6ae6e342014-02-06 02:21:421049 QuicWindowUpdateFrame* window_update_frame;
1050 QuicBlockedFrame* blocked_frame;
[email protected]8b37a092012-10-18 21:53:491051 };
1052};
rtenneti5ca6eee2015-10-15 21:54:301053// QuicFrameType consumes 8 bytes with padding.
1054static_assert(sizeof(QuicFrame) <= 16,
1055 "Frames larger than 8 bytes should be referenced by pointer.");
[email protected]8b37a092012-10-18 21:53:491056
[email protected]be24ab22012-10-22 03:01:521057typedef std::vector<QuicFrame> QuicFrames;
[email protected]8b37a092012-10-18 21:53:491058
[email protected]8b37a092012-10-18 21:53:491059class NET_EXPORT_PRIVATE QuicData {
1060 public:
[email protected]6ae6e342014-02-06 02:21:421061 QuicData(const char* buffer, size_t length);
1062 QuicData(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:491063 virtual ~QuicData();
1064
1065 base::StringPiece AsStringPiece() const {
1066 return base::StringPiece(data(), length());
1067 }
1068
1069 const char* data() const { return buffer_; }
1070 size_t length() const { return length_; }
rtennetie0ee6eb2015-05-01 00:55:091071 bool owns_buffer() const { return owns_buffer_; }
[email protected]8b37a092012-10-18 21:53:491072
1073 private:
1074 const char* buffer_;
1075 size_t length_;
1076 bool owns_buffer_;
1077
1078 DISALLOW_COPY_AND_ASSIGN(QuicData);
1079};
1080
1081class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
1082 public:
rtennetica5ac272015-02-07 12:35:121083 QuicPacket(char* buffer,
1084 size_t length,
1085 bool owns_buffer,
1086 QuicConnectionIdLength connection_id_length,
1087 bool includes_version,
rtennetia004d332015-08-28 06:44:571088 QuicPacketNumberLength packet_number_length);
[email protected]8b37a092012-10-18 21:53:491089
[email protected]5351cc4b2013-03-03 07:22:411090 base::StringPiece FecProtectedData() const;
1091 base::StringPiece AssociatedData() const;
1092 base::StringPiece BeforePlaintext() const;
1093 base::StringPiece Plaintext() const;
[email protected]082b65b2012-11-10 19:11:311094
[email protected]8b37a092012-10-18 21:53:491095 char* mutable_data() { return buffer_; }
1096
1097 private:
1098 char* buffer_;
[email protected]3aa9ca72014-02-27 19:39:431099 const QuicConnectionIdLength connection_id_length_;
[email protected]5351cc4b2013-03-03 07:22:411100 const bool includes_version_;
rtennetia004d332015-08-28 06:44:571101 const QuicPacketNumberLength packet_number_length_;
[email protected]8b37a092012-10-18 21:53:491102
[email protected]2e740db2012-10-20 19:35:191103 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
[email protected]8b37a092012-10-18 21:53:491104};
1105
1106class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
1107 public:
[email protected]6ae6e342014-02-06 02:21:421108 QuicEncryptedPacket(const char* buffer, size_t length);
1109 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer);
[email protected]8b37a092012-10-18 21:53:491110
[email protected]ec86d5462013-11-17 16:04:491111 // Clones the packet into a new packet which owns the buffer.
1112 QuicEncryptedPacket* Clone() const;
1113
[email protected]c1b32c62013-01-20 02:49:101114 // By default, gtest prints the raw bytes of an object. The bool data
1115 // member (in the base class QuicData) causes this object to have padding
1116 // bytes, which causes the default gtest object printer to read
1117 // uninitialize memory. So we need to teach gtest how to print this object.
1118 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
1119 std::ostream& os, const QuicEncryptedPacket& s);
1120
[email protected]2e740db2012-10-20 19:35:191121 private:
1122 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
[email protected]8b37a092012-10-18 21:53:491123};
1124
[email protected]9db443912013-02-25 05:27:031125class NET_EXPORT_PRIVATE RetransmittableFrames {
1126 public:
rtennetidc8e5a22015-02-25 01:38:521127 explicit RetransmittableFrames(EncryptionLevel level);
[email protected]9db443912013-02-25 05:27:031128 ~RetransmittableFrames();
1129
[email protected]9db443912013-02-25 05:27:031130 // Takes ownership of the frame inside |frame|.
rtennetia4228ea2015-06-04 02:31:441131 const QuicFrame& AddFrame(const QuicFrame& frame);
1132 // Takes ownership of the frame inside |frame| and |buffer|.
rtennetif60c32d82015-10-14 00:07:001133 const QuicFrame& AddFrame(const QuicFrame& frame, UniqueStreamBuffer buffer);
rtenneti73e25c12015-03-16 06:12:431134 // Removes all stream frames associated with |stream_id|.
1135 void RemoveFramesForStream(QuicStreamId stream_id);
1136
[email protected]9db443912013-02-25 05:27:031137 const QuicFrames& frames() const { return frames_; }
1138
[email protected]672631c2014-08-16 06:11:451139 IsHandshake HasCryptoHandshake() const {
1140 return has_crypto_handshake_;
1141 }
[email protected]2115d33ba2014-01-02 21:53:521142
[email protected]8ba81212013-05-03 13:11:481143 EncryptionLevel encryption_level() const {
1144 return encryption_level_;
1145 }
1146
rtennetid7d78b02015-06-17 16:54:341147 bool needs_padding() const { return needs_padding_; }
1148
1149 void set_needs_padding(bool needs_padding) { needs_padding_ = needs_padding; }
1150
[email protected]9db443912013-02-25 05:27:031151 private:
1152 QuicFrames frames_;
rtennetidc8e5a22015-02-25 01:38:521153 const EncryptionLevel encryption_level_;
[email protected]672631c2014-08-16 06:11:451154 IsHandshake has_crypto_handshake_;
rtennetid7d78b02015-06-17 16:54:341155 bool needs_padding_;
rtennetic14c8ab2015-06-18 05:47:401156 // Data referenced by the StringPiece of a QuicStreamFrame.
rtennetif60c32d82015-10-14 00:07:001157 //
1158 // TODO(rtenneti): Change const char* to UniqueStreamBuffer once chrome has
1159 // c++11 library support.
1160 // std::vector<UniqueStreamBuffer> stream_data_;
rtennetia4228ea2015-06-04 02:31:441161 std::vector<const char*> stream_data_;
[email protected]9db443912013-02-25 05:27:031162
1163 DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames);
1164};
1165
rtenneti8dd12b22015-10-21 01:26:381166struct NET_EXPORT_PRIVATE AckListenerWrapper {
1167 AckListenerWrapper(QuicAckListenerInterface* listener,
1168 QuicPacketLength data_length);
1169 ~AckListenerWrapper();
1170
1171 scoped_refptr<QuicAckListenerInterface> ack_listener;
1172 QuicPacketLength length;
1173};
1174
[email protected]9db443912013-02-25 05:27:031175struct NET_EXPORT_PRIVATE SerializedPacket {
rtennetia004d332015-08-28 06:44:571176 SerializedPacket(QuicPacketNumber packet_number,
1177 QuicPacketNumberLength packet_number_length,
rtennetib6ac61a52015-02-11 20:20:521178 QuicEncryptedPacket* packet,
[email protected]9db443912013-02-25 05:27:031179 QuicPacketEntropyHash entropy_hash,
rtenneti9bd5d4b2015-08-21 05:44:521180 RetransmittableFrames* retransmittable_frames,
1181 bool has_ack,
1182 bool has_stop_waiting);
rch99b644c2015-11-04 05:25:281183 SerializedPacket(QuicPacketNumber packet_number,
1184 QuicPacketNumberLength packet_number_length,
1185 char* encrypted_buffer,
1186 size_t encrypted_length,
1187 bool owns_buffer,
1188 QuicPacketEntropyHash entropy_hash,
1189 RetransmittableFrames* retransmittable_frames,
1190 bool has_ack,
1191 bool has_stop_waiting);
[email protected]97cf3022013-09-05 14:30:161192 ~SerializedPacket();
[email protected]9db443912013-02-25 05:27:031193
rtennetid39bd762015-06-12 01:05:521194 QuicEncryptedPacket* packet;
1195 RetransmittableFrames* retransmittable_frames;
rtennetia004d332015-08-28 06:44:571196 QuicPacketNumber packet_number;
1197 QuicPacketNumberLength packet_number_length;
[email protected]9db443912013-02-25 05:27:031198 QuicPacketEntropyHash entropy_hash;
rtennetica5ac272015-02-07 12:35:121199 bool is_fec_packet;
rtenneti9bd5d4b2015-08-21 05:44:521200 bool has_ack;
1201 bool has_stop_waiting;
[email protected]97cf3022013-09-05 14:30:161202
rtenneti6b1c5b12015-01-13 20:08:351203 // Optional notifiers which will be informed when this packet has been ACKed.
rtenneti8dd12b22015-10-21 01:26:381204 std::list<AckListenerWrapper> listeners;
[email protected]9db443912013-02-25 05:27:031205};
1206
[email protected]77b5d50b2014-05-07 22:48:481207struct NET_EXPORT_PRIVATE TransmissionInfo {
1208 // Used by STL when assigning into a map.
1209 TransmissionInfo();
1210
1211 // Constructs a Transmission with a new all_tranmissions set
rtennetia004d332015-08-28 06:44:571212 // containing |packet_number|.
[email protected]77b5d50b2014-05-07 22:48:481213 TransmissionInfo(RetransmittableFrames* retransmittable_frames,
rtennetia004d332015-08-28 06:44:571214 QuicPacketNumberLength packet_number_length,
[email protected]730b35d72014-06-05 03:23:221215 TransmissionType transmission_type,
rtenneti3183ac42015-02-28 03:39:411216 QuicTime sent_time,
rtenneti5ca6eee2015-10-15 21:54:301217 QuicPacketLength bytes_sent,
rtenneti3183ac42015-02-28 03:39:411218 bool is_fec_packet);
[email protected]77b5d50b2014-05-07 22:48:481219
rtenneti8dd12b22015-10-21 01:26:381220 ~TransmissionInfo();
1221
[email protected]77b5d50b2014-05-07 22:48:481222 RetransmittableFrames* retransmittable_frames;
rtennetia004d332015-08-28 06:44:571223 QuicPacketNumberLength packet_number_length;
rtenneti5ca6eee2015-10-15 21:54:301224 QuicPacketLength bytes_sent;
1225 uint16 nack_count;
[email protected]77b5d50b2014-05-07 22:48:481226 QuicTime sent_time;
[email protected]730b35d72014-06-05 03:23:221227 // Reason why this packet was transmitted.
1228 TransmissionType transmission_type;
[email protected]aa7e4ef2014-05-28 03:53:151229 // In flight packets have not been abandoned or lost.
1230 bool in_flight;
rtenneti31e9fd62014-09-16 05:22:151231 // True if the packet can never be acked, so it can be removed.
1232 bool is_unackable;
rtenneti85d89712014-11-20 03:32:241233 // True if the packet is an FEC packet.
1234 bool is_fec_packet;
rtenneti5ca6eee2015-10-15 21:54:301235 // Stores the packet numbers of all transmissions of this packet.
1236 // Must always be nullptr or have multiple elements.
zhongyi1fb9bc52015-11-24 23:09:421237 // TODO(ianswett): Deprecate with quic_track_single_retransmission.
rtenneti5ca6eee2015-10-15 21:54:301238 PacketNumberList* all_transmissions;
zhongyi1fb9bc52015-11-24 23:09:421239 // Stores the packet number of the next retransmission of this packet.
1240 // Zero if the packet has not been retransmitted.
1241 QuicPacketNumber retransmission;
rtenneti8dd12b22015-10-21 01:26:381242 // Non-empty if there is a listener for this packet.
1243 std::list<AckListenerWrapper> ack_listeners;
[email protected]77b5d50b2014-05-07 22:48:481244};
rtenneti8dd12b22015-10-21 01:26:381245static_assert(sizeof(QuicFrame) <= 64,
1246 "Keep the TransmissionInfo size to a cacheline.");
[email protected]77b5d50b2014-05-07 22:48:481247
rtennetic14c8ab2015-06-18 05:47:401248// Convenience wrapper to wrap an iovec array and the total length, which must
1249// be less than or equal to the actual total length of the iovecs.
1250struct NET_EXPORT_PRIVATE QuicIOVector {
1251 QuicIOVector(const struct iovec* iov, int iov_count, size_t total_length)
1252 : iov(iov), iov_count(iov_count), total_length(total_length) {}
1253
1254 const struct iovec* iov;
1255 const int iov_count;
1256 const size_t total_length;
1257};
1258
[email protected]8b37a092012-10-18 21:53:491259} // namespace net
1260
1261#endif // NET_QUIC_QUIC_PROTOCOL_H_