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 19 matching lines...) Expand all Loading... |
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; | 39 typedef uint32 QuicVersionTag; |
| 40 typedef std::vector<QuicVersionTag> QuicVersionTagList; |
40 | 41 |
41 // TODO(rch): Consider Quic specific names for these constants. | 42 // TODO(rch): Consider Quic specific names for these constants. |
42 // Maximum size in bytes of a QUIC packet. | 43 // Maximum size in bytes of a QUIC packet. |
43 const QuicByteCount kMaxPacketSize = 1200; | 44 const QuicByteCount kMaxPacketSize = 1200; |
44 | 45 |
45 // Maximum number of open streams per connection. | 46 // Maximum number of open streams per connection. |
46 const size_t kDefaultMaxStreamsPerConnection = 100; | 47 const size_t kDefaultMaxStreamsPerConnection = 100; |
47 | 48 |
48 // Number of bytes reserved for guid in the packet header. | 49 // Number of bytes reserved for guid in the packet header. |
49 const size_t kQuicGuidSize = 8; | 50 const size_t kQuicGuidSize = 8; |
(...skipping 15 matching lines...) Expand all Loading... |
65 | 66 |
66 // Size in bytes of the data or fec packet header. | 67 // Size in bytes of the data or fec packet header. |
67 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(bool include_version); | 68 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(bool include_version); |
68 // Size in bytes of the public reset packet. | 69 // Size in bytes of the public reset packet. |
69 NET_EXPORT_PRIVATE size_t GetPublicResetPacketSize(); | 70 NET_EXPORT_PRIVATE size_t GetPublicResetPacketSize(); |
70 | 71 |
71 // Index of the first byte in a QUIC packet of FEC protected data. | 72 // Index of the first byte in a QUIC packet of FEC protected data. |
72 NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(bool include_version); | 73 NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(bool include_version); |
73 // Index of the first byte in a QUIC packet of encrypted data. | 74 // Index of the first byte in a QUIC packet of encrypted data. |
74 NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(bool include_version); | 75 NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(bool include_version); |
| 76 // Returns true if |version| is a supported protocol version. |
| 77 NET_EXPORT_PRIVATE bool IsSupportedVersion(QuicVersionTag version); |
75 | 78 |
76 // Index of the first byte in a QUIC packet which is used in hash calculation. | 79 // Index of the first byte in a QUIC packet which is used in hash calculation. |
77 const size_t kStartOfHashData = 0; | 80 const size_t kStartOfHashData = 0; |
78 | 81 |
79 // Limit on the delta between stream IDs. | 82 // Limit on the delta between stream IDs. |
80 const QuicStreamId kMaxStreamIdDelta = 100; | 83 const QuicStreamId kMaxStreamIdDelta = 100; |
81 | 84 |
82 // Reserved ID for the crypto stream. | 85 // Reserved ID for the crypto stream. |
83 // TODO(rch): ensure that this is not usable by any other streams. | 86 // TODO(rch): ensure that this is not usable by any other streams. |
84 const QuicStreamId kCryptoStreamId = 1; | 87 const QuicStreamId kCryptoStreamId = 1; |
(...skipping 26 matching lines...) Expand all Loading... |
111 PACKET_PRIVATE_FLAGS_FEC = 1 << 0, // Payload is FEC as opposed to frames. | 114 PACKET_PRIVATE_FLAGS_FEC = 1 << 0, // Payload is FEC as opposed to frames. |
112 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 1, | 115 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 1, |
113 PACKET_PRIVATE_FLAGS_FEC_ENTROPY = 1 << 2, | 116 PACKET_PRIVATE_FLAGS_FEC_ENTROPY = 1 << 2, |
114 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1 // All bits set. | 117 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1 // All bits set. |
115 }; | 118 }; |
116 | 119 |
117 enum QuicErrorCode { | 120 enum QuicErrorCode { |
118 // Stream errors. | 121 // Stream errors. |
119 QUIC_NO_ERROR = 0, | 122 QUIC_NO_ERROR = 0, |
120 | 123 |
| 124 // Connection has reached an invalid state. |
| 125 QUIC_INTERNAL_ERROR, |
| 126 |
121 // There were data frames after the a fin or reset. | 127 // There were data frames after the a fin or reset. |
122 QUIC_STREAM_DATA_AFTER_TERMINATION, | 128 QUIC_STREAM_DATA_AFTER_TERMINATION, |
123 // There was some server error which halted stream processing. | 129 // There was some server error which halted stream processing. |
124 QUIC_SERVER_ERROR_PROCESSING_STREAM, | 130 QUIC_SERVER_ERROR_PROCESSING_STREAM, |
125 // We got two fin or reset offsets which did not match. | 131 // We got two fin or reset offsets which did not match. |
126 QUIC_MULTIPLE_TERMINATION_OFFSETS, | 132 QUIC_MULTIPLE_TERMINATION_OFFSETS, |
127 // We got bad payload and can not respond to it at the protocol level. | 133 // We got bad payload and can not respond to it at the protocol level. |
128 QUIC_BAD_APPLICATION_PAYLOAD, | 134 QUIC_BAD_APPLICATION_PAYLOAD, |
129 | 135 |
130 // Connection errors. | 136 // Connection errors. |
131 | 137 |
132 // Control frame is malformed. | 138 // Control frame is malformed. |
133 QUIC_INVALID_PACKET_HEADER, | 139 QUIC_INVALID_PACKET_HEADER, |
134 // Frame data is malformed. | 140 // Frame data is malformed. |
135 QUIC_INVALID_FRAME_DATA, | 141 QUIC_INVALID_FRAME_DATA, |
136 // FEC data is malformed. | 142 // FEC data is malformed. |
137 QUIC_INVALID_FEC_DATA, | 143 QUIC_INVALID_FEC_DATA, |
138 // Stream rst data is malformed | 144 // Stream rst data is malformed |
139 QUIC_INVALID_RST_STREAM_DATA, | 145 QUIC_INVALID_RST_STREAM_DATA, |
140 // Connection close data is malformed. | 146 // Connection close data is malformed. |
141 QUIC_INVALID_CONNECTION_CLOSE_DATA, | 147 QUIC_INVALID_CONNECTION_CLOSE_DATA, |
142 // GoAway data is malformed. | 148 // GoAway data is malformed. |
143 QUIC_INVALID_GOAWAY_DATA, | 149 QUIC_INVALID_GOAWAY_DATA, |
144 // Ack data is malformed. | 150 // Ack data is malformed. |
145 QUIC_INVALID_ACK_DATA, | 151 QUIC_INVALID_ACK_DATA, |
| 152 // Version negotiation packet is malformed. |
| 153 QUIC_INVALID_VERSION_NEGOTIATION_PACKET, |
146 // There was an error decrypting. | 154 // There was an error decrypting. |
147 QUIC_DECRYPTION_FAILURE, | 155 QUIC_DECRYPTION_FAILURE, |
148 // There was an error encrypting. | 156 // There was an error encrypting. |
149 QUIC_ENCRYPTION_FAILURE, | 157 QUIC_ENCRYPTION_FAILURE, |
150 // The packet exceeded kMaxPacketSize. | 158 // The packet exceeded kMaxPacketSize. |
151 QUIC_PACKET_TOO_LARGE, | 159 QUIC_PACKET_TOO_LARGE, |
152 // Data was sent for a stream which did not exist. | 160 // Data was sent for a stream which did not exist. |
153 QUIC_PACKET_FOR_NONEXISTENT_STREAM, | 161 QUIC_PACKET_FOR_NONEXISTENT_STREAM, |
154 // The peer is going away. May be a client or server. | 162 // The peer is going away. May be a client or server. |
155 QUIC_PEER_GOING_AWAY, | 163 QUIC_PEER_GOING_AWAY, |
156 // A stream ID was invalid. | 164 // A stream ID was invalid. |
157 QUIC_INVALID_STREAM_ID, | 165 QUIC_INVALID_STREAM_ID, |
158 // Too many streams already open. | 166 // Too many streams already open. |
159 QUIC_TOO_MANY_OPEN_STREAMS, | 167 QUIC_TOO_MANY_OPEN_STREAMS, |
160 // Received public reset for this connection. | 168 // Received public reset for this connection. |
161 QUIC_PUBLIC_RESET, | 169 QUIC_PUBLIC_RESET, |
| 170 // Invalid protocol version |
| 171 QUIC_INVALID_VERSION, |
162 | 172 |
163 // We hit our prenegotiated (or default) timeout | 173 // We hit our prenegotiated (or default) timeout |
164 QUIC_CONNECTION_TIMED_OUT, | 174 QUIC_CONNECTION_TIMED_OUT, |
165 | 175 |
166 // Crypto errors. | 176 // Crypto errors. |
167 | 177 |
168 // Handshake message contained out of order tags. | 178 // Handshake message contained out of order tags. |
169 QUIC_CRYPTO_TAGS_OUT_OF_ORDER, | 179 QUIC_CRYPTO_TAGS_OUT_OF_ORDER, |
170 // Handshake message contained too many entries. | 180 // Handshake message contained too many entries. |
171 QUIC_CRYPTO_TOO_MANY_ENTRIES, | 181 QUIC_CRYPTO_TOO_MANY_ENTRIES, |
(...skipping 16 matching lines...) Expand all Loading... |
188 }; | 198 }; |
189 | 199 |
190 // Version and Crypto tags are written to the wire with a big-endian | 200 // Version and Crypto tags are written to the wire with a big-endian |
191 // representation of the name of the tag. For example | 201 // representation of the name of the tag. For example |
192 // the client hello tag (CHLO) will be written as the | 202 // the client hello tag (CHLO) will be written as the |
193 // following 4 bytes: 'C' 'H' 'L' 'O'. Since it is | 203 // following 4 bytes: 'C' 'H' 'L' 'O'. Since it is |
194 // stored in memory as a little endian uint32, we need | 204 // stored in memory as a little endian uint32, we need |
195 // to reverse the order of the bytes. | 205 // to reverse the order of the bytes. |
196 #define MAKE_TAG(a, b, c, d) ((d << 24) + (c << 16) + (b << 8) + a) | 206 #define MAKE_TAG(a, b, c, d) ((d << 24) + (c << 16) + (b << 8) + a) |
197 | 207 |
| 208 const QuicVersionTag kUnsupportedVersion = -1; |
198 const QuicVersionTag kQuicVersion1 = MAKE_TAG('Q', '1', '.', '0'); | 209 const QuicVersionTag kQuicVersion1 = MAKE_TAG('Q', '1', '.', '0'); |
199 | 210 |
200 struct NET_EXPORT_PRIVATE QuicPacketPublicHeader { | 211 struct NET_EXPORT_PRIVATE QuicPacketPublicHeader { |
| 212 QuicPacketPublicHeader(); |
| 213 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other); |
| 214 ~QuicPacketPublicHeader(); |
| 215 |
| 216 QuicPacketPublicHeader& operator=(const QuicPacketPublicHeader& other); |
| 217 |
201 // Universal header. All QuicPacket headers will have a guid and public flags. | 218 // Universal header. All QuicPacket headers will have a guid and public flags. |
202 QuicGuid guid; | 219 QuicGuid guid; |
203 bool reset_flag; | 220 bool reset_flag; |
204 bool version_flag; | 221 bool version_flag; |
205 QuicVersionTag version; | 222 QuicVersionTagList versions; |
206 }; | 223 }; |
207 | 224 |
208 // Header for Data or FEC packets. | 225 // Header for Data or FEC packets. |
209 struct QuicPacketHeader { | 226 struct QuicPacketHeader { |
210 QuicPacketHeader() {} | 227 QuicPacketHeader() {} |
211 explicit QuicPacketHeader(const QuicPacketPublicHeader& header) | 228 explicit QuicPacketHeader(const QuicPacketPublicHeader& header) |
212 : public_header(header) {} | 229 : public_header(header) {} |
213 | 230 |
214 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | 231 NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
215 std::ostream& os, const QuicPacketHeader& s); | 232 std::ostream& os, const QuicPacketHeader& s); |
216 | 233 |
217 QuicPacketPublicHeader public_header; | 234 QuicPacketPublicHeader public_header; |
218 bool fec_flag; | 235 bool fec_flag; |
219 bool fec_entropy_flag; | 236 bool fec_entropy_flag; |
220 bool entropy_flag; | 237 bool entropy_flag; |
221 QuicPacketEntropyHash entropy_hash; | 238 QuicPacketEntropyHash entropy_hash; |
222 QuicPacketSequenceNumber packet_sequence_number; | 239 QuicPacketSequenceNumber packet_sequence_number; |
223 QuicFecGroupNumber fec_group; | 240 QuicFecGroupNumber fec_group; |
224 }; | 241 }; |
225 | 242 |
226 struct QuicPublicResetPacket { | 243 struct QuicPublicResetPacket { |
227 QuicPublicResetPacket() {} | 244 QuicPublicResetPacket() {} |
228 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header) | 245 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header) |
229 : public_header(header) {} | 246 : public_header(header) {} |
230 QuicPacketPublicHeader public_header; | 247 QuicPacketPublicHeader public_header; |
231 QuicPacketSequenceNumber rejected_sequence_number; | 248 QuicPacketSequenceNumber rejected_sequence_number; |
232 QuicPublicResetNonceProof nonce_proof; | 249 QuicPublicResetNonceProof nonce_proof; |
233 }; | 250 }; |
234 | 251 |
| 252 enum QuicVersionNegotiationState { |
| 253 START_NEGOTIATION = 0, |
| 254 SENT_NEGOTIATION_PACKET, |
| 255 NEGOTIATED_VERSION |
| 256 }; |
| 257 |
| 258 typedef QuicPacketPublicHeader QuicVersionNegotiationPacket; |
| 259 |
235 // A padding frame contains no payload. | 260 // A padding frame contains no payload. |
236 struct NET_EXPORT_PRIVATE QuicPaddingFrame { | 261 struct NET_EXPORT_PRIVATE QuicPaddingFrame { |
237 }; | 262 }; |
238 | 263 |
239 struct NET_EXPORT_PRIVATE QuicStreamFrame { | 264 struct NET_EXPORT_PRIVATE QuicStreamFrame { |
240 QuicStreamFrame(); | 265 QuicStreamFrame(); |
241 QuicStreamFrame(QuicStreamId stream_id, | 266 QuicStreamFrame(QuicStreamId stream_id, |
242 bool fin, | 267 bool fin, |
243 QuicStreamOffset offset, | 268 QuicStreamOffset offset, |
244 base::StringPiece data); | 269 base::StringPiece data); |
(...skipping 23 matching lines...) Expand all Loading... |
268 // The highest packet sequence number we've observed from the peer. | 293 // The highest packet sequence number we've observed from the peer. |
269 // | 294 // |
270 // In general, this should be the largest packet number we've received. In | 295 // In general, this should be the largest packet number we've received. In |
271 // the case of truncated acks, we may have to advertise a lower "upper bound" | 296 // the case of truncated acks, we may have to advertise a lower "upper bound" |
272 // than largest received, to avoid implicitly acking missing packets that | 297 // than largest received, to avoid implicitly acking missing packets that |
273 // don't fit in the missing packet list due to size limitations. In this | 298 // don't fit in the missing packet list due to size limitations. In this |
274 // case, largest_observed may be a packet which is also in the missing packets | 299 // case, largest_observed may be a packet which is also in the missing packets |
275 // list. | 300 // list. |
276 QuicPacketSequenceNumber largest_observed; | 301 QuicPacketSequenceNumber largest_observed; |
277 | 302 |
| 303 // Time elapsed since largest_observed was received until this Ack frame was |
| 304 // sent. |
| 305 QuicTime::Delta delta_time_largest_observed; |
| 306 |
278 // TODO(satyamshekhar): Can be optimized using an interval set like data | 307 // TODO(satyamshekhar): Can be optimized using an interval set like data |
279 // structure. | 308 // structure. |
280 // The set of packets which we're expecting and have not received. | 309 // The set of packets which we're expecting and have not received. |
281 SequenceNumberSet missing_packets; | 310 SequenceNumberSet missing_packets; |
282 }; | 311 }; |
283 | 312 |
284 // True if the sequence number is greater than largest_observed or is listed | 313 // True if the sequence number is greater than largest_observed or is listed |
285 // as missing. | 314 // as missing. |
286 // Always returns false for sequence numbers less than least_unacked. | 315 // Always returns false for sequence numbers less than least_unacked. |
287 bool NET_EXPORT_PRIVATE IsAwaitingPacket( | 316 bool NET_EXPORT_PRIVATE IsAwaitingPacket( |
(...skipping 17 matching lines...) Expand all Loading... |
305 QuicPacketEntropyHash entropy_hash; | 334 QuicPacketEntropyHash entropy_hash; |
306 // The lowest packet we've sent which is unacked, and we expect an ack for. | 335 // The lowest packet we've sent which is unacked, and we expect an ack for. |
307 QuicPacketSequenceNumber least_unacked; | 336 QuicPacketSequenceNumber least_unacked; |
308 }; | 337 }; |
309 | 338 |
310 struct NET_EXPORT_PRIVATE QuicAckFrame { | 339 struct NET_EXPORT_PRIVATE QuicAckFrame { |
311 QuicAckFrame() {} | 340 QuicAckFrame() {} |
312 // Testing convenience method to construct a QuicAckFrame with all packets | 341 // Testing convenience method to construct a QuicAckFrame with all packets |
313 // from least_unacked to largest_observed acked. | 342 // from least_unacked to largest_observed acked. |
314 QuicAckFrame(QuicPacketSequenceNumber largest_observed, | 343 QuicAckFrame(QuicPacketSequenceNumber largest_observed, |
| 344 QuicTime largest_observed_receive_time, |
315 QuicPacketSequenceNumber least_unacked); | 345 QuicPacketSequenceNumber least_unacked); |
316 | 346 |
317 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | 347 NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
318 std::ostream& os, const QuicAckFrame& s); | 348 std::ostream& os, const QuicAckFrame& s); |
319 | 349 |
320 SentPacketInfo sent_info; | 350 SentPacketInfo sent_info; |
321 ReceivedPacketInfo received_info; | 351 ReceivedPacketInfo received_info; |
322 }; | 352 }; |
323 | 353 |
324 // Defines for all types of congestion feedback that will be negotiated in QUIC, | 354 // Defines for all types of congestion feedback that will be negotiated in QUIC, |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | 629 NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
600 std::ostream& os, const QuicConsumedData& s); | 630 std::ostream& os, const QuicConsumedData& s); |
601 | 631 |
602 size_t bytes_consumed; | 632 size_t bytes_consumed; |
603 bool fin_consumed; | 633 bool fin_consumed; |
604 }; | 634 }; |
605 | 635 |
606 } // namespace net | 636 } // namespace net |
607 | 637 |
608 #endif // NET_QUIC_QUIC_PROTOCOL_H_ | 638 #endif // NET_QUIC_QUIC_PROTOCOL_H_ |
OLD | NEW |