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