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