[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> |
tfarina | 3723da2 | 2015-06-03 21:39:30 | [diff] [blame] | 9 | #include <stdint.h> |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 10 | #include <limits> |
rtenneti | 4b06ae7 | 2014-08-26 03:43:43 | [diff] [blame] | 11 | #include <list> |
[email protected] | a674b4c | 2012-12-05 03:44:30 | [diff] [blame] | 12 | #include <map> |
[email protected] | 5640d0a | 2012-10-22 18:17:02 | [diff] [blame] | 13 | #include <ostream> |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 14 | #include <set> |
| 15 | #include <string> |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 16 | #include <utility> |
| 17 | #include <vector> |
| 18 | |
| 19 | #include "base/basictypes.h" |
[email protected] | 14c1c23 | 2013-06-11 17:52:44 | [diff] [blame] | 20 | #include "base/containers/hash_tables.h" |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 21 | #include "base/logging.h" |
rtenneti | 8dd12b2 | 2015-10-21 01:26:38 | [diff] [blame] | 22 | #include "base/memory/ref_counted.h" |
rtenneti | f60c32d8 | 2015-10-14 00:07:00 | [diff] [blame] | 23 | #include "base/memory/scoped_ptr.h" |
[email protected] | d069c11a | 2013-04-13 00:01:55 | [diff] [blame] | 24 | #include "base/strings/string_piece.h" |
[email protected] | 165e075 | 2012-11-16 07:49:44 | [diff] [blame] | 25 | #include "net/base/int128.h" |
rtenneti | c14c8ab | 2015-06-18 05:47:40 | [diff] [blame] | 26 | #include "net/base/iovec.h" |
[email protected] | 79d13dcb | 2014-02-05 07:23:13 | [diff] [blame] | 27 | #include "net/base/ip_endpoint.h" |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 28 | #include "net/base/net_export.h" |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 29 | #include "net/quic/interval_set.h" |
rtenneti | 8dd12b2 | 2015-10-21 01:26:38 | [diff] [blame] | 30 | #include "net/quic/quic_ack_listener_interface.h" |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 31 | #include "net/quic/quic_bandwidth.h" |
[email protected] | 2a960e0 | 2012-11-11 14:48:10 | [diff] [blame] | 32 | #include "net/quic/quic_time.h" |
rtenneti | c14c8ab | 2015-06-18 05:47:40 | [diff] [blame] | 33 | #include "net/quic/quic_types.h" |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 34 | |
| 35 | namespace net { |
| 36 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 37 | class QuicPacket; |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 38 | struct QuicPacketHeader; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 39 | |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 40 | typedef uint64 QuicConnectionId; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 41 | typedef uint32 QuicStreamId; |
| 42 | typedef uint64 QuicStreamOffset; |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 43 | typedef uint64 QuicPacketNumber; |
rjshade | c86dbfa | 2015-11-12 20:16:25 | [diff] [blame] | 44 | typedef uint8 QuicPathId; |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 45 | typedef QuicPacketNumber QuicFecGroupNumber; |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 46 | typedef uint64 QuicPublicResetNonceProof; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 47 | typedef uint8 QuicPacketEntropyHash; |
[email protected] | c244c5a1 | 2013-05-07 20:55:04 | [diff] [blame] | 48 | typedef uint32 QuicHeaderId; |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 49 | // QuicTag is the type of a tag in the wire protocol. |
| 50 | typedef uint32 QuicTag; |
| 51 | typedef std::vector<QuicTag> QuicTagVector; |
[email protected] | 79d13dcb | 2014-02-05 07:23:13 | [diff] [blame] | 52 | typedef std::map<QuicTag, std::string> QuicTagValueMap; |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 53 | typedef uint16 QuicPacketLength; |
[email protected] | cff7b7b | 2013-01-11 08:49:07 | [diff] [blame] | 54 | |
rtenneti | bb2780c | 2015-07-22 19:16:08 | [diff] [blame] | 55 | // Default initial maximum size in bytes of a QUIC packet. |
[email protected] | 310d37b | 2014-08-02 06:15:37 | [diff] [blame] | 56 | const QuicByteCount kDefaultMaxPacketSize = 1350; |
rtenneti | 16a2077 | 2015-02-17 18:58:48 | [diff] [blame] | 57 | // Default initial maximum size in bytes of a QUIC packet for servers. |
| 58 | const QuicByteCount kDefaultServerMaxPacketSize = 1000; |
[email protected] | 8e01c06 | 2013-10-31 07:35:31 | [diff] [blame] | 59 | // 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] | 60 | // minus the IP and UDP headers. IPv6 has a 40 byte header, UPD adds an |
| 61 | // additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's |
| 62 | // max packet size is 1500 bytes, 1500 - 48 = 1452. |
| 63 | const QuicByteCount kMaxPacketSize = 1452; |
rtenneti | 9e0fb50 | 2015-03-08 06:07:16 | [diff] [blame] | 64 | // Default maximum packet size used in the Linux TCP implementation. |
| 65 | // Used in QUIC for congestion window computations in bytes. |
[email protected] | ce7bb141 | 2014-05-17 15:51:33 | [diff] [blame] | 66 | const QuicByteCount kDefaultTCPMSS = 1460; |
[email protected] | 8e01c06 | 2013-10-31 07:35:31 | [diff] [blame] | 67 | |
rch | 1fe2eeb | 2015-10-26 14:45:57 | [diff] [blame] | 68 | // We match SPDY's use of 32 (since we'd compete with SPDY). |
| 69 | const QuicPacketCount kInitialCongestionWindow = 32; |
[email protected] | 8e01c06 | 2013-10-31 07:35:31 | [diff] [blame] | 70 | |
rtenneti | 7652bf3 | 2015-01-05 18:51:07 | [diff] [blame] | 71 | // Minimum size of initial flow control window, for both stream and session. |
| 72 | const uint32 kMinimumFlowControlSendWindow = 16 * 1024; // 16 KB |
[email protected] | 9bb57c7 | 2014-03-31 20:36:04 | [diff] [blame] | 73 | |
rjshade | c86dbfa | 2015-11-12 20:16:25 | [diff] [blame] | 74 | // Maximum flow control receive window limits for connection and stream. |
| 75 | const QuicByteCount kStreamReceiveWindowLimit = 16 * 1024 * 1024; // 16 MB |
| 76 | const QuicByteCount kSessionReceiveWindowLimit = 24 * 1024 * 1024; // 24 MB |
| 77 | |
rtenneti | fb3fa6c | 2015-03-16 23:04:55 | [diff] [blame] | 78 | // Minimum size of the CWND, in packets, when doing bandwidth resumption. |
rtenneti | 8d2a808d | 2014-11-26 01:10:09 | [diff] [blame] | 79 | const QuicPacketCount kMinCongestionWindowForBandwidthResumption = 10; |
| 80 | |
rtenneti | 581b6ae8 | 2015-07-20 20:48:01 | [diff] [blame] | 81 | // Maximum size of the CWND, in packets. |
| 82 | const QuicPacketCount kMaxCongestionWindow = 200; |
rtenneti | 69e64aa | 2015-06-26 04:25:30 | [diff] [blame] | 83 | |
| 84 | // Maximum number of tracked packets. |
| 85 | const QuicPacketCount kMaxTrackedPackets = 5000; |
[email protected] | 0ac0c5b | 2013-11-20 05:55:58 | [diff] [blame] | 86 | |
rtenneti | 2318668 | 2014-10-30 01:49:33 | [diff] [blame] | 87 | // Default size of the socket receive buffer in bytes. |
[email protected] | 648f8114 | 2014-08-15 21:38:46 | [diff] [blame] | 88 | const QuicByteCount kDefaultSocketReceiveBuffer = 256 * 1024; |
rtenneti | 2318668 | 2014-10-30 01:49:33 | [diff] [blame] | 89 | // Minimum size of the socket receive buffer in bytes. |
| 90 | // Smaller values are ignored. |
| 91 | const QuicByteCount kMinSocketReceiveBuffer = 16 * 1024; |
[email protected] | a97b318 | 2014-08-08 08:10:18 | [diff] [blame] | 92 | |
rtenneti | 9529380 | 2015-03-27 18:59:23 | [diff] [blame] | 93 | // Fraction of the receive buffer that can be used for encrypted bytes. |
| 94 | // Allows a 5% overhead for IP and UDP framing, as well as ack only packets. |
| 95 | static const float kUsableRecieveBufferFraction = 0.95f; |
rtenneti | 581b6ae8 | 2015-07-20 20:48:01 | [diff] [blame] | 96 | // Fraction of the receive buffer that can be used, based on conservative |
| 97 | // estimates and testing on Linux. |
| 98 | // An alternative to kUsableRecieveBufferFraction. |
| 99 | static const float kConservativeReceiveBufferFraction = 0.6f; |
rtenneti | 9529380 | 2015-03-27 18:59:23 | [diff] [blame] | 100 | |
rtenneti | fc97ab6 | 2014-11-11 22:17:49 | [diff] [blame] | 101 | // Don't allow a client to suggest an RTT shorter than 10ms. |
| 102 | const uint32 kMinInitialRoundTripTimeUs = 10 * kNumMicrosPerMilli; |
| 103 | |
[email protected] | 8e01c06 | 2013-10-31 07:35:31 | [diff] [blame] | 104 | // Don't allow a client to suggest an RTT longer than 15 seconds. |
[email protected] | 2d43c4012 | 2014-04-21 14:51:27 | [diff] [blame] | 105 | const uint32 kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 106 | |
| 107 | // Maximum number of open streams per connection. |
| 108 | const size_t kDefaultMaxStreamsPerConnection = 100; |
| 109 | |
[email protected] | af806e6 | 2013-05-22 14:47:50 | [diff] [blame] | 110 | // Number of bytes reserved for public flags in the packet header. |
| 111 | const size_t kPublicFlagsSize = 1; |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 112 | // Number of bytes reserved for version number in the packet header. |
| 113 | const size_t kQuicVersionSize = 4; |
zhongyi | b867702 | 2015-12-01 05:51:30 | [diff] [blame^] | 114 | // Number of bytes reserved for path id in the packet header. |
| 115 | const size_t kQuicPathIdSize = 1; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 116 | // Number of bytes reserved for private flags in the packet header. |
| 117 | const size_t kPrivateFlagsSize = 1; |
| 118 | // Number of bytes reserved for FEC group in the packet header. |
| 119 | const size_t kFecGroupSize = 1; |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 120 | |
| 121 | // Signifies that the QuicPacket will contain version of the protocol. |
| 122 | const bool kIncludeVersion = true; |
zhongyi | b867702 | 2015-12-01 05:51:30 | [diff] [blame^] | 123 | // Signifies that the QuicPacket will contain path id. |
| 124 | const bool kIncludePathId = true; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 125 | |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 126 | // Index of the first byte in a QUIC packet which is used in hash calculation. |
| 127 | const size_t kStartOfHashData = 0; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 128 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 129 | // Reserved ID for the crypto stream. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 130 | const QuicStreamId kCryptoStreamId = 1; |
| 131 | |
[email protected] | 4d64079 | 2013-12-18 22:21:08 | [diff] [blame] | 132 | // Reserved ID for the headers stream. |
| 133 | const QuicStreamId kHeadersStreamId = 3; |
| 134 | |
[email protected] | 648f8114 | 2014-08-15 21:38:46 | [diff] [blame] | 135 | // Maximum delayed ack time, in ms. |
pkasting | acec86f | 2014-10-14 23:08:55 | [diff] [blame] | 136 | const int64 kMaxDelayedAckTimeMs = 25; |
[email protected] | 648f8114 | 2014-08-15 21:38:46 | [diff] [blame] | 137 | |
rtenneti | b5512bb | 2014-09-29 19:17:15 | [diff] [blame] | 138 | // The timeout before the handshake succeeds. |
| 139 | const int64 kInitialIdleTimeoutSecs = 5; |
| 140 | // The default idle timeout. |
| 141 | const int64 kDefaultIdleTimeoutSecs = 30; |
rtenneti | 31e9fd6 | 2014-09-16 05:22:15 | [diff] [blame] | 142 | // The maximum idle timeout that can be negotiated. |
| 143 | const int64 kMaximumIdleTimeoutSecs = 60 * 10; // 10 minutes. |
| 144 | // The default timeout for a connection until the crypto handshake succeeds. |
rtenneti | b5512bb | 2014-09-29 19:17:15 | [diff] [blame] | 145 | const int64 kMaxTimeForCryptoHandshakeSecs = 10; // 10 secs. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 146 | |
rtenneti | 93bce7ece | 2014-10-13 22:38:41 | [diff] [blame] | 147 | // Default limit on the number of undecryptable packets the connection buffers |
| 148 | // before the CHLO/SHLO arrive. |
| 149 | const size_t kDefaultMaxUndecryptablePackets = 10; |
| 150 | |
[email protected] | 525948df | 2014-04-21 06:26:58 | [diff] [blame] | 151 | // Default ping timeout. |
| 152 | const int64 kPingTimeoutSecs = 15; // 15 secs. |
| 153 | |
[email protected] | ca4e0d9 | 2014-08-22 16:33:22 | [diff] [blame] | 154 | // Minimum number of RTTs between Server Config Updates (SCUP) sent to client. |
| 155 | const int kMinIntervalBetweenServerConfigUpdatesRTTs = 10; |
| 156 | |
| 157 | // Minimum time between Server Config Updates (SCUP) sent to client. |
| 158 | const int kMinIntervalBetweenServerConfigUpdatesMs = 1000; |
| 159 | |
rtenneti | 33da8ab | 2014-11-04 04:17:00 | [diff] [blame] | 160 | // Minimum number of packets between Server Config Updates (SCUP). |
| 161 | const int kMinPacketsBetweenServerConfigUpdates = 100; |
| 162 | |
rtenneti | b5512bb | 2014-09-29 19:17:15 | [diff] [blame] | 163 | // The number of open streams that a server will accept is set to be slightly |
| 164 | // larger than the negotiated limit. Immediately closing the connection if the |
| 165 | // client opens slightly too many streams is not ideal: the client may have sent |
| 166 | // a FIN that was lost, and simultaneously opened a new stream. The number of |
| 167 | // streams a server accepts is a fixed increment over the negotiated limit, or a |
| 168 | // percentage increase, whichever is larger. |
rtenneti | 31e9fd6 | 2014-09-16 05:22:15 | [diff] [blame] | 169 | const float kMaxStreamsMultiplier = 1.1f; |
rtenneti | b5512bb | 2014-09-29 19:17:15 | [diff] [blame] | 170 | const int kMaxStreamsMinimumIncrement = 10; |
rtenneti | 31e9fd6 | 2014-09-16 05:22:15 | [diff] [blame] | 171 | |
rtenneti | 159828f | 2015-10-13 06:58:09 | [diff] [blame] | 172 | // Available streams are ones with IDs less than the highest stream that has |
| 173 | // been opened which have neither been opened or reset. The limit on the number |
| 174 | // of available streams is 10 times the limit on the number of open streams. |
| 175 | const int kMaxAvailableStreamsMultiplier = 10; |
| 176 | |
[email protected] | b007e63 | 2013-10-28 08:39:25 | [diff] [blame] | 177 | // We define an unsigned 16-bit floating point value, inspired by IEEE floats |
| 178 | // (http://en.wikipedia.org/wiki/Half_precision_floating-point_format), |
| 179 | // with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden |
| 180 | // bit) and denormals, but without signs, transfinites or fractions. Wire format |
| 181 | // 16 bits (little-endian byte order) are split into exponent (high 5) and |
| 182 | // mantissa (low 11) and decoded as: |
| 183 | // uint64 value; |
| 184 | // if (exponent == 0) value = mantissa; |
| 185 | // else value = (mantissa | 1 << 11) << (exponent - 1) |
| 186 | const int kUFloat16ExponentBits = 5; |
| 187 | const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30 |
| 188 | const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11 |
| 189 | const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12 |
| 190 | const uint64 kUFloat16MaxValue = // 0x3FFC0000000 |
tfarina | 3723da2 | 2015-06-03 21:39:30 | [diff] [blame] | 191 | ((UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1) << |
[email protected] | b007e63 | 2013-10-28 08:39:25 | [diff] [blame] | 192 | kUFloat16MaxExponent; |
| 193 | |
[email protected] | c67a82cb | 2013-09-24 02:53:21 | [diff] [blame] | 194 | enum TransmissionType { |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 195 | NOT_RETRANSMISSION, |
[email protected] | b9475b58 | 2014-03-20 20:04:33 | [diff] [blame] | 196 | FIRST_TRANSMISSION_TYPE = NOT_RETRANSMISSION, |
| 197 | HANDSHAKE_RETRANSMISSION, // Retransmits due to handshake timeouts. |
rtenneti | 31e9fd6 | 2014-09-16 05:22:15 | [diff] [blame] | 198 | ALL_UNACKED_RETRANSMISSION, // Retransmits all unacked packets. |
| 199 | ALL_INITIAL_RETRANSMISSION, // Retransmits all initially encrypted packets. |
[email protected] | b9475b58 | 2014-03-20 20:04:33 | [diff] [blame] | 200 | LOSS_RETRANSMISSION, // Retransmits due to loss detection. |
| 201 | RTO_RETRANSMISSION, // Retransmits due to retransmit time out. |
| 202 | TLP_RETRANSMISSION, // Tail loss probes. |
| 203 | LAST_TRANSMISSION_TYPE = TLP_RETRANSMISSION, |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | enum HasRetransmittableData { |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 207 | NO_RETRANSMITTABLE_DATA, |
| 208 | HAS_RETRANSMITTABLE_DATA, |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 209 | }; |
| 210 | |
[email protected] | 575cce6 | 2013-08-03 02:06:43 | [diff] [blame] | 211 | enum IsHandshake { |
| 212 | NOT_HANDSHAKE, |
| 213 | IS_HANDSHAKE |
| 214 | }; |
| 215 | |
rtenneti | 6f48aa9 | 2015-03-16 02:18:48 | [diff] [blame] | 216 | enum class Perspective { IS_SERVER, IS_CLIENT }; |
| 217 | |
| 218 | NET_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, |
| 219 | const Perspective& s); |
| 220 | |
[email protected] | bbb1007 | 2014-06-13 07:41:59 | [diff] [blame] | 221 | // Indicates FEC protection level for data being written. |
| 222 | enum FecProtection { |
| 223 | MUST_FEC_PROTECT, // Callee must FEC protect this data. |
[email protected] | a5b9817 | 2014-06-18 07:01:59 | [diff] [blame] | 224 | MAY_FEC_PROTECT // Callee does not have to but may FEC protect this data. |
| 225 | }; |
| 226 | |
[email protected] | bc356fe | 2014-06-19 11:14:14 | [diff] [blame] | 227 | // Indicates FEC policy. |
[email protected] | a5b9817 | 2014-06-18 07:01:59 | [diff] [blame] | 228 | enum FecPolicy { |
| 229 | FEC_PROTECT_ALWAYS, // All data in the stream should be FEC protected. |
| 230 | FEC_PROTECT_OPTIONAL // Data in the stream does not need FEC protection. |
[email protected] | bbb1007 | 2014-06-13 07:41:59 | [diff] [blame] | 231 | }; |
| 232 | |
rtenneti | a4228ea | 2015-06-04 02:31:44 | [diff] [blame] | 233 | // Indicates FEC policy about when to send FEC packet. |
| 234 | enum FecSendPolicy { |
| 235 | // Send FEC packet when FEC group is full or when FEC alarm goes off. |
| 236 | FEC_ANY_TRIGGER, |
| 237 | // Send FEC packet only when FEC alarm goes off. |
| 238 | FEC_ALARM_TRIGGER |
| 239 | }; |
| 240 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 241 | enum QuicFrameType { |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 242 | // Regular frame types. The values set here cannot change without the |
| 243 | // introduction of a new QUIC version. |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 244 | PADDING_FRAME = 0, |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 245 | RST_STREAM_FRAME = 1, |
| 246 | CONNECTION_CLOSE_FRAME = 2, |
| 247 | GOAWAY_FRAME = 3, |
| 248 | WINDOW_UPDATE_FRAME = 4, |
| 249 | BLOCKED_FRAME = 5, |
[email protected] | 93dd91f | 2014-02-27 00:09:03 | [diff] [blame] | 250 | STOP_WAITING_FRAME = 6, |
[email protected] | d8c52211 | 2014-04-23 09:23:25 | [diff] [blame] | 251 | PING_FRAME = 7, |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 252 | |
rtenneti | f4bdb54 | 2015-01-21 14:33:05 | [diff] [blame] | 253 | // STREAM and ACK frames are special frames. They are encoded differently on |
| 254 | // the wire and their values do not need to be stable. |
[email protected] | 97cf302 | 2013-09-05 14:30:16 | [diff] [blame] | 255 | STREAM_FRAME, |
| 256 | ACK_FRAME, |
rtenneti | 69e64aa | 2015-06-26 04:25:30 | [diff] [blame] | 257 | // The path MTU discovery frame is encoded as a PING frame on the wire. |
| 258 | MTU_DISCOVERY_FRAME, |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 259 | NUM_FRAME_TYPES |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 260 | }; |
| 261 | |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 262 | enum QuicConnectionIdLength { |
| 263 | PACKET_0BYTE_CONNECTION_ID = 0, |
| 264 | PACKET_1BYTE_CONNECTION_ID = 1, |
| 265 | PACKET_4BYTE_CONNECTION_ID = 4, |
| 266 | PACKET_8BYTE_CONNECTION_ID = 8 |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 267 | }; |
| 268 | |
| 269 | enum InFecGroup { |
| 270 | NOT_IN_FEC_GROUP, |
| 271 | IN_FEC_GROUP, |
| 272 | }; |
| 273 | |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 274 | enum QuicPacketNumberLength { |
| 275 | PACKET_1BYTE_PACKET_NUMBER = 1, |
| 276 | PACKET_2BYTE_PACKET_NUMBER = 2, |
| 277 | PACKET_4BYTE_PACKET_NUMBER = 4, |
| 278 | PACKET_6BYTE_PACKET_NUMBER = 6 |
[email protected] | 25c31dc | 2013-06-05 17:56:04 | [diff] [blame] | 279 | }; |
| 280 | |
[email protected] | 8e01c06 | 2013-10-31 07:35:31 | [diff] [blame] | 281 | // Used to indicate a QuicSequenceNumberLength using two flag bits. |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 282 | enum QuicPacketNumberLengthFlags { |
| 283 | PACKET_FLAGS_1BYTE_PACKET = 0, // 00 |
| 284 | PACKET_FLAGS_2BYTE_PACKET = 1, // 01 |
| 285 | PACKET_FLAGS_4BYTE_PACKET = 1 << 1, // 10 |
| 286 | PACKET_FLAGS_6BYTE_PACKET = 1 << 1 | 1, // 11 |
[email protected] | 8e01c06 | 2013-10-31 07:35:31 | [diff] [blame] | 287 | }; |
| 288 | |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame] | 289 | // The public flags are specified in one byte. |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 290 | enum QuicPacketPublicFlags { |
| 291 | PACKET_PUBLIC_FLAGS_NONE = 0, |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame] | 292 | |
| 293 | // Bit 0: Does the packet header contains version info? |
| 294 | PACKET_PUBLIC_FLAGS_VERSION = 1 << 0, |
| 295 | |
| 296 | // Bit 1: Is this packet a public reset packet? |
| 297 | PACKET_PUBLIC_FLAGS_RST = 1 << 1, |
| 298 | |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 299 | // Bits 2 and 3 specify the length of the ConnectionId as follows: |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame] | 300 | // ----00--: 0 bytes |
| 301 | // ----01--: 1 byte |
| 302 | // ----10--: 4 bytes |
| 303 | // ----11--: 8 bytes |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 304 | PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID = 0, |
| 305 | PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID = 1 << 2, |
| 306 | PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID = 1 << 3, |
| 307 | PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID = 1 << 3 | 1 << 2, |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame] | 308 | |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 309 | // Bits 4 and 5 describe the packet number length as follows: |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame] | 310 | // --00----: 1 byte |
| 311 | // --01----: 2 bytes |
| 312 | // --10----: 4 bytes |
| 313 | // --11----: 6 bytes |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 314 | PACKET_PUBLIC_FLAGS_1BYTE_PACKET = PACKET_FLAGS_1BYTE_PACKET << 4, |
| 315 | PACKET_PUBLIC_FLAGS_2BYTE_PACKET = PACKET_FLAGS_2BYTE_PACKET << 4, |
| 316 | PACKET_PUBLIC_FLAGS_4BYTE_PACKET = PACKET_FLAGS_4BYTE_PACKET << 4, |
| 317 | PACKET_PUBLIC_FLAGS_6BYTE_PACKET = PACKET_FLAGS_6BYTE_PACKET << 4, |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame] | 318 | |
zhongyi | b867702 | 2015-12-01 05:51:30 | [diff] [blame^] | 319 | // Bit 6: Does the packet header contain a path id? |
| 320 | PACKET_PUBLIC_FLAGS_MULTIPATH = 1 << 6, |
| 321 | |
| 322 | // All bits set (bit7 are not currently used): 01111111 |
| 323 | PACKET_PUBLIC_FLAGS_MAX = (1 << 7) - 1, |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 324 | }; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 325 | |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame] | 326 | // The private flags are specified in one byte. |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 327 | enum QuicPacketPrivateFlags { |
| 328 | PACKET_PRIVATE_FLAGS_NONE = 0, |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame] | 329 | |
| 330 | // Bit 0: Does this packet contain an entropy bit? |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 331 | PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0, |
[email protected] | f62262b | 2013-07-05 20:57:30 | [diff] [blame] | 332 | |
| 333 | // Bit 1: Payload is part of an FEC group? |
| 334 | PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1, |
| 335 | |
| 336 | // Bit 2: Payload is FEC as opposed to frames? |
| 337 | PACKET_PRIVATE_FLAGS_FEC = 1 << 2, |
| 338 | |
| 339 | // All bits set (bits 3-7 are not currently used): 00000111 |
| 340 | PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1 |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 341 | }; |
| 342 | |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 343 | // The available versions of QUIC. Guaranteed that the integer value of the enum |
| 344 | // will match the version number. |
| 345 | // When adding a new version to this enum you should add it to |
[email protected] | 8bbfaeb7 | 2013-08-09 06:38:26 | [diff] [blame] | 346 | // kSupportedQuicVersions (if appropriate), and also add a new case to the |
| 347 | // helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and |
| 348 | // QuicVersionToString. |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 349 | enum QuicVersion { |
| 350 | // Special case to indicate unknown/unsupported QUIC version. |
| 351 | QUIC_VERSION_UNSUPPORTED = 0, |
| 352 | |
rch | c081544 | 2015-04-18 13:29:46 | [diff] [blame] | 353 | QUIC_VERSION_25 = 25, // SPDY/4 header keys, and removal of error_details |
| 354 | // from QuicRstStreamFrame |
zhongyi | c92bc49 | 2015-09-22 19:14:36 | [diff] [blame] | 355 | QUIC_VERSION_26 = 26, // In CHLO, send XLCT tag containing hash of leaf cert |
rtenneti | 159828f | 2015-10-13 06:58:09 | [diff] [blame] | 356 | QUIC_VERSION_27 = 27, // Sends a nonce in the SHLO. |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 357 | QUIC_VERSION_28 = 28, // Receiver can refuse to create a requested stream. |
rch | 99b644c | 2015-11-04 05:25:28 | [diff] [blame] | 358 | QUIC_VERSION_29 = 29, // Server and client honor QUIC_STREAM_NO_ERROR. |
| 359 | QUIC_VERSION_30 = 30, // Add server side support of cert transparency. |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 360 | }; |
| 361 | |
| 362 | // This vector contains QUIC versions which we currently support. |
| 363 | // This should be ordered such that the highest supported version is the first |
| 364 | // element, with subsequent elements in descending order (versions can be |
| 365 | // skipped as necessary). |
[email protected] | 31ae85484 | 2013-11-27 00:05:46 | [diff] [blame] | 366 | // |
[email protected] | 310d37b | 2014-08-02 06:15:37 | [diff] [blame] | 367 | // IMPORTANT: if you are adding to this list, follow the instructions at |
[email protected] | 31ae85484 | 2013-11-27 00:05:46 | [diff] [blame] | 368 | // http://sites/quic/adding-and-removing-versions |
zhongyi | c92bc49 | 2015-09-22 19:14:36 | [diff] [blame] | 369 | static const QuicVersion kSupportedQuicVersions[] = { |
rch | 99b644c | 2015-11-04 05:25:28 | [diff] [blame] | 370 | QUIC_VERSION_30, QUIC_VERSION_29, QUIC_VERSION_28, |
| 371 | QUIC_VERSION_27, QUIC_VERSION_26, QUIC_VERSION_25}; |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 372 | |
| 373 | typedef std::vector<QuicVersion> QuicVersionVector; |
| 374 | |
[email protected] | b007e63 | 2013-10-28 08:39:25 | [diff] [blame] | 375 | // Returns a vector of QUIC versions in kSupportedQuicVersions. |
| 376 | NET_EXPORT_PRIVATE QuicVersionVector QuicSupportedVersions(); |
[email protected] | ea2ab47b | 2013-08-13 00:44:11 | [diff] [blame] | 377 | |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 378 | // QuicTag is written to and read from the wire, but we prefer to use |
| 379 | // the more readable QuicVersion at other levels. |
| 380 | // Helper function which translates from a QuicVersion to a QuicTag. Returns 0 |
| 381 | // if QuicVersion is unsupported. |
| 382 | NET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version); |
| 383 | |
| 384 | // Returns appropriate QuicVersion from a QuicTag. |
| 385 | // Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood. |
| 386 | NET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag); |
| 387 | |
| 388 | // Helper function which translates from a QuicVersion to a string. |
| 389 | // Returns strings corresponding to enum names (e.g. QUIC_VERSION_6). |
| 390 | NET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version); |
| 391 | |
| 392 | // Returns comma separated list of string representations of QuicVersion enum |
[email protected] | b007e63 | 2013-10-28 08:39:25 | [diff] [blame] | 393 | // values in the supplied |versions| vector. |
| 394 | NET_EXPORT_PRIVATE std::string QuicVersionVectorToString( |
| 395 | const QuicVersionVector& versions); |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 396 | |
| 397 | // Version and Crypto tags are written to the wire with a big-endian |
| 398 | // representation of the name of the tag. For example |
| 399 | // the client hello tag (CHLO) will be written as the |
| 400 | // following 4 bytes: 'C' 'H' 'L' 'O'. Since it is |
| 401 | // stored in memory as a little endian uint32, we need |
| 402 | // to reverse the order of the bytes. |
| 403 | |
| 404 | // MakeQuicTag returns a value given the four bytes. For example: |
| 405 | // MakeQuicTag('C', 'H', 'L', 'O'); |
| 406 | NET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d); |
| 407 | |
[email protected] | 9cda5fd | 2014-06-03 10:20:28 | [diff] [blame] | 408 | // Returns true if the tag vector contains the specified tag. |
[email protected] | cc1aa27 | 2014-06-30 19:48:22 | [diff] [blame] | 409 | NET_EXPORT_PRIVATE bool ContainsQuicTag(const QuicTagVector& tag_vector, |
| 410 | QuicTag tag); |
[email protected] | 9cda5fd | 2014-06-03 10:20:28 | [diff] [blame] | 411 | |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 412 | // Size in bytes of the data or fec packet header. |
[email protected] | 79d13dcb | 2014-02-05 07:23:13 | [diff] [blame] | 413 | NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(const QuicPacketHeader& header); |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 414 | |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 415 | NET_EXPORT_PRIVATE size_t |
| 416 | GetPacketHeaderSize(QuicConnectionIdLength connection_id_length, |
| 417 | bool include_version, |
zhongyi | b867702 | 2015-12-01 05:51:30 | [diff] [blame^] | 418 | bool include_path_id, |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 419 | QuicPacketNumberLength packet_number_length, |
| 420 | InFecGroup is_in_fec_group); |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 421 | |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 422 | // Index of the first byte in a QUIC packet of FEC protected data. |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 423 | NET_EXPORT_PRIVATE size_t |
| 424 | GetStartOfFecProtectedData(QuicConnectionIdLength connection_id_length, |
| 425 | bool include_version, |
| 426 | QuicPacketNumberLength packet_number_length); |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 427 | // Index of the first byte in a QUIC packet of encrypted data. |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 428 | NET_EXPORT_PRIVATE size_t |
| 429 | GetStartOfEncryptedData(QuicConnectionIdLength connection_id_length, |
| 430 | bool include_version, |
| 431 | QuicPacketNumberLength packet_number_length); |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 432 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 433 | enum QuicRstStreamErrorCode { |
rch | 99b644c | 2015-11-04 05:25:28 | [diff] [blame] | 434 | // Complete response has been sent, sending a RST to ask the other endpoint |
| 435 | // to stop sending request data without discarding the response. |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 436 | QUIC_STREAM_NO_ERROR = 0, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 437 | |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 438 | // There was some error which halted stream processing. |
| 439 | QUIC_ERROR_PROCESSING_STREAM, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 440 | // We got two fin or reset offsets which did not match. |
| 441 | QUIC_MULTIPLE_TERMINATION_OFFSETS, |
| 442 | // We got bad payload and can not respond to it at the protocol level. |
| 443 | QUIC_BAD_APPLICATION_PAYLOAD, |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 444 | // Stream closed due to connection error. No reset frame is sent when this |
| 445 | // happens. |
| 446 | QUIC_STREAM_CONNECTION_ERROR, |
| 447 | // GoAway frame sent. No more stream can be created. |
| 448 | QUIC_STREAM_PEER_GOING_AWAY, |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 449 | // The stream has been cancelled. |
| 450 | QUIC_STREAM_CANCELLED, |
rtenneti | 4a5df26 | 2014-11-07 00:43:58 | [diff] [blame] | 451 | // Closing stream locally, sending a RST to allow for proper flow control |
| 452 | // accounting. Sent in response to a RST from the peer. |
| 453 | QUIC_RST_ACKNOWLEDGEMENT, |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 454 | // Receiver refused to create the stream (because its limit on open streams |
| 455 | // has been reached). The sender should retry the request later (using |
| 456 | // another stream). |
| 457 | QUIC_REFUSED_STREAM, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 458 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 459 | // No error. Used as bound while iterating. |
| 460 | QUIC_STREAM_LAST_ERROR, |
| 461 | }; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 462 | |
[email protected] | 51cc134 | 2014-04-18 23:44:37 | [diff] [blame] | 463 | // Because receiving an unknown QuicRstStreamErrorCode results in connection |
| 464 | // teardown, we use this to make sure any errors predating a given version are |
| 465 | // downgraded to the most appropriate existing error. |
| 466 | NET_EXPORT_PRIVATE QuicRstStreamErrorCode AdjustErrorForVersion( |
| 467 | QuicRstStreamErrorCode error_code, |
| 468 | QuicVersion version); |
| 469 | |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 470 | // These values must remain stable as they are uploaded to UMA histograms. |
| 471 | // To add a new error code, use the current value of QUIC_LAST_ERROR and |
| 472 | // increment QUIC_LAST_ERROR. |
rtenneti | 159828f | 2015-10-13 06:58:09 | [diff] [blame] | 473 | // last value = 77 |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 474 | enum QuicErrorCode { |
| 475 | QUIC_NO_ERROR = 0, |
| 476 | |
| 477 | // Connection has reached an invalid state. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 478 | QUIC_INTERNAL_ERROR = 1, |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 479 | // There were data frames after the a fin or reset. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 480 | QUIC_STREAM_DATA_AFTER_TERMINATION = 2, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 481 | // Control frame is malformed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 482 | QUIC_INVALID_PACKET_HEADER = 3, |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 483 | // Frame data is malformed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 484 | QUIC_INVALID_FRAME_DATA = 4, |
| 485 | // The packet contained no payload. |
| 486 | QUIC_MISSING_PAYLOAD = 48, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 487 | // FEC data is malformed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 488 | QUIC_INVALID_FEC_DATA = 5, |
| 489 | // STREAM frame data is malformed. |
| 490 | QUIC_INVALID_STREAM_DATA = 46, |
[email protected] | 42a3eba | 2014-04-30 10:52:55 | [diff] [blame] | 491 | // STREAM frame data is not encrypted. |
| 492 | QUIC_UNENCRYPTED_STREAM_DATA = 61, |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 493 | // RST_STREAM frame data is malformed. |
| 494 | QUIC_INVALID_RST_STREAM_DATA = 6, |
| 495 | // CONNECTION_CLOSE frame data is malformed. |
| 496 | QUIC_INVALID_CONNECTION_CLOSE_DATA = 7, |
| 497 | // GOAWAY frame data is malformed. |
| 498 | QUIC_INVALID_GOAWAY_DATA = 8, |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 499 | // WINDOW_UPDATE frame data is malformed. |
| 500 | QUIC_INVALID_WINDOW_UPDATE_DATA = 57, |
| 501 | // BLOCKED frame data is malformed. |
| 502 | QUIC_INVALID_BLOCKED_DATA = 58, |
[email protected] | 93dd91f | 2014-02-27 00:09:03 | [diff] [blame] | 503 | // STOP_WAITING frame data is malformed. |
| 504 | QUIC_INVALID_STOP_WAITING_DATA = 60, |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 505 | // ACK frame data is malformed. |
| 506 | QUIC_INVALID_ACK_DATA = 9, |
rtenneti | f4bdb54 | 2015-01-21 14:33:05 | [diff] [blame] | 507 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 508 | // Version negotiation packet is malformed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 509 | QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10, |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 510 | // Public RST packet is malformed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 511 | QUIC_INVALID_PUBLIC_RST_PACKET = 11, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 512 | // There was an error decrypting. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 513 | QUIC_DECRYPTION_FAILURE = 12, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 514 | // There was an error encrypting. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 515 | QUIC_ENCRYPTION_FAILURE = 13, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 516 | // The packet exceeded kMaxPacketSize. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 517 | QUIC_PACKET_TOO_LARGE = 14, |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 518 | // The peer is going away. May be a client or server. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 519 | QUIC_PEER_GOING_AWAY = 16, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 520 | // A stream ID was invalid. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 521 | QUIC_INVALID_STREAM_ID = 17, |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 522 | // A priority was invalid. |
| 523 | QUIC_INVALID_PRIORITY = 49, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 524 | // Too many streams already open. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 525 | QUIC_TOO_MANY_OPEN_STREAMS = 18, |
rtenneti | 159828f | 2015-10-13 06:58:09 | [diff] [blame] | 526 | // The peer created too many available streams. |
| 527 | QUIC_TOO_MANY_AVAILABLE_STREAMS = 76, |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 528 | // Received public reset for this connection. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 529 | QUIC_PUBLIC_RESET = 19, |
[email protected] | c244c5a1 | 2013-05-07 20:55:04 | [diff] [blame] | 530 | // Invalid protocol version. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 531 | QUIC_INVALID_VERSION = 20, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 532 | |
[email protected] | c244c5a1 | 2013-05-07 20:55:04 | [diff] [blame] | 533 | // The Header ID for a stream was too far from the previous. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 534 | QUIC_INVALID_HEADER_ID = 22, |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 535 | // Negotiable parameter received during handshake had invalid value. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 536 | QUIC_INVALID_NEGOTIATED_VALUE = 23, |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 537 | // There was an error decompressing data. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 538 | QUIC_DECOMPRESSION_FAILURE = 24, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 539 | // We hit our prenegotiated (or default) timeout |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 540 | QUIC_CONNECTION_TIMED_OUT = 25, |
rtenneti | 31e9fd6 | 2014-09-16 05:22:15 | [diff] [blame] | 541 | // We hit our overall connection timeout |
| 542 | QUIC_CONNECTION_OVERALL_TIMED_OUT = 67, |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 543 | // There was an error encountered migrating addresses |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 544 | QUIC_ERROR_MIGRATING_ADDRESS = 26, |
[email protected] | 1505a51 | 2013-09-04 22:59:35 | [diff] [blame] | 545 | // There was an error while writing to the socket. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 546 | QUIC_PACKET_WRITE_ERROR = 27, |
[email protected] | 1505a51 | 2013-09-04 22:59:35 | [diff] [blame] | 547 | // There was an error while reading from the socket. |
| 548 | QUIC_PACKET_READ_ERROR = 51, |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 549 | // We received a STREAM_FRAME with no data and no fin flag set. |
| 550 | QUIC_INVALID_STREAM_FRAME = 50, |
[email protected] | 4d64079 | 2013-12-18 22:21:08 | [diff] [blame] | 551 | // We received invalid data on the headers stream. |
| 552 | QUIC_INVALID_HEADERS_STREAM_DATA = 56, |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 553 | // The peer received too much data, violating flow control. |
| 554 | QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA = 59, |
| 555 | // The peer sent too much data, violating flow control. |
| 556 | QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA = 63, |
| 557 | // The peer received an invalid flow control window. |
| 558 | QUIC_FLOW_CONTROL_INVALID_WINDOW = 64, |
[email protected] | 71c84e59 | 2014-05-28 23:39:29 | [diff] [blame] | 559 | // The connection has been IP pooled into an existing connection. |
| 560 | QUIC_CONNECTION_IP_POOLED = 62, |
rtenneti | 2318668 | 2014-10-30 01:49:33 | [diff] [blame] | 561 | // The connection has too many outstanding sent packets. |
| 562 | QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS = 68, |
| 563 | // The connection has too many outstanding received packets. |
| 564 | QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS = 69, |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 565 | // The quic connection job to load server config is cancelled. |
| 566 | QUIC_CONNECTION_CANCELLED = 70, |
rtenneti | 85dcfac2 | 2015-03-27 20:22:19 | [diff] [blame] | 567 | // Disabled QUIC because of high packet loss rate. |
| 568 | QUIC_BAD_PACKET_LOSS_RATE = 71, |
ckrasic | 1e53b64 | 2015-07-08 22:39:35 | [diff] [blame] | 569 | // Disabled QUIC because of too many PUBLIC_RESETs post handshake. |
| 570 | QUIC_PUBLIC_RESETS_POST_HANDSHAKE = 73, |
| 571 | // Disabled QUIC because of too many timeouts with streams open. |
| 572 | QUIC_TIMEOUTS_WITH_OPEN_STREAMS = 74, |
rtenneti | 8811fdb | 2015-07-22 00:17:07 | [diff] [blame] | 573 | // Closed because we failed to serialize a packet. |
| 574 | QUIC_FAILED_TO_SERIALIZE_PACKET = 75, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 575 | |
| 576 | // Crypto errors. |
| 577 | |
[email protected] | 1354bf6 | 2013-05-23 23:17:18 | [diff] [blame] | 578 | // Hanshake failed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 579 | QUIC_HANDSHAKE_FAILED = 28, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 580 | // Handshake message contained out of order tags. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 581 | QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29, |
[email protected] | 701bc89 | 2013-01-17 04:51:54 | [diff] [blame] | 582 | // Handshake message contained too many entries. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 583 | QUIC_CRYPTO_TOO_MANY_ENTRIES = 30, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 584 | // Handshake message contained an invalid value length. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 585 | QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 586 | // A crypto message was received after the handshake was complete. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 587 | QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32, |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 588 | // A crypto message was received with an illegal message tag. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 589 | QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33, |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 590 | // A crypto message was received with an illegal parameter. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 591 | QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34, |
[email protected] | 752fbe5 | 2013-10-14 08:35:32 | [diff] [blame] | 592 | // An invalid channel id signature was supplied. |
| 593 | QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52, |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 594 | // A crypto message was received with a mandatory parameter missing. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 595 | QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35, |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 596 | // A crypto message was received with a parameter that has no overlap |
| 597 | // with the local parameter. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 598 | QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36, |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 599 | // A crypto message was received that contained a parameter with too few |
| 600 | // values. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 601 | QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37, |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 602 | // An internal error occured in crypto processing. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 603 | QUIC_CRYPTO_INTERNAL_ERROR = 38, |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 604 | // A crypto handshake message specified an unsupported version. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 605 | QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39, |
rtenneti | e0ee6eb | 2015-05-01 00:55:09 | [diff] [blame] | 606 | // A crypto handshake message resulted in a stateless reject. |
| 607 | QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT = 72, |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 608 | // There was no intersection between the crypto primitives supported by the |
| 609 | // peer and ourselves. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 610 | QUIC_CRYPTO_NO_SUPPORT = 40, |
[email protected] | ef95114d | 2013-04-17 17:57:01 | [diff] [blame] | 611 | // The server rejected our client hello messages too many times. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 612 | QUIC_CRYPTO_TOO_MANY_REJECTS = 41, |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 613 | // The client rejected the server's certificate chain or signature. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 614 | QUIC_PROOF_INVALID = 42, |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 615 | // A crypto message was received with a duplicate tag. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 616 | QUIC_CRYPTO_DUPLICATE_TAG = 43, |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 617 | // A crypto message was received with the wrong encryption level (i.e. it |
| 618 | // should have been encrypted but was not.) |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 619 | QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44, |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 620 | // The server config for a server has expired. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 621 | QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45, |
[email protected] | 752fbe5 | 2013-10-14 08:35:32 | [diff] [blame] | 622 | // We failed to setup the symmetric keys for a connection. |
| 623 | QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53, |
[email protected] | 691f45a98 | 2013-11-19 10:52:04 | [diff] [blame] | 624 | // A handshake message arrived, but we are still validating the |
| 625 | // previous handshake message. |
| 626 | QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54, |
[email protected] | ccb3421 | 2014-07-18 09:27:50 | [diff] [blame] | 627 | // A server config update arrived before the handshake is complete. |
| 628 | QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE = 65, |
[email protected] | d89f186 | 2013-11-26 21:21:27 | [diff] [blame] | 629 | // This connection involved a version negotiation which appears to have been |
| 630 | // tampered with. |
| 631 | QUIC_VERSION_NEGOTIATION_MISMATCH = 55, |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 632 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 633 | // No error. Used as bound while iterating. |
rtenneti | 159828f | 2015-10-13 06:58:09 | [diff] [blame] | 634 | QUIC_LAST_ERROR = 77, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 635 | }; |
| 636 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 637 | struct NET_EXPORT_PRIVATE QuicPacketPublicHeader { |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 638 | QuicPacketPublicHeader(); |
| 639 | explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other); |
| 640 | ~QuicPacketPublicHeader(); |
| 641 | |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 642 | // Universal header. All QuicPacket headers will have a connection_id and |
| 643 | // public flags. |
| 644 | QuicConnectionId connection_id; |
| 645 | QuicConnectionIdLength connection_id_length; |
zhongyi | b867702 | 2015-12-01 05:51:30 | [diff] [blame^] | 646 | bool multipath_flag; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 647 | bool reset_flag; |
| 648 | bool version_flag; |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 649 | QuicPacketNumberLength packet_number_length; |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 650 | QuicVersionVector versions; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 651 | }; |
| 652 | |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 653 | // An integer which cannot be a packet number. |
| 654 | const QuicPacketNumber kInvalidPacketNumber = 0; |
rtenneti | 9e0fb50 | 2015-03-08 06:07:16 | [diff] [blame] | 655 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 656 | // Header for Data or FEC packets. |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 657 | struct NET_EXPORT_PRIVATE QuicPacketHeader { |
| 658 | QuicPacketHeader(); |
| 659 | explicit QuicPacketHeader(const QuicPacketPublicHeader& header); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 660 | |
| 661 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 662 | std::ostream& os, const QuicPacketHeader& s); |
| 663 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 664 | QuicPacketPublicHeader public_header; |
zhongyi | b867702 | 2015-12-01 05:51:30 | [diff] [blame^] | 665 | QuicPathId path_id; |
rtenneti | 8dd12b2 | 2015-10-21 01:26:38 | [diff] [blame] | 666 | QuicPacketNumber packet_number; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 667 | bool fec_flag; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 668 | bool entropy_flag; |
| 669 | QuicPacketEntropyHash entropy_hash; |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 670 | InFecGroup is_in_fec_group; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 671 | QuicFecGroupNumber fec_group; |
| 672 | }; |
| 673 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 674 | struct NET_EXPORT_PRIVATE QuicPublicResetPacket { |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 675 | QuicPublicResetPacket(); |
| 676 | explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header); |
| 677 | |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 678 | QuicPacketPublicHeader public_header; |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 679 | QuicPublicResetNonceProof nonce_proof; |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 680 | QuicPacketNumber rejected_packet_number; |
[email protected] | 79d13dcb | 2014-02-05 07:23:13 | [diff] [blame] | 681 | IPEndPoint client_address; |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 682 | }; |
| 683 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 684 | enum QuicVersionNegotiationState { |
| 685 | START_NEGOTIATION = 0, |
[email protected] | ec64011 | 2013-08-09 03:56:18 | [diff] [blame] | 686 | // Server-side this implies we've sent a version negotiation packet and are |
| 687 | // waiting on the client to select a compatible version. Client-side this |
| 688 | // implies we've gotten a version negotiation packet, are retransmitting the |
| 689 | // initial packets with a supported version and are waiting for our first |
| 690 | // packet from the server. |
| 691 | NEGOTIATION_IN_PROGRESS, |
| 692 | // This indicates this endpoint has received a packet from the peer with a |
| 693 | // version this endpoint supports. Version negotiation is complete, and the |
| 694 | // version number will no longer be sent with future packets. |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 695 | NEGOTIATED_VERSION |
| 696 | }; |
| 697 | |
| 698 | typedef QuicPacketPublicHeader QuicVersionNegotiationPacket; |
| 699 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 700 | // A padding frame contains no payload. |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 701 | struct NET_EXPORT_PRIVATE QuicPaddingFrame {}; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 702 | |
[email protected] | d8c52211 | 2014-04-23 09:23:25 | [diff] [blame] | 703 | // A ping frame contains no payload, though it is retransmittable, |
| 704 | // and ACK'd just like other normal frames. |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 705 | struct NET_EXPORT_PRIVATE QuicPingFrame {}; |
[email protected] | d8c52211 | 2014-04-23 09:23:25 | [diff] [blame] | 706 | |
rtenneti | 69e64aa | 2015-06-26 04:25:30 | [diff] [blame] | 707 | // A path MTU discovery frame contains no payload and is serialized as a ping |
| 708 | // frame. |
| 709 | struct NET_EXPORT_PRIVATE QuicMtuDiscoveryFrame {}; |
| 710 | |
rtenneti | f60c32d8 | 2015-10-14 00:07:00 | [diff] [blame] | 711 | typedef scoped_ptr<char[]> UniqueStreamBuffer; |
| 712 | |
| 713 | // Allocates memory of size |size| for a QUIC stream buffer. |
| 714 | UniqueStreamBuffer NewStreamBuffer(size_t size); |
| 715 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 716 | struct NET_EXPORT_PRIVATE QuicStreamFrame { |
| 717 | QuicStreamFrame(); |
[email protected] | 5dafdb6 | 2013-11-14 01:24:26 | [diff] [blame] | 718 | QuicStreamFrame(const QuicStreamFrame& frame); |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 719 | QuicStreamFrame(QuicStreamId stream_id, |
[email protected] | a506124 | 2012-10-23 23:29:37 | [diff] [blame] | 720 | bool fin, |
[email protected] | 701bc89 | 2013-01-17 04:51:54 | [diff] [blame] | 721 | QuicStreamOffset offset, |
rtenneti | a4228ea | 2015-06-04 02:31:44 | [diff] [blame] | 722 | base::StringPiece data); |
[email protected] | 5dafdb6 | 2013-11-14 01:24:26 | [diff] [blame] | 723 | |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 724 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 725 | std::ostream& os, const QuicStreamFrame& s); |
| 726 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 727 | QuicStreamId stream_id; |
| 728 | bool fin; |
[email protected] | 701bc89 | 2013-01-17 04:51:54 | [diff] [blame] | 729 | QuicStreamOffset offset; // Location of this data in the stream. |
rtenneti | a4228ea | 2015-06-04 02:31:44 | [diff] [blame] | 730 | base::StringPiece data; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 731 | }; |
| 732 | |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 733 | // TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing |
| 734 | // is finalized. |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 735 | typedef std::set<QuicPacketNumber> PacketNumberSet; |
| 736 | typedef std::list<QuicPacketNumber> PacketNumberList; |
rtenneti | 4b06ae7 | 2014-08-26 03:43:43 | [diff] [blame] | 737 | |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 738 | typedef std::vector<std::pair<QuicPacketNumber, QuicTime>> PacketTimeVector; |
[email protected] | 044ac2b | 2012-11-13 21:41:06 | [diff] [blame] | 739 | |
[email protected] | 310d37b | 2014-08-02 06:15:37 | [diff] [blame] | 740 | struct NET_EXPORT_PRIVATE QuicStopWaitingFrame { |
| 741 | QuicStopWaitingFrame(); |
| 742 | ~QuicStopWaitingFrame(); |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 743 | |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 744 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
[email protected] | 310d37b | 2014-08-02 06:15:37 | [diff] [blame] | 745 | std::ostream& os, const QuicStopWaitingFrame& s); |
| 746 | // Entropy hash of all packets up to, but not including, the least unacked |
| 747 | // packet. |
| 748 | QuicPacketEntropyHash entropy_hash; |
| 749 | // The lowest packet we've sent which is unacked, and we expect an ack for. |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 750 | QuicPacketNumber least_unacked; |
[email protected] | 310d37b | 2014-08-02 06:15:37 | [diff] [blame] | 751 | }; |
| 752 | |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 753 | // A sequence of packet numbers where each number is unique. Intended to be used |
| 754 | // in a sliding window fashion, where smaller old packet numbers are removed and |
| 755 | // larger new packet numbers are added, with the occasional random access. |
| 756 | class NET_EXPORT_PRIVATE PacketNumberQueue { |
| 757 | public: |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 758 | // TODO(jdorfman): remove const_iterator and change the callers to |
| 759 | // iterate over the intervals. |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 760 | class NET_EXPORT_PRIVATE const_iterator |
| 761 | : public std::iterator<std::input_iterator_tag, |
| 762 | QuicPacketNumber, |
| 763 | std::ptrdiff_t, |
| 764 | const QuicPacketNumber*, |
| 765 | const QuicPacketNumber&> { |
| 766 | public: |
| 767 | explicit const_iterator(PacketNumberSet::const_iterator set_iter); |
| 768 | const_iterator( |
| 769 | IntervalSet<QuicPacketNumber>::const_iterator interval_set_iter, |
| 770 | QuicPacketNumber first, |
| 771 | QuicPacketNumber last); |
| 772 | const_iterator(const const_iterator& other); |
| 773 | const_iterator& operator=(const const_iterator& other); |
| 774 | // TODO(rtenneti): on windows RValue reference gives errors. |
| 775 | // const_iterator(const_iterator&& other); |
| 776 | ~const_iterator(); |
| 777 | |
| 778 | // TODO(rtenneti): on windows RValue reference gives errors. |
| 779 | // const_iterator& operator=(const_iterator&& other); |
| 780 | bool operator!=(const const_iterator& other) const; |
| 781 | bool operator==(const const_iterator& other) const; |
| 782 | value_type operator*() const; |
| 783 | const_iterator& operator++(); |
| 784 | const_iterator operator++(int /* postincrement */); |
| 785 | |
| 786 | private: |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 787 | IntervalSet<QuicPacketNumber>::const_iterator interval_set_iter_; |
| 788 | QuicPacketNumber current_; |
| 789 | QuicPacketNumber last_; |
| 790 | }; |
| 791 | |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 792 | PacketNumberQueue(); |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 793 | PacketNumberQueue(const PacketNumberQueue& other); |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 794 | // TODO(rtenneti): on windows RValue reference gives errors. |
| 795 | // PacketNumberQueue(PacketNumberQueue&& other); |
rtenneti | 93209a0 | 2015-09-19 01:51:18 | [diff] [blame] | 796 | ~PacketNumberQueue(); |
| 797 | |
| 798 | PacketNumberQueue& operator=(const PacketNumberQueue& other); |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 799 | // PacketNumberQueue& operator=(PacketNumberQueue&& other); |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 800 | |
| 801 | // Adds |packet_number| to the set of packets in the queue. |
| 802 | void Add(QuicPacketNumber packet_number); |
| 803 | |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 804 | // Adds packets between [lower, higher) to the set of packets in the queue. It |
| 805 | // is undefined behavior to call this with |higher| < |lower|. |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 806 | void Add(QuicPacketNumber lower, QuicPacketNumber higher); |
| 807 | |
| 808 | // Removes |packet_number| from the set of packets in the queue. |
| 809 | void Remove(QuicPacketNumber packet_number); |
| 810 | |
| 811 | // Removes packets with values less than |higher| from the set of packets in |
| 812 | // the queue. Returns true if packets were removed. |
| 813 | bool RemoveUpTo(QuicPacketNumber higher); |
| 814 | |
| 815 | // Returns true if the queue contains |packet_number|. |
| 816 | bool Contains(QuicPacketNumber packet_number) const; |
| 817 | |
| 818 | // Returns true if the queue is empty. |
| 819 | bool Empty() const; |
| 820 | |
| 821 | // Returns the minimum packet number stored in the queue. It is undefined |
| 822 | // behavior to call this if the queue is empty. |
| 823 | QuicPacketNumber Min() const; |
| 824 | |
| 825 | // Returns the maximum packet number stored in the queue. It is undefined |
| 826 | // behavior to call this if the queue is empty. |
| 827 | QuicPacketNumber Max() const; |
| 828 | |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 829 | // Returns the number of unique packets stored in the queue. Inefficient; only |
| 830 | // exposed for testing. |
| 831 | size_t NumPacketsSlow() const; |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 832 | |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 833 | // Returns iterators over the individual packet numbers. |
| 834 | const_iterator begin() const; |
| 835 | const_iterator end() const; |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 836 | const_iterator lower_bound(QuicPacketNumber packet_number) const; |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 837 | |
| 838 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 839 | std::ostream& os, |
| 840 | const PacketNumberQueue& q); |
| 841 | |
| 842 | private: |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 843 | IntervalSet<QuicPacketNumber> packet_number_intervals_; |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 844 | }; |
| 845 | |
[email protected] | 310d37b | 2014-08-02 06:15:37 | [diff] [blame] | 846 | struct NET_EXPORT_PRIVATE QuicAckFrame { |
| 847 | QuicAckFrame(); |
| 848 | ~QuicAckFrame(); |
| 849 | |
| 850 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 851 | std::ostream& os, const QuicAckFrame& s); |
[email protected] | a674b4c | 2012-12-05 03:44:30 | [diff] [blame] | 852 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 853 | // Entropy hash of all packets up to largest observed not including missing |
| 854 | // packets. |
| 855 | QuicPacketEntropyHash entropy_hash; |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 856 | |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 857 | // Whether the ack had to be truncated when sent. |
| 858 | bool is_truncated; |
| 859 | |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 860 | // The highest packet number we've observed from the peer. |
[email protected] | 48697d8a | 2013-01-15 19:42:24 | [diff] [blame] | 861 | // |
| 862 | // In general, this should be the largest packet number we've received. In |
| 863 | // the case of truncated acks, we may have to advertise a lower "upper bound" |
| 864 | // than largest received, to avoid implicitly acking missing packets that |
| 865 | // don't fit in the missing packet list due to size limitations. In this |
| 866 | // case, largest_observed may be a packet which is also in the missing packets |
| 867 | // list. |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 868 | QuicPacketNumber largest_observed; |
[email protected] | a674b4c | 2012-12-05 03:44:30 | [diff] [blame] | 869 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 870 | // Time elapsed since largest_observed was received until this Ack frame was |
| 871 | // sent. |
| 872 | QuicTime::Delta delta_time_largest_observed; |
| 873 | |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 874 | // Vector of <packet_number, time> for when packets arrived. |
| 875 | PacketTimeVector received_packet_times; |
| 876 | |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 877 | // The set of packets which we're expecting and have not received. |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 878 | PacketNumberQueue missing_packets; |
[email protected] | 8e01c06 | 2013-10-31 07:35:31 | [diff] [blame] | 879 | |
rch | 99b644c | 2015-11-04 05:25:28 | [diff] [blame] | 880 | // Packet most recently revived via FEC, 0 if no packet was revived by FEC. |
| 881 | // If non-zero, must be present in missing_packets. |
| 882 | QuicPacketNumber latest_revived_packet; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 883 | }; |
| 884 | |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 885 | // True if the packet number is greater than largest_observed or is listed |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 886 | // as missing. |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 887 | // Always returns false for packet numbers less than least_unacked. |
| 888 | bool NET_EXPORT_PRIVATE IsAwaitingPacket(const QuicAckFrame& ack_frame, |
| 889 | QuicPacketNumber packet_number); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 890 | |
[email protected] | a692ad9d | 2014-07-18 21:35:24 | [diff] [blame] | 891 | // Defines for all types of congestion control algorithms that can be used in |
| 892 | // QUIC. Note that this is separate from the congestion feedback type - |
| 893 | // some congestion control algorithms may use the same feedback type |
| 894 | // (Reno and Cubic are the classic example for that). |
| 895 | enum CongestionControlType { |
| 896 | kCubic, |
rtenneti | fb3fa6c | 2015-03-16 23:04:55 | [diff] [blame] | 897 | kCubicBytes, |
[email protected] | a692ad9d | 2014-07-18 21:35:24 | [diff] [blame] | 898 | kReno, |
rtenneti | fb3fa6c | 2015-03-16 23:04:55 | [diff] [blame] | 899 | kRenoBytes, |
[email protected] | a692ad9d | 2014-07-18 21:35:24 | [diff] [blame] | 900 | kBBR, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 901 | }; |
| 902 | |
[email protected] | c5cc9bd | 2014-03-31 23:17:14 | [diff] [blame] | 903 | enum LossDetectionType { |
| 904 | kNack, // Used to mimic TCP's loss detection. |
| 905 | kTime, // Time based loss detection. |
| 906 | }; |
| 907 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 908 | struct NET_EXPORT_PRIVATE QuicRstStreamFrame { |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 909 | QuicRstStreamFrame(); |
| 910 | QuicRstStreamFrame(QuicStreamId stream_id, |
| 911 | QuicRstStreamErrorCode error_code, |
| 912 | QuicStreamOffset bytes_written); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 913 | |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 914 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 915 | std::ostream& os, const QuicRstStreamFrame& r); |
| 916 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 917 | QuicStreamId stream_id; |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 918 | QuicRstStreamErrorCode error_code; |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 919 | |
| 920 | // Used to update flow control windows. On termination of a stream, both |
| 921 | // endpoints must inform the peer of the number of bytes they have sent on |
| 922 | // that stream. This can be done through normal termination (data packet with |
| 923 | // FIN) or through a RST. |
| 924 | QuicStreamOffset byte_offset; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 925 | }; |
| 926 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 927 | struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame { |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 928 | QuicConnectionCloseFrame(); |
| 929 | |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 930 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 931 | std::ostream& os, const QuicConnectionCloseFrame& c); |
| 932 | |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 933 | QuicErrorCode error_code; |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 934 | std::string error_details; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 935 | }; |
| 936 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 937 | struct NET_EXPORT_PRIVATE QuicGoAwayFrame { |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 938 | QuicGoAwayFrame(); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 939 | QuicGoAwayFrame(QuicErrorCode error_code, |
| 940 | QuicStreamId last_good_stream_id, |
| 941 | const std::string& reason); |
| 942 | |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 943 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 944 | std::ostream& os, const QuicGoAwayFrame& g); |
| 945 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 946 | QuicErrorCode error_code; |
| 947 | QuicStreamId last_good_stream_id; |
| 948 | std::string reason_phrase; |
| 949 | }; |
| 950 | |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 951 | // Flow control updates per-stream and at the connection levoel. |
| 952 | // Based on SPDY's WINDOW_UPDATE frame, but uses an absolute byte offset rather |
| 953 | // than a window delta. |
| 954 | // TODO(rjshade): A possible future optimization is to make stream_id and |
| 955 | // byte_offset variable length, similar to stream frames. |
| 956 | struct NET_EXPORT_PRIVATE QuicWindowUpdateFrame { |
| 957 | QuicWindowUpdateFrame() {} |
| 958 | QuicWindowUpdateFrame(QuicStreamId stream_id, QuicStreamOffset byte_offset); |
| 959 | |
| 960 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 961 | std::ostream& os, const QuicWindowUpdateFrame& w); |
| 962 | |
| 963 | // The stream this frame applies to. 0 is a special case meaning the overall |
| 964 | // connection rather than a specific stream. |
| 965 | QuicStreamId stream_id; |
| 966 | |
| 967 | // Byte offset in the stream or connection. The receiver of this frame must |
| 968 | // not send data which would result in this offset being exceeded. |
| 969 | QuicStreamOffset byte_offset; |
| 970 | }; |
| 971 | |
| 972 | // The BLOCKED frame is used to indicate to the remote endpoint that this |
| 973 | // endpoint believes itself to be flow-control blocked but otherwise ready to |
| 974 | // send data. The BLOCKED frame is purely advisory and optional. |
| 975 | // Based on SPDY's BLOCKED frame (undocumented as of 2014-01-28). |
| 976 | struct NET_EXPORT_PRIVATE QuicBlockedFrame { |
| 977 | QuicBlockedFrame() {} |
| 978 | explicit QuicBlockedFrame(QuicStreamId stream_id); |
| 979 | |
| 980 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 981 | std::ostream& os, const QuicBlockedFrame& b); |
| 982 | |
| 983 | // The stream this frame applies to. 0 is a special case meaning the overall |
| 984 | // connection rather than a specific stream. |
| 985 | QuicStreamId stream_id; |
| 986 | }; |
| 987 | |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 988 | // EncryptionLevel enumerates the stages of encryption that a QUIC connection |
| 989 | // progresses through. When retransmitting a packet, the encryption level needs |
| 990 | // to be specified so that it is retransmitted at a level which the peer can |
| 991 | // understand. |
| 992 | enum EncryptionLevel { |
| 993 | ENCRYPTION_NONE = 0, |
| 994 | ENCRYPTION_INITIAL = 1, |
| 995 | ENCRYPTION_FORWARD_SECURE = 2, |
| 996 | |
| 997 | NUM_ENCRYPTION_LEVELS, |
| 998 | }; |
| 999 | |
rch | 99b644c | 2015-11-04 05:25:28 | [diff] [blame] | 1000 | enum PeerAddressChangeType { |
| 1001 | NO_CHANGE, |
| 1002 | // Peer address changes which are considered to be cause by NATs. Currently, |
| 1003 | // IPv4 address change with /24 does not change is considered to be cause by |
| 1004 | // NATs. |
| 1005 | NAT_PORT_REBINDING, |
| 1006 | IPV4_SUBNET_REBINDING, |
| 1007 | // IPv6 related address changes. |
| 1008 | IPV4_TO_IPV6, |
| 1009 | IPV6_TO_IPV4, |
| 1010 | IPV6_TO_IPV6, |
| 1011 | // This type is used when we always allow peer address changes. |
| 1012 | UNKNOWN, |
| 1013 | // All other peer address change types. |
| 1014 | UNSPECIFIED, |
| 1015 | }; |
| 1016 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 1017 | struct NET_EXPORT_PRIVATE QuicFrame { |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1018 | QuicFrame(); |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 1019 | explicit QuicFrame(QuicPaddingFrame padding_frame); |
| 1020 | explicit QuicFrame(QuicMtuDiscoveryFrame frame); |
| 1021 | explicit QuicFrame(QuicPingFrame frame); |
| 1022 | |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1023 | explicit QuicFrame(QuicStreamFrame* stream_frame); |
| 1024 | explicit QuicFrame(QuicAckFrame* frame); |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1025 | explicit QuicFrame(QuicRstStreamFrame* frame); |
| 1026 | explicit QuicFrame(QuicConnectionCloseFrame* frame); |
[email protected] | 93dd91f | 2014-02-27 00:09:03 | [diff] [blame] | 1027 | explicit QuicFrame(QuicStopWaitingFrame* frame); |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1028 | explicit QuicFrame(QuicGoAwayFrame* frame); |
| 1029 | explicit QuicFrame(QuicWindowUpdateFrame* frame); |
| 1030 | explicit QuicFrame(QuicBlockedFrame* frame); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1031 | |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 1032 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 1033 | std::ostream& os, const QuicFrame& frame); |
| 1034 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 1035 | QuicFrameType type; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1036 | union { |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 1037 | // Frames smaller than a pointer are inline. |
| 1038 | QuicPaddingFrame padding_frame; |
| 1039 | QuicMtuDiscoveryFrame mtu_discovery_frame; |
| 1040 | QuicPingFrame ping_frame; |
| 1041 | |
| 1042 | // Frames larger than a pointer. |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 1043 | QuicStreamFrame* stream_frame; |
| 1044 | QuicAckFrame* ack_frame; |
[email protected] | 93dd91f | 2014-02-27 00:09:03 | [diff] [blame] | 1045 | QuicStopWaitingFrame* stop_waiting_frame; |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 1046 | QuicRstStreamFrame* rst_stream_frame; |
| 1047 | QuicConnectionCloseFrame* connection_close_frame; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1048 | QuicGoAwayFrame* goaway_frame; |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1049 | QuicWindowUpdateFrame* window_update_frame; |
| 1050 | QuicBlockedFrame* blocked_frame; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1051 | }; |
| 1052 | }; |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 1053 | // QuicFrameType consumes 8 bytes with padding. |
| 1054 | static_assert(sizeof(QuicFrame) <= 16, |
| 1055 | "Frames larger than 8 bytes should be referenced by pointer."); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1056 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 1057 | typedef std::vector<QuicFrame> QuicFrames; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1058 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1059 | class NET_EXPORT_PRIVATE QuicData { |
| 1060 | public: |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1061 | QuicData(const char* buffer, size_t length); |
| 1062 | QuicData(char* buffer, size_t length, bool owns_buffer); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1063 | virtual ~QuicData(); |
| 1064 | |
| 1065 | base::StringPiece AsStringPiece() const { |
| 1066 | return base::StringPiece(data(), length()); |
| 1067 | } |
| 1068 | |
| 1069 | const char* data() const { return buffer_; } |
| 1070 | size_t length() const { return length_; } |
rtenneti | e0ee6eb | 2015-05-01 00:55:09 | [diff] [blame] | 1071 | bool owns_buffer() const { return owns_buffer_; } |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1072 | |
| 1073 | private: |
| 1074 | const char* buffer_; |
| 1075 | size_t length_; |
| 1076 | bool owns_buffer_; |
| 1077 | |
| 1078 | DISALLOW_COPY_AND_ASSIGN(QuicData); |
| 1079 | }; |
| 1080 | |
| 1081 | class NET_EXPORT_PRIVATE QuicPacket : public QuicData { |
| 1082 | public: |
rtenneti | ca5ac27 | 2015-02-07 12:35:12 | [diff] [blame] | 1083 | QuicPacket(char* buffer, |
| 1084 | size_t length, |
| 1085 | bool owns_buffer, |
| 1086 | QuicConnectionIdLength connection_id_length, |
| 1087 | bool includes_version, |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 1088 | QuicPacketNumberLength packet_number_length); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1089 | |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 1090 | base::StringPiece FecProtectedData() const; |
| 1091 | base::StringPiece AssociatedData() const; |
| 1092 | base::StringPiece BeforePlaintext() const; |
| 1093 | base::StringPiece Plaintext() const; |
[email protected] | 082b65b | 2012-11-10 19:11:31 | [diff] [blame] | 1094 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1095 | char* mutable_data() { return buffer_; } |
| 1096 | |
| 1097 | private: |
| 1098 | char* buffer_; |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 1099 | const QuicConnectionIdLength connection_id_length_; |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 1100 | const bool includes_version_; |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 1101 | const QuicPacketNumberLength packet_number_length_; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1102 | |
[email protected] | 2e740db | 2012-10-20 19:35:19 | [diff] [blame] | 1103 | DISALLOW_COPY_AND_ASSIGN(QuicPacket); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1104 | }; |
| 1105 | |
| 1106 | class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData { |
| 1107 | public: |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1108 | QuicEncryptedPacket(const char* buffer, size_t length); |
| 1109 | QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1110 | |
[email protected] | ec86d546 | 2013-11-17 16:04:49 | [diff] [blame] | 1111 | // Clones the packet into a new packet which owns the buffer. |
| 1112 | QuicEncryptedPacket* Clone() const; |
| 1113 | |
[email protected] | c1b32c6 | 2013-01-20 02:49:10 | [diff] [blame] | 1114 | // By default, gtest prints the raw bytes of an object. The bool data |
| 1115 | // member (in the base class QuicData) causes this object to have padding |
| 1116 | // bytes, which causes the default gtest object printer to read |
| 1117 | // uninitialize memory. So we need to teach gtest how to print this object. |
| 1118 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 1119 | std::ostream& os, const QuicEncryptedPacket& s); |
| 1120 | |
[email protected] | 2e740db | 2012-10-20 19:35:19 | [diff] [blame] | 1121 | private: |
| 1122 | DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1123 | }; |
| 1124 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1125 | class NET_EXPORT_PRIVATE RetransmittableFrames { |
| 1126 | public: |
rtenneti | dc8e5a2 | 2015-02-25 01:38:52 | [diff] [blame] | 1127 | explicit RetransmittableFrames(EncryptionLevel level); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1128 | ~RetransmittableFrames(); |
| 1129 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1130 | // Takes ownership of the frame inside |frame|. |
rtenneti | a4228ea | 2015-06-04 02:31:44 | [diff] [blame] | 1131 | const QuicFrame& AddFrame(const QuicFrame& frame); |
| 1132 | // Takes ownership of the frame inside |frame| and |buffer|. |
rtenneti | f60c32d8 | 2015-10-14 00:07:00 | [diff] [blame] | 1133 | const QuicFrame& AddFrame(const QuicFrame& frame, UniqueStreamBuffer buffer); |
rtenneti | 73e25c1 | 2015-03-16 06:12:43 | [diff] [blame] | 1134 | // Removes all stream frames associated with |stream_id|. |
| 1135 | void RemoveFramesForStream(QuicStreamId stream_id); |
| 1136 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1137 | const QuicFrames& frames() const { return frames_; } |
| 1138 | |
[email protected] | 672631c | 2014-08-16 06:11:45 | [diff] [blame] | 1139 | IsHandshake HasCryptoHandshake() const { |
| 1140 | return has_crypto_handshake_; |
| 1141 | } |
[email protected] | 2115d33ba | 2014-01-02 21:53:52 | [diff] [blame] | 1142 | |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 1143 | EncryptionLevel encryption_level() const { |
| 1144 | return encryption_level_; |
| 1145 | } |
| 1146 | |
rtenneti | d7d78b0 | 2015-06-17 16:54:34 | [diff] [blame] | 1147 | bool needs_padding() const { return needs_padding_; } |
| 1148 | |
| 1149 | void set_needs_padding(bool needs_padding) { needs_padding_ = needs_padding; } |
| 1150 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1151 | private: |
| 1152 | QuicFrames frames_; |
rtenneti | dc8e5a2 | 2015-02-25 01:38:52 | [diff] [blame] | 1153 | const EncryptionLevel encryption_level_; |
[email protected] | 672631c | 2014-08-16 06:11:45 | [diff] [blame] | 1154 | IsHandshake has_crypto_handshake_; |
rtenneti | d7d78b0 | 2015-06-17 16:54:34 | [diff] [blame] | 1155 | bool needs_padding_; |
rtenneti | c14c8ab | 2015-06-18 05:47:40 | [diff] [blame] | 1156 | // Data referenced by the StringPiece of a QuicStreamFrame. |
rtenneti | f60c32d8 | 2015-10-14 00:07:00 | [diff] [blame] | 1157 | // |
| 1158 | // TODO(rtenneti): Change const char* to UniqueStreamBuffer once chrome has |
| 1159 | // c++11 library support. |
| 1160 | // std::vector<UniqueStreamBuffer> stream_data_; |
rtenneti | a4228ea | 2015-06-04 02:31:44 | [diff] [blame] | 1161 | std::vector<const char*> stream_data_; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1162 | |
| 1163 | DISALLOW_COPY_AND_ASSIGN(RetransmittableFrames); |
| 1164 | }; |
| 1165 | |
rtenneti | 8dd12b2 | 2015-10-21 01:26:38 | [diff] [blame] | 1166 | struct NET_EXPORT_PRIVATE AckListenerWrapper { |
| 1167 | AckListenerWrapper(QuicAckListenerInterface* listener, |
| 1168 | QuicPacketLength data_length); |
| 1169 | ~AckListenerWrapper(); |
| 1170 | |
| 1171 | scoped_refptr<QuicAckListenerInterface> ack_listener; |
| 1172 | QuicPacketLength length; |
| 1173 | }; |
| 1174 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1175 | struct NET_EXPORT_PRIVATE SerializedPacket { |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 1176 | SerializedPacket(QuicPacketNumber packet_number, |
| 1177 | QuicPacketNumberLength packet_number_length, |
rtenneti | b6ac61a5 | 2015-02-11 20:20:52 | [diff] [blame] | 1178 | QuicEncryptedPacket* packet, |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1179 | QuicPacketEntropyHash entropy_hash, |
rtenneti | 9bd5d4b | 2015-08-21 05:44:52 | [diff] [blame] | 1180 | RetransmittableFrames* retransmittable_frames, |
| 1181 | bool has_ack, |
| 1182 | bool has_stop_waiting); |
rch | 99b644c | 2015-11-04 05:25:28 | [diff] [blame] | 1183 | SerializedPacket(QuicPacketNumber packet_number, |
| 1184 | QuicPacketNumberLength packet_number_length, |
| 1185 | char* encrypted_buffer, |
| 1186 | size_t encrypted_length, |
| 1187 | bool owns_buffer, |
| 1188 | QuicPacketEntropyHash entropy_hash, |
| 1189 | RetransmittableFrames* retransmittable_frames, |
| 1190 | bool has_ack, |
| 1191 | bool has_stop_waiting); |
[email protected] | 97cf302 | 2013-09-05 14:30:16 | [diff] [blame] | 1192 | ~SerializedPacket(); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1193 | |
rtenneti | d39bd76 | 2015-06-12 01:05:52 | [diff] [blame] | 1194 | QuicEncryptedPacket* packet; |
| 1195 | RetransmittableFrames* retransmittable_frames; |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 1196 | QuicPacketNumber packet_number; |
| 1197 | QuicPacketNumberLength packet_number_length; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1198 | QuicPacketEntropyHash entropy_hash; |
rtenneti | ca5ac27 | 2015-02-07 12:35:12 | [diff] [blame] | 1199 | bool is_fec_packet; |
rtenneti | 9bd5d4b | 2015-08-21 05:44:52 | [diff] [blame] | 1200 | bool has_ack; |
| 1201 | bool has_stop_waiting; |
[email protected] | 97cf302 | 2013-09-05 14:30:16 | [diff] [blame] | 1202 | |
rtenneti | 6b1c5b1 | 2015-01-13 20:08:35 | [diff] [blame] | 1203 | // Optional notifiers which will be informed when this packet has been ACKed. |
rtenneti | 8dd12b2 | 2015-10-21 01:26:38 | [diff] [blame] | 1204 | std::list<AckListenerWrapper> listeners; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1205 | }; |
| 1206 | |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 1207 | struct NET_EXPORT_PRIVATE TransmissionInfo { |
| 1208 | // Used by STL when assigning into a map. |
| 1209 | TransmissionInfo(); |
| 1210 | |
| 1211 | // Constructs a Transmission with a new all_tranmissions set |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 1212 | // containing |packet_number|. |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 1213 | TransmissionInfo(RetransmittableFrames* retransmittable_frames, |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 1214 | QuicPacketNumberLength packet_number_length, |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 1215 | TransmissionType transmission_type, |
rtenneti | 3183ac4 | 2015-02-28 03:39:41 | [diff] [blame] | 1216 | QuicTime sent_time, |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 1217 | QuicPacketLength bytes_sent, |
rtenneti | 3183ac4 | 2015-02-28 03:39:41 | [diff] [blame] | 1218 | bool is_fec_packet); |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 1219 | |
rtenneti | 8dd12b2 | 2015-10-21 01:26:38 | [diff] [blame] | 1220 | ~TransmissionInfo(); |
| 1221 | |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 1222 | RetransmittableFrames* retransmittable_frames; |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 1223 | QuicPacketNumberLength packet_number_length; |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 1224 | QuicPacketLength bytes_sent; |
| 1225 | uint16 nack_count; |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 1226 | QuicTime sent_time; |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 1227 | // Reason why this packet was transmitted. |
| 1228 | TransmissionType transmission_type; |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 1229 | // In flight packets have not been abandoned or lost. |
| 1230 | bool in_flight; |
rtenneti | 31e9fd6 | 2014-09-16 05:22:15 | [diff] [blame] | 1231 | // True if the packet can never be acked, so it can be removed. |
| 1232 | bool is_unackable; |
rtenneti | 85d8971 | 2014-11-20 03:32:24 | [diff] [blame] | 1233 | // True if the packet is an FEC packet. |
| 1234 | bool is_fec_packet; |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 1235 | // Stores the packet numbers of all transmissions of this packet. |
| 1236 | // Must always be nullptr or have multiple elements. |
zhongyi | 1fb9bc5 | 2015-11-24 23:09:42 | [diff] [blame] | 1237 | // TODO(ianswett): Deprecate with quic_track_single_retransmission. |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 1238 | PacketNumberList* all_transmissions; |
zhongyi | 1fb9bc5 | 2015-11-24 23:09:42 | [diff] [blame] | 1239 | // Stores the packet number of the next retransmission of this packet. |
| 1240 | // Zero if the packet has not been retransmitted. |
| 1241 | QuicPacketNumber retransmission; |
rtenneti | 8dd12b2 | 2015-10-21 01:26:38 | [diff] [blame] | 1242 | // Non-empty if there is a listener for this packet. |
| 1243 | std::list<AckListenerWrapper> ack_listeners; |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 1244 | }; |
rtenneti | 8dd12b2 | 2015-10-21 01:26:38 | [diff] [blame] | 1245 | static_assert(sizeof(QuicFrame) <= 64, |
| 1246 | "Keep the TransmissionInfo size to a cacheline."); |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 1247 | |
rtenneti | c14c8ab | 2015-06-18 05:47:40 | [diff] [blame] | 1248 | // Convenience wrapper to wrap an iovec array and the total length, which must |
| 1249 | // be less than or equal to the actual total length of the iovecs. |
| 1250 | struct NET_EXPORT_PRIVATE QuicIOVector { |
| 1251 | QuicIOVector(const struct iovec* iov, int iov_count, size_t total_length) |
| 1252 | : iov(iov), iov_count(iov_count), total_length(total_length) {} |
| 1253 | |
| 1254 | const struct iovec* iov; |
| 1255 | const int iov_count; |
| 1256 | const size_t total_length; |
| 1257 | }; |
| 1258 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1259 | } // namespace net |
| 1260 | |
| 1261 | #endif // NET_QUIC_QUIC_PROTOCOL_H_ |