OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_QUIC_QUIC_PROTOCOL_H_ | 5 #ifndef NET_QUIC_QUIC_PROTOCOL_H_ |
6 #define NET_QUIC_QUIC_PROTOCOL_H_ | 6 #define NET_QUIC_QUIC_PROTOCOL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <limits> | 9 #include <limits> |
10 #include <map> | 10 #include <map> |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 class QuicPacket; | 30 class QuicPacket; |
31 | 31 |
32 typedef uint64 QuicGuid; | 32 typedef uint64 QuicGuid; |
33 typedef uint32 QuicStreamId; | 33 typedef uint32 QuicStreamId; |
34 typedef uint64 QuicStreamOffset; | 34 typedef uint64 QuicStreamOffset; |
35 typedef uint64 QuicPacketSequenceNumber; | 35 typedef uint64 QuicPacketSequenceNumber; |
36 typedef QuicPacketSequenceNumber QuicFecGroupNumber; | 36 typedef QuicPacketSequenceNumber QuicFecGroupNumber; |
37 typedef uint64 QuicPublicResetNonceProof; | 37 typedef uint64 QuicPublicResetNonceProof; |
38 typedef uint8 QuicPacketEntropyHash; | 38 typedef uint8 QuicPacketEntropyHash; |
39 typedef uint32 QuicVersionTag; | |
40 typedef std::vector<QuicVersionTag> QuicVersionTagList; | |
41 typedef uint32 QuicHeaderId; | 39 typedef uint32 QuicHeaderId; |
| 40 // QuicTag is the type of a tag in the wire protocol. |
| 41 typedef uint32 QuicTag; |
| 42 typedef std::vector<QuicTag> QuicTagVector; |
42 | 43 |
43 // TODO(rch): Consider Quic specific names for these constants. | 44 // TODO(rch): Consider Quic specific names for these constants. |
44 // Maximum size in bytes of a QUIC packet. | 45 // Maximum size in bytes of a QUIC packet. |
45 const QuicByteCount kMaxPacketSize = 1200; | 46 const QuicByteCount kMaxPacketSize = 1200; |
46 | 47 |
47 // Maximum number of open streams per connection. | 48 // Maximum number of open streams per connection. |
48 const size_t kDefaultMaxStreamsPerConnection = 100; | 49 const size_t kDefaultMaxStreamsPerConnection = 100; |
49 | 50 |
50 // Number of bytes reserved for guid in the packet header. | 51 // Number of bytes reserved for guid in the packet header. |
51 const size_t kQuicGuidSize = 8; | 52 const size_t kQuicGuidSize = 8; |
(...skipping 16 matching lines...) Expand all Loading... |
68 // Size in bytes of the data or fec packet header. | 69 // Size in bytes of the data or fec packet header. |
69 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(bool include_version); | 70 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(bool include_version); |
70 // Size in bytes of the public reset packet. | 71 // Size in bytes of the public reset packet. |
71 NET_EXPORT_PRIVATE size_t GetPublicResetPacketSize(); | 72 NET_EXPORT_PRIVATE size_t GetPublicResetPacketSize(); |
72 | 73 |
73 // Index of the first byte in a QUIC packet of FEC protected data. | 74 // Index of the first byte in a QUIC packet of FEC protected data. |
74 NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(bool include_version); | 75 NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(bool include_version); |
75 // Index of the first byte in a QUIC packet of encrypted data. | 76 // Index of the first byte in a QUIC packet of encrypted data. |
76 NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(bool include_version); | 77 NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(bool include_version); |
77 // Returns true if |version| is a supported protocol version. | 78 // Returns true if |version| is a supported protocol version. |
78 NET_EXPORT_PRIVATE bool IsSupportedVersion(QuicVersionTag version); | 79 NET_EXPORT_PRIVATE bool IsSupportedVersion(QuicTag version); |
79 | 80 |
80 // Index of the first byte in a QUIC packet which is used in hash calculation. | 81 // Index of the first byte in a QUIC packet which is used in hash calculation. |
81 const size_t kStartOfHashData = 0; | 82 const size_t kStartOfHashData = 0; |
82 | 83 |
83 // Limit on the delta between stream IDs. | 84 // Limit on the delta between stream IDs. |
84 const QuicStreamId kMaxStreamIdDelta = 100; | 85 const QuicStreamId kMaxStreamIdDelta = 100; |
85 // Limit on the delta between header IDs. | 86 // Limit on the delta between header IDs. |
86 const QuicHeaderId kMaxHeaderIdDelta = 100; | 87 const QuicHeaderId kMaxHeaderIdDelta = 100; |
87 | 88 |
88 // Reserved ID for the crypto stream. | 89 // Reserved ID for the crypto stream. |
89 // TODO(rch): ensure that this is not usable by any other streams. | 90 // TODO(rch): ensure that this is not usable by any other streams. |
90 const QuicStreamId kCryptoStreamId = 1; | 91 const QuicStreamId kCryptoStreamId = 1; |
91 | 92 |
92 // Value which indicates this packet is not FEC protected. | 93 // Value which indicates this packet is not FEC protected. |
93 const uint8 kNoFecOffset = 0xFF; | 94 const uint8 kNoFecOffset = 0xFF; |
94 | 95 |
95 const int64 kDefaultTimeoutUs = 600000000; // 10 minutes. | 96 const int64 kDefaultTimeoutUs = 600000000; // 10 minutes. |
96 | 97 |
97 enum Retransmission { | 98 enum Retransmission { |
98 NOT_RETRANSMISSION = 0, | 99 NOT_RETRANSMISSION, |
99 IS_RETRANSMISSION = 1, | 100 IS_RETRANSMISSION, |
100 }; | 101 }; |
101 | 102 |
102 enum HasRetransmittableData { | 103 enum HasRetransmittableData { |
103 HAS_RETRANSMITTABLE_DATA = 0, | 104 NO_RETRANSMITTABLE_DATA, |
104 NO_RETRANSMITTABLE_DATA = 1, | 105 HAS_RETRANSMITTABLE_DATA, |
105 }; | 106 }; |
106 | 107 |
107 enum QuicFrameType { | 108 enum QuicFrameType { |
108 PADDING_FRAME = 0, | 109 PADDING_FRAME = 0, |
109 STREAM_FRAME, | 110 STREAM_FRAME, |
110 ACK_FRAME, | 111 ACK_FRAME, |
111 CONGESTION_FEEDBACK_FRAME, | 112 CONGESTION_FEEDBACK_FRAME, |
112 RST_STREAM_FRAME, | 113 RST_STREAM_FRAME, |
113 CONNECTION_CLOSE_FRAME, | 114 CONNECTION_CLOSE_FRAME, |
114 GOAWAY_FRAME, | 115 GOAWAY_FRAME, |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 QUIC_CRYPTO_VERSION_NOT_SUPPORTED, | 227 QUIC_CRYPTO_VERSION_NOT_SUPPORTED, |
227 // There was no intersection between the crypto primitives supported by the | 228 // There was no intersection between the crypto primitives supported by the |
228 // peer and ourselves. | 229 // peer and ourselves. |
229 QUIC_CRYPTO_NO_SUPPORT, | 230 QUIC_CRYPTO_NO_SUPPORT, |
230 // The server rejected our client hello messages too many times. | 231 // The server rejected our client hello messages too many times. |
231 QUIC_CRYPTO_TOO_MANY_REJECTS, | 232 QUIC_CRYPTO_TOO_MANY_REJECTS, |
232 // The client rejected the server's certificate chain or signature. | 233 // The client rejected the server's certificate chain or signature. |
233 QUIC_PROOF_INVALID, | 234 QUIC_PROOF_INVALID, |
234 // A crypto message was received with a duplicate tag. | 235 // A crypto message was received with a duplicate tag. |
235 QUIC_CRYPTO_DUPLICATE_TAG, | 236 QUIC_CRYPTO_DUPLICATE_TAG, |
| 237 // A crypto message was received with the wrong encryption level (i.e. it |
| 238 // should have been encrypted but was not.) |
| 239 QUIC_CRYPTO_ENCRYPTION_LEVEL_INCORRECT, |
| 240 // The server config for a server has expired. |
| 241 QUIC_CRYPTO_SERVER_CONFIG_EXPIRED, |
236 | 242 |
237 // No error. Used as bound while iterating. | 243 // No error. Used as bound while iterating. |
238 QUIC_LAST_ERROR, | 244 QUIC_LAST_ERROR, |
239 }; | 245 }; |
240 | 246 |
241 // Version and Crypto tags are written to the wire with a big-endian | 247 // Version and Crypto tags are written to the wire with a big-endian |
242 // representation of the name of the tag. For example | 248 // representation of the name of the tag. For example |
243 // the client hello tag (CHLO) will be written as the | 249 // the client hello tag (CHLO) will be written as the |
244 // following 4 bytes: 'C' 'H' 'L' 'O'. Since it is | 250 // following 4 bytes: 'C' 'H' 'L' 'O'. Since it is |
245 // stored in memory as a little endian uint32, we need | 251 // stored in memory as a little endian uint32, we need |
246 // to reverse the order of the bytes. | 252 // to reverse the order of the bytes. |
247 // | 253 // |
248 // The TAG macro is used in header files to ensure that we don't create static | 254 // The TAG macro is used in header files to ensure that we don't create static |
249 // initialisers. In normal code, the MakeQuicTag function should be used. | 255 // initialisers. In normal code, the MakeQuicTag function should be used. |
250 #define TAG(a, b, c, d) ((d << 24) + (c << 16) + (b << 8) + a) | 256 #define TAG(a, b, c, d) ((d << 24) + (c << 16) + (b << 8) + a) |
251 const QuicVersionTag kUnsupportedVersion = -1; | 257 const QuicTag kUnsupportedVersion = -1; |
252 const QuicVersionTag kQuicVersion1 = TAG('Q', '1', '.', '0'); | 258 // Each time the wire format changes, this need needs to be incremented. |
| 259 // At some point, we will actually freeze the wire format and make an official |
| 260 // version number, but this works for now. |
| 261 const QuicTag kQuicVersion1 = TAG('Q', '0', '0', '1'); |
253 #undef TAG | 262 #undef TAG |
254 | 263 |
255 // MakeQuicTag returns a value given the four bytes. For example: | 264 // MakeQuicTag returns a value given the four bytes. For example: |
256 // MakeQuicTag('C', 'H', 'L', 'O'); | 265 // MakeQuicTag('C', 'H', 'L', 'O'); |
257 uint32 NET_EXPORT_PRIVATE MakeQuicTag(char a, char b, char c, char d); | 266 uint32 NET_EXPORT_PRIVATE MakeQuicTag(char a, char b, char c, char d); |
258 | 267 |
259 struct NET_EXPORT_PRIVATE QuicPacketPublicHeader { | 268 struct NET_EXPORT_PRIVATE QuicPacketPublicHeader { |
260 QuicPacketPublicHeader(); | 269 QuicPacketPublicHeader(); |
261 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other); | 270 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other); |
262 ~QuicPacketPublicHeader(); | 271 ~QuicPacketPublicHeader(); |
263 | 272 |
264 QuicPacketPublicHeader& operator=(const QuicPacketPublicHeader& other); | 273 QuicPacketPublicHeader& operator=(const QuicPacketPublicHeader& other); |
265 | 274 |
266 // Universal header. All QuicPacket headers will have a guid and public flags. | 275 // Universal header. All QuicPacket headers will have a guid and public flags. |
267 QuicGuid guid; | 276 QuicGuid guid; |
268 bool reset_flag; | 277 bool reset_flag; |
269 bool version_flag; | 278 bool version_flag; |
270 QuicVersionTagList versions; | 279 QuicTagVector versions; |
271 }; | 280 }; |
272 | 281 |
273 // Header for Data or FEC packets. | 282 // Header for Data or FEC packets. |
274 struct NET_EXPORT_PRIVATE QuicPacketHeader { | 283 struct NET_EXPORT_PRIVATE QuicPacketHeader { |
275 QuicPacketHeader(); | 284 QuicPacketHeader(); |
276 explicit QuicPacketHeader(const QuicPacketPublicHeader& header); | 285 explicit QuicPacketHeader(const QuicPacketPublicHeader& header); |
277 | 286 |
278 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | 287 NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
279 std::ostream& os, const QuicPacketHeader& s); | 288 std::ostream& os, const QuicPacketHeader& s); |
280 | 289 |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | 703 NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
695 std::ostream& os, const QuicConsumedData& s); | 704 std::ostream& os, const QuicConsumedData& s); |
696 | 705 |
697 size_t bytes_consumed; | 706 size_t bytes_consumed; |
698 bool fin_consumed; | 707 bool fin_consumed; |
699 }; | 708 }; |
700 | 709 |
701 } // namespace net | 710 } // namespace net |
702 | 711 |
703 #endif // NET_QUIC_QUIC_PROTOCOL_H_ | 712 #endif // NET_QUIC_QUIC_PROTOCOL_H_ |
OLD | NEW |