[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1 | // 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] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 8 | #include <stddef.h> |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 9 | #include <limits> |
[email protected] | a674b4c | 2012-12-05 03:44:30 | [diff] [blame] | 10 | #include <map> |
[email protected] | 5640d0a | 2012-10-22 18:17:02 | [diff] [blame] | 11 | #include <ostream> |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 12 | #include <set> |
| 13 | #include <string> |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 14 | #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] | 165e075 | 2012-11-16 07:49:44 | [diff] [blame] | 21 | #include "net/base/int128.h" |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 22 | #include "net/base/net_export.h" |
[email protected] | 2a960e0 | 2012-11-11 14:48:10 | [diff] [blame] | 23 | #include "net/quic/quic_time.h" |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 24 | |
| 25 | namespace net { |
| 26 | |
[email protected] | f1e97e9 | 2012-12-16 04:53:25 | [diff] [blame] | 27 | using ::operator<<; |
| 28 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 29 | class QuicPacket; |
| 30 | |
| 31 | typedef uint64 QuicGuid; |
| 32 | typedef uint32 QuicStreamId; |
| 33 | typedef uint64 QuicStreamOffset; |
| 34 | typedef uint64 QuicPacketSequenceNumber; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 35 | typedef uint8 QuicFecGroupNumber; |
| 36 | |
[email protected] | cff7b7b | 2013-01-11 08:49:07 | [diff] [blame] | 37 | // A struct for functions which consume data payloads and fins. |
| 38 | // The first member of the pair indicates bytes consumed. |
| 39 | // The second member of the pair indicates if an incoming fin was consumed. |
| 40 | struct QuicConsumedData { |
| 41 | QuicConsumedData(size_t bytes_consumed, bool fin_consumed) |
| 42 | : bytes_consumed(bytes_consumed), |
| 43 | fin_consumed(fin_consumed) { |
| 44 | } |
| 45 | size_t bytes_consumed; |
| 46 | bool fin_consumed; |
| 47 | }; |
| 48 | |
| 49 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 50 | // TODO(rch): Consider Quic specific names for these constants. |
| 51 | const size_t kMaxPacketSize = 1200; // Maximum size in bytes of a QUIC packet. |
| 52 | |
| 53 | // Maximum number of open streams per connection. |
| 54 | const size_t kDefaultMaxStreamsPerConnection = 100; |
| 55 | |
| 56 | // Size in bytes of the packet header common across all packets. |
[email protected] | 05e845d | 2012-11-11 16:39:24 | [diff] [blame] | 57 | const size_t kPacketHeaderSize = 16; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 58 | // Index of the first byte in a QUIC packet of FEC protected data. |
| 59 | const size_t kStartOfFecProtectedData = kPacketHeaderSize; |
| 60 | // Index of the first byte in a QUIC packet of encrypted data. |
| 61 | const size_t kStartOfEncryptedData = kPacketHeaderSize - 1; |
| 62 | // Index of the first byte in a QUIC packet which is hashed. |
| 63 | const size_t kStartOfHashData = 0; |
[email protected] | 082b65b | 2012-11-10 19:11:31 | [diff] [blame] | 64 | // Index into the sequence number offset in the header. |
| 65 | const int kSequenceNumberOffset = 8; |
[email protected] | 082b65b | 2012-11-10 19:11:31 | [diff] [blame] | 66 | // Index into the flags offset in the header. |
[email protected] | 05e845d | 2012-11-11 16:39:24 | [diff] [blame] | 67 | const int kFlagsOffset = 14; |
[email protected] | 082b65b | 2012-11-10 19:11:31 | [diff] [blame] | 68 | // Index into the fec group offset in the header. |
[email protected] | 05e845d | 2012-11-11 16:39:24 | [diff] [blame] | 69 | const int kFecGroupOffset = 15; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 70 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 71 | // Size in bytes of all stream frame fields. |
| 72 | const size_t kMinStreamFrameLength = 15; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 73 | |
| 74 | // Limit on the delta between stream IDs. |
| 75 | const QuicStreamId kMaxStreamIdDelta = 100; |
| 76 | |
| 77 | // Reserved ID for the crypto stream. |
| 78 | // TODO(rch): ensure that this is not usable by any other streams. |
| 79 | const QuicStreamId kCryptoStreamId = 1; |
| 80 | |
| 81 | typedef std::pair<QuicPacketSequenceNumber, QuicPacket*> PacketPair; |
| 82 | |
[email protected] | 2a960e0 | 2012-11-11 14:48:10 | [diff] [blame] | 83 | const int64 kDefaultTimeoutUs = 600000000; // 10 minutes. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 84 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 85 | enum QuicFrameType { |
| 86 | STREAM_FRAME = 0, |
| 87 | PDU_FRAME, |
| 88 | ACK_FRAME, |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 89 | CONGESTION_FEEDBACK_FRAME, |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 90 | RST_STREAM_FRAME, |
| 91 | CONNECTION_CLOSE_FRAME, |
| 92 | NUM_FRAME_TYPES |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | enum QuicPacketFlags { |
| 96 | PACKET_FLAGS_NONE = 0, |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 97 | PACKET_FLAGS_FEC = 1, // Payload is FEC as opposed to frames. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 98 | |
| 99 | PACKET_FLAGS_MAX = PACKET_FLAGS_FEC |
| 100 | }; |
| 101 | |
| 102 | enum QuicErrorCode { |
| 103 | // Stream errors. |
| 104 | QUIC_NO_ERROR = 0, |
| 105 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 106 | // There were data frames after the a fin or reset. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 107 | QUIC_STREAM_DATA_AFTER_TERMINATION, |
| 108 | // There was some server error which halted stream processing. |
| 109 | QUIC_SERVER_ERROR_PROCESSING_STREAM, |
| 110 | // We got two fin or reset offsets which did not match. |
| 111 | QUIC_MULTIPLE_TERMINATION_OFFSETS, |
| 112 | // We got bad payload and can not respond to it at the protocol level. |
| 113 | QUIC_BAD_APPLICATION_PAYLOAD, |
| 114 | |
| 115 | // Connection errors. |
| 116 | |
| 117 | // Control frame is malformed. |
| 118 | QUIC_INVALID_PACKET_HEADER, |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 119 | // Frame data is malformed. |
| 120 | QUIC_INVALID_FRAME_DATA, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 121 | // FEC data is malformed. |
| 122 | QUIC_INVALID_FEC_DATA, |
| 123 | // Stream rst data is malformed |
| 124 | QUIC_INVALID_RST_STREAM_DATA, |
| 125 | // Connection close data is malformed. |
| 126 | QUIC_INVALID_CONNECTION_CLOSE_DATA, |
| 127 | // Ack data is malformed. |
| 128 | QUIC_INVALID_ACK_DATA, |
| 129 | // There was an error decrypting. |
| 130 | QUIC_DECRYPTION_FAILURE, |
| 131 | // There was an error encrypting. |
| 132 | QUIC_ENCRYPTION_FAILURE, |
| 133 | // The packet exceeded kMaxPacketSize. |
| 134 | QUIC_PACKET_TOO_LARGE, |
| 135 | // Data was sent for a stream which did not exist. |
| 136 | QUIC_PACKET_FOR_NONEXISTENT_STREAM, |
| 137 | // The client is going away (browser close, etc.) |
| 138 | QUIC_CLIENT_GOING_AWAY, |
| 139 | // The server is going away (restart etc.) |
| 140 | QUIC_SERVER_GOING_AWAY, |
| 141 | // A stream ID was invalid. |
| 142 | QUIC_INVALID_STREAM_ID, |
| 143 | // Too many streams already open. |
| 144 | QUIC_TOO_MANY_OPEN_STREAMS, |
| 145 | |
| 146 | // We hit our prenegotiated (or default) timeout |
| 147 | QUIC_CONNECTION_TIMED_OUT, |
| 148 | |
| 149 | // Crypto errors. |
| 150 | |
| 151 | // Handshake message contained out of order tags. |
| 152 | QUIC_CRYPTO_TAGS_OUT_OF_ORDER, |
| 153 | // Handshake message contained too many entires. |
| 154 | QUIC_CRYPTO_TOO_MANY_ENTRIES, |
| 155 | // Handshake message contained an invalid value length. |
| 156 | QUIC_CRYPTO_INVALID_VALUE_LENGTH, |
| 157 | // A crypto message was received after the handshake was complete. |
| 158 | QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE, |
| 159 | // A crypto message was receieved with an illegal message tag. |
| 160 | QUIC_INVALID_CRYPTO_MESSAGE_TYPE, |
| 161 | |
| 162 | }; |
| 163 | |
| 164 | struct NET_EXPORT_PRIVATE QuicPacketHeader { |
| 165 | // Includes the ConnectionHeader and CongestionMonitoredHeader |
| 166 | // from the design docs, as well as some elements of DecryptedData. |
| 167 | QuicGuid guid; |
| 168 | QuicPacketSequenceNumber packet_sequence_number; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 169 | QuicPacketFlags flags; |
| 170 | QuicFecGroupNumber fec_group; |
| 171 | }; |
| 172 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 173 | struct NET_EXPORT_PRIVATE QuicStreamFrame { |
| 174 | QuicStreamFrame(); |
| 175 | QuicStreamFrame(QuicStreamId stream_id, |
[email protected] | a506124 | 2012-10-23 23:29:37 | [diff] [blame] | 176 | bool fin, |
| 177 | uint64 offset, |
| 178 | base::StringPiece data); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 179 | |
| 180 | QuicStreamId stream_id; |
| 181 | bool fin; |
| 182 | uint64 offset; |
| 183 | base::StringPiece data; |
| 184 | }; |
| 185 | |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 186 | // TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing |
| 187 | // is finalized. |
| 188 | typedef std::set<QuicPacketSequenceNumber> SequenceSet; |
[email protected] | 3c5f4a73 | 2013-01-12 16:45:34 | [diff] [blame^] | 189 | // TODO(pwestin): Add a way to enforce the max size of this map. |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 190 | typedef std::map<QuicPacketSequenceNumber, QuicTime> TimeMap; |
[email protected] | 044ac2b | 2012-11-13 21:41:06 | [diff] [blame] | 191 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 192 | struct NET_EXPORT_PRIVATE ReceivedPacketInfo { |
| 193 | ReceivedPacketInfo(); |
| 194 | ~ReceivedPacketInfo(); |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 195 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 196 | std::ostream& os, const ReceivedPacketInfo& s); |
[email protected] | a674b4c | 2012-12-05 03:44:30 | [diff] [blame] | 197 | |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 198 | // Records a packet receipt. |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 199 | void RecordReceived(QuicPacketSequenceNumber sequence_number); |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 200 | |
| 201 | // True if the sequence number is greater than largest_received or is listed |
| 202 | // as missing. |
| 203 | // Always returns false for sequence numbers less than least_unacked. |
| 204 | bool IsAwaitingPacket(QuicPacketSequenceNumber sequence_number) const; |
| 205 | |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 206 | // Clears all missing packets less than |least_unacked|. |
| 207 | void ClearMissingBefore(QuicPacketSequenceNumber least_unacked); |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 208 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 209 | // The highest packet sequence number we've received from the peer. |
| 210 | QuicPacketSequenceNumber largest_received; |
[email protected] | a674b4c | 2012-12-05 03:44:30 | [diff] [blame] | 211 | |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 212 | // The set of packets which we're expecting and have not received. |
| 213 | SequenceSet missing_packets; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 214 | }; |
| 215 | |
| 216 | struct NET_EXPORT_PRIVATE SentPacketInfo { |
| 217 | SentPacketInfo(); |
| 218 | ~SentPacketInfo(); |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 219 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 220 | std::ostream& os, const SentPacketInfo& s); |
| 221 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 222 | // The lowest packet we've sent which is unacked, and we expect an ack for. |
| 223 | QuicPacketSequenceNumber least_unacked; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 224 | }; |
| 225 | |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 226 | struct NET_EXPORT_PRIVATE QuicAckFrame { |
| 227 | QuicAckFrame() {} |
| 228 | // Testing convenience method to construct a QuicAckFrame with all packets |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 229 | // from least_unacked to largest_received acked. |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 230 | QuicAckFrame(QuicPacketSequenceNumber largest_received, |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 231 | QuicPacketSequenceNumber least_unacked); |
| 232 | |
| 233 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 234 | std::ostream& os, const QuicAckFrame& s); |
| 235 | |
| 236 | SentPacketInfo sent_info; |
| 237 | ReceivedPacketInfo received_info; |
| 238 | }; |
| 239 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 240 | // Defines for all types of congestion feedback that will be negotiated in QUIC, |
| 241 | // kTCP MUST be supported by all QUIC implementations to guarentee 100% |
| 242 | // compatibility. |
| 243 | enum CongestionFeedbackType { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 244 | kTCP, // Used to mimic TCP. |
| 245 | kInterArrival, // Use additional inter arrival information. |
| 246 | kFixRate, // Provided for testing. |
| 247 | }; |
| 248 | |
| 249 | struct NET_EXPORT_PRIVATE CongestionFeedbackMessageTCP { |
| 250 | uint16 accumulated_number_of_lost_packets; |
| 251 | uint16 receive_window; // Number of bytes >> 4. |
| 252 | }; |
| 253 | |
| 254 | struct NET_EXPORT_PRIVATE CongestionFeedbackMessageInterArrival { |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 255 | CongestionFeedbackMessageInterArrival(); |
| 256 | ~CongestionFeedbackMessageInterArrival(); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 257 | uint16 accumulated_number_of_lost_packets; |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 258 | // The set of received packets since the last feedback was sent, along with |
| 259 | // their arrival times. |
| 260 | TimeMap received_packet_times; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 261 | }; |
| 262 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 263 | struct NET_EXPORT_PRIVATE CongestionFeedbackMessageFixRate { |
| 264 | uint32 bitrate_in_bytes_per_second; |
| 265 | }; |
| 266 | |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 267 | struct NET_EXPORT_PRIVATE QuicCongestionFeedbackFrame { |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 268 | QuicCongestionFeedbackFrame(); |
| 269 | ~QuicCongestionFeedbackFrame(); |
| 270 | |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 271 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 272 | std::ostream& os, const QuicCongestionFeedbackFrame& c); |
| 273 | |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 274 | CongestionFeedbackType type; |
| 275 | // This should really be a union, but since the inter arrival struct |
| 276 | // is non-trivial, C++ prohibits it. |
| 277 | CongestionFeedbackMessageTCP tcp; |
| 278 | CongestionFeedbackMessageInterArrival inter_arrival; |
| 279 | CongestionFeedbackMessageFixRate fix_rate; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 280 | }; |
| 281 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 282 | struct NET_EXPORT_PRIVATE QuicRstStreamFrame { |
| 283 | QuicRstStreamFrame() {} |
| 284 | QuicRstStreamFrame(QuicStreamId stream_id, uint64 offset, |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 285 | QuicErrorCode error_code) |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 286 | : stream_id(stream_id), offset(offset), error_code(error_code) { |
| 287 | DCHECK_LE(error_code, std::numeric_limits<uint8>::max()); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | QuicStreamId stream_id; |
| 291 | uint64 offset; |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 292 | QuicErrorCode error_code; |
| 293 | std::string error_details; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 294 | }; |
| 295 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 296 | struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame { |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 297 | QuicErrorCode error_code; |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 298 | QuicAckFrame ack_frame; |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 299 | std::string error_details; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 300 | }; |
| 301 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 302 | struct NET_EXPORT_PRIVATE QuicFrame { |
| 303 | QuicFrame() {} |
| 304 | explicit QuicFrame(QuicStreamFrame* stream_frame) |
[email protected] | 610a7e94 | 2012-12-18 00:21:39 | [diff] [blame] | 305 | : type(STREAM_FRAME), |
| 306 | stream_frame(stream_frame) { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 307 | } |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 308 | explicit QuicFrame(QuicAckFrame* frame) |
[email protected] | 610a7e94 | 2012-12-18 00:21:39 | [diff] [blame] | 309 | : type(ACK_FRAME), |
| 310 | ack_frame(frame) { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 311 | } |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 312 | explicit QuicFrame(QuicCongestionFeedbackFrame* frame) |
[email protected] | 610a7e94 | 2012-12-18 00:21:39 | [diff] [blame] | 313 | : type(CONGESTION_FEEDBACK_FRAME), |
| 314 | congestion_feedback_frame(frame) { |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 315 | } |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 316 | explicit QuicFrame(QuicRstStreamFrame* frame) |
| 317 | : type(RST_STREAM_FRAME), |
| 318 | rst_stream_frame(frame) { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 319 | } |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 320 | explicit QuicFrame(QuicConnectionCloseFrame* frame) |
| 321 | : type(CONNECTION_CLOSE_FRAME), |
| 322 | connection_close_frame(frame) { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 323 | } |
| 324 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 325 | QuicFrameType type; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 326 | union { |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 327 | QuicStreamFrame* stream_frame; |
| 328 | QuicAckFrame* ack_frame; |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 329 | QuicCongestionFeedbackFrame* congestion_feedback_frame; |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 330 | QuicRstStreamFrame* rst_stream_frame; |
| 331 | QuicConnectionCloseFrame* connection_close_frame; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 332 | }; |
| 333 | }; |
| 334 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 335 | typedef std::vector<QuicFrame> QuicFrames; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 336 | |
| 337 | struct NET_EXPORT_PRIVATE QuicFecData { |
| 338 | QuicFecData(); |
[email protected] | a506124 | 2012-10-23 23:29:37 | [diff] [blame] | 339 | |
| 340 | bool operator==(const QuicFecData& other) const; |
| 341 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 342 | QuicFecGroupNumber fec_group; |
[email protected] | a506124 | 2012-10-23 23:29:37 | [diff] [blame] | 343 | QuicPacketSequenceNumber min_protected_packet_sequence_number; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 344 | // The last protected packet's sequence number will be one |
| 345 | // less than the sequence number of the FEC packet. |
| 346 | base::StringPiece redundancy; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 347 | }; |
| 348 | |
| 349 | struct NET_EXPORT_PRIVATE QuicPacketData { |
| 350 | std::string data; |
| 351 | }; |
| 352 | |
| 353 | class NET_EXPORT_PRIVATE QuicData { |
| 354 | public: |
| 355 | QuicData(const char* buffer, size_t length) |
| 356 | : buffer_(buffer), |
| 357 | length_(length), |
| 358 | owns_buffer_(false) { } |
| 359 | |
| 360 | QuicData(char* buffer, size_t length, bool owns_buffer) |
| 361 | : buffer_(buffer), |
| 362 | length_(length), |
| 363 | owns_buffer_(owns_buffer) { } |
| 364 | |
| 365 | virtual ~QuicData(); |
| 366 | |
| 367 | base::StringPiece AsStringPiece() const { |
| 368 | return base::StringPiece(data(), length()); |
| 369 | } |
| 370 | |
| 371 | const char* data() const { return buffer_; } |
| 372 | size_t length() const { return length_; } |
| 373 | |
| 374 | private: |
| 375 | const char* buffer_; |
| 376 | size_t length_; |
| 377 | bool owns_buffer_; |
| 378 | |
| 379 | DISALLOW_COPY_AND_ASSIGN(QuicData); |
| 380 | }; |
| 381 | |
| 382 | class NET_EXPORT_PRIVATE QuicPacket : public QuicData { |
| 383 | public: |
[email protected] | 082b65b | 2012-11-10 19:11:31 | [diff] [blame] | 384 | QuicPacket( |
| 385 | char* buffer, size_t length, bool owns_buffer, QuicPacketFlags flags) |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 386 | : QuicData(buffer, length, owns_buffer), |
[email protected] | 082b65b | 2012-11-10 19:11:31 | [diff] [blame] | 387 | buffer_(buffer), |
| 388 | flags_(flags) { } |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 389 | |
| 390 | base::StringPiece FecProtectedData() const { |
| 391 | return base::StringPiece(data() + kStartOfFecProtectedData, |
| 392 | length() - kStartOfFecProtectedData); |
| 393 | } |
| 394 | |
| 395 | base::StringPiece AssociatedData() const { |
| 396 | return base::StringPiece(data() + kStartOfHashData, kStartOfEncryptedData); |
| 397 | } |
| 398 | |
| 399 | base::StringPiece Plaintext() const { |
| 400 | return base::StringPiece(data() + kStartOfEncryptedData, |
| 401 | length() - kStartOfEncryptedData); |
| 402 | } |
[email protected] | 082b65b | 2012-11-10 19:11:31 | [diff] [blame] | 403 | |
| 404 | bool IsFecPacket() const { |
| 405 | return flags_ == PACKET_FLAGS_FEC; |
| 406 | } |
| 407 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 408 | char* mutable_data() { return buffer_; } |
| 409 | |
| 410 | private: |
| 411 | char* buffer_; |
[email protected] | 082b65b | 2012-11-10 19:11:31 | [diff] [blame] | 412 | const QuicPacketFlags flags_; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 413 | |
[email protected] | 2e740db | 2012-10-20 19:35:19 | [diff] [blame] | 414 | DISALLOW_COPY_AND_ASSIGN(QuicPacket); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 415 | }; |
| 416 | |
| 417 | class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData { |
| 418 | public: |
| 419 | QuicEncryptedPacket(const char* buffer, size_t length) |
| 420 | : QuicData(buffer, length) { } |
| 421 | |
| 422 | QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer) |
| 423 | : QuicData(buffer, length, owns_buffer) { } |
| 424 | |
| 425 | base::StringPiece AssociatedData() const { |
| 426 | return base::StringPiece(data() + kStartOfHashData, kStartOfEncryptedData); |
| 427 | } |
| 428 | |
[email protected] | 2e740db | 2012-10-20 19:35:19 | [diff] [blame] | 429 | private: |
| 430 | DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 431 | }; |
| 432 | |
| 433 | } // namespace net |
| 434 | |
| 435 | #endif // NET_QUIC_QUIC_PROTOCOL_H_ |