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