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