[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] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 23 | #include "net/quic/quic_bandwidth.h" |
[email protected] | 2a960e0 | 2012-11-11 14:48:10 | [diff] [blame] | 24 | #include "net/quic/quic_time.h" |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 25 | |
| 26 | namespace net { |
| 27 | |
[email protected] | f1e97e9 | 2012-12-16 04:53:25 | [diff] [blame] | 28 | using ::operator<<; |
| 29 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 30 | class QuicPacket; |
| 31 | |
| 32 | typedef uint64 QuicGuid; |
| 33 | typedef uint32 QuicStreamId; |
| 34 | typedef uint64 QuicStreamOffset; |
| 35 | typedef uint64 QuicPacketSequenceNumber; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 36 | typedef QuicPacketSequenceNumber QuicFecGroupNumber; |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 37 | typedef uint64 QuicPublicResetNonceProof; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 38 | typedef uint8 QuicPacketEntropyHash; |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 39 | typedef uint32 QuicVersionTag; |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 40 | typedef std::vector<QuicVersionTag> QuicVersionTagList; |
[email protected] | cff7b7b | 2013-01-11 08:49:07 | [diff] [blame] | 41 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 42 | // TODO(rch): Consider Quic specific names for these constants. |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 43 | // Maximum size in bytes of a QUIC packet. |
| 44 | const QuicByteCount kMaxPacketSize = 1200; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 45 | |
| 46 | // Maximum number of open streams per connection. |
| 47 | const size_t kDefaultMaxStreamsPerConnection = 100; |
| 48 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 49 | // Number of bytes reserved for guid in the packet header. |
| 50 | const size_t kQuicGuidSize = 8; |
| 51 | // Number of bytes reserved for public flags in the packet header. |
| 52 | const size_t kPublicFlagsSize = 1; |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 53 | // Number of bytes reserved for version number in the packet header. |
| 54 | const size_t kQuicVersionSize = 4; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 55 | // Number of bytes reserved for sequence number in the packet header. |
| 56 | const size_t kSequenceNumberSize = 6; |
| 57 | // Number of bytes reserved for private flags in the packet header. |
| 58 | const size_t kPrivateFlagsSize = 1; |
| 59 | // Number of bytes reserved for FEC group in the packet header. |
| 60 | const size_t kFecGroupSize = 1; |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 61 | // Number of bytes reserved for the nonce proof in public reset packet. |
| 62 | const size_t kPublicResetNonceSize = 8; |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 63 | |
| 64 | // Signifies that the QuicPacket will contain version of the protocol. |
| 65 | const bool kIncludeVersion = true; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 66 | |
| 67 | // Size in bytes of the data or fec packet header. |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 68 | NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(bool include_version); |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 69 | // Size in bytes of the public reset packet. |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 70 | NET_EXPORT_PRIVATE size_t GetPublicResetPacketSize(); |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 71 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 72 | // Index of the first byte in a QUIC packet of FEC protected data. |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 73 | NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(bool include_version); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 74 | // Index of the first byte in a QUIC packet of encrypted data. |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 75 | NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(bool include_version); |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 76 | // Returns true if |version| is a supported protocol version. |
| 77 | NET_EXPORT_PRIVATE bool IsSupportedVersion(QuicVersionTag version); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 78 | |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 79 | // Index of the first byte in a QUIC packet which is used in hash calculation. |
| 80 | const size_t kStartOfHashData = 0; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 81 | |
| 82 | // Limit on the delta between stream IDs. |
| 83 | const QuicStreamId kMaxStreamIdDelta = 100; |
| 84 | |
| 85 | // Reserved ID for the crypto stream. |
| 86 | // TODO(rch): ensure that this is not usable by any other streams. |
| 87 | const QuicStreamId kCryptoStreamId = 1; |
| 88 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 89 | // Value which indicates this packet is not FEC protected. |
| 90 | const uint8 kNoFecOffset = 0xFF; |
| 91 | |
[email protected] | 2a960e0 | 2012-11-11 14:48:10 | [diff] [blame] | 92 | const int64 kDefaultTimeoutUs = 600000000; // 10 minutes. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 93 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame^] | 94 | enum Retransmission { |
| 95 | NOT_RETRANSMISSION = 0, |
| 96 | IS_RETRANSMISSION = 1, |
| 97 | }; |
| 98 | |
| 99 | enum HasRetransmittableData { |
| 100 | HAS_RETRANSMITTABLE_DATA = 0, |
| 101 | NO_RETRANSMITTABLE_DATA = 1, |
| 102 | }; |
| 103 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 104 | enum QuicFrameType { |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 105 | PADDING_FRAME = 0, |
| 106 | STREAM_FRAME, |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 107 | ACK_FRAME, |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 108 | CONGESTION_FEEDBACK_FRAME, |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 109 | RST_STREAM_FRAME, |
| 110 | CONNECTION_CLOSE_FRAME, |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 111 | GOAWAY_FRAME, |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 112 | NUM_FRAME_TYPES |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 113 | }; |
| 114 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 115 | enum QuicPacketPublicFlags { |
| 116 | PACKET_PUBLIC_FLAGS_NONE = 0, |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 117 | PACKET_PUBLIC_FLAGS_VERSION = 1 << 0, // Packet header contains version info. |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 118 | PACKET_PUBLIC_FLAGS_RST = 1 << 1, // Packet is a public reset packet. |
| 119 | PACKET_PUBLIC_FLAGS_MAX = (1 << 2) - 1 // All bits set. |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 120 | }; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 121 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 122 | enum QuicPacketPrivateFlags { |
| 123 | PACKET_PRIVATE_FLAGS_NONE = 0, |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 124 | PACKET_PRIVATE_FLAGS_FEC = 1 << 0, // Payload is FEC as opposed to frames. |
| 125 | PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 1, |
| 126 | PACKET_PRIVATE_FLAGS_FEC_ENTROPY = 1 << 2, |
| 127 | PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1 // All bits set. |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 128 | }; |
| 129 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame^] | 130 | enum QuicRstStreamErrorCode { |
| 131 | QUIC_STREAM_NO_ERROR = 0, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 132 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 133 | // There was some server error which halted stream processing. |
| 134 | QUIC_SERVER_ERROR_PROCESSING_STREAM, |
| 135 | // We got two fin or reset offsets which did not match. |
| 136 | QUIC_MULTIPLE_TERMINATION_OFFSETS, |
| 137 | // We got bad payload and can not respond to it at the protocol level. |
| 138 | QUIC_BAD_APPLICATION_PAYLOAD, |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame^] | 139 | // Stream closed due to connection error. No reset frame is sent when this |
| 140 | // happens. |
| 141 | QUIC_STREAM_CONNECTION_ERROR, |
| 142 | // GoAway frame sent. No more stream can be created. |
| 143 | QUIC_STREAM_PEER_GOING_AWAY, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 144 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame^] | 145 | // No error. Used as bound while iterating. |
| 146 | QUIC_STREAM_LAST_ERROR, |
| 147 | }; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 148 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame^] | 149 | enum QuicErrorCode { |
| 150 | QUIC_NO_ERROR = 0, |
| 151 | |
| 152 | // Connection has reached an invalid state. |
| 153 | QUIC_INTERNAL_ERROR, |
| 154 | // There were data frames after the a fin or reset. |
| 155 | QUIC_STREAM_DATA_AFTER_TERMINATION, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 156 | // Control frame is malformed. |
| 157 | QUIC_INVALID_PACKET_HEADER, |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 158 | // Frame data is malformed. |
| 159 | QUIC_INVALID_FRAME_DATA, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 160 | // FEC data is malformed. |
| 161 | QUIC_INVALID_FEC_DATA, |
| 162 | // Stream rst data is malformed |
| 163 | QUIC_INVALID_RST_STREAM_DATA, |
| 164 | // Connection close data is malformed. |
| 165 | QUIC_INVALID_CONNECTION_CLOSE_DATA, |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 166 | // GoAway data is malformed. |
| 167 | QUIC_INVALID_GOAWAY_DATA, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 168 | // Ack data is malformed. |
| 169 | QUIC_INVALID_ACK_DATA, |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 170 | // Version negotiation packet is malformed. |
| 171 | QUIC_INVALID_VERSION_NEGOTIATION_PACKET, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 172 | // There was an error decrypting. |
| 173 | QUIC_DECRYPTION_FAILURE, |
| 174 | // There was an error encrypting. |
| 175 | QUIC_ENCRYPTION_FAILURE, |
| 176 | // The packet exceeded kMaxPacketSize. |
| 177 | QUIC_PACKET_TOO_LARGE, |
| 178 | // Data was sent for a stream which did not exist. |
| 179 | QUIC_PACKET_FOR_NONEXISTENT_STREAM, |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 180 | // The peer is going away. May be a client or server. |
| 181 | QUIC_PEER_GOING_AWAY, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 182 | // A stream ID was invalid. |
| 183 | QUIC_INVALID_STREAM_ID, |
| 184 | // Too many streams already open. |
| 185 | QUIC_TOO_MANY_OPEN_STREAMS, |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 186 | // Received public reset for this connection. |
| 187 | QUIC_PUBLIC_RESET, |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 188 | // Invalid protocol version |
| 189 | QUIC_INVALID_VERSION, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 190 | |
| 191 | // We hit our prenegotiated (or default) timeout |
| 192 | QUIC_CONNECTION_TIMED_OUT, |
| 193 | |
| 194 | // Crypto errors. |
| 195 | |
| 196 | // Handshake message contained out of order tags. |
| 197 | QUIC_CRYPTO_TAGS_OUT_OF_ORDER, |
[email protected] | 701bc89 | 2013-01-17 04:51:54 | [diff] [blame] | 198 | // Handshake message contained too many entries. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 199 | QUIC_CRYPTO_TOO_MANY_ENTRIES, |
| 200 | // Handshake message contained an invalid value length. |
| 201 | QUIC_CRYPTO_INVALID_VALUE_LENGTH, |
| 202 | // A crypto message was received after the handshake was complete. |
| 203 | QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE, |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 204 | // A crypto message was received with an illegal message tag. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 205 | QUIC_INVALID_CRYPTO_MESSAGE_TYPE, |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 206 | // A crypto message was received with an illegal parameter. |
| 207 | QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER, |
| 208 | // A crypto message was received with a mandatory parameter missing. |
| 209 | QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND, |
| 210 | // A crypto message was received with a parameter that has no overlap |
| 211 | // with the local parameter. |
| 212 | QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP, |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 213 | // A crypto message was received that contained a parameter with too few |
| 214 | // values. |
| 215 | QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND, |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 216 | // An internal error occured in crypto processing. |
| 217 | QUIC_CRYPTO_INTERNAL_ERROR, |
| 218 | // A crypto handshake message specified an unsupported version. |
| 219 | QUIC_VERSION_NOT_SUPPORTED, |
| 220 | // There was no intersection between the crypto primitives supported by the |
| 221 | // peer and ourselves. |
| 222 | QUIC_CRYPTO_NO_SUPPORT, |
| 223 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame^] | 224 | // No error. Used as bound while iterating. |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 225 | QUIC_LAST_ERROR, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 226 | }; |
| 227 | |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 228 | // Version and Crypto tags are written to the wire with a big-endian |
| 229 | // representation of the name of the tag. For example |
| 230 | // the client hello tag (CHLO) will be written as the |
| 231 | // following 4 bytes: 'C' 'H' 'L' 'O'. Since it is |
| 232 | // stored in memory as a little endian uint32, we need |
| 233 | // to reverse the order of the bytes. |
| 234 | #define MAKE_TAG(a, b, c, d) ((d << 24) + (c << 16) + (b << 8) + a) |
| 235 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 236 | const QuicVersionTag kUnsupportedVersion = -1; |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 237 | const QuicVersionTag kQuicVersion1 = MAKE_TAG('Q', '1', '.', '0'); |
| 238 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 239 | struct NET_EXPORT_PRIVATE QuicPacketPublicHeader { |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 240 | QuicPacketPublicHeader(); |
| 241 | explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other); |
| 242 | ~QuicPacketPublicHeader(); |
| 243 | |
| 244 | QuicPacketPublicHeader& operator=(const QuicPacketPublicHeader& other); |
| 245 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 246 | // Universal header. All QuicPacket headers will have a guid and public flags. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 247 | QuicGuid guid; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 248 | bool reset_flag; |
| 249 | bool version_flag; |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 250 | QuicVersionTagList versions; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 251 | }; |
| 252 | |
| 253 | // Header for Data or FEC packets. |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame^] | 254 | struct NET_EXPORT_PRIVATE QuicPacketHeader { |
| 255 | QuicPacketHeader(); |
| 256 | explicit QuicPacketHeader(const QuicPacketPublicHeader& header); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 257 | |
| 258 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 259 | std::ostream& os, const QuicPacketHeader& s); |
| 260 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 261 | QuicPacketPublicHeader public_header; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 262 | bool fec_flag; |
| 263 | bool fec_entropy_flag; |
| 264 | bool entropy_flag; |
| 265 | QuicPacketEntropyHash entropy_hash; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 266 | QuicPacketSequenceNumber packet_sequence_number; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 267 | QuicFecGroupNumber fec_group; |
| 268 | }; |
| 269 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame^] | 270 | struct NET_EXPORT_PRIVATE QuicPublicResetPacket { |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 271 | QuicPublicResetPacket() {} |
| 272 | explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header) |
| 273 | : public_header(header) {} |
| 274 | QuicPacketPublicHeader public_header; |
| 275 | QuicPacketSequenceNumber rejected_sequence_number; |
| 276 | QuicPublicResetNonceProof nonce_proof; |
| 277 | }; |
| 278 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 279 | enum QuicVersionNegotiationState { |
| 280 | START_NEGOTIATION = 0, |
| 281 | SENT_NEGOTIATION_PACKET, |
| 282 | NEGOTIATED_VERSION |
| 283 | }; |
| 284 | |
| 285 | typedef QuicPacketPublicHeader QuicVersionNegotiationPacket; |
| 286 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 287 | // A padding frame contains no payload. |
| 288 | struct NET_EXPORT_PRIVATE QuicPaddingFrame { |
| 289 | }; |
| 290 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 291 | struct NET_EXPORT_PRIVATE QuicStreamFrame { |
| 292 | QuicStreamFrame(); |
| 293 | QuicStreamFrame(QuicStreamId stream_id, |
[email protected] | a506124 | 2012-10-23 23:29:37 | [diff] [blame] | 294 | bool fin, |
[email protected] | 701bc89 | 2013-01-17 04:51:54 | [diff] [blame] | 295 | QuicStreamOffset offset, |
[email protected] | a506124 | 2012-10-23 23:29:37 | [diff] [blame] | 296 | base::StringPiece data); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 297 | |
| 298 | QuicStreamId stream_id; |
| 299 | bool fin; |
[email protected] | 701bc89 | 2013-01-17 04:51:54 | [diff] [blame] | 300 | QuicStreamOffset offset; // Location of this data in the stream. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 301 | base::StringPiece data; |
| 302 | }; |
| 303 | |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 304 | // TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing |
| 305 | // is finalized. |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 306 | typedef std::set<QuicPacketSequenceNumber> SequenceNumberSet; |
[email protected] | 3c5f4a73 | 2013-01-12 16:45:34 | [diff] [blame] | 307 | // TODO(pwestin): Add a way to enforce the max size of this map. |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 308 | typedef std::map<QuicPacketSequenceNumber, QuicTime> TimeMap; |
[email protected] | 044ac2b | 2012-11-13 21:41:06 | [diff] [blame] | 309 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 310 | struct NET_EXPORT_PRIVATE ReceivedPacketInfo { |
| 311 | ReceivedPacketInfo(); |
| 312 | ~ReceivedPacketInfo(); |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 313 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 314 | std::ostream& os, const ReceivedPacketInfo& s); |
[email protected] | a674b4c | 2012-12-05 03:44:30 | [diff] [blame] | 315 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 316 | // Entropy hash of all packets up to largest observed not including missing |
| 317 | // packets. |
| 318 | QuicPacketEntropyHash entropy_hash; |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 319 | |
[email protected] | 48697d8a | 2013-01-15 19:42:24 | [diff] [blame] | 320 | // The highest packet sequence number we've observed from the peer. |
| 321 | // |
| 322 | // In general, this should be the largest packet number we've received. In |
| 323 | // the case of truncated acks, we may have to advertise a lower "upper bound" |
| 324 | // than largest received, to avoid implicitly acking missing packets that |
| 325 | // don't fit in the missing packet list due to size limitations. In this |
| 326 | // case, largest_observed may be a packet which is also in the missing packets |
| 327 | // list. |
| 328 | QuicPacketSequenceNumber largest_observed; |
[email protected] | a674b4c | 2012-12-05 03:44:30 | [diff] [blame] | 329 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 330 | // Time elapsed since largest_observed was received until this Ack frame was |
| 331 | // sent. |
| 332 | QuicTime::Delta delta_time_largest_observed; |
| 333 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 334 | // TODO(satyamshekhar): Can be optimized using an interval set like data |
| 335 | // structure. |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 336 | // The set of packets which we're expecting and have not received. |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 337 | SequenceNumberSet missing_packets; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 338 | }; |
| 339 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 340 | // True if the sequence number is greater than largest_observed or is listed |
| 341 | // as missing. |
| 342 | // Always returns false for sequence numbers less than least_unacked. |
| 343 | bool NET_EXPORT_PRIVATE IsAwaitingPacket( |
| 344 | const ReceivedPacketInfo& received_info, |
| 345 | QuicPacketSequenceNumber sequence_number); |
| 346 | |
| 347 | // Inserts missing packets between [lower, higher). |
| 348 | void NET_EXPORT_PRIVATE InsertMissingPacketsBetween( |
| 349 | ReceivedPacketInfo* received_info, |
| 350 | QuicPacketSequenceNumber lower, |
| 351 | QuicPacketSequenceNumber higher); |
| 352 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 353 | struct NET_EXPORT_PRIVATE SentPacketInfo { |
| 354 | SentPacketInfo(); |
| 355 | ~SentPacketInfo(); |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 356 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 357 | std::ostream& os, const SentPacketInfo& s); |
| 358 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 359 | // Entropy hash of all packets up to, but not including, the least unacked |
| 360 | // packet. |
| 361 | QuicPacketEntropyHash entropy_hash; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 362 | // The lowest packet we've sent which is unacked, and we expect an ack for. |
| 363 | QuicPacketSequenceNumber least_unacked; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 364 | }; |
| 365 | |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 366 | struct NET_EXPORT_PRIVATE QuicAckFrame { |
| 367 | QuicAckFrame() {} |
| 368 | // Testing convenience method to construct a QuicAckFrame with all packets |
[email protected] | 48697d8a | 2013-01-15 19:42:24 | [diff] [blame] | 369 | // from least_unacked to largest_observed acked. |
| 370 | QuicAckFrame(QuicPacketSequenceNumber largest_observed, |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 371 | QuicTime largest_observed_receive_time, |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 372 | QuicPacketSequenceNumber least_unacked); |
| 373 | |
| 374 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 375 | std::ostream& os, const QuicAckFrame& s); |
| 376 | |
| 377 | SentPacketInfo sent_info; |
| 378 | ReceivedPacketInfo received_info; |
| 379 | }; |
| 380 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 381 | // Defines for all types of congestion feedback that will be negotiated in QUIC, |
| 382 | // kTCP MUST be supported by all QUIC implementations to guarentee 100% |
| 383 | // compatibility. |
| 384 | enum CongestionFeedbackType { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 385 | kTCP, // Used to mimic TCP. |
| 386 | kInterArrival, // Use additional inter arrival information. |
| 387 | kFixRate, // Provided for testing. |
| 388 | }; |
| 389 | |
| 390 | struct NET_EXPORT_PRIVATE CongestionFeedbackMessageTCP { |
| 391 | uint16 accumulated_number_of_lost_packets; |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 392 | QuicByteCount receive_window; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 393 | }; |
| 394 | |
| 395 | struct NET_EXPORT_PRIVATE CongestionFeedbackMessageInterArrival { |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 396 | CongestionFeedbackMessageInterArrival(); |
| 397 | ~CongestionFeedbackMessageInterArrival(); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 398 | uint16 accumulated_number_of_lost_packets; |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 399 | // The set of received packets since the last feedback was sent, along with |
| 400 | // their arrival times. |
| 401 | TimeMap received_packet_times; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 402 | }; |
| 403 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 404 | struct NET_EXPORT_PRIVATE CongestionFeedbackMessageFixRate { |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 405 | CongestionFeedbackMessageFixRate(); |
| 406 | QuicBandwidth bitrate; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 407 | }; |
| 408 | |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 409 | struct NET_EXPORT_PRIVATE QuicCongestionFeedbackFrame { |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 410 | QuicCongestionFeedbackFrame(); |
| 411 | ~QuicCongestionFeedbackFrame(); |
| 412 | |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 413 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 414 | std::ostream& os, const QuicCongestionFeedbackFrame& c); |
| 415 | |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 416 | CongestionFeedbackType type; |
| 417 | // This should really be a union, but since the inter arrival struct |
| 418 | // is non-trivial, C++ prohibits it. |
| 419 | CongestionFeedbackMessageTCP tcp; |
| 420 | CongestionFeedbackMessageInterArrival inter_arrival; |
| 421 | CongestionFeedbackMessageFixRate fix_rate; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 422 | }; |
| 423 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 424 | struct NET_EXPORT_PRIVATE QuicRstStreamFrame { |
| 425 | QuicRstStreamFrame() {} |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame^] | 426 | QuicRstStreamFrame(QuicStreamId stream_id, QuicRstStreamErrorCode error_code) |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 427 | : stream_id(stream_id), error_code(error_code) { |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 428 | DCHECK_LE(error_code, std::numeric_limits<uint8>::max()); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | QuicStreamId stream_id; |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame^] | 432 | QuicRstStreamErrorCode error_code; |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 433 | std::string error_details; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 434 | }; |
| 435 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 436 | struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame { |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 437 | QuicErrorCode error_code; |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 438 | std::string error_details; |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 439 | QuicAckFrame ack_frame; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 440 | }; |
| 441 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 442 | struct NET_EXPORT_PRIVATE QuicGoAwayFrame { |
| 443 | QuicGoAwayFrame() {} |
| 444 | QuicGoAwayFrame(QuicErrorCode error_code, |
| 445 | QuicStreamId last_good_stream_id, |
| 446 | const std::string& reason); |
| 447 | |
| 448 | QuicErrorCode error_code; |
| 449 | QuicStreamId last_good_stream_id; |
| 450 | std::string reason_phrase; |
| 451 | }; |
| 452 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 453 | struct NET_EXPORT_PRIVATE QuicFrame { |
| 454 | QuicFrame() {} |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 455 | explicit QuicFrame(QuicPaddingFrame* padding_frame) |
| 456 | : type(PADDING_FRAME), |
| 457 | padding_frame(padding_frame) { |
| 458 | } |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 459 | explicit QuicFrame(QuicStreamFrame* stream_frame) |
[email protected] | 610a7e94 | 2012-12-18 00:21:39 | [diff] [blame] | 460 | : type(STREAM_FRAME), |
| 461 | stream_frame(stream_frame) { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 462 | } |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 463 | explicit QuicFrame(QuicAckFrame* frame) |
[email protected] | 610a7e94 | 2012-12-18 00:21:39 | [diff] [blame] | 464 | : type(ACK_FRAME), |
| 465 | ack_frame(frame) { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 466 | } |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 467 | explicit QuicFrame(QuicCongestionFeedbackFrame* frame) |
[email protected] | 610a7e94 | 2012-12-18 00:21:39 | [diff] [blame] | 468 | : type(CONGESTION_FEEDBACK_FRAME), |
| 469 | congestion_feedback_frame(frame) { |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 470 | } |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 471 | explicit QuicFrame(QuicRstStreamFrame* frame) |
| 472 | : type(RST_STREAM_FRAME), |
| 473 | rst_stream_frame(frame) { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 474 | } |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 475 | explicit QuicFrame(QuicConnectionCloseFrame* frame) |
| 476 | : type(CONNECTION_CLOSE_FRAME), |
| 477 | connection_close_frame(frame) { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 478 | } |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 479 | explicit QuicFrame(QuicGoAwayFrame* frame) |
| 480 | : type(GOAWAY_FRAME), |
| 481 | goaway_frame(frame) { |
| 482 | } |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 483 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 484 | QuicFrameType type; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 485 | union { |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 486 | QuicPaddingFrame* padding_frame; |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 487 | QuicStreamFrame* stream_frame; |
| 488 | QuicAckFrame* ack_frame; |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 489 | QuicCongestionFeedbackFrame* congestion_feedback_frame; |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 490 | QuicRstStreamFrame* rst_stream_frame; |
| 491 | QuicConnectionCloseFrame* connection_close_frame; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 492 | QuicGoAwayFrame* goaway_frame; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 493 | }; |
| 494 | }; |
| 495 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 496 | typedef std::vector<QuicFrame> QuicFrames; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 497 | |
| 498 | struct NET_EXPORT_PRIVATE QuicFecData { |
| 499 | QuicFecData(); |
[email protected] | a506124 | 2012-10-23 23:29:37 | [diff] [blame] | 500 | |
| 501 | bool operator==(const QuicFecData& other) const; |
| 502 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 503 | // The FEC group number is also the sequence number of the first |
| 504 | // FEC protected packet. The last protected packet's sequence number will |
| 505 | // be one less than the sequence number of the FEC packet. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 506 | QuicFecGroupNumber fec_group; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 507 | base::StringPiece redundancy; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 508 | }; |
| 509 | |
| 510 | struct NET_EXPORT_PRIVATE QuicPacketData { |
| 511 | std::string data; |
| 512 | }; |
| 513 | |
| 514 | class NET_EXPORT_PRIVATE QuicData { |
| 515 | public: |
| 516 | QuicData(const char* buffer, size_t length) |
| 517 | : buffer_(buffer), |
| 518 | length_(length), |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 519 | owns_buffer_(false) {} |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 520 | |
| 521 | QuicData(char* buffer, size_t length, bool owns_buffer) |
| 522 | : buffer_(buffer), |
| 523 | length_(length), |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 524 | owns_buffer_(owns_buffer) {} |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 525 | |
| 526 | virtual ~QuicData(); |
| 527 | |
| 528 | base::StringPiece AsStringPiece() const { |
| 529 | return base::StringPiece(data(), length()); |
| 530 | } |
| 531 | |
| 532 | const char* data() const { return buffer_; } |
| 533 | size_t length() const { return length_; } |
| 534 | |
| 535 | private: |
| 536 | const char* buffer_; |
| 537 | size_t length_; |
| 538 | bool owns_buffer_; |
| 539 | |
| 540 | DISALLOW_COPY_AND_ASSIGN(QuicData); |
| 541 | }; |
| 542 | |
| 543 | class NET_EXPORT_PRIVATE QuicPacket : public QuicData { |
| 544 | public: |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 545 | static QuicPacket* NewDataPacket(char* buffer, |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 546 | size_t length, |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 547 | bool owns_buffer, |
| 548 | bool includes_version) { |
| 549 | return new QuicPacket(buffer, length, owns_buffer, includes_version, false); |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | static QuicPacket* NewFecPacket(char* buffer, |
| 553 | size_t length, |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 554 | bool owns_buffer, |
| 555 | bool includes_version) { |
| 556 | return new QuicPacket(buffer, length, owns_buffer, includes_version, true); |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 557 | } |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 558 | |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 559 | base::StringPiece FecProtectedData() const; |
| 560 | base::StringPiece AssociatedData() const; |
| 561 | base::StringPiece BeforePlaintext() const; |
| 562 | base::StringPiece Plaintext() const; |
[email protected] | 082b65b | 2012-11-10 19:11:31 | [diff] [blame] | 563 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 564 | bool is_fec_packet() const { return is_fec_packet_; } |
[email protected] | 082b65b | 2012-11-10 19:11:31 | [diff] [blame] | 565 | |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 566 | bool includes_version() const { return includes_version_; } |
| 567 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 568 | char* mutable_data() { return buffer_; } |
| 569 | |
| 570 | private: |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 571 | QuicPacket(char* buffer, |
| 572 | size_t length, |
| 573 | bool owns_buffer, |
| 574 | bool includes_version, |
| 575 | bool is_fec_packet) |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 576 | : QuicData(buffer, length, owns_buffer), |
| 577 | buffer_(buffer), |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 578 | is_fec_packet_(is_fec_packet), |
| 579 | includes_version_(includes_version) {} |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 580 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 581 | char* buffer_; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 582 | const bool is_fec_packet_; |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 583 | const bool includes_version_; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 584 | |
[email protected] | 2e740db | 2012-10-20 19:35:19 | [diff] [blame] | 585 | DISALLOW_COPY_AND_ASSIGN(QuicPacket); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 586 | }; |
| 587 | |
| 588 | class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData { |
| 589 | public: |
| 590 | QuicEncryptedPacket(const char* buffer, size_t length) |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 591 | : QuicData(buffer, length) {} |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 592 | |
| 593 | QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer) |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 594 | : QuicData(buffer, length, owns_buffer) {} |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 595 | |
[email protected] | c1b32c6 | 2013-01-20 02:49:10 | [diff] [blame] | 596 | // By default, gtest prints the raw bytes of an object. The bool data |
| 597 | // member (in the base class QuicData) causes this object to have padding |
| 598 | // bytes, which causes the default gtest object printer to read |
| 599 | // uninitialize memory. So we need to teach gtest how to print this object. |
| 600 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 601 | std::ostream& os, const QuicEncryptedPacket& s); |
| 602 | |
[email protected] | 2e740db | 2012-10-20 19:35:19 | [diff] [blame] | 603 | private: |
| 604 | DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 605 | }; |
| 606 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 607 | class NET_EXPORT_PRIVATE RetransmittableFrames { |
| 608 | public: |
| 609 | RetransmittableFrames(); |
| 610 | ~RetransmittableFrames(); |
| 611 | |
| 612 | // Allocates a local copy of the referenced StringPiece has QuicStreamFrame |
| 613 | // use it. |
| 614 | // Takes ownership of |stream_frame|. |
| 615 | const QuicFrame& AddStreamFrame(QuicStreamFrame* stream_frame); |
| 616 | // Takes ownership of the frame inside |frame|. |
| 617 | const QuicFrame& AddNonStreamFrame(const QuicFrame& frame); |
| 618 | const QuicFrames& frames() const { return frames_; } |
| 619 | |
| 620 | private: |
| 621 | QuicFrames frames_; |
| 622 | // Data referenced by the StringPiece of a QuicStreamFrame. |
| 623 | std::vector<std::string*> stream_data_; |
| 624 | |
| 625 | DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames); |
| 626 | }; |
| 627 | |
| 628 | struct NET_EXPORT_PRIVATE SerializedPacket { |
| 629 | SerializedPacket(QuicPacketSequenceNumber sequence_number, |
| 630 | QuicPacket* packet, |
| 631 | QuicPacketEntropyHash entropy_hash, |
| 632 | RetransmittableFrames* retransmittable_frames) |
| 633 | : sequence_number(sequence_number), |
| 634 | packet(packet), |
| 635 | entropy_hash(entropy_hash), |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 636 | retransmittable_frames(retransmittable_frames) {} |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 637 | |
| 638 | QuicPacketSequenceNumber sequence_number; |
| 639 | QuicPacket* packet; |
| 640 | QuicPacketEntropyHash entropy_hash; |
| 641 | RetransmittableFrames* retransmittable_frames; |
| 642 | }; |
| 643 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 644 | // A struct for functions which consume data payloads and fins. |
| 645 | // The first member of the pair indicates bytes consumed. |
| 646 | // The second member of the pair indicates if an incoming fin was consumed. |
| 647 | struct QuicConsumedData { |
| 648 | QuicConsumedData(size_t bytes_consumed, bool fin_consumed) |
| 649 | : bytes_consumed(bytes_consumed), |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 650 | fin_consumed(fin_consumed) {} |
[email protected] | c1b32c6 | 2013-01-20 02:49:10 | [diff] [blame] | 651 | |
| 652 | // By default, gtest prints the raw bytes of an object. The bool data |
| 653 | // member causes this object to have padding bytes, which causes the |
| 654 | // default gtest object printer to read uninitialize memory. So we need |
| 655 | // to teach gtest how to print this object. |
| 656 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 657 | std::ostream& os, const QuicConsumedData& s); |
| 658 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 659 | size_t bytes_consumed; |
| 660 | bool fin_consumed; |
| 661 | }; |
| 662 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 663 | } // namespace net |
| 664 | |
| 665 | #endif // NET_QUIC_QUIC_PROTOCOL_H_ |