blob: 4cde9969ad2dc977f5972a22e7793c1802eecffd [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"
18#include "base/hash_tables.h"
19#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]fee17f72013-02-03 07:47:4123#include "net/quic/quic_bandwidth.h"
[email protected]2a960e02012-11-11 14:48:1024#include "net/quic/quic_time.h"
[email protected]8b37a092012-10-18 21:53:4925
26namespace net {
27
[email protected]f1e97e92012-12-16 04:53:2528using ::operator<<;
29
[email protected]8b37a092012-10-18 21:53:4930class QuicPacket;
[email protected]b064310782013-05-30 21:12:1731struct QuicPacketHeader;
[email protected]8b37a092012-10-18 21:53:4932
33typedef uint64 QuicGuid;
34typedef uint32 QuicStreamId;
35typedef uint64 QuicStreamOffset;
36typedef uint64 QuicPacketSequenceNumber;
[email protected]c995c572013-01-18 05:43:2037typedef QuicPacketSequenceNumber QuicFecGroupNumber;
[email protected]86a318d2013-01-23 21:16:0438typedef uint64 QuicPublicResetNonceProof;
[email protected]9db443912013-02-25 05:27:0339typedef uint8 QuicPacketEntropyHash;
[email protected]c244c5a12013-05-07 20:55:0440typedef uint32 QuicHeaderId;
[email protected]2532de12013-05-09 12:29:3341// QuicTag is the type of a tag in the wire protocol.
42typedef uint32 QuicTag;
43typedef std::vector<QuicTag> QuicTagVector;
[email protected]cff7b7b2013-01-11 08:49:0744
[email protected]8b37a092012-10-18 21:53:4945// TODO(rch): Consider Quic specific names for these constants.
[email protected]fee17f72013-02-03 07:47:4146// Maximum size in bytes of a QUIC packet.
47const QuicByteCount kMaxPacketSize = 1200;
[email protected]8b37a092012-10-18 21:53:4948
49// Maximum number of open streams per connection.
50const size_t kDefaultMaxStreamsPerConnection = 100;
51
[email protected]af806e62013-05-22 14:47:5052// Number of bytes reserved for public flags in the packet header.
53const size_t kPublicFlagsSize = 1;
[email protected]5351cc4b2013-03-03 07:22:4154// Number of bytes reserved for version number in the packet header.
55const size_t kQuicVersionSize = 4;
[email protected]c995c572013-01-18 05:43:2056// Number of bytes reserved for sequence number in the packet header.
57const size_t kSequenceNumberSize = 6;
58// Number of bytes reserved for private flags in the packet header.
59const size_t kPrivateFlagsSize = 1;
60// Number of bytes reserved for FEC group in the packet header.
61const size_t kFecGroupSize = 1;
[email protected]86a318d2013-01-23 21:16:0462// Number of bytes reserved for the nonce proof in public reset packet.
63const size_t kPublicResetNonceSize = 8;
[email protected]5351cc4b2013-03-03 07:22:4164
65// Signifies that the QuicPacket will contain version of the protocol.
66const bool kIncludeVersion = true;
[email protected]c995c572013-01-18 05:43:2067
[email protected]14e8106c2013-03-14 16:25:3368// Returns true if |version| is a supported protocol version.
[email protected]2532de12013-05-09 12:29:3369NET_EXPORT_PRIVATE bool IsSupportedVersion(QuicTag version);
[email protected]8b37a092012-10-18 21:53:4970
[email protected]5351cc4b2013-03-03 07:22:4171// Index of the first byte in a QUIC packet which is used in hash calculation.
72const size_t kStartOfHashData = 0;
[email protected]8b37a092012-10-18 21:53:4973
74// Limit on the delta between stream IDs.
75const QuicStreamId kMaxStreamIdDelta = 100;
[email protected]c244c5a12013-05-07 20:55:0476// Limit on the delta between header IDs.
77const QuicHeaderId kMaxHeaderIdDelta = 100;
[email protected]8b37a092012-10-18 21:53:4978
79// Reserved ID for the crypto stream.
80// TODO(rch): ensure that this is not usable by any other streams.
81const QuicStreamId kCryptoStreamId = 1;
82
[email protected]899951652013-05-16 12:52:3983// This is the default network timeout a for connection till the crypto
84// handshake succeeds and the negotiated timeout from the handshake is received.
[email protected]b064310782013-05-30 21:12:1785const int64 kDefaultInitialTimeoutSecs = 120; // 2 mins.
[email protected]899951652013-05-16 12:52:3986const int64 kDefaultTimeoutSecs = 60 * 10; // 10 minutes.
[email protected]b064310782013-05-30 21:12:1787const int64 kDefaultMaxTimeForCryptoHandshakeSecs = 5; // 5 secs.
[email protected]8b37a092012-10-18 21:53:4988
[email protected]74bda142013-03-31 02:49:1189enum Retransmission {
[email protected]2532de12013-05-09 12:29:3390 NOT_RETRANSMISSION,
91 IS_RETRANSMISSION,
[email protected]74bda142013-03-31 02:49:1192};
93
94enum HasRetransmittableData {
[email protected]2532de12013-05-09 12:29:3395 NO_RETRANSMITTABLE_DATA,
96 HAS_RETRANSMITTABLE_DATA,
[email protected]74bda142013-03-31 02:49:1197};
98
[email protected]be24ab22012-10-22 03:01:5299enum QuicFrameType {
[email protected]c995c572013-01-18 05:43:20100 PADDING_FRAME = 0,
101 STREAM_FRAME,
[email protected]be24ab22012-10-22 03:01:52102 ACK_FRAME,
[email protected]26f3f8e2012-12-13 21:07:19103 CONGESTION_FEEDBACK_FRAME,
[email protected]be24ab22012-10-22 03:01:52104 RST_STREAM_FRAME,
105 CONNECTION_CLOSE_FRAME,
[email protected]9db443912013-02-25 05:27:03106 GOAWAY_FRAME,
[email protected]be24ab22012-10-22 03:01:52107 NUM_FRAME_TYPES
[email protected]8b37a092012-10-18 21:53:49108};
109
[email protected]b064310782013-05-30 21:12:17110enum QuicGuidLength {
111 PACKET_0BYTE_GUID = 0,
112 PACKET_1BYTE_GUID = 1,
113 PACKET_4BYTE_GUID = 4,
114 PACKET_8BYTE_GUID = 8
115};
116
117enum InFecGroup {
118 NOT_IN_FEC_GROUP,
119 IN_FEC_GROUP,
120};
121
[email protected]c995c572013-01-18 05:43:20122enum QuicPacketPublicFlags {
123 PACKET_PUBLIC_FLAGS_NONE = 0,
[email protected]5351cc4b2013-03-03 07:22:41124 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0, // Packet header contains version info.
[email protected]9db443912013-02-25 05:27:03125 PACKET_PUBLIC_FLAGS_RST = 1 << 1, // Packet is a public reset packet.
[email protected]1354bf62013-05-23 23:17:18126 // Packet header guid length in bytes.
127 PACKET_PUBLIC_FLAGS_0BYTE_GUID = 0,
128 PACKET_PUBLIC_FLAGS_1BYTE_GUID = 1 << 2,
129 PACKET_PUBLIC_FLAGS_4BYTE_GUID = 1 << 3,
130 PACKET_PUBLIC_FLAGS_8BYTE_GUID = 1 << 3 | 1 << 2,
131 PACKET_PUBLIC_FLAGS_MAX = (1 << 4) - 1 // All bits set.
[email protected]c995c572013-01-18 05:43:20132};
[email protected]8b37a092012-10-18 21:53:49133
[email protected]c995c572013-01-18 05:43:20134enum QuicPacketPrivateFlags {
135 PACKET_PRIVATE_FLAGS_NONE = 0,
[email protected]b064310782013-05-30 21:12:17136 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0,
137 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1, // Payload is part of an FEC group.
138 PACKET_PRIVATE_FLAGS_FEC = 1 << 2, // Payload is FEC as opposed to frames.
[email protected]9db443912013-02-25 05:27:03139 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1 // All bits set.
[email protected]c995c572013-01-18 05:43:20140};
141
[email protected]b064310782013-05-30 21:12:17142// Size in bytes of the data or fec packet header.
143NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicPacketHeader header);
144
145NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicGuidLength guid_length,
146 bool include_version,
147 InFecGroup is_in_fec_group);
148
149// Size in bytes of the public reset packet.
150NET_EXPORT_PRIVATE size_t GetPublicResetPacketSize();
151
152// Index of the first byte in a QUIC packet of FEC protected data.
153NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(QuicGuidLength guid_length,
154 bool include_version);
155// Index of the first byte in a QUIC packet of encrypted data.
156NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(QuicGuidLength guid_length,
157 bool include_version);
158
[email protected]74bda142013-03-31 02:49:11159enum QuicRstStreamErrorCode {
160 QUIC_STREAM_NO_ERROR = 0,
[email protected]8b37a092012-10-18 21:53:49161
[email protected]8b37a092012-10-18 21:53:49162 // There was some server error which halted stream processing.
163 QUIC_SERVER_ERROR_PROCESSING_STREAM,
164 // We got two fin or reset offsets which did not match.
165 QUIC_MULTIPLE_TERMINATION_OFFSETS,
166 // We got bad payload and can not respond to it at the protocol level.
167 QUIC_BAD_APPLICATION_PAYLOAD,
[email protected]74bda142013-03-31 02:49:11168 // Stream closed due to connection error. No reset frame is sent when this
169 // happens.
170 QUIC_STREAM_CONNECTION_ERROR,
171 // GoAway frame sent. No more stream can be created.
172 QUIC_STREAM_PEER_GOING_AWAY,
[email protected]8b37a092012-10-18 21:53:49173
[email protected]74bda142013-03-31 02:49:11174 // No error. Used as bound while iterating.
175 QUIC_STREAM_LAST_ERROR,
176};
[email protected]8b37a092012-10-18 21:53:49177
[email protected]74bda142013-03-31 02:49:11178enum QuicErrorCode {
179 QUIC_NO_ERROR = 0,
180
181 // Connection has reached an invalid state.
182 QUIC_INTERNAL_ERROR,
183 // There were data frames after the a fin or reset.
184 QUIC_STREAM_DATA_AFTER_TERMINATION,
[email protected]8b37a092012-10-18 21:53:49185 // Control frame is malformed.
186 QUIC_INVALID_PACKET_HEADER,
[email protected]be24ab22012-10-22 03:01:52187 // Frame data is malformed.
188 QUIC_INVALID_FRAME_DATA,
[email protected]8b37a092012-10-18 21:53:49189 // FEC data is malformed.
190 QUIC_INVALID_FEC_DATA,
191 // Stream rst data is malformed
192 QUIC_INVALID_RST_STREAM_DATA,
193 // Connection close data is malformed.
194 QUIC_INVALID_CONNECTION_CLOSE_DATA,
[email protected]9db443912013-02-25 05:27:03195 // GoAway data is malformed.
196 QUIC_INVALID_GOAWAY_DATA,
[email protected]8b37a092012-10-18 21:53:49197 // Ack data is malformed.
198 QUIC_INVALID_ACK_DATA,
[email protected]14e8106c2013-03-14 16:25:33199 // Version negotiation packet is malformed.
200 QUIC_INVALID_VERSION_NEGOTIATION_PACKET,
[email protected]899951652013-05-16 12:52:39201 // Public RST packet is malformed.
202 QUIC_INVALID_PUBLIC_RST_PACKET,
[email protected]8b37a092012-10-18 21:53:49203 // There was an error decrypting.
204 QUIC_DECRYPTION_FAILURE,
205 // There was an error encrypting.
206 QUIC_ENCRYPTION_FAILURE,
207 // The packet exceeded kMaxPacketSize.
208 QUIC_PACKET_TOO_LARGE,
209 // Data was sent for a stream which did not exist.
210 QUIC_PACKET_FOR_NONEXISTENT_STREAM,
[email protected]9db443912013-02-25 05:27:03211 // The peer is going away. May be a client or server.
212 QUIC_PEER_GOING_AWAY,
[email protected]8b37a092012-10-18 21:53:49213 // A stream ID was invalid.
214 QUIC_INVALID_STREAM_ID,
215 // Too many streams already open.
216 QUIC_TOO_MANY_OPEN_STREAMS,
[email protected]86a318d2013-01-23 21:16:04217 // Received public reset for this connection.
218 QUIC_PUBLIC_RESET,
[email protected]c244c5a12013-05-07 20:55:04219 // Invalid protocol version.
[email protected]14e8106c2013-03-14 16:25:33220 QUIC_INVALID_VERSION,
[email protected]c244c5a12013-05-07 20:55:04221 // Stream reset before headers decompressed.
222 QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED,
223 // The Header ID for a stream was too far from the previous.
224 QUIC_INVALID_HEADER_ID,
[email protected]899951652013-05-16 12:52:39225 // Negotiable parameter received during handshake had invalid value.
226 QUIC_INVALID_NEGOTIATED_VALUE,
227 // There was an error decompressing data.
228 QUIC_DECOMPRESSION_FAILURE,
[email protected]8b37a092012-10-18 21:53:49229 // We hit our prenegotiated (or default) timeout
230 QUIC_CONNECTION_TIMED_OUT,
[email protected]899951652013-05-16 12:52:39231 // There was an error encountered migrating addresses
232 QUIC_ERROR_MIGRATING_ADDRESS,
233 // There was an error while writing the packet.
234 QUIC_PACKET_WRITE_ERROR,
235
[email protected]8b37a092012-10-18 21:53:49236
237 // Crypto errors.
238
[email protected]1354bf62013-05-23 23:17:18239 // Hanshake failed.
240 QUIC_HANDSHAKE_FAILED,
[email protected]8b37a092012-10-18 21:53:49241 // Handshake message contained out of order tags.
242 QUIC_CRYPTO_TAGS_OUT_OF_ORDER,
[email protected]701bc892013-01-17 04:51:54243 // Handshake message contained too many entries.
[email protected]8b37a092012-10-18 21:53:49244 QUIC_CRYPTO_TOO_MANY_ENTRIES,
245 // Handshake message contained an invalid value length.
246 QUIC_CRYPTO_INVALID_VALUE_LENGTH,
247 // A crypto message was received after the handshake was complete.
248 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE,
[email protected]d3d15bf2013-01-30 02:51:54249 // A crypto message was received with an illegal message tag.
[email protected]8b37a092012-10-18 21:53:49250 QUIC_INVALID_CRYPTO_MESSAGE_TYPE,
[email protected]d3d15bf2013-01-30 02:51:54251 // A crypto message was received with an illegal parameter.
252 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER,
253 // A crypto message was received with a mandatory parameter missing.
254 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND,
255 // A crypto message was received with a parameter that has no overlap
256 // with the local parameter.
257 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP,
[email protected]ed3fc15d2013-03-08 18:37:44258 // A crypto message was received that contained a parameter with too few
259 // values.
260 QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND,
[email protected]ccc66e8a2013-03-26 08:26:14261 // An internal error occured in crypto processing.
262 QUIC_CRYPTO_INTERNAL_ERROR,
263 // A crypto handshake message specified an unsupported version.
[email protected]fe053f92013-04-23 20:18:55264 QUIC_CRYPTO_VERSION_NOT_SUPPORTED,
[email protected]ccc66e8a2013-03-26 08:26:14265 // There was no intersection between the crypto primitives supported by the
266 // peer and ourselves.
267 QUIC_CRYPTO_NO_SUPPORT,
[email protected]ef95114d2013-04-17 17:57:01268 // The server rejected our client hello messages too many times.
269 QUIC_CRYPTO_TOO_MANY_REJECTS,
[email protected]a57e0272013-04-26 07:31:47270 // The client rejected the server's certificate chain or signature.
271 QUIC_PROOF_INVALID,
[email protected]8ba81212013-05-03 13:11:48272 // A crypto message was received with a duplicate tag.
273 QUIC_CRYPTO_DUPLICATE_TAG,
[email protected]2532de12013-05-09 12:29:33274 // A crypto message was received with the wrong encryption level (i.e. it
275 // should have been encrypted but was not.)
276 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT,
277 // The server config for a server has expired.
278 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED,
[email protected]ccc66e8a2013-03-26 08:26:14279
[email protected]74bda142013-03-31 02:49:11280 // No error. Used as bound while iterating.
[email protected]ccc66e8a2013-03-26 08:26:14281 QUIC_LAST_ERROR,
[email protected]8b37a092012-10-18 21:53:49282};
283
[email protected]5351cc4b2013-03-03 07:22:41284// Version and Crypto tags are written to the wire with a big-endian
285// representation of the name of the tag. For example
286// the client hello tag (CHLO) will be written as the
287// following 4 bytes: 'C' 'H' 'L' 'O'. Since it is
288// stored in memory as a little endian uint32, we need
289// to reverse the order of the bytes.
[email protected]a57e0272013-04-26 07:31:47290//
291// The TAG macro is used in header files to ensure that we don't create static
292// initialisers. In normal code, the MakeQuicTag function should be used.
293#define TAG(a, b, c, d) ((d << 24) + (c << 16) + (b << 8) + a)
[email protected]2532de12013-05-09 12:29:33294const QuicTag kUnsupportedVersion = -1;
295// Each time the wire format changes, this need needs to be incremented.
296// At some point, we will actually freeze the wire format and make an official
297// version number, but this works for now.
[email protected]b064310782013-05-30 21:12:17298const QuicTag kQuicVersion1 = TAG('Q', '0', '0', '5');
[email protected]a57e0272013-04-26 07:31:47299#undef TAG
300
301// MakeQuicTag returns a value given the four bytes. For example:
302// MakeQuicTag('C', 'H', 'L', 'O');
303uint32 NET_EXPORT_PRIVATE MakeQuicTag(char a, char b, char c, char d);
[email protected]5351cc4b2013-03-03 07:22:41304
[email protected]c995c572013-01-18 05:43:20305struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
[email protected]14e8106c2013-03-14 16:25:33306 QuicPacketPublicHeader();
307 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
308 ~QuicPacketPublicHeader();
309
310 QuicPacketPublicHeader& operator=(const QuicPacketPublicHeader& other);
311
[email protected]c995c572013-01-18 05:43:20312 // Universal header. All QuicPacket headers will have a guid and public flags.
[email protected]8b37a092012-10-18 21:53:49313 QuicGuid guid;
[email protected]b064310782013-05-30 21:12:17314 QuicGuidLength guid_length;
[email protected]9db443912013-02-25 05:27:03315 bool reset_flag;
316 bool version_flag;
[email protected]2532de12013-05-09 12:29:33317 QuicTagVector versions;
[email protected]c995c572013-01-18 05:43:20318};
319
320// Header for Data or FEC packets.
[email protected]74bda142013-03-31 02:49:11321struct NET_EXPORT_PRIVATE QuicPacketHeader {
322 QuicPacketHeader();
323 explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
[email protected]9db443912013-02-25 05:27:03324
325 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
326 std::ostream& os, const QuicPacketHeader& s);
327
[email protected]c995c572013-01-18 05:43:20328 QuicPacketPublicHeader public_header;
[email protected]9db443912013-02-25 05:27:03329 bool fec_flag;
[email protected]9db443912013-02-25 05:27:03330 bool entropy_flag;
331 QuicPacketEntropyHash entropy_hash;
[email protected]8b37a092012-10-18 21:53:49332 QuicPacketSequenceNumber packet_sequence_number;
[email protected]b064310782013-05-30 21:12:17333 InFecGroup is_in_fec_group;
[email protected]8b37a092012-10-18 21:53:49334 QuicFecGroupNumber fec_group;
335};
336
[email protected]74bda142013-03-31 02:49:11337struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
[email protected]86a318d2013-01-23 21:16:04338 QuicPublicResetPacket() {}
339 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header)
340 : public_header(header) {}
341 QuicPacketPublicHeader public_header;
342 QuicPacketSequenceNumber rejected_sequence_number;
343 QuicPublicResetNonceProof nonce_proof;
344};
345
[email protected]14e8106c2013-03-14 16:25:33346enum QuicVersionNegotiationState {
347 START_NEGOTIATION = 0,
348 SENT_NEGOTIATION_PACKET,
349 NEGOTIATED_VERSION
350};
351
352typedef QuicPacketPublicHeader QuicVersionNegotiationPacket;
353
[email protected]c995c572013-01-18 05:43:20354// A padding frame contains no payload.
355struct NET_EXPORT_PRIVATE QuicPaddingFrame {
356};
357
[email protected]be24ab22012-10-22 03:01:52358struct NET_EXPORT_PRIVATE QuicStreamFrame {
359 QuicStreamFrame();
360 QuicStreamFrame(QuicStreamId stream_id,
[email protected]a5061242012-10-23 23:29:37361 bool fin,
[email protected]701bc892013-01-17 04:51:54362 QuicStreamOffset offset,
[email protected]a5061242012-10-23 23:29:37363 base::StringPiece data);
[email protected]8b37a092012-10-18 21:53:49364
365 QuicStreamId stream_id;
366 bool fin;
[email protected]701bc892013-01-17 04:51:54367 QuicStreamOffset offset; // Location of this data in the stream.
[email protected]8b37a092012-10-18 21:53:49368 base::StringPiece data;
369};
370
[email protected]e537f742012-12-07 15:33:53371// TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
372// is finalized.
[email protected]9db443912013-02-25 05:27:03373typedef std::set<QuicPacketSequenceNumber> SequenceNumberSet;
[email protected]3c5f4a732013-01-12 16:45:34374// TODO(pwestin): Add a way to enforce the max size of this map.
[email protected]e537f742012-12-07 15:33:53375typedef std::map<QuicPacketSequenceNumber, QuicTime> TimeMap;
[email protected]044ac2b2012-11-13 21:41:06376
[email protected]8b37a092012-10-18 21:53:49377struct NET_EXPORT_PRIVATE ReceivedPacketInfo {
378 ReceivedPacketInfo();
379 ~ReceivedPacketInfo();
[email protected]26f3f8e2012-12-13 21:07:19380 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
381 std::ostream& os, const ReceivedPacketInfo& s);
[email protected]a674b4c2012-12-05 03:44:30382
[email protected]9db443912013-02-25 05:27:03383 // Entropy hash of all packets up to largest observed not including missing
384 // packets.
385 QuicPacketEntropyHash entropy_hash;
[email protected]e537f742012-12-07 15:33:53386
[email protected]48697d8a2013-01-15 19:42:24387 // The highest packet sequence number we've observed from the peer.
388 //
389 // In general, this should be the largest packet number we've received. In
390 // the case of truncated acks, we may have to advertise a lower "upper bound"
391 // than largest received, to avoid implicitly acking missing packets that
392 // don't fit in the missing packet list due to size limitations. In this
393 // case, largest_observed may be a packet which is also in the missing packets
394 // list.
395 QuicPacketSequenceNumber largest_observed;
[email protected]a674b4c2012-12-05 03:44:30396
[email protected]14e8106c2013-03-14 16:25:33397 // Time elapsed since largest_observed was received until this Ack frame was
398 // sent.
399 QuicTime::Delta delta_time_largest_observed;
400
[email protected]9db443912013-02-25 05:27:03401 // TODO(satyamshekhar): Can be optimized using an interval set like data
402 // structure.
[email protected]e537f742012-12-07 15:33:53403 // The set of packets which we're expecting and have not received.
[email protected]9db443912013-02-25 05:27:03404 SequenceNumberSet missing_packets;
[email protected]8b37a092012-10-18 21:53:49405};
406
[email protected]9db443912013-02-25 05:27:03407// True if the sequence number is greater than largest_observed or is listed
408// as missing.
409// Always returns false for sequence numbers less than least_unacked.
410bool NET_EXPORT_PRIVATE IsAwaitingPacket(
411 const ReceivedPacketInfo& received_info,
412 QuicPacketSequenceNumber sequence_number);
413
414// Inserts missing packets between [lower, higher).
415void NET_EXPORT_PRIVATE InsertMissingPacketsBetween(
416 ReceivedPacketInfo* received_info,
417 QuicPacketSequenceNumber lower,
418 QuicPacketSequenceNumber higher);
419
[email protected]8b37a092012-10-18 21:53:49420struct NET_EXPORT_PRIVATE SentPacketInfo {
421 SentPacketInfo();
422 ~SentPacketInfo();
[email protected]26f3f8e2012-12-13 21:07:19423 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
424 std::ostream& os, const SentPacketInfo& s);
425
[email protected]9db443912013-02-25 05:27:03426 // Entropy hash of all packets up to, but not including, the least unacked
427 // packet.
428 QuicPacketEntropyHash entropy_hash;
[email protected]8b37a092012-10-18 21:53:49429 // The lowest packet we've sent which is unacked, and we expect an ack for.
430 QuicPacketSequenceNumber least_unacked;
[email protected]8b37a092012-10-18 21:53:49431};
432
[email protected]26f3f8e2012-12-13 21:07:19433struct NET_EXPORT_PRIVATE QuicAckFrame {
434 QuicAckFrame() {}
435 // Testing convenience method to construct a QuicAckFrame with all packets
[email protected]48697d8a2013-01-15 19:42:24436 // from least_unacked to largest_observed acked.
437 QuicAckFrame(QuicPacketSequenceNumber largest_observed,
[email protected]14e8106c2013-03-14 16:25:33438 QuicTime largest_observed_receive_time,
[email protected]26f3f8e2012-12-13 21:07:19439 QuicPacketSequenceNumber least_unacked);
440
441 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
442 std::ostream& os, const QuicAckFrame& s);
443
444 SentPacketInfo sent_info;
445 ReceivedPacketInfo received_info;
446};
447
[email protected]8b37a092012-10-18 21:53:49448// Defines for all types of congestion feedback that will be negotiated in QUIC,
449// kTCP MUST be supported by all QUIC implementations to guarentee 100%
450// compatibility.
451enum CongestionFeedbackType {
[email protected]8b37a092012-10-18 21:53:49452 kTCP, // Used to mimic TCP.
453 kInterArrival, // Use additional inter arrival information.
454 kFixRate, // Provided for testing.
455};
456
457struct NET_EXPORT_PRIVATE CongestionFeedbackMessageTCP {
458 uint16 accumulated_number_of_lost_packets;
[email protected]fee17f72013-02-03 07:47:41459 QuicByteCount receive_window;
[email protected]8b37a092012-10-18 21:53:49460};
461
462struct NET_EXPORT_PRIVATE CongestionFeedbackMessageInterArrival {
[email protected]7884ecad2012-12-14 22:55:15463 CongestionFeedbackMessageInterArrival();
464 ~CongestionFeedbackMessageInterArrival();
[email protected]8b37a092012-10-18 21:53:49465 uint16 accumulated_number_of_lost_packets;
[email protected]7884ecad2012-12-14 22:55:15466 // The set of received packets since the last feedback was sent, along with
467 // their arrival times.
468 TimeMap received_packet_times;
[email protected]8b37a092012-10-18 21:53:49469};
470
[email protected]8b37a092012-10-18 21:53:49471struct NET_EXPORT_PRIVATE CongestionFeedbackMessageFixRate {
[email protected]fee17f72013-02-03 07:47:41472 CongestionFeedbackMessageFixRate();
473 QuicBandwidth bitrate;
[email protected]8b37a092012-10-18 21:53:49474};
475
[email protected]26f3f8e2012-12-13 21:07:19476struct NET_EXPORT_PRIVATE QuicCongestionFeedbackFrame {
[email protected]7884ecad2012-12-14 22:55:15477 QuicCongestionFeedbackFrame();
478 ~QuicCongestionFeedbackFrame();
479
[email protected]26f3f8e2012-12-13 21:07:19480 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
481 std::ostream& os, const QuicCongestionFeedbackFrame& c);
482
[email protected]7884ecad2012-12-14 22:55:15483 CongestionFeedbackType type;
484 // This should really be a union, but since the inter arrival struct
485 // is non-trivial, C++ prohibits it.
486 CongestionFeedbackMessageTCP tcp;
487 CongestionFeedbackMessageInterArrival inter_arrival;
488 CongestionFeedbackMessageFixRate fix_rate;
[email protected]8b37a092012-10-18 21:53:49489};
490
[email protected]be24ab22012-10-22 03:01:52491struct NET_EXPORT_PRIVATE QuicRstStreamFrame {
492 QuicRstStreamFrame() {}
[email protected]74bda142013-03-31 02:49:11493 QuicRstStreamFrame(QuicStreamId stream_id, QuicRstStreamErrorCode error_code)
[email protected]9db443912013-02-25 05:27:03494 : stream_id(stream_id), error_code(error_code) {
[email protected]431bb4fd2012-10-19 17:46:09495 DCHECK_LE(error_code, std::numeric_limits<uint8>::max());
[email protected]8b37a092012-10-18 21:53:49496 }
497
498 QuicStreamId stream_id;
[email protected]74bda142013-03-31 02:49:11499 QuicRstStreamErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09500 std::string error_details;
[email protected]8b37a092012-10-18 21:53:49501};
502
[email protected]be24ab22012-10-22 03:01:52503struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame {
[email protected]431bb4fd2012-10-19 17:46:09504 QuicErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09505 std::string error_details;
[email protected]d3d15bf2013-01-30 02:51:54506 QuicAckFrame ack_frame;
[email protected]8b37a092012-10-18 21:53:49507};
508
[email protected]9db443912013-02-25 05:27:03509struct NET_EXPORT_PRIVATE QuicGoAwayFrame {
510 QuicGoAwayFrame() {}
511 QuicGoAwayFrame(QuicErrorCode error_code,
512 QuicStreamId last_good_stream_id,
513 const std::string& reason);
514
515 QuicErrorCode error_code;
516 QuicStreamId last_good_stream_id;
517 std::string reason_phrase;
518};
519
[email protected]8ba81212013-05-03 13:11:48520// EncryptionLevel enumerates the stages of encryption that a QUIC connection
521// progresses through. When retransmitting a packet, the encryption level needs
522// to be specified so that it is retransmitted at a level which the peer can
523// understand.
524enum EncryptionLevel {
525 ENCRYPTION_NONE = 0,
526 ENCRYPTION_INITIAL = 1,
527 ENCRYPTION_FORWARD_SECURE = 2,
528
529 NUM_ENCRYPTION_LEVELS,
530};
531
[email protected]be24ab22012-10-22 03:01:52532struct NET_EXPORT_PRIVATE QuicFrame {
533 QuicFrame() {}
[email protected]c995c572013-01-18 05:43:20534 explicit QuicFrame(QuicPaddingFrame* padding_frame)
535 : type(PADDING_FRAME),
536 padding_frame(padding_frame) {
537 }
[email protected]be24ab22012-10-22 03:01:52538 explicit QuicFrame(QuicStreamFrame* stream_frame)
[email protected]610a7e942012-12-18 00:21:39539 : type(STREAM_FRAME),
540 stream_frame(stream_frame) {
[email protected]8b37a092012-10-18 21:53:49541 }
[email protected]be24ab22012-10-22 03:01:52542 explicit QuicFrame(QuicAckFrame* frame)
[email protected]610a7e942012-12-18 00:21:39543 : type(ACK_FRAME),
544 ack_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49545 }
[email protected]26f3f8e2012-12-13 21:07:19546 explicit QuicFrame(QuicCongestionFeedbackFrame* frame)
[email protected]610a7e942012-12-18 00:21:39547 : type(CONGESTION_FEEDBACK_FRAME),
548 congestion_feedback_frame(frame) {
[email protected]26f3f8e2012-12-13 21:07:19549 }
[email protected]be24ab22012-10-22 03:01:52550 explicit QuicFrame(QuicRstStreamFrame* frame)
551 : type(RST_STREAM_FRAME),
552 rst_stream_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49553 }
[email protected]be24ab22012-10-22 03:01:52554 explicit QuicFrame(QuicConnectionCloseFrame* frame)
555 : type(CONNECTION_CLOSE_FRAME),
556 connection_close_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49557 }
[email protected]9db443912013-02-25 05:27:03558 explicit QuicFrame(QuicGoAwayFrame* frame)
559 : type(GOAWAY_FRAME),
560 goaway_frame(frame) {
561 }
[email protected]8b37a092012-10-18 21:53:49562
[email protected]be24ab22012-10-22 03:01:52563 QuicFrameType type;
[email protected]8b37a092012-10-18 21:53:49564 union {
[email protected]c995c572013-01-18 05:43:20565 QuicPaddingFrame* padding_frame;
[email protected]be24ab22012-10-22 03:01:52566 QuicStreamFrame* stream_frame;
567 QuicAckFrame* ack_frame;
[email protected]26f3f8e2012-12-13 21:07:19568 QuicCongestionFeedbackFrame* congestion_feedback_frame;
[email protected]be24ab22012-10-22 03:01:52569 QuicRstStreamFrame* rst_stream_frame;
570 QuicConnectionCloseFrame* connection_close_frame;
[email protected]9db443912013-02-25 05:27:03571 QuicGoAwayFrame* goaway_frame;
[email protected]8b37a092012-10-18 21:53:49572 };
573};
574
[email protected]be24ab22012-10-22 03:01:52575typedef std::vector<QuicFrame> QuicFrames;
[email protected]8b37a092012-10-18 21:53:49576
577struct NET_EXPORT_PRIVATE QuicFecData {
578 QuicFecData();
[email protected]a5061242012-10-23 23:29:37579
580 bool operator==(const QuicFecData& other) const;
581
[email protected]c995c572013-01-18 05:43:20582 // The FEC group number is also the sequence number of the first
583 // FEC protected packet. The last protected packet's sequence number will
584 // be one less than the sequence number of the FEC packet.
[email protected]8b37a092012-10-18 21:53:49585 QuicFecGroupNumber fec_group;
[email protected]8b37a092012-10-18 21:53:49586 base::StringPiece redundancy;
[email protected]8b37a092012-10-18 21:53:49587};
588
589struct NET_EXPORT_PRIVATE QuicPacketData {
590 std::string data;
591};
592
593class NET_EXPORT_PRIVATE QuicData {
594 public:
595 QuicData(const char* buffer, size_t length)
596 : buffer_(buffer),
597 length_(length),
[email protected]5351cc4b2013-03-03 07:22:41598 owns_buffer_(false) {}
[email protected]8b37a092012-10-18 21:53:49599
600 QuicData(char* buffer, size_t length, bool owns_buffer)
601 : buffer_(buffer),
602 length_(length),
[email protected]5351cc4b2013-03-03 07:22:41603 owns_buffer_(owns_buffer) {}
[email protected]8b37a092012-10-18 21:53:49604
605 virtual ~QuicData();
606
607 base::StringPiece AsStringPiece() const {
608 return base::StringPiece(data(), length());
609 }
610
611 const char* data() const { return buffer_; }
612 size_t length() const { return length_; }
613
614 private:
615 const char* buffer_;
616 size_t length_;
617 bool owns_buffer_;
618
619 DISALLOW_COPY_AND_ASSIGN(QuicData);
620};
621
622class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
623 public:
[email protected]c995c572013-01-18 05:43:20624 static QuicPacket* NewDataPacket(char* buffer,
[email protected]9db443912013-02-25 05:27:03625 size_t length,
[email protected]5351cc4b2013-03-03 07:22:41626 bool owns_buffer,
[email protected]b064310782013-05-30 21:12:17627 QuicGuidLength guid_length,
[email protected]5351cc4b2013-03-03 07:22:41628 bool includes_version) {
[email protected]b064310782013-05-30 21:12:17629 return new QuicPacket(
630 buffer, length, owns_buffer, guid_length, includes_version, false);
[email protected]c995c572013-01-18 05:43:20631 }
632
633 static QuicPacket* NewFecPacket(char* buffer,
634 size_t length,
[email protected]5351cc4b2013-03-03 07:22:41635 bool owns_buffer,
[email protected]b064310782013-05-30 21:12:17636 QuicGuidLength guid_length,
[email protected]5351cc4b2013-03-03 07:22:41637 bool includes_version) {
[email protected]b064310782013-05-30 21:12:17638 return new QuicPacket(
639 buffer, length, owns_buffer, guid_length, includes_version, true);
[email protected]c995c572013-01-18 05:43:20640 }
[email protected]8b37a092012-10-18 21:53:49641
[email protected]5351cc4b2013-03-03 07:22:41642 base::StringPiece FecProtectedData() const;
643 base::StringPiece AssociatedData() const;
644 base::StringPiece BeforePlaintext() const;
645 base::StringPiece Plaintext() const;
[email protected]082b65b2012-11-10 19:11:31646
[email protected]c995c572013-01-18 05:43:20647 bool is_fec_packet() const { return is_fec_packet_; }
[email protected]082b65b2012-11-10 19:11:31648
[email protected]5351cc4b2013-03-03 07:22:41649 bool includes_version() const { return includes_version_; }
650
[email protected]8b37a092012-10-18 21:53:49651 char* mutable_data() { return buffer_; }
652
653 private:
[email protected]5351cc4b2013-03-03 07:22:41654 QuicPacket(char* buffer,
655 size_t length,
656 bool owns_buffer,
[email protected]b064310782013-05-30 21:12:17657 QuicGuidLength guid_length,
[email protected]5351cc4b2013-03-03 07:22:41658 bool includes_version,
659 bool is_fec_packet)
[email protected]c995c572013-01-18 05:43:20660 : QuicData(buffer, length, owns_buffer),
661 buffer_(buffer),
[email protected]5351cc4b2013-03-03 07:22:41662 is_fec_packet_(is_fec_packet),
[email protected]b064310782013-05-30 21:12:17663 guid_length_(guid_length),
[email protected]5351cc4b2013-03-03 07:22:41664 includes_version_(includes_version) {}
[email protected]c995c572013-01-18 05:43:20665
[email protected]8b37a092012-10-18 21:53:49666 char* buffer_;
[email protected]c995c572013-01-18 05:43:20667 const bool is_fec_packet_;
[email protected]b064310782013-05-30 21:12:17668 const QuicGuidLength guid_length_;
[email protected]5351cc4b2013-03-03 07:22:41669 const bool includes_version_;
[email protected]8b37a092012-10-18 21:53:49670
[email protected]2e740db2012-10-20 19:35:19671 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
[email protected]8b37a092012-10-18 21:53:49672};
673
674class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
675 public:
676 QuicEncryptedPacket(const char* buffer, size_t length)
[email protected]5351cc4b2013-03-03 07:22:41677 : QuicData(buffer, length) {}
[email protected]8b37a092012-10-18 21:53:49678
679 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer)
[email protected]5351cc4b2013-03-03 07:22:41680 : QuicData(buffer, length, owns_buffer) {}
[email protected]8b37a092012-10-18 21:53:49681
[email protected]c1b32c62013-01-20 02:49:10682 // By default, gtest prints the raw bytes of an object. The bool data
683 // member (in the base class QuicData) causes this object to have padding
684 // bytes, which causes the default gtest object printer to read
685 // uninitialize memory. So we need to teach gtest how to print this object.
686 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
687 std::ostream& os, const QuicEncryptedPacket& s);
688
[email protected]2e740db2012-10-20 19:35:19689 private:
690 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
[email protected]8b37a092012-10-18 21:53:49691};
692
[email protected]9db443912013-02-25 05:27:03693class NET_EXPORT_PRIVATE RetransmittableFrames {
694 public:
695 RetransmittableFrames();
696 ~RetransmittableFrames();
697
698 // Allocates a local copy of the referenced StringPiece has QuicStreamFrame
699 // use it.
700 // Takes ownership of |stream_frame|.
701 const QuicFrame& AddStreamFrame(QuicStreamFrame* stream_frame);
702 // Takes ownership of the frame inside |frame|.
703 const QuicFrame& AddNonStreamFrame(const QuicFrame& frame);
704 const QuicFrames& frames() const { return frames_; }
705
[email protected]8ba81212013-05-03 13:11:48706 void set_encryption_level(EncryptionLevel level);
707 EncryptionLevel encryption_level() const {
708 return encryption_level_;
709 }
710
[email protected]9db443912013-02-25 05:27:03711 private:
712 QuicFrames frames_;
[email protected]8ba81212013-05-03 13:11:48713 EncryptionLevel encryption_level_;
[email protected]9db443912013-02-25 05:27:03714 // Data referenced by the StringPiece of a QuicStreamFrame.
715 std::vector<std::string*> stream_data_;
716
717 DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames);
718};
719
720struct NET_EXPORT_PRIVATE SerializedPacket {
721 SerializedPacket(QuicPacketSequenceNumber sequence_number,
722 QuicPacket* packet,
723 QuicPacketEntropyHash entropy_hash,
724 RetransmittableFrames* retransmittable_frames)
725 : sequence_number(sequence_number),
726 packet(packet),
727 entropy_hash(entropy_hash),
[email protected]5351cc4b2013-03-03 07:22:41728 retransmittable_frames(retransmittable_frames) {}
[email protected]9db443912013-02-25 05:27:03729
730 QuicPacketSequenceNumber sequence_number;
731 QuicPacket* packet;
732 QuicPacketEntropyHash entropy_hash;
733 RetransmittableFrames* retransmittable_frames;
734};
735
[email protected]c995c572013-01-18 05:43:20736// A struct for functions which consume data payloads and fins.
737// The first member of the pair indicates bytes consumed.
738// The second member of the pair indicates if an incoming fin was consumed.
739struct QuicConsumedData {
740 QuicConsumedData(size_t bytes_consumed, bool fin_consumed)
741 : bytes_consumed(bytes_consumed),
[email protected]5351cc4b2013-03-03 07:22:41742 fin_consumed(fin_consumed) {}
[email protected]c1b32c62013-01-20 02:49:10743
744 // By default, gtest prints the raw bytes of an object. The bool data
745 // member causes this object to have padding bytes, which causes the
746 // default gtest object printer to read uninitialize memory. So we need
747 // to teach gtest how to print this object.
748 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
749 std::ostream& os, const QuicConsumedData& s);
750
[email protected]c995c572013-01-18 05:43:20751 size_t bytes_consumed;
752 bool fin_consumed;
753};
754
[email protected]8b37a092012-10-18 21:53:49755} // namespace net
756
757#endif // NET_QUIC_QUIC_PROTOCOL_H_