15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NET_QUIC_QUIC_PROTOCOL_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NET_QUIC_QUIC_PROTOCOL_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <stddef.h>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <limits>
101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include <list>
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <map>
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <ostream>
132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <set>
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string>
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <utility>
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/containers/hash_tables.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/logging.h"
21c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/strings/string_piece.h"
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/base/int128.h"
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "net/base/ip_endpoint.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_export.h"
25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "net/quic/iovector.h"
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/quic/quic_bandwidth.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/quic/quic_time.h"
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)class QuicAckNotifier;
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class QuicPacket;
33868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)struct QuicPacketHeader;
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)typedef uint64 QuicConnectionId;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef uint32 QuicStreamId;
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef uint64 QuicStreamOffset;
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef uint64 QuicPacketSequenceNumber;
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef QuicPacketSequenceNumber QuicFecGroupNumber;
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef uint64 QuicPublicResetNonceProof;
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef uint8 QuicPacketEntropyHash;
42b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)typedef uint32 QuicHeaderId;
43b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// QuicTag is the type of a tag in the wire protocol.
44b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)typedef uint32 QuicTag;
45b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)typedef std::vector<QuicTag> QuicTagVector;
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)typedef std::map<QuicTag, std::string> QuicTagValueMap;
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// TODO(rtenneti): Didn't use SpdyPriority because SpdyPriority is uint8 and
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// QuicPriority is uint32. Use SpdyPriority when we change the QUIC_VERSION.
49424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)typedef uint32 QuicPriority;
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TODO(rch): Consider Quic specific names for these constants.
520f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Default and initial maximum size in bytes of a QUIC packet.
535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)const QuicByteCount kDefaultMaxPacketSize = 1350;
540f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// The maximum packet size of any QUIC packet, based on ethernet's max size,
55a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// minus the IP and UDP headers. IPv6 has a 40 byte header, UPD adds an
56a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// additional 8 bytes.  This is a total overhead of 48 bytes.  Ethernet's
57a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// max packet size is 1500 bytes,  1500 - 48 = 1452.
58a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)const QuicByteCount kMaxPacketSize = 1452;
59cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Default maximum packet size used in Linux TCP implementations.
60cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)const QuicByteCount kDefaultTCPMSS = 1460;
610f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
620f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Maximum size of the initial congestion window in packets.
630f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)const size_t kDefaultInitialWindow = 10;
640529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochconst uint32 kMaxInitialWindow = 100;
650f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
666d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)// Default size of initial flow control window, for both stream and session.
67e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochconst uint32 kDefaultFlowControlSendWindow = 16 * 1024;  // 16 KB
68e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch
69f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// Maximum size of the congestion window, in packets, for TCP congestion control
70f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// algorithms.
71f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)const size_t kMaxTcpCongestionWindow = 200;
72f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
736e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Size of the socket receive buffer in bytes.
746e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)const QuicByteCount kDefaultSocketReceiveBuffer = 256 * 1024;
756e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
760f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Don't allow a client to suggest an RTT longer than 15 seconds.
770529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochconst uint32 kMaxInitialRoundTripTimeUs = 15 * kNumMicrosPerSecond;
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Maximum number of open streams per connection.
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const size_t kDefaultMaxStreamsPerConnection = 100;
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Number of bytes reserved for public flags in the packet header.
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const size_t kPublicFlagsSize = 1;
842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Number of bytes reserved for version number in the packet header.
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const size_t kQuicVersionSize = 4;
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Number of bytes reserved for private flags in the packet header.
872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const size_t kPrivateFlagsSize = 1;
882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Number of bytes reserved for FEC group in the packet header.
892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const size_t kFecGroupSize = 1;
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Signifies that the QuicPacket will contain version of the protocol.
922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const bool kIncludeVersion = true;
932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Index of the first byte in a QUIC packet which is used in hash calculation.
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const size_t kStartOfHashData = 0;
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Limit on the delta between stream IDs.
98e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochconst QuicStreamId kMaxStreamIdDelta = 200;
99b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Limit on the delta between header IDs.
100e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochconst QuicHeaderId kMaxHeaderIdDelta = 200;
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Reserved ID for the crypto stream.
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const QuicStreamId kCryptoStreamId = 1;
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Reserved ID for the headers stream.
1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const QuicStreamId kHeadersStreamId = 3;
1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1086e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)// Maximum delayed ack time, in ms.
10903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)const int kMaxDelayedAckTimeMs = 25;
1106e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// The default idle timeout before the crypto handshake succeeds.
112868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)const int64 kDefaultInitialTimeoutSecs = 120;  // 2 mins.
1131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// The maximum idle timeout that can be negotiated.
1141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciconst int64 kMaximumIdleTimeoutSecs = 60 * 10;  // 10 minutes.
1151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// The default timeout for a connection until the crypto handshake succeeds.
1161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciconst int64 kDefaultMaxTimeForCryptoHandshakeSecs = 10;  // 10 secs.
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// Default ping timeout.
1190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochconst int64 kPingTimeoutSecs = 15;  // 15 secs.
1200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
12103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// Minimum number of RTTs between Server Config Updates (SCUP) sent to client.
12203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)const int kMinIntervalBetweenServerConfigUpdatesRTTs = 10;
12303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
12403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)// Minimum time between Server Config Updates (SCUP) sent to client.
12503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)const int kMinIntervalBetweenServerConfigUpdatesMs = 1000;
12603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
1271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Multiplier that allows server to accept slightly more streams than
1281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// negotiated in handshake.
1291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciconst float kMaxStreamsMultiplier = 1.1f;
1301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// We define an unsigned 16-bit floating point value, inspired by IEEE floats
1321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// (http://en.wikipedia.org/wiki/Half_precision_floating-point_format),
1331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// with 5-bit exponent (bias 1), 11-bit mantissa (effective 12 with hidden
1341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// bit) and denormals, but without signs, transfinites or fractions. Wire format
1351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// 16 bits (little-endian byte order) are split into exponent (high 5) and
1361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// mantissa (low 11) and decoded as:
1371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//   uint64 value;
1381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//   if (exponent == 0) value = mantissa;
1391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)//   else value = (mantissa | 1 << 11) << (exponent - 1)
1401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const int kUFloat16ExponentBits = 5;
1411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const int kUFloat16MaxExponent = (1 << kUFloat16ExponentBits) - 2;  // 30
1421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const int kUFloat16MantissaBits = 16 - kUFloat16ExponentBits;  // 11
1431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const int kUFloat16MantissaEffectiveBits = kUFloat16MantissaBits + 1;  // 12
1441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)const uint64 kUFloat16MaxValue =  // 0x3FFC0000000
1451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    ((GG_UINT64_C(1) << kUFloat16MantissaEffectiveBits) - 1) <<
1461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    kUFloat16MaxExponent;
1471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
14868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles)enum TransmissionType {
149b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  NOT_RETRANSMISSION,
15023730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  FIRST_TRANSMISSION_TYPE = NOT_RETRANSMISSION,
15123730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  HANDSHAKE_RETRANSMISSION,  // Retransmits due to handshake timeouts.
1521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ALL_UNACKED_RETRANSMISSION,  // Retransmits all unacked packets.
1531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  ALL_INITIAL_RETRANSMISSION,  // Retransmits all initially encrypted packets.
15423730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  LOSS_RETRANSMISSION,  // Retransmits due to loss detection.
15523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  RTO_RETRANSMISSION,  // Retransmits due to retransmit time out.
15623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  TLP_RETRANSMISSION,  // Tail loss probes.
15723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)  LAST_TRANSMISSION_TYPE = TLP_RETRANSMISSION,
158c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)};
159c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
160c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)enum HasRetransmittableData {
161b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  NO_RETRANSMITTABLE_DATA,
162b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  HAS_RETRANSMITTABLE_DATA,
163c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)};
164c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
165a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)enum IsHandshake {
166a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  NOT_HANDSHAKE,
167a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)  IS_HANDSHAKE
168a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)};
169a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)
170f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)// Indicates FEC protection level for data being written.
171f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)enum FecProtection {
172f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  MUST_FEC_PROTECT,  // Callee must FEC protect this data.
173f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  MAY_FEC_PROTECT    // Callee does not have to but may FEC protect this data.
174f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)};
175f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1766d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)// Indicates FEC policy.
177f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)enum FecPolicy {
178f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  FEC_PROTECT_ALWAYS,   // All data in the stream should be FEC protected.
179f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  FEC_PROTECT_OPTIONAL  // Data in the stream does not need FEC protection.
180f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)};
181f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum QuicFrameType {
1835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Regular frame types. The values set here cannot change without the
1845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // introduction of a new QUIC version.
1852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  PADDING_FRAME = 0,
1865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  RST_STREAM_FRAME = 1,
1875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  CONNECTION_CLOSE_FRAME = 2,
1885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  GOAWAY_FRAME = 3,
1895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  WINDOW_UPDATE_FRAME = 4,
1905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  BLOCKED_FRAME = 5,
191a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  STOP_WAITING_FRAME = 6,
1920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  PING_FRAME = 7,
1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // STREAM, ACK, and CONGESTION_FEEDBACK frames are special frames. They are
1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // encoded differently on the wire and their values do not need to be stable.
19658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  STREAM_FRAME,
19758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  ACK_FRAME,
19858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  CONGESTION_FEEDBACK_FRAME,
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  NUM_FRAME_TYPES
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
202a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)enum QuicConnectionIdLength {
203a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  PACKET_0BYTE_CONNECTION_ID = 0,
204a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  PACKET_1BYTE_CONNECTION_ID = 1,
205a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  PACKET_4BYTE_CONNECTION_ID = 4,
206a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  PACKET_8BYTE_CONNECTION_ID = 8
207868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
208868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
209868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)enum InFecGroup {
210868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  NOT_IN_FEC_GROUP,
211868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  IN_FEC_GROUP,
212868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
213868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
214868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)enum QuicSequenceNumberLength {
215868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PACKET_1BYTE_SEQUENCE_NUMBER = 1,
216868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PACKET_2BYTE_SEQUENCE_NUMBER = 2,
217868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PACKET_4BYTE_SEQUENCE_NUMBER = 4,
218868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PACKET_6BYTE_SEQUENCE_NUMBER = 6
219868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)};
220868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
2210f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// Used to indicate a QuicSequenceNumberLength using two flag bits.
2220f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)enum QuicSequenceNumberLengthFlags {
2230f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  PACKET_FLAGS_1BYTE_SEQUENCE = 0,  // 00
2240f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  PACKET_FLAGS_2BYTE_SEQUENCE = 1,  // 01
2250f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  PACKET_FLAGS_4BYTE_SEQUENCE = 1 << 1,  // 10
2260f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  PACKET_FLAGS_6BYTE_SEQUENCE = 1 << 1 | 1,  // 11
2270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)};
2280f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
2297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// The public flags are specified in one byte.
2302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)enum QuicPacketPublicFlags {
2312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  PACKET_PUBLIC_FLAGS_NONE = 0,
2327dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
2337dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Bit 0: Does the packet header contains version info?
2347dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  PACKET_PUBLIC_FLAGS_VERSION = 1 << 0,
2357dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
2367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Bit 1: Is this packet a public reset packet?
2377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  PACKET_PUBLIC_FLAGS_RST = 1 << 1,
2387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
239a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Bits 2 and 3 specify the length of the ConnectionId as follows:
2407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // ----00--: 0 bytes
2417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // ----01--: 1 byte
2427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // ----10--: 4 bytes
2437dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // ----11--: 8 bytes
244a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  PACKET_PUBLIC_FLAGS_0BYTE_CONNECTION_ID = 0,
245a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  PACKET_PUBLIC_FLAGS_1BYTE_CONNECTION_ID = 1 << 2,
246a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  PACKET_PUBLIC_FLAGS_4BYTE_CONNECTION_ID = 1 << 3,
247a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  PACKET_PUBLIC_FLAGS_8BYTE_CONNECTION_ID = 1 << 3 | 1 << 2,
2487dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
2497dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Bits 4 and 5 describe the packet sequence number length as follows:
2507dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // --00----: 1 byte
2517dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // --01----: 2 bytes
2527dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // --10----: 4 bytes
2537dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // --11----: 6 bytes
2540f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  PACKET_PUBLIC_FLAGS_1BYTE_SEQUENCE = PACKET_FLAGS_1BYTE_SEQUENCE << 4,
2550f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  PACKET_PUBLIC_FLAGS_2BYTE_SEQUENCE = PACKET_FLAGS_2BYTE_SEQUENCE << 4,
2560f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  PACKET_PUBLIC_FLAGS_4BYTE_SEQUENCE = PACKET_FLAGS_4BYTE_SEQUENCE << 4,
2570f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  PACKET_PUBLIC_FLAGS_6BYTE_SEQUENCE = PACKET_FLAGS_6BYTE_SEQUENCE << 4,
2587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
2597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // All bits set (bits 6 and 7 are not currently used): 00111111
2607dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  PACKET_PUBLIC_FLAGS_MAX = (1 << 6) - 1
2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// The private flags are specified in one byte.
2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)enum QuicPacketPrivateFlags {
2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  PACKET_PRIVATE_FLAGS_NONE = 0,
2667dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
2677dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Bit 0: Does this packet contain an entropy bit?
268868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0,
2697dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
2707dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Bit 1: Payload is part of an FEC group?
2717dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1,
2727dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
2737dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // Bit 2: Payload is FEC as opposed to frames?
2747dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  PACKET_PRIVATE_FLAGS_FEC = 1 << 2,
2757dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
2767dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  // All bits set (bits 3-7 are not currently used): 00000111
2777dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
280558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// The available versions of QUIC. Guaranteed that the integer value of the enum
281558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// will match the version number.
282558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// When adding a new version to this enum you should add it to
283ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// kSupportedQuicVersions (if appropriate), and also add a new case to the
284ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// helper methods QuicVersionToQuicTag, QuicTagToQuicVersion, and
285ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// QuicVersionToString.
286558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdochenum QuicVersion {
287558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  // Special case to indicate unknown/unsupported QUIC version.
288558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  QUIC_VERSION_UNSUPPORTED = 0,
289558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
290116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  QUIC_VERSION_16 = 16,  // STOP_WAITING frame.
291116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  QUIC_VERSION_18 = 18,  // PING frame.
2925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  QUIC_VERSION_19 = 19,  // Connection level flow control.
293116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  QUIC_VERSION_21 = 21,  // Headers/crypto streams are flow controlled.
2946e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  QUIC_VERSION_22 = 22,  // Send Server Config Update messages on crypto stream.
2951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  QUIC_VERSION_23 = 23,  // Timestamp in the ack frame.
296558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch};
297558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
298558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// This vector contains QUIC versions which we currently support.
299558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// This should be ordered such that the highest supported version is the first
300558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// element, with subsequent elements in descending order (versions can be
301558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// skipped as necessary).
302f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)//
3035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// IMPORTANT: if you are adding to this list, follow the instructions at
304f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// http://sites/quic/adding-and-removing-versions
3051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccistatic const QuicVersion kSupportedQuicVersions[] = {QUIC_VERSION_23,
3061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                                     QUIC_VERSION_22,
3076e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                                                     QUIC_VERSION_21,
3086d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)                                                     QUIC_VERSION_19,
309cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                                                     QUIC_VERSION_18,
3105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)                                                     QUIC_VERSION_16};
311558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
312558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdochtypedef std::vector<QuicVersion> QuicVersionVector;
313558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
3141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Returns a vector of QUIC versions in kSupportedQuicVersions.
3151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)NET_EXPORT_PRIVATE QuicVersionVector QuicSupportedVersions();
316c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch
317558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// QuicTag is written to and read from the wire, but we prefer to use
318558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// the more readable QuicVersion at other levels.
319558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// Helper function which translates from a QuicVersion to a QuicTag. Returns 0
320558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// if QuicVersion is unsupported.
321558790d6acca3451cf3a6b497803a5f07d0bec58Ben MurdochNET_EXPORT_PRIVATE QuicTag QuicVersionToQuicTag(const QuicVersion version);
322558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
323558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// Returns appropriate QuicVersion from a QuicTag.
324558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// Returns QUIC_VERSION_UNSUPPORTED if version_tag cannot be understood.
325558790d6acca3451cf3a6b497803a5f07d0bec58Ben MurdochNET_EXPORT_PRIVATE QuicVersion QuicTagToQuicVersion(const QuicTag version_tag);
326558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
327558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// Helper function which translates from a QuicVersion to a string.
328558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// Returns strings corresponding to enum names (e.g. QUIC_VERSION_6).
329558790d6acca3451cf3a6b497803a5f07d0bec58Ben MurdochNET_EXPORT_PRIVATE std::string QuicVersionToString(const QuicVersion version);
330558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
331558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// Returns comma separated list of string representations of QuicVersion enum
3321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// values in the supplied |versions| vector.
3331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)NET_EXPORT_PRIVATE std::string QuicVersionVectorToString(
3341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    const QuicVersionVector& versions);
335558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
336558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// Version and Crypto tags are written to the wire with a big-endian
337558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// representation of the name of the tag.  For example
338558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// the client hello tag (CHLO) will be written as the
339558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// following 4 bytes: 'C' 'H' 'L' 'O'.  Since it is
340558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// stored in memory as a little endian uint32, we need
341558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// to reverse the order of the bytes.
342558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
343558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch// MakeQuicTag returns a value given the four bytes. For example:
344558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch//   MakeQuicTag('C', 'H', 'L', 'O');
345558790d6acca3451cf3a6b497803a5f07d0bec58Ben MurdochNET_EXPORT_PRIVATE QuicTag MakeQuicTag(char a, char b, char c, char d);
346558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch
34746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)// Returns true if the tag vector contains the specified tag.
348116680a4aac90f2aa7413d9095a592090648e557Ben MurdochNET_EXPORT_PRIVATE bool ContainsQuicTag(const QuicTagVector& tag_vector,
349116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                        QuicTag tag);
35046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
351868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Size in bytes of the data or fec packet header.
3525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(const QuicPacketHeader& header);
353868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
354868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(
355a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    QuicConnectionIdLength connection_id_length,
356868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    bool include_version,
357868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    QuicSequenceNumberLength sequence_number_length,
358868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    InFecGroup is_in_fec_group);
359868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
360868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Index of the first byte in a QUIC packet of FEC protected data.
361868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(
362a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    QuicConnectionIdLength connection_id_length,
363868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    bool include_version,
364868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    QuicSequenceNumberLength sequence_number_length);
365868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)// Index of the first byte in a QUIC packet of encrypted data.
366868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(
367a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    QuicConnectionIdLength connection_id_length,
368868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    bool include_version,
369868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)    QuicSequenceNumberLength sequence_number_length);
370868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)
371c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)enum QuicRstStreamErrorCode {
372c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  QUIC_STREAM_NO_ERROR = 0,
3732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
374d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // There was some error which halted stream processing.
375d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  QUIC_ERROR_PROCESSING_STREAM,
3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // We got two fin or reset offsets which did not match.
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QUIC_MULTIPLE_TERMINATION_OFFSETS,
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // We got bad payload and can not respond to it at the protocol level.
3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QUIC_BAD_APPLICATION_PAYLOAD,
380c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Stream closed due to connection error. No reset frame is sent when this
381c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // happens.
382c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  QUIC_STREAM_CONNECTION_ERROR,
383c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // GoAway frame sent. No more stream can be created.
384c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  QUIC_STREAM_PEER_GOING_AWAY,
385424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  // The stream has been cancelled.
386424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)  QUIC_STREAM_CANCELLED,
3870529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  // Sending a RST to allow for proper flow control accounting.
3880529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  QUIC_RST_FLOW_CONTROL_ACCOUNTING,
389c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
390c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // No error. Used as bound while iterating.
391c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  QUIC_STREAM_LAST_ERROR,
392c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)};
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3940529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// Because receiving an unknown QuicRstStreamErrorCode results in connection
3950529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// teardown, we use this to make sure any errors predating a given version are
3960529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// downgraded to the most appropriate existing error.
3970529e5d033099cbfc42635f6f6183833b09dff6eBen MurdochNET_EXPORT_PRIVATE QuicRstStreamErrorCode AdjustErrorForVersion(
3980529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    QuicRstStreamErrorCode error_code,
3990529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    QuicVersion version);
4000529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
4013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// These values must remain stable as they are uploaded to UMA histograms.
4023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// To add a new error code, use the current value of QUIC_LAST_ERROR and
4033551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// increment QUIC_LAST_ERROR.
404c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)enum QuicErrorCode {
405c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  QUIC_NO_ERROR = 0,
4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
407c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // Connection has reached an invalid state.
4083551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INTERNAL_ERROR = 1,
409c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // There were data frames after the a fin or reset.
4103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_STREAM_DATA_AFTER_TERMINATION = 2,
4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Control frame is malformed.
4123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INVALID_PACKET_HEADER = 3,
4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Frame data is malformed.
4143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INVALID_FRAME_DATA = 4,
4153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // The packet contained no payload.
4163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_MISSING_PAYLOAD = 48,
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // FEC data is malformed.
4183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INVALID_FEC_DATA = 5,
4193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // STREAM frame data is malformed.
4203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INVALID_STREAM_DATA = 46,
4215c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  // STREAM frame data is not encrypted.
4225c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  QUIC_UNENCRYPTED_STREAM_DATA = 61,
4233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // RST_STREAM frame data is malformed.
4243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INVALID_RST_STREAM_DATA = 6,
4253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // CONNECTION_CLOSE frame data is malformed.
4263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INVALID_CONNECTION_CLOSE_DATA = 7,
4273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // GOAWAY frame data is malformed.
4283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INVALID_GOAWAY_DATA = 8,
4295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // WINDOW_UPDATE frame data is malformed.
4305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QUIC_INVALID_WINDOW_UPDATE_DATA = 57,
4315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // BLOCKED frame data is malformed.
4325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QUIC_INVALID_BLOCKED_DATA = 58,
433a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // STOP_WAITING frame data is malformed.
434a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  QUIC_INVALID_STOP_WAITING_DATA = 60,
4353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // ACK frame data is malformed.
4363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INVALID_ACK_DATA = 9,
4373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // CONGESTION_FEEDBACK frame data is malformed.
4383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INVALID_CONGESTION_FEEDBACK_DATA = 47,
4392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Version negotiation packet is malformed.
4403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INVALID_VERSION_NEGOTIATION_PACKET = 10,
44190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Public RST packet is malformed.
4423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INVALID_PUBLIC_RST_PACKET = 11,
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // There was an error decrypting.
4443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_DECRYPTION_FAILURE = 12,
4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // There was an error encrypting.
4463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_ENCRYPTION_FAILURE = 13,
4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The packet exceeded kMaxPacketSize.
4483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_PACKET_TOO_LARGE = 14,
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Data was sent for a stream which did not exist.
4503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_PACKET_FOR_NONEXISTENT_STREAM = 15,
4512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The peer is going away.  May be a client or server.
4523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_PEER_GOING_AWAY = 16,
4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A stream ID was invalid.
4543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INVALID_STREAM_ID = 17,
455d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // A priority was invalid.
456d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  QUIC_INVALID_PRIORITY = 49,
4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Too many streams already open.
4583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_TOO_MANY_OPEN_STREAMS = 18,
4596e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // The peer must send a FIN/RST for each stream, and has not been doing so.
4606e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  QUIC_TOO_MANY_UNFINISHED_STREAMS = 66,
4612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Received public reset for this connection.
4623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_PUBLIC_RESET = 19,
463b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // Invalid protocol version.
4643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INVALID_VERSION = 20,
465a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
466a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // deprecated: QUIC_STREAM_RST_BEFORE_HEADERS_DECOMPRESSED = 21
467a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
468b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // The Header ID for a stream was too far from the previous.
4693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INVALID_HEADER_ID = 22,
47090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Negotiable parameter received during handshake had invalid value.
4713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INVALID_NEGOTIATED_VALUE = 23,
47290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // There was an error decompressing data.
4733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_DECOMPRESSION_FAILURE = 24,
4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // We hit our prenegotiated (or default) timeout
4753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_CONNECTION_TIMED_OUT = 25,
4761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // We hit our overall connection timeout
4771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  QUIC_CONNECTION_OVERALL_TIMED_OUT = 67,
47890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // There was an error encountered migrating addresses
4793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_ERROR_MIGRATING_ADDRESS = 26,
48058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // There was an error while writing to the socket.
4813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_PACKET_WRITE_ERROR = 27,
48258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // There was an error while reading from the socket.
48358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  QUIC_PACKET_READ_ERROR = 51,
484d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  // We received a STREAM_FRAME with no data and no fin flag set.
485d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)  QUIC_INVALID_STREAM_FRAME = 50,
4865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // We received invalid data on the headers stream.
4875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QUIC_INVALID_HEADERS_STREAM_DATA = 56,
48846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // The peer received too much data, violating flow control.
48946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA = 59,
49046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // The peer sent too much data, violating flow control.
49146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  QUIC_FLOW_CONTROL_SENT_TOO_MUCH_DATA = 63,
49246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // The peer received an invalid flow control window.
49346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  QUIC_FLOW_CONTROL_INVALID_WINDOW = 64,
494cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // The connection has been IP pooled into an existing connection.
495cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  QUIC_CONNECTION_IP_POOLED = 62,
4965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Crypto errors.
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
49990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Hanshake failed.
5003551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_HANDSHAKE_FAILED = 28,
5015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Handshake message contained out of order tags.
5023551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_CRYPTO_TAGS_OUT_OF_ORDER = 29,
5032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Handshake message contained too many entries.
5043551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_CRYPTO_TOO_MANY_ENTRIES = 30,
5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Handshake message contained an invalid value length.
5063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_CRYPTO_INVALID_VALUE_LENGTH = 31,
5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A crypto message was received after the handshake was complete.
5083551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE = 32,
5092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // A crypto message was received with an illegal message tag.
5103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INVALID_CRYPTO_MESSAGE_TYPE = 33,
5112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // A crypto message was received with an illegal parameter.
5123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER = 34,
5134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // An invalid channel id signature was supplied.
5144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  QUIC_INVALID_CHANNEL_ID_SIGNATURE = 52,
5152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // A crypto message was received with a mandatory parameter missing.
5163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_CRYPTO_MESSAGE_PARAMETER_NOT_FOUND = 35,
5172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // A crypto message was received with a parameter that has no overlap
5182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // with the local parameter.
5193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_CRYPTO_MESSAGE_PARAMETER_NO_OVERLAP = 36,
5202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // A crypto message was received that contained a parameter with too few
5212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // values.
5223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_CRYPTO_MESSAGE_INDEX_NOT_FOUND = 37,
523c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // An internal error occured in crypto processing.
5243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_CRYPTO_INTERNAL_ERROR = 38,
525c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // A crypto handshake message specified an unsupported version.
5263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_CRYPTO_VERSION_NOT_SUPPORTED = 39,
527c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // There was no intersection between the crypto primitives supported by the
528c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // peer and ourselves.
5293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_CRYPTO_NO_SUPPORT = 40,
530c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // The server rejected our client hello messages too many times.
5313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_CRYPTO_TOO_MANY_REJECTS = 41,
532c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // The client rejected the server's certificate chain or signature.
5333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_PROOF_INVALID = 42,
534c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // A crypto message was received with a duplicate tag.
5353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_CRYPTO_DUPLICATE_TAG = 43,
536b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // A crypto message was received with the wrong encryption level (i.e. it
537b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // should have been encrypted but was not.)
5383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT = 44,
539b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // The server config for a server has expired.
5403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  QUIC_CRYPTO_SERVER_CONFIG_EXPIRED = 45,
5414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  // We failed to setup the symmetric keys for a connection.
5424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  QUIC_CRYPTO_SYMMETRIC_KEY_SETUP_FAILED = 53,
543f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // A handshake message arrived, but we are still validating the
544f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // previous handshake message.
545f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  QUIC_CRYPTO_MESSAGE_WHILE_VALIDATING_CLIENT_HELLO = 54,
546116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // A server config update arrived before the handshake is complete.
547116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  QUIC_CRYPTO_UPDATE_BEFORE_HANDSHAKE_COMPLETE = 65,
548f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // This connection involved a version negotiation which appears to have been
549f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // tampered with.
550f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  QUIC_VERSION_NEGOTIATION_MISMATCH = 55,
551c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
552c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  // No error. Used as bound while iterating.
5531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  QUIC_LAST_ERROR = 68,
5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
5572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicPacketPublicHeader();
5582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
5592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ~QuicPacketPublicHeader();
5602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
561a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Universal header. All QuicPacket headers will have a connection_id and
562a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // public flags.
563a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  QuicConnectionId connection_id;
564a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  QuicConnectionIdLength connection_id_length;
5652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool reset_flag;
5662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool version_flag;
567868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  QuicSequenceNumberLength sequence_number_length;
568558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch  QuicVersionVector versions;
5692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
5702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Header for Data or FEC packets.
572c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)struct NET_EXPORT_PRIVATE QuicPacketHeader {
573c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  QuicPacketHeader();
574c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
5752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  NET_EXPORT_PRIVATE friend std::ostream& operator<<(
5772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      std::ostream& os, const QuicPacketHeader& s);
5782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicPacketPublicHeader public_header;
5802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool fec_flag;
5812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool entropy_flag;
5822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicPacketEntropyHash entropy_hash;
5835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QuicPacketSequenceNumber packet_sequence_number;
584868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  InFecGroup is_in_fec_group;
5855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QuicFecGroupNumber fec_group;
5865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
5875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
588c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
5895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicPublicResetPacket();
5905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header);
5915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
5922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicPacketPublicHeader public_header;
5932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicPublicResetNonceProof nonce_proof;
5945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicPacketSequenceNumber rejected_sequence_number;
5955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  IPEndPoint client_address;
5962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
5972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
5982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)enum QuicVersionNegotiationState {
5992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  START_NEGOTIATION = 0,
600ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // Server-side this implies we've sent a version negotiation packet and are
601ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // waiting on the client to select a compatible version.  Client-side this
602ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // implies we've gotten a version negotiation packet, are retransmitting the
603ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // initial packets with a supported version and are waiting for our first
604ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // packet from the server.
605ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  NEGOTIATION_IN_PROGRESS,
606ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // This indicates this endpoint has received a packet from the peer with a
607ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // version this endpoint supports.  Version negotiation is complete, and the
608ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  // version number will no longer be sent with future packets.
6092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  NEGOTIATED_VERSION
6102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
6112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef QuicPacketPublicHeader QuicVersionNegotiationPacket;
6132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// A padding frame contains no payload.
6152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct NET_EXPORT_PRIVATE QuicPaddingFrame {
6162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
6172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6180529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// A ping frame contains no payload, though it is retransmittable,
6190529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch// and ACK'd just like other normal frames.
6200529e5d033099cbfc42635f6f6183833b09dff6eBen Murdochstruct NET_EXPORT_PRIVATE QuicPingFrame {
6210529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch};
6220529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct NET_EXPORT_PRIVATE QuicStreamFrame {
6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QuicStreamFrame();
625f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  QuicStreamFrame(const QuicStreamFrame& frame);
6265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QuicStreamFrame(QuicStreamId stream_id,
6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                  bool fin,
6282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                  QuicStreamOffset offset,
629f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                  IOVector data);
630f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
6315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  NET_EXPORT_PRIVATE friend std::ostream& operator<<(
6325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      std::ostream& os, const QuicStreamFrame& s);
6335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
634f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Returns a copy of the IOVector |data| as a heap-allocated string.
635f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Caller must take ownership of the returned string.
636f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  std::string* GetDataAsString() const;
6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QuicStreamId stream_id;
6395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool fin;
6402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicStreamOffset offset;  // Location of this data in the stream.
641f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  IOVector data;
64258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
64358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // If this is set, then when this packet is ACKed the AckNotifier will be
64458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  // informed.
64558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)  QuicAckNotifier* notifier;
6465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// TODO(ianswett): Re-evaluate the trade-offs of hash_set vs set when framing
6492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// is finalized.
6502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)typedef std::set<QuicPacketSequenceNumber> SequenceNumberSet;
6511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccitypedef std::list<QuicPacketSequenceNumber> SequenceNumberList;
6521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
6531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccitypedef std::list<
6541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    std::pair<QuicPacketSequenceNumber, QuicTime> > PacketTimeList;
6552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)struct NET_EXPORT_PRIVATE QuicStopWaitingFrame {
6575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  QuicStopWaitingFrame();
6585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ~QuicStopWaitingFrame();
6595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
6605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  NET_EXPORT_PRIVATE friend std::ostream& operator<<(
6615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      std::ostream& os, const QuicStopWaitingFrame& s);
6625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // Entropy hash of all packets up to, but not including, the least unacked
6635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // packet.
6645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  QuicPacketEntropyHash entropy_hash;
6655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  // The lowest packet we've sent which is unacked, and we expect an ack for.
6665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  QuicPacketSequenceNumber least_unacked;
6675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)};
6685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
6695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)struct NET_EXPORT_PRIVATE QuicAckFrame {
6705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  QuicAckFrame();
6715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  ~QuicAckFrame();
6725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
6732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  NET_EXPORT_PRIVATE friend std::ostream& operator<<(
6745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)      std::ostream& os, const QuicAckFrame& s);
6752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Entropy hash of all packets up to largest observed not including missing
6772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // packets.
6782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicPacketEntropyHash entropy_hash;
6792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The highest packet sequence number we've observed from the peer.
6812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  //
6822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // In general, this should be the largest packet number we've received.  In
6832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // the case of truncated acks, we may have to advertise a lower "upper bound"
6842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // than largest received, to avoid implicitly acking missing packets that
6852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // don't fit in the missing packet list due to size limitations.  In this
6862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // case, largest_observed may be a packet which is also in the missing packets
6872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // list.
6882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicPacketSequenceNumber largest_observed;
6892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Time elapsed since largest_observed was received until this Ack frame was
6912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // sent.
6922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicTime::Delta delta_time_largest_observed;
6932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
6942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // TODO(satyamshekhar): Can be optimized using an interval set like data
6952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // structure.
6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The set of packets which we're expecting and have not received.
6972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  SequenceNumberSet missing_packets;
6980f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
6990f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  // Whether the ack had to be truncated when sent.
7000f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)  bool is_truncated;
7015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Packets which have been revived via FEC.
7035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // All of these must also be in missing_packets.
7045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  SequenceNumberSet revived_packets;
7051320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
7061320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // List of <sequence_number, time> for when packets arrived.
7071320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  PacketTimeList received_packet_times;
7085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
7095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// True if the sequence number is greater than largest_observed or is listed
7112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// as missing.
7122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Always returns false for sequence numbers less than least_unacked.
7132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)bool NET_EXPORT_PRIVATE IsAwaitingPacket(
7145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    const QuicAckFrame& ack_frame,
7152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    QuicPacketSequenceNumber sequence_number);
7162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Inserts missing packets between [lower, higher).
7182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void NET_EXPORT_PRIVATE InsertMissingPacketsBetween(
7195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    QuicAckFrame* ack_frame,
7202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    QuicPacketSequenceNumber lower,
7212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    QuicPacketSequenceNumber higher);
7222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Defines for all types of congestion feedback that will be negotiated in QUIC,
7247dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// kTCP MUST be supported by all QUIC implementations to guarantee 100%
7255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// compatibility.
7261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// TODO(cyr): Remove this when removing QUIC_VERSION_22.
7275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)enum CongestionFeedbackType {
7285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  kTCP,  // Used to mimic TCP.
7295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)};
7305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)
7315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Defines for all types of congestion control algorithms that can be used in
7325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// QUIC. Note that this is separate from the congestion feedback type -
7335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// some congestion control algorithms may use the same feedback type
7345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// (Reno and Cubic are the classic example for that).
7355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)enum CongestionControlType {
7365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  kCubic,
7375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  kReno,
7385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)  kBBR,
7395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
7405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
741e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdochenum LossDetectionType {
742e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  kNack,  // Used to mimic TCP's loss detection.
743e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch  kTime,  // Time based loss detection.
744e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch};
745e5d81f57cb97b3b6b7fccc9c5610d21eb81db09dBen Murdoch
7461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// TODO(cyr): Remove this when removing QUIC_VERSION_22.
7475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct NET_EXPORT_PRIVATE CongestionFeedbackMessageTCP {
7485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  CongestionFeedbackMessageTCP();
7495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicByteCount receive_window;
7515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
7525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// TODO(cyr): Remove this when removing QUIC_VERSION_22.
7542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct NET_EXPORT_PRIVATE QuicCongestionFeedbackFrame {
7552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicCongestionFeedbackFrame();
7562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ~QuicCongestionFeedbackFrame();
7575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  NET_EXPORT_PRIVATE friend std::ostream& operator<<(
7592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      std::ostream& os, const QuicCongestionFeedbackFrame& c);
7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CongestionFeedbackType type;
7626e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  // This should really be a union, but since the timestamp struct
7632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // is non-trivial, C++ prohibits it.
7642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  CongestionFeedbackMessageTCP tcp;
7655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
7665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct NET_EXPORT_PRIVATE QuicRstStreamFrame {
7685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicRstStreamFrame();
7695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicRstStreamFrame(QuicStreamId stream_id,
7705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                     QuicRstStreamErrorCode error_code,
7715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                     QuicStreamOffset bytes_written);
7725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  NET_EXPORT_PRIVATE friend std::ostream& operator<<(
7745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      std::ostream& os, const QuicRstStreamFrame& r);
7755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QuicStreamId stream_id;
777c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  QuicRstStreamErrorCode error_code;
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string error_details;
7795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Used to update flow control windows. On termination of a stream, both
7815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // endpoints must inform the peer of the number of bytes they have sent on
7825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // that stream. This can be done through normal termination (data packet with
7835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // FIN) or through a RST.
7845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicStreamOffset byte_offset;
7855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct NET_EXPORT_PRIVATE QuicConnectionCloseFrame {
7885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicConnectionCloseFrame();
7895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  NET_EXPORT_PRIVATE friend std::ostream& operator<<(
7915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      std::ostream& os, const QuicConnectionCloseFrame& c);
7925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
7935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QuicErrorCode error_code;
7945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string error_details;
7952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)};
7962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
7972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct NET_EXPORT_PRIVATE QuicGoAwayFrame {
7985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicGoAwayFrame();
7992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicGoAwayFrame(QuicErrorCode error_code,
8002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                  QuicStreamId last_good_stream_id,
8012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                  const std::string& reason);
8022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  NET_EXPORT_PRIVATE friend std::ostream& operator<<(
8045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      std::ostream& os, const QuicGoAwayFrame& g);
8055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicErrorCode error_code;
8072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicStreamId last_good_stream_id;
8082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  std::string reason_phrase;
8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
8105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Flow control updates per-stream and at the connection levoel.
8125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Based on SPDY's WINDOW_UPDATE frame, but uses an absolute byte offset rather
8135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// than a window delta.
8145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// TODO(rjshade): A possible future optimization is to make stream_id and
8155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)//                byte_offset variable length, similar to stream frames.
8165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)struct NET_EXPORT_PRIVATE QuicWindowUpdateFrame {
8175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicWindowUpdateFrame() {}
8185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicWindowUpdateFrame(QuicStreamId stream_id, QuicStreamOffset byte_offset);
8195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  NET_EXPORT_PRIVATE friend std::ostream& operator<<(
8215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      std::ostream& os, const QuicWindowUpdateFrame& w);
8225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The stream this frame applies to.  0 is a special case meaning the overall
8245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // connection rather than a specific stream.
8255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicStreamId stream_id;
8265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Byte offset in the stream or connection. The receiver of this frame must
8285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // not send data which would result in this offset being exceeded.
8295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicStreamOffset byte_offset;
8305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
8315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// The BLOCKED frame is used to indicate to the remote endpoint that this
8335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// endpoint believes itself to be flow-control blocked but otherwise ready to
8345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// send data. The BLOCKED frame is purely advisory and optional.
8355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Based on SPDY's BLOCKED frame (undocumented as of 2014-01-28).
8365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)struct NET_EXPORT_PRIVATE QuicBlockedFrame {
8375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicBlockedFrame() {}
8385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit QuicBlockedFrame(QuicStreamId stream_id);
8395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  NET_EXPORT_PRIVATE friend std::ostream& operator<<(
8415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      std::ostream& os, const QuicBlockedFrame& b);
8425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // The stream this frame applies to.  0 is a special case meaning the overall
8445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // connection rather than a specific stream.
8455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicStreamId stream_id;
8465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)};
8475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
848c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// EncryptionLevel enumerates the stages of encryption that a QUIC connection
849c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// progresses through. When retransmitting a packet, the encryption level needs
850c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// to be specified so that it is retransmitted at a level which the peer can
851c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)// understand.
852c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)enum EncryptionLevel {
853c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ENCRYPTION_NONE = 0,
854c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ENCRYPTION_INITIAL = 1,
855c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  ENCRYPTION_FORWARD_SECURE = 2,
856c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
857c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  NUM_ENCRYPTION_LEVELS,
858c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)};
859c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct NET_EXPORT_PRIVATE QuicFrame {
8615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicFrame();
8625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit QuicFrame(QuicPaddingFrame* padding_frame);
8635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit QuicFrame(QuicStreamFrame* stream_frame);
8645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit QuicFrame(QuicAckFrame* frame);
8651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
8661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // TODO(cyr): Remove this when removing QUIC_VERSION_22.
8675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit QuicFrame(QuicCongestionFeedbackFrame* frame);
8681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
8695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit QuicFrame(QuicRstStreamFrame* frame);
8705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit QuicFrame(QuicConnectionCloseFrame* frame);
871a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  explicit QuicFrame(QuicStopWaitingFrame* frame);
8720529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  explicit QuicFrame(QuicPingFrame* frame);
8735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit QuicFrame(QuicGoAwayFrame* frame);
8745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit QuicFrame(QuicWindowUpdateFrame* frame);
8755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  explicit QuicFrame(QuicBlockedFrame* frame);
8765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
8775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  NET_EXPORT_PRIVATE friend std::ostream& operator<<(
8785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)      std::ostream& os, const QuicFrame& frame);
8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QuicFrameType type;
8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  union {
8822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    QuicPaddingFrame* padding_frame;
8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    QuicStreamFrame* stream_frame;
8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    QuicAckFrame* ack_frame;
8851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
8861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci    // TODO(cyr): Remove this when removing QUIC_VERSION_22.
8872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    QuicCongestionFeedbackFrame* congestion_feedback_frame;
888a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    QuicStopWaitingFrame* stop_waiting_frame;
8891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
8900529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch    QuicPingFrame* ping_frame;
8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    QuicRstStreamFrame* rst_stream_frame;
8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    QuicConnectionCloseFrame* connection_close_frame;
8932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    QuicGoAwayFrame* goaway_frame;
8945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    QuicWindowUpdateFrame* window_update_frame;
8955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    QuicBlockedFrame* blocked_frame;
8965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
8975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
8985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef std::vector<QuicFrame> QuicFrames;
9005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct NET_EXPORT_PRIVATE QuicFecData {
9025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QuicFecData();
9035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The FEC group number is also the sequence number of the first
9052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // FEC protected packet.  The last protected packet's sequence number will
9062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // be one less than the sequence number of the FEC packet.
9075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  QuicFecGroupNumber fec_group;
9085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::StringPiece redundancy;
9095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
9105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NET_EXPORT_PRIVATE QuicData {
9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
9135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicData(const char* buffer, size_t length);
9145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicData(char* buffer, size_t length, bool owns_buffer);
9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~QuicData();
9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::StringPiece AsStringPiece() const {
9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return base::StringPiece(data(), length());
9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const char* data() const { return buffer_; }
9225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  size_t length() const { return length_; }
9235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
9255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  const char* buffer_;
9265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  size_t length_;
9275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool owns_buffer_;
9285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(QuicData);
9305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
9315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
9335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
934868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static QuicPacket* NewDataPacket(
935868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      char* buffer,
936868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      size_t length,
937868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      bool owns_buffer,
938a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      QuicConnectionIdLength connection_id_length,
939868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      bool includes_version,
940868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      QuicSequenceNumberLength sequence_number_length) {
941a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return new QuicPacket(buffer, length, owns_buffer, connection_id_length,
942868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                          includes_version, sequence_number_length, false);
9435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
9445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
945868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  static QuicPacket* NewFecPacket(
946868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      char* buffer,
947868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      size_t length,
948868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      bool owns_buffer,
949a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)      QuicConnectionIdLength connection_id_length,
950868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      bool includes_version,
951868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      QuicSequenceNumberLength sequence_number_length) {
952a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    return new QuicPacket(buffer, length, owns_buffer, connection_id_length,
953868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)                          includes_version, sequence_number_length, true);
9545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
9555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::StringPiece FecProtectedData() const;
9572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::StringPiece AssociatedData() const;
9582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::StringPiece BeforePlaintext() const;
9592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  base::StringPiece Plaintext() const;
9605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool is_fec_packet() const { return is_fec_packet_; }
9622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  char* mutable_data() { return buffer_; }
9645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
9662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  QuicPacket(char* buffer,
9672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)             size_t length,
9682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)             bool owns_buffer,
969a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)             QuicConnectionIdLength connection_id_length,
9702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)             bool includes_version,
971868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)             QuicSequenceNumberLength sequence_number_length,
9725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)             bool is_fec_packet);
9732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
9745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  char* buffer_;
9752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const bool is_fec_packet_;
976a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  const QuicConnectionIdLength connection_id_length_;
9772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const bool includes_version_;
978868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  const QuicSequenceNumberLength sequence_number_length_;
9795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(QuicPacket);
9815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
9825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
9845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
9855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicEncryptedPacket(const char* buffer, size_t length);
9865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer);
9875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
988f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  // Clones the packet into a new packet which owns the buffer.
989f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  QuicEncryptedPacket* Clone() const;
990f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
9912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // By default, gtest prints the raw bytes of an object. The bool data
9922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // member (in the base class QuicData) causes this object to have padding
9932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // bytes, which causes the default gtest object printer to read
9942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // uninitialize memory. So we need to teach gtest how to print this object.
9952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  NET_EXPORT_PRIVATE friend std::ostream& operator<<(
9962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      std::ostream& os, const QuicEncryptedPacket& s);
9975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
9985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
9995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket);
10005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
10015821806