blob: d4f23ded364300a31c439470a5c443e3263c9c27 [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;
31
32typedef uint64 QuicGuid;
33typedef uint32 QuicStreamId;
34typedef uint64 QuicStreamOffset;
35typedef uint64 QuicPacketSequenceNumber;
[email protected]c995c572013-01-18 05:43:2036typedef QuicPacketSequenceNumber QuicFecGroupNumber;
[email protected]86a318d2013-01-23 21:16:0437typedef uint64 QuicPublicResetNonceProof;
[email protected]9db443912013-02-25 05:27:0338typedef uint8 QuicPacketEntropyHash;
[email protected]5351cc4b2013-03-03 07:22:4139typedef uint32 QuicVersionTag;
[email protected]14e8106c2013-03-14 16:25:3340typedef std::vector<QuicVersionTag> QuicVersionTagList;
[email protected]cff7b7b2013-01-11 08:49:0741
[email protected]8b37a092012-10-18 21:53:4942// TODO(rch): Consider Quic specific names for these constants.
[email protected]fee17f72013-02-03 07:47:4143// Maximum size in bytes of a QUIC packet.
44const QuicByteCount kMaxPacketSize = 1200;
[email protected]8b37a092012-10-18 21:53:4945
46// Maximum number of open streams per connection.
47const size_t kDefaultMaxStreamsPerConnection = 100;
48
[email protected]c995c572013-01-18 05:43:2049// Number of bytes reserved for guid in the packet header.
50const size_t kQuicGuidSize = 8;
51// Number of bytes reserved for public flags in the packet header.
52const size_t kPublicFlagsSize = 1;
[email protected]5351cc4b2013-03-03 07:22:4153// Number of bytes reserved for version number in the packet header.
54const size_t kQuicVersionSize = 4;
[email protected]c995c572013-01-18 05:43:2055// Number of bytes reserved for sequence number in the packet header.
56const size_t kSequenceNumberSize = 6;
57// Number of bytes reserved for private flags in the packet header.
58const size_t kPrivateFlagsSize = 1;
59// Number of bytes reserved for FEC group in the packet header.
60const size_t kFecGroupSize = 1;
[email protected]86a318d2013-01-23 21:16:0461// Number of bytes reserved for the nonce proof in public reset packet.
62const size_t kPublicResetNonceSize = 8;
[email protected]5351cc4b2013-03-03 07:22:4163
64// Signifies that the QuicPacket will contain version of the protocol.
65const bool kIncludeVersion = true;
[email protected]c995c572013-01-18 05:43:2066
67// Size in bytes of the data or fec packet header.
[email protected]5351cc4b2013-03-03 07:22:4168NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(bool include_version);
[email protected]86a318d2013-01-23 21:16:0469// Size in bytes of the public reset packet.
[email protected]5351cc4b2013-03-03 07:22:4170NET_EXPORT_PRIVATE size_t GetPublicResetPacketSize();
[email protected]86a318d2013-01-23 21:16:0471
[email protected]8b37a092012-10-18 21:53:4972// Index of the first byte in a QUIC packet of FEC protected data.
[email protected]5351cc4b2013-03-03 07:22:4173NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(bool include_version);
[email protected]8b37a092012-10-18 21:53:4974// Index of the first byte in a QUIC packet of encrypted data.
[email protected]5351cc4b2013-03-03 07:22:4175NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(bool include_version);
[email protected]14e8106c2013-03-14 16:25:3376// Returns true if |version| is a supported protocol version.
77NET_EXPORT_PRIVATE bool IsSupportedVersion(QuicVersionTag version);
[email protected]8b37a092012-10-18 21:53:4978
[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;
84
85// Reserved ID for the crypto stream.
86// TODO(rch): ensure that this is not usable by any other streams.
87const QuicStreamId kCryptoStreamId = 1;
88
[email protected]c995c572013-01-18 05:43:2089// Value which indicates this packet is not FEC protected.
90const uint8 kNoFecOffset = 0xFF;
91
[email protected]2a960e02012-11-11 14:48:1092const int64 kDefaultTimeoutUs = 600000000; // 10 minutes.
[email protected]8b37a092012-10-18 21:53:4993
[email protected]74bda142013-03-31 02:49:1194enum Retransmission {
95 NOT_RETRANSMISSION = 0,
96 IS_RETRANSMISSION = 1,
97};
98
99enum HasRetransmittableData {
100 HAS_RETRANSMITTABLE_DATA = 0,
101 NO_RETRANSMITTABLE_DATA = 1,
102};
103
[email protected]be24ab22012-10-22 03:01:52104enum QuicFrameType {
[email protected]c995c572013-01-18 05:43:20105 PADDING_FRAME = 0,
106 STREAM_FRAME,
[email protected]be24ab22012-10-22 03:01:52107 ACK_FRAME,
[email protected]26f3f8e2012-12-13 21:07:19108 CONGESTION_FEEDBACK_FRAME,
[email protected]be24ab22012-10-22 03:01:52109 RST_STREAM_FRAME,
110 CONNECTION_CLOSE_FRAME,
[email protected]9db443912013-02-25 05:27:03111 GOAWAY_FRAME,
[email protected]be24ab22012-10-22 03:01:52112 NUM_FRAME_TYPES
[email protected]8b37a092012-10-18 21:53:49113};
114
[email protected]c995c572013-01-18 05:43:20115enum QuicPacketPublicFlags {
116 PACKET_PUBLIC_FLAGS_NONE = 0,
[email protected]5351cc4b2013-03-03 07:22:41117 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0, // Packet header contains version info.
[email protected]9db443912013-02-25 05:27:03118 PACKET_PUBLIC_FLAGS_RST = 1 << 1, // Packet is a public reset packet.
119 PACKET_PUBLIC_FLAGS_MAX = (1 << 2) - 1 // All bits set.
[email protected]c995c572013-01-18 05:43:20120};
[email protected]8b37a092012-10-18 21:53:49121
[email protected]c995c572013-01-18 05:43:20122enum QuicPacketPrivateFlags {
123 PACKET_PRIVATE_FLAGS_NONE = 0,
[email protected]9db443912013-02-25 05:27:03124 PACKET_PRIVATE_FLAGS_FEC = 1 << 0, // Payload is FEC as opposed to frames.
125 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 1,
126 PACKET_PRIVATE_FLAGS_FEC_ENTROPY = 1 << 2,
127 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1 // All bits set.
[email protected]c995c572013-01-18 05:43:20128};
129
[email protected]74bda142013-03-31 02:49:11130enum QuicRstStreamErrorCode {
131 QUIC_STREAM_NO_ERROR = 0,
[email protected]8b37a092012-10-18 21:53:49132
[email protected]8b37a092012-10-18 21:53:49133 // There was some server error which halted stream processing.
134 QUIC_SERVER_ERROR_PROCESSING_STREAM,
135 // We got two fin or reset offsets which did not match.
136 QUIC_MULTIPLE_TERMINATION_OFFSETS,
137 // We got bad payload and can not respond to it at the protocol level.
138 QUIC_BAD_APPLICATION_PAYLOAD,
[email protected]74bda142013-03-31 02:49:11139 // Stream closed due to connection error. No reset frame is sent when this
140 // happens.
141 QUIC_STREAM_CONNECTION_ERROR,
142 // GoAway frame sent. No more stream can be created.
143 QUIC_STREAM_PEER_GOING_AWAY,
[email protected]8b37a092012-10-18 21:53:49144
[email protected]74bda142013-03-31 02:49:11145 // No error. Used as bound while iterating.
146 QUIC_STREAM_LAST_ERROR,
147};
[email protected]8b37a092012-10-18 21:53:49148
[email protected]74bda142013-03-31 02:49:11149enum QuicErrorCode {
150 QUIC_NO_ERROR = 0,
151
152 // Connection has reached an invalid state.
153 QUIC_INTERNAL_ERROR,
154 // There were data frames after the a fin or reset.
155 QUIC_STREAM_DATA_AFTER_TERMINATION,
[email protected]8b37a092012-10-18 21:53:49156 // Control frame is malformed.
157 QUIC_INVALID_PACKET_HEADER,
[email protected]be24ab22012-10-22 03:01:52158 // Frame data is malformed.
159 QUIC_INVALID_FRAME_DATA,
[email protected]8b37a092012-10-18 21:53:49160 // FEC data is malformed.
161 QUIC_INVALID_FEC_DATA,
162 // Stream rst data is malformed
163 QUIC_INVALID_RST_STREAM_DATA,
164 // Connection close data is malformed.
165 QUIC_INVALID_CONNECTION_CLOSE_DATA,
[email protected]9db443912013-02-25 05:27:03166 // GoAway data is malformed.
167 QUIC_INVALID_GOAWAY_DATA,
[email protected]8b37a092012-10-18 21:53:49168 // Ack data is malformed.
169 QUIC_INVALID_ACK_DATA,
[email protected]14e8106c2013-03-14 16:25:33170 // Version negotiation packet is malformed.
171 QUIC_INVALID_VERSION_NEGOTIATION_PACKET,
[email protected]8b37a092012-10-18 21:53:49172 // There was an error decrypting.
173 QUIC_DECRYPTION_FAILURE,
174 // There was an error encrypting.
175 QUIC_ENCRYPTION_FAILURE,
176 // The packet exceeded kMaxPacketSize.
177 QUIC_PACKET_TOO_LARGE,
178 // Data was sent for a stream which did not exist.
179 QUIC_PACKET_FOR_NONEXISTENT_STREAM,
[email protected]9db443912013-02-25 05:27:03180 // The peer is going away. May be a client or server.
181 QUIC_PEER_GOING_AWAY,
[email protected]8b37a092012-10-18 21:53:49182 // A stream ID was invalid.
183 QUIC_INVALID_STREAM_ID,
184 // Too many streams already open.
185 QUIC_TOO_MANY_OPEN_STREAMS,
[email protected]86a318d2013-01-23 21:16:04186 // Received public reset for this connection.
187 QUIC_PUBLIC_RESET,
[email protected]14e8106c2013-03-14 16:25:33188 // Invalid protocol version
189 QUIC_INVALID_VERSION,
[email protected]8b37a092012-10-18 21:53:49190
191 // We hit our prenegotiated (or default) timeout
192 QUIC_CONNECTION_TIMED_OUT,
193
194 // Crypto errors.
195
196 // Handshake message contained out of order tags.
197 QUIC_CRYPTO_TAGS_OUT_OF_ORDER,
[email protected]701bc892013-01-17 04:51:54198 // Handshake message contained too many entries.
[email protected]8b37a092012-10-18 21:53:49199 QUIC_CRYPTO_TOO_MANY_ENTRIES,
200 // Handshake message contained an invalid value length.
201 QUIC_CRYPTO_INVALID_VALUE_LENGTH,
202 // A crypto message was received after the handshake was complete.
203 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE,
[email protected]d3d15bf2013-01-30 02:51:54204 // A crypto message was received with an illegal message tag.
[email protected]8b37a092012-10-18 21:53:49205 QUIC_INVALID_CRYPTO_MESSAGE_TYPE,
[email protected]d3d15bf2013-01-30 02:51:54206 // A crypto message was received with an illegal parameter.
207 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER,
208 // A crypto message was received with a mandatory parameter missing.
209 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND,
210 // A crypto message was received with a parameter that has no overlap
211 // with the local parameter.
212 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP,
[email protected]ed3fc15d2013-03-08 18:37:44213 // A crypto message was received that contained a parameter with too few
214 // values.
215 QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND,
[email protected]ccc66e8a2013-03-26 08:26:14216 // An internal error occured in crypto processing.
217 QUIC_CRYPTO_INTERNAL_ERROR,
218 // A crypto handshake message specified an unsupported version.
[email protected]fe053f92013-04-23 20:18:55219 QUIC_CRYPTO_VERSION_NOT_SUPPORTED,
[email protected]ccc66e8a2013-03-26 08:26:14220 // There was no intersection between the crypto primitives supported by the
221 // peer and ourselves.
222 QUIC_CRYPTO_NO_SUPPORT,
[email protected]ef95114d2013-04-17 17:57:01223 // The server rejected our client hello messages too many times.
224 QUIC_CRYPTO_TOO_MANY_REJECTS,
[email protected]a57e0272013-04-26 07:31:47225 // The client rejected the server's certificate chain or signature.
226 QUIC_PROOF_INVALID,
[email protected]ccc66e8a2013-03-26 08:26:14227
[email protected]74bda142013-03-31 02:49:11228 // No error. Used as bound while iterating.
[email protected]ccc66e8a2013-03-26 08:26:14229 QUIC_LAST_ERROR,
[email protected]8b37a092012-10-18 21:53:49230};
231
[email protected]5351cc4b2013-03-03 07:22:41232// Version and Crypto tags are written to the wire with a big-endian
233// representation of the name of the tag. For example
234// the client hello tag (CHLO) will be written as the
235// following 4 bytes: 'C' 'H' 'L' 'O'. Since it is
236// stored in memory as a little endian uint32, we need
237// to reverse the order of the bytes.
[email protected]a57e0272013-04-26 07:31:47238//
239// The TAG macro is used in header files to ensure that we don't create static
240// initialisers. In normal code, the MakeQuicTag function should be used.
241#define TAG(a, b, c, d) ((d << 24) + (c << 16) + (b << 8) + a)
[email protected]14e8106c2013-03-14 16:25:33242const QuicVersionTag kUnsupportedVersion = -1;
[email protected]a57e0272013-04-26 07:31:47243const QuicVersionTag kQuicVersion1 = TAG('Q', '1', '.', '0');
244#undef TAG
245
246// MakeQuicTag returns a value given the four bytes. For example:
247// MakeQuicTag('C', 'H', 'L', 'O');
248uint32 NET_EXPORT_PRIVATE MakeQuicTag(char a, char b, char c, char d);
[email protected]5351cc4b2013-03-03 07:22:41249
[email protected]c995c572013-01-18 05:43:20250struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
[email protected]14e8106c2013-03-14 16:25:33251 QuicPacketPublicHeader();
252 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
253 ~QuicPacketPublicHeader();
254
255 QuicPacketPublicHeader& operator=(const QuicPacketPublicHeader& other);
256
[email protected]c995c572013-01-18 05:43:20257 // Universal header. All QuicPacket headers will have a guid and public flags.
[email protected]8b37a092012-10-18 21:53:49258 QuicGuid guid;
[email protected]9db443912013-02-25 05:27:03259 bool reset_flag;
260 bool version_flag;
[email protected]14e8106c2013-03-14 16:25:33261 QuicVersionTagList versions;
[email protected]c995c572013-01-18 05:43:20262};
263
264// Header for Data or FEC packets.
[email protected]74bda142013-03-31 02:49:11265struct NET_EXPORT_PRIVATE QuicPacketHeader {
266 QuicPacketHeader();
267 explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
[email protected]9db443912013-02-25 05:27:03268
269 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
270 std::ostream& os, const QuicPacketHeader& s);
271
[email protected]c995c572013-01-18 05:43:20272 QuicPacketPublicHeader public_header;
[email protected]9db443912013-02-25 05:27:03273 bool fec_flag;
274 bool fec_entropy_flag;
275 bool entropy_flag;
276 QuicPacketEntropyHash entropy_hash;
[email protected]8b37a092012-10-18 21:53:49277 QuicPacketSequenceNumber packet_sequence_number;
[email protected]8b37a092012-10-18 21:53:49278 QuicFecGroupNumber fec_group;
279};
280
[email protected]74bda142013-03-31 02:49:11281struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
[email protected]86a318d2013-01-23 21:16:04282 QuicPublicResetPacket() {}
283 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header)
284 : public_header(header) {}
285 QuicPacketPublicHeader public_header;
286 QuicPacketSequenceNumber rejected_sequence_number;
287 QuicPublicResetNonceProof nonce_proof;
288};
289
[email protected]14e8106c2013-03-14 16:25:33290enum QuicVersionNegotiationState {
291 START_NEGOTIATION = 0,
292 SENT_NEGOTIATION_PACKET,
293 NEGOTIATED_VERSION
294};
295
296typedef QuicPacketPublicHeader QuicVersionNegotiationPacket;
297
[email protected]c995c572013-01-18 05:43:20298// A padding frame contains no payload.
299struct NET_EXPORT_PRIVATE QuicPaddingFrame {
300};
301
[email protected]be24ab22012-10-22 03:01:52302struct NET_EXPORT_PRIVATE QuicStreamFrame {
303 QuicStreamFrame();
304 QuicStreamFrame(QuicStreamId stream_id,
[email protected]a5061242012-10-23 23:29:37305 bool fin,
[email protected]701bc892013-01-17 04:51:54306 QuicStreamOffset offset,
[email protected]a5061242012-10-23 23:29:37307 base::StringPiece data);
[email protected]8b37a092012-10-18 21:53:49308
309 QuicStreamId stream_id;
310 bool fin;
[email protected]701bc892013-01-17 04:51:54311 QuicStreamOffset offset; // Location of this data in the stream.
[email protected]8b37a092012-10-18 21:53:49312 base::StringPiece data;
313};
314
[email protected]e537f742012-12-07 15:33:53315// TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
316// is finalized.
[email protected]9db443912013-02-25 05:27:03317typedef std::set<QuicPacketSequenceNumber> SequenceNumberSet;
[email protected]3c5f4a732013-01-12 16:45:34318// TODO(pwestin): Add a way to enforce the max size of this map.
[email protected]e537f742012-12-07 15:33:53319typedef std::map<QuicPacketSequenceNumber, QuicTime> TimeMap;
[email protected]044ac2b2012-11-13 21:41:06320
[email protected]8b37a092012-10-18 21:53:49321struct NET_EXPORT_PRIVATE ReceivedPacketInfo {
322 ReceivedPacketInfo();
323 ~ReceivedPacketInfo();
[email protected]26f3f8e2012-12-13 21:07:19324 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
325 std::ostream& os, const ReceivedPacketInfo& s);
[email protected]a674b4c2012-12-05 03:44:30326
[email protected]9db443912013-02-25 05:27:03327 // Entropy hash of all packets up to largest observed not including missing
328 // packets.
329 QuicPacketEntropyHash entropy_hash;
[email protected]e537f742012-12-07 15:33:53330
[email protected]48697d8a2013-01-15 19:42:24331 // The highest packet sequence number we've observed from the peer.
332 //
333 // In general, this should be the largest packet number we've received. In
334 // the case of truncated acks, we may have to advertise a lower "upper bound"
335 // than largest received, to avoid implicitly acking missing packets that
336 // don't fit in the missing packet list due to size limitations. In this
337 // case, largest_observed may be a packet which is also in the missing packets
338 // list.
339 QuicPacketSequenceNumber largest_observed;
[email protected]a674b4c2012-12-05 03:44:30340
[email protected]14e8106c2013-03-14 16:25:33341 // Time elapsed since largest_observed was received until this Ack frame was
342 // sent.
343 QuicTime::Delta delta_time_largest_observed;
344
[email protected]9db443912013-02-25 05:27:03345 // TODO(satyamshekhar): Can be optimized using an interval set like data
346 // structure.
[email protected]e537f742012-12-07 15:33:53347 // The set of packets which we're expecting and have not received.
[email protected]9db443912013-02-25 05:27:03348 SequenceNumberSet missing_packets;
[email protected]8b37a092012-10-18 21:53:49349};
350
[email protected]9db443912013-02-25 05:27:03351// True if the sequence number is greater than largest_observed or is listed
352// as missing.
353// Always returns false for sequence numbers less than least_unacked.
354bool NET_EXPORT_PRIVATE IsAwaitingPacket(
355 const ReceivedPacketInfo& received_info,
356 QuicPacketSequenceNumber sequence_number);
357
358// Inserts missing packets between [lower, higher).
359void NET_EXPORT_PRIVATE InsertMissingPacketsBetween(
360 ReceivedPacketInfo* received_info,
361 QuicPacketSequenceNumber lower,
362 QuicPacketSequenceNumber higher);
363
[email protected]8b37a092012-10-18 21:53:49364struct NET_EXPORT_PRIVATE SentPacketInfo {
365 SentPacketInfo();
366 ~SentPacketInfo();
[email protected]26f3f8e2012-12-13 21:07:19367 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
368 std::ostream& os, const SentPacketInfo& s);
369
[email protected]9db443912013-02-25 05:27:03370 // Entropy hash of all packets up to, but not including, the least unacked
371 // packet.
372 QuicPacketEntropyHash entropy_hash;
[email protected]8b37a092012-10-18 21:53:49373 // The lowest packet we've sent which is unacked, and we expect an ack for.
374 QuicPacketSequenceNumber least_unacked;
[email protected]8b37a092012-10-18 21:53:49375};
376
[email protected]26f3f8e2012-12-13 21:07:19377struct NET_EXPORT_PRIVATE QuicAckFrame {
378 QuicAckFrame() {}
379 // Testing convenience method to construct a QuicAckFrame with all packets
[email protected]48697d8a2013-01-15 19:42:24380 // from least_unacked to largest_observed acked.
381 QuicAckFrame(QuicPacketSequenceNumber largest_observed,
[email protected]14e8106c2013-03-14 16:25:33382 QuicTime largest_observed_receive_time,
[email protected]26f3f8e2012-12-13 21:07:19383 QuicPacketSequenceNumber least_unacked);
384
385 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
386 std::ostream& os, const QuicAckFrame& s);
387
388 SentPacketInfo sent_info;
389 ReceivedPacketInfo received_info;
390};
391
[email protected]8b37a092012-10-18 21:53:49392// Defines for all types of congestion feedback that will be negotiated in QUIC,
393// kTCP MUST be supported by all QUIC implementations to guarentee 100%
394// compatibility.
395enum CongestionFeedbackType {
[email protected]8b37a092012-10-18 21:53:49396 kTCP, // Used to mimic TCP.
397 kInterArrival, // Use additional inter arrival information.
398 kFixRate, // Provided for testing.
399};
400
401struct NET_EXPORT_PRIVATE CongestionFeedbackMessageTCP {
402 uint16 accumulated_number_of_lost_packets;
[email protected]fee17f72013-02-03 07:47:41403 QuicByteCount receive_window;
[email protected]8b37a092012-10-18 21:53:49404};
405
406struct NET_EXPORT_PRIVATE CongestionFeedbackMessageInterArrival {
[email protected]7884ecad2012-12-14 22:55:15407 CongestionFeedbackMessageInterArrival();
408 ~CongestionFeedbackMessageInterArrival();
[email protected]8b37a092012-10-18 21:53:49409 uint16 accumulated_number_of_lost_packets;
[email protected]7884ecad2012-12-14 22:55:15410 // The set of received packets since the last feedback was sent, along with
411 // their arrival times.
412 TimeMap received_packet_times;
[email protected]8b37a092012-10-18 21:53:49413};
414
[email protected]8b37a092012-10-18 21:53:49415struct NET_EXPORT_PRIVATE CongestionFeedbackMessageFixRate {
[email protected]fee17f72013-02-03 07:47:41416 CongestionFeedbackMessageFixRate();
417 QuicBandwidth bitrate;
[email protected]8b37a092012-10-18 21:53:49418};
419
[email protected]26f3f8e2012-12-13 21:07:19420struct NET_EXPORT_PRIVATE QuicCongestionFeedbackFrame {
[email protected]7884ecad2012-12-14 22:55:15421 QuicCongestionFeedbackFrame();
422 ~QuicCongestionFeedbackFrame();
423
[email protected]26f3f8e2012-12-13 21:07:19424 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
425 std::ostream& os, const QuicCongestionFeedbackFrame& c);
426
[email protected]7884ecad2012-12-14 22:55:15427 CongestionFeedbackType type;
428 // This should really be a union, but since the inter arrival struct
429 // is non-trivial, C++ prohibits it.
430 CongestionFeedbackMessageTCP tcp;
431 CongestionFeedbackMessageInterArrival inter_arrival;
432 CongestionFeedbackMessageFixRate fix_rate;
[email protected]8b37a092012-10-18 21:53:49433};
434
[email protected]be24ab22012-10-22 03:01:52435struct NET_EXPORT_PRIVATE QuicRstStreamFrame {
436 QuicRstStreamFrame() {}
[email protected]74bda142013-03-31 02:49:11437 QuicRstStreamFrame(QuicStreamId stream_id, QuicRstStreamErrorCode error_code)
[email protected]9db443912013-02-25 05:27:03438 : stream_id(stream_id), error_code(error_code) {
[email protected]431bb4fd2012-10-19 17:46:09439 DCHECK_LE(error_code, std::numeric_limits<uint8>::max());
[email protected]8b37a092012-10-18 21:53:49440 }
441
442 QuicStreamId stream_id;
[email protected]74bda142013-03-31 02:49:11443 QuicRstStreamErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09444 std::string error_details;
[email protected]8b37a092012-10-18 21:53:49445};
446
[email protected]be24ab22012-10-22 03:01:52447struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame {
[email protected]431bb4fd2012-10-19 17:46:09448 QuicErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09449 std::string error_details;
[email protected]d3d15bf2013-01-30 02:51:54450 QuicAckFrame ack_frame;
[email protected]8b37a092012-10-18 21:53:49451};
452
[email protected]9db443912013-02-25 05:27:03453struct NET_EXPORT_PRIVATE QuicGoAwayFrame {
454 QuicGoAwayFrame() {}
455 QuicGoAwayFrame(QuicErrorCode error_code,
456 QuicStreamId last_good_stream_id,
457 const std::string& reason);
458
459 QuicErrorCode error_code;
460 QuicStreamId last_good_stream_id;
461 std::string reason_phrase;
462};
463
[email protected]be24ab22012-10-22 03:01:52464struct NET_EXPORT_PRIVATE QuicFrame {
465 QuicFrame() {}
[email protected]c995c572013-01-18 05:43:20466 explicit QuicFrame(QuicPaddingFrame* padding_frame)
467 : type(PADDING_FRAME),
468 padding_frame(padding_frame) {
469 }
[email protected]be24ab22012-10-22 03:01:52470 explicit QuicFrame(QuicStreamFrame* stream_frame)
[email protected]610a7e942012-12-18 00:21:39471 : type(STREAM_FRAME),
472 stream_frame(stream_frame) {
[email protected]8b37a092012-10-18 21:53:49473 }
[email protected]be24ab22012-10-22 03:01:52474 explicit QuicFrame(QuicAckFrame* frame)
[email protected]610a7e942012-12-18 00:21:39475 : type(ACK_FRAME),
476 ack_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49477 }
[email protected]26f3f8e2012-12-13 21:07:19478 explicit QuicFrame(QuicCongestionFeedbackFrame* frame)
[email protected]610a7e942012-12-18 00:21:39479 : type(CONGESTION_FEEDBACK_FRAME),
480 congestion_feedback_frame(frame) {
[email protected]26f3f8e2012-12-13 21:07:19481 }
[email protected]be24ab22012-10-22 03:01:52482 explicit QuicFrame(QuicRstStreamFrame* frame)
483 : type(RST_STREAM_FRAME),
484 rst_stream_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49485 }
[email protected]be24ab22012-10-22 03:01:52486 explicit QuicFrame(QuicConnectionCloseFrame* frame)
487 : type(CONNECTION_CLOSE_FRAME),
488 connection_close_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49489 }
[email protected]9db443912013-02-25 05:27:03490 explicit QuicFrame(QuicGoAwayFrame* frame)
491 : type(GOAWAY_FRAME),
492 goaway_frame(frame) {
493 }
[email protected]8b37a092012-10-18 21:53:49494
[email protected]be24ab22012-10-22 03:01:52495 QuicFrameType type;
[email protected]8b37a092012-10-18 21:53:49496 union {
[email protected]c995c572013-01-18 05:43:20497 QuicPaddingFrame* padding_frame;
[email protected]be24ab22012-10-22 03:01:52498 QuicStreamFrame* stream_frame;
499 QuicAckFrame* ack_frame;
[email protected]26f3f8e2012-12-13 21:07:19500 QuicCongestionFeedbackFrame* congestion_feedback_frame;
[email protected]be24ab22012-10-22 03:01:52501 QuicRstStreamFrame* rst_stream_frame;
502 QuicConnectionCloseFrame* connection_close_frame;
[email protected]9db443912013-02-25 05:27:03503 QuicGoAwayFrame* goaway_frame;
[email protected]8b37a092012-10-18 21:53:49504 };
505};
506
[email protected]be24ab22012-10-22 03:01:52507typedef std::vector<QuicFrame> QuicFrames;
[email protected]8b37a092012-10-18 21:53:49508
509struct NET_EXPORT_PRIVATE QuicFecData {
510 QuicFecData();
[email protected]a5061242012-10-23 23:29:37511
512 bool operator==(const QuicFecData& other) const;
513
[email protected]c995c572013-01-18 05:43:20514 // The FEC group number is also the sequence number of the first
515 // FEC protected packet. The last protected packet's sequence number will
516 // be one less than the sequence number of the FEC packet.
[email protected]8b37a092012-10-18 21:53:49517 QuicFecGroupNumber fec_group;
[email protected]8b37a092012-10-18 21:53:49518 base::StringPiece redundancy;
[email protected]8b37a092012-10-18 21:53:49519};
520
521struct NET_EXPORT_PRIVATE QuicPacketData {
522 std::string data;
523};
524
525class NET_EXPORT_PRIVATE QuicData {
526 public:
527 QuicData(const char* buffer, size_t length)
528 : buffer_(buffer),
529 length_(length),
[email protected]5351cc4b2013-03-03 07:22:41530 owns_buffer_(false) {}
[email protected]8b37a092012-10-18 21:53:49531
532 QuicData(char* buffer, size_t length, bool owns_buffer)
533 : buffer_(buffer),
534 length_(length),
[email protected]5351cc4b2013-03-03 07:22:41535 owns_buffer_(owns_buffer) {}
[email protected]8b37a092012-10-18 21:53:49536
537 virtual ~QuicData();
538
539 base::StringPiece AsStringPiece() const {
540 return base::StringPiece(data(), length());
541 }
542
543 const char* data() const { return buffer_; }
544 size_t length() const { return length_; }
545
546 private:
547 const char* buffer_;
548 size_t length_;
549 bool owns_buffer_;
550
551 DISALLOW_COPY_AND_ASSIGN(QuicData);
552};
553
554class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
555 public:
[email protected]c995c572013-01-18 05:43:20556 static QuicPacket* NewDataPacket(char* buffer,
[email protected]9db443912013-02-25 05:27:03557 size_t length,
[email protected]5351cc4b2013-03-03 07:22:41558 bool owns_buffer,
559 bool includes_version) {
560 return new QuicPacket(buffer, length, owns_buffer, includes_version, false);
[email protected]c995c572013-01-18 05:43:20561 }
562
563 static QuicPacket* NewFecPacket(char* buffer,
564 size_t length,
[email protected]5351cc4b2013-03-03 07:22:41565 bool owns_buffer,
566 bool includes_version) {
567 return new QuicPacket(buffer, length, owns_buffer, includes_version, true);
[email protected]c995c572013-01-18 05:43:20568 }
[email protected]8b37a092012-10-18 21:53:49569
[email protected]5351cc4b2013-03-03 07:22:41570 base::StringPiece FecProtectedData() const;
571 base::StringPiece AssociatedData() const;
572 base::StringPiece BeforePlaintext() const;
573 base::StringPiece Plaintext() const;
[email protected]082b65b2012-11-10 19:11:31574
[email protected]c995c572013-01-18 05:43:20575 bool is_fec_packet() const { return is_fec_packet_; }
[email protected]082b65b2012-11-10 19:11:31576
[email protected]5351cc4b2013-03-03 07:22:41577 bool includes_version() const { return includes_version_; }
578
[email protected]8b37a092012-10-18 21:53:49579 char* mutable_data() { return buffer_; }
580
581 private:
[email protected]5351cc4b2013-03-03 07:22:41582 QuicPacket(char* buffer,
583 size_t length,
584 bool owns_buffer,
585 bool includes_version,
586 bool is_fec_packet)
[email protected]c995c572013-01-18 05:43:20587 : QuicData(buffer, length, owns_buffer),
588 buffer_(buffer),
[email protected]5351cc4b2013-03-03 07:22:41589 is_fec_packet_(is_fec_packet),
590 includes_version_(includes_version) {}
[email protected]c995c572013-01-18 05:43:20591
[email protected]8b37a092012-10-18 21:53:49592 char* buffer_;
[email protected]c995c572013-01-18 05:43:20593 const bool is_fec_packet_;
[email protected]5351cc4b2013-03-03 07:22:41594 const bool includes_version_;
[email protected]8b37a092012-10-18 21:53:49595
[email protected]2e740db2012-10-20 19:35:19596 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
[email protected]8b37a092012-10-18 21:53:49597};
598
599class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
600 public:
601 QuicEncryptedPacket(const char* buffer, size_t length)
[email protected]5351cc4b2013-03-03 07:22:41602 : QuicData(buffer, length) {}
[email protected]8b37a092012-10-18 21:53:49603
604 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer)
[email protected]5351cc4b2013-03-03 07:22:41605 : QuicData(buffer, length, owns_buffer) {}
[email protected]8b37a092012-10-18 21:53:49606
[email protected]c1b32c62013-01-20 02:49:10607 // By default, gtest prints the raw bytes of an object. The bool data
608 // member (in the base class QuicData) causes this object to have padding
609 // bytes, which causes the default gtest object printer to read
610 // uninitialize memory. So we need to teach gtest how to print this object.
611 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
612 std::ostream& os, const QuicEncryptedPacket& s);
613
[email protected]2e740db2012-10-20 19:35:19614 private:
615 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
[email protected]8b37a092012-10-18 21:53:49616};
617
[email protected]9db443912013-02-25 05:27:03618class NET_EXPORT_PRIVATE RetransmittableFrames {
619 public:
620 RetransmittableFrames();
621 ~RetransmittableFrames();
622
623 // Allocates a local copy of the referenced StringPiece has QuicStreamFrame
624 // use it.
625 // Takes ownership of |stream_frame|.
626 const QuicFrame& AddStreamFrame(QuicStreamFrame* stream_frame);
627 // Takes ownership of the frame inside |frame|.
628 const QuicFrame& AddNonStreamFrame(const QuicFrame& frame);
629 const QuicFrames& frames() const { return frames_; }
630
631 private:
632 QuicFrames frames_;
633 // Data referenced by the StringPiece of a QuicStreamFrame.
634 std::vector<std::string*> stream_data_;
635
636 DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames);
637};
638
639struct NET_EXPORT_PRIVATE SerializedPacket {
640 SerializedPacket(QuicPacketSequenceNumber sequence_number,
641 QuicPacket* packet,
642 QuicPacketEntropyHash entropy_hash,
643 RetransmittableFrames* retransmittable_frames)
644 : sequence_number(sequence_number),
645 packet(packet),
646 entropy_hash(entropy_hash),
[email protected]5351cc4b2013-03-03 07:22:41647 retransmittable_frames(retransmittable_frames) {}
[email protected]9db443912013-02-25 05:27:03648
649 QuicPacketSequenceNumber sequence_number;
650 QuicPacket* packet;
651 QuicPacketEntropyHash entropy_hash;
652 RetransmittableFrames* retransmittable_frames;
653};
654
[email protected]c995c572013-01-18 05:43:20655// A struct for functions which consume data payloads and fins.
656// The first member of the pair indicates bytes consumed.
657// The second member of the pair indicates if an incoming fin was consumed.
658struct QuicConsumedData {
659 QuicConsumedData(size_t bytes_consumed, bool fin_consumed)
660 : bytes_consumed(bytes_consumed),
[email protected]5351cc4b2013-03-03 07:22:41661 fin_consumed(fin_consumed) {}
[email protected]c1b32c62013-01-20 02:49:10662
663 // By default, gtest prints the raw bytes of an object. The bool data
664 // member causes this object to have padding bytes, which causes the
665 // default gtest object printer to read uninitialize memory. So we need
666 // to teach gtest how to print this object.
667 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
668 std::ostream& os, const QuicConsumedData& s);
669
[email protected]c995c572013-01-18 05:43:20670 size_t bytes_consumed;
671 bool fin_consumed;
672};
673
[email protected]8b37a092012-10-18 21:53:49674} // namespace net
675
676#endif // NET_QUIC_QUIC_PROTOCOL_H_