[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" |
[email protected] | d069c11a | 2013-04-13 00:01:55 | [diff] [blame] | 20 | #include "base/strings/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. |
[email protected] | fe053f9 | 2013-04-23 20:18:55 | [diff] [blame] | 219 | QUIC_CRYPTO_VERSION_NOT_SUPPORTED, |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 220 | // There was no intersection between the crypto primitives supported by the |
| 221 | // peer and ourselves. |
| 222 | QUIC_CRYPTO_NO_SUPPORT, |
[email protected] | ef95114d | 2013-04-17 17:57:01 | [diff] [blame] | 223 | // The server rejected our client hello messages too many times. |
| 224 | QUIC_CRYPTO_TOO_MANY_REJECTS, |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame^] | 225 | // The client rejected the server's certificate chain or signature. |
| 226 | QUIC_PROOF_INVALID, |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 227 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 228 | // No error. Used as bound while iterating. |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 229 | QUIC_LAST_ERROR, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 230 | }; |
| 231 | |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 232 | // Version and Crypto tags are written to the wire with a big-endian |
| 233 | // representation of the name of the tag. For example |
| 234 | // the client hello tag (CHLO) will be written as the |
| 235 | // following 4 bytes: 'C' 'H' 'L' 'O'. Since it is |
| 236 | // stored in memory as a little endian uint32, we need |
| 237 | // to reverse the order of the bytes. |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame^] | 238 | // |
| 239 | // The TAG macro is used in header files to ensure that we don't create static |
| 240 | // initialisers. In normal code, the MakeQuicTag function should be used. |
| 241 | #define TAG(a, b, c, d) ((d << 24) + (c << 16) + (b << 8) + a) |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 242 | const QuicVersionTag kUnsupportedVersion = -1; |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame^] | 243 | const QuicVersionTag kQuicVersion1 = TAG('Q', '1', '.', '0'); |
| 244 | #undef TAG |
| 245 | |
| 246 | // MakeQuicTag returns a value given the four bytes. For example: |
| 247 | // MakeQuicTag('C', 'H', 'L', 'O'); |
| 248 | uint32 NET_EXPORT_PRIVATE MakeQuicTag(char a, char b, char c, char d); |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 249 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 250 | struct NET_EXPORT_PRIVATE QuicPacketPublicHeader { |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 251 | QuicPacketPublicHeader(); |
| 252 | explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other); |
| 253 | ~QuicPacketPublicHeader(); |
| 254 | |
| 255 | QuicPacketPublicHeader& operator=(const QuicPacketPublicHeader& other); |
| 256 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 257 | // Universal header. All QuicPacket headers will have a guid and public flags. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 258 | QuicGuid guid; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 259 | bool reset_flag; |
| 260 | bool version_flag; |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 261 | QuicVersionTagList versions; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 262 | }; |
| 263 | |
| 264 | // Header for Data or FEC packets. |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 265 | struct NET_EXPORT_PRIVATE QuicPacketHeader { |
| 266 | QuicPacketHeader(); |
| 267 | explicit QuicPacketHeader(const QuicPacketPublicHeader& header); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 268 | |
| 269 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 270 | std::ostream& os, const QuicPacketHeader& s); |
| 271 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 272 | QuicPacketPublicHeader public_header; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 273 | bool fec_flag; |
| 274 | bool fec_entropy_flag; |
| 275 | bool entropy_flag; |
| 276 | QuicPacketEntropyHash entropy_hash; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 277 | QuicPacketSequenceNumber packet_sequence_number; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 278 | QuicFecGroupNumber fec_group; |
| 279 | }; |
| 280 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 281 | struct NET_EXPORT_PRIVATE QuicPublicResetPacket { |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 282 | QuicPublicResetPacket() {} |
| 283 | explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header) |
| 284 | : public_header(header) {} |
| 285 | QuicPacketPublicHeader public_header; |
| 286 | QuicPacketSequenceNumber rejected_sequence_number; |
| 287 | QuicPublicResetNonceProof nonce_proof; |
| 288 | }; |
| 289 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 290 | enum QuicVersionNegotiationState { |
| 291 | START_NEGOTIATION = 0, |
| 292 | SENT_NEGOTIATION_PACKET, |
| 293 | NEGOTIATED_VERSION |
| 294 | }; |
| 295 | |
| 296 | typedef QuicPacketPublicHeader QuicVersionNegotiationPacket; |
| 297 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 298 | // A padding frame contains no payload. |
| 299 | struct NET_EXPORT_PRIVATE QuicPaddingFrame { |
| 300 | }; |
| 301 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 302 | struct NET_EXPORT_PRIVATE QuicStreamFrame { |
| 303 | QuicStreamFrame(); |
| 304 | QuicStreamFrame(QuicStreamId stream_id, |
[email protected] | a506124 | 2012-10-23 23:29:37 | [diff] [blame] | 305 | bool fin, |
[email protected] | 701bc89 | 2013-01-17 04:51:54 | [diff] [blame] | 306 | QuicStreamOffset offset, |
[email protected] | a506124 | 2012-10-23 23:29:37 | [diff] [blame] | 307 | base::StringPiece data); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 308 | |
| 309 | QuicStreamId stream_id; |
| 310 | bool fin; |
[email protected] | 701bc89 | 2013-01-17 04:51:54 | [diff] [blame] | 311 | QuicStreamOffset offset; // Location of this data in the stream. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 312 | base::StringPiece data; |
| 313 | }; |
| 314 | |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 315 | // TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing |
| 316 | // is finalized. |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 317 | typedef std::set<QuicPacketSequenceNumber> SequenceNumberSet; |
[email protected] | 3c5f4a73 | 2013-01-12 16:45:34 | [diff] [blame] | 318 | // TODO(pwestin): Add a way to enforce the max size of this map. |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 319 | typedef std::map<QuicPacketSequenceNumber, QuicTime> TimeMap; |
[email protected] | 044ac2b | 2012-11-13 21:41:06 | [diff] [blame] | 320 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 321 | struct NET_EXPORT_PRIVATE ReceivedPacketInfo { |
| 322 | ReceivedPacketInfo(); |
| 323 | ~ReceivedPacketInfo(); |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 324 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 325 | std::ostream& os, const ReceivedPacketInfo& s); |
[email protected] | a674b4c | 2012-12-05 03:44:30 | [diff] [blame] | 326 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 327 | // Entropy hash of all packets up to largest observed not including missing |
| 328 | // packets. |
| 329 | QuicPacketEntropyHash entropy_hash; |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 330 | |
[email protected] | 48697d8a | 2013-01-15 19:42:24 | [diff] [blame] | 331 | // The highest packet sequence number we've observed from the peer. |
| 332 | // |
| 333 | // In general, this should be the largest packet number we've received. In |
| 334 | // the case of truncated acks, we may have to advertise a lower "upper bound" |
| 335 | // than largest received, to avoid implicitly acking missing packets that |
| 336 | // don't fit in the missing packet list due to size limitations. In this |
| 337 | // case, largest_observed may be a packet which is also in the missing packets |
| 338 | // list. |
| 339 | QuicPacketSequenceNumber largest_observed; |
[email protected] | a674b4c | 2012-12-05 03:44:30 | [diff] [blame] | 340 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 341 | // Time elapsed since largest_observed was received until this Ack frame was |
| 342 | // sent. |
| 343 | QuicTime::Delta delta_time_largest_observed; |
| 344 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 345 | // TODO(satyamshekhar): Can be optimized using an interval set like data |
| 346 | // structure. |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 347 | // The set of packets which we're expecting and have not received. |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 348 | SequenceNumberSet missing_packets; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 349 | }; |
| 350 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 351 | // True if the sequence number is greater than largest_observed or is listed |
| 352 | // as missing. |
| 353 | // Always returns false for sequence numbers less than least_unacked. |
| 354 | bool NET_EXPORT_PRIVATE IsAwaitingPacket( |
| 355 | const ReceivedPacketInfo& received_info, |
| 356 | QuicPacketSequenceNumber sequence_number); |
| 357 | |
| 358 | // Inserts missing packets between [lower, higher). |
| 359 | void NET_EXPORT_PRIVATE InsertMissingPacketsBetween( |
| 360 | ReceivedPacketInfo* received_info, |
| 361 | QuicPacketSequenceNumber lower, |
| 362 | QuicPacketSequenceNumber higher); |
| 363 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 364 | struct NET_EXPORT_PRIVATE SentPacketInfo { |
| 365 | SentPacketInfo(); |
| 366 | ~SentPacketInfo(); |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 367 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 368 | std::ostream& os, const SentPacketInfo& s); |
| 369 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 370 | // Entropy hash of all packets up to, but not including, the least unacked |
| 371 | // packet. |
| 372 | QuicPacketEntropyHash entropy_hash; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 373 | // The lowest packet we've sent which is unacked, and we expect an ack for. |
| 374 | QuicPacketSequenceNumber least_unacked; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 375 | }; |
| 376 | |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 377 | struct NET_EXPORT_PRIVATE QuicAckFrame { |
| 378 | QuicAckFrame() {} |
| 379 | // Testing convenience method to construct a QuicAckFrame with all packets |
[email protected] | 48697d8a | 2013-01-15 19:42:24 | [diff] [blame] | 380 | // from least_unacked to largest_observed acked. |
| 381 | QuicAckFrame(QuicPacketSequenceNumber largest_observed, |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 382 | QuicTime largest_observed_receive_time, |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 383 | QuicPacketSequenceNumber least_unacked); |
| 384 | |
| 385 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 386 | std::ostream& os, const QuicAckFrame& s); |
| 387 | |
| 388 | SentPacketInfo sent_info; |
| 389 | ReceivedPacketInfo received_info; |
| 390 | }; |
| 391 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 392 | // Defines for all types of congestion feedback that will be negotiated in QUIC, |
| 393 | // kTCP MUST be supported by all QUIC implementations to guarentee 100% |
| 394 | // compatibility. |
| 395 | enum CongestionFeedbackType { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 396 | kTCP, // Used to mimic TCP. |
| 397 | kInterArrival, // Use additional inter arrival information. |
| 398 | kFixRate, // Provided for testing. |
| 399 | }; |
| 400 | |
| 401 | struct NET_EXPORT_PRIVATE CongestionFeedbackMessageTCP { |
| 402 | uint16 accumulated_number_of_lost_packets; |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 403 | QuicByteCount receive_window; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 404 | }; |
| 405 | |
| 406 | struct NET_EXPORT_PRIVATE CongestionFeedbackMessageInterArrival { |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 407 | CongestionFeedbackMessageInterArrival(); |
| 408 | ~CongestionFeedbackMessageInterArrival(); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 409 | uint16 accumulated_number_of_lost_packets; |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 410 | // The set of received packets since the last feedback was sent, along with |
| 411 | // their arrival times. |
| 412 | TimeMap received_packet_times; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 413 | }; |
| 414 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 415 | struct NET_EXPORT_PRIVATE CongestionFeedbackMessageFixRate { |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 416 | CongestionFeedbackMessageFixRate(); |
| 417 | QuicBandwidth bitrate; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 418 | }; |
| 419 | |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 420 | struct NET_EXPORT_PRIVATE QuicCongestionFeedbackFrame { |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 421 | QuicCongestionFeedbackFrame(); |
| 422 | ~QuicCongestionFeedbackFrame(); |
| 423 | |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 424 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 425 | std::ostream& os, const QuicCongestionFeedbackFrame& c); |
| 426 | |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 427 | CongestionFeedbackType type; |
| 428 | // This should really be a union, but since the inter arrival struct |
| 429 | // is non-trivial, C++ prohibits it. |
| 430 | CongestionFeedbackMessageTCP tcp; |
| 431 | CongestionFeedbackMessageInterArrival inter_arrival; |
| 432 | CongestionFeedbackMessageFixRate fix_rate; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 433 | }; |
| 434 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 435 | struct NET_EXPORT_PRIVATE QuicRstStreamFrame { |
| 436 | QuicRstStreamFrame() {} |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 437 | QuicRstStreamFrame(QuicStreamId stream_id, QuicRstStreamErrorCode error_code) |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 438 | : stream_id(stream_id), error_code(error_code) { |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 439 | DCHECK_LE(error_code, std::numeric_limits<uint8>::max()); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | QuicStreamId stream_id; |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 443 | QuicRstStreamErrorCode error_code; |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 444 | std::string error_details; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 445 | }; |
| 446 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 447 | struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame { |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 448 | QuicErrorCode error_code; |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 449 | std::string error_details; |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 450 | QuicAckFrame ack_frame; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 451 | }; |
| 452 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 453 | struct NET_EXPORT_PRIVATE QuicGoAwayFrame { |
| 454 | QuicGoAwayFrame() {} |
| 455 | QuicGoAwayFrame(QuicErrorCode error_code, |
| 456 | QuicStreamId last_good_stream_id, |
| 457 | const std::string& reason); |
| 458 | |
| 459 | QuicErrorCode error_code; |
| 460 | QuicStreamId last_good_stream_id; |
| 461 | std::string reason_phrase; |
| 462 | }; |
| 463 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 464 | struct NET_EXPORT_PRIVATE QuicFrame { |
| 465 | QuicFrame() {} |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 466 | explicit QuicFrame(QuicPaddingFrame* padding_frame) |
| 467 | : type(PADDING_FRAME), |
| 468 | padding_frame(padding_frame) { |
| 469 | } |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 470 | explicit QuicFrame(QuicStreamFrame* stream_frame) |
[email protected] | 610a7e94 | 2012-12-18 00:21:39 | [diff] [blame] | 471 | : type(STREAM_FRAME), |
| 472 | stream_frame(stream_frame) { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 473 | } |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 474 | explicit QuicFrame(QuicAckFrame* frame) |
[email protected] | 610a7e94 | 2012-12-18 00:21:39 | [diff] [blame] | 475 | : type(ACK_FRAME), |
| 476 | ack_frame(frame) { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 477 | } |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 478 | explicit QuicFrame(QuicCongestionFeedbackFrame* frame) |
[email protected] | 610a7e94 | 2012-12-18 00:21:39 | [diff] [blame] | 479 | : type(CONGESTION_FEEDBACK_FRAME), |
| 480 | congestion_feedback_frame(frame) { |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 481 | } |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 482 | explicit QuicFrame(QuicRstStreamFrame* frame) |
| 483 | : type(RST_STREAM_FRAME), |
| 484 | rst_stream_frame(frame) { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 485 | } |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 486 | explicit QuicFrame(QuicConnectionCloseFrame* frame) |
| 487 | : type(CONNECTION_CLOSE_FRAME), |
| 488 | connection_close_frame(frame) { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 489 | } |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 490 | explicit QuicFrame(QuicGoAwayFrame* frame) |
| 491 | : type(GOAWAY_FRAME), |
| 492 | goaway_frame(frame) { |
| 493 | } |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 494 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 495 | QuicFrameType type; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 496 | union { |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 497 | QuicPaddingFrame* padding_frame; |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 498 | QuicStreamFrame* stream_frame; |
| 499 | QuicAckFrame* ack_frame; |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 500 | QuicCongestionFeedbackFrame* congestion_feedback_frame; |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 501 | QuicRstStreamFrame* rst_stream_frame; |
| 502 | QuicConnectionCloseFrame* connection_close_frame; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 503 | QuicGoAwayFrame* goaway_frame; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 504 | }; |
| 505 | }; |
| 506 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 507 | typedef std::vector<QuicFrame> QuicFrames; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 508 | |
| 509 | struct NET_EXPORT_PRIVATE QuicFecData { |
| 510 | QuicFecData(); |
[email protected] | a506124 | 2012-10-23 23:29:37 | [diff] [blame] | 511 | |
| 512 | bool operator==(const QuicFecData& other) const; |
| 513 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 514 | // The FEC group number is also the sequence number of the first |
| 515 | // FEC protected packet. The last protected packet's sequence number will |
| 516 | // be one less than the sequence number of the FEC packet. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 517 | QuicFecGroupNumber fec_group; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 518 | base::StringPiece redundancy; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 519 | }; |
| 520 | |
| 521 | struct NET_EXPORT_PRIVATE QuicPacketData { |
| 522 | std::string data; |
| 523 | }; |
| 524 | |
| 525 | class NET_EXPORT_PRIVATE QuicData { |
| 526 | public: |
| 527 | QuicData(const char* buffer, size_t length) |
| 528 | : buffer_(buffer), |
| 529 | length_(length), |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 530 | owns_buffer_(false) {} |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 531 | |
| 532 | QuicData(char* buffer, size_t length, bool owns_buffer) |
| 533 | : buffer_(buffer), |
| 534 | length_(length), |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 535 | owns_buffer_(owns_buffer) {} |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 536 | |
| 537 | virtual ~QuicData(); |
| 538 | |
| 539 | base::StringPiece AsStringPiece() const { |
| 540 | return base::StringPiece(data(), length()); |
| 541 | } |
| 542 | |
| 543 | const char* data() const { return buffer_; } |
| 544 | size_t length() const { return length_; } |
| 545 | |
| 546 | private: |
| 547 | const char* buffer_; |
| 548 | size_t length_; |
| 549 | bool owns_buffer_; |
| 550 | |
| 551 | DISALLOW_COPY_AND_ASSIGN(QuicData); |
| 552 | }; |
| 553 | |
| 554 | class NET_EXPORT_PRIVATE QuicPacket : public QuicData { |
| 555 | public: |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 556 | static QuicPacket* NewDataPacket(char* buffer, |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 557 | size_t length, |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 558 | bool owns_buffer, |
| 559 | bool includes_version) { |
| 560 | return new QuicPacket(buffer, length, owns_buffer, includes_version, false); |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | static QuicPacket* NewFecPacket(char* buffer, |
| 564 | size_t length, |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 565 | bool owns_buffer, |
| 566 | bool includes_version) { |
| 567 | return new QuicPacket(buffer, length, owns_buffer, includes_version, true); |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 568 | } |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 569 | |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 570 | base::StringPiece FecProtectedData() const; |
| 571 | base::StringPiece AssociatedData() const; |
| 572 | base::StringPiece BeforePlaintext() const; |
| 573 | base::StringPiece Plaintext() const; |
[email protected] | 082b65b | 2012-11-10 19:11:31 | [diff] [blame] | 574 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 575 | bool is_fec_packet() const { return is_fec_packet_; } |
[email protected] | 082b65b | 2012-11-10 19:11:31 | [diff] [blame] | 576 | |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 577 | bool includes_version() const { return includes_version_; } |
| 578 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 579 | char* mutable_data() { return buffer_; } |
| 580 | |
| 581 | private: |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 582 | QuicPacket(char* buffer, |
| 583 | size_t length, |
| 584 | bool owns_buffer, |
| 585 | bool includes_version, |
| 586 | bool is_fec_packet) |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 587 | : QuicData(buffer, length, owns_buffer), |
| 588 | buffer_(buffer), |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 589 | is_fec_packet_(is_fec_packet), |
| 590 | includes_version_(includes_version) {} |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 591 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 592 | char* buffer_; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 593 | const bool is_fec_packet_; |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 594 | const bool includes_version_; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 595 | |
[email protected] | 2e740db | 2012-10-20 19:35:19 | [diff] [blame] | 596 | DISALLOW_COPY_AND_ASSIGN(QuicPacket); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 597 | }; |
| 598 | |
| 599 | class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData { |
| 600 | public: |
| 601 | QuicEncryptedPacket(const char* buffer, size_t length) |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 602 | : QuicData(buffer, length) {} |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 603 | |
| 604 | QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer) |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 605 | : QuicData(buffer, length, owns_buffer) {} |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 606 | |
[email protected] | c1b32c6 | 2013-01-20 02:49:10 | [diff] [blame] | 607 | // By default, gtest prints the raw bytes of an object. The bool data |
| 608 | // member (in the base class QuicData) causes this object to have padding |
| 609 | // bytes, which causes the default gtest object printer to read |
| 610 | // uninitialize memory. So we need to teach gtest how to print this object. |
| 611 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 612 | std::ostream& os, const QuicEncryptedPacket& s); |
| 613 | |
[email protected] | 2e740db | 2012-10-20 19:35:19 | [diff] [blame] | 614 | private: |
| 615 | DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 616 | }; |
| 617 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 618 | class NET_EXPORT_PRIVATE RetransmittableFrames { |
| 619 | public: |
| 620 | RetransmittableFrames(); |
| 621 | ~RetransmittableFrames(); |
| 622 | |
| 623 | // Allocates a local copy of the referenced StringPiece has QuicStreamFrame |
| 624 | // use it. |
| 625 | // Takes ownership of |stream_frame|. |
| 626 | const QuicFrame& AddStreamFrame(QuicStreamFrame* stream_frame); |
| 627 | // Takes ownership of the frame inside |frame|. |
| 628 | const QuicFrame& AddNonStreamFrame(const QuicFrame& frame); |
| 629 | const QuicFrames& frames() const { return frames_; } |
| 630 | |
| 631 | private: |
| 632 | QuicFrames frames_; |
| 633 | // Data referenced by the StringPiece of a QuicStreamFrame. |
| 634 | std::vector<std::string*> stream_data_; |
| 635 | |
| 636 | DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames); |
| 637 | }; |
| 638 | |
| 639 | struct NET_EXPORT_PRIVATE SerializedPacket { |
| 640 | SerializedPacket(QuicPacketSequenceNumber sequence_number, |
| 641 | QuicPacket* packet, |
| 642 | QuicPacketEntropyHash entropy_hash, |
| 643 | RetransmittableFrames* retransmittable_frames) |
| 644 | : sequence_number(sequence_number), |
| 645 | packet(packet), |
| 646 | entropy_hash(entropy_hash), |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 647 | retransmittable_frames(retransmittable_frames) {} |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 648 | |
| 649 | QuicPacketSequenceNumber sequence_number; |
| 650 | QuicPacket* packet; |
| 651 | QuicPacketEntropyHash entropy_hash; |
| 652 | RetransmittableFrames* retransmittable_frames; |
| 653 | }; |
| 654 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 655 | // A struct for functions which consume data payloads and fins. |
| 656 | // The first member of the pair indicates bytes consumed. |
| 657 | // The second member of the pair indicates if an incoming fin was consumed. |
| 658 | struct QuicConsumedData { |
| 659 | QuicConsumedData(size_t bytes_consumed, bool fin_consumed) |
| 660 | : bytes_consumed(bytes_consumed), |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 661 | fin_consumed(fin_consumed) {} |
[email protected] | c1b32c6 | 2013-01-20 02:49:10 | [diff] [blame] | 662 | |
| 663 | // By default, gtest prints the raw bytes of an object. The bool data |
| 664 | // member causes this object to have padding bytes, which causes the |
| 665 | // default gtest object printer to read uninitialize memory. So we need |
| 666 | // to teach gtest how to print this object. |
| 667 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 668 | std::ostream& os, const QuicConsumedData& s); |
| 669 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 670 | size_t bytes_consumed; |
| 671 | bool fin_consumed; |
| 672 | }; |
| 673 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 674 | } // namespace net |
| 675 | |
| 676 | #endif // NET_QUIC_QUIC_PROTOCOL_H_ |