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