blob: eca6cee627b989a5e4fa34840a16747065234a26 [file] [log] [blame]
[email protected]8b37a092012-10-18 21:53:491// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_QUIC_QUIC_PROTOCOL_H_
6#define NET_QUIC_QUIC_PROTOCOL_H_
7
[email protected]e537f742012-12-07 15:33:538#include <stddef.h>
[email protected]8b37a092012-10-18 21:53:499#include <limits>
[email protected]a674b4c2012-12-05 03:44:3010#include <map>
[email protected]5640d0a2012-10-22 18:17:0211#include <ostream>
[email protected]e537f742012-12-07 15:33:5312#include <set>
13#include <string>
[email protected]8b37a092012-10-18 21:53:4914#include <utility>
15#include <vector>
16
17#include "base/basictypes.h"
[email protected]14c1c232013-06-11 17:52:4418#include "base/containers/hash_tables.h"
[email protected]8b37a092012-10-18 21:53:4919#include "base/logging.h"
[email protected]d069c11a2013-04-13 00:01:5520#include "base/strings/string_piece.h"
[email protected]165e0752012-11-16 07:49:4421#include "net/base/int128.h"
[email protected]8b37a092012-10-18 21:53:4922#include "net/base/net_export.h"
[email protected]5dafdb62013-11-14 01:24:2623#include "net/quic/iovector.h"
[email protected]fee17f72013-02-03 07:47:4124#include "net/quic/quic_bandwidth.h"
[email protected]2a960e02012-11-11 14:48:1025#include "net/quic/quic_time.h"
[email protected]8b37a092012-10-18 21:53:4926
27namespace net {
28
[email protected]f1e97e92012-12-16 04:53:2529using ::operator<<;
30
[email protected]97cf3022013-09-05 14:30:1631class QuicAckNotifier;
[email protected]8b37a092012-10-18 21:53:4932class QuicPacket;
[email protected]b064310782013-05-30 21:12:1733struct QuicPacketHeader;
[email protected]8b37a092012-10-18 21:53:4934
35typedef uint64 QuicGuid;
36typedef uint32 QuicStreamId;
37typedef uint64 QuicStreamOffset;
38typedef uint64 QuicPacketSequenceNumber;
[email protected]c995c572013-01-18 05:43:2039typedef QuicPacketSequenceNumber QuicFecGroupNumber;
[email protected]86a318d2013-01-23 21:16:0440typedef uint64 QuicPublicResetNonceProof;
[email protected]9db443912013-02-25 05:27:0341typedef uint8 QuicPacketEntropyHash;
[email protected]c244c5a12013-05-07 20:55:0442typedef uint32 QuicHeaderId;
[email protected]2532de12013-05-09 12:29:3343// QuicTag is the type of a tag in the wire protocol.
44typedef uint32 QuicTag;
45typedef std::vector<QuicTag> QuicTagVector;
[email protected]8edeb8d2013-08-28 06:11:4346typedef uint32 QuicPriority;
[email protected]cff7b7b2013-01-11 08:49:0747
[email protected]8b37a092012-10-18 21:53:4948// TODO(rch): Consider Quic specific names for these constants.
[email protected]8e01c062013-10-31 07:35:3149// Default and initial maximum size in bytes of a QUIC packet.
50const QuicByteCount kDefaultMaxPacketSize = 1200;
51// The maximum packet size of any QUIC packet, based on ethernet's max size,
[email protected]41fb6372013-12-10 05:26:4052// minus the IP and UDP headers. IPv6 has a 40 byte header, UPD adds an
53// additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's
54// max packet size is 1500 bytes, 1500 - 48 = 1452.
55const QuicByteCount kMaxPacketSize = 1452;
[email protected]8e01c062013-10-31 07:35:3156
57// Maximum size of the initial congestion window in packets.
58const size_t kDefaultInitialWindow = 10;
[email protected]457d6952013-12-13 09:24:5859// TODO(ianswett): Temporarily changed to 10 due to a large number of clients
60// mistakenly negotiating 100 initially and suffering the consequences.
61const size_t kMaxInitialWindow = 10;
[email protected]8e01c062013-10-31 07:35:3162
[email protected]0ac0c5b2013-11-20 05:55:5863// Maximum size of the congestion window, in packets, for TCP congestion control
64// algorithms.
65const size_t kMaxTcpCongestionWindow = 200;
66
[email protected]8e01c062013-10-31 07:35:3167// Don't allow a client to suggest an RTT longer than 15 seconds.
[email protected]e18e1072013-11-12 22:06:0768const size_t kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond;
[email protected]8b37a092012-10-18 21:53:4969
70// Maximum number of open streams per connection.
71const size_t kDefaultMaxStreamsPerConnection = 100;
72
[email protected]af806e62013-05-22 14:47:5073// Number of bytes reserved for public flags in the packet header.
74const size_t kPublicFlagsSize = 1;
[email protected]5351cc4b2013-03-03 07:22:4175// Number of bytes reserved for version number in the packet header.
76const size_t kQuicVersionSize = 4;
[email protected]c995c572013-01-18 05:43:2077// Number of bytes reserved for private flags in the packet header.
78const size_t kPrivateFlagsSize = 1;
79// Number of bytes reserved for FEC group in the packet header.
80const size_t kFecGroupSize = 1;
[email protected]86a318d2013-01-23 21:16:0481// Number of bytes reserved for the nonce proof in public reset packet.
82const size_t kPublicResetNonceSize = 8;
[email protected]5351cc4b2013-03-03 07:22:4183
84// Signifies that the QuicPacket will contain version of the protocol.
85const bool kIncludeVersion = true;
[email protected]c995c572013-01-18 05:43:2086
[email protected]5351cc4b2013-03-03 07:22:4187// Index of the first byte in a QUIC packet which is used in hash calculation.
88const size_t kStartOfHashData = 0;
[email protected]8b37a092012-10-18 21:53:4989
90// Limit on the delta between stream IDs.
91const QuicStreamId kMaxStreamIdDelta = 100;
[email protected]c244c5a12013-05-07 20:55:0492// Limit on the delta between header IDs.
93const QuicHeaderId kMaxHeaderIdDelta = 100;
[email protected]8b37a092012-10-18 21:53:4994
95// Reserved ID for the crypto stream.
[email protected]8b37a092012-10-18 21:53:4996const QuicStreamId kCryptoStreamId = 1;
97
[email protected]4d640792013-12-18 22:21:0898// Reserved ID for the headers stream.
99const QuicStreamId kHeadersStreamId = 3;
100
[email protected]899951652013-05-16 12:52:39101// This is the default network timeout a for connection till the crypto
102// handshake succeeds and the negotiated timeout from the handshake is received.
[email protected]b064310782013-05-30 21:12:17103const int64 kDefaultInitialTimeoutSecs = 120; // 2 mins.
[email protected]899951652013-05-16 12:52:39104const int64 kDefaultTimeoutSecs = 60 * 10; // 10 minutes.
[email protected]b064310782013-05-30 21:12:17105const int64 kDefaultMaxTimeForCryptoHandshakeSecs = 5; // 5 secs.
[email protected]8b37a092012-10-18 21:53:49106
[email protected]b007e632013-10-28 08:39:25107// We define an unsigned 16-bit floating point value, inspired by IEEE floats
108// (http://en.wikipedia.org/wiki/Half_precision_floating-point_format),
109// with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden
110// bit) and denormals, but without signs, transfinites or fractions. Wire format
111// 16 bits (little-endian byte order) are split into exponent (high 5) and
112// mantissa (low 11) and decoded as:
113// uint64 value;
114// if (exponent == 0) value = mantissa;
115// else value = (mantissa | 1 << 11) << (exponent - 1)
116const int kUFloat16ExponentBits = 5;
117const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30
118const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11
119const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12
120const uint64 kUFloat16MaxValue = // 0x3FFC0000000
121 ((GG_UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1) <<
122 kUFloat16MaxExponent;
123
[email protected]c67a82cb2013-09-24 02:53:21124enum TransmissionType {
[email protected]2532de12013-05-09 12:29:33125 NOT_RETRANSMISSION,
[email protected]c67a82cb2013-09-24 02:53:21126 NACK_RETRANSMISSION,
127 RTO_RETRANSMISSION,
[email protected]74bda142013-03-31 02:49:11128};
129
[email protected]41fb6372013-12-10 05:26:40130enum RetransmissionType {
131 INITIAL_ENCRYPTION_ONLY,
132 ALL_PACKETS
133};
134
[email protected]74bda142013-03-31 02:49:11135enum HasRetransmittableData {
[email protected]2532de12013-05-09 12:29:33136 NO_RETRANSMITTABLE_DATA,
137 HAS_RETRANSMITTABLE_DATA,
[email protected]74bda142013-03-31 02:49:11138};
139
[email protected]575cce62013-08-03 02:06:43140enum IsHandshake {
141 NOT_HANDSHAKE,
142 IS_HANDSHAKE
143};
144
[email protected]be24ab22012-10-22 03:01:52145enum QuicFrameType {
[email protected]c995c572013-01-18 05:43:20146 PADDING_FRAME = 0,
[email protected]be24ab22012-10-22 03:01:52147 RST_STREAM_FRAME,
148 CONNECTION_CLOSE_FRAME,
[email protected]9db443912013-02-25 05:27:03149 GOAWAY_FRAME,
[email protected]97cf3022013-09-05 14:30:16150 STREAM_FRAME,
151 ACK_FRAME,
152 CONGESTION_FEEDBACK_FRAME,
[email protected]be24ab22012-10-22 03:01:52153 NUM_FRAME_TYPES
[email protected]8b37a092012-10-18 21:53:49154};
155
[email protected]b064310782013-05-30 21:12:17156enum QuicGuidLength {
157 PACKET_0BYTE_GUID = 0,
158 PACKET_1BYTE_GUID = 1,
159 PACKET_4BYTE_GUID = 4,
160 PACKET_8BYTE_GUID = 8
161};
162
163enum InFecGroup {
164 NOT_IN_FEC_GROUP,
165 IN_FEC_GROUP,
166};
167
[email protected]25c31dc2013-06-05 17:56:04168enum QuicSequenceNumberLength {
169 PACKET_1BYTE_SEQUENCE_NUMBER = 1,
170 PACKET_2BYTE_SEQUENCE_NUMBER = 2,
171 PACKET_4BYTE_SEQUENCE_NUMBER = 4,
172 PACKET_6BYTE_SEQUENCE_NUMBER = 6
173};
174
[email protected]8e01c062013-10-31 07:35:31175// Used to indicate a QuicSequenceNumberLength using two flag bits.
176enum QuicSequenceNumberLengthFlags {
177 PACKET_FLAGS_1BYTE_SEQUENCE = 0, // 00
178 PACKET_FLAGS_2BYTE_SEQUENCE = 1, // 01
179 PACKET_FLAGS_4BYTE_SEQUENCE = 1 << 1, // 10
180 PACKET_FLAGS_6BYTE_SEQUENCE = 1 << 1 | 1, // 11
181};
182
[email protected]f62262b2013-07-05 20:57:30183// The public flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20184enum QuicPacketPublicFlags {
185 PACKET_PUBLIC_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30186
187 // Bit 0: Does the packet header contains version info?
188 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0,
189
190 // Bit 1: Is this packet a public reset packet?
191 PACKET_PUBLIC_FLAGS_RST = 1 << 1,
192
193 // Bits 2 and 3 specify the length of the GUID as follows:
194 // ----00--: 0 bytes
195 // ----01--: 1 byte
196 // ----10--: 4 bytes
197 // ----11--: 8 bytes
[email protected]1354bf62013-05-23 23:17:18198 PACKET_PUBLIC_FLAGS_0BYTE_GUID = 0,
199 PACKET_PUBLIC_FLAGS_1BYTE_GUID = 1 << 2,
200 PACKET_PUBLIC_FLAGS_4BYTE_GUID = 1 << 3,
201 PACKET_PUBLIC_FLAGS_8BYTE_GUID = 1 << 3 | 1 << 2,
[email protected]f62262b2013-07-05 20:57:30202
203 // Bits 4 and 5 describe the packet sequence number length as follows:
204 // --00----: 1 byte
205 // --01----: 2 bytes
206 // --10----: 4 bytes
207 // --11----: 6 bytes
[email protected]8e01c062013-10-31 07:35:31208 PACKET_PUBLIC_FLAGS_1BYTE_SEQUENCE = PACKET_FLAGS_1BYTE_SEQUENCE << 4,
209 PACKET_PUBLIC_FLAGS_2BYTE_SEQUENCE = PACKET_FLAGS_2BYTE_SEQUENCE << 4,
210 PACKET_PUBLIC_FLAGS_4BYTE_SEQUENCE = PACKET_FLAGS_4BYTE_SEQUENCE << 4,
211 PACKET_PUBLIC_FLAGS_6BYTE_SEQUENCE = PACKET_FLAGS_6BYTE_SEQUENCE << 4,
[email protected]f62262b2013-07-05 20:57:30212
213 // All bits set (bits 6 and 7 are not currently used): 00111111
214 PACKET_PUBLIC_FLAGS_MAX = (1 << 6) - 1
[email protected]c995c572013-01-18 05:43:20215};
[email protected]8b37a092012-10-18 21:53:49216
[email protected]f62262b2013-07-05 20:57:30217// The private flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20218enum QuicPacketPrivateFlags {
219 PACKET_PRIVATE_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30220
221 // Bit 0: Does this packet contain an entropy bit?
[email protected]b064310782013-05-30 21:12:17222 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0,
[email protected]f62262b2013-07-05 20:57:30223
224 // Bit 1: Payload is part of an FEC group?
225 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1,
226
227 // Bit 2: Payload is FEC as opposed to frames?
228 PACKET_PRIVATE_FLAGS_FEC = 1 << 2,
229
230 // All bits set (bits 3-7 are not currently used): 00000111
231 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1
[email protected]c995c572013-01-18 05:43:20232};
233
[email protected]48878092013-07-26 14:51:56234// The available versions of QUIC. Guaranteed that the integer value of the enum
235// will match the version number.
236// When adding a new version to this enum you should add it to
[email protected]8bbfaeb72013-08-09 06:38:26237// kSupportedQuicVersions (if appropriate), and also add a new case to the
238// helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and
239// QuicVersionToString.
[email protected]48878092013-07-26 14:51:56240enum QuicVersion {
241 // Special case to indicate unknown/unsupported QUIC version.
242 QUIC_VERSION_UNSUPPORTED = 0,
243
[email protected]4d640792013-12-18 22:21:08244 QUIC_VERSION_12 = 12,
245 QUIC_VERSION_13 = 13, // Current version.
[email protected]48878092013-07-26 14:51:56246};
247
248// This vector contains QUIC versions which we currently support.
249// This should be ordered such that the highest supported version is the first
250// element, with subsequent elements in descending order (versions can be
251// skipped as necessary).
[email protected]31ae854842013-11-27 00:05:46252//
253// IMPORTANT: if you are addding to this list, follow the instructions at
254// http://sites/quic/adding-and-removing-versions
255static const QuicVersion kSupportedQuicVersions[] = {QUIC_VERSION_12};
[email protected]48878092013-07-26 14:51:56256
257typedef std::vector<QuicVersion> QuicVersionVector;
258
[email protected]b007e632013-10-28 08:39:25259// Returns a vector of QUIC versions in kSupportedQuicVersions.
260NET_EXPORT_PRIVATE QuicVersionVector QuicSupportedVersions();
[email protected]ea2ab47b2013-08-13 00:44:11261
[email protected]48878092013-07-26 14:51:56262// QuicTag is written to and read from the wire, but we prefer to use
263// the more readable QuicVersion at other levels.
264// Helper function which translates from a QuicVersion to a QuicTag. Returns 0
265// if QuicVersion is unsupported.
266NET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version);
267
268// Returns appropriate QuicVersion from a QuicTag.
269// Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood.
270NET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag);
271
272// Helper function which translates from a QuicVersion to a string.
273// Returns strings corresponding to enum names (e.g. QUIC_VERSION_6).
274NET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version);
275
276// Returns comma separated list of string representations of QuicVersion enum
[email protected]b007e632013-10-28 08:39:25277// values in the supplied |versions| vector.
278NET_EXPORT_PRIVATE std::string QuicVersionVectorToString(
279 const QuicVersionVector& versions);
[email protected]48878092013-07-26 14:51:56280
281// Version and Crypto tags are written to the wire with a big-endian
282// representation of the name of the tag. For example
283// the client hello tag (CHLO) will be written as the
284// following 4 bytes: 'C' 'H' 'L' 'O'. Since it is
285// stored in memory as a little endian uint32, we need
286// to reverse the order of the bytes.
287
288// MakeQuicTag returns a value given the four bytes. For example:
289// MakeQuicTag('C', 'H', 'L', 'O');
290NET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d);
291
[email protected]b064310782013-05-30 21:12:17292// Size in bytes of the data or fec packet header.
293NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicPacketHeader header);
294
[email protected]25c31dc2013-06-05 17:56:04295NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(
296 QuicGuidLength guid_length,
297 bool include_version,
298 QuicSequenceNumberLength sequence_number_length,
299 InFecGroup is_in_fec_group);
[email protected]b064310782013-05-30 21:12:17300
301// Size in bytes of the public reset packet.
302NET_EXPORT_PRIVATE size_t GetPublicResetPacketSize();
303
304// Index of the first byte in a QUIC packet of FEC protected data.
[email protected]25c31dc2013-06-05 17:56:04305NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(
306 QuicGuidLength guid_length,
307 bool include_version,
308 QuicSequenceNumberLength sequence_number_length);
[email protected]b064310782013-05-30 21:12:17309// Index of the first byte in a QUIC packet of encrypted data.
[email protected]25c31dc2013-06-05 17:56:04310NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(
311 QuicGuidLength guid_length,
312 bool include_version,
313 QuicSequenceNumberLength sequence_number_length);
[email protected]b064310782013-05-30 21:12:17314
[email protected]74bda142013-03-31 02:49:11315enum QuicRstStreamErrorCode {
316 QUIC_STREAM_NO_ERROR = 0,
[email protected]8b37a092012-10-18 21:53:49317
[email protected]24e5bc52013-09-18 15:36:58318 // There was some error which halted stream processing.
319 QUIC_ERROR_PROCESSING_STREAM,
[email protected]8b37a092012-10-18 21:53:49320 // We got two fin or reset offsets which did not match.
321 QUIC_MULTIPLE_TERMINATION_OFFSETS,
322 // We got bad payload and can not respond to it at the protocol level.
323 QUIC_BAD_APPLICATION_PAYLOAD,
[email protected]74bda142013-03-31 02:49:11324 // Stream closed due to connection error. No reset frame is sent when this
325 // happens.
326 QUIC_STREAM_CONNECTION_ERROR,
327 // GoAway frame sent. No more stream can be created.
328 QUIC_STREAM_PEER_GOING_AWAY,
[email protected]06ff5152013-08-29 01:03:05329 // The stream has been cancelled.
330 QUIC_STREAM_CANCELLED,
[email protected]8b37a092012-10-18 21:53:49331
[email protected]74bda142013-03-31 02:49:11332 // No error. Used as bound while iterating.
333 QUIC_STREAM_LAST_ERROR,
334};
[email protected]8b37a092012-10-18 21:53:49335
[email protected]89264042013-08-21 07:35:24336// These values must remain stable as they are uploaded to UMA histograms.
337// To add a new error code, use the current value of QUIC_LAST_ERROR and
338// increment QUIC_LAST_ERROR.
[email protected]74bda142013-03-31 02:49:11339enum QuicErrorCode {
340 QUIC_NO_ERROR = 0,
341
342 // Connection has reached an invalid state.
[email protected]89264042013-08-21 07:35:24343 QUIC_INTERNAL_ERROR = 1,
[email protected]74bda142013-03-31 02:49:11344 // There were data frames after the a fin or reset.
[email protected]89264042013-08-21 07:35:24345 QUIC_STREAM_DATA_AFTER_TERMINATION = 2,
[email protected]8b37a092012-10-18 21:53:49346 // Control frame is malformed.
[email protected]89264042013-08-21 07:35:24347 QUIC_INVALID_PACKET_HEADER = 3,
[email protected]be24ab22012-10-22 03:01:52348 // Frame data is malformed.
[email protected]89264042013-08-21 07:35:24349 QUIC_INVALID_FRAME_DATA = 4,
350 // The packet contained no payload.
351 QUIC_MISSING_PAYLOAD = 48,
[email protected]8b37a092012-10-18 21:53:49352 // FEC data is malformed.
[email protected]89264042013-08-21 07:35:24353 QUIC_INVALID_FEC_DATA = 5,
354 // STREAM frame data is malformed.
355 QUIC_INVALID_STREAM_DATA = 46,
356 // RST_STREAM frame data is malformed.
357 QUIC_INVALID_RST_STREAM_DATA = 6,
358 // CONNECTION_CLOSE frame data is malformed.
359 QUIC_INVALID_CONNECTION_CLOSE_DATA = 7,
360 // GOAWAY frame data is malformed.
361 QUIC_INVALID_GOAWAY_DATA = 8,
362 // ACK frame data is malformed.
363 QUIC_INVALID_ACK_DATA = 9,
364 // CONGESTION_FEEDBACK frame data is malformed.
365 QUIC_INVALID_CONGESTION_FEEDBACK_DATA = 47,
[email protected]14e8106c2013-03-14 16:25:33366 // Version negotiation packet is malformed.
[email protected]89264042013-08-21 07:35:24367 QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10,
[email protected]899951652013-05-16 12:52:39368 // Public RST packet is malformed.
[email protected]89264042013-08-21 07:35:24369 QUIC_INVALID_PUBLIC_RST_PACKET = 11,
[email protected]8b37a092012-10-18 21:53:49370 // There was an error decrypting.
[email protected]89264042013-08-21 07:35:24371 QUIC_DECRYPTION_FAILURE = 12,
[email protected]8b37a092012-10-18 21:53:49372 // There was an error encrypting.
[email protected]89264042013-08-21 07:35:24373 QUIC_ENCRYPTION_FAILURE = 13,
[email protected]8b37a092012-10-18 21:53:49374 // The packet exceeded kMaxPacketSize.
[email protected]89264042013-08-21 07:35:24375 QUIC_PACKET_TOO_LARGE = 14,
[email protected]8b37a092012-10-18 21:53:49376 // Data was sent for a stream which did not exist.
[email protected]89264042013-08-21 07:35:24377 QUIC_PACKET_FOR_NONEXISTENT_STREAM = 15,
[email protected]9db443912013-02-25 05:27:03378 // The peer is going away. May be a client or server.
[email protected]89264042013-08-21 07:35:24379 QUIC_PEER_GOING_AWAY = 16,
[email protected]8b37a092012-10-18 21:53:49380 // A stream ID was invalid.
[email protected]89264042013-08-21 07:35:24381 QUIC_INVALID_STREAM_ID = 17,
[email protected]24e5bc52013-09-18 15:36:58382 // A priority was invalid.
383 QUIC_INVALID_PRIORITY = 49,
[email protected]8b37a092012-10-18 21:53:49384 // Too many streams already open.
[email protected]89264042013-08-21 07:35:24385 QUIC_TOO_MANY_OPEN_STREAMS = 18,
[email protected]86a318d2013-01-23 21:16:04386 // Received public reset for this connection.
[email protected]89264042013-08-21 07:35:24387 QUIC_PUBLIC_RESET = 19,
[email protected]c244c5a12013-05-07 20:55:04388 // Invalid protocol version.
[email protected]89264042013-08-21 07:35:24389 QUIC_INVALID_VERSION = 20,
[email protected]c244c5a12013-05-07 20:55:04390 // Stream reset before headers decompressed.
[email protected]89264042013-08-21 07:35:24391 QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED = 21,
[email protected]c244c5a12013-05-07 20:55:04392 // The Header ID for a stream was too far from the previous.
[email protected]89264042013-08-21 07:35:24393 QUIC_INVALID_HEADER_ID = 22,
[email protected]899951652013-05-16 12:52:39394 // Negotiable parameter received during handshake had invalid value.
[email protected]89264042013-08-21 07:35:24395 QUIC_INVALID_NEGOTIATED_VALUE = 23,
[email protected]899951652013-05-16 12:52:39396 // There was an error decompressing data.
[email protected]89264042013-08-21 07:35:24397 QUIC_DECOMPRESSION_FAILURE = 24,
[email protected]8b37a092012-10-18 21:53:49398 // We hit our prenegotiated (or default) timeout
[email protected]89264042013-08-21 07:35:24399 QUIC_CONNECTION_TIMED_OUT = 25,
[email protected]899951652013-05-16 12:52:39400 // There was an error encountered migrating addresses
[email protected]89264042013-08-21 07:35:24401 QUIC_ERROR_MIGRATING_ADDRESS = 26,
[email protected]1505a512013-09-04 22:59:35402 // There was an error while writing to the socket.
[email protected]89264042013-08-21 07:35:24403 QUIC_PACKET_WRITE_ERROR = 27,
[email protected]1505a512013-09-04 22:59:35404 // There was an error while reading from the socket.
405 QUIC_PACKET_READ_ERROR = 51,
[email protected]24e5bc52013-09-18 15:36:58406 // We received a STREAM_FRAME with no data and no fin flag set.
407 QUIC_INVALID_STREAM_FRAME = 50,
[email protected]4d640792013-12-18 22:21:08408 // We received invalid data on the headers stream.
409 QUIC_INVALID_HEADERS_STREAM_DATA = 56,
[email protected]8b37a092012-10-18 21:53:49410
411 // Crypto errors.
412
[email protected]1354bf62013-05-23 23:17:18413 // Hanshake failed.
[email protected]89264042013-08-21 07:35:24414 QUIC_HANDSHAKE_FAILED = 28,
[email protected]8b37a092012-10-18 21:53:49415 // Handshake message contained out of order tags.
[email protected]89264042013-08-21 07:35:24416 QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29,
[email protected]701bc892013-01-17 04:51:54417 // Handshake message contained too many entries.
[email protected]89264042013-08-21 07:35:24418 QUIC_CRYPTO_TOO_MANY_ENTRIES = 30,
[email protected]8b37a092012-10-18 21:53:49419 // Handshake message contained an invalid value length.
[email protected]89264042013-08-21 07:35:24420 QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31,
[email protected]8b37a092012-10-18 21:53:49421 // A crypto message was received after the handshake was complete.
[email protected]89264042013-08-21 07:35:24422 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32,
[email protected]d3d15bf2013-01-30 02:51:54423 // A crypto message was received with an illegal message tag.
[email protected]89264042013-08-21 07:35:24424 QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33,
[email protected]d3d15bf2013-01-30 02:51:54425 // A crypto message was received with an illegal parameter.
[email protected]89264042013-08-21 07:35:24426 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34,
[email protected]752fbe52013-10-14 08:35:32427 // An invalid channel id signature was supplied.
428 QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52,
[email protected]d3d15bf2013-01-30 02:51:54429 // A crypto message was received with a mandatory parameter missing.
[email protected]89264042013-08-21 07:35:24430 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35,
[email protected]d3d15bf2013-01-30 02:51:54431 // A crypto message was received with a parameter that has no overlap
432 // with the local parameter.
[email protected]89264042013-08-21 07:35:24433 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36,
[email protected]ed3fc15d2013-03-08 18:37:44434 // A crypto message was received that contained a parameter with too few
435 // values.
[email protected]89264042013-08-21 07:35:24436 QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37,
[email protected]ccc66e8a2013-03-26 08:26:14437 // An internal error occured in crypto processing.
[email protected]89264042013-08-21 07:35:24438 QUIC_CRYPTO_INTERNAL_ERROR = 38,
[email protected]ccc66e8a2013-03-26 08:26:14439 // A crypto handshake message specified an unsupported version.
[email protected]89264042013-08-21 07:35:24440 QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39,
[email protected]ccc66e8a2013-03-26 08:26:14441 // There was no intersection between the crypto primitives supported by the
442 // peer and ourselves.
[email protected]89264042013-08-21 07:35:24443 QUIC_CRYPTO_NO_SUPPORT = 40,
[email protected]ef95114d2013-04-17 17:57:01444 // The server rejected our client hello messages too many times.
[email protected]89264042013-08-21 07:35:24445 QUIC_CRYPTO_TOO_MANY_REJECTS = 41,
[email protected]a57e0272013-04-26 07:31:47446 // The client rejected the server's certificate chain or signature.
[email protected]89264042013-08-21 07:35:24447 QUIC_PROOF_INVALID = 42,
[email protected]8ba81212013-05-03 13:11:48448 // A crypto message was received with a duplicate tag.
[email protected]89264042013-08-21 07:35:24449 QUIC_CRYPTO_DUPLICATE_TAG = 43,
[email protected]2532de12013-05-09 12:29:33450 // A crypto message was received with the wrong encryption level (i.e. it
451 // should have been encrypted but was not.)
[email protected]89264042013-08-21 07:35:24452 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44,
[email protected]2532de12013-05-09 12:29:33453 // The server config for a server has expired.
[email protected]89264042013-08-21 07:35:24454 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45,
[email protected]752fbe52013-10-14 08:35:32455 // We failed to setup the symmetric keys for a connection.
456 QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53,
[email protected]691f45a982013-11-19 10:52:04457 // A handshake message arrived, but we are still validating the
458 // previous handshake message.
459 QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54,
[email protected]d89f1862013-11-26 21:21:27460 // This connection involved a version negotiation which appears to have been
461 // tampered with.
462 QUIC_VERSION_NEGOTIATION_MISMATCH = 55,
[email protected]ccc66e8a2013-03-26 08:26:14463
[email protected]74bda142013-03-31 02:49:11464 // No error. Used as bound while iterating.
[email protected]4d640792013-12-18 22:21:08465 QUIC_LAST_ERROR = 57,
[email protected]8b37a092012-10-18 21:53:49466};
467
[email protected]c995c572013-01-18 05:43:20468struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
[email protected]14e8106c2013-03-14 16:25:33469 QuicPacketPublicHeader();
470 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
471 ~QuicPacketPublicHeader();
472
[email protected]c995c572013-01-18 05:43:20473 // Universal header. All QuicPacket headers will have a guid and public flags.
[email protected]8b37a092012-10-18 21:53:49474 QuicGuid guid;
[email protected]b064310782013-05-30 21:12:17475 QuicGuidLength guid_length;
[email protected]9db443912013-02-25 05:27:03476 bool reset_flag;
477 bool version_flag;
[email protected]25c31dc2013-06-05 17:56:04478 QuicSequenceNumberLength sequence_number_length;
[email protected]48878092013-07-26 14:51:56479 QuicVersionVector versions;
[email protected]c995c572013-01-18 05:43:20480};
481
482// Header for Data or FEC packets.
[email protected]74bda142013-03-31 02:49:11483struct NET_EXPORT_PRIVATE QuicPacketHeader {
484 QuicPacketHeader();
485 explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
[email protected]9db443912013-02-25 05:27:03486
487 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
488 std::ostream& os, const QuicPacketHeader& s);
489
[email protected]c995c572013-01-18 05:43:20490 QuicPacketPublicHeader public_header;
[email protected]9db443912013-02-25 05:27:03491 bool fec_flag;
[email protected]9db443912013-02-25 05:27:03492 bool entropy_flag;
493 QuicPacketEntropyHash entropy_hash;
[email protected]8b37a092012-10-18 21:53:49494 QuicPacketSequenceNumber packet_sequence_number;
[email protected]b064310782013-05-30 21:12:17495 InFecGroup is_in_fec_group;
[email protected]8b37a092012-10-18 21:53:49496 QuicFecGroupNumber fec_group;
497};
498
[email protected]74bda142013-03-31 02:49:11499struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
[email protected]86a318d2013-01-23 21:16:04500 QuicPublicResetPacket() {}
501 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header)
502 : public_header(header) {}
503 QuicPacketPublicHeader public_header;
504 QuicPacketSequenceNumber rejected_sequence_number;
505 QuicPublicResetNonceProof nonce_proof;
506};
507
[email protected]14e8106c2013-03-14 16:25:33508enum QuicVersionNegotiationState {
509 START_NEGOTIATION = 0,
[email protected]ec640112013-08-09 03:56:18510 // Server-side this implies we've sent a version negotiation packet and are
511 // waiting on the client to select a compatible version. Client-side this
512 // implies we've gotten a version negotiation packet, are retransmitting the
513 // initial packets with a supported version and are waiting for our first
514 // packet from the server.
515 NEGOTIATION_IN_PROGRESS,
516 // This indicates this endpoint has received a packet from the peer with a
517 // version this endpoint supports. Version negotiation is complete, and the
518 // version number will no longer be sent with future packets.
[email protected]14e8106c2013-03-14 16:25:33519 NEGOTIATED_VERSION
520};
521
522typedef QuicPacketPublicHeader QuicVersionNegotiationPacket;
523
[email protected]c995c572013-01-18 05:43:20524// A padding frame contains no payload.
525struct NET_EXPORT_PRIVATE QuicPaddingFrame {
526};
527
[email protected]be24ab22012-10-22 03:01:52528struct NET_EXPORT_PRIVATE QuicStreamFrame {
529 QuicStreamFrame();
[email protected]5dafdb62013-11-14 01:24:26530 QuicStreamFrame(const QuicStreamFrame& frame);
[email protected]be24ab22012-10-22 03:01:52531 QuicStreamFrame(QuicStreamId stream_id,
[email protected]a5061242012-10-23 23:29:37532 bool fin,
[email protected]701bc892013-01-17 04:51:54533 QuicStreamOffset offset,
[email protected]5dafdb62013-11-14 01:24:26534 IOVector data);
535
536 // Returns a copy of the IOVector |data| as a heap-allocated string.
537 // Caller must take ownership of the returned string.
538 std::string* GetDataAsString() const;
[email protected]8b37a092012-10-18 21:53:49539
540 QuicStreamId stream_id;
541 bool fin;
[email protected]701bc892013-01-17 04:51:54542 QuicStreamOffset offset; // Location of this data in the stream.
[email protected]5dafdb62013-11-14 01:24:26543 IOVector data;
[email protected]97cf3022013-09-05 14:30:16544
545 // If this is set, then when this packet is ACKed the AckNotifier will be
546 // informed.
547 QuicAckNotifier* notifier;
[email protected]8b37a092012-10-18 21:53:49548};
549
[email protected]e537f742012-12-07 15:33:53550// TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
551// is finalized.
[email protected]9db443912013-02-25 05:27:03552typedef std::set<QuicPacketSequenceNumber> SequenceNumberSet;
[email protected]3c5f4a732013-01-12 16:45:34553// TODO(pwestin): Add a way to enforce the max size of this map.
[email protected]e537f742012-12-07 15:33:53554typedef std::map<QuicPacketSequenceNumber, QuicTime> TimeMap;
[email protected]044ac2b2012-11-13 21:41:06555
[email protected]8b37a092012-10-18 21:53:49556struct NET_EXPORT_PRIVATE ReceivedPacketInfo {
557 ReceivedPacketInfo();
558 ~ReceivedPacketInfo();
[email protected]26f3f8e2012-12-13 21:07:19559 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
560 std::ostream& os, const ReceivedPacketInfo& s);
[email protected]a674b4c2012-12-05 03:44:30561
[email protected]9db443912013-02-25 05:27:03562 // Entropy hash of all packets up to largest observed not including missing
563 // packets.
564 QuicPacketEntropyHash entropy_hash;
[email protected]e537f742012-12-07 15:33:53565
[email protected]48697d8a2013-01-15 19:42:24566 // The highest packet sequence number we've observed from the peer.
567 //
568 // In general, this should be the largest packet number we've received. In
569 // the case of truncated acks, we may have to advertise a lower "upper bound"
570 // than largest received, to avoid implicitly acking missing packets that
571 // don't fit in the missing packet list due to size limitations. In this
572 // case, largest_observed may be a packet which is also in the missing packets
573 // list.
574 QuicPacketSequenceNumber largest_observed;
[email protected]a674b4c2012-12-05 03:44:30575
[email protected]14e8106c2013-03-14 16:25:33576 // Time elapsed since largest_observed was received until this Ack frame was
577 // sent.
578 QuicTime::Delta delta_time_largest_observed;
579
[email protected]9db443912013-02-25 05:27:03580 // TODO(satyamshekhar): Can be optimized using an interval set like data
581 // structure.
[email protected]e537f742012-12-07 15:33:53582 // The set of packets which we're expecting and have not received.
[email protected]9db443912013-02-25 05:27:03583 SequenceNumberSet missing_packets;
[email protected]8e01c062013-10-31 07:35:31584
585 // Whether the ack had to be truncated when sent.
586 bool is_truncated;
[email protected]8b37a092012-10-18 21:53:49587};
588
[email protected]9db443912013-02-25 05:27:03589// True if the sequence number is greater than largest_observed or is listed
590// as missing.
591// Always returns false for sequence numbers less than least_unacked.
592bool NET_EXPORT_PRIVATE IsAwaitingPacket(
593 const ReceivedPacketInfo& received_info,
594 QuicPacketSequenceNumber sequence_number);
595
596// Inserts missing packets between [lower, higher).
597void NET_EXPORT_PRIVATE InsertMissingPacketsBetween(
598 ReceivedPacketInfo* received_info,
599 QuicPacketSequenceNumber lower,
600 QuicPacketSequenceNumber higher);
601
[email protected]8b37a092012-10-18 21:53:49602struct NET_EXPORT_PRIVATE SentPacketInfo {
603 SentPacketInfo();
604 ~SentPacketInfo();
[email protected]26f3f8e2012-12-13 21:07:19605 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
606 std::ostream& os, const SentPacketInfo& s);
607
[email protected]9db443912013-02-25 05:27:03608 // Entropy hash of all packets up to, but not including, the least unacked
609 // packet.
610 QuicPacketEntropyHash entropy_hash;
[email protected]8b37a092012-10-18 21:53:49611 // The lowest packet we've sent which is unacked, and we expect an ack for.
612 QuicPacketSequenceNumber least_unacked;
[email protected]8b37a092012-10-18 21:53:49613};
614
[email protected]26f3f8e2012-12-13 21:07:19615struct NET_EXPORT_PRIVATE QuicAckFrame {
616 QuicAckFrame() {}
617 // Testing convenience method to construct a QuicAckFrame with all packets
[email protected]48697d8a2013-01-15 19:42:24618 // from least_unacked to largest_observed acked.
619 QuicAckFrame(QuicPacketSequenceNumber largest_observed,
[email protected]14e8106c2013-03-14 16:25:33620 QuicTime largest_observed_receive_time,
[email protected]26f3f8e2012-12-13 21:07:19621 QuicPacketSequenceNumber least_unacked);
622
623 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
624 std::ostream& os, const QuicAckFrame& s);
625
626 SentPacketInfo sent_info;
627 ReceivedPacketInfo received_info;
628};
629
[email protected]8b37a092012-10-18 21:53:49630// Defines for all types of congestion feedback that will be negotiated in QUIC,
[email protected]f62262b2013-07-05 20:57:30631// kTCP MUST be supported by all QUIC implementations to guarantee 100%
[email protected]8b37a092012-10-18 21:53:49632// compatibility.
633enum CongestionFeedbackType {
[email protected]8b37a092012-10-18 21:53:49634 kTCP, // Used to mimic TCP.
635 kInterArrival, // Use additional inter arrival information.
636 kFixRate, // Provided for testing.
637};
638
639struct NET_EXPORT_PRIVATE CongestionFeedbackMessageTCP {
640 uint16 accumulated_number_of_lost_packets;
[email protected]fee17f72013-02-03 07:47:41641 QuicByteCount receive_window;
[email protected]8b37a092012-10-18 21:53:49642};
643
644struct NET_EXPORT_PRIVATE CongestionFeedbackMessageInterArrival {
[email protected]7884ecad2012-12-14 22:55:15645 CongestionFeedbackMessageInterArrival();
646 ~CongestionFeedbackMessageInterArrival();
[email protected]8b37a092012-10-18 21:53:49647 uint16 accumulated_number_of_lost_packets;
[email protected]7884ecad2012-12-14 22:55:15648 // The set of received packets since the last feedback was sent, along with
649 // their arrival times.
650 TimeMap received_packet_times;
[email protected]8b37a092012-10-18 21:53:49651};
652
[email protected]8b37a092012-10-18 21:53:49653struct NET_EXPORT_PRIVATE CongestionFeedbackMessageFixRate {
[email protected]fee17f72013-02-03 07:47:41654 CongestionFeedbackMessageFixRate();
655 QuicBandwidth bitrate;
[email protected]8b37a092012-10-18 21:53:49656};
657
[email protected]26f3f8e2012-12-13 21:07:19658struct NET_EXPORT_PRIVATE QuicCongestionFeedbackFrame {
[email protected]7884ecad2012-12-14 22:55:15659 QuicCongestionFeedbackFrame();
660 ~QuicCongestionFeedbackFrame();
661
[email protected]26f3f8e2012-12-13 21:07:19662 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
663 std::ostream& os, const QuicCongestionFeedbackFrame& c);
664
[email protected]7884ecad2012-12-14 22:55:15665 CongestionFeedbackType type;
666 // This should really be a union, but since the inter arrival struct
667 // is non-trivial, C++ prohibits it.
668 CongestionFeedbackMessageTCP tcp;
669 CongestionFeedbackMessageInterArrival inter_arrival;
670 CongestionFeedbackMessageFixRate fix_rate;
[email protected]8b37a092012-10-18 21:53:49671};
672
[email protected]be24ab22012-10-22 03:01:52673struct NET_EXPORT_PRIVATE QuicRstStreamFrame {
674 QuicRstStreamFrame() {}
[email protected]74bda142013-03-31 02:49:11675 QuicRstStreamFrame(QuicStreamId stream_id, QuicRstStreamErrorCode error_code)
[email protected]9db443912013-02-25 05:27:03676 : stream_id(stream_id), error_code(error_code) {
[email protected]431bb4fd2012-10-19 17:46:09677 DCHECK_LE(error_code, std::numeric_limits<uint8>::max());
[email protected]8b37a092012-10-18 21:53:49678 }
679
680 QuicStreamId stream_id;
[email protected]74bda142013-03-31 02:49:11681 QuicRstStreamErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09682 std::string error_details;
[email protected]8b37a092012-10-18 21:53:49683};
684
[email protected]be24ab22012-10-22 03:01:52685struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame {
[email protected]431bb4fd2012-10-19 17:46:09686 QuicErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09687 std::string error_details;
[email protected]8b37a092012-10-18 21:53:49688};
689
[email protected]9db443912013-02-25 05:27:03690struct NET_EXPORT_PRIVATE QuicGoAwayFrame {
691 QuicGoAwayFrame() {}
692 QuicGoAwayFrame(QuicErrorCode error_code,
693 QuicStreamId last_good_stream_id,
694 const std::string& reason);
695
696 QuicErrorCode error_code;
697 QuicStreamId last_good_stream_id;
698 std::string reason_phrase;
699};
700
[email protected]8ba81212013-05-03 13:11:48701// EncryptionLevel enumerates the stages of encryption that a QUIC connection
702// progresses through. When retransmitting a packet, the encryption level needs
703// to be specified so that it is retransmitted at a level which the peer can
704// understand.
705enum EncryptionLevel {
706 ENCRYPTION_NONE = 0,
707 ENCRYPTION_INITIAL = 1,
708 ENCRYPTION_FORWARD_SECURE = 2,
709
710 NUM_ENCRYPTION_LEVELS,
711};
712
[email protected]be24ab22012-10-22 03:01:52713struct NET_EXPORT_PRIVATE QuicFrame {
714 QuicFrame() {}
[email protected]c995c572013-01-18 05:43:20715 explicit QuicFrame(QuicPaddingFrame* padding_frame)
716 : type(PADDING_FRAME),
717 padding_frame(padding_frame) {
718 }
[email protected]be24ab22012-10-22 03:01:52719 explicit QuicFrame(QuicStreamFrame* stream_frame)
[email protected]610a7e942012-12-18 00:21:39720 : type(STREAM_FRAME),
721 stream_frame(stream_frame) {
[email protected]8b37a092012-10-18 21:53:49722 }
[email protected]be24ab22012-10-22 03:01:52723 explicit QuicFrame(QuicAckFrame* frame)
[email protected]610a7e942012-12-18 00:21:39724 : type(ACK_FRAME),
725 ack_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49726 }
[email protected]26f3f8e2012-12-13 21:07:19727 explicit QuicFrame(QuicCongestionFeedbackFrame* frame)
[email protected]610a7e942012-12-18 00:21:39728 : type(CONGESTION_FEEDBACK_FRAME),
729 congestion_feedback_frame(frame) {
[email protected]26f3f8e2012-12-13 21:07:19730 }
[email protected]be24ab22012-10-22 03:01:52731 explicit QuicFrame(QuicRstStreamFrame* frame)
732 : type(RST_STREAM_FRAME),
733 rst_stream_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49734 }
[email protected]be24ab22012-10-22 03:01:52735 explicit QuicFrame(QuicConnectionCloseFrame* frame)
736 : type(CONNECTION_CLOSE_FRAME),
737 connection_close_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49738 }
[email protected]9db443912013-02-25 05:27:03739 explicit QuicFrame(QuicGoAwayFrame* frame)
740 : type(GOAWAY_FRAME),
741 goaway_frame(frame) {
742 }
[email protected]8b37a092012-10-18 21:53:49743
[email protected]be24ab22012-10-22 03:01:52744 QuicFrameType type;
[email protected]8b37a092012-10-18 21:53:49745 union {
[email protected]c995c572013-01-18 05:43:20746 QuicPaddingFrame* padding_frame;
[email protected]be24ab22012-10-22 03:01:52747 QuicStreamFrame* stream_frame;
748 QuicAckFrame* ack_frame;
[email protected]26f3f8e2012-12-13 21:07:19749 QuicCongestionFeedbackFrame* congestion_feedback_frame;
[email protected]be24ab22012-10-22 03:01:52750 QuicRstStreamFrame* rst_stream_frame;
751 QuicConnectionCloseFrame* connection_close_frame;
[email protected]9db443912013-02-25 05:27:03752 QuicGoAwayFrame* goaway_frame;
[email protected]8b37a092012-10-18 21:53:49753 };
754};
755
[email protected]be24ab22012-10-22 03:01:52756typedef std::vector<QuicFrame> QuicFrames;
[email protected]8b37a092012-10-18 21:53:49757
758struct NET_EXPORT_PRIVATE QuicFecData {
759 QuicFecData();
[email protected]a5061242012-10-23 23:29:37760
[email protected]c995c572013-01-18 05:43:20761 // The FEC group number is also the sequence number of the first
762 // FEC protected packet. The last protected packet's sequence number will
763 // be one less than the sequence number of the FEC packet.
[email protected]8b37a092012-10-18 21:53:49764 QuicFecGroupNumber fec_group;
[email protected]8b37a092012-10-18 21:53:49765 base::StringPiece redundancy;
[email protected]8b37a092012-10-18 21:53:49766};
767
[email protected]8b37a092012-10-18 21:53:49768class NET_EXPORT_PRIVATE QuicData {
769 public:
770 QuicData(const char* buffer, size_t length)
771 : buffer_(buffer),
772 length_(length),
[email protected]5351cc4b2013-03-03 07:22:41773 owns_buffer_(false) {}
[email protected]8b37a092012-10-18 21:53:49774
775 QuicData(char* buffer, size_t length, bool owns_buffer)
776 : buffer_(buffer),
777 length_(length),
[email protected]5351cc4b2013-03-03 07:22:41778 owns_buffer_(owns_buffer) {}
[email protected]8b37a092012-10-18 21:53:49779
780 virtual ~QuicData();
781
782 base::StringPiece AsStringPiece() const {
783 return base::StringPiece(data(), length());
784 }
785
786 const char* data() const { return buffer_; }
787 size_t length() const { return length_; }
788
789 private:
790 const char* buffer_;
791 size_t length_;
792 bool owns_buffer_;
793
794 DISALLOW_COPY_AND_ASSIGN(QuicData);
795};
796
797class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
798 public:
[email protected]25c31dc2013-06-05 17:56:04799 static QuicPacket* NewDataPacket(
800 char* buffer,
801 size_t length,
802 bool owns_buffer,
803 QuicGuidLength guid_length,
804 bool includes_version,
805 QuicSequenceNumberLength sequence_number_length) {
806 return new QuicPacket(buffer, length, owns_buffer, guid_length,
807 includes_version, sequence_number_length, false);
[email protected]c995c572013-01-18 05:43:20808 }
809
[email protected]25c31dc2013-06-05 17:56:04810 static QuicPacket* NewFecPacket(
811 char* buffer,
812 size_t length,
813 bool owns_buffer,
814 QuicGuidLength guid_length,
815 bool includes_version,
816 QuicSequenceNumberLength sequence_number_length) {
817 return new QuicPacket(buffer, length, owns_buffer, guid_length,
818 includes_version, sequence_number_length, true);
[email protected]c995c572013-01-18 05:43:20819 }
[email protected]8b37a092012-10-18 21:53:49820
[email protected]5351cc4b2013-03-03 07:22:41821 base::StringPiece FecProtectedData() const;
822 base::StringPiece AssociatedData() const;
823 base::StringPiece BeforePlaintext() const;
824 base::StringPiece Plaintext() const;
[email protected]082b65b2012-11-10 19:11:31825
[email protected]c995c572013-01-18 05:43:20826 bool is_fec_packet() const { return is_fec_packet_; }
[email protected]082b65b2012-11-10 19:11:31827
[email protected]8b37a092012-10-18 21:53:49828 char* mutable_data() { return buffer_; }
829
830 private:
[email protected]5351cc4b2013-03-03 07:22:41831 QuicPacket(char* buffer,
832 size_t length,
833 bool owns_buffer,
[email protected]b064310782013-05-30 21:12:17834 QuicGuidLength guid_length,
[email protected]5351cc4b2013-03-03 07:22:41835 bool includes_version,
[email protected]25c31dc2013-06-05 17:56:04836 QuicSequenceNumberLength sequence_number_length,
[email protected]5351cc4b2013-03-03 07:22:41837 bool is_fec_packet)
[email protected]c995c572013-01-18 05:43:20838 : QuicData(buffer, length, owns_buffer),
839 buffer_(buffer),
[email protected]5351cc4b2013-03-03 07:22:41840 is_fec_packet_(is_fec_packet),
[email protected]b064310782013-05-30 21:12:17841 guid_length_(guid_length),
[email protected]25c31dc2013-06-05 17:56:04842 includes_version_(includes_version),
843 sequence_number_length_(sequence_number_length) {}
[email protected]c995c572013-01-18 05:43:20844
[email protected]8b37a092012-10-18 21:53:49845 char* buffer_;
[email protected]c995c572013-01-18 05:43:20846 const bool is_fec_packet_;
[email protected]b064310782013-05-30 21:12:17847 const QuicGuidLength guid_length_;
[email protected]5351cc4b2013-03-03 07:22:41848 const bool includes_version_;
[email protected]25c31dc2013-06-05 17:56:04849 const QuicSequenceNumberLength sequence_number_length_;
[email protected]8b37a092012-10-18 21:53:49850
[email protected]2e740db2012-10-20 19:35:19851 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
[email protected]8b37a092012-10-18 21:53:49852};
853
854class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
855 public:
856 QuicEncryptedPacket(const char* buffer, size_t length)
[email protected]5351cc4b2013-03-03 07:22:41857 : QuicData(buffer, length) {}
[email protected]8b37a092012-10-18 21:53:49858
859 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer)
[email protected]5351cc4b2013-03-03 07:22:41860 : QuicData(buffer, length, owns_buffer) {}
[email protected]8b37a092012-10-18 21:53:49861
[email protected]ec86d5462013-11-17 16:04:49862 // Clones the packet into a new packet which owns the buffer.
863 QuicEncryptedPacket* Clone() const;
864
[email protected]c1b32c62013-01-20 02:49:10865 // By default, gtest prints the raw bytes of an object. The bool data
866 // member (in the base class QuicData) causes this object to have padding
867 // bytes, which causes the default gtest object printer to read
868 // uninitialize memory. So we need to teach gtest how to print this object.
869 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
870 std::ostream& os, const QuicEncryptedPacket& s);
871
[email protected]2e740db2012-10-20 19:35:19872 private:
873 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
[email protected]8b37a092012-10-18 21:53:49874};
875
[email protected]9db443912013-02-25 05:27:03876class NET_EXPORT_PRIVATE RetransmittableFrames {
877 public:
878 RetransmittableFrames();
879 ~RetransmittableFrames();
880
881 // Allocates a local copy of the referenced StringPiece has QuicStreamFrame
882 // use it.
883 // Takes ownership of |stream_frame|.
884 const QuicFrame& AddStreamFrame(QuicStreamFrame* stream_frame);
885 // Takes ownership of the frame inside |frame|.
886 const QuicFrame& AddNonStreamFrame(const QuicFrame& frame);
887 const QuicFrames& frames() const { return frames_; }
888
[email protected]8ba81212013-05-03 13:11:48889 void set_encryption_level(EncryptionLevel level);
890 EncryptionLevel encryption_level() const {
891 return encryption_level_;
892 }
893
[email protected]9db443912013-02-25 05:27:03894 private:
895 QuicFrames frames_;
[email protected]8ba81212013-05-03 13:11:48896 EncryptionLevel encryption_level_;
[email protected]9db443912013-02-25 05:27:03897 // Data referenced by the StringPiece of a QuicStreamFrame.
898 std::vector<std::string*> stream_data_;
899
900 DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames);
901};
902
903struct NET_EXPORT_PRIVATE SerializedPacket {
904 SerializedPacket(QuicPacketSequenceNumber sequence_number,
[email protected]ea825e02013-08-21 18:12:45905 QuicSequenceNumberLength sequence_number_length,
[email protected]9db443912013-02-25 05:27:03906 QuicPacket* packet,
907 QuicPacketEntropyHash entropy_hash,
[email protected]97cf3022013-09-05 14:30:16908 RetransmittableFrames* retransmittable_frames);
909 ~SerializedPacket();
[email protected]9db443912013-02-25 05:27:03910
911 QuicPacketSequenceNumber sequence_number;
[email protected]ea825e02013-08-21 18:12:45912 QuicSequenceNumberLength sequence_number_length;
[email protected]9db443912013-02-25 05:27:03913 QuicPacket* packet;
914 QuicPacketEntropyHash entropy_hash;
915 RetransmittableFrames* retransmittable_frames;
[email protected]97cf3022013-09-05 14:30:16916
917 // If set, these will be called when this packet is ACKed by the peer.
918 std::set<QuicAckNotifier*> notifiers;
[email protected]9db443912013-02-25 05:27:03919};
920
[email protected]c995c572013-01-18 05:43:20921// A struct for functions which consume data payloads and fins.
[email protected]c995c572013-01-18 05:43:20922struct QuicConsumedData {
923 QuicConsumedData(size_t bytes_consumed, bool fin_consumed)
924 : bytes_consumed(bytes_consumed),
[email protected]5351cc4b2013-03-03 07:22:41925 fin_consumed(fin_consumed) {}
[email protected]c1b32c62013-01-20 02:49:10926 // By default, gtest prints the raw bytes of an object. The bool data
927 // member causes this object to have padding bytes, which causes the
928 // default gtest object printer to read uninitialize memory. So we need
929 // to teach gtest how to print this object.
930 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
931 std::ostream& os, const QuicConsumedData& s);
932
[email protected]97cf3022013-09-05 14:30:16933 // How many bytes were consumed.
[email protected]c995c572013-01-18 05:43:20934 size_t bytes_consumed;
[email protected]97cf3022013-09-05 14:30:16935
936 // True if an incoming fin was consumed.
[email protected]c995c572013-01-18 05:43:20937 bool fin_consumed;
938};
939
[email protected]752fbe52013-10-14 08:35:32940enum WriteStatus {
941 WRITE_STATUS_OK,
942 WRITE_STATUS_BLOCKED,
943 WRITE_STATUS_ERROR,
944};
945
946// A struct used to return the result of write calls including either the number
947// of bytes written or the error code, depending upon the status.
948struct NET_EXPORT_PRIVATE WriteResult {
949 WriteResult(WriteStatus status, int bytes_written_or_error_code) :
950 status(status), bytes_written(bytes_written_or_error_code) {
951 }
952
953 WriteStatus status;
954 union {
955 int bytes_written; // only valid when status is OK
956 int error_code; // only valid when status is ERROR
957 };
958};
959
[email protected]8b37a092012-10-18 21:53:49960} // namespace net
961
962#endif // NET_QUIC_QUIC_PROTOCOL_H_