blob: 44aedf9e2a1fd54adc1367896ac74e2c4c38ecc9 [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"
20#include "base/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.
219 QUIC_VERSION_NOT_SUPPORTED,
220 // There was no intersection between the crypto primitives supported by the
221 // peer and ourselves.
222 QUIC_CRYPTO_NO_SUPPORT,
223
[email protected]74bda142013-03-31 02:49:11224 // No error. Used as bound while iterating.
[email protected]ccc66e8a2013-03-26 08:26:14225 QUIC_LAST_ERROR,
[email protected]8b37a092012-10-18 21:53:49226};
227
[email protected]5351cc4b2013-03-03 07:22:41228// Version and Crypto tags are written to the wire with a big-endian
229// representation of the name of the tag. For example
230// the client hello tag (CHLO) will be written as the
231// following 4 bytes: 'C' 'H' 'L' 'O'. Since it is
232// stored in memory as a little endian uint32, we need
233// to reverse the order of the bytes.
234#define MAKE_TAG(a, b, c, d) ((d << 24) + (c << 16) + (b << 8) + a)
235
[email protected]14e8106c2013-03-14 16:25:33236const QuicVersionTag kUnsupportedVersion = -1;
[email protected]5351cc4b2013-03-03 07:22:41237const QuicVersionTag kQuicVersion1 = MAKE_TAG('Q', '1', '.', '0');
238
[email protected]c995c572013-01-18 05:43:20239struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
[email protected]14e8106c2013-03-14 16:25:33240 QuicPacketPublicHeader();
241 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
242 ~QuicPacketPublicHeader();
243
244 QuicPacketPublicHeader& operator=(const QuicPacketPublicHeader& other);
245
[email protected]c995c572013-01-18 05:43:20246 // Universal header. All QuicPacket headers will have a guid and public flags.
[email protected]8b37a092012-10-18 21:53:49247 QuicGuid guid;
[email protected]9db443912013-02-25 05:27:03248 bool reset_flag;
249 bool version_flag;
[email protected]14e8106c2013-03-14 16:25:33250 QuicVersionTagList versions;
[email protected]c995c572013-01-18 05:43:20251};
252
253// Header for Data or FEC packets.
[email protected]74bda142013-03-31 02:49:11254struct NET_EXPORT_PRIVATE QuicPacketHeader {
255 QuicPacketHeader();
256 explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
[email protected]9db443912013-02-25 05:27:03257
258 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
259 std::ostream& os, const QuicPacketHeader& s);
260
[email protected]c995c572013-01-18 05:43:20261 QuicPacketPublicHeader public_header;
[email protected]9db443912013-02-25 05:27:03262 bool fec_flag;
263 bool fec_entropy_flag;
264 bool entropy_flag;
265 QuicPacketEntropyHash entropy_hash;
[email protected]8b37a092012-10-18 21:53:49266 QuicPacketSequenceNumber packet_sequence_number;
[email protected]8b37a092012-10-18 21:53:49267 QuicFecGroupNumber fec_group;
268};
269
[email protected]74bda142013-03-31 02:49:11270struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
[email protected]86a318d2013-01-23 21:16:04271 QuicPublicResetPacket() {}
272 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header)
273 : public_header(header) {}
274 QuicPacketPublicHeader public_header;
275 QuicPacketSequenceNumber rejected_sequence_number;
276 QuicPublicResetNonceProof nonce_proof;
277};
278
[email protected]14e8106c2013-03-14 16:25:33279enum QuicVersionNegotiationState {
280 START_NEGOTIATION = 0,
281 SENT_NEGOTIATION_PACKET,
282 NEGOTIATED_VERSION
283};
284
285typedef QuicPacketPublicHeader QuicVersionNegotiationPacket;
286
[email protected]c995c572013-01-18 05:43:20287// A padding frame contains no payload.
288struct NET_EXPORT_PRIVATE QuicPaddingFrame {
289};
290
[email protected]be24ab22012-10-22 03:01:52291struct NET_EXPORT_PRIVATE QuicStreamFrame {
292 QuicStreamFrame();
293 QuicStreamFrame(QuicStreamId stream_id,
[email protected]a5061242012-10-23 23:29:37294 bool fin,
[email protected]701bc892013-01-17 04:51:54295 QuicStreamOffset offset,
[email protected]a5061242012-10-23 23:29:37296 base::StringPiece data);
[email protected]8b37a092012-10-18 21:53:49297
298 QuicStreamId stream_id;
299 bool fin;
[email protected]701bc892013-01-17 04:51:54300 QuicStreamOffset offset; // Location of this data in the stream.
[email protected]8b37a092012-10-18 21:53:49301 base::StringPiece data;
302};
303
[email protected]e537f742012-12-07 15:33:53304// TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
305// is finalized.
[email protected]9db443912013-02-25 05:27:03306typedef std::set<QuicPacketSequenceNumber> SequenceNumberSet;
[email protected]3c5f4a732013-01-12 16:45:34307// TODO(pwestin): Add a way to enforce the max size of this map.
[email protected]e537f742012-12-07 15:33:53308typedef std::map<QuicPacketSequenceNumber, QuicTime> TimeMap;
[email protected]044ac2b2012-11-13 21:41:06309
[email protected]8b37a092012-10-18 21:53:49310struct NET_EXPORT_PRIVATE ReceivedPacketInfo {
311 ReceivedPacketInfo();
312 ~ReceivedPacketInfo();
[email protected]26f3f8e2012-12-13 21:07:19313 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
314 std::ostream& os, const ReceivedPacketInfo& s);
[email protected]a674b4c2012-12-05 03:44:30315
[email protected]9db443912013-02-25 05:27:03316 // Entropy hash of all packets up to largest observed not including missing
317 // packets.
318 QuicPacketEntropyHash entropy_hash;
[email protected]e537f742012-12-07 15:33:53319
[email protected]48697d8a2013-01-15 19:42:24320 // The highest packet sequence number we've observed from the peer.
321 //
322 // In general, this should be the largest packet number we've received. In
323 // the case of truncated acks, we may have to advertise a lower "upper bound"
324 // than largest received, to avoid implicitly acking missing packets that
325 // don't fit in the missing packet list due to size limitations. In this
326 // case, largest_observed may be a packet which is also in the missing packets
327 // list.
328 QuicPacketSequenceNumber largest_observed;
[email protected]a674b4c2012-12-05 03:44:30329
[email protected]14e8106c2013-03-14 16:25:33330 // Time elapsed since largest_observed was received until this Ack frame was
331 // sent.
332 QuicTime::Delta delta_time_largest_observed;
333
[email protected]9db443912013-02-25 05:27:03334 // TODO(satyamshekhar): Can be optimized using an interval set like data
335 // structure.
[email protected]e537f742012-12-07 15:33:53336 // The set of packets which we're expecting and have not received.
[email protected]9db443912013-02-25 05:27:03337 SequenceNumberSet missing_packets;
[email protected]8b37a092012-10-18 21:53:49338};
339
[email protected]9db443912013-02-25 05:27:03340// True if the sequence number is greater than largest_observed or is listed
341// as missing.
342// Always returns false for sequence numbers less than least_unacked.
343bool NET_EXPORT_PRIVATE IsAwaitingPacket(
344 const ReceivedPacketInfo& received_info,
345 QuicPacketSequenceNumber sequence_number);
346
347// Inserts missing packets between [lower, higher).
348void NET_EXPORT_PRIVATE InsertMissingPacketsBetween(
349 ReceivedPacketInfo* received_info,
350 QuicPacketSequenceNumber lower,
351 QuicPacketSequenceNumber higher);
352
[email protected]8b37a092012-10-18 21:53:49353struct NET_EXPORT_PRIVATE SentPacketInfo {
354 SentPacketInfo();
355 ~SentPacketInfo();
[email protected]26f3f8e2012-12-13 21:07:19356 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
357 std::ostream& os, const SentPacketInfo& s);
358
[email protected]9db443912013-02-25 05:27:03359 // Entropy hash of all packets up to, but not including, the least unacked
360 // packet.
361 QuicPacketEntropyHash entropy_hash;
[email protected]8b37a092012-10-18 21:53:49362 // The lowest packet we've sent which is unacked, and we expect an ack for.
363 QuicPacketSequenceNumber least_unacked;
[email protected]8b37a092012-10-18 21:53:49364};
365
[email protected]26f3f8e2012-12-13 21:07:19366struct NET_EXPORT_PRIVATE QuicAckFrame {
367 QuicAckFrame() {}
368 // Testing convenience method to construct a QuicAckFrame with all packets
[email protected]48697d8a2013-01-15 19:42:24369 // from least_unacked to largest_observed acked.
370 QuicAckFrame(QuicPacketSequenceNumber largest_observed,
[email protected]14e8106c2013-03-14 16:25:33371 QuicTime largest_observed_receive_time,
[email protected]26f3f8e2012-12-13 21:07:19372 QuicPacketSequenceNumber least_unacked);
373
374 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
375 std::ostream& os, const QuicAckFrame& s);
376
377 SentPacketInfo sent_info;
378 ReceivedPacketInfo received_info;
379};
380
[email protected]8b37a092012-10-18 21:53:49381// Defines for all types of congestion feedback that will be negotiated in QUIC,
382// kTCP MUST be supported by all QUIC implementations to guarentee 100%
383// compatibility.
384enum CongestionFeedbackType {
[email protected]8b37a092012-10-18 21:53:49385 kTCP, // Used to mimic TCP.
386 kInterArrival, // Use additional inter arrival information.
387 kFixRate, // Provided for testing.
388};
389
390struct NET_EXPORT_PRIVATE CongestionFeedbackMessageTCP {
391 uint16 accumulated_number_of_lost_packets;
[email protected]fee17f72013-02-03 07:47:41392 QuicByteCount receive_window;
[email protected]8b37a092012-10-18 21:53:49393};
394
395struct NET_EXPORT_PRIVATE CongestionFeedbackMessageInterArrival {
[email protected]7884ecad2012-12-14 22:55:15396 CongestionFeedbackMessageInterArrival();
397 ~CongestionFeedbackMessageInterArrival();
[email protected]8b37a092012-10-18 21:53:49398 uint16 accumulated_number_of_lost_packets;
[email protected]7884ecad2012-12-14 22:55:15399 // The set of received packets since the last feedback was sent, along with
400 // their arrival times.
401 TimeMap received_packet_times;
[email protected]8b37a092012-10-18 21:53:49402};
403
[email protected]8b37a092012-10-18 21:53:49404struct NET_EXPORT_PRIVATE CongestionFeedbackMessageFixRate {
[email protected]fee17f72013-02-03 07:47:41405 CongestionFeedbackMessageFixRate();
406 QuicBandwidth bitrate;
[email protected]8b37a092012-10-18 21:53:49407};
408
[email protected]26f3f8e2012-12-13 21:07:19409struct NET_EXPORT_PRIVATE QuicCongestionFeedbackFrame {
[email protected]7884ecad2012-12-14 22:55:15410 QuicCongestionFeedbackFrame();
411 ~QuicCongestionFeedbackFrame();
412
[email protected]26f3f8e2012-12-13 21:07:19413 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
414 std::ostream& os, const QuicCongestionFeedbackFrame& c);
415
[email protected]7884ecad2012-12-14 22:55:15416 CongestionFeedbackType type;
417 // This should really be a union, but since the inter arrival struct
418 // is non-trivial, C++ prohibits it.
419 CongestionFeedbackMessageTCP tcp;
420 CongestionFeedbackMessageInterArrival inter_arrival;
421 CongestionFeedbackMessageFixRate fix_rate;
[email protected]8b37a092012-10-18 21:53:49422};
423
[email protected]be24ab22012-10-22 03:01:52424struct NET_EXPORT_PRIVATE QuicRstStreamFrame {
425 QuicRstStreamFrame() {}
[email protected]74bda142013-03-31 02:49:11426 QuicRstStreamFrame(QuicStreamId stream_id, QuicRstStreamErrorCode error_code)
[email protected]9db443912013-02-25 05:27:03427 : stream_id(stream_id), error_code(error_code) {
[email protected]431bb4fd2012-10-19 17:46:09428 DCHECK_LE(error_code, std::numeric_limits<uint8>::max());
[email protected]8b37a092012-10-18 21:53:49429 }
430
431 QuicStreamId stream_id;
[email protected]74bda142013-03-31 02:49:11432 QuicRstStreamErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09433 std::string error_details;
[email protected]8b37a092012-10-18 21:53:49434};
435
[email protected]be24ab22012-10-22 03:01:52436struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame {
[email protected]431bb4fd2012-10-19 17:46:09437 QuicErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09438 std::string error_details;
[email protected]d3d15bf2013-01-30 02:51:54439 QuicAckFrame ack_frame;
[email protected]8b37a092012-10-18 21:53:49440};
441
[email protected]9db443912013-02-25 05:27:03442struct NET_EXPORT_PRIVATE QuicGoAwayFrame {
443 QuicGoAwayFrame() {}
444 QuicGoAwayFrame(QuicErrorCode error_code,
445 QuicStreamId last_good_stream_id,
446 const std::string& reason);
447
448 QuicErrorCode error_code;
449 QuicStreamId last_good_stream_id;
450 std::string reason_phrase;
451};
452
[email protected]be24ab22012-10-22 03:01:52453struct NET_EXPORT_PRIVATE QuicFrame {
454 QuicFrame() {}
[email protected]c995c572013-01-18 05:43:20455 explicit QuicFrame(QuicPaddingFrame* padding_frame)
456 : type(PADDING_FRAME),
457 padding_frame(padding_frame) {
458 }
[email protected]be24ab22012-10-22 03:01:52459 explicit QuicFrame(QuicStreamFrame* stream_frame)
[email protected]610a7e942012-12-18 00:21:39460 : type(STREAM_FRAME),
461 stream_frame(stream_frame) {
[email protected]8b37a092012-10-18 21:53:49462 }
[email protected]be24ab22012-10-22 03:01:52463 explicit QuicFrame(QuicAckFrame* frame)
[email protected]610a7e942012-12-18 00:21:39464 : type(ACK_FRAME),
465 ack_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49466 }
[email protected]26f3f8e2012-12-13 21:07:19467 explicit QuicFrame(QuicCongestionFeedbackFrame* frame)
[email protected]610a7e942012-12-18 00:21:39468 : type(CONGESTION_FEEDBACK_FRAME),
469 congestion_feedback_frame(frame) {
[email protected]26f3f8e2012-12-13 21:07:19470 }
[email protected]be24ab22012-10-22 03:01:52471 explicit QuicFrame(QuicRstStreamFrame* frame)
472 : type(RST_STREAM_FRAME),
473 rst_stream_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49474 }
[email protected]be24ab22012-10-22 03:01:52475 explicit QuicFrame(QuicConnectionCloseFrame* frame)
476 : type(CONNECTION_CLOSE_FRAME),
477 connection_close_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49478 }
[email protected]9db443912013-02-25 05:27:03479 explicit QuicFrame(QuicGoAwayFrame* frame)
480 : type(GOAWAY_FRAME),
481 goaway_frame(frame) {
482 }
[email protected]8b37a092012-10-18 21:53:49483
[email protected]be24ab22012-10-22 03:01:52484 QuicFrameType type;
[email protected]8b37a092012-10-18 21:53:49485 union {
[email protected]c995c572013-01-18 05:43:20486 QuicPaddingFrame* padding_frame;
[email protected]be24ab22012-10-22 03:01:52487 QuicStreamFrame* stream_frame;
488 QuicAckFrame* ack_frame;
[email protected]26f3f8e2012-12-13 21:07:19489 QuicCongestionFeedbackFrame* congestion_feedback_frame;
[email protected]be24ab22012-10-22 03:01:52490 QuicRstStreamFrame* rst_stream_frame;
491 QuicConnectionCloseFrame* connection_close_frame;
[email protected]9db443912013-02-25 05:27:03492 QuicGoAwayFrame* goaway_frame;
[email protected]8b37a092012-10-18 21:53:49493 };
494};
495
[email protected]be24ab22012-10-22 03:01:52496typedef std::vector<QuicFrame> QuicFrames;
[email protected]8b37a092012-10-18 21:53:49497
498struct NET_EXPORT_PRIVATE QuicFecData {
499 QuicFecData();
[email protected]a5061242012-10-23 23:29:37500
501 bool operator==(const QuicFecData& other) const;
502
[email protected]c995c572013-01-18 05:43:20503 // The FEC group number is also the sequence number of the first
504 // FEC protected packet. The last protected packet's sequence number will
505 // be one less than the sequence number of the FEC packet.
[email protected]8b37a092012-10-18 21:53:49506 QuicFecGroupNumber fec_group;
[email protected]8b37a092012-10-18 21:53:49507 base::StringPiece redundancy;
[email protected]8b37a092012-10-18 21:53:49508};
509
510struct NET_EXPORT_PRIVATE QuicPacketData {
511 std::string data;
512};
513
514class NET_EXPORT_PRIVATE QuicData {
515 public:
516 QuicData(const char* buffer, size_t length)
517 : buffer_(buffer),
518 length_(length),
[email protected]5351cc4b2013-03-03 07:22:41519 owns_buffer_(false) {}
[email protected]8b37a092012-10-18 21:53:49520
521 QuicData(char* buffer, size_t length, bool owns_buffer)
522 : buffer_(buffer),
523 length_(length),
[email protected]5351cc4b2013-03-03 07:22:41524 owns_buffer_(owns_buffer) {}
[email protected]8b37a092012-10-18 21:53:49525
526 virtual ~QuicData();
527
528 base::StringPiece AsStringPiece() const {
529 return base::StringPiece(data(), length());
530 }
531
532 const char* data() const { return buffer_; }
533 size_t length() const { return length_; }
534
535 private:
536 const char* buffer_;
537 size_t length_;
538 bool owns_buffer_;
539
540 DISALLOW_COPY_AND_ASSIGN(QuicData);
541};
542
543class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
544 public:
[email protected]c995c572013-01-18 05:43:20545 static QuicPacket* NewDataPacket(char* buffer,
[email protected]9db443912013-02-25 05:27:03546 size_t length,
[email protected]5351cc4b2013-03-03 07:22:41547 bool owns_buffer,
548 bool includes_version) {
549 return new QuicPacket(buffer, length, owns_buffer, includes_version, false);
[email protected]c995c572013-01-18 05:43:20550 }
551
552 static QuicPacket* NewFecPacket(char* buffer,
553 size_t length,
[email protected]5351cc4b2013-03-03 07:22:41554 bool owns_buffer,
555 bool includes_version) {
556 return new QuicPacket(buffer, length, owns_buffer, includes_version, true);
[email protected]c995c572013-01-18 05:43:20557 }
[email protected]8b37a092012-10-18 21:53:49558
[email protected]5351cc4b2013-03-03 07:22:41559 base::StringPiece FecProtectedData() const;
560 base::StringPiece AssociatedData() const;
561 base::StringPiece BeforePlaintext() const;
562 base::StringPiece Plaintext() const;
[email protected]082b65b2012-11-10 19:11:31563
[email protected]c995c572013-01-18 05:43:20564 bool is_fec_packet() const { return is_fec_packet_; }
[email protected]082b65b2012-11-10 19:11:31565
[email protected]5351cc4b2013-03-03 07:22:41566 bool includes_version() const { return includes_version_; }
567
[email protected]8b37a092012-10-18 21:53:49568 char* mutable_data() { return buffer_; }
569
570 private:
[email protected]5351cc4b2013-03-03 07:22:41571 QuicPacket(char* buffer,
572 size_t length,
573 bool owns_buffer,
574 bool includes_version,
575 bool is_fec_packet)
[email protected]c995c572013-01-18 05:43:20576 : QuicData(buffer, length, owns_buffer),
577 buffer_(buffer),
[email protected]5351cc4b2013-03-03 07:22:41578 is_fec_packet_(is_fec_packet),
579 includes_version_(includes_version) {}
[email protected]c995c572013-01-18 05:43:20580
[email protected]8b37a092012-10-18 21:53:49581 char* buffer_;
[email protected]c995c572013-01-18 05:43:20582 const bool is_fec_packet_;
[email protected]5351cc4b2013-03-03 07:22:41583 const bool includes_version_;
[email protected]8b37a092012-10-18 21:53:49584
[email protected]2e740db2012-10-20 19:35:19585 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
[email protected]8b37a092012-10-18 21:53:49586};
587
588class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
589 public:
590 QuicEncryptedPacket(const char* buffer, size_t length)
[email protected]5351cc4b2013-03-03 07:22:41591 : QuicData(buffer, length) {}
[email protected]8b37a092012-10-18 21:53:49592
593 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer)
[email protected]5351cc4b2013-03-03 07:22:41594 : QuicData(buffer, length, owns_buffer) {}
[email protected]8b37a092012-10-18 21:53:49595
[email protected]c1b32c62013-01-20 02:49:10596 // By default, gtest prints the raw bytes of an object. The bool data
597 // member (in the base class QuicData) causes this object to have padding
598 // bytes, which causes the default gtest object printer to read
599 // uninitialize memory. So we need to teach gtest how to print this object.
600 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
601 std::ostream& os, const QuicEncryptedPacket& s);
602
[email protected]2e740db2012-10-20 19:35:19603 private:
604 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
[email protected]8b37a092012-10-18 21:53:49605};
606
[email protected]9db443912013-02-25 05:27:03607class NET_EXPORT_PRIVATE RetransmittableFrames {
608 public:
609 RetransmittableFrames();
610 ~RetransmittableFrames();
611
612 // Allocates a local copy of the referenced StringPiece has QuicStreamFrame
613 // use it.
614 // Takes ownership of |stream_frame|.
615 const QuicFrame& AddStreamFrame(QuicStreamFrame* stream_frame);
616 // Takes ownership of the frame inside |frame|.
617 const QuicFrame& AddNonStreamFrame(const QuicFrame& frame);
618 const QuicFrames& frames() const { return frames_; }
619
620 private:
621 QuicFrames frames_;
622 // Data referenced by the StringPiece of a QuicStreamFrame.
623 std::vector<std::string*> stream_data_;
624
625 DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames);
626};
627
628struct NET_EXPORT_PRIVATE SerializedPacket {
629 SerializedPacket(QuicPacketSequenceNumber sequence_number,
630 QuicPacket* packet,
631 QuicPacketEntropyHash entropy_hash,
632 RetransmittableFrames* retransmittable_frames)
633 : sequence_number(sequence_number),
634 packet(packet),
635 entropy_hash(entropy_hash),
[email protected]5351cc4b2013-03-03 07:22:41636 retransmittable_frames(retransmittable_frames) {}
[email protected]9db443912013-02-25 05:27:03637
638 QuicPacketSequenceNumber sequence_number;
639 QuicPacket* packet;
640 QuicPacketEntropyHash entropy_hash;
641 RetransmittableFrames* retransmittable_frames;
642};
643
[email protected]c995c572013-01-18 05:43:20644// A struct for functions which consume data payloads and fins.
645// The first member of the pair indicates bytes consumed.
646// The second member of the pair indicates if an incoming fin was consumed.
647struct QuicConsumedData {
648 QuicConsumedData(size_t bytes_consumed, bool fin_consumed)
649 : bytes_consumed(bytes_consumed),
[email protected]5351cc4b2013-03-03 07:22:41650 fin_consumed(fin_consumed) {}
[email protected]c1b32c62013-01-20 02:49:10651
652 // By default, gtest prints the raw bytes of an object. The bool data
653 // member causes this object to have padding bytes, which causes the
654 // default gtest object printer to read uninitialize memory. So we need
655 // to teach gtest how to print this object.
656 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
657 std::ostream& os, const QuicConsumedData& s);
658
[email protected]c995c572013-01-18 05:43:20659 size_t bytes_consumed;
660 bool fin_consumed;
661};
662
[email protected]8b37a092012-10-18 21:53:49663} // namespace net
664
665#endif // NET_QUIC_QUIC_PROTOCOL_H_