blob: 9d641ee77011421c2188f230ee253a9aa3a351d5 [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]2a960e02012-11-11 14:48:1023#include "net/quic/quic_time.h"
[email protected]8b37a092012-10-18 21:53:4924
25namespace net {
26
[email protected]f1e97e92012-12-16 04:53:2527using ::operator<<;
28
[email protected]8b37a092012-10-18 21:53:4929class QuicPacket;
30
31typedef uint64 QuicGuid;
32typedef uint32 QuicStreamId;
33typedef uint64 QuicStreamOffset;
34typedef uint64 QuicPacketSequenceNumber;
[email protected]c995c572013-01-18 05:43:2035typedef QuicPacketSequenceNumber QuicFecGroupNumber;
[email protected]86a318d2013-01-23 21:16:0436typedef uint64 QuicPublicResetNonceProof;
[email protected]cff7b7b2013-01-11 08:49:0737
[email protected]8b37a092012-10-18 21:53:4938// TODO(rch): Consider Quic specific names for these constants.
39const size_t kMaxPacketSize = 1200; // Maximum size in bytes of a QUIC packet.
40
41// Maximum number of open streams per connection.
42const size_t kDefaultMaxStreamsPerConnection = 100;
43
[email protected]c995c572013-01-18 05:43:2044// Number of bytes reserved for guid in the packet header.
45const size_t kQuicGuidSize = 8;
46// Number of bytes reserved for public flags in the packet header.
47const size_t kPublicFlagsSize = 1;
48// Number of bytes reserved for sequence number in the packet header.
49const size_t kSequenceNumberSize = 6;
50// Number of bytes reserved for private flags in the packet header.
51const size_t kPrivateFlagsSize = 1;
52// Number of bytes reserved for FEC group in the packet header.
53const size_t kFecGroupSize = 1;
[email protected]86a318d2013-01-23 21:16:0454// Number of bytes reserved for the nonce proof in public reset packet.
55const size_t kPublicResetNonceSize = 8;
[email protected]c995c572013-01-18 05:43:2056
57// Size in bytes of the data or fec packet header.
58const size_t kPacketHeaderSize = kQuicGuidSize + kPublicFlagsSize +
59 kPrivateFlagsSize + kSequenceNumberSize + kFecGroupSize;
[email protected]86a318d2013-01-23 21:16:0460// Size in bytes of the public reset packet.
61const size_t kPublicResetPacketSize = kQuicGuidSize + kPublicFlagsSize +
62 kPublicResetNonceSize + kSequenceNumberSize;
[email protected]c995c572013-01-18 05:43:2063
64// Index into the guid offset in the header.
65const size_t kGuidOffset = 0;
66// Index into the flags offset in the header.
67const size_t kPublicFlagsOffset = kQuicGuidSize;
68
69// Index into the sequence number offset in the header.
70const size_t kSequenceNumberOffset = kPublicFlagsOffset + kPublicFlagsSize;
71// Index into the private flags offset in the data packet header.
72const size_t kPrivateFlagsOffset = kSequenceNumberOffset + kSequenceNumberSize;
73// Index into the fec group offset in the header.
74const size_t kFecGroupOffset = kPrivateFlagsOffset + kPrivateFlagsSize;
75
[email protected]86a318d2013-01-23 21:16:0476// Index into the nonce proof of the public reset packet.
77const size_t kPublicResetPacketNonceProofOffset = kPublicFlagsOffset +
78 kPublicFlagsSize;
79// Index into the rejected sequence number of the public reset packet.
80const size_t kPublicResetPacketRejectedSequenceNumberOffset =
81 kPublicResetPacketNonceProofOffset + kPublicResetNonceSize;
82
[email protected]8b37a092012-10-18 21:53:4983// Index of the first byte in a QUIC packet of FEC protected data.
84const size_t kStartOfFecProtectedData = kPacketHeaderSize;
85// Index of the first byte in a QUIC packet of encrypted data.
[email protected]c995c572013-01-18 05:43:2086const size_t kStartOfEncryptedData = kPacketHeaderSize - kPrivateFlagsSize -
87 kFecGroupSize;
[email protected]8b37a092012-10-18 21:53:4988// Index of the first byte in a QUIC packet which is hashed.
89const size_t kStartOfHashData = 0;
[email protected]8b37a092012-10-18 21:53:4990
[email protected]be24ab22012-10-22 03:01:5291// Size in bytes of all stream frame fields.
92const size_t kMinStreamFrameLength = 15;
[email protected]8b37a092012-10-18 21:53:4993
94// Limit on the delta between stream IDs.
95const QuicStreamId kMaxStreamIdDelta = 100;
96
97// Reserved ID for the crypto stream.
98// TODO(rch): ensure that this is not usable by any other streams.
99const QuicStreamId kCryptoStreamId = 1;
100
[email protected]c995c572013-01-18 05:43:20101// Value which indicates this packet is not FEC protected.
102const uint8 kNoFecOffset = 0xFF;
103
[email protected]8b37a092012-10-18 21:53:49104typedef std::pair<QuicPacketSequenceNumber, QuicPacket*> PacketPair;
105
[email protected]2a960e02012-11-11 14:48:10106const int64 kDefaultTimeoutUs = 600000000; // 10 minutes.
[email protected]8b37a092012-10-18 21:53:49107
[email protected]be24ab22012-10-22 03:01:52108enum QuicFrameType {
[email protected]c995c572013-01-18 05:43:20109 PADDING_FRAME = 0,
110 STREAM_FRAME,
[email protected]be24ab22012-10-22 03:01:52111 ACK_FRAME,
[email protected]26f3f8e2012-12-13 21:07:19112 CONGESTION_FEEDBACK_FRAME,
[email protected]be24ab22012-10-22 03:01:52113 RST_STREAM_FRAME,
114 CONNECTION_CLOSE_FRAME,
115 NUM_FRAME_TYPES
[email protected]8b37a092012-10-18 21:53:49116};
117
[email protected]c995c572013-01-18 05:43:20118enum QuicPacketPublicFlags {
119 PACKET_PUBLIC_FLAGS_NONE = 0,
120 PACKET_PUBLIC_FLAGS_VERSION = 1,
121 PACKET_PUBLIC_FLAGS_RST = 2, // Packet is a public reset packet.
122 PACKET_PUBLIC_FLAGS_MAX = 3 // Both bit set.
123};
[email protected]8b37a092012-10-18 21:53:49124
[email protected]c995c572013-01-18 05:43:20125enum QuicPacketPrivateFlags {
126 PACKET_PRIVATE_FLAGS_NONE = 0,
127 PACKET_PRIVATE_FLAGS_FEC = 1, // Payload is FEC as opposed to frames.
128 PACKET_PRIVATE_FLAGS_MAX = PACKET_PRIVATE_FLAGS_FEC
129};
130
131enum QuicVersion {
132 QUIC_VERSION_1 = 0
[email protected]8b37a092012-10-18 21:53:49133};
134
135enum QuicErrorCode {
136 // Stream errors.
137 QUIC_NO_ERROR = 0,
138
[email protected]be24ab22012-10-22 03:01:52139 // There were data frames after the a fin or reset.
[email protected]8b37a092012-10-18 21:53:49140 QUIC_STREAM_DATA_AFTER_TERMINATION,
141 // There was some server error which halted stream processing.
142 QUIC_SERVER_ERROR_PROCESSING_STREAM,
143 // We got two fin or reset offsets which did not match.
144 QUIC_MULTIPLE_TERMINATION_OFFSETS,
145 // We got bad payload and can not respond to it at the protocol level.
146 QUIC_BAD_APPLICATION_PAYLOAD,
147
148 // Connection errors.
149
150 // Control frame is malformed.
151 QUIC_INVALID_PACKET_HEADER,
[email protected]be24ab22012-10-22 03:01:52152 // Frame data is malformed.
153 QUIC_INVALID_FRAME_DATA,
[email protected]8b37a092012-10-18 21:53:49154 // FEC data is malformed.
155 QUIC_INVALID_FEC_DATA,
156 // Stream rst data is malformed
157 QUIC_INVALID_RST_STREAM_DATA,
158 // Connection close data is malformed.
159 QUIC_INVALID_CONNECTION_CLOSE_DATA,
160 // Ack data is malformed.
161 QUIC_INVALID_ACK_DATA,
162 // There was an error decrypting.
163 QUIC_DECRYPTION_FAILURE,
164 // There was an error encrypting.
165 QUIC_ENCRYPTION_FAILURE,
166 // The packet exceeded kMaxPacketSize.
167 QUIC_PACKET_TOO_LARGE,
168 // Data was sent for a stream which did not exist.
169 QUIC_PACKET_FOR_NONEXISTENT_STREAM,
170 // The client is going away (browser close, etc.)
171 QUIC_CLIENT_GOING_AWAY,
172 // The server is going away (restart etc.)
173 QUIC_SERVER_GOING_AWAY,
174 // A stream ID was invalid.
175 QUIC_INVALID_STREAM_ID,
176 // Too many streams already open.
177 QUIC_TOO_MANY_OPEN_STREAMS,
[email protected]86a318d2013-01-23 21:16:04178 // Received public reset for this connection.
179 QUIC_PUBLIC_RESET,
[email protected]8b37a092012-10-18 21:53:49180
181 // We hit our prenegotiated (or default) timeout
182 QUIC_CONNECTION_TIMED_OUT,
183
184 // Crypto errors.
185
186 // Handshake message contained out of order tags.
187 QUIC_CRYPTO_TAGS_OUT_OF_ORDER,
[email protected]701bc892013-01-17 04:51:54188 // Handshake message contained too many entries.
[email protected]8b37a092012-10-18 21:53:49189 QUIC_CRYPTO_TOO_MANY_ENTRIES,
190 // Handshake message contained an invalid value length.
191 QUIC_CRYPTO_INVALID_VALUE_LENGTH,
192 // A crypto message was received after the handshake was complete.
193 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE,
[email protected]d3d15bf2013-01-30 02:51:54194 // A crypto message was received with an illegal message tag.
[email protected]8b37a092012-10-18 21:53:49195 QUIC_INVALID_CRYPTO_MESSAGE_TYPE,
[email protected]d3d15bf2013-01-30 02:51:54196 // A crypto message was received with an illegal parameter.
197 QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER,
198 // A crypto message was received with a mandatory parameter missing.
199 QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND,
200 // A crypto message was received with a parameter that has no overlap
201 // with the local parameter.
202 QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP,
[email protected]8b37a092012-10-18 21:53:49203};
204
[email protected]c995c572013-01-18 05:43:20205struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
206 // Universal header. All QuicPacket headers will have a guid and public flags.
207 // TODO(satyamshekhar): Support versioning as per Protocol Negotiation Doc.
[email protected]8b37a092012-10-18 21:53:49208 QuicGuid guid;
[email protected]c995c572013-01-18 05:43:20209 QuicPacketPublicFlags flags;
210};
211
212// Header for Data or FEC packets.
213struct QuicPacketHeader {
214 QuicPacketHeader() {}
215 explicit QuicPacketHeader(const QuicPacketPublicHeader& header)
216 : public_header(header) {}
217 QuicPacketPublicHeader public_header;
218 QuicPacketPrivateFlags private_flags;
[email protected]8b37a092012-10-18 21:53:49219 QuicPacketSequenceNumber packet_sequence_number;
[email protected]8b37a092012-10-18 21:53:49220 QuicFecGroupNumber fec_group;
221};
222
[email protected]86a318d2013-01-23 21:16:04223struct QuicPublicResetPacket {
224 QuicPublicResetPacket() {}
225 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header)
226 : public_header(header) {}
227 QuicPacketPublicHeader public_header;
228 QuicPacketSequenceNumber rejected_sequence_number;
229 QuicPublicResetNonceProof nonce_proof;
230};
231
[email protected]c995c572013-01-18 05:43:20232// A padding frame contains no payload.
233struct NET_EXPORT_PRIVATE QuicPaddingFrame {
234};
235
[email protected]be24ab22012-10-22 03:01:52236struct NET_EXPORT_PRIVATE QuicStreamFrame {
237 QuicStreamFrame();
238 QuicStreamFrame(QuicStreamId stream_id,
[email protected]a5061242012-10-23 23:29:37239 bool fin,
[email protected]701bc892013-01-17 04:51:54240 QuicStreamOffset offset,
[email protected]a5061242012-10-23 23:29:37241 base::StringPiece data);
[email protected]8b37a092012-10-18 21:53:49242
243 QuicStreamId stream_id;
244 bool fin;
[email protected]701bc892013-01-17 04:51:54245 QuicStreamOffset offset; // Location of this data in the stream.
[email protected]8b37a092012-10-18 21:53:49246 base::StringPiece data;
247};
248
[email protected]e537f742012-12-07 15:33:53249// TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
250// is finalized.
251typedef std::set<QuicPacketSequenceNumber> SequenceSet;
[email protected]3c5f4a732013-01-12 16:45:34252// TODO(pwestin): Add a way to enforce the max size of this map.
[email protected]e537f742012-12-07 15:33:53253typedef std::map<QuicPacketSequenceNumber, QuicTime> TimeMap;
[email protected]044ac2b2012-11-13 21:41:06254
[email protected]8b37a092012-10-18 21:53:49255struct NET_EXPORT_PRIVATE ReceivedPacketInfo {
256 ReceivedPacketInfo();
257 ~ReceivedPacketInfo();
[email protected]26f3f8e2012-12-13 21:07:19258 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
259 std::ostream& os, const ReceivedPacketInfo& s);
[email protected]a674b4c2012-12-05 03:44:30260
[email protected]e537f742012-12-07 15:33:53261 // Records a packet receipt.
[email protected]7884ecad2012-12-14 22:55:15262 void RecordReceived(QuicPacketSequenceNumber sequence_number);
[email protected]e537f742012-12-07 15:33:53263
[email protected]48697d8a2013-01-15 19:42:24264 // True if the sequence number is greater than largest_observed or is listed
[email protected]e537f742012-12-07 15:33:53265 // as missing.
266 // Always returns false for sequence numbers less than least_unacked.
267 bool IsAwaitingPacket(QuicPacketSequenceNumber sequence_number) const;
268
[email protected]7884ecad2012-12-14 22:55:15269 // Clears all missing packets less than |least_unacked|.
270 void ClearMissingBefore(QuicPacketSequenceNumber least_unacked);
[email protected]e537f742012-12-07 15:33:53271
[email protected]48697d8a2013-01-15 19:42:24272 // The highest packet sequence number we've observed from the peer.
273 //
274 // In general, this should be the largest packet number we've received. In
275 // the case of truncated acks, we may have to advertise a lower "upper bound"
276 // than largest received, to avoid implicitly acking missing packets that
277 // don't fit in the missing packet list due to size limitations. In this
278 // case, largest_observed may be a packet which is also in the missing packets
279 // list.
280 QuicPacketSequenceNumber largest_observed;
[email protected]a674b4c2012-12-05 03:44:30281
[email protected]e537f742012-12-07 15:33:53282 // The set of packets which we're expecting and have not received.
283 SequenceSet missing_packets;
[email protected]8b37a092012-10-18 21:53:49284};
285
286struct NET_EXPORT_PRIVATE SentPacketInfo {
287 SentPacketInfo();
288 ~SentPacketInfo();
[email protected]26f3f8e2012-12-13 21:07:19289 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
290 std::ostream& os, const SentPacketInfo& s);
291
[email protected]8b37a092012-10-18 21:53:49292 // The lowest packet we've sent which is unacked, and we expect an ack for.
293 QuicPacketSequenceNumber least_unacked;
[email protected]8b37a092012-10-18 21:53:49294};
295
[email protected]26f3f8e2012-12-13 21:07:19296struct NET_EXPORT_PRIVATE QuicAckFrame {
297 QuicAckFrame() {}
298 // Testing convenience method to construct a QuicAckFrame with all packets
[email protected]48697d8a2013-01-15 19:42:24299 // from least_unacked to largest_observed acked.
300 QuicAckFrame(QuicPacketSequenceNumber largest_observed,
[email protected]26f3f8e2012-12-13 21:07:19301 QuicPacketSequenceNumber least_unacked);
302
303 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
304 std::ostream& os, const QuicAckFrame& s);
305
306 SentPacketInfo sent_info;
307 ReceivedPacketInfo received_info;
308};
309
[email protected]8b37a092012-10-18 21:53:49310// Defines for all types of congestion feedback that will be negotiated in QUIC,
311// kTCP MUST be supported by all QUIC implementations to guarentee 100%
312// compatibility.
313enum CongestionFeedbackType {
[email protected]8b37a092012-10-18 21:53:49314 kTCP, // Used to mimic TCP.
315 kInterArrival, // Use additional inter arrival information.
316 kFixRate, // Provided for testing.
317};
318
319struct NET_EXPORT_PRIVATE CongestionFeedbackMessageTCP {
320 uint16 accumulated_number_of_lost_packets;
321 uint16 receive_window; // Number of bytes >> 4.
322};
323
324struct NET_EXPORT_PRIVATE CongestionFeedbackMessageInterArrival {
[email protected]7884ecad2012-12-14 22:55:15325 CongestionFeedbackMessageInterArrival();
326 ~CongestionFeedbackMessageInterArrival();
[email protected]8b37a092012-10-18 21:53:49327 uint16 accumulated_number_of_lost_packets;
[email protected]7884ecad2012-12-14 22:55:15328 // The set of received packets since the last feedback was sent, along with
329 // their arrival times.
330 TimeMap received_packet_times;
[email protected]8b37a092012-10-18 21:53:49331};
332
[email protected]8b37a092012-10-18 21:53:49333struct NET_EXPORT_PRIVATE CongestionFeedbackMessageFixRate {
334 uint32 bitrate_in_bytes_per_second;
335};
336
[email protected]26f3f8e2012-12-13 21:07:19337struct NET_EXPORT_PRIVATE QuicCongestionFeedbackFrame {
[email protected]7884ecad2012-12-14 22:55:15338 QuicCongestionFeedbackFrame();
339 ~QuicCongestionFeedbackFrame();
340
[email protected]26f3f8e2012-12-13 21:07:19341 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
342 std::ostream& os, const QuicCongestionFeedbackFrame& c);
343
[email protected]7884ecad2012-12-14 22:55:15344 CongestionFeedbackType type;
345 // This should really be a union, but since the inter arrival struct
346 // is non-trivial, C++ prohibits it.
347 CongestionFeedbackMessageTCP tcp;
348 CongestionFeedbackMessageInterArrival inter_arrival;
349 CongestionFeedbackMessageFixRate fix_rate;
[email protected]8b37a092012-10-18 21:53:49350};
351
[email protected]be24ab22012-10-22 03:01:52352struct NET_EXPORT_PRIVATE QuicRstStreamFrame {
353 QuicRstStreamFrame() {}
354 QuicRstStreamFrame(QuicStreamId stream_id, uint64 offset,
[email protected]f702d572012-12-04 15:56:20355 QuicErrorCode error_code)
[email protected]431bb4fd2012-10-19 17:46:09356 : stream_id(stream_id), offset(offset), error_code(error_code) {
357 DCHECK_LE(error_code, std::numeric_limits<uint8>::max());
[email protected]8b37a092012-10-18 21:53:49358 }
359
360 QuicStreamId stream_id;
361 uint64 offset;
[email protected]431bb4fd2012-10-19 17:46:09362 QuicErrorCode error_code;
363 std::string error_details;
[email protected]8b37a092012-10-18 21:53:49364};
365
[email protected]be24ab22012-10-22 03:01:52366struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame {
[email protected]431bb4fd2012-10-19 17:46:09367 QuicErrorCode error_code;
[email protected]431bb4fd2012-10-19 17:46:09368 std::string error_details;
[email protected]d3d15bf2013-01-30 02:51:54369 QuicAckFrame ack_frame;
[email protected]8b37a092012-10-18 21:53:49370};
371
[email protected]be24ab22012-10-22 03:01:52372struct NET_EXPORT_PRIVATE QuicFrame {
373 QuicFrame() {}
[email protected]c995c572013-01-18 05:43:20374 explicit QuicFrame(QuicPaddingFrame* padding_frame)
375 : type(PADDING_FRAME),
376 padding_frame(padding_frame) {
377 }
[email protected]be24ab22012-10-22 03:01:52378 explicit QuicFrame(QuicStreamFrame* stream_frame)
[email protected]610a7e942012-12-18 00:21:39379 : type(STREAM_FRAME),
380 stream_frame(stream_frame) {
[email protected]8b37a092012-10-18 21:53:49381 }
[email protected]be24ab22012-10-22 03:01:52382 explicit QuicFrame(QuicAckFrame* frame)
[email protected]610a7e942012-12-18 00:21:39383 : type(ACK_FRAME),
384 ack_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49385 }
[email protected]26f3f8e2012-12-13 21:07:19386 explicit QuicFrame(QuicCongestionFeedbackFrame* frame)
[email protected]610a7e942012-12-18 00:21:39387 : type(CONGESTION_FEEDBACK_FRAME),
388 congestion_feedback_frame(frame) {
[email protected]26f3f8e2012-12-13 21:07:19389 }
[email protected]be24ab22012-10-22 03:01:52390 explicit QuicFrame(QuicRstStreamFrame* frame)
391 : type(RST_STREAM_FRAME),
392 rst_stream_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49393 }
[email protected]be24ab22012-10-22 03:01:52394 explicit QuicFrame(QuicConnectionCloseFrame* frame)
395 : type(CONNECTION_CLOSE_FRAME),
396 connection_close_frame(frame) {
[email protected]8b37a092012-10-18 21:53:49397 }
398
[email protected]be24ab22012-10-22 03:01:52399 QuicFrameType type;
[email protected]8b37a092012-10-18 21:53:49400 union {
[email protected]c995c572013-01-18 05:43:20401 QuicPaddingFrame* padding_frame;
[email protected]be24ab22012-10-22 03:01:52402 QuicStreamFrame* stream_frame;
403 QuicAckFrame* ack_frame;
[email protected]26f3f8e2012-12-13 21:07:19404 QuicCongestionFeedbackFrame* congestion_feedback_frame;
[email protected]be24ab22012-10-22 03:01:52405 QuicRstStreamFrame* rst_stream_frame;
406 QuicConnectionCloseFrame* connection_close_frame;
[email protected]8b37a092012-10-18 21:53:49407 };
408};
409
[email protected]be24ab22012-10-22 03:01:52410typedef std::vector<QuicFrame> QuicFrames;
[email protected]8b37a092012-10-18 21:53:49411
412struct NET_EXPORT_PRIVATE QuicFecData {
413 QuicFecData();
[email protected]a5061242012-10-23 23:29:37414
415 bool operator==(const QuicFecData& other) const;
416
[email protected]c995c572013-01-18 05:43:20417 // The FEC group number is also the sequence number of the first
418 // FEC protected packet. The last protected packet's sequence number will
419 // be one less than the sequence number of the FEC packet.
[email protected]8b37a092012-10-18 21:53:49420 QuicFecGroupNumber fec_group;
[email protected]a5061242012-10-23 23:29:37421 QuicPacketSequenceNumber min_protected_packet_sequence_number;
[email protected]8b37a092012-10-18 21:53:49422 // The last protected packet's sequence number will be one
423 // less than the sequence number of the FEC packet.
424 base::StringPiece redundancy;
[email protected]8b37a092012-10-18 21:53:49425};
426
427struct NET_EXPORT_PRIVATE QuicPacketData {
428 std::string data;
429};
430
431class NET_EXPORT_PRIVATE QuicData {
432 public:
433 QuicData(const char* buffer, size_t length)
434 : buffer_(buffer),
435 length_(length),
436 owns_buffer_(false) { }
437
438 QuicData(char* buffer, size_t length, bool owns_buffer)
439 : buffer_(buffer),
440 length_(length),
441 owns_buffer_(owns_buffer) { }
442
443 virtual ~QuicData();
444
445 base::StringPiece AsStringPiece() const {
446 return base::StringPiece(data(), length());
447 }
448
449 const char* data() const { return buffer_; }
450 size_t length() const { return length_; }
451
452 private:
453 const char* buffer_;
454 size_t length_;
455 bool owns_buffer_;
456
457 DISALLOW_COPY_AND_ASSIGN(QuicData);
458};
459
460class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
461 public:
[email protected]c995c572013-01-18 05:43:20462 static QuicPacket* NewDataPacket(char* buffer,
463 size_t length,
464 bool owns_buffer) {
465 return new QuicPacket(buffer, length, owns_buffer, false);
466 }
467
468 static QuicPacket* NewFecPacket(char* buffer,
469 size_t length,
470 bool owns_buffer) {
471 return new QuicPacket(buffer, length, owns_buffer, true);
472 }
[email protected]8b37a092012-10-18 21:53:49473
474 base::StringPiece FecProtectedData() const {
475 return base::StringPiece(data() + kStartOfFecProtectedData,
476 length() - kStartOfFecProtectedData);
477 }
478
479 base::StringPiece AssociatedData() const {
480 return base::StringPiece(data() + kStartOfHashData, kStartOfEncryptedData);
481 }
482
483 base::StringPiece Plaintext() const {
484 return base::StringPiece(data() + kStartOfEncryptedData,
485 length() - kStartOfEncryptedData);
486 }
[email protected]082b65b2012-11-10 19:11:31487
[email protected]c995c572013-01-18 05:43:20488 bool is_fec_packet() const { return is_fec_packet_; }
[email protected]082b65b2012-11-10 19:11:31489
[email protected]8b37a092012-10-18 21:53:49490 char* mutable_data() { return buffer_; }
491
492 private:
[email protected]c995c572013-01-18 05:43:20493 QuicPacket(char* buffer, size_t length, bool owns_buffer, bool is_fec_packet)
494 : QuicData(buffer, length, owns_buffer),
495 buffer_(buffer),
496 is_fec_packet_(is_fec_packet) { }
497
[email protected]8b37a092012-10-18 21:53:49498 char* buffer_;
[email protected]c995c572013-01-18 05:43:20499 const bool is_fec_packet_;
[email protected]8b37a092012-10-18 21:53:49500
[email protected]2e740db2012-10-20 19:35:19501 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
[email protected]8b37a092012-10-18 21:53:49502};
503
504class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
505 public:
506 QuicEncryptedPacket(const char* buffer, size_t length)
507 : QuicData(buffer, length) { }
508
509 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer)
510 : QuicData(buffer, length, owns_buffer) { }
511
[email protected]c1b32c62013-01-20 02:49:10512 // By default, gtest prints the raw bytes of an object. The bool data
513 // member (in the base class QuicData) causes this object to have padding
514 // bytes, which causes the default gtest object printer to read
515 // uninitialize memory. So we need to teach gtest how to print this object.
516 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
517 std::ostream& os, const QuicEncryptedPacket& s);
518
[email protected]8b37a092012-10-18 21:53:49519 base::StringPiece AssociatedData() const {
520 return base::StringPiece(data() + kStartOfHashData, kStartOfEncryptedData);
521 }
522
[email protected]2e740db2012-10-20 19:35:19523 private:
524 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
[email protected]8b37a092012-10-18 21:53:49525};
526
[email protected]c995c572013-01-18 05:43:20527// A struct for functions which consume data payloads and fins.
528// The first member of the pair indicates bytes consumed.
529// The second member of the pair indicates if an incoming fin was consumed.
530struct QuicConsumedData {
531 QuicConsumedData(size_t bytes_consumed, bool fin_consumed)
532 : bytes_consumed(bytes_consumed),
533 fin_consumed(fin_consumed) {
534 }
[email protected]c1b32c62013-01-20 02:49:10535
536 // By default, gtest prints the raw bytes of an object. The bool data
537 // member causes this object to have padding bytes, which causes the
538 // default gtest object printer to read uninitialize memory. So we need
539 // to teach gtest how to print this object.
540 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
541 std::ostream& os, const QuicConsumedData& s);
542
[email protected]c995c572013-01-18 05:43:20543 size_t bytes_consumed;
544 bool fin_consumed;
545};
546
[email protected]8b37a092012-10-18 21:53:49547} // namespace net
548
549#endif // NET_QUIC_QUIC_PROTOCOL_H_