blob: 650eb6b68e5aee59aa98e9c7fcaa1dfafa4b6df4 [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,
52// minus the IP and UDP headers.
53const QuicByteCount kMaxPacketSize = 1472;
54
55// Maximum size of the initial congestion window in packets.
56const size_t kDefaultInitialWindow = 10;
57const size_t kMaxInitialWindow = 100;
58
59// Don't allow a client to suggest an RTT longer than 15 seconds.
[email protected]e18e1072013-11-12 22:06:0760const size_t kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond;
[email protected]8b37a092012-10-18 21:53:4961
62// Maximum number of open streams per connection.
63const size_t kDefaultMaxStreamsPerConnection = 100;
64
[email protected]af806e62013-05-22 14:47:5065// Number of bytes reserved for public flags in the packet header.
66const size_t kPublicFlagsSize = 1;
[email protected]5351cc4b2013-03-03 07:22:4167// Number of bytes reserved for version number in the packet header.
68const size_t kQuicVersionSize = 4;
[email protected]c995c572013-01-18 05:43:2069// Number of bytes reserved for private flags in the packet header.
70const size_t kPrivateFlagsSize = 1;
71// Number of bytes reserved for FEC group in the packet header.
72const size_t kFecGroupSize = 1;
[email protected]86a318d2013-01-23 21:16:0473// Number of bytes reserved for the nonce proof in public reset packet.
74const size_t kPublicResetNonceSize = 8;
[email protected]5351cc4b2013-03-03 07:22:4175
76// Signifies that the QuicPacket will contain version of the protocol.
77const bool kIncludeVersion = true;
[email protected]c995c572013-01-18 05:43:2078
[email protected]5351cc4b2013-03-03 07:22:4179// Index of the first byte in a QUIC packet which is used in hash calculation.
80const size_t kStartOfHashData = 0;
[email protected]8b37a092012-10-18 21:53:4981
82// Limit on the delta between stream IDs.
83const QuicStreamId kMaxStreamIdDelta = 100;
[email protected]c244c5a12013-05-07 20:55:0484// Limit on the delta between header IDs.
85const QuicHeaderId kMaxHeaderIdDelta = 100;
[email protected]8b37a092012-10-18 21:53:4986
87// Reserved ID for the crypto stream.
88// TODO(rch): ensure that this is not usable by any other streams.
89const QuicStreamId kCryptoStreamId = 1;
90
[email protected]899951652013-05-16 12:52:3991// This is the default network timeout a for connection till the crypto
92// handshake succeeds and the negotiated timeout from the handshake is received.
[email protected]b064310782013-05-30 21:12:1793const int64 kDefaultInitialTimeoutSecs = 120; // 2 mins.
[email protected]899951652013-05-16 12:52:3994const int64 kDefaultTimeoutSecs = 60 * 10; // 10 minutes.
[email protected]b064310782013-05-30 21:12:1795const int64 kDefaultMaxTimeForCryptoHandshakeSecs = 5; // 5 secs.
[email protected]8b37a092012-10-18 21:53:4996
[email protected]b007e632013-10-28 08:39:2597// We define an unsigned 16-bit floating point value, inspired by IEEE floats
98// (http://en.wikipedia.org/wiki/Half_precision_floating-point_format),
99// with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden
100// bit) and denormals, but without signs, transfinites or fractions. Wire format
101// 16 bits (little-endian byte order) are split into exponent (high 5) and
102// mantissa (low 11) and decoded as:
103// uint64 value;
104// if (exponent == 0) value = mantissa;
105// else value = (mantissa | 1 << 11) << (exponent - 1)
106const int kUFloat16ExponentBits = 5;
107const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30
108const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11
109const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12
110const uint64 kUFloat16MaxValue = // 0x3FFC0000000
111 ((GG_UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1) <<
112 kUFloat16MaxExponent;
113
[email protected]c67a82cb2013-09-24 02:53:21114enum TransmissionType {
[email protected]2532de12013-05-09 12:29:33115 NOT_RETRANSMISSION,
[email protected]c67a82cb2013-09-24 02:53:21116 NACK_RETRANSMISSION,
117 RTO_RETRANSMISSION,
[email protected]74bda142013-03-31 02:49:11118};
119
120enum HasRetransmittableData {
[email protected]2532de12013-05-09 12:29:33121 NO_RETRANSMITTABLE_DATA,
122 HAS_RETRANSMITTABLE_DATA,
[email protected]74bda142013-03-31 02:49:11123};
124
[email protected]575cce62013-08-03 02:06:43125enum IsHandshake {
126 NOT_HANDSHAKE,
127 IS_HANDSHAKE
128};
129
[email protected]be24ab22012-10-22 03:01:52130enum QuicFrameType {
[email protected]c995c572013-01-18 05:43:20131 PADDING_FRAME = 0,
[email protected]be24ab22012-10-22 03:01:52132 RST_STREAM_FRAME,
133 CONNECTION_CLOSE_FRAME,
[email protected]9db443912013-02-25 05:27:03134 GOAWAY_FRAME,
[email protected]97cf3022013-09-05 14:30:16135 STREAM_FRAME,
136 ACK_FRAME,
137 CONGESTION_FEEDBACK_FRAME,
[email protected]be24ab22012-10-22 03:01:52138 NUM_FRAME_TYPES
[email protected]8b37a092012-10-18 21:53:49139};
140
[email protected]b064310782013-05-30 21:12:17141enum QuicGuidLength {
142 PACKET_0BYTE_GUID = 0,
143 PACKET_1BYTE_GUID = 1,
144 PACKET_4BYTE_GUID = 4,
145 PACKET_8BYTE_GUID = 8
146};
147
148enum InFecGroup {
149 NOT_IN_FEC_GROUP,
150 IN_FEC_GROUP,
151};
152
[email protected]25c31dc2013-06-05 17:56:04153enum QuicSequenceNumberLength {
154 PACKET_1BYTE_SEQUENCE_NUMBER = 1,
155 PACKET_2BYTE_SEQUENCE_NUMBER = 2,
156 PACKET_4BYTE_SEQUENCE_NUMBER = 4,
157 PACKET_6BYTE_SEQUENCE_NUMBER = 6
158};
159
[email protected]8e01c062013-10-31 07:35:31160// Used to indicate a QuicSequenceNumberLength using two flag bits.
161enum QuicSequenceNumberLengthFlags {
162 PACKET_FLAGS_1BYTE_SEQUENCE = 0, // 00
163 PACKET_FLAGS_2BYTE_SEQUENCE = 1, // 01
164 PACKET_FLAGS_4BYTE_SEQUENCE = 1 << 1, // 10
165 PACKET_FLAGS_6BYTE_SEQUENCE = 1 << 1 | 1, // 11
166};
167
[email protected]f62262b2013-07-05 20:57:30168// The public flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20169enum QuicPacketPublicFlags {
170 PACKET_PUBLIC_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30171
172 // Bit 0: Does the packet header contains version info?
173 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0,
174
175 // Bit 1: Is this packet a public reset packet?
176 PACKET_PUBLIC_FLAGS_RST = 1 << 1,
177
178 // Bits 2 and 3 specify the length of the GUID as follows:
179 // ----00--: 0 bytes
180 // ----01--: 1 byte
181 // ----10--: 4 bytes
182 // ----11--: 8 bytes
[email protected]1354bf62013-05-23 23:17:18183 PACKET_PUBLIC_FLAGS_0BYTE_GUID = 0,
184 PACKET_PUBLIC_FLAGS_1BYTE_GUID = 1 << 2,
185 PACKET_PUBLIC_FLAGS_4BYTE_GUID = 1 << 3,
186 PACKET_PUBLIC_FLAGS_8BYTE_GUID = 1 << 3 | 1 << 2,
[email protected]f62262b2013-07-05 20:57:30187
188 // Bits 4 and 5 describe the packet sequence number length as follows:
189 // --00----: 1 byte
190 // --01----: 2 bytes
191 // --10----: 4 bytes
192 // --11----: 6 bytes
[email protected]8e01c062013-10-31 07:35:31193 PACKET_PUBLIC_FLAGS_1BYTE_SEQUENCE = PACKET_FLAGS_1BYTE_SEQUENCE << 4,
194 PACKET_PUBLIC_FLAGS_2BYTE_SEQUENCE = PACKET_FLAGS_2BYTE_SEQUENCE << 4,
195 PACKET_PUBLIC_FLAGS_4BYTE_SEQUENCE = PACKET_FLAGS_4BYTE_SEQUENCE << 4,
196 PACKET_PUBLIC_FLAGS_6BYTE_SEQUENCE = PACKET_FLAGS_6BYTE_SEQUENCE << 4,
[email protected]f62262b2013-07-05 20:57:30197
198 // All bits set (bits 6 and 7 are not currently used): 00111111
199 PACKET_PUBLIC_FLAGS_MAX = (1 << 6) - 1
[email protected]c995c572013-01-18 05:43:20200};
[email protected]8b37a092012-10-18 21:53:49201
[email protected]f62262b2013-07-05 20:57:30202// The private flags are specified in one byte.
[email protected]c995c572013-01-18 05:43:20203enum QuicPacketPrivateFlags {
204 PACKET_PRIVATE_FLAGS_NONE = 0,
[email protected]f62262b2013-07-05 20:57:30205
206 // Bit 0: Does this packet contain an entropy bit?
[email protected]b064310782013-05-30 21:12:17207 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0,
[email protected]f62262b2013-07-05 20:57:30208
209 // Bit 1: Payload is part of an FEC group?
210 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1,
211
212 // Bit 2: Payload is FEC as opposed to frames?
213 PACKET_PRIVATE_FLAGS_FEC = 1 << 2,
214
215 // All bits set (bits 3-7 are not currently used): 00000111
216 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1
[email protected]c995c572013-01-18 05:43:20217};
218
[email protected]48878092013-07-26 14:51:56219// The available versions of QUIC. Guaranteed that the integer value of the enum
220// will match the version number.
221// When adding a new version to this enum you should add it to
[email protected]8bbfaeb72013-08-09 06:38:26222// kSupportedQuicVersions (if appropriate), and also add a new case to the
223// helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and
224// QuicVersionToString.
[email protected]48878092013-07-26 14:51:56225enum QuicVersion {
226 // Special case to indicate unknown/unsupported QUIC version.
227 QUIC_VERSION_UNSUPPORTED = 0,
228
[email protected]8e01c062013-10-31 07:35:31229 QUIC_VERSION_11 = 11,
230 QUIC_VERSION_12 = 12, // Current version.
[email protected]48878092013-07-26 14:51:56231};
232
233// This vector contains QUIC versions which we currently support.
234// This should be ordered such that the highest supported version is the first
235// element, with subsequent elements in descending order (versions can be
236// skipped as necessary).
[email protected]3e60db82013-08-05 19:43:06237static const QuicVersion kSupportedQuicVersions[] =
[email protected]933da772013-11-13 20:45:46238 {QUIC_VERSION_12};
[email protected]48878092013-07-26 14:51:56239
240typedef std::vector<QuicVersion> QuicVersionVector;
241
[email protected]b007e632013-10-28 08:39:25242// Returns a vector of QUIC versions in kSupportedQuicVersions.
243NET_EXPORT_PRIVATE QuicVersionVector QuicSupportedVersions();
[email protected]ea2ab47b2013-08-13 00:44:11244
[email protected]48878092013-07-26 14:51:56245// QuicTag is written to and read from the wire, but we prefer to use
246// the more readable QuicVersion at other levels.
247// Helper function which translates from a QuicVersion to a QuicTag. Returns 0
248// if QuicVersion is unsupported.
249NET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version);
250
251// Returns appropriate QuicVersion from a QuicTag.
252// Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood.
253NET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag);
254
255// Helper function which translates from a QuicVersion to a string.
256// Returns strings corresponding to enum names (e.g. QUIC_VERSION_6).
257NET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version);
258
259// Returns comma separated list of string representations of QuicVersion enum
[email protected]b007e632013-10-28 08:39:25260// values in the supplied |versions| vector.
261NET_EXPORT_PRIVATE std::string QuicVersionVectorToString(
262 const QuicVersionVector& versions);
[email protected]48878092013-07-26 14:51:56263
264// Version and Crypto tags are written to the wire with a big-endian
265// representation of the name of the tag. For example
266// the client hello tag (CHLO) will be written as the
267// following 4 bytes: 'C' 'H' 'L' 'O'. Since it is
268// stored in memory as a little endian uint32, we need
269// to reverse the order of the bytes.
270
271// MakeQuicTag returns a value given the four bytes. For example:
272// MakeQuicTag('C', 'H', 'L', 'O');
273NET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d);
274
[email protected]b064310782013-05-30 21:12:17275// Size in bytes of the data or fec packet header.
276NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicPacketHeader header);
277
[email protected]25c31dc2013-06-05 17:56:04278NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(
279 QuicGuidLength guid_length,
280 bool include_version,
281 QuicSequenceNumberLength sequence_number_length,
282 InFecGroup is_in_fec_group);
[email protected]b064310782013-05-30 21:12:17283
284// Size in bytes of the public reset packet.
285NET_EXPORT_PRIVATE size_t GetPublicResetPacketSize();
286
287// Index of the first byte in a QUIC packet of FEC protected data.
[email protected]25c31dc2013-06-05 17:56:04288NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(
289 QuicGuidLength guid_length,
290 bool include_version,
291 QuicSequenceNumberLength sequence_number_length);
[email protected]b064310782013-05-30 21:12:17292// Index of the first byte in a QUIC packet of encrypted data.
[email protected]25c31dc2013-06-05 17:56:04293NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(
294 QuicGuidLength guid_length,
295 bool include_version,
296 QuicSequenceNumberLength sequence_number_length);
[email protected]b064310782013-05-30 21:12:17297
[email protected]74bda142013-03-31 02:49:11298enum QuicRstStreamErrorCode {
299 QUIC_STREAM_NO_ERROR = 0,
[email protected]8b37a092012-10-18 21:53:49300
[email protected]24e5bc52013-09-18 15:36:58301 // There was some error which halted stream processing.
302 QUIC_ERROR_PROCESSING_STREAM,
[email protected]8b37a092012-10-18 21:53:49303 // We got two fin or reset offsets which did not match.
304 QUIC_MULTIPLE_TERMINATION_OFFSETS,
305 // We got bad payload and can not respond to it at the protocol level.
306 QUIC_BAD_APPLICATION_PAYLOAD,
[email protected]74bda142013-03-31 02:49:11307 // Stream closed due to connection error. No reset frame is sent when this
308 // happens.
309 QUIC_STREAM_CONNECTION_ERROR,
310 // GoAway frame sent. No more stream can be created.
311 QUIC_STREAM_PEER_GOING_AWAY,
[email protected]06ff5152013-08-29 01:03:05312 // The stream has been cancelled.
313 QUIC_STREAM_CANCELLED,
[email protected]8b37a092012-10-18 21:53:49314
[email protected]74bda142013-03-31 02:49:11315 // No error. Used as bound while iterating.
316 QUIC_STREAM_LAST_ERROR,
317};
[email protected]8b37a092012-10-18 21:53:49318
[email protected]89264042013-08-21 07:35:24319// These values must remain stable as they are uploaded to UMA histograms.
320// To add a new error code, use the current value of QUIC_LAST_ERROR and
321// increment QUIC_LAST_ERROR.
[email protected]74bda142013-03-31 02:49:11322enum QuicErrorCode {
323 QUIC_NO_ERROR = 0,
324
325 // Connection has reached an invalid state.
[email protected]89264042013-08-21 07:35:24326 QUIC_INTERNAL_ERROR = 1,
[email protected]74bda142013-03-31 02:49:11327 // There were data frames after the a fin or reset.
[email protected]89264042013-08-21 07:35:24328 QUIC_STREAM_DATA_AFTER_TERMINATION = 2,
[email protected]8b37a092012-10-18 21:53:49329 // Control frame is malformed.
[email protected]89264042013-08-21 07:35:24330 QUIC_INVALID_PACKET_HEADER = 3,
[email protected]be24ab22012-10-22 03:01:52331 // Frame data is malformed.
[email protected]89264042013-08-21 07:35:24332 QUIC_INVALID_FRAME_DATA = 4,
333 // The packet contained no payload.
334 QUIC_MISSING_PAYLOAD = 48,
[email protected]8b37a092012-10-18 21:53:49335 // FEC data is malformed.
[email protected]89264042013-08-21 07:35:24336 QUIC_INVALID_FEC_DATA = 5,
337 // STREAM frame data is malformed.
338 QUIC_INVALID_STREAM_DATA = 46,
339 // RST_STREAM frame data is malformed.
340 QUIC_INVALID_RST_STREAM_DATA = 6,
341 // CONNECTION_CLOSE frame data is malformed.
342 QUIC_INVALID_CONNECTION_CLOSE_DATA = 7,
343 // GOAWAY frame data is malformed.
344 QUIC_INVALID_GOAWAY_DATA = 8,
345 // ACK frame data is malformed.
346 QUIC_INVALID_ACK_DATA = 9,
347 // CONGESTION_FEEDBACK frame data is malformed.
348 QUIC_INVALID_CONGESTION_FEEDBACK_DATA = 47,
[email protected]14e8106c2013-03-14 16:25:33349 // Version negotiation packet is malformed.
[email protected]89264042013-08-21 07:35:24350 QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10,
[email protected]899951652013-05-16 12:52:39351 // Public RST packet is malformed.
[email protected]89264042013-08-21 07:35:24352 QUIC_INVALID_PUBLIC_RST_PACKET = 11,
[email protected]8b37a092012-10-18 21:53:49353 // There was an error decrypting.
[email protected]89264042013-08-21 07:35:24354 QUIC_DECRYPTION_FAILURE = 12,
[email protected]8b37a092012-10-18 21:53:49355 // There was an error encrypting.
[email protected]89264042013-08-21 07:35:24356 QUIC_ENCRYPTION_FAILURE = 13,
[email protected]8b37a092012-10-18 21:53:49357 // The packet exceeded kMaxPacketSize.
[email protected]89264042013-08-21 07:35:24358 QUIC_PACKET_TOO_LARGE = 14,
[email protected]8b37a092012-10-18 21:53:49359 // Data was sent for a stream which did not exist.
[email protected]89264042013-08-21 07:35:24360 QUIC_PACKET_FOR_NONEXISTENT_STREAM = 15,
[email protected]9db443912013-02-25 05:27:03361 // The peer is going away. May be a client or server.
[email protected]89264042013-08-21 07:35:24362 QUIC_PEER_GOING_AWAY = 16,
[email protected]8b37a092012-10-18 21:53:49363 // A stream ID was invalid.
[email protected]89264042013-08-21 07:35:24364 QUIC_INVALID_STREAM_ID = 17,
[email protected]24e5bc52013-09-18 15:36:58365 // A priority was invalid.
366 QUIC_INVALID_PRIORITY = 49,
[email protected]8b37a092012-10-18 21:53:49367 // Too many streams already open.
[email protected]89264042013-08-21 07:35:24368 QUIC_TOO_MANY_OPEN_STREAMS = 18,
[email protected]86a318d2013-01-23 21:16:04369 // Received public reset for this connection.
[email protected]89264042013-08-21 07:35:24370 QUIC_PUBLIC_RESET = 19,
[email protected]c244c5a12013-05-07 20:55:04371 // Invalid protocol version.
[email protected]89264042013-08-21 07:35:24372 QUIC_INVALID_VERSION = 20,
[email protected]c244c5a12013-05-07 20:55:04373 // Stream reset before headers decompressed.
[email protected]89264042013-08-21 07:35:24374 QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED = 21,
[email protected]c244c5a12013-05-07 20:55:04375 // The Header ID for a stream was too far from the previous.
[email protected]89264042013-08-21 07:35:24376 QUIC_INVALID_HEADER_ID = 22,
[email protected]899951652013-05-16 12:52:39377 // Negotiable parameter received during handshake had invalid value.
[email protected]89264042013-08-21 07:35:24378 QUIC_INVALID_NEGOTIATED_VALUE = 23,
[email protected]899951652013-05-16 12:52:39379 // There was an error decompressing data.
[email protected]89264042013-08-21 07:35:24380 QUIC_DECOMPRESSION_FAILURE = 24,
[email protected]8b37a092012-10-18 21:53:49381 // We hit our prenegotiated (or default) timeout
[email protected]89264042013-08-21 07:35:24382 QUIC_CONNECTION_TIMED_OUT = 25,
[email protected]899951652013-05-16 12:52:39383 // There was an error encountered migrating addresses
[email protected]89264042013-08-21 07:35:24384 QUIC_ERROR_MIGRATING_ADDRESS = 26,
[email protected]1505a512013-09-04 22:59:35385 // There was an error while writing to the socket.
[email protected]89264042013-08-21 07:35:24386 QUIC_PACKET_WRITE_ERROR = 27,
[email protected]1505a512013-09-04 22:59:35387 // There was an error while reading from the socket.
388 QUIC_PACKET_READ_ERROR = 51,
[email protected]24e5bc52013-09-18 15:36:58389 // We received a STREAM_FRAME with no data and no fin flag set.
390 QUIC_INVALID_STREAM_FRAME = 50,
[email protected]899951652013-05-16 12:52:39391
[email protected]8b37a092012-10-18 21:53:49392
393 // Crypto errors.
394
[email protected]1354bf62013-05-23 23:17:18395 // Hanshake failed.
[email protected]89264042013-08-21 07:35:24396 QUIC_HANDSHAKE_FAILED = 28,
[email protected]8b37a092012-10-18 21:53:49397 // Handshake message contained out of order tags.
[email protected]89264042013-08-21 07:35:24398 QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29,
[email protected]701bc892013-01-17 04:51:54399 // Handshake message contained too many entries.
[email protected]89264042013-08-21 07:35:24400 QUIC_CRYPTO_TOO_MANY_ENTRIES = 30,
[email protected]8b37a092012-10-18 21:53:49401 // Handshake message contained an invalid value length.
[email protected]89264042013-08-21 07:35:24402 QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31,
[email protected]8b37a092012-10-18 21:53:49403 // A crypto message was received after the handshake was complete.
[email protected]89264042013-08-21 07:35:24404 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32,
[email protected]d3d15bf2013-01-30 02:51:54405 // A crypto message was received with an illegal message tag.
[email protected]89264042013-08-21 07:35:24406 QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33,
[email protected]d3d15bf2013-01-30 02:51:54407 // A crypto message was received with an illegal parameter.
[email protected]89264042013-08-21 07:35:24408 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34,
[email protected]752fbe52013-10-14 08:35:32409 // An invalid channel id signature was supplied.
410 QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52,
[email protected]d3d15bf2013-01-30 02:51:54411 // A crypto message was received with a mandatory parameter missing.
[email protected]89264042013-08-21 07:35:24412 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35,
[email protected]d3d15bf2013-01-30 02:51:54413 // A crypto message was received with a parameter that has no overlap
414 // with the local parameter.
[email protected]89264042013-08-21 07:35:24415 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36,
[email protected]ed3fc15d2013-03-08 18:37:44416 // A crypto message was received that contained a parameter with too few
417 // values.
[email protected]89264042013-08-21 07:35:24418 QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37,
[email protected]ccc66e8a2013-03-26 08:26:14419 // An internal error occured in crypto processing.
[email protected]89264042013-08-21 07:35:24420 QUIC_CRYPTO_INTERNAL_ERROR = 38,
[email protected]ccc66e8a2013-03-26 08:26:14421 // A crypto handshake message specified an unsupported version.
[email protected]89264042013-08-21 07:35:24422 QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39,
[email protected]ccc66e8a2013-03-26 08:26:14423 // There was no intersection between the crypto primitives supported by the
424 // peer and ourselves.
[email protected]89264042013-08-21 07:35:24425 QUIC_CRYPTO_NO_SUPPORT = 40,
[email protected]ef95114d2013-04-17 17:57:01426 // The server rejected our client hello messages too many times.
[email protected]89264042013-08-21 07:35:24427 QUIC_CRYPTO_TOO_MANY_REJECTS = 41,
[email protected]a57e0272013-04-26 07:31:47428 // The client rejected the server's certificate chain or signature.
[email protected]89264042013-08-21 07:35:24429 QUIC_PROOF_INVALID = 42,
[email protected]8ba81212013-05-03 13:11:48430 // A crypto message was received with a duplicate tag.
[email protected]89264042013-08-21 07:35:24431 QUIC_CRYPTO_DUPLICATE_TAG = 43,
[email protected]2532de12013-05-09 12:29:33432 // A crypto message was received with the wrong encryption level (i.e. it
433 // should have been encrypted but was not.)
[email protected]89264042013-08-21 07:35:24434 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44,
[email protected]2532de12013-05-09 12:29:33435 // The server config for a server has expired.
[email protected]89264042013-08-21 07:35:24436 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45,
[email protected]752fbe52013-10-14 08:35:32437 // We failed to setup the symmetric keys for a connection.
438 QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53,
[email protected]ccc66e8a2013-03-26 08:26:14439
[email protected]74bda142013-03-31 02:49:11440 // No error. Used as bound while iterating.
[email protected]752fbe52013-10-14 08:35:32441 QUIC_LAST_ERROR = 54,
[email protected]8b37a092012-10-18 21:53:49442};
443
[email protected]c995c572013-01-18 05:43:20444struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
[email protected]14e8106c2013-03-14 16:25:33445 QuicPacketPublicHeader();
446 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
447 ~QuicPacketPublicHeader();
448
[email protected]c995c572013-01-18 05:43:20449 // Universal header. All QuicPacket headers will have a guid and public flags.
[email protected]8b37a092012-10-18 21:53:49450 QuicGuid guid;
[email protected]b064310782013-05-30 21:12:17451 QuicGuidLength guid_length;
[email protected]9db443912013-02-25 05:27:03452 bool reset_flag;
453 bool version_flag;
[email protected]25c31dc2013-06-05 17:56:04454 QuicSequenceNumberLength sequence_number_length;
[email protected]48878092013-07-26 14:51:56455 QuicVersionVector versions;
[email protected]c995c572013-01-18 05:43:20456};
457
458// Header for Data or FEC packets.
[email protected]74bda142013-03-31 02:49:11459struct NET_EXPORT_PRIVATE QuicPacketHeader {
460 QuicPacketHeader();
461 explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
[email protected]9db443912013-02-25 05:27:03462
463 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
464 std::ostream& os, const QuicPacketHeader& s);
465
[email protected]c995c572013-01-18 05:43:20466 QuicPacketPublicHeader public_header;
[email protected]9db443912013-02-25 05:27:03467 bool fec_flag;
[email protected]9db443912013-02-25 05:27:03468 bool entropy_flag;
469 QuicPacketEntropyHash entropy_hash;
[email protected]8b37a092012-10-18 21:53:49470 QuicPacketSequenceNumber packet_sequence_number;
[email protected]b064310782013-05-30 21:12:17471 InFecGroup is_in_fec_group;
[email protected]8b37a092012-10-18 21:53:49472 QuicFecGroupNumber fec_group;
473};
474
[email protected]74bda142013-03-31 02:49:11475struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
[email protected]86a318d2013-01-23 21:16:04476 QuicPublicResetPacket() {}
477 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header)
478 : public_header(header) {}
479 QuicPacketPublicHeader public_header;
480 QuicPacketSequenceNumber rejected_sequence_number;
481 QuicPublicResetNonceProof nonce_proof;
482};
483
[email protected]14e8106c2013-03-14 16:25:33484enum QuicVersionNegotiationState {
485 START_NEGOTIATION = 0,
[email protected]ec640112013-08-09 03:56:18486 // Server-side this implies we've sent a version negotiation packet and are
487 // waiting on the client to select a compatible version. Client-side this
488 // implies we've gotten a version negotiation packet, are retransmitting the
489 // initial packets with a supported version and are waiting for our first
490 // packet from the server.
491 NEGOTIATION_IN_PROGRESS,
492 // This indicates this endpoint has received a packet from the peer with a
493 // version this endpoint supports. Version negotiation is complete, and the
494 // version number will no longer be sent with future packets.
[email protected]14e8106c2013-03-14 16:25:33495 NEGOTIATED_VERSION
496};
497
498typedef QuicPacketPublicHeader QuicVersionNegotiationPacket;
499
[email protected]c995c572013-01-18 05:43:20500// A padding frame contains no payload.
501struct NET_EXPORT_PRIVATE QuicPaddingFrame {
502};
503
[email protected]be24ab22012-10-22 03:01:52504struct NET_EXPORT_PRIVATE QuicStreamFrame {
505 QuicStreamFrame();
[email protected]5dafdb62013-11-14 01:24:26506 QuicStreamFrame(const QuicStreamFrame& frame);
[email protected]be24ab22012-10-22 03:01:52507 QuicStreamFrame(QuicStreamId stream_id,
[email protected]a5061242012-10-23 23:29:37508 bool fin,
[email protected]701bc892013-01-17 04:51:54509 QuicStreamOffset offset,
[email protected]5dafdb62013-11-14 01:24:26510 IOVector data);
511
512 // Returns a copy of the IOVector |data| as a heap-allocated string.
513 // Caller must take ownership of the returned string.
514 std::string* GetDataAsString() const;
[email protected]8b37a092012-10-18 21:53:49515
516 QuicStreamId stream_id;
517 bool fin;
[email protected]701bc892013-01-17 04:51:54518 QuicStreamOffset offset; // Location of this data in the stream.
[email protected]5dafdb62013-11-14 01:24:26519 IOVector data;
[email protected]97cf3022013-09-05 14:30:16520
521 // If this is set, then when this packet is ACKed the AckNotifier will be
522 // informed.
523 QuicAckNotifier* notifier;
[email protected]8b37a092012-10-18 21:53:49524};
525
[email protected]e537f742012-12-07 15:33:53526// TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
527// is finalized.
[email protected]9db443912013-02-25 05:27:03528typedef std::set<QuicPacketSequenceNumber> SequenceNumberSet;
[email protected]3c5f4a732013-01-12 16:45:34529// TODO(pwestin): Add a way to enforce the max size of this map.
[email protected]e537f742012-12-07 15:33:53530typedef std::map<QuicPacketSequenceNumber, QuicTime> TimeMap;
[email protected]044ac2b2012-11-13 21:41:06531
[email protected]8b37a092012-10-18 21:53:49532struct NET_EXPORT_PRIVATE ReceivedPacketInfo {
533 ReceivedPacketInfo();
534 ~ReceivedPacketInfo();
[email protected]26f3f8e2012-12-13 21:07:19535 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
536 std::ostream& os, const ReceivedPacketInfo& s);
[email protected]a674b4c2012-12-05 03:44:30537
[email protected]9db443912013-02-25 05:27:03538 // Entropy hash of all packets up to largest observed not including missing
539 // packets.
540 QuicPacketEntropyHash entropy_hash;
[email protected]e537f742012-12-07 15:33:53541
[email protected]48697d8a2013-01-15 19:42:24542 // The highest packet sequence number we've observed from the peer.
543 //
544 // In general, this should be the largest packet number we've received. In
545 // the case of truncated acks, we may have to advertise a lower "upper bound"
546 // than largest received, to avoid implicitly acking missing packets that
547 // don't fit in the missing packet list due to size limitations. In this
548 // case, largest_observed may be a packet which is also in the missing packets
549 // list.
550 QuicPacketSequenceNumber largest_observed;
[email protected]a674b4c2012-12-05 03:44:30551
[email protected]14e8106c2013-03-14 16:25:33552 // Time elapsed since largest_observed was received until this Ack frame was
553 // sent.
554 QuicTime::Delta delta_time_largest_observed;
555
[email protected]9db443912013-02-25 05:27:03556 // TODO(satyamshekhar): Can be optimized using an interval set like data
557 // structure.
[email protected]e537f742012-12-07 15:33:53558 // The set of packets which we're expecting and have not received.
[email protected]9db443912013-02-25 05:27:03559 SequenceNumberSet missing_packets;
[email protected]8e01c062013-10-31 07:35:31560
561 // Whether the ack had to be truncated when sent.
562 bool is_truncated;
[email protected]8b37a092012-10-18 21:53:49563};
564
[email protected]9db443912013-02-25 05:27:03565// True if the sequence number is greater than largest_observed or is listed
566// as missing.
567// Always returns false for sequence numbers less than least_unacked.
568bool NET_EXPORT_PRIVATE IsAwaitingPacket(
569 const ReceivedPacketInfo& received_info,
570 QuicPacketSequenceNumber sequence_number);
571
572// Inserts missing packets between [lower, higher).
573void NET_EXPORT_PRIVATE InsertMissingPacketsBetween(
574 ReceivedPacketInfo* received_info,
575 QuicPacketSequenceNumber lower,
576 QuicPacketSequenceNumber higher);
577
[email protected]8b37a092012-10-18 21:53:49578struct NET_EXPORT_PRIVATE SentPacketInfo {
579 SentPacketInfo();
580 ~SentPacketInfo();
[email protected]26f3f8e2012-12-13 21:07:19581 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
582 std::ostream& os, const SentPacketInfo& s);
583
[email protected]9db443912013-02-25 05:27:03584 // Entropy hash of all packets up to, but not including, the least unacked
585 // packet.
586 QuicPacketEntropyHash entropy_hash;
[email protected]8b37a092012-10-18 21:53:49587 // The lowest packet we've sent which is unacked, and we expect an ack for.
588 QuicPacketSequenceNumber least_unacked;
[email protected]8b37a092012-10-18 21:53:49589};
590
[email protected]26f3f8e2012-12-13 21:07:19591struct NET_EXPORT_PRIVATE QuicAckFrame {
592 QuicAckFrame() {}
593 // Testing convenience method to construct a QuicAckFrame with all packets
[email protected]48697d8a2013-01-15 19:42:24594 // from least_unacked to largest_observed acked.
595 QuicAckFrame(QuicPacketSequenceNumber largest_observed,
[email protected]14e8106c2013-03-14 16:25:33596 QuicTime largest_observed_receive_time,
[email protected]26f3f8e2012-12-13 21:07:19597 QuicPacketSequenceNumber least_unacked);
598
599 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
600 std::ostream& os, const QuicAckFrame& s);
601
602 SentPacketInfo sent_info;
603 ReceivedPacketInfo received_info;
604};
605
[email protected]8b37a092012-10-18 21:53:49606// Defines for all types of congestion feedback that will be negotiated in QUIC,
[email protected]f62262b2013-07-05 20:57:30607// kTCP MUST be supported by all QUIC implementations to guarantee 100%
[email protected]8b37a092012-10-18 21:53:49608// compatibility.
609enum CongestionFeedbackType {
[email protected]8b37a092012-10-18 21:53:49610 kTCP, // Used to mimic TCP.
611 kInterArrival, // Use additional inter arrival information.
612 kFixRate, // Provided for testing.
613};
614
615struct NET_EXPORT_PRIVATE CongestionFeedbackMessageTCP {
616 uint16 accumulated_number_of_lost_packets;
[email protected]fee17f72013-02-03 07:47:41617 QuicByteCount receive_window;
[email protected]8b37a092012-10-18 21:53:49618};
619
620struct NET_EXPORT_PRIVATE CongestionFeedbackMessageInterArrival {
[email protected]7884ecad2012-12-14 22:55:15621 CongestionFeedbackMessageInterArrival();
622 ~CongestionFeedbackMessageInterArrival();
[email protected]8b37a092012-10-18 21:53:49623 uint16 accumulated_number_of_lost_packets;
[email protected]7884ecad2012-12-14 22:55:15624 // The set of received packets since the last feedback was sent, along with
625 // their arrival times.
626 TimeMap received_packet_times;
[email protected]8b37a092012-10-18 21:53:49627};
628
[email protected]8b37a092012-10-18 21:53:49629struct NET_EXPORT_PRIVATE CongestionFeedbackMessageFixRate {
[email protected]fee17f72013-02-03 07:47:41630 CongestionFeedbackMessageFixRate();
631 QuicBandwidth bitrate;
[email protected]8b37a092012-10-18 21:53:49632};
633
[email protected]26f3f8e2012-12-13 21:07:19634struct NET_EXPORT_PRIVATE QuicCongestionFeedbackFrame {
[email protected]7884ecad2012-12-14 22:55:15635 QuicCongestionFeedbackFrame();
636 ~QuicCongestionFeedbackFrame();
637
[email protected]26f3f8e2012-12-13 21:07:19638 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
639 std::ostream& os, const QuicCongestionFeedbackFrame& c);
640
[email protected]7884ecad2012-12-14 22:55:15641 CongestionFeedbackType type;
642 // This should really be a union, but since the inter arrival struct
643 // is non-trivial, C++ prohibits it.
644 CongestionFeedbackMessageTCP tcp;
645 CongestionFeedbackMessageInterArrival inter_arrival;
646 CongestionFeedbackMessageFixRate fix_rate;
[email protected]8b37a092012-10-18 21:53:49647};
648
[email protected]be24ab22012-10-22 03:01:52649struct NET_EXPORT_PRIVATE QuicRstStreamFrame {
650 QuicRstStreamFrame() {}
[email protected]74bda142013-03-31 02:49:11651 QuicRstStreamFrame(QuicStreamId stream_id, QuicRstStreamErrorCode error_code)
[email protected]9db443912013-02-25 05:27:03652 : stream_id(stream_id), error_code(error_code) {
[email protected]431bb4fd2012-10-19 17:46:09653 DCHECK_LE(error_code, std::numeric_limits<uint8>::max());
[email protected]8b37a092012-10-18 21:53:49654 }
655
656 QuicStreamId stream_id;
[email protected]74bda142013-03-31 02:49:11657 QuicRstStreamErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09658 std::string error_details;
[email protected]8b37a092012-10-18 21:53:49659};
660
[email protected]be24ab22012-10-22 03:01:52661struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame {
[email protected]431bb4fd2012-10-19 17:46:09662 QuicErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09663 std::string error_details;
[email protected]8e01c062013-10-31 07:35:31664 // TODO(ianswett): Remove this once QUIC_VERSION_11 is removed.
[email protected]d3d15bf2013-01-30 02:51:54665 QuicAckFrame ack_frame;
[email protected]8b37a092012-10-18 21:53:49666};
667
[email protected]9db443912013-02-25 05:27:03668struct NET_EXPORT_PRIVATE QuicGoAwayFrame {
669 QuicGoAwayFrame() {}
670 QuicGoAwayFrame(QuicErrorCode error_code,
671 QuicStreamId last_good_stream_id,
672 const std::string& reason);
673
674 QuicErrorCode error_code;
675 QuicStreamId last_good_stream_id;
676 std::string reason_phrase;
677};
678
[email protected]8ba81212013-05-03 13:11:48679// EncryptionLevel enumerates the stages of encryption that a QUIC connection
680// progresses through. When retransmitting a packet, the encryption level needs
681// to be specified so that it is retransmitted at a level which the peer can
682// understand.
683enum EncryptionLevel {
684 ENCRYPTION_NONE = 0,
685 ENCRYPTION_INITIAL = 1,
686 ENCRYPTION_FORWARD_SECURE = 2,
687
688 NUM_ENCRYPTION_LEVELS,
689};
690
[email protected]be24ab22012-10-22 03:01:52691struct NET_EXPORT_PRIVATE QuicFrame {
692 QuicFrame() {}
[email protected]c995c572013-01-18 05:43:20693 explicit QuicFrame(QuicPaddingFrame* padding_frame)
694 : type(PADDING_FRAME),
695 padding_frame(padding_frame) {
696 }
[email protected]be24ab22012-10-22 03:01:52697 explicit QuicFrame(QuicStreamFrame* stream_frame)
[email protected]610a7e942012-12-18 00:21:39698 : type(STREAM_FRAME),
699 stream_frame(stream_frame) {
[email protected]8b37a092012-10-18 21:53:49700 }
[email protected]be24ab22012-10-22 03:01:52701 explicit QuicFrame(QuicAckFrame* frame)
[email protected]610a7e942012-12-18 00:21:39702 : type(ACK_FRAME),
703 ack_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49704 }
[email protected]26f3f8e2012-12-13 21:07:19705 explicit QuicFrame(QuicCongestionFeedbackFrame* frame)
[email protected]610a7e942012-12-18 00:21:39706 : type(CONGESTION_FEEDBACK_FRAME),
707 congestion_feedback_frame(frame) {
[email protected]26f3f8e2012-12-13 21:07:19708 }
[email protected]be24ab22012-10-22 03:01:52709 explicit QuicFrame(QuicRstStreamFrame* frame)
710 : type(RST_STREAM_FRAME),
711 rst_stream_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49712 }
[email protected]be24ab22012-10-22 03:01:52713 explicit QuicFrame(QuicConnectionCloseFrame* frame)
714 : type(CONNECTION_CLOSE_FRAME),
715 connection_close_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49716 }
[email protected]9db443912013-02-25 05:27:03717 explicit QuicFrame(QuicGoAwayFrame* frame)
718 : type(GOAWAY_FRAME),
719 goaway_frame(frame) {
720 }
[email protected]8b37a092012-10-18 21:53:49721
[email protected]be24ab22012-10-22 03:01:52722 QuicFrameType type;
[email protected]8b37a092012-10-18 21:53:49723 union {
[email protected]c995c572013-01-18 05:43:20724 QuicPaddingFrame* padding_frame;
[email protected]be24ab22012-10-22 03:01:52725 QuicStreamFrame* stream_frame;
726 QuicAckFrame* ack_frame;
[email protected]26f3f8e2012-12-13 21:07:19727 QuicCongestionFeedbackFrame* congestion_feedback_frame;
[email protected]be24ab22012-10-22 03:01:52728 QuicRstStreamFrame* rst_stream_frame;
729 QuicConnectionCloseFrame* connection_close_frame;
[email protected]9db443912013-02-25 05:27:03730 QuicGoAwayFrame* goaway_frame;
[email protected]8b37a092012-10-18 21:53:49731 };
732};
733
[email protected]be24ab22012-10-22 03:01:52734typedef std::vector<QuicFrame> QuicFrames;
[email protected]8b37a092012-10-18 21:53:49735
736struct NET_EXPORT_PRIVATE QuicFecData {
737 QuicFecData();
[email protected]a5061242012-10-23 23:29:37738
[email protected]c995c572013-01-18 05:43:20739 // The FEC group number is also the sequence number of the first
740 // FEC protected packet. The last protected packet's sequence number will
741 // be one less than the sequence number of the FEC packet.
[email protected]8b37a092012-10-18 21:53:49742 QuicFecGroupNumber fec_group;
[email protected]8b37a092012-10-18 21:53:49743 base::StringPiece redundancy;
[email protected]8b37a092012-10-18 21:53:49744};
745
[email protected]8b37a092012-10-18 21:53:49746class NET_EXPORT_PRIVATE QuicData {
747 public:
748 QuicData(const char* buffer, size_t length)
749 : buffer_(buffer),
750 length_(length),
[email protected]5351cc4b2013-03-03 07:22:41751 owns_buffer_(false) {}
[email protected]8b37a092012-10-18 21:53:49752
753 QuicData(char* buffer, size_t length, bool owns_buffer)
754 : buffer_(buffer),
755 length_(length),
[email protected]5351cc4b2013-03-03 07:22:41756 owns_buffer_(owns_buffer) {}
[email protected]8b37a092012-10-18 21:53:49757
758 virtual ~QuicData();
759
760 base::StringPiece AsStringPiece() const {
761 return base::StringPiece(data(), length());
762 }
763
764 const char* data() const { return buffer_; }
765 size_t length() const { return length_; }
766
767 private:
768 const char* buffer_;
769 size_t length_;
770 bool owns_buffer_;
771
772 DISALLOW_COPY_AND_ASSIGN(QuicData);
773};
774
775class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
776 public:
[email protected]25c31dc2013-06-05 17:56:04777 static QuicPacket* NewDataPacket(
778 char* buffer,
779 size_t length,
780 bool owns_buffer,
781 QuicGuidLength guid_length,
782 bool includes_version,
783 QuicSequenceNumberLength sequence_number_length) {
784 return new QuicPacket(buffer, length, owns_buffer, guid_length,
785 includes_version, sequence_number_length, false);
[email protected]c995c572013-01-18 05:43:20786 }
787
[email protected]25c31dc2013-06-05 17:56:04788 static QuicPacket* NewFecPacket(
789 char* buffer,
790 size_t length,
791 bool owns_buffer,
792 QuicGuidLength guid_length,
793 bool includes_version,
794 QuicSequenceNumberLength sequence_number_length) {
795 return new QuicPacket(buffer, length, owns_buffer, guid_length,
796 includes_version, sequence_number_length, true);
[email protected]c995c572013-01-18 05:43:20797 }
[email protected]8b37a092012-10-18 21:53:49798
[email protected]5351cc4b2013-03-03 07:22:41799 base::StringPiece FecProtectedData() const;
800 base::StringPiece AssociatedData() const;
801 base::StringPiece BeforePlaintext() const;
802 base::StringPiece Plaintext() const;
[email protected]082b65b2012-11-10 19:11:31803
[email protected]c995c572013-01-18 05:43:20804 bool is_fec_packet() const { return is_fec_packet_; }
[email protected]082b65b2012-11-10 19:11:31805
[email protected]8b37a092012-10-18 21:53:49806 char* mutable_data() { return buffer_; }
807
808 private:
[email protected]5351cc4b2013-03-03 07:22:41809 QuicPacket(char* buffer,
810 size_t length,
811 bool owns_buffer,
[email protected]b064310782013-05-30 21:12:17812 QuicGuidLength guid_length,
[email protected]5351cc4b2013-03-03 07:22:41813 bool includes_version,
[email protected]25c31dc2013-06-05 17:56:04814 QuicSequenceNumberLength sequence_number_length,
[email protected]5351cc4b2013-03-03 07:22:41815 bool is_fec_packet)
[email protected]c995c572013-01-18 05:43:20816 : QuicData(buffer, length, owns_buffer),
817 buffer_(buffer),
[email protected]5351cc4b2013-03-03 07:22:41818 is_fec_packet_(is_fec_packet),
[email protected]b064310782013-05-30 21:12:17819 guid_length_(guid_length),
[email protected]25c31dc2013-06-05 17:56:04820 includes_version_(includes_version),
821 sequence_number_length_(sequence_number_length) {}
[email protected]c995c572013-01-18 05:43:20822
[email protected]8b37a092012-10-18 21:53:49823 char* buffer_;
[email protected]c995c572013-01-18 05:43:20824 const bool is_fec_packet_;
[email protected]b064310782013-05-30 21:12:17825 const QuicGuidLength guid_length_;
[email protected]5351cc4b2013-03-03 07:22:41826 const bool includes_version_;
[email protected]25c31dc2013-06-05 17:56:04827 const QuicSequenceNumberLength sequence_number_length_;
[email protected]8b37a092012-10-18 21:53:49828
[email protected]2e740db2012-10-20 19:35:19829 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
[email protected]8b37a092012-10-18 21:53:49830};
831
832class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
833 public:
834 QuicEncryptedPacket(const char* buffer, size_t length)
[email protected]5351cc4b2013-03-03 07:22:41835 : QuicData(buffer, length) {}
[email protected]8b37a092012-10-18 21:53:49836
837 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer)
[email protected]5351cc4b2013-03-03 07:22:41838 : QuicData(buffer, length, owns_buffer) {}
[email protected]8b37a092012-10-18 21:53:49839
[email protected]c1b32c62013-01-20 02:49:10840 // By default, gtest prints the raw bytes of an object. The bool data
841 // member (in the base class QuicData) causes this object to have padding
842 // bytes, which causes the default gtest object printer to read
843 // uninitialize memory. So we need to teach gtest how to print this object.
844 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
845 std::ostream& os, const QuicEncryptedPacket& s);
846
[email protected]2e740db2012-10-20 19:35:19847 private:
848 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
[email protected]8b37a092012-10-18 21:53:49849};
850
[email protected]9db443912013-02-25 05:27:03851class NET_EXPORT_PRIVATE RetransmittableFrames {
852 public:
853 RetransmittableFrames();
854 ~RetransmittableFrames();
855
856 // Allocates a local copy of the referenced StringPiece has QuicStreamFrame
857 // use it.
858 // Takes ownership of |stream_frame|.
859 const QuicFrame& AddStreamFrame(QuicStreamFrame* stream_frame);
860 // Takes ownership of the frame inside |frame|.
861 const QuicFrame& AddNonStreamFrame(const QuicFrame& frame);
862 const QuicFrames& frames() const { return frames_; }
863
[email protected]8ba81212013-05-03 13:11:48864 void set_encryption_level(EncryptionLevel level);
865 EncryptionLevel encryption_level() const {
866 return encryption_level_;
867 }
868
[email protected]9db443912013-02-25 05:27:03869 private:
870 QuicFrames frames_;
[email protected]8ba81212013-05-03 13:11:48871 EncryptionLevel encryption_level_;
[email protected]9db443912013-02-25 05:27:03872 // Data referenced by the StringPiece of a QuicStreamFrame.
873 std::vector<std::string*> stream_data_;
874
875 DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames);
876};
877
878struct NET_EXPORT_PRIVATE SerializedPacket {
879 SerializedPacket(QuicPacketSequenceNumber sequence_number,
[email protected]ea825e02013-08-21 18:12:45880 QuicSequenceNumberLength sequence_number_length,
[email protected]9db443912013-02-25 05:27:03881 QuicPacket* packet,
882 QuicPacketEntropyHash entropy_hash,
[email protected]97cf3022013-09-05 14:30:16883 RetransmittableFrames* retransmittable_frames);
884 ~SerializedPacket();
[email protected]9db443912013-02-25 05:27:03885
886 QuicPacketSequenceNumber sequence_number;
[email protected]ea825e02013-08-21 18:12:45887 QuicSequenceNumberLength sequence_number_length;
[email protected]9db443912013-02-25 05:27:03888 QuicPacket* packet;
889 QuicPacketEntropyHash entropy_hash;
890 RetransmittableFrames* retransmittable_frames;
[email protected]97cf3022013-09-05 14:30:16891
892 // If set, these will be called when this packet is ACKed by the peer.
893 std::set<QuicAckNotifier*> notifiers;
[email protected]9db443912013-02-25 05:27:03894};
895
[email protected]c995c572013-01-18 05:43:20896// A struct for functions which consume data payloads and fins.
[email protected]c995c572013-01-18 05:43:20897struct QuicConsumedData {
898 QuicConsumedData(size_t bytes_consumed, bool fin_consumed)
899 : bytes_consumed(bytes_consumed),
[email protected]5351cc4b2013-03-03 07:22:41900 fin_consumed(fin_consumed) {}
[email protected]c1b32c62013-01-20 02:49:10901 // By default, gtest prints the raw bytes of an object. The bool data
902 // member causes this object to have padding bytes, which causes the
903 // default gtest object printer to read uninitialize memory. So we need
904 // to teach gtest how to print this object.
905 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
906 std::ostream& os, const QuicConsumedData& s);
907
[email protected]97cf3022013-09-05 14:30:16908 // How many bytes were consumed.
[email protected]c995c572013-01-18 05:43:20909 size_t bytes_consumed;
[email protected]97cf3022013-09-05 14:30:16910
911 // True if an incoming fin was consumed.
[email protected]c995c572013-01-18 05:43:20912 bool fin_consumed;
913};
914
[email protected]752fbe52013-10-14 08:35:32915enum WriteStatus {
916 WRITE_STATUS_OK,
917 WRITE_STATUS_BLOCKED,
918 WRITE_STATUS_ERROR,
919};
920
921// A struct used to return the result of write calls including either the number
922// of bytes written or the error code, depending upon the status.
923struct NET_EXPORT_PRIVATE WriteResult {
924 WriteResult(WriteStatus status, int bytes_written_or_error_code) :
925 status(status), bytes_written(bytes_written_or_error_code) {
926 }
927
928 WriteStatus status;
929 union {
930 int bytes_written; // only valid when status is OK
931 int error_code; // only valid when status is ERROR
932 };
933};
934
[email protected]8b37a092012-10-18 21:53:49935} // namespace net
936
937#endif // NET_QUIC_QUIC_PROTOCOL_H_