[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" |
[email protected] | 14c1c23 | 2013-06-11 17:52:44 | [diff] [blame] | 18 | #include "base/containers/hash_tables.h" |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 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] | 97cf302 | 2013-09-05 14:30:16 | [diff] [blame] | 30 | class QuicAckNotifier; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 31 | class QuicPacket; |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 32 | struct QuicPacketHeader; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 33 | |
| 34 | typedef uint64 QuicGuid; |
| 35 | typedef uint32 QuicStreamId; |
| 36 | typedef uint64 QuicStreamOffset; |
| 37 | typedef uint64 QuicPacketSequenceNumber; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 38 | typedef QuicPacketSequenceNumber QuicFecGroupNumber; |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 39 | typedef uint64 QuicPublicResetNonceProof; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 40 | typedef uint8 QuicPacketEntropyHash; |
[email protected] | c244c5a1 | 2013-05-07 20:55:04 | [diff] [blame] | 41 | typedef uint32 QuicHeaderId; |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 42 | // QuicTag is the type of a tag in the wire protocol. |
| 43 | typedef uint32 QuicTag; |
| 44 | typedef std::vector<QuicTag> QuicTagVector; |
[email protected] | 8edeb8d | 2013-08-28 06:11:43 | [diff] [blame] | 45 | typedef uint32 QuicPriority; |
[email protected] | cff7b7b | 2013-01-11 08:49:07 | [diff] [blame] | 46 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 47 | // TODO(rch): Consider Quic specific names for these constants. |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 48 | // Maximum size in bytes of a QUIC packet. |
| 49 | const QuicByteCount kMaxPacketSize = 1200; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 50 | |
| 51 | // Maximum number of open streams per connection. |
| 52 | const size_t kDefaultMaxStreamsPerConnection = 100; |
| 53 | |
[email protected] | af806e6 | 2013-05-22 14:47:50 | [diff] [blame] | 54 | // Number of bytes reserved for public flags in the packet header. |
| 55 | const size_t kPublicFlagsSize = 1; |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 56 | // Number of bytes reserved for version number in the packet header. |
| 57 | const size_t kQuicVersionSize = 4; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 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] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 68 | // Index of the first byte in a QUIC packet which is used in hash calculation. |
| 69 | const size_t kStartOfHashData = 0; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 70 | |
| 71 | // Limit on the delta between stream IDs. |
| 72 | const QuicStreamId kMaxStreamIdDelta = 100; |
[email protected] | c244c5a1 | 2013-05-07 20:55:04 | [diff] [blame] | 73 | // Limit on the delta between header IDs. |
| 74 | const QuicHeaderId kMaxHeaderIdDelta = 100; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 75 | |
| 76 | // Reserved ID for the crypto stream. |
| 77 | // TODO(rch): ensure that this is not usable by any other streams. |
| 78 | const QuicStreamId kCryptoStreamId = 1; |
| 79 | |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 80 | // This is the default network timeout a for connection till the crypto |
| 81 | // handshake succeeds and the negotiated timeout from the handshake is received. |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 82 | const int64 kDefaultInitialTimeoutSecs = 120; // 2 mins. |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 83 | const int64 kDefaultTimeoutSecs = 60 * 10; // 10 minutes. |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 84 | const int64 kDefaultMaxTimeForCryptoHandshakeSecs = 5; // 5 secs. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 85 | |
[email protected] | b007e63 | 2013-10-28 08:39:25 | [diff] [blame^] | 86 | // We define an unsigned 16-bit floating point value, inspired by IEEE floats |
| 87 | // (http://en.wikipedia.org/wiki/Half_precision_floating-point_format), |
| 88 | // with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden |
| 89 | // bit) and denormals, but without signs, transfinites or fractions. Wire format |
| 90 | // 16 bits (little-endian byte order) are split into exponent (high 5) and |
| 91 | // mantissa (low 11) and decoded as: |
| 92 | // uint64 value; |
| 93 | // if (exponent == 0) value = mantissa; |
| 94 | // else value = (mantissa | 1 << 11) << (exponent - 1) |
| 95 | const int kUFloat16ExponentBits = 5; |
| 96 | const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30 |
| 97 | const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11 |
| 98 | const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12 |
| 99 | const uint64 kUFloat16MaxValue = // 0x3FFC0000000 |
| 100 | ((GG_UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1) << |
| 101 | kUFloat16MaxExponent; |
| 102 | |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 103 | enum TransmissionType { |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 104 | NOT_RETRANSMISSION, |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 105 | NACK_RETRANSMISSION, |
| 106 | RTO_RETRANSMISSION, |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | enum HasRetransmittableData { |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 110 | NO_RETRANSMITTABLE_DATA, |
| 111 | HAS_RETRANSMITTABLE_DATA, |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 112 | }; |
| 113 | |
[email protected] | 575cce6 | 2013-08-03 02:06:43 | [diff] [blame] | 114 | enum IsHandshake { |
| 115 | NOT_HANDSHAKE, |
| 116 | IS_HANDSHAKE |
| 117 | }; |
| 118 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 119 | enum QuicFrameType { |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 120 | PADDING_FRAME = 0, |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 121 | RST_STREAM_FRAME, |
| 122 | CONNECTION_CLOSE_FRAME, |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 123 | GOAWAY_FRAME, |
[email protected] | 97cf302 | 2013-09-05 14:30:16 | [diff] [blame] | 124 | STREAM_FRAME, |
| 125 | ACK_FRAME, |
| 126 | CONGESTION_FEEDBACK_FRAME, |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 127 | NUM_FRAME_TYPES |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 128 | }; |
| 129 | |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 130 | enum QuicGuidLength { |
| 131 | PACKET_0BYTE_GUID = 0, |
| 132 | PACKET_1BYTE_GUID = 1, |
| 133 | PACKET_4BYTE_GUID = 4, |
| 134 | PACKET_8BYTE_GUID = 8 |
| 135 | }; |
| 136 | |
| 137 | enum InFecGroup { |
| 138 | NOT_IN_FEC_GROUP, |
| 139 | IN_FEC_GROUP, |
| 140 | }; |
| 141 | |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 142 | enum QuicSequenceNumberLength { |
| 143 | PACKET_1BYTE_SEQUENCE_NUMBER = 1, |
| 144 | PACKET_2BYTE_SEQUENCE_NUMBER = 2, |
| 145 | PACKET_4BYTE_SEQUENCE_NUMBER = 4, |
| 146 | PACKET_6BYTE_SEQUENCE_NUMBER = 6 |
| 147 | }; |
| 148 | |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame] | 149 | // The public flags are specified in one byte. |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 150 | enum QuicPacketPublicFlags { |
| 151 | PACKET_PUBLIC_FLAGS_NONE = 0, |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame] | 152 | |
| 153 | // Bit 0: Does the packet header contains version info? |
| 154 | PACKET_PUBLIC_FLAGS_VERSION = 1 << 0, |
| 155 | |
| 156 | // Bit 1: Is this packet a public reset packet? |
| 157 | PACKET_PUBLIC_FLAGS_RST = 1 << 1, |
| 158 | |
| 159 | // Bits 2 and 3 specify the length of the GUID as follows: |
| 160 | // ----00--: 0 bytes |
| 161 | // ----01--: 1 byte |
| 162 | // ----10--: 4 bytes |
| 163 | // ----11--: 8 bytes |
[email protected] | 1354bf6 | 2013-05-23 23:17:18 | [diff] [blame] | 164 | PACKET_PUBLIC_FLAGS_0BYTE_GUID = 0, |
| 165 | PACKET_PUBLIC_FLAGS_1BYTE_GUID = 1 << 2, |
| 166 | PACKET_PUBLIC_FLAGS_4BYTE_GUID = 1 << 3, |
| 167 | PACKET_PUBLIC_FLAGS_8BYTE_GUID = 1 << 3 | 1 << 2, |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame] | 168 | |
| 169 | // Bits 4 and 5 describe the packet sequence number length as follows: |
| 170 | // --00----: 1 byte |
| 171 | // --01----: 2 bytes |
| 172 | // --10----: 4 bytes |
| 173 | // --11----: 6 bytes |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 174 | PACKET_PUBLIC_FLAGS_1BYTE_SEQUENCE = 0, |
| 175 | PACKET_PUBLIC_FLAGS_2BYTE_SEQUENCE = 1 << 4, |
| 176 | PACKET_PUBLIC_FLAGS_4BYTE_SEQUENCE = 1 << 5, |
| 177 | PACKET_PUBLIC_FLAGS_6BYTE_SEQUENCE = 1 << 5 | 1 << 4, |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame] | 178 | |
| 179 | // All bits set (bits 6 and 7 are not currently used): 00111111 |
| 180 | PACKET_PUBLIC_FLAGS_MAX = (1 << 6) - 1 |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 181 | }; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 182 | |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame] | 183 | // The private flags are specified in one byte. |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 184 | enum QuicPacketPrivateFlags { |
| 185 | PACKET_PRIVATE_FLAGS_NONE = 0, |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame] | 186 | |
| 187 | // Bit 0: Does this packet contain an entropy bit? |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 188 | PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0, |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame] | 189 | |
| 190 | // Bit 1: Payload is part of an FEC group? |
| 191 | PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1, |
| 192 | |
| 193 | // Bit 2: Payload is FEC as opposed to frames? |
| 194 | PACKET_PRIVATE_FLAGS_FEC = 1 << 2, |
| 195 | |
| 196 | // All bits set (bits 3-7 are not currently used): 00000111 |
| 197 | PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1 |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 198 | }; |
| 199 | |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 200 | // The available versions of QUIC. Guaranteed that the integer value of the enum |
| 201 | // will match the version number. |
| 202 | // When adding a new version to this enum you should add it to |
[email protected] | 8bbfaeb7 | 2013-08-09 06:38:26 | [diff] [blame] | 203 | // kSupportedQuicVersions (if appropriate), and also add a new case to the |
| 204 | // helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and |
| 205 | // QuicVersionToString. |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 206 | enum QuicVersion { |
| 207 | // Special case to indicate unknown/unsupported QUIC version. |
| 208 | QUIC_VERSION_UNSUPPORTED = 0, |
| 209 | |
[email protected] | 752fbe5 | 2013-10-14 08:35:32 | [diff] [blame] | 210 | QUIC_VERSION_10 = 10, |
| 211 | QUIC_VERSION_11 = 11, // Current version. |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 212 | }; |
| 213 | |
| 214 | // This vector contains QUIC versions which we currently support. |
| 215 | // This should be ordered such that the highest supported version is the first |
| 216 | // element, with subsequent elements in descending order (versions can be |
| 217 | // skipped as necessary). |
[email protected] | 3e60db8 | 2013-08-05 19:43:06 | [diff] [blame] | 218 | static const QuicVersion kSupportedQuicVersions[] = |
[email protected] | 8f547ea | 2013-10-24 05:55:04 | [diff] [blame] | 219 | {QUIC_VERSION_10}; |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 220 | |
| 221 | typedef std::vector<QuicVersion> QuicVersionVector; |
| 222 | |
[email protected] | b007e63 | 2013-10-28 08:39:25 | [diff] [blame^] | 223 | // Returns a vector of QUIC versions in kSupportedQuicVersions. |
| 224 | NET_EXPORT_PRIVATE QuicVersionVector QuicSupportedVersions(); |
[email protected] | ea2ab47b | 2013-08-13 00:44:11 | [diff] [blame] | 225 | |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 226 | // QuicTag is written to and read from the wire, but we prefer to use |
| 227 | // the more readable QuicVersion at other levels. |
| 228 | // Helper function which translates from a QuicVersion to a QuicTag. Returns 0 |
| 229 | // if QuicVersion is unsupported. |
| 230 | NET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version); |
| 231 | |
| 232 | // Returns appropriate QuicVersion from a QuicTag. |
| 233 | // Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood. |
| 234 | NET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag); |
| 235 | |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 236 | // Helper function which translates from a QuicVersion to a string. |
| 237 | // Returns strings corresponding to enum names (e.g. QUIC_VERSION_6). |
| 238 | NET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version); |
| 239 | |
| 240 | // Returns comma separated list of string representations of QuicVersion enum |
[email protected] | b007e63 | 2013-10-28 08:39:25 | [diff] [blame^] | 241 | // values in the supplied |versions| vector. |
| 242 | NET_EXPORT_PRIVATE std::string QuicVersionVectorToString( |
| 243 | const QuicVersionVector& versions); |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 244 | |
| 245 | // Version and Crypto tags are written to the wire with a big-endian |
| 246 | // representation of the name of the tag. For example |
| 247 | // the client hello tag (CHLO) will be written as the |
| 248 | // following 4 bytes: 'C' 'H' 'L' 'O'. Since it is |
| 249 | // stored in memory as a little endian uint32, we need |
| 250 | // to reverse the order of the bytes. |
| 251 | |
| 252 | // MakeQuicTag returns a value given the four bytes. For example: |
| 253 | // MakeQuicTag('C', 'H', 'L', 'O'); |
| 254 | NET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d); |
| 255 | |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 256 | // Size in bytes of the data or fec packet header. |
| 257 | NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicPacketHeader header); |
| 258 | |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 259 | NET_EXPORT_PRIVATE size_t GetPacketHeaderSize( |
| 260 | QuicGuidLength guid_length, |
| 261 | bool include_version, |
| 262 | QuicSequenceNumberLength sequence_number_length, |
| 263 | InFecGroup is_in_fec_group); |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 264 | |
| 265 | // Size in bytes of the public reset packet. |
| 266 | NET_EXPORT_PRIVATE size_t GetPublicResetPacketSize(); |
| 267 | |
| 268 | // Index of the first byte in a QUIC packet of FEC protected data. |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 269 | NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData( |
| 270 | QuicGuidLength guid_length, |
| 271 | bool include_version, |
| 272 | QuicSequenceNumberLength sequence_number_length); |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 273 | // Index of the first byte in a QUIC packet of encrypted data. |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 274 | NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData( |
| 275 | QuicGuidLength guid_length, |
| 276 | bool include_version, |
| 277 | QuicSequenceNumberLength sequence_number_length); |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 278 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 279 | enum QuicRstStreamErrorCode { |
| 280 | QUIC_STREAM_NO_ERROR = 0, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 281 | |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 282 | // There was some error which halted stream processing. |
| 283 | QUIC_ERROR_PROCESSING_STREAM, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 284 | // We got two fin or reset offsets which did not match. |
| 285 | QUIC_MULTIPLE_TERMINATION_OFFSETS, |
| 286 | // We got bad payload and can not respond to it at the protocol level. |
| 287 | QUIC_BAD_APPLICATION_PAYLOAD, |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 288 | // Stream closed due to connection error. No reset frame is sent when this |
| 289 | // happens. |
| 290 | QUIC_STREAM_CONNECTION_ERROR, |
| 291 | // GoAway frame sent. No more stream can be created. |
| 292 | QUIC_STREAM_PEER_GOING_AWAY, |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 293 | // The stream has been cancelled. |
| 294 | QUIC_STREAM_CANCELLED, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 295 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 296 | // No error. Used as bound while iterating. |
| 297 | QUIC_STREAM_LAST_ERROR, |
| 298 | }; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 299 | |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 300 | // These values must remain stable as they are uploaded to UMA histograms. |
| 301 | // To add a new error code, use the current value of QUIC_LAST_ERROR and |
| 302 | // increment QUIC_LAST_ERROR. |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 303 | enum QuicErrorCode { |
| 304 | QUIC_NO_ERROR = 0, |
| 305 | |
| 306 | // Connection has reached an invalid state. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 307 | QUIC_INTERNAL_ERROR = 1, |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 308 | // There were data frames after the a fin or reset. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 309 | QUIC_STREAM_DATA_AFTER_TERMINATION = 2, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 310 | // Control frame is malformed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 311 | QUIC_INVALID_PACKET_HEADER = 3, |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 312 | // Frame data is malformed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 313 | QUIC_INVALID_FRAME_DATA = 4, |
| 314 | // The packet contained no payload. |
| 315 | QUIC_MISSING_PAYLOAD = 48, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 316 | // FEC data is malformed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 317 | QUIC_INVALID_FEC_DATA = 5, |
| 318 | // STREAM frame data is malformed. |
| 319 | QUIC_INVALID_STREAM_DATA = 46, |
| 320 | // RST_STREAM frame data is malformed. |
| 321 | QUIC_INVALID_RST_STREAM_DATA = 6, |
| 322 | // CONNECTION_CLOSE frame data is malformed. |
| 323 | QUIC_INVALID_CONNECTION_CLOSE_DATA = 7, |
| 324 | // GOAWAY frame data is malformed. |
| 325 | QUIC_INVALID_GOAWAY_DATA = 8, |
| 326 | // ACK frame data is malformed. |
| 327 | QUIC_INVALID_ACK_DATA = 9, |
| 328 | // CONGESTION_FEEDBACK frame data is malformed. |
| 329 | QUIC_INVALID_CONGESTION_FEEDBACK_DATA = 47, |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 330 | // Version negotiation packet is malformed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 331 | QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10, |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 332 | // Public RST packet is malformed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 333 | QUIC_INVALID_PUBLIC_RST_PACKET = 11, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 334 | // There was an error decrypting. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 335 | QUIC_DECRYPTION_FAILURE = 12, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 336 | // There was an error encrypting. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 337 | QUIC_ENCRYPTION_FAILURE = 13, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 338 | // The packet exceeded kMaxPacketSize. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 339 | QUIC_PACKET_TOO_LARGE = 14, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 340 | // Data was sent for a stream which did not exist. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 341 | QUIC_PACKET_FOR_NONEXISTENT_STREAM = 15, |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 342 | // The peer is going away. May be a client or server. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 343 | QUIC_PEER_GOING_AWAY = 16, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 344 | // A stream ID was invalid. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 345 | QUIC_INVALID_STREAM_ID = 17, |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 346 | // A priority was invalid. |
| 347 | QUIC_INVALID_PRIORITY = 49, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 348 | // Too many streams already open. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 349 | QUIC_TOO_MANY_OPEN_STREAMS = 18, |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 350 | // Received public reset for this connection. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 351 | QUIC_PUBLIC_RESET = 19, |
[email protected] | c244c5a1 | 2013-05-07 20:55:04 | [diff] [blame] | 352 | // Invalid protocol version. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 353 | QUIC_INVALID_VERSION = 20, |
[email protected] | c244c5a1 | 2013-05-07 20:55:04 | [diff] [blame] | 354 | // Stream reset before headers decompressed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 355 | QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED = 21, |
[email protected] | c244c5a1 | 2013-05-07 20:55:04 | [diff] [blame] | 356 | // The Header ID for a stream was too far from the previous. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 357 | QUIC_INVALID_HEADER_ID = 22, |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 358 | // Negotiable parameter received during handshake had invalid value. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 359 | QUIC_INVALID_NEGOTIATED_VALUE = 23, |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 360 | // There was an error decompressing data. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 361 | QUIC_DECOMPRESSION_FAILURE = 24, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 362 | // We hit our prenegotiated (or default) timeout |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 363 | QUIC_CONNECTION_TIMED_OUT = 25, |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 364 | // There was an error encountered migrating addresses |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 365 | QUIC_ERROR_MIGRATING_ADDRESS = 26, |
[email protected] | 1505a51 | 2013-09-04 22:59:35 | [diff] [blame] | 366 | // There was an error while writing to the socket. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 367 | QUIC_PACKET_WRITE_ERROR = 27, |
[email protected] | 1505a51 | 2013-09-04 22:59:35 | [diff] [blame] | 368 | // There was an error while reading from the socket. |
| 369 | QUIC_PACKET_READ_ERROR = 51, |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 370 | // We received a STREAM_FRAME with no data and no fin flag set. |
| 371 | QUIC_INVALID_STREAM_FRAME = 50, |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 372 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 373 | |
| 374 | // Crypto errors. |
| 375 | |
[email protected] | 1354bf6 | 2013-05-23 23:17:18 | [diff] [blame] | 376 | // Hanshake failed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 377 | QUIC_HANDSHAKE_FAILED = 28, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 378 | // Handshake message contained out of order tags. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 379 | QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29, |
[email protected] | 701bc89 | 2013-01-17 04:51:54 | [diff] [blame] | 380 | // Handshake message contained too many entries. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 381 | QUIC_CRYPTO_TOO_MANY_ENTRIES = 30, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 382 | // Handshake message contained an invalid value length. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 383 | QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 384 | // A crypto message was received after the handshake was complete. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 385 | QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32, |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 386 | // A crypto message was received with an illegal message tag. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 387 | QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33, |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 388 | // A crypto message was received with an illegal parameter. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 389 | QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34, |
[email protected] | 752fbe5 | 2013-10-14 08:35:32 | [diff] [blame] | 390 | // An invalid channel id signature was supplied. |
| 391 | QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52, |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 392 | // A crypto message was received with a mandatory parameter missing. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 393 | QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35, |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 394 | // A crypto message was received with a parameter that has no overlap |
| 395 | // with the local parameter. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 396 | QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36, |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 397 | // A crypto message was received that contained a parameter with too few |
| 398 | // values. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 399 | QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37, |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 400 | // An internal error occured in crypto processing. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 401 | QUIC_CRYPTO_INTERNAL_ERROR = 38, |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 402 | // A crypto handshake message specified an unsupported version. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 403 | QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39, |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 404 | // There was no intersection between the crypto primitives supported by the |
| 405 | // peer and ourselves. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 406 | QUIC_CRYPTO_NO_SUPPORT = 40, |
[email protected] | ef95114d | 2013-04-17 17:57:01 | [diff] [blame] | 407 | // The server rejected our client hello messages too many times. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 408 | QUIC_CRYPTO_TOO_MANY_REJECTS = 41, |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 409 | // The client rejected the server's certificate chain or signature. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 410 | QUIC_PROOF_INVALID = 42, |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 411 | // A crypto message was received with a duplicate tag. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 412 | QUIC_CRYPTO_DUPLICATE_TAG = 43, |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 413 | // A crypto message was received with the wrong encryption level (i.e. it |
| 414 | // should have been encrypted but was not.) |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 415 | QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44, |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 416 | // The server config for a server has expired. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 417 | QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45, |
[email protected] | 752fbe5 | 2013-10-14 08:35:32 | [diff] [blame] | 418 | // We failed to setup the symmetric keys for a connection. |
| 419 | QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53, |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 420 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 421 | // No error. Used as bound while iterating. |
[email protected] | 752fbe5 | 2013-10-14 08:35:32 | [diff] [blame] | 422 | QUIC_LAST_ERROR = 54, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 423 | }; |
| 424 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 425 | struct NET_EXPORT_PRIVATE QuicPacketPublicHeader { |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 426 | QuicPacketPublicHeader(); |
| 427 | explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other); |
| 428 | ~QuicPacketPublicHeader(); |
| 429 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 430 | // Universal header. All QuicPacket headers will have a guid and public flags. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 431 | QuicGuid guid; |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 432 | QuicGuidLength guid_length; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 433 | bool reset_flag; |
| 434 | bool version_flag; |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 435 | QuicSequenceNumberLength sequence_number_length; |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 436 | QuicVersionVector versions; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 437 | }; |
| 438 | |
| 439 | // Header for Data or FEC packets. |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 440 | struct NET_EXPORT_PRIVATE QuicPacketHeader { |
| 441 | QuicPacketHeader(); |
| 442 | explicit QuicPacketHeader(const QuicPacketPublicHeader& header); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 443 | |
| 444 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 445 | std::ostream& os, const QuicPacketHeader& s); |
| 446 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 447 | QuicPacketPublicHeader public_header; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 448 | bool fec_flag; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 449 | bool entropy_flag; |
| 450 | QuicPacketEntropyHash entropy_hash; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 451 | QuicPacketSequenceNumber packet_sequence_number; |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 452 | InFecGroup is_in_fec_group; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 453 | QuicFecGroupNumber fec_group; |
| 454 | }; |
| 455 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 456 | struct NET_EXPORT_PRIVATE QuicPublicResetPacket { |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 457 | QuicPublicResetPacket() {} |
| 458 | explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header) |
| 459 | : public_header(header) {} |
| 460 | QuicPacketPublicHeader public_header; |
| 461 | QuicPacketSequenceNumber rejected_sequence_number; |
| 462 | QuicPublicResetNonceProof nonce_proof; |
| 463 | }; |
| 464 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 465 | enum QuicVersionNegotiationState { |
| 466 | START_NEGOTIATION = 0, |
[email protected] | ec64011 | 2013-08-09 03:56:18 | [diff] [blame] | 467 | // Server-side this implies we've sent a version negotiation packet and are |
| 468 | // waiting on the client to select a compatible version. Client-side this |
| 469 | // implies we've gotten a version negotiation packet, are retransmitting the |
| 470 | // initial packets with a supported version and are waiting for our first |
| 471 | // packet from the server. |
| 472 | NEGOTIATION_IN_PROGRESS, |
| 473 | // This indicates this endpoint has received a packet from the peer with a |
| 474 | // version this endpoint supports. Version negotiation is complete, and the |
| 475 | // version number will no longer be sent with future packets. |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 476 | NEGOTIATED_VERSION |
| 477 | }; |
| 478 | |
| 479 | typedef QuicPacketPublicHeader QuicVersionNegotiationPacket; |
| 480 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 481 | // A padding frame contains no payload. |
| 482 | struct NET_EXPORT_PRIVATE QuicPaddingFrame { |
| 483 | }; |
| 484 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 485 | struct NET_EXPORT_PRIVATE QuicStreamFrame { |
| 486 | QuicStreamFrame(); |
| 487 | QuicStreamFrame(QuicStreamId stream_id, |
[email protected] | a506124 | 2012-10-23 23:29:37 | [diff] [blame] | 488 | bool fin, |
[email protected] | 701bc89 | 2013-01-17 04:51:54 | [diff] [blame] | 489 | QuicStreamOffset offset, |
[email protected] | a506124 | 2012-10-23 23:29:37 | [diff] [blame] | 490 | base::StringPiece data); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 491 | |
| 492 | QuicStreamId stream_id; |
| 493 | bool fin; |
[email protected] | 701bc89 | 2013-01-17 04:51:54 | [diff] [blame] | 494 | QuicStreamOffset offset; // Location of this data in the stream. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 495 | base::StringPiece data; |
[email protected] | 97cf302 | 2013-09-05 14:30:16 | [diff] [blame] | 496 | |
| 497 | // If this is set, then when this packet is ACKed the AckNotifier will be |
| 498 | // informed. |
| 499 | QuicAckNotifier* notifier; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 500 | }; |
| 501 | |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 502 | // TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing |
| 503 | // is finalized. |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 504 | typedef std::set<QuicPacketSequenceNumber> SequenceNumberSet; |
[email protected] | 3c5f4a73 | 2013-01-12 16:45:34 | [diff] [blame] | 505 | // TODO(pwestin): Add a way to enforce the max size of this map. |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 506 | typedef std::map<QuicPacketSequenceNumber, QuicTime> TimeMap; |
[email protected] | 044ac2b | 2012-11-13 21:41:06 | [diff] [blame] | 507 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 508 | struct NET_EXPORT_PRIVATE ReceivedPacketInfo { |
| 509 | ReceivedPacketInfo(); |
| 510 | ~ReceivedPacketInfo(); |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 511 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 512 | std::ostream& os, const ReceivedPacketInfo& s); |
[email protected] | a674b4c | 2012-12-05 03:44:30 | [diff] [blame] | 513 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 514 | // Entropy hash of all packets up to largest observed not including missing |
| 515 | // packets. |
| 516 | QuicPacketEntropyHash entropy_hash; |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 517 | |
[email protected] | 48697d8a | 2013-01-15 19:42:24 | [diff] [blame] | 518 | // The highest packet sequence number we've observed from the peer. |
| 519 | // |
| 520 | // In general, this should be the largest packet number we've received. In |
| 521 | // the case of truncated acks, we may have to advertise a lower "upper bound" |
| 522 | // than largest received, to avoid implicitly acking missing packets that |
| 523 | // don't fit in the missing packet list due to size limitations. In this |
| 524 | // case, largest_observed may be a packet which is also in the missing packets |
| 525 | // list. |
| 526 | QuicPacketSequenceNumber largest_observed; |
[email protected] | a674b4c | 2012-12-05 03:44:30 | [diff] [blame] | 527 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 528 | // Time elapsed since largest_observed was received until this Ack frame was |
| 529 | // sent. |
| 530 | QuicTime::Delta delta_time_largest_observed; |
| 531 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 532 | // TODO(satyamshekhar): Can be optimized using an interval set like data |
| 533 | // structure. |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 534 | // The set of packets which we're expecting and have not received. |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 535 | SequenceNumberSet missing_packets; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 536 | }; |
| 537 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 538 | // True if the sequence number is greater than largest_observed or is listed |
| 539 | // as missing. |
| 540 | // Always returns false for sequence numbers less than least_unacked. |
| 541 | bool NET_EXPORT_PRIVATE IsAwaitingPacket( |
| 542 | const ReceivedPacketInfo& received_info, |
| 543 | QuicPacketSequenceNumber sequence_number); |
| 544 | |
| 545 | // Inserts missing packets between [lower, higher). |
| 546 | void NET_EXPORT_PRIVATE InsertMissingPacketsBetween( |
| 547 | ReceivedPacketInfo* received_info, |
| 548 | QuicPacketSequenceNumber lower, |
| 549 | QuicPacketSequenceNumber higher); |
| 550 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 551 | struct NET_EXPORT_PRIVATE SentPacketInfo { |
| 552 | SentPacketInfo(); |
| 553 | ~SentPacketInfo(); |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 554 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 555 | std::ostream& os, const SentPacketInfo& s); |
| 556 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 557 | // Entropy hash of all packets up to, but not including, the least unacked |
| 558 | // packet. |
| 559 | QuicPacketEntropyHash entropy_hash; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 560 | // The lowest packet we've sent which is unacked, and we expect an ack for. |
| 561 | QuicPacketSequenceNumber least_unacked; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 562 | }; |
| 563 | |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 564 | struct NET_EXPORT_PRIVATE QuicAckFrame { |
| 565 | QuicAckFrame() {} |
| 566 | // Testing convenience method to construct a QuicAckFrame with all packets |
[email protected] | 48697d8a | 2013-01-15 19:42:24 | [diff] [blame] | 567 | // from least_unacked to largest_observed acked. |
| 568 | QuicAckFrame(QuicPacketSequenceNumber largest_observed, |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 569 | QuicTime largest_observed_receive_time, |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 570 | QuicPacketSequenceNumber least_unacked); |
| 571 | |
| 572 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 573 | std::ostream& os, const QuicAckFrame& s); |
| 574 | |
| 575 | SentPacketInfo sent_info; |
| 576 | ReceivedPacketInfo received_info; |
| 577 | }; |
| 578 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 579 | // Defines for all types of congestion feedback that will be negotiated in QUIC, |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame] | 580 | // kTCP MUST be supported by all QUIC implementations to guarantee 100% |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 581 | // compatibility. |
| 582 | enum CongestionFeedbackType { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 583 | kTCP, // Used to mimic TCP. |
| 584 | kInterArrival, // Use additional inter arrival information. |
| 585 | kFixRate, // Provided for testing. |
| 586 | }; |
| 587 | |
| 588 | struct NET_EXPORT_PRIVATE CongestionFeedbackMessageTCP { |
| 589 | uint16 accumulated_number_of_lost_packets; |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 590 | QuicByteCount receive_window; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 591 | }; |
| 592 | |
| 593 | struct NET_EXPORT_PRIVATE CongestionFeedbackMessageInterArrival { |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 594 | CongestionFeedbackMessageInterArrival(); |
| 595 | ~CongestionFeedbackMessageInterArrival(); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 596 | uint16 accumulated_number_of_lost_packets; |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 597 | // The set of received packets since the last feedback was sent, along with |
| 598 | // their arrival times. |
| 599 | TimeMap received_packet_times; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 600 | }; |
| 601 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 602 | struct NET_EXPORT_PRIVATE CongestionFeedbackMessageFixRate { |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 603 | CongestionFeedbackMessageFixRate(); |
| 604 | QuicBandwidth bitrate; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 605 | }; |
| 606 | |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 607 | struct NET_EXPORT_PRIVATE QuicCongestionFeedbackFrame { |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 608 | QuicCongestionFeedbackFrame(); |
| 609 | ~QuicCongestionFeedbackFrame(); |
| 610 | |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 611 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 612 | std::ostream& os, const QuicCongestionFeedbackFrame& c); |
| 613 | |
[email protected] | 7884ecad | 2012-12-14 22:55:15 | [diff] [blame] | 614 | CongestionFeedbackType type; |
| 615 | // This should really be a union, but since the inter arrival struct |
| 616 | // is non-trivial, C++ prohibits it. |
| 617 | CongestionFeedbackMessageTCP tcp; |
| 618 | CongestionFeedbackMessageInterArrival inter_arrival; |
| 619 | CongestionFeedbackMessageFixRate fix_rate; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 620 | }; |
| 621 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 622 | struct NET_EXPORT_PRIVATE QuicRstStreamFrame { |
| 623 | QuicRstStreamFrame() {} |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 624 | QuicRstStreamFrame(QuicStreamId stream_id, QuicRstStreamErrorCode error_code) |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 625 | : stream_id(stream_id), error_code(error_code) { |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 626 | DCHECK_LE(error_code, std::numeric_limits<uint8>::max()); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | QuicStreamId stream_id; |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 630 | QuicRstStreamErrorCode error_code; |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 631 | std::string error_details; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 632 | }; |
| 633 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 634 | struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame { |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 635 | QuicErrorCode error_code; |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 636 | std::string error_details; |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 637 | QuicAckFrame ack_frame; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 638 | }; |
| 639 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 640 | struct NET_EXPORT_PRIVATE QuicGoAwayFrame { |
| 641 | QuicGoAwayFrame() {} |
| 642 | QuicGoAwayFrame(QuicErrorCode error_code, |
| 643 | QuicStreamId last_good_stream_id, |
| 644 | const std::string& reason); |
| 645 | |
| 646 | QuicErrorCode error_code; |
| 647 | QuicStreamId last_good_stream_id; |
| 648 | std::string reason_phrase; |
| 649 | }; |
| 650 | |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 651 | // EncryptionLevel enumerates the stages of encryption that a QUIC connection |
| 652 | // progresses through. When retransmitting a packet, the encryption level needs |
| 653 | // to be specified so that it is retransmitted at a level which the peer can |
| 654 | // understand. |
| 655 | enum EncryptionLevel { |
| 656 | ENCRYPTION_NONE = 0, |
| 657 | ENCRYPTION_INITIAL = 1, |
| 658 | ENCRYPTION_FORWARD_SECURE = 2, |
| 659 | |
| 660 | NUM_ENCRYPTION_LEVELS, |
| 661 | }; |
| 662 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 663 | struct NET_EXPORT_PRIVATE QuicFrame { |
| 664 | QuicFrame() {} |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 665 | explicit QuicFrame(QuicPaddingFrame* padding_frame) |
| 666 | : type(PADDING_FRAME), |
| 667 | padding_frame(padding_frame) { |
| 668 | } |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 669 | explicit QuicFrame(QuicStreamFrame* stream_frame) |
[email protected] | 610a7e94 | 2012-12-18 00:21:39 | [diff] [blame] | 670 | : type(STREAM_FRAME), |
| 671 | stream_frame(stream_frame) { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 672 | } |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 673 | explicit QuicFrame(QuicAckFrame* frame) |
[email protected] | 610a7e94 | 2012-12-18 00:21:39 | [diff] [blame] | 674 | : type(ACK_FRAME), |
| 675 | ack_frame(frame) { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 676 | } |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 677 | explicit QuicFrame(QuicCongestionFeedbackFrame* frame) |
[email protected] | 610a7e94 | 2012-12-18 00:21:39 | [diff] [blame] | 678 | : type(CONGESTION_FEEDBACK_FRAME), |
| 679 | congestion_feedback_frame(frame) { |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 680 | } |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 681 | explicit QuicFrame(QuicRstStreamFrame* frame) |
| 682 | : type(RST_STREAM_FRAME), |
| 683 | rst_stream_frame(frame) { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 684 | } |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 685 | explicit QuicFrame(QuicConnectionCloseFrame* frame) |
| 686 | : type(CONNECTION_CLOSE_FRAME), |
| 687 | connection_close_frame(frame) { |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 688 | } |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 689 | explicit QuicFrame(QuicGoAwayFrame* frame) |
| 690 | : type(GOAWAY_FRAME), |
| 691 | goaway_frame(frame) { |
| 692 | } |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 693 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 694 | QuicFrameType type; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 695 | union { |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 696 | QuicPaddingFrame* padding_frame; |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 697 | QuicStreamFrame* stream_frame; |
| 698 | QuicAckFrame* ack_frame; |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 699 | QuicCongestionFeedbackFrame* congestion_feedback_frame; |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 700 | QuicRstStreamFrame* rst_stream_frame; |
| 701 | QuicConnectionCloseFrame* connection_close_frame; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 702 | QuicGoAwayFrame* goaway_frame; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 703 | }; |
| 704 | }; |
| 705 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 706 | typedef std::vector<QuicFrame> QuicFrames; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 707 | |
| 708 | struct NET_EXPORT_PRIVATE QuicFecData { |
| 709 | QuicFecData(); |
[email protected] | a506124 | 2012-10-23 23:29:37 | [diff] [blame] | 710 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 711 | // The FEC group number is also the sequence number of the first |
| 712 | // FEC protected packet. The last protected packet's sequence number will |
| 713 | // be one less than the sequence number of the FEC packet. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 714 | QuicFecGroupNumber fec_group; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 715 | base::StringPiece redundancy; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 716 | }; |
| 717 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 718 | class NET_EXPORT_PRIVATE QuicData { |
| 719 | public: |
| 720 | QuicData(const char* buffer, size_t length) |
| 721 | : buffer_(buffer), |
| 722 | length_(length), |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 723 | owns_buffer_(false) {} |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 724 | |
| 725 | QuicData(char* buffer, size_t length, bool owns_buffer) |
| 726 | : buffer_(buffer), |
| 727 | length_(length), |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 728 | owns_buffer_(owns_buffer) {} |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 729 | |
| 730 | virtual ~QuicData(); |
| 731 | |
| 732 | base::StringPiece AsStringPiece() const { |
| 733 | return base::StringPiece(data(), length()); |
| 734 | } |
| 735 | |
| 736 | const char* data() const { return buffer_; } |
| 737 | size_t length() const { return length_; } |
| 738 | |
| 739 | private: |
| 740 | const char* buffer_; |
| 741 | size_t length_; |
| 742 | bool owns_buffer_; |
| 743 | |
| 744 | DISALLOW_COPY_AND_ASSIGN(QuicData); |
| 745 | }; |
| 746 | |
| 747 | class NET_EXPORT_PRIVATE QuicPacket : public QuicData { |
| 748 | public: |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 749 | static QuicPacket* NewDataPacket( |
| 750 | char* buffer, |
| 751 | size_t length, |
| 752 | bool owns_buffer, |
| 753 | QuicGuidLength guid_length, |
| 754 | bool includes_version, |
| 755 | QuicSequenceNumberLength sequence_number_length) { |
| 756 | return new QuicPacket(buffer, length, owns_buffer, guid_length, |
| 757 | includes_version, sequence_number_length, false); |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 758 | } |
| 759 | |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 760 | static QuicPacket* NewFecPacket( |
| 761 | char* buffer, |
| 762 | size_t length, |
| 763 | bool owns_buffer, |
| 764 | QuicGuidLength guid_length, |
| 765 | bool includes_version, |
| 766 | QuicSequenceNumberLength sequence_number_length) { |
| 767 | return new QuicPacket(buffer, length, owns_buffer, guid_length, |
| 768 | includes_version, sequence_number_length, true); |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 769 | } |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 770 | |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 771 | base::StringPiece FecProtectedData() const; |
| 772 | base::StringPiece AssociatedData() const; |
| 773 | base::StringPiece BeforePlaintext() const; |
| 774 | base::StringPiece Plaintext() const; |
[email protected] | 082b65b | 2012-11-10 19:11:31 | [diff] [blame] | 775 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 776 | bool is_fec_packet() const { return is_fec_packet_; } |
[email protected] | 082b65b | 2012-11-10 19:11:31 | [diff] [blame] | 777 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 778 | char* mutable_data() { return buffer_; } |
| 779 | |
| 780 | private: |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 781 | QuicPacket(char* buffer, |
| 782 | size_t length, |
| 783 | bool owns_buffer, |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 784 | QuicGuidLength guid_length, |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 785 | bool includes_version, |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 786 | QuicSequenceNumberLength sequence_number_length, |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 787 | bool is_fec_packet) |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 788 | : QuicData(buffer, length, owns_buffer), |
| 789 | buffer_(buffer), |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 790 | is_fec_packet_(is_fec_packet), |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 791 | guid_length_(guid_length), |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 792 | includes_version_(includes_version), |
| 793 | sequence_number_length_(sequence_number_length) {} |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 794 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 795 | char* buffer_; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 796 | const bool is_fec_packet_; |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 797 | const QuicGuidLength guid_length_; |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 798 | const bool includes_version_; |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 799 | const QuicSequenceNumberLength sequence_number_length_; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 800 | |
[email protected] | 2e740db | 2012-10-20 19:35:19 | [diff] [blame] | 801 | DISALLOW_COPY_AND_ASSIGN(QuicPacket); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 802 | }; |
| 803 | |
| 804 | class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData { |
| 805 | public: |
| 806 | QuicEncryptedPacket(const char* buffer, size_t length) |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 807 | : QuicData(buffer, length) {} |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 808 | |
| 809 | QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer) |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 810 | : QuicData(buffer, length, owns_buffer) {} |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 811 | |
[email protected] | c1b32c6 | 2013-01-20 02:49:10 | [diff] [blame] | 812 | // By default, gtest prints the raw bytes of an object. The bool data |
| 813 | // member (in the base class QuicData) causes this object to have padding |
| 814 | // bytes, which causes the default gtest object printer to read |
| 815 | // uninitialize memory. So we need to teach gtest how to print this object. |
| 816 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 817 | std::ostream& os, const QuicEncryptedPacket& s); |
| 818 | |
[email protected] | 2e740db | 2012-10-20 19:35:19 | [diff] [blame] | 819 | private: |
| 820 | DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 821 | }; |
| 822 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 823 | class NET_EXPORT_PRIVATE RetransmittableFrames { |
| 824 | public: |
| 825 | RetransmittableFrames(); |
| 826 | ~RetransmittableFrames(); |
| 827 | |
| 828 | // Allocates a local copy of the referenced StringPiece has QuicStreamFrame |
| 829 | // use it. |
| 830 | // Takes ownership of |stream_frame|. |
| 831 | const QuicFrame& AddStreamFrame(QuicStreamFrame* stream_frame); |
| 832 | // Takes ownership of the frame inside |frame|. |
| 833 | const QuicFrame& AddNonStreamFrame(const QuicFrame& frame); |
| 834 | const QuicFrames& frames() const { return frames_; } |
| 835 | |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 836 | void set_encryption_level(EncryptionLevel level); |
| 837 | EncryptionLevel encryption_level() const { |
| 838 | return encryption_level_; |
| 839 | } |
| 840 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 841 | private: |
| 842 | QuicFrames frames_; |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 843 | EncryptionLevel encryption_level_; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 844 | // Data referenced by the StringPiece of a QuicStreamFrame. |
| 845 | std::vector<std::string*> stream_data_; |
| 846 | |
| 847 | DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames); |
| 848 | }; |
| 849 | |
| 850 | struct NET_EXPORT_PRIVATE SerializedPacket { |
| 851 | SerializedPacket(QuicPacketSequenceNumber sequence_number, |
[email protected] | ea825e0 | 2013-08-21 18:12:45 | [diff] [blame] | 852 | QuicSequenceNumberLength sequence_number_length, |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 853 | QuicPacket* packet, |
| 854 | QuicPacketEntropyHash entropy_hash, |
[email protected] | 97cf302 | 2013-09-05 14:30:16 | [diff] [blame] | 855 | RetransmittableFrames* retransmittable_frames); |
| 856 | ~SerializedPacket(); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 857 | |
| 858 | QuicPacketSequenceNumber sequence_number; |
[email protected] | ea825e0 | 2013-08-21 18:12:45 | [diff] [blame] | 859 | QuicSequenceNumberLength sequence_number_length; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 860 | QuicPacket* packet; |
| 861 | QuicPacketEntropyHash entropy_hash; |
| 862 | RetransmittableFrames* retransmittable_frames; |
[email protected] | 97cf302 | 2013-09-05 14:30:16 | [diff] [blame] | 863 | |
| 864 | // If set, these will be called when this packet is ACKed by the peer. |
| 865 | std::set<QuicAckNotifier*> notifiers; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 866 | }; |
| 867 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 868 | // A struct for functions which consume data payloads and fins. |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 869 | struct QuicConsumedData { |
| 870 | QuicConsumedData(size_t bytes_consumed, bool fin_consumed) |
| 871 | : bytes_consumed(bytes_consumed), |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 872 | fin_consumed(fin_consumed) {} |
[email protected] | c1b32c6 | 2013-01-20 02:49:10 | [diff] [blame] | 873 | // By default, gtest prints the raw bytes of an object. The bool data |
| 874 | // member causes this object to have padding bytes, which causes the |
| 875 | // default gtest object printer to read uninitialize memory. So we need |
| 876 | // to teach gtest how to print this object. |
| 877 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 878 | std::ostream& os, const QuicConsumedData& s); |
| 879 | |
[email protected] | 97cf302 | 2013-09-05 14:30:16 | [diff] [blame] | 880 | // How many bytes were consumed. |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 881 | size_t bytes_consumed; |
[email protected] | 97cf302 | 2013-09-05 14:30:16 | [diff] [blame] | 882 | |
| 883 | // True if an incoming fin was consumed. |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 884 | bool fin_consumed; |
| 885 | }; |
| 886 | |
[email protected] | 752fbe5 | 2013-10-14 08:35:32 | [diff] [blame] | 887 | enum WriteStatus { |
| 888 | WRITE_STATUS_OK, |
| 889 | WRITE_STATUS_BLOCKED, |
| 890 | WRITE_STATUS_ERROR, |
| 891 | }; |
| 892 | |
| 893 | // A struct used to return the result of write calls including either the number |
| 894 | // of bytes written or the error code, depending upon the status. |
| 895 | struct NET_EXPORT_PRIVATE WriteResult { |
| 896 | WriteResult(WriteStatus status, int bytes_written_or_error_code) : |
| 897 | status(status), bytes_written(bytes_written_or_error_code) { |
| 898 | } |
| 899 | |
| 900 | WriteStatus status; |
| 901 | union { |
| 902 | int bytes_written; // only valid when status is OK |
| 903 | int error_code; // only valid when status is ERROR |
| 904 | }; |
| 905 | }; |
| 906 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 907 | } // namespace net |
| 908 | |
| 909 | #endif // NET_QUIC_QUIC_PROTOCOL_H_ |