[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> |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 10 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 11 | #include <limits> |
rtenneti | 4b06ae7 | 2014-08-26 03:43:43 | [diff] [blame] | 12 | #include <list> |
[email protected] | a674b4c | 2012-12-05 03:44:30 | [diff] [blame] | 13 | #include <map> |
[email protected] | 5640d0a | 2012-10-22 18:17:02 | [diff] [blame] | 14 | #include <ostream> |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 15 | #include <set> |
| 16 | #include <string> |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 17 | #include <utility> |
| 18 | #include <vector> |
| 19 | |
[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" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 22 | #include "base/macros.h" |
rtenneti | 8dd12b2 | 2015-10-21 01:26:38 | [diff] [blame] | 23 | #include "base/memory/ref_counted.h" |
rtenneti | f60c32d8 | 2015-10-14 00:07:00 | [diff] [blame] | 24 | #include "base/memory/scoped_ptr.h" |
[email protected] | d069c11a | 2013-04-13 00:01:55 | [diff] [blame] | 25 | #include "base/strings/string_piece.h" |
[email protected] | 165e075 | 2012-11-16 07:49:44 | [diff] [blame] | 26 | #include "net/base/int128.h" |
rtenneti | c14c8ab | 2015-06-18 05:47:40 | [diff] [blame] | 27 | #include "net/base/iovec.h" |
[email protected] | 79d13dcb | 2014-02-05 07:23:13 | [diff] [blame] | 28 | #include "net/base/ip_endpoint.h" |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 29 | #include "net/base/net_export.h" |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 30 | #include "net/quic/interval_set.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; |
jokulik | c971baf9 | 2016-01-06 00:36:39 | [diff] [blame] | 39 | class QuicAckListenerInterface; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 40 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 41 | typedef uint64_t QuicConnectionId; |
| 42 | typedef uint32_t QuicStreamId; |
| 43 | typedef uint64_t QuicStreamOffset; |
| 44 | typedef uint64_t QuicPacketNumber; |
| 45 | typedef uint8_t QuicPathId; |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 46 | typedef QuicPacketNumber QuicFecGroupNumber; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 47 | typedef uint64_t QuicPublicResetNonceProof; |
| 48 | typedef uint8_t QuicPacketEntropyHash; |
| 49 | typedef uint32_t QuicHeaderId; |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 50 | // QuicTag is the type of a tag in the wire protocol. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 51 | typedef uint32_t QuicTag; |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 52 | typedef std::vector<QuicTag> QuicTagVector; |
[email protected] | 79d13dcb | 2014-02-05 07:23:13 | [diff] [blame] | 53 | typedef std::map<QuicTag, std::string> QuicTagValueMap; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 54 | typedef uint16_t QuicPacketLength; |
[email protected] | cff7b7b | 2013-01-11 08:49:07 | [diff] [blame] | 55 | |
rtenneti | bb2780c | 2015-07-22 19:16:08 | [diff] [blame] | 56 | // Default initial maximum size in bytes of a QUIC packet. |
[email protected] | 310d37b | 2014-08-02 06:15:37 | [diff] [blame] | 57 | const QuicByteCount kDefaultMaxPacketSize = 1350; |
rtenneti | 16a2077 | 2015-02-17 18:58:48 | [diff] [blame] | 58 | // Default initial maximum size in bytes of a QUIC packet for servers. |
| 59 | const QuicByteCount kDefaultServerMaxPacketSize = 1000; |
[email protected] | 8e01c06 | 2013-10-31 07:35:31 | [diff] [blame] | 60 | // The maximum packet size of any QUIC packet, based on ethernet's max size, |
fayang | a31a74b | 2015-12-28 17:27:14 | [diff] [blame] | 61 | // minus the IP and UDP headers. IPv6 has a 40 byte header, UDP adds an |
[email protected] | 41fb637 | 2013-12-10 05:26:40 | [diff] [blame] | 62 | // additional 8 bytes. This is a total overhead of 48 bytes. Ethernet's |
| 63 | // max packet size is 1500 bytes, 1500 - 48 = 1452. |
| 64 | const QuicByteCount kMaxPacketSize = 1452; |
rtenneti | 9e0fb50 | 2015-03-08 06:07:16 | [diff] [blame] | 65 | // Default maximum packet size used in the Linux TCP implementation. |
| 66 | // Used in QUIC for congestion window computations in bytes. |
[email protected] | ce7bb141 | 2014-05-17 15:51:33 | [diff] [blame] | 67 | const QuicByteCount kDefaultTCPMSS = 1460; |
[email protected] | 8e01c06 | 2013-10-31 07:35:31 | [diff] [blame] | 68 | |
rch | 1fe2eeb | 2015-10-26 14:45:57 | [diff] [blame] | 69 | // We match SPDY's use of 32 (since we'd compete with SPDY). |
| 70 | const QuicPacketCount kInitialCongestionWindow = 32; |
[email protected] | 8e01c06 | 2013-10-31 07:35:31 | [diff] [blame] | 71 | |
rtenneti | 7652bf3 | 2015-01-05 18:51:07 | [diff] [blame] | 72 | // Minimum size of initial flow control window, for both stream and session. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 73 | const uint32_t kMinimumFlowControlSendWindow = 16 * 1024; // 16 KB |
[email protected] | 9bb57c7 | 2014-03-31 20:36:04 | [diff] [blame] | 74 | |
rjshade | c86dbfa | 2015-11-12 20:16:25 | [diff] [blame] | 75 | // Maximum flow control receive window limits for connection and stream. |
| 76 | const QuicByteCount kStreamReceiveWindowLimit = 16 * 1024 * 1024; // 16 MB |
| 77 | const QuicByteCount kSessionReceiveWindowLimit = 24 * 1024 * 1024; // 24 MB |
| 78 | |
rtenneti | fb3fa6c | 2015-03-16 23:04:55 | [diff] [blame] | 79 | // Minimum size of the CWND, in packets, when doing bandwidth resumption. |
rtenneti | 8d2a808d | 2014-11-26 01:10:09 | [diff] [blame] | 80 | const QuicPacketCount kMinCongestionWindowForBandwidthResumption = 10; |
| 81 | |
rtenneti | 581b6ae8 | 2015-07-20 20:48:01 | [diff] [blame] | 82 | // Maximum size of the CWND, in packets. |
| 83 | const QuicPacketCount kMaxCongestionWindow = 200; |
rtenneti | 69e64aa | 2015-06-26 04:25:30 | [diff] [blame] | 84 | |
| 85 | // Maximum number of tracked packets. |
| 86 | const QuicPacketCount kMaxTrackedPackets = 5000; |
[email protected] | 0ac0c5b | 2013-11-20 05:55:58 | [diff] [blame] | 87 | |
rtenneti | 2318668 | 2014-10-30 01:49:33 | [diff] [blame] | 88 | // Default size of the socket receive buffer in bytes. |
[email protected] | 648f8114 | 2014-08-15 21:38:46 | [diff] [blame] | 89 | const QuicByteCount kDefaultSocketReceiveBuffer = 256 * 1024; |
rtenneti | 2318668 | 2014-10-30 01:49:33 | [diff] [blame] | 90 | // Minimum size of the socket receive buffer in bytes. |
| 91 | // Smaller values are ignored. |
| 92 | const QuicByteCount kMinSocketReceiveBuffer = 16 * 1024; |
[email protected] | a97b318 | 2014-08-08 08:10:18 | [diff] [blame] | 93 | |
rtenneti | 9529380 | 2015-03-27 18:59:23 | [diff] [blame] | 94 | // Fraction of the receive buffer that can be used for encrypted bytes. |
| 95 | // Allows a 5% overhead for IP and UDP framing, as well as ack only packets. |
| 96 | static const float kUsableRecieveBufferFraction = 0.95f; |
rtenneti | 581b6ae8 | 2015-07-20 20:48:01 | [diff] [blame] | 97 | // Fraction of the receive buffer that can be used, based on conservative |
| 98 | // estimates and testing on Linux. |
| 99 | // An alternative to kUsableRecieveBufferFraction. |
| 100 | static const float kConservativeReceiveBufferFraction = 0.6f; |
rtenneti | 9529380 | 2015-03-27 18:59:23 | [diff] [blame] | 101 | |
rtenneti | fc97ab6 | 2014-11-11 22:17:49 | [diff] [blame] | 102 | // Don't allow a client to suggest an RTT shorter than 10ms. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 103 | const uint32_t kMinInitialRoundTripTimeUs = 10 * kNumMicrosPerMilli; |
rtenneti | fc97ab6 | 2014-11-11 22:17:49 | [diff] [blame] | 104 | |
[email protected] | 8e01c06 | 2013-10-31 07:35:31 | [diff] [blame] | 105 | // Don't allow a client to suggest an RTT longer than 15 seconds. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 106 | const uint32_t kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 107 | |
| 108 | // Maximum number of open streams per connection. |
| 109 | const size_t kDefaultMaxStreamsPerConnection = 100; |
| 110 | |
[email protected] | af806e6 | 2013-05-22 14:47:50 | [diff] [blame] | 111 | // Number of bytes reserved for public flags in the packet header. |
| 112 | const size_t kPublicFlagsSize = 1; |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 113 | // Number of bytes reserved for version number in the packet header. |
| 114 | const size_t kQuicVersionSize = 4; |
zhongyi | b867702 | 2015-12-01 05:51:30 | [diff] [blame] | 115 | // Number of bytes reserved for path id in the packet header. |
| 116 | const size_t kQuicPathIdSize = 1; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 117 | // Number of bytes reserved for private flags in the packet header. |
| 118 | const size_t kPrivateFlagsSize = 1; |
| 119 | // Number of bytes reserved for FEC group in the packet header. |
| 120 | const size_t kFecGroupSize = 1; |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 121 | |
| 122 | // Signifies that the QuicPacket will contain version of the protocol. |
| 123 | const bool kIncludeVersion = true; |
zhongyi | b867702 | 2015-12-01 05:51:30 | [diff] [blame] | 124 | // Signifies that the QuicPacket will contain path id. |
| 125 | const bool kIncludePathId = true; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 126 | |
zhongyi | 4a9d27b | 2016-01-12 20:08:31 | [diff] [blame] | 127 | // Stream ID is reserved to denote an invalid ID. |
| 128 | const QuicStreamId kInvalidStreamId = 0; |
| 129 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 130 | // Reserved ID for the crypto stream. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 131 | const QuicStreamId kCryptoStreamId = 1; |
| 132 | |
[email protected] | 4d64079 | 2013-12-18 22:21:08 | [diff] [blame] | 133 | // Reserved ID for the headers stream. |
| 134 | const QuicStreamId kHeadersStreamId = 3; |
| 135 | |
jri | 3285d93a | 2015-12-14 08:53:19 | [diff] [blame] | 136 | // Header key used to identify final offset on data stream when sending HTTP/2 |
| 137 | // trailing headers over QUIC. |
| 138 | NET_EXPORT_PRIVATE extern const char* const kFinalOffsetHeaderKey; |
| 139 | |
[email protected] | 648f8114 | 2014-08-15 21:38:46 | [diff] [blame] | 140 | // Maximum delayed ack time, in ms. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 141 | const int64_t kMaxDelayedAckTimeMs = 25; |
[email protected] | 648f8114 | 2014-08-15 21:38:46 | [diff] [blame] | 142 | |
rjshade | d069aaee | 2016-03-11 20:42:17 | [diff] [blame^] | 143 | // Minimum tail loss probe time in ms. |
| 144 | static const int64_t kMinTailLossProbeTimeoutMs = 10; |
| 145 | |
rtenneti | b5512bb | 2014-09-29 19:17:15 | [diff] [blame] | 146 | // The timeout before the handshake succeeds. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 147 | const int64_t kInitialIdleTimeoutSecs = 5; |
rtenneti | b5512bb | 2014-09-29 19:17:15 | [diff] [blame] | 148 | // The default idle timeout. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 149 | const int64_t kDefaultIdleTimeoutSecs = 30; |
rtenneti | 31e9fd6 | 2014-09-16 05:22:15 | [diff] [blame] | 150 | // The maximum idle timeout that can be negotiated. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 151 | const int64_t kMaximumIdleTimeoutSecs = 60 * 10; // 10 minutes. |
rtenneti | 31e9fd6 | 2014-09-16 05:22:15 | [diff] [blame] | 152 | // The default timeout for a connection until the crypto handshake succeeds. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 153 | const int64_t kMaxTimeForCryptoHandshakeSecs = 10; // 10 secs. |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 154 | |
rtenneti | 93bce7ece | 2014-10-13 22:38:41 | [diff] [blame] | 155 | // Default limit on the number of undecryptable packets the connection buffers |
| 156 | // before the CHLO/SHLO arrive. |
| 157 | const size_t kDefaultMaxUndecryptablePackets = 10; |
| 158 | |
[email protected] | 525948df | 2014-04-21 06:26:58 | [diff] [blame] | 159 | // Default ping timeout. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 160 | const int64_t kPingTimeoutSecs = 15; // 15 secs. |
[email protected] | 525948df | 2014-04-21 06:26:58 | [diff] [blame] | 161 | |
[email protected] | ca4e0d9 | 2014-08-22 16:33:22 | [diff] [blame] | 162 | // Minimum number of RTTs between Server Config Updates (SCUP) sent to client. |
| 163 | const int kMinIntervalBetweenServerConfigUpdatesRTTs = 10; |
| 164 | |
| 165 | // Minimum time between Server Config Updates (SCUP) sent to client. |
| 166 | const int kMinIntervalBetweenServerConfigUpdatesMs = 1000; |
| 167 | |
rtenneti | 33da8ab | 2014-11-04 04:17:00 | [diff] [blame] | 168 | // Minimum number of packets between Server Config Updates (SCUP). |
| 169 | const int kMinPacketsBetweenServerConfigUpdates = 100; |
| 170 | |
rtenneti | b5512bb | 2014-09-29 19:17:15 | [diff] [blame] | 171 | // The number of open streams that a server will accept is set to be slightly |
| 172 | // larger than the negotiated limit. Immediately closing the connection if the |
| 173 | // client opens slightly too many streams is not ideal: the client may have sent |
| 174 | // a FIN that was lost, and simultaneously opened a new stream. The number of |
| 175 | // streams a server accepts is a fixed increment over the negotiated limit, or a |
| 176 | // percentage increase, whichever is larger. |
rtenneti | 31e9fd6 | 2014-09-16 05:22:15 | [diff] [blame] | 177 | const float kMaxStreamsMultiplier = 1.1f; |
rtenneti | b5512bb | 2014-09-29 19:17:15 | [diff] [blame] | 178 | const int kMaxStreamsMinimumIncrement = 10; |
rtenneti | 31e9fd6 | 2014-09-16 05:22:15 | [diff] [blame] | 179 | |
rtenneti | 159828f | 2015-10-13 06:58:09 | [diff] [blame] | 180 | // Available streams are ones with IDs less than the highest stream that has |
| 181 | // been opened which have neither been opened or reset. The limit on the number |
| 182 | // of available streams is 10 times the limit on the number of open streams. |
| 183 | const int kMaxAvailableStreamsMultiplier = 10; |
| 184 | |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 185 | // Track the number of promises that are not yet claimed by a |
| 186 | // corresponding get. This must be smaller than |
| 187 | // kMaxAvailableStreamsMultiplier, because RST on a promised stream my |
| 188 | // create available streams entries. |
| 189 | const int kMaxPromisedStreamsMultiplier = kMaxAvailableStreamsMultiplier - 1; |
| 190 | |
[email protected] | b007e63 | 2013-10-28 08:39:25 | [diff] [blame] | 191 | // We define an unsigned 16-bit floating point value, inspired by IEEE floats |
| 192 | // (http://en.wikipedia.org/wiki/Half_precision_floating-point_format), |
| 193 | // with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden |
| 194 | // bit) and denormals, but without signs, transfinites or fractions. Wire format |
| 195 | // 16 bits (little-endian byte order) are split into exponent (high 5) and |
| 196 | // mantissa (low 11) and decoded as: |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 197 | // uint64_t value; |
[email protected] | b007e63 | 2013-10-28 08:39:25 | [diff] [blame] | 198 | // if (exponent == 0) value = mantissa; |
| 199 | // else value = (mantissa | 1 << 11) << (exponent - 1) |
| 200 | const int kUFloat16ExponentBits = 5; |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 201 | const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2; // 30 |
| 202 | const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits; // 11 |
[email protected] | b007e63 | 2013-10-28 08:39:25 | [diff] [blame] | 203 | const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1; // 12 |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 204 | const uint64_t kUFloat16MaxValue = // 0x3FFC0000000 |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 205 | ((UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1) |
| 206 | << kUFloat16MaxExponent; |
[email protected] | b007e63 | 2013-10-28 08:39:25 | [diff] [blame] | 207 | |
jri | 3285d93a | 2015-12-14 08:53:19 | [diff] [blame] | 208 | // Default path ID. |
| 209 | const QuicPathId kDefaultPathId = 0; |
fayang | a31a74b | 2015-12-28 17:27:14 | [diff] [blame] | 210 | // Invalid path ID. |
| 211 | const QuicPathId kInvalidPathId = 0xff; |
jri | 3285d93a | 2015-12-14 08:53:19 | [diff] [blame] | 212 | |
fayang | a64c1a9 | 2016-02-13 01:55:58 | [diff] [blame] | 213 | enum TransmissionType : int8_t { |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 214 | NOT_RETRANSMISSION, |
[email protected] | b9475b58 | 2014-03-20 20:04:33 | [diff] [blame] | 215 | FIRST_TRANSMISSION_TYPE = NOT_RETRANSMISSION, |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 216 | HANDSHAKE_RETRANSMISSION, // Retransmits due to handshake timeouts. |
rtenneti | 31e9fd6 | 2014-09-16 05:22:15 | [diff] [blame] | 217 | ALL_UNACKED_RETRANSMISSION, // Retransmits all unacked packets. |
| 218 | ALL_INITIAL_RETRANSMISSION, // Retransmits all initially encrypted packets. |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 219 | LOSS_RETRANSMISSION, // Retransmits due to loss detection. |
| 220 | RTO_RETRANSMISSION, // Retransmits due to retransmit time out. |
| 221 | TLP_RETRANSMISSION, // Tail loss probes. |
[email protected] | b9475b58 | 2014-03-20 20:04:33 | [diff] [blame] | 222 | LAST_TRANSMISSION_TYPE = TLP_RETRANSMISSION, |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 223 | }; |
| 224 | |
fayang | a64c1a9 | 2016-02-13 01:55:58 | [diff] [blame] | 225 | enum HasRetransmittableData : int8_t { |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 226 | NO_RETRANSMITTABLE_DATA, |
| 227 | HAS_RETRANSMITTABLE_DATA, |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 228 | }; |
| 229 | |
fayang | a64c1a9 | 2016-02-13 01:55:58 | [diff] [blame] | 230 | enum IsHandshake : int8_t { NOT_HANDSHAKE, IS_HANDSHAKE }; |
[email protected] | 575cce6 | 2013-08-03 02:06:43 | [diff] [blame] | 231 | |
rtenneti | 6f48aa9 | 2015-03-16 02:18:48 | [diff] [blame] | 232 | enum class Perspective { IS_SERVER, IS_CLIENT }; |
| 233 | |
fayang | a64c1a9 | 2016-02-13 01:55:58 | [diff] [blame] | 234 | // Describes whether a ConnectionClose was originated by the peer. |
| 235 | enum class ConnectionCloseSource { FROM_PEER, FROM_SELF }; |
| 236 | |
rtenneti | 6f48aa9 | 2015-03-16 02:18:48 | [diff] [blame] | 237 | NET_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os, |
| 238 | const Perspective& s); |
| 239 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 240 | enum QuicFrameType { |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 241 | // Regular frame types. The values set here cannot change without the |
| 242 | // introduction of a new QUIC version. |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 243 | PADDING_FRAME = 0, |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 244 | RST_STREAM_FRAME = 1, |
| 245 | CONNECTION_CLOSE_FRAME = 2, |
| 246 | GOAWAY_FRAME = 3, |
| 247 | WINDOW_UPDATE_FRAME = 4, |
| 248 | BLOCKED_FRAME = 5, |
[email protected] | 93dd91f | 2014-02-27 00:09:03 | [diff] [blame] | 249 | STOP_WAITING_FRAME = 6, |
[email protected] | d8c52211 | 2014-04-23 09:23:25 | [diff] [blame] | 250 | PING_FRAME = 7, |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 251 | PATH_CLOSE_FRAME = 8, |
[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 | |
fayang | a64c1a9 | 2016-02-13 01:55:58 | [diff] [blame] | 274 | enum QuicPacketNumberLength : int8_t { |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 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 | |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 322 | // All bits set (bit 7 is not currently used): 01111111 |
zhongyi | b867702 | 2015-12-01 05:51:30 | [diff] [blame] | 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 |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 401 | // stored in memory as a little endian uint32_t, we need |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 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 | |
rjshade | d069aaee | 2016-03-11 20:42:17 | [diff] [blame^] | 412 | // Size in bytes of the data 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, |
rjshade | d069aaee | 2016-03-11 20:42:17 | [diff] [blame^] | 419 | QuicPacketNumberLength packet_number_length); |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 420 | |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 421 | // Index of the first byte in a QUIC packet of encrypted data. |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 422 | NET_EXPORT_PRIVATE size_t |
rjshade | d069aaee | 2016-03-11 20:42:17 | [diff] [blame^] | 423 | GetStartOfEncryptedData(const QuicPacketHeader& header); |
| 424 | |
| 425 | NET_EXPORT_PRIVATE size_t |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 426 | GetStartOfEncryptedData(QuicConnectionIdLength connection_id_length, |
| 427 | bool include_version, |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 428 | bool include_path_id, |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 429 | QuicPacketNumberLength packet_number_length); |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 430 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 431 | enum QuicRstStreamErrorCode { |
rch | 99b644c | 2015-11-04 05:25:28 | [diff] [blame] | 432 | // Complete response has been sent, sending a RST to ask the other endpoint |
| 433 | // to stop sending request data without discarding the response. |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 434 | QUIC_STREAM_NO_ERROR = 0, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 435 | |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 436 | // There was some error which halted stream processing. |
| 437 | QUIC_ERROR_PROCESSING_STREAM, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 438 | // We got two fin or reset offsets which did not match. |
| 439 | QUIC_MULTIPLE_TERMINATION_OFFSETS, |
| 440 | // We got bad payload and can not respond to it at the protocol level. |
| 441 | QUIC_BAD_APPLICATION_PAYLOAD, |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 442 | // Stream closed due to connection error. No reset frame is sent when this |
| 443 | // happens. |
| 444 | QUIC_STREAM_CONNECTION_ERROR, |
| 445 | // GoAway frame sent. No more stream can be created. |
| 446 | QUIC_STREAM_PEER_GOING_AWAY, |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 447 | // The stream has been cancelled. |
| 448 | QUIC_STREAM_CANCELLED, |
rtenneti | 4a5df26 | 2014-11-07 00:43:58 | [diff] [blame] | 449 | // Closing stream locally, sending a RST to allow for proper flow control |
| 450 | // accounting. Sent in response to a RST from the peer. |
| 451 | QUIC_RST_ACKNOWLEDGEMENT, |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 452 | // Receiver refused to create the stream (because its limit on open streams |
| 453 | // has been reached). The sender should retry the request later (using |
| 454 | // another stream). |
| 455 | QUIC_REFUSED_STREAM, |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 456 | // Invalid URL in PUSH_PROMISE request header. |
| 457 | QUIC_INVALID_PROMISE_URL, |
| 458 | // Server is not authoritative for this URL. |
| 459 | QUIC_UNAUTHORIZED_PROMISE_URL, |
| 460 | // Can't have more than one active PUSH_PROMISE per URL. |
| 461 | QUIC_DUPLICATE_PROMISE_URL, |
ckrasic | 244375a3 | 2016-02-04 21:21:22 | [diff] [blame] | 462 | // Vary check failed. |
| 463 | QUIC_PROMISE_VARY_MISMATCH, |
ckrasic | 171ef13e | 2016-02-26 01:20:16 | [diff] [blame] | 464 | // Only GET and HEAD methods allowed. |
| 465 | QUIC_INVALID_PROMISE_METHOD, |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 466 | // No error. Used as bound while iterating. |
| 467 | QUIC_STREAM_LAST_ERROR, |
| 468 | }; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 469 | |
[email protected] | 51cc134 | 2014-04-18 23:44:37 | [diff] [blame] | 470 | // Because receiving an unknown QuicRstStreamErrorCode results in connection |
| 471 | // teardown, we use this to make sure any errors predating a given version are |
| 472 | // downgraded to the most appropriate existing error. |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 473 | NET_EXPORT_PRIVATE QuicRstStreamErrorCode |
| 474 | AdjustErrorForVersion(QuicRstStreamErrorCode error_code, QuicVersion version); |
[email protected] | 51cc134 | 2014-04-18 23:44:37 | [diff] [blame] | 475 | |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 476 | // These values must remain stable as they are uploaded to UMA histograms. |
| 477 | // To add a new error code, use the current value of QUIC_LAST_ERROR and |
| 478 | // increment QUIC_LAST_ERROR. |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 479 | enum QuicErrorCode { |
| 480 | QUIC_NO_ERROR = 0, |
| 481 | |
| 482 | // Connection has reached an invalid state. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 483 | QUIC_INTERNAL_ERROR = 1, |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 484 | // There were data frames after the a fin or reset. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 485 | QUIC_STREAM_DATA_AFTER_TERMINATION = 2, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 486 | // Control frame is malformed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 487 | QUIC_INVALID_PACKET_HEADER = 3, |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 488 | // Frame data is malformed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 489 | QUIC_INVALID_FRAME_DATA = 4, |
| 490 | // The packet contained no payload. |
| 491 | QUIC_MISSING_PAYLOAD = 48, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 492 | // FEC data is malformed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 493 | QUIC_INVALID_FEC_DATA = 5, |
| 494 | // STREAM frame data is malformed. |
| 495 | QUIC_INVALID_STREAM_DATA = 46, |
[email protected] | 42a3eba | 2014-04-30 10:52:55 | [diff] [blame] | 496 | // STREAM frame data is not encrypted. |
| 497 | QUIC_UNENCRYPTED_STREAM_DATA = 61, |
zhongyi | 4a9d27b | 2016-01-12 20:08:31 | [diff] [blame] | 498 | // FEC frame data is not encrypted. |
| 499 | QUIC_UNENCRYPTED_FEC_DATA = 77, |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 500 | // RST_STREAM frame data is malformed. |
| 501 | QUIC_INVALID_RST_STREAM_DATA = 6, |
| 502 | // CONNECTION_CLOSE frame data is malformed. |
| 503 | QUIC_INVALID_CONNECTION_CLOSE_DATA = 7, |
| 504 | // GOAWAY frame data is malformed. |
| 505 | QUIC_INVALID_GOAWAY_DATA = 8, |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 506 | // WINDOW_UPDATE frame data is malformed. |
| 507 | QUIC_INVALID_WINDOW_UPDATE_DATA = 57, |
| 508 | // BLOCKED frame data is malformed. |
| 509 | QUIC_INVALID_BLOCKED_DATA = 58, |
[email protected] | 93dd91f | 2014-02-27 00:09:03 | [diff] [blame] | 510 | // STOP_WAITING frame data is malformed. |
| 511 | QUIC_INVALID_STOP_WAITING_DATA = 60, |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 512 | // PATH_CLOSE frame data is malformed. |
| 513 | QUIC_INVALID_PATH_CLOSE_DATA = 78, |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 514 | // ACK frame data is malformed. |
| 515 | QUIC_INVALID_ACK_DATA = 9, |
rtenneti | f4bdb54 | 2015-01-21 14:33:05 | [diff] [blame] | 516 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 517 | // Version negotiation packet is malformed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 518 | QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10, |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 519 | // Public RST packet is malformed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 520 | QUIC_INVALID_PUBLIC_RST_PACKET = 11, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 521 | // There was an error decrypting. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 522 | QUIC_DECRYPTION_FAILURE = 12, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 523 | // There was an error encrypting. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 524 | QUIC_ENCRYPTION_FAILURE = 13, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 525 | // The packet exceeded kMaxPacketSize. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 526 | QUIC_PACKET_TOO_LARGE = 14, |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 527 | // The peer is going away. May be a client or server. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 528 | QUIC_PEER_GOING_AWAY = 16, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 529 | // A stream ID was invalid. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 530 | QUIC_INVALID_STREAM_ID = 17, |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 531 | // A priority was invalid. |
| 532 | QUIC_INVALID_PRIORITY = 49, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 533 | // Too many streams already open. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 534 | QUIC_TOO_MANY_OPEN_STREAMS = 18, |
rtenneti | 159828f | 2015-10-13 06:58:09 | [diff] [blame] | 535 | // The peer created too many available streams. |
| 536 | QUIC_TOO_MANY_AVAILABLE_STREAMS = 76, |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 537 | // Received public reset for this connection. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 538 | QUIC_PUBLIC_RESET = 19, |
[email protected] | c244c5a1 | 2013-05-07 20:55:04 | [diff] [blame] | 539 | // Invalid protocol version. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 540 | QUIC_INVALID_VERSION = 20, |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 541 | |
[email protected] | c244c5a1 | 2013-05-07 20:55:04 | [diff] [blame] | 542 | // The Header ID for a stream was too far from the previous. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 543 | QUIC_INVALID_HEADER_ID = 22, |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 544 | // Negotiable parameter received during handshake had invalid value. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 545 | QUIC_INVALID_NEGOTIATED_VALUE = 23, |
[email protected] | 89995165 | 2013-05-16 12:52:39 | [diff] [blame] | 546 | // There was an error decompressing data. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 547 | QUIC_DECOMPRESSION_FAILURE = 24, |
rtenneti | 2cae207 | 2016-02-05 02:21:33 | [diff] [blame] | 548 | // The connection timed out due to no network activity. |
| 549 | QUIC_NETWORK_IDLE_TIMEOUT = 25, |
| 550 | // The connection timed out waiting for the handshake to complete. |
| 551 | QUIC_HANDSHAKE_TIMEOUT = 67, |
zhongyi | 2341cda | 2016-03-10 04:09:34 | [diff] [blame] | 552 | // There was an error encountered migrating addresses. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 553 | QUIC_ERROR_MIGRATING_ADDRESS = 26, |
zhongyi | 2341cda | 2016-03-10 04:09:34 | [diff] [blame] | 554 | // There was an error encountered migrating port only. |
| 555 | QUIC_ERROR_MIGRATING_PORT = 86, |
[email protected] | 1505a51 | 2013-09-04 22:59:35 | [diff] [blame] | 556 | // There was an error while writing to the socket. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 557 | QUIC_PACKET_WRITE_ERROR = 27, |
[email protected] | 1505a51 | 2013-09-04 22:59:35 | [diff] [blame] | 558 | // There was an error while reading from the socket. |
| 559 | QUIC_PACKET_READ_ERROR = 51, |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 560 | // We received a STREAM_FRAME with no data and no fin flag set. |
| 561 | QUIC_INVALID_STREAM_FRAME = 50, |
[email protected] | 4d64079 | 2013-12-18 22:21:08 | [diff] [blame] | 562 | // We received invalid data on the headers stream. |
| 563 | QUIC_INVALID_HEADERS_STREAM_DATA = 56, |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 564 | // The peer received too much data, violating flow control. |
| 565 | QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA = 59, |
| 566 | // The peer sent too much data, violating flow control. |
| 567 | QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA = 63, |
| 568 | // The peer received an invalid flow control window. |
| 569 | QUIC_FLOW_CONTROL_INVALID_WINDOW = 64, |
[email protected] | 71c84e59 | 2014-05-28 23:39:29 | [diff] [blame] | 570 | // The connection has been IP pooled into an existing connection. |
| 571 | QUIC_CONNECTION_IP_POOLED = 62, |
rtenneti | 2318668 | 2014-10-30 01:49:33 | [diff] [blame] | 572 | // The connection has too many outstanding sent packets. |
| 573 | QUIC_TOO_MANY_OUTSTANDING_SENT_PACKETS = 68, |
| 574 | // The connection has too many outstanding received packets. |
| 575 | QUIC_TOO_MANY_OUTSTANDING_RECEIVED_PACKETS = 69, |
fayang | a64c1a9 | 2016-02-13 01:55:58 | [diff] [blame] | 576 | // The quic connection has been cancelled. |
rtenneti | 14abd31 | 2015-02-06 21:56:01 | [diff] [blame] | 577 | QUIC_CONNECTION_CANCELLED = 70, |
rtenneti | 85dcfac2 | 2015-03-27 20:22:19 | [diff] [blame] | 578 | // Disabled QUIC because of high packet loss rate. |
| 579 | QUIC_BAD_PACKET_LOSS_RATE = 71, |
ckrasic | 1e53b64 | 2015-07-08 22:39:35 | [diff] [blame] | 580 | // Disabled QUIC because of too many PUBLIC_RESETs post handshake. |
| 581 | QUIC_PUBLIC_RESETS_POST_HANDSHAKE = 73, |
| 582 | // Disabled QUIC because of too many timeouts with streams open. |
| 583 | QUIC_TIMEOUTS_WITH_OPEN_STREAMS = 74, |
rtenneti | 8811fdb | 2015-07-22 00:17:07 | [diff] [blame] | 584 | // Closed because we failed to serialize a packet. |
| 585 | QUIC_FAILED_TO_SERIALIZE_PACKET = 75, |
zhongyi | 2341cda | 2016-03-10 04:09:34 | [diff] [blame] | 586 | // QUIC timed out after too many RTOs. |
| 587 | QUIC_TOO_MANY_RTOS = 85, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 588 | |
| 589 | // Crypto errors. |
| 590 | |
[email protected] | 1354bf6 | 2013-05-23 23:17:18 | [diff] [blame] | 591 | // Hanshake failed. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 592 | QUIC_HANDSHAKE_FAILED = 28, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 593 | // Handshake message contained out of order tags. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 594 | QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29, |
[email protected] | 701bc89 | 2013-01-17 04:51:54 | [diff] [blame] | 595 | // Handshake message contained too many entries. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 596 | QUIC_CRYPTO_TOO_MANY_ENTRIES = 30, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 597 | // Handshake message contained an invalid value length. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 598 | QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 599 | // A crypto message was received after the handshake was complete. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 600 | QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32, |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 601 | // A crypto message was received with an illegal message tag. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 602 | QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33, |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 603 | // A crypto message was received with an illegal parameter. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 604 | QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34, |
[email protected] | 752fbe5 | 2013-10-14 08:35:32 | [diff] [blame] | 605 | // An invalid channel id signature was supplied. |
| 606 | QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52, |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 607 | // A crypto message was received with a mandatory parameter missing. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 608 | QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35, |
[email protected] | d3d15bf | 2013-01-30 02:51:54 | [diff] [blame] | 609 | // A crypto message was received with a parameter that has no overlap |
| 610 | // with the local parameter. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 611 | QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36, |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 612 | // A crypto message was received that contained a parameter with too few |
| 613 | // values. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 614 | QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37, |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 615 | // An internal error occured in crypto processing. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 616 | QUIC_CRYPTO_INTERNAL_ERROR = 38, |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 617 | // A crypto handshake message specified an unsupported version. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 618 | QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39, |
rtenneti | e0ee6eb | 2015-05-01 00:55:09 | [diff] [blame] | 619 | // A crypto handshake message resulted in a stateless reject. |
| 620 | QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT = 72, |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 621 | // There was no intersection between the crypto primitives supported by the |
| 622 | // peer and ourselves. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 623 | QUIC_CRYPTO_NO_SUPPORT = 40, |
[email protected] | ef95114d | 2013-04-17 17:57:01 | [diff] [blame] | 624 | // The server rejected our client hello messages too many times. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 625 | QUIC_CRYPTO_TOO_MANY_REJECTS = 41, |
[email protected] | a57e027 | 2013-04-26 07:31:47 | [diff] [blame] | 626 | // The client rejected the server's certificate chain or signature. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 627 | QUIC_PROOF_INVALID = 42, |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 628 | // A crypto message was received with a duplicate tag. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 629 | QUIC_CRYPTO_DUPLICATE_TAG = 43, |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 630 | // A crypto message was received with the wrong encryption level (i.e. it |
| 631 | // should have been encrypted but was not.) |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 632 | QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44, |
[email protected] | 2532de1 | 2013-05-09 12:29:33 | [diff] [blame] | 633 | // The server config for a server has expired. |
[email protected] | 8926404 | 2013-08-21 07:35:24 | [diff] [blame] | 634 | QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45, |
[email protected] | 752fbe5 | 2013-10-14 08:35:32 | [diff] [blame] | 635 | // We failed to setup the symmetric keys for a connection. |
| 636 | QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53, |
[email protected] | 691f45a98 | 2013-11-19 10:52:04 | [diff] [blame] | 637 | // A handshake message arrived, but we are still validating the |
| 638 | // previous handshake message. |
| 639 | QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54, |
[email protected] | ccb3421 | 2014-07-18 09:27:50 | [diff] [blame] | 640 | // A server config update arrived before the handshake is complete. |
| 641 | QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE = 65, |
[email protected] | d89f186 | 2013-11-26 21:21:27 | [diff] [blame] | 642 | // This connection involved a version negotiation which appears to have been |
| 643 | // tampered with. |
| 644 | QUIC_VERSION_NEGOTIATION_MISMATCH = 55, |
[email protected] | ccc66e8a | 2013-03-26 08:26:14 | [diff] [blame] | 645 | |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 646 | // Multipath is not enabled, but a packet with multipath flag on is received. |
| 647 | QUIC_BAD_MULTIPATH_FLAG = 79, |
| 648 | |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 649 | // IP address changed causing connection close. |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 650 | QUIC_IP_ADDRESS_CHANGED = 80, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 651 | |
| 652 | // Connection migration errors. |
| 653 | // Network changed, but connection had no migratable streams. |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 654 | QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS = 81, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 655 | // Connection changed networks too many times. |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 656 | QUIC_CONNECTION_MIGRATION_TOO_MANY_CHANGES = 82, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 657 | // Connection migration was attempted, but there was no new network to |
| 658 | // migrate to. |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 659 | QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK = 83, |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 660 | // Network changed, but connection had one or more non-migratable streams. |
| 661 | QUIC_CONNECTION_MIGRATION_NON_MIGRATABLE_STREAM = 84, |
jri | 7e63664 | 2016-01-14 06:57:08 | [diff] [blame] | 662 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 663 | // No error. Used as bound while iterating. |
zhongyi | 2341cda | 2016-03-10 04:09:34 | [diff] [blame] | 664 | QUIC_LAST_ERROR = 87, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 665 | }; |
| 666 | |
zhongyi | 291d030 | 2015-12-14 07:06:25 | [diff] [blame] | 667 | // Must be updated any time a QuicErrorCode is deprecated. |
| 668 | const int kDeprecatedQuicErrorCount = 4; |
| 669 | const int kActiveQuicErrorCount = QUIC_LAST_ERROR - kDeprecatedQuicErrorCount; |
| 670 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 671 | struct NET_EXPORT_PRIVATE QuicPacketPublicHeader { |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 672 | QuicPacketPublicHeader(); |
| 673 | explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other); |
| 674 | ~QuicPacketPublicHeader(); |
| 675 | |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 676 | // Universal header. All QuicPacket headers will have a connection_id and |
| 677 | // public flags. |
| 678 | QuicConnectionId connection_id; |
| 679 | QuicConnectionIdLength connection_id_length; |
zhongyi | b867702 | 2015-12-01 05:51:30 | [diff] [blame] | 680 | bool multipath_flag; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 681 | bool reset_flag; |
| 682 | bool version_flag; |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 683 | QuicPacketNumberLength packet_number_length; |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 684 | QuicVersionVector versions; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 685 | }; |
| 686 | |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 687 | // An integer which cannot be a packet number. |
| 688 | const QuicPacketNumber kInvalidPacketNumber = 0; |
rtenneti | 9e0fb50 | 2015-03-08 06:07:16 | [diff] [blame] | 689 | |
rjshade | d069aaee | 2016-03-11 20:42:17 | [diff] [blame^] | 690 | // Header for Data packets. |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 691 | struct NET_EXPORT_PRIVATE QuicPacketHeader { |
| 692 | QuicPacketHeader(); |
| 693 | explicit QuicPacketHeader(const QuicPacketPublicHeader& header); |
vmpstr | acd23b7 | 2016-02-26 21:08:55 | [diff] [blame] | 694 | QuicPacketHeader(const QuicPacketHeader& other); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 695 | |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 696 | NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, |
| 697 | const QuicPacketHeader& s); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 698 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 699 | QuicPacketPublicHeader public_header; |
rtenneti | 8dd12b2 | 2015-10-21 01:26:38 | [diff] [blame] | 700 | QuicPacketNumber packet_number; |
fayang | a64c1a9 | 2016-02-13 01:55:58 | [diff] [blame] | 701 | QuicPathId path_id; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 702 | bool entropy_flag; |
| 703 | QuicPacketEntropyHash entropy_hash; |
fayang | a64c1a9 | 2016-02-13 01:55:58 | [diff] [blame] | 704 | bool fec_flag; |
[email protected] | b06431078 | 2013-05-30 21:12:17 | [diff] [blame] | 705 | InFecGroup is_in_fec_group; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 706 | QuicFecGroupNumber fec_group; |
| 707 | }; |
| 708 | |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 709 | struct NET_EXPORT_PRIVATE QuicPublicResetPacket { |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 710 | QuicPublicResetPacket(); |
| 711 | explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header); |
| 712 | |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 713 | QuicPacketPublicHeader public_header; |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 714 | QuicPublicResetNonceProof nonce_proof; |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 715 | QuicPacketNumber rejected_packet_number; |
[email protected] | 79d13dcb | 2014-02-05 07:23:13 | [diff] [blame] | 716 | IPEndPoint client_address; |
[email protected] | 86a318d | 2013-01-23 21:16:04 | [diff] [blame] | 717 | }; |
| 718 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 719 | enum QuicVersionNegotiationState { |
| 720 | START_NEGOTIATION = 0, |
[email protected] | ec64011 | 2013-08-09 03:56:18 | [diff] [blame] | 721 | // Server-side this implies we've sent a version negotiation packet and are |
| 722 | // waiting on the client to select a compatible version. Client-side this |
| 723 | // implies we've gotten a version negotiation packet, are retransmitting the |
| 724 | // initial packets with a supported version and are waiting for our first |
| 725 | // packet from the server. |
| 726 | NEGOTIATION_IN_PROGRESS, |
| 727 | // This indicates this endpoint has received a packet from the peer with a |
| 728 | // version this endpoint supports. Version negotiation is complete, and the |
| 729 | // version number will no longer be sent with future packets. |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 730 | NEGOTIATED_VERSION |
| 731 | }; |
| 732 | |
| 733 | typedef QuicPacketPublicHeader QuicVersionNegotiationPacket; |
| 734 | |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 735 | // A padding frame contains no payload. |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 736 | struct NET_EXPORT_PRIVATE QuicPaddingFrame {}; |
[email protected] | c995c57 | 2013-01-18 05:43:20 | [diff] [blame] | 737 | |
[email protected] | d8c52211 | 2014-04-23 09:23:25 | [diff] [blame] | 738 | // A ping frame contains no payload, though it is retransmittable, |
| 739 | // and ACK'd just like other normal frames. |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 740 | struct NET_EXPORT_PRIVATE QuicPingFrame {}; |
[email protected] | d8c52211 | 2014-04-23 09:23:25 | [diff] [blame] | 741 | |
rtenneti | 69e64aa | 2015-06-26 04:25:30 | [diff] [blame] | 742 | // A path MTU discovery frame contains no payload and is serialized as a ping |
| 743 | // frame. |
| 744 | struct NET_EXPORT_PRIVATE QuicMtuDiscoveryFrame {}; |
| 745 | |
jdorfman | 5a60672 | 2016-01-04 17:41:29 | [diff] [blame] | 746 | class NET_EXPORT_PRIVATE QuicBufferAllocator { |
| 747 | public: |
| 748 | virtual ~QuicBufferAllocator(); |
| 749 | |
| 750 | // Returns or allocates a new buffer of |size|. Never returns null. |
| 751 | virtual char* New(size_t size) = 0; |
| 752 | |
rch | a0023224 | 2016-01-22 21:07:51 | [diff] [blame] | 753 | // Returns or allocates a new buffer of |size| if |flag_enable| is true. |
| 754 | // Otherwise, returns a buffer that is compatible with this class directly |
| 755 | // with operator new. Never returns null. |
| 756 | virtual char* New(size_t size, bool flag_enable) = 0; |
| 757 | |
jdorfman | 5a60672 | 2016-01-04 17:41:29 | [diff] [blame] | 758 | // Releases a buffer. |
| 759 | virtual void Delete(char* buffer) = 0; |
rch | a0023224 | 2016-01-22 21:07:51 | [diff] [blame] | 760 | |
| 761 | // Marks the allocator as being idle. Serves as a hint to notify the allocator |
| 762 | // that it should release any resources it's still holding on to. |
| 763 | virtual void MarkAllocatorIdle() {} |
jdorfman | 5a60672 | 2016-01-04 17:41:29 | [diff] [blame] | 764 | }; |
| 765 | |
| 766 | // Deleter for stream buffers. Copyable to support platforms where the deleter |
| 767 | // of a unique_ptr must be copyable. Otherwise it would be nice for this to be |
| 768 | // move-only. |
zhongyi | 2f5f40c | 2015-12-08 02:13:02 | [diff] [blame] | 769 | class NET_EXPORT_PRIVATE StreamBufferDeleter { |
| 770 | public: |
jdorfman | 5a60672 | 2016-01-04 17:41:29 | [diff] [blame] | 771 | StreamBufferDeleter() : allocator_(nullptr) {} |
| 772 | explicit StreamBufferDeleter(QuicBufferAllocator* allocator) |
| 773 | : allocator_(allocator) {} |
| 774 | |
| 775 | // Deletes |buffer| using |allocator_|. |
| 776 | void operator()(char* buffer) const; |
| 777 | |
| 778 | private: |
| 779 | // Not owned; must be valid so long as the buffer stored in the unique_ptr |
| 780 | // that owns |this| is valid. |
| 781 | QuicBufferAllocator* allocator_; |
zhongyi | 2f5f40c | 2015-12-08 02:13:02 | [diff] [blame] | 782 | }; |
| 783 | |
| 784 | using UniqueStreamBuffer = std::unique_ptr<char[], StreamBufferDeleter>; |
rtenneti | f60c32d8 | 2015-10-14 00:07:00 | [diff] [blame] | 785 | |
jdorfman | 5a60672 | 2016-01-04 17:41:29 | [diff] [blame] | 786 | // Allocates memory of size |size| using |allocator| for a QUIC stream buffer. |
| 787 | NET_EXPORT_PRIVATE UniqueStreamBuffer |
| 788 | NewStreamBuffer(QuicBufferAllocator* allocator, size_t size); |
rtenneti | f60c32d8 | 2015-10-14 00:07:00 | [diff] [blame] | 789 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 790 | struct NET_EXPORT_PRIVATE QuicStreamFrame { |
| 791 | QuicStreamFrame(); |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 792 | QuicStreamFrame(QuicStreamId stream_id, |
[email protected] | a506124 | 2012-10-23 23:29:37 | [diff] [blame] | 793 | bool fin, |
[email protected] | 701bc89 | 2013-01-17 04:51:54 | [diff] [blame] | 794 | QuicStreamOffset offset, |
rtenneti | a4228ea | 2015-06-04 02:31:44 | [diff] [blame] | 795 | base::StringPiece data); |
zhongyi | 36727b8 | 2015-12-03 00:42:23 | [diff] [blame] | 796 | QuicStreamFrame(QuicStreamId stream_id, |
| 797 | bool fin, |
| 798 | QuicStreamOffset offset, |
jokulik | 2324d28 | 2015-12-08 21:42:57 | [diff] [blame] | 799 | QuicPacketLength frame_length, |
zhongyi | 36727b8 | 2015-12-03 00:42:23 | [diff] [blame] | 800 | UniqueStreamBuffer buffer); |
| 801 | ~QuicStreamFrame(); |
[email protected] | 5dafdb6 | 2013-11-14 01:24:26 | [diff] [blame] | 802 | |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 803 | NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, |
| 804 | const QuicStreamFrame& s); |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 805 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 806 | QuicStreamId stream_id; |
| 807 | bool fin; |
jokulik | 2324d28 | 2015-12-08 21:42:57 | [diff] [blame] | 808 | QuicPacketLength frame_length; |
| 809 | const char* frame_buffer; |
[email protected] | 701bc89 | 2013-01-17 04:51:54 | [diff] [blame] | 810 | QuicStreamOffset offset; // Location of this data in the stream. |
zhongyi | 36727b8 | 2015-12-03 00:42:23 | [diff] [blame] | 811 | // nullptr when the QuicStreamFrame is received, and non-null when sent. |
| 812 | UniqueStreamBuffer buffer; |
zhongyi | 4249f9b0 | 2015-12-02 20:26:30 | [diff] [blame] | 813 | |
zhongyi | 36727b8 | 2015-12-03 00:42:23 | [diff] [blame] | 814 | private: |
jokulik | 2324d28 | 2015-12-08 21:42:57 | [diff] [blame] | 815 | QuicStreamFrame(QuicStreamId stream_id, |
| 816 | bool fin, |
| 817 | QuicStreamOffset offset, |
| 818 | const char* frame_buffer, |
| 819 | QuicPacketLength frame_length, |
| 820 | UniqueStreamBuffer buffer); |
| 821 | |
zhongyi | 36727b8 | 2015-12-03 00:42:23 | [diff] [blame] | 822 | DISALLOW_COPY_AND_ASSIGN(QuicStreamFrame); |
| 823 | }; |
| 824 | static_assert(sizeof(QuicStreamFrame) <= 64, |
| 825 | "Keep the QuicStreamFrame size to a cacheline."); |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 826 | // TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing |
| 827 | // is finalized. |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 828 | typedef std::set<QuicPacketNumber> PacketNumberSet; |
| 829 | typedef std::list<QuicPacketNumber> PacketNumberList; |
rtenneti | 4b06ae7 | 2014-08-26 03:43:43 | [diff] [blame] | 830 | |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 831 | typedef std::vector<std::pair<QuicPacketNumber, QuicTime>> PacketTimeVector; |
[email protected] | 044ac2b | 2012-11-13 21:41:06 | [diff] [blame] | 832 | |
[email protected] | 310d37b | 2014-08-02 06:15:37 | [diff] [blame] | 833 | struct NET_EXPORT_PRIVATE QuicStopWaitingFrame { |
| 834 | QuicStopWaitingFrame(); |
| 835 | ~QuicStopWaitingFrame(); |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 836 | |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 837 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 838 | std::ostream& os, |
| 839 | const QuicStopWaitingFrame& s); |
jri | 3285d93a | 2015-12-14 08:53:19 | [diff] [blame] | 840 | // Path which this stop waiting frame belongs to. |
| 841 | QuicPathId path_id; |
[email protected] | 310d37b | 2014-08-02 06:15:37 | [diff] [blame] | 842 | // Entropy hash of all packets up to, but not including, the least unacked |
| 843 | // packet. |
| 844 | QuicPacketEntropyHash entropy_hash; |
| 845 | // 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] | 846 | QuicPacketNumber least_unacked; |
[email protected] | 310d37b | 2014-08-02 06:15:37 | [diff] [blame] | 847 | }; |
| 848 | |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 849 | // A sequence of packet numbers where each number is unique. Intended to be used |
| 850 | // in a sliding window fashion, where smaller old packet numbers are removed and |
| 851 | // larger new packet numbers are added, with the occasional random access. |
| 852 | class NET_EXPORT_PRIVATE PacketNumberQueue { |
| 853 | public: |
rtenneti | 55a807c | 2016-02-05 03:05:54 | [diff] [blame] | 854 | // TODO(jdorfman): remove const_iterator and change the callers to iterate |
| 855 | // over the intervals. |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 856 | class NET_EXPORT_PRIVATE const_iterator |
| 857 | : public std::iterator<std::input_iterator_tag, |
| 858 | QuicPacketNumber, |
| 859 | std::ptrdiff_t, |
| 860 | const QuicPacketNumber*, |
| 861 | const QuicPacketNumber&> { |
| 862 | public: |
| 863 | explicit const_iterator(PacketNumberSet::const_iterator set_iter); |
| 864 | const_iterator( |
| 865 | IntervalSet<QuicPacketNumber>::const_iterator interval_set_iter, |
| 866 | QuicPacketNumber first, |
| 867 | QuicPacketNumber last); |
| 868 | const_iterator(const const_iterator& other); |
| 869 | const_iterator& operator=(const const_iterator& other); |
| 870 | // TODO(rtenneti): on windows RValue reference gives errors. |
| 871 | // const_iterator(const_iterator&& other); |
| 872 | ~const_iterator(); |
| 873 | |
| 874 | // TODO(rtenneti): on windows RValue reference gives errors. |
| 875 | // const_iterator& operator=(const_iterator&& other); |
| 876 | bool operator!=(const const_iterator& other) const; |
| 877 | bool operator==(const const_iterator& other) const; |
| 878 | value_type operator*() const; |
| 879 | const_iterator& operator++(); |
| 880 | const_iterator operator++(int /* postincrement */); |
| 881 | |
| 882 | private: |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 883 | IntervalSet<QuicPacketNumber>::const_iterator interval_set_iter_; |
| 884 | QuicPacketNumber current_; |
| 885 | QuicPacketNumber last_; |
| 886 | }; |
| 887 | |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 888 | PacketNumberQueue(); |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 889 | PacketNumberQueue(const PacketNumberQueue& other); |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 890 | // TODO(rtenneti): on windows RValue reference gives errors. |
| 891 | // PacketNumberQueue(PacketNumberQueue&& other); |
rtenneti | 93209a0 | 2015-09-19 01:51:18 | [diff] [blame] | 892 | ~PacketNumberQueue(); |
| 893 | |
| 894 | PacketNumberQueue& operator=(const PacketNumberQueue& other); |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 895 | // PacketNumberQueue& operator=(PacketNumberQueue&& other); |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 896 | |
| 897 | // Adds |packet_number| to the set of packets in the queue. |
| 898 | void Add(QuicPacketNumber packet_number); |
| 899 | |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 900 | // Adds packets between [lower, higher) to the set of packets in the queue. It |
| 901 | // is undefined behavior to call this with |higher| < |lower|. |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 902 | void Add(QuicPacketNumber lower, QuicPacketNumber higher); |
| 903 | |
| 904 | // Removes |packet_number| from the set of packets in the queue. |
| 905 | void Remove(QuicPacketNumber packet_number); |
| 906 | |
| 907 | // Removes packets with values less than |higher| from the set of packets in |
| 908 | // the queue. Returns true if packets were removed. |
| 909 | bool RemoveUpTo(QuicPacketNumber higher); |
| 910 | |
| 911 | // Returns true if the queue contains |packet_number|. |
| 912 | bool Contains(QuicPacketNumber packet_number) const; |
| 913 | |
| 914 | // Returns true if the queue is empty. |
| 915 | bool Empty() const; |
| 916 | |
| 917 | // Returns the minimum packet number stored in the queue. It is undefined |
| 918 | // behavior to call this if the queue is empty. |
| 919 | QuicPacketNumber Min() const; |
| 920 | |
| 921 | // Returns the maximum packet number stored in the queue. It is undefined |
| 922 | // behavior to call this if the queue is empty. |
| 923 | QuicPacketNumber Max() const; |
| 924 | |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 925 | // Returns the number of unique packets stored in the queue. Inefficient; only |
| 926 | // exposed for testing. |
| 927 | size_t NumPacketsSlow() const; |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 928 | |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 929 | // Returns iterators over the individual packet numbers. |
| 930 | const_iterator begin() const; |
| 931 | const_iterator end() const; |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 932 | const_iterator lower_bound(QuicPacketNumber packet_number) const; |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 933 | |
| 934 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 935 | std::ostream& os, |
| 936 | const PacketNumberQueue& q); |
| 937 | |
| 938 | private: |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 939 | IntervalSet<QuicPacketNumber> packet_number_intervals_; |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 940 | }; |
| 941 | |
[email protected] | 310d37b | 2014-08-02 06:15:37 | [diff] [blame] | 942 | struct NET_EXPORT_PRIVATE QuicAckFrame { |
| 943 | QuicAckFrame(); |
vmpstr | acd23b7 | 2016-02-26 21:08:55 | [diff] [blame] | 944 | QuicAckFrame(const QuicAckFrame& other); |
[email protected] | 310d37b | 2014-08-02 06:15:37 | [diff] [blame] | 945 | ~QuicAckFrame(); |
| 946 | |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 947 | NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, |
| 948 | const QuicAckFrame& s); |
[email protected] | a674b4c | 2012-12-05 03:44:30 | [diff] [blame] | 949 | |
jri | 3285d93a | 2015-12-14 08:53:19 | [diff] [blame] | 950 | // Path which this ack belongs to. |
| 951 | QuicPathId path_id; |
| 952 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 953 | // Entropy hash of all packets up to largest observed not including missing |
| 954 | // packets. |
| 955 | QuicPacketEntropyHash entropy_hash; |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 956 | |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 957 | // Whether the ack had to be truncated when sent. |
| 958 | bool is_truncated; |
| 959 | |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 960 | // The highest packet number we've observed from the peer. |
[email protected] | 48697d8a | 2013-01-15 19:42:24 | [diff] [blame] | 961 | // |
| 962 | // In general, this should be the largest packet number we've received. In |
| 963 | // the case of truncated acks, we may have to advertise a lower "upper bound" |
| 964 | // than largest received, to avoid implicitly acking missing packets that |
| 965 | // don't fit in the missing packet list due to size limitations. In this |
| 966 | // case, largest_observed may be a packet which is also in the missing packets |
| 967 | // list. |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 968 | QuicPacketNumber largest_observed; |
[email protected] | a674b4c | 2012-12-05 03:44:30 | [diff] [blame] | 969 | |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 970 | // Time elapsed since largest_observed was received until this Ack frame was |
| 971 | // sent. |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 972 | QuicTime::Delta ack_delay_time; |
[email protected] | 14e8106c | 2013-03-14 16:25:33 | [diff] [blame] | 973 | |
ckrasic | ea295fe | 2015-10-31 05:03:27 | [diff] [blame] | 974 | // Vector of <packet_number, time> for when packets arrived. |
| 975 | PacketTimeVector received_packet_times; |
| 976 | |
[email protected] | e537f74 | 2012-12-07 15:33:53 | [diff] [blame] | 977 | // The set of packets which we're expecting and have not received. |
rtenneti | 493d90ef | 2015-09-14 04:43:11 | [diff] [blame] | 978 | PacketNumberQueue missing_packets; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 979 | }; |
| 980 | |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 981 | // True if the packet number is greater than largest_observed or is listed |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 982 | // as missing. |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 983 | // Always returns false for packet numbers less than least_unacked. |
| 984 | bool NET_EXPORT_PRIVATE IsAwaitingPacket(const QuicAckFrame& ack_frame, |
| 985 | QuicPacketNumber packet_number); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 986 | |
[email protected] | a692ad9d | 2014-07-18 21:35:24 | [diff] [blame] | 987 | // Defines for all types of congestion control algorithms that can be used in |
| 988 | // QUIC. Note that this is separate from the congestion feedback type - |
| 989 | // some congestion control algorithms may use the same feedback type |
| 990 | // (Reno and Cubic are the classic example for that). |
| 991 | enum CongestionControlType { |
| 992 | kCubic, |
rtenneti | fb3fa6c | 2015-03-16 23:04:55 | [diff] [blame] | 993 | kCubicBytes, |
[email protected] | a692ad9d | 2014-07-18 21:35:24 | [diff] [blame] | 994 | kReno, |
rtenneti | fb3fa6c | 2015-03-16 23:04:55 | [diff] [blame] | 995 | kRenoBytes, |
[email protected] | a692ad9d | 2014-07-18 21:35:24 | [diff] [blame] | 996 | kBBR, |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 997 | }; |
| 998 | |
[email protected] | c5cc9bd | 2014-03-31 23:17:14 | [diff] [blame] | 999 | enum LossDetectionType { |
| 1000 | kNack, // Used to mimic TCP's loss detection. |
| 1001 | kTime, // Time based loss detection. |
| 1002 | }; |
| 1003 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 1004 | struct NET_EXPORT_PRIVATE QuicRstStreamFrame { |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1005 | QuicRstStreamFrame(); |
| 1006 | QuicRstStreamFrame(QuicStreamId stream_id, |
| 1007 | QuicRstStreamErrorCode error_code, |
| 1008 | QuicStreamOffset bytes_written); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1009 | |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 1010 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1011 | std::ostream& os, |
| 1012 | const QuicRstStreamFrame& r); |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 1013 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1014 | QuicStreamId stream_id; |
[email protected] | 74bda14 | 2013-03-31 02:49:11 | [diff] [blame] | 1015 | QuicRstStreamErrorCode error_code; |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1016 | |
| 1017 | // Used to update flow control windows. On termination of a stream, both |
| 1018 | // endpoints must inform the peer of the number of bytes they have sent on |
| 1019 | // that stream. This can be done through normal termination (data packet with |
| 1020 | // FIN) or through a RST. |
| 1021 | QuicStreamOffset byte_offset; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1022 | }; |
| 1023 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 1024 | struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame { |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1025 | QuicConnectionCloseFrame(); |
| 1026 | |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 1027 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1028 | std::ostream& os, |
| 1029 | const QuicConnectionCloseFrame& c); |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 1030 | |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 1031 | QuicErrorCode error_code; |
[email protected] | 431bb4fd | 2012-10-19 17:46:09 | [diff] [blame] | 1032 | std::string error_details; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1033 | }; |
| 1034 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1035 | struct NET_EXPORT_PRIVATE QuicGoAwayFrame { |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1036 | QuicGoAwayFrame(); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1037 | QuicGoAwayFrame(QuicErrorCode error_code, |
| 1038 | QuicStreamId last_good_stream_id, |
| 1039 | const std::string& reason); |
| 1040 | |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1041 | NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, |
| 1042 | const QuicGoAwayFrame& g); |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 1043 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1044 | QuicErrorCode error_code; |
| 1045 | QuicStreamId last_good_stream_id; |
| 1046 | std::string reason_phrase; |
| 1047 | }; |
| 1048 | |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1049 | // Flow control updates per-stream and at the connection levoel. |
| 1050 | // Based on SPDY's WINDOW_UPDATE frame, but uses an absolute byte offset rather |
| 1051 | // than a window delta. |
| 1052 | // TODO(rjshade): A possible future optimization is to make stream_id and |
| 1053 | // byte_offset variable length, similar to stream frames. |
| 1054 | struct NET_EXPORT_PRIVATE QuicWindowUpdateFrame { |
| 1055 | QuicWindowUpdateFrame() {} |
| 1056 | QuicWindowUpdateFrame(QuicStreamId stream_id, QuicStreamOffset byte_offset); |
| 1057 | |
| 1058 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1059 | std::ostream& os, |
| 1060 | const QuicWindowUpdateFrame& w); |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1061 | |
| 1062 | // The stream this frame applies to. 0 is a special case meaning the overall |
| 1063 | // connection rather than a specific stream. |
| 1064 | QuicStreamId stream_id; |
| 1065 | |
| 1066 | // Byte offset in the stream or connection. The receiver of this frame must |
| 1067 | // not send data which would result in this offset being exceeded. |
| 1068 | QuicStreamOffset byte_offset; |
| 1069 | }; |
| 1070 | |
| 1071 | // The BLOCKED frame is used to indicate to the remote endpoint that this |
| 1072 | // endpoint believes itself to be flow-control blocked but otherwise ready to |
| 1073 | // send data. The BLOCKED frame is purely advisory and optional. |
| 1074 | // Based on SPDY's BLOCKED frame (undocumented as of 2014-01-28). |
| 1075 | struct NET_EXPORT_PRIVATE QuicBlockedFrame { |
| 1076 | QuicBlockedFrame() {} |
| 1077 | explicit QuicBlockedFrame(QuicStreamId stream_id); |
| 1078 | |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1079 | NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, |
| 1080 | const QuicBlockedFrame& b); |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1081 | |
| 1082 | // The stream this frame applies to. 0 is a special case meaning the overall |
| 1083 | // connection rather than a specific stream. |
| 1084 | QuicStreamId stream_id; |
| 1085 | }; |
| 1086 | |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 1087 | // The PATH_CLOSE frame is used to explicitly close a path. Both endpoints can |
| 1088 | // send a PATH_CLOSE frame to initiate a path termination. A path is considered |
| 1089 | // to be closed either a PATH_CLOSE frame is sent or received. An endpoint drops |
| 1090 | // receive side of a closed path, and packets with retransmittable frames on a |
| 1091 | // closed path are marked as retransmissions which will be transmitted on other |
| 1092 | // paths. |
| 1093 | struct NET_EXPORT_PRIVATE QuicPathCloseFrame { |
| 1094 | QuicPathCloseFrame() {} |
| 1095 | explicit QuicPathCloseFrame(QuicPathId path_id); |
| 1096 | |
| 1097 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 1098 | std::ostream& os, |
| 1099 | const QuicPathCloseFrame& p); |
| 1100 | |
| 1101 | QuicPathId path_id; |
| 1102 | }; |
| 1103 | |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 1104 | // EncryptionLevel enumerates the stages of encryption that a QUIC connection |
| 1105 | // progresses through. When retransmitting a packet, the encryption level needs |
| 1106 | // to be specified so that it is retransmitted at a level which the peer can |
| 1107 | // understand. |
fayang | a64c1a9 | 2016-02-13 01:55:58 | [diff] [blame] | 1108 | enum EncryptionLevel : int8_t { |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 1109 | ENCRYPTION_NONE = 0, |
| 1110 | ENCRYPTION_INITIAL = 1, |
| 1111 | ENCRYPTION_FORWARD_SECURE = 2, |
| 1112 | |
| 1113 | NUM_ENCRYPTION_LEVELS, |
| 1114 | }; |
| 1115 | |
rch | 99b644c | 2015-11-04 05:25:28 | [diff] [blame] | 1116 | enum PeerAddressChangeType { |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 1117 | // IP address and port remain unchanged. |
rch | 99b644c | 2015-11-04 05:25:28 | [diff] [blame] | 1118 | NO_CHANGE, |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 1119 | // Port changed, but IP address remains unchanged. |
| 1120 | PORT_CHANGE, |
| 1121 | // IPv4 address changed, but within the /24 subnet (port may have changed.) |
| 1122 | IPV4_SUBNET_CHANGE, |
| 1123 | // IP address change from an IPv4 to an IPv6 address (port may have changed.) |
| 1124 | IPV4_TO_IPV6_CHANGE, |
| 1125 | // IP address change from an IPv6 to an IPv4 address (port may have changed.) |
| 1126 | IPV6_TO_IPV4_CHANGE, |
| 1127 | // IP address change from an IPv6 to an IPv6 address (port may have changed.) |
| 1128 | IPV6_TO_IPV6_CHANGE, |
| 1129 | // All other peer address changes. |
| 1130 | UNSPECIFIED_CHANGE, |
rch | 99b644c | 2015-11-04 05:25:28 | [diff] [blame] | 1131 | }; |
| 1132 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 1133 | struct NET_EXPORT_PRIVATE QuicFrame { |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1134 | QuicFrame(); |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 1135 | explicit QuicFrame(QuicPaddingFrame padding_frame); |
| 1136 | explicit QuicFrame(QuicMtuDiscoveryFrame frame); |
| 1137 | explicit QuicFrame(QuicPingFrame frame); |
| 1138 | |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1139 | explicit QuicFrame(QuicStreamFrame* stream_frame); |
| 1140 | explicit QuicFrame(QuicAckFrame* frame); |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1141 | explicit QuicFrame(QuicRstStreamFrame* frame); |
| 1142 | explicit QuicFrame(QuicConnectionCloseFrame* frame); |
[email protected] | 93dd91f | 2014-02-27 00:09:03 | [diff] [blame] | 1143 | explicit QuicFrame(QuicStopWaitingFrame* frame); |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1144 | explicit QuicFrame(QuicGoAwayFrame* frame); |
| 1145 | explicit QuicFrame(QuicWindowUpdateFrame* frame); |
| 1146 | explicit QuicFrame(QuicBlockedFrame* frame); |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 1147 | explicit QuicFrame(QuicPathCloseFrame* frame); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1148 | |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1149 | NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, |
| 1150 | const QuicFrame& frame); |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 1151 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 1152 | QuicFrameType type; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1153 | union { |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 1154 | // Frames smaller than a pointer are inline. |
| 1155 | QuicPaddingFrame padding_frame; |
| 1156 | QuicMtuDiscoveryFrame mtu_discovery_frame; |
| 1157 | QuicPingFrame ping_frame; |
| 1158 | |
| 1159 | // Frames larger than a pointer. |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 1160 | QuicStreamFrame* stream_frame; |
| 1161 | QuicAckFrame* ack_frame; |
[email protected] | 93dd91f | 2014-02-27 00:09:03 | [diff] [blame] | 1162 | QuicStopWaitingFrame* stop_waiting_frame; |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 1163 | QuicRstStreamFrame* rst_stream_frame; |
| 1164 | QuicConnectionCloseFrame* connection_close_frame; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1165 | QuicGoAwayFrame* goaway_frame; |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1166 | QuicWindowUpdateFrame* window_update_frame; |
| 1167 | QuicBlockedFrame* blocked_frame; |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 1168 | QuicPathCloseFrame* path_close_frame; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1169 | }; |
| 1170 | }; |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 1171 | // QuicFrameType consumes 8 bytes with padding. |
| 1172 | static_assert(sizeof(QuicFrame) <= 16, |
| 1173 | "Frames larger than 8 bytes should be referenced by pointer."); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1174 | |
[email protected] | be24ab2 | 2012-10-22 03:01:52 | [diff] [blame] | 1175 | typedef std::vector<QuicFrame> QuicFrames; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1176 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1177 | class NET_EXPORT_PRIVATE QuicData { |
| 1178 | public: |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1179 | QuicData(const char* buffer, size_t length); |
| 1180 | QuicData(char* buffer, size_t length, bool owns_buffer); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1181 | virtual ~QuicData(); |
| 1182 | |
| 1183 | base::StringPiece AsStringPiece() const { |
| 1184 | return base::StringPiece(data(), length()); |
| 1185 | } |
| 1186 | |
| 1187 | const char* data() const { return buffer_; } |
| 1188 | size_t length() const { return length_; } |
rtenneti | e0ee6eb | 2015-05-01 00:55:09 | [diff] [blame] | 1189 | bool owns_buffer() const { return owns_buffer_; } |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1190 | |
| 1191 | private: |
| 1192 | const char* buffer_; |
| 1193 | size_t length_; |
| 1194 | bool owns_buffer_; |
| 1195 | |
| 1196 | DISALLOW_COPY_AND_ASSIGN(QuicData); |
| 1197 | }; |
| 1198 | |
| 1199 | class NET_EXPORT_PRIVATE QuicPacket : public QuicData { |
| 1200 | public: |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 1201 | // TODO(fayang): 4 fields from public header are passed in as arguments. |
| 1202 | // Consider to add a convenience method which directly accepts the entire |
| 1203 | // public header. |
rtenneti | ca5ac27 | 2015-02-07 12:35:12 | [diff] [blame] | 1204 | QuicPacket(char* buffer, |
| 1205 | size_t length, |
| 1206 | bool owns_buffer, |
| 1207 | QuicConnectionIdLength connection_id_length, |
| 1208 | bool includes_version, |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 1209 | bool includes_path_id, |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 1210 | QuicPacketNumberLength packet_number_length); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1211 | |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 1212 | base::StringPiece AssociatedData() const; |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 1213 | base::StringPiece Plaintext() const; |
[email protected] | 082b65b | 2012-11-10 19:11:31 | [diff] [blame] | 1214 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1215 | char* mutable_data() { return buffer_; } |
| 1216 | |
| 1217 | private: |
| 1218 | char* buffer_; |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 1219 | const QuicConnectionIdLength connection_id_length_; |
[email protected] | 5351cc4b | 2013-03-03 07:22:41 | [diff] [blame] | 1220 | const bool includes_version_; |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 1221 | const bool includes_path_id_; |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 1222 | const QuicPacketNumberLength packet_number_length_; |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1223 | |
[email protected] | 2e740db | 2012-10-20 19:35:19 | [diff] [blame] | 1224 | DISALLOW_COPY_AND_ASSIGN(QuicPacket); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1225 | }; |
| 1226 | |
| 1227 | class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData { |
| 1228 | public: |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 1229 | QuicEncryptedPacket(const char* buffer, size_t length); |
| 1230 | QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1231 | |
[email protected] | ec86d546 | 2013-11-17 16:04:49 | [diff] [blame] | 1232 | // Clones the packet into a new packet which owns the buffer. |
| 1233 | QuicEncryptedPacket* Clone() const; |
| 1234 | |
[email protected] | c1b32c6 | 2013-01-20 02:49:10 | [diff] [blame] | 1235 | // By default, gtest prints the raw bytes of an object. The bool data |
| 1236 | // member (in the base class QuicData) causes this object to have padding |
| 1237 | // bytes, which causes the default gtest object printer to read |
| 1238 | // uninitialize memory. So we need to teach gtest how to print this object. |
| 1239 | NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1240 | std::ostream& os, |
| 1241 | const QuicEncryptedPacket& s); |
[email protected] | c1b32c6 | 2013-01-20 02:49:10 | [diff] [blame] | 1242 | |
[email protected] | 2e740db | 2012-10-20 19:35:19 | [diff] [blame] | 1243 | private: |
| 1244 | DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket); |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1245 | }; |
| 1246 | |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 1247 | // Pure virtual class to listen for packet acknowledgements. |
| 1248 | class NET_EXPORT_PRIVATE QuicAckListenerInterface |
| 1249 | : public base::RefCounted<QuicAckListenerInterface> { |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1250 | public: |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 1251 | QuicAckListenerInterface() {} |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1252 | |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 1253 | // Called when a packet is acked. Called once per packet. |
| 1254 | // |acked_bytes| is the number of data bytes acked. |
| 1255 | virtual void OnPacketAcked(int acked_bytes, |
| 1256 | QuicTime::Delta ack_delay_time) = 0; |
rtenneti | 73e25c1 | 2015-03-16 06:12:43 | [diff] [blame] | 1257 | |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 1258 | // Called when a packet is retransmitted. Called once per packet. |
| 1259 | // |retransmitted_bytes| is the number of data bytes retransmitted. |
| 1260 | virtual void OnPacketRetransmitted(int retransmitted_bytes) = 0; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1261 | |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 1262 | protected: |
| 1263 | friend class base::RefCounted<QuicAckListenerInterface>; |
[email protected] | 2115d33ba | 2014-01-02 21:53:52 | [diff] [blame] | 1264 | |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 1265 | // Delegates are ref counted. |
| 1266 | virtual ~QuicAckListenerInterface() {} |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1267 | }; |
| 1268 | |
rtenneti | 8dd12b2 | 2015-10-21 01:26:38 | [diff] [blame] | 1269 | struct NET_EXPORT_PRIVATE AckListenerWrapper { |
| 1270 | AckListenerWrapper(QuicAckListenerInterface* listener, |
| 1271 | QuicPacketLength data_length); |
vmpstr | acd23b7 | 2016-02-26 21:08:55 | [diff] [blame] | 1272 | AckListenerWrapper(const AckListenerWrapper& other); |
rtenneti | 8dd12b2 | 2015-10-21 01:26:38 | [diff] [blame] | 1273 | ~AckListenerWrapper(); |
| 1274 | |
| 1275 | scoped_refptr<QuicAckListenerInterface> ack_listener; |
| 1276 | QuicPacketLength length; |
| 1277 | }; |
| 1278 | |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1279 | struct NET_EXPORT_PRIVATE SerializedPacket { |
fayang | a31a74b | 2015-12-28 17:27:14 | [diff] [blame] | 1280 | SerializedPacket(QuicPathId path_id, |
| 1281 | QuicPacketNumber packet_number, |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 1282 | QuicPacketNumberLength packet_number_length, |
rtenneti | 2cae207 | 2016-02-05 02:21:33 | [diff] [blame] | 1283 | const char* encrypted_buffer, |
| 1284 | QuicPacketLength encrypted_length, |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1285 | QuicPacketEntropyHash entropy_hash, |
rtenneti | 9bd5d4b | 2015-08-21 05:44:52 | [diff] [blame] | 1286 | bool has_ack, |
| 1287 | bool has_stop_waiting); |
vmpstr | acd23b7 | 2016-02-26 21:08:55 | [diff] [blame] | 1288 | SerializedPacket(const SerializedPacket& other); |
[email protected] | 97cf302 | 2013-09-05 14:30:16 | [diff] [blame] | 1289 | ~SerializedPacket(); |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1290 | |
rtenneti | 2cae207 | 2016-02-05 02:21:33 | [diff] [blame] | 1291 | // Not owned. |
| 1292 | const char* encrypted_buffer; |
| 1293 | QuicPacketLength encrypted_length; |
rtenneti | f85706db | 2016-02-04 02:43:03 | [diff] [blame] | 1294 | QuicFrames retransmittable_frames; |
jri | c533399b | 2016-01-29 07:36:01 | [diff] [blame] | 1295 | IsHandshake has_crypto_handshake; |
| 1296 | bool needs_padding; |
fayang | a31a74b | 2015-12-28 17:27:14 | [diff] [blame] | 1297 | QuicPathId path_id; |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 1298 | QuicPacketNumber packet_number; |
| 1299 | QuicPacketNumberLength packet_number_length; |
jokulik | 2324d28 | 2015-12-08 21:42:57 | [diff] [blame] | 1300 | EncryptionLevel encryption_level; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1301 | QuicPacketEntropyHash entropy_hash; |
rtenneti | 9bd5d4b | 2015-08-21 05:44:52 | [diff] [blame] | 1302 | bool has_ack; |
| 1303 | bool has_stop_waiting; |
zhongyi | 4a9d27b | 2016-01-12 20:08:31 | [diff] [blame] | 1304 | QuicPacketNumber original_packet_number; |
| 1305 | TransmissionType transmission_type; |
[email protected] | 97cf302 | 2013-09-05 14:30:16 | [diff] [blame] | 1306 | |
rtenneti | 6b1c5b1 | 2015-01-13 20:08:35 | [diff] [blame] | 1307 | // Optional notifiers which will be informed when this packet has been ACKed. |
rtenneti | 8dd12b2 | 2015-10-21 01:26:38 | [diff] [blame] | 1308 | std::list<AckListenerWrapper> listeners; |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 1309 | }; |
| 1310 | |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 1311 | struct NET_EXPORT_PRIVATE TransmissionInfo { |
| 1312 | // Used by STL when assigning into a map. |
| 1313 | TransmissionInfo(); |
| 1314 | |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 1315 | // Constructs a Transmission with a new all_transmissions set |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 1316 | // containing |packet_number|. |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 1317 | TransmissionInfo(EncryptionLevel level, |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 1318 | QuicPacketNumberLength packet_number_length, |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 1319 | TransmissionType transmission_type, |
rtenneti | 3183ac4 | 2015-02-28 03:39:41 | [diff] [blame] | 1320 | QuicTime sent_time, |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 1321 | QuicPacketLength bytes_sent, |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 1322 | bool has_crypto_handshake, |
| 1323 | bool needs_padding); |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 1324 | |
vmpstr | acd23b7 | 2016-02-26 21:08:55 | [diff] [blame] | 1325 | TransmissionInfo(const TransmissionInfo& other); |
| 1326 | |
rtenneti | 8dd12b2 | 2015-10-21 01:26:38 | [diff] [blame] | 1327 | ~TransmissionInfo(); |
| 1328 | |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 1329 | QuicFrames retransmittable_frames; |
jokulik | 2324d28 | 2015-12-08 21:42:57 | [diff] [blame] | 1330 | EncryptionLevel encryption_level; |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 1331 | QuicPacketNumberLength packet_number_length; |
rtenneti | 5ca6eee | 2015-10-15 21:54:30 | [diff] [blame] | 1332 | QuicPacketLength bytes_sent; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 1333 | uint16_t nack_count; |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 1334 | QuicTime sent_time; |
[email protected] | 730b35d7 | 2014-06-05 03:23:22 | [diff] [blame] | 1335 | // Reason why this packet was transmitted. |
| 1336 | TransmissionType transmission_type; |
[email protected] | aa7e4ef | 2014-05-28 03:53:15 | [diff] [blame] | 1337 | // In flight packets have not been abandoned or lost. |
| 1338 | bool in_flight; |
rtenneti | 31e9fd6 | 2014-09-16 05:22:15 | [diff] [blame] | 1339 | // True if the packet can never be acked, so it can be removed. |
| 1340 | bool is_unackable; |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 1341 | // True if the packet contains stream data from the crypto stream. |
| 1342 | bool has_crypto_handshake; |
| 1343 | // True if the packet needs padding if it's retransmitted. |
| 1344 | bool needs_padding; |
zhongyi | 1fb9bc5 | 2015-11-24 23:09:42 | [diff] [blame] | 1345 | // Stores the packet number of the next retransmission of this packet. |
| 1346 | // Zero if the packet has not been retransmitted. |
| 1347 | QuicPacketNumber retransmission; |
rtenneti | 8dd12b2 | 2015-10-21 01:26:38 | [diff] [blame] | 1348 | // Non-empty if there is a listener for this packet. |
| 1349 | std::list<AckListenerWrapper> ack_listeners; |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 1350 | }; |
fayang | a64c1a9 | 2016-02-13 01:55:58 | [diff] [blame] | 1351 | static_assert(sizeof(TransmissionInfo) <= 128, |
| 1352 | "TODO(ianswett): Keep the TransmissionInfo size to a cacheline."); |
[email protected] | 77b5d50b | 2014-05-07 22:48:48 | [diff] [blame] | 1353 | |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 1354 | // Struct to store the pending retransmission information. |
| 1355 | struct PendingRetransmission { |
| 1356 | PendingRetransmission(QuicPathId path_id, |
| 1357 | QuicPacketNumber packet_number, |
| 1358 | TransmissionType transmission_type, |
| 1359 | const QuicFrames& retransmittable_frames, |
| 1360 | bool has_crypto_handshake, |
| 1361 | bool needs_padding, |
| 1362 | EncryptionLevel encryption_level, |
| 1363 | QuicPacketNumberLength packet_number_length) |
fayang | a64c1a9 | 2016-02-13 01:55:58 | [diff] [blame] | 1364 | : packet_number(packet_number), |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 1365 | retransmittable_frames(retransmittable_frames), |
fayang | a64c1a9 | 2016-02-13 01:55:58 | [diff] [blame] | 1366 | transmission_type(transmission_type), |
| 1367 | path_id(path_id), |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 1368 | has_crypto_handshake(has_crypto_handshake), |
| 1369 | needs_padding(needs_padding), |
| 1370 | encryption_level(encryption_level), |
| 1371 | packet_number_length(packet_number_length) {} |
| 1372 | |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 1373 | QuicPacketNumber packet_number; |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 1374 | const QuicFrames& retransmittable_frames; |
fayang | a64c1a9 | 2016-02-13 01:55:58 | [diff] [blame] | 1375 | TransmissionType transmission_type; |
| 1376 | QuicPathId path_id; |
rch | caec424 | 2016-01-22 20:49:52 | [diff] [blame] | 1377 | bool has_crypto_handshake; |
| 1378 | bool needs_padding; |
| 1379 | EncryptionLevel encryption_level; |
| 1380 | QuicPacketNumberLength packet_number_length; |
| 1381 | }; |
| 1382 | |
rtenneti | c14c8ab | 2015-06-18 05:47:40 | [diff] [blame] | 1383 | // Convenience wrapper to wrap an iovec array and the total length, which must |
| 1384 | // be less than or equal to the actual total length of the iovecs. |
| 1385 | struct NET_EXPORT_PRIVATE QuicIOVector { |
| 1386 | QuicIOVector(const struct iovec* iov, int iov_count, size_t total_length) |
| 1387 | : iov(iov), iov_count(iov_count), total_length(total_length) {} |
| 1388 | |
| 1389 | const struct iovec* iov; |
| 1390 | const int iov_count; |
| 1391 | const size_t total_length; |
| 1392 | }; |
| 1393 | |
[email protected] | 8b37a09 | 2012-10-18 21:53:49 | [diff] [blame] | 1394 | } // namespace net |
| 1395 | |
| 1396 | #endif // NET_QUIC_QUIC_PROTOCOL_H_ |