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