Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: net/quic/quic_protocol.h

Issue 15937012: Land Recent QUIC changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Small bug fixes Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 10 matching lines...) Expand all
21 #include "net/base/int128.h" 21 #include "net/base/int128.h"
22 #include "net/base/net_export.h" 22 #include "net/base/net_export.h"
23 #include "net/quic/quic_bandwidth.h" 23 #include "net/quic/quic_bandwidth.h"
24 #include "net/quic/quic_time.h" 24 #include "net/quic/quic_time.h"
25 25
26 namespace net { 26 namespace net {
27 27
28 using ::operator<<; 28 using ::operator<<;
29 29
30 class QuicPacket; 30 class QuicPacket;
31 struct QuicPacketHeader;
31 32
32 typedef uint64 QuicGuid; 33 typedef uint64 QuicGuid;
33 typedef uint32 QuicStreamId; 34 typedef uint32 QuicStreamId;
34 typedef uint64 QuicStreamOffset; 35 typedef uint64 QuicStreamOffset;
35 typedef uint64 QuicPacketSequenceNumber; 36 typedef uint64 QuicPacketSequenceNumber;
36 typedef QuicPacketSequenceNumber QuicFecGroupNumber; 37 typedef QuicPacketSequenceNumber QuicFecGroupNumber;
37 typedef uint64 QuicPublicResetNonceProof; 38 typedef uint64 QuicPublicResetNonceProof;
38 typedef uint8 QuicPacketEntropyHash; 39 typedef uint8 QuicPacketEntropyHash;
39 typedef uint32 QuicHeaderId; 40 typedef uint32 QuicHeaderId;
40 // QuicTag is the type of a tag in the wire protocol. 41 // QuicTag is the type of a tag in the wire protocol.
41 typedef uint32 QuicTag; 42 typedef uint32 QuicTag;
42 typedef std::vector<QuicTag> QuicTagVector; 43 typedef std::vector<QuicTag> QuicTagVector;
43 44
44 // TODO(rch): Consider Quic specific names for these constants. 45 // TODO(rch): Consider Quic specific names for these constants.
45 // Maximum size in bytes of a QUIC packet. 46 // Maximum size in bytes of a QUIC packet.
46 const QuicByteCount kMaxPacketSize = 1200; 47 const QuicByteCount kMaxPacketSize = 1200;
47 48
48 // Maximum number of open streams per connection. 49 // Maximum number of open streams per connection.
49 const size_t kDefaultMaxStreamsPerConnection = 100; 50 const size_t kDefaultMaxStreamsPerConnection = 100;
50 51
51 // Number of bytes reserved for public flags in the packet header. 52 // Number of bytes reserved for public flags in the packet header.
52 const size_t kPublicFlagsSize = 1; 53 const size_t kPublicFlagsSize = 1;
53 // Number of bytes reserved for guid in the packet header.
54 const size_t kQuicGuidSize = 8;
55 // Number of bytes reserved for version number in the packet header. 54 // Number of bytes reserved for version number in the packet header.
56 const size_t kQuicVersionSize = 4; 55 const size_t kQuicVersionSize = 4;
57 // Number of bytes reserved for sequence number in the packet header. 56 // Number of bytes reserved for sequence number in the packet header.
58 const size_t kSequenceNumberSize = 6; 57 const size_t kSequenceNumberSize = 6;
59 // Number of bytes reserved for private flags in the packet header. 58 // Number of bytes reserved for private flags in the packet header.
60 const size_t kPrivateFlagsSize = 1; 59 const size_t kPrivateFlagsSize = 1;
61 // Number of bytes reserved for FEC group in the packet header. 60 // Number of bytes reserved for FEC group in the packet header.
62 const size_t kFecGroupSize = 1; 61 const size_t kFecGroupSize = 1;
63 // Number of bytes reserved for the nonce proof in public reset packet. 62 // Number of bytes reserved for the nonce proof in public reset packet.
64 const size_t kPublicResetNonceSize = 8; 63 const size_t kPublicResetNonceSize = 8;
65 64
66 // Signifies that the QuicPacket will contain version of the protocol. 65 // Signifies that the QuicPacket will contain version of the protocol.
67 const bool kIncludeVersion = true; 66 const bool kIncludeVersion = true;
68 67
69 // Size in bytes of the data or fec packet header.
70 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(bool include_version);
71 // Size in bytes of the public reset packet.
72 NET_EXPORT_PRIVATE size_t GetPublicResetPacketSize();
73
74 // Index of the first byte in a QUIC packet of FEC protected data.
75 NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(bool include_version);
76 // Index of the first byte in a QUIC packet of encrypted data.
77 NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(bool include_version);
78 // Returns true if |version| is a supported protocol version. 68 // Returns true if |version| is a supported protocol version.
79 NET_EXPORT_PRIVATE bool IsSupportedVersion(QuicTag version); 69 NET_EXPORT_PRIVATE bool IsSupportedVersion(QuicTag version);
80 70
81 // Index of the first byte in a QUIC packet which is used in hash calculation. 71 // Index of the first byte in a QUIC packet which is used in hash calculation.
82 const size_t kStartOfHashData = 0; 72 const size_t kStartOfHashData = 0;
83 73
84 // Limit on the delta between stream IDs. 74 // Limit on the delta between stream IDs.
85 const QuicStreamId kMaxStreamIdDelta = 100; 75 const QuicStreamId kMaxStreamIdDelta = 100;
86 // Limit on the delta between header IDs. 76 // Limit on the delta between header IDs.
87 const QuicHeaderId kMaxHeaderIdDelta = 100; 77 const QuicHeaderId kMaxHeaderIdDelta = 100;
88 78
89 // Reserved ID for the crypto stream. 79 // Reserved ID for the crypto stream.
90 // TODO(rch): ensure that this is not usable by any other streams. 80 // TODO(rch): ensure that this is not usable by any other streams.
91 const QuicStreamId kCryptoStreamId = 1; 81 const QuicStreamId kCryptoStreamId = 1;
92 82
93 // Value which indicates this packet is not FEC protected.
94 const uint8 kNoFecOffset = 0xFF;
95
96 // This is the default network timeout a for connection till the crypto 83 // This is the default network timeout a for connection till the crypto
97 // handshake succeeds and the negotiated timeout from the handshake is received. 84 // handshake succeeds and the negotiated timeout from the handshake is received.
98 const int64 kDefaultInitialTimeoutSecs = 30; // 30 secs. 85 const int64 kDefaultInitialTimeoutSecs = 120; // 2 mins.
99 const int64 kDefaultTimeoutSecs = 60 * 10; // 10 minutes. 86 const int64 kDefaultTimeoutSecs = 60 * 10; // 10 minutes.
87 const int64 kDefaultMaxTimeForCryptoHandshakeSecs = 5; // 5 secs.
100 88
101 enum Retransmission { 89 enum Retransmission {
102 NOT_RETRANSMISSION, 90 NOT_RETRANSMISSION,
103 IS_RETRANSMISSION, 91 IS_RETRANSMISSION,
104 }; 92 };
105 93
106 enum HasRetransmittableData { 94 enum HasRetransmittableData {
107 NO_RETRANSMITTABLE_DATA, 95 NO_RETRANSMITTABLE_DATA,
108 HAS_RETRANSMITTABLE_DATA, 96 HAS_RETRANSMITTABLE_DATA,
109 }; 97 };
110 98
111 enum QuicFrameType { 99 enum QuicFrameType {
112 PADDING_FRAME = 0, 100 PADDING_FRAME = 0,
113 STREAM_FRAME, 101 STREAM_FRAME,
114 ACK_FRAME, 102 ACK_FRAME,
115 CONGESTION_FEEDBACK_FRAME, 103 CONGESTION_FEEDBACK_FRAME,
116 RST_STREAM_FRAME, 104 RST_STREAM_FRAME,
117 CONNECTION_CLOSE_FRAME, 105 CONNECTION_CLOSE_FRAME,
118 GOAWAY_FRAME, 106 GOAWAY_FRAME,
119 NUM_FRAME_TYPES 107 NUM_FRAME_TYPES
120 }; 108 };
121 109
110 enum QuicGuidLength {
111 PACKET_0BYTE_GUID = 0,
112 PACKET_1BYTE_GUID = 1,
113 PACKET_4BYTE_GUID = 4,
114 PACKET_8BYTE_GUID = 8
115 };
116
117 enum InFecGroup {
118 NOT_IN_FEC_GROUP,
119 IN_FEC_GROUP,
120 };
121
122 enum QuicPacketPublicFlags { 122 enum QuicPacketPublicFlags {
123 PACKET_PUBLIC_FLAGS_NONE = 0, 123 PACKET_PUBLIC_FLAGS_NONE = 0,
124 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0, // Packet header contains version info. 124 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0, // Packet header contains version info.
125 PACKET_PUBLIC_FLAGS_RST = 1 << 1, // Packet is a public reset packet. 125 PACKET_PUBLIC_FLAGS_RST = 1 << 1, // Packet is a public reset packet.
126 // Packet header guid length in bytes. 126 // Packet header guid length in bytes.
127 PACKET_PUBLIC_FLAGS_0BYTE_GUID = 0, 127 PACKET_PUBLIC_FLAGS_0BYTE_GUID = 0,
128 PACKET_PUBLIC_FLAGS_1BYTE_GUID = 1 << 2, 128 PACKET_PUBLIC_FLAGS_1BYTE_GUID = 1 << 2,
129 PACKET_PUBLIC_FLAGS_4BYTE_GUID = 1 << 3, 129 PACKET_PUBLIC_FLAGS_4BYTE_GUID = 1 << 3,
130 PACKET_PUBLIC_FLAGS_8BYTE_GUID = 1 << 3 | 1 << 2, 130 PACKET_PUBLIC_FLAGS_8BYTE_GUID = 1 << 3 | 1 << 2,
131 PACKET_PUBLIC_FLAGS_MAX = (1 << 4) - 1 // All bits set. 131 PACKET_PUBLIC_FLAGS_MAX = (1 << 4) - 1 // All bits set.
132 }; 132 };
133 133
134 enum QuicPacketPrivateFlags { 134 enum QuicPacketPrivateFlags {
135 PACKET_PRIVATE_FLAGS_NONE = 0, 135 PACKET_PRIVATE_FLAGS_NONE = 0,
136 PACKET_PRIVATE_FLAGS_FEC = 1 << 0, // Payload is FEC as opposed to frames. 136 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0,
137 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 1, 137 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1, // Payload is part of an FEC group.
138 PACKET_PRIVATE_FLAGS_FEC_ENTROPY = 1 << 2, 138 PACKET_PRIVATE_FLAGS_FEC = 1 << 2, // Payload is FEC as opposed to frames.
139 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1 // All bits set. 139 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1 // All bits set.
140 }; 140 };
141 141
142 // Size in bytes of the data or fec packet header.
143 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicPacketHeader header);
144
145 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicGuidLength guid_length,
146 bool include_version,
147 InFecGroup is_in_fec_group);
148
149 // Size in bytes of the public reset packet.
150 NET_EXPORT_PRIVATE size_t GetPublicResetPacketSize();
151
152 // Index of the first byte in a QUIC packet of FEC protected data.
153 NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(QuicGuidLength guid_length,
154 bool include_version);
155 // Index of the first byte in a QUIC packet of encrypted data.
156 NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(QuicGuidLength guid_length,
157 bool include_version);
158
142 enum QuicRstStreamErrorCode { 159 enum QuicRstStreamErrorCode {
143 QUIC_STREAM_NO_ERROR = 0, 160 QUIC_STREAM_NO_ERROR = 0,
144 161
145 // There was some server error which halted stream processing. 162 // There was some server error which halted stream processing.
146 QUIC_SERVER_ERROR_PROCESSING_STREAM, 163 QUIC_SERVER_ERROR_PROCESSING_STREAM,
147 // We got two fin or reset offsets which did not match. 164 // We got two fin or reset offsets which did not match.
148 QUIC_MULTIPLE_TERMINATION_OFFSETS, 165 QUIC_MULTIPLE_TERMINATION_OFFSETS,
149 // We got bad payload and can not respond to it at the protocol level. 166 // We got bad payload and can not respond to it at the protocol level.
150 QUIC_BAD_APPLICATION_PAYLOAD, 167 QUIC_BAD_APPLICATION_PAYLOAD,
151 // Stream closed due to connection error. No reset frame is sent when this 168 // Stream closed due to connection error. No reset frame is sent when this
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 // stored in memory as a little endian uint32, we need 288 // stored in memory as a little endian uint32, we need
272 // to reverse the order of the bytes. 289 // to reverse the order of the bytes.
273 // 290 //
274 // The TAG macro is used in header files to ensure that we don't create static 291 // The TAG macro is used in header files to ensure that we don't create static
275 // initialisers. In normal code, the MakeQuicTag function should be used. 292 // initialisers. In normal code, the MakeQuicTag function should be used.
276 #define TAG(a, b, c, d) ((d << 24) + (c << 16) + (b << 8) + a) 293 #define TAG(a, b, c, d) ((d << 24) + (c << 16) + (b << 8) + a)
277 const QuicTag kUnsupportedVersion = -1; 294 const QuicTag kUnsupportedVersion = -1;
278 // Each time the wire format changes, this need needs to be incremented. 295 // Each time the wire format changes, this need needs to be incremented.
279 // At some point, we will actually freeze the wire format and make an official 296 // At some point, we will actually freeze the wire format and make an official
280 // version number, but this works for now. 297 // version number, but this works for now.
281 const QuicTag kQuicVersion1 = TAG('Q', '0', '0', '4'); 298 const QuicTag kQuicVersion1 = TAG('Q', '0', '0', '5');
282 #undef TAG 299 #undef TAG
283 300
284 // MakeQuicTag returns a value given the four bytes. For example: 301 // MakeQuicTag returns a value given the four bytes. For example:
285 // MakeQuicTag('C', 'H', 'L', 'O'); 302 // MakeQuicTag('C', 'H', 'L', 'O');
286 uint32 NET_EXPORT_PRIVATE MakeQuicTag(char a, char b, char c, char d); 303 uint32 NET_EXPORT_PRIVATE MakeQuicTag(char a, char b, char c, char d);
287 304
288 struct NET_EXPORT_PRIVATE QuicPacketPublicHeader { 305 struct NET_EXPORT_PRIVATE QuicPacketPublicHeader {
289 QuicPacketPublicHeader(); 306 QuicPacketPublicHeader();
290 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other); 307 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other);
291 ~QuicPacketPublicHeader(); 308 ~QuicPacketPublicHeader();
292 309
293 QuicPacketPublicHeader& operator=(const QuicPacketPublicHeader& other); 310 QuicPacketPublicHeader& operator=(const QuicPacketPublicHeader& other);
294 311
295 // Universal header. All QuicPacket headers will have a guid and public flags. 312 // Universal header. All QuicPacket headers will have a guid and public flags.
296 QuicGuid guid; 313 QuicGuid guid;
314 QuicGuidLength guid_length;
297 bool reset_flag; 315 bool reset_flag;
298 bool version_flag; 316 bool version_flag;
299 QuicTagVector versions; 317 QuicTagVector versions;
300 }; 318 };
301 319
302 // Header for Data or FEC packets. 320 // Header for Data or FEC packets.
303 struct NET_EXPORT_PRIVATE QuicPacketHeader { 321 struct NET_EXPORT_PRIVATE QuicPacketHeader {
304 QuicPacketHeader(); 322 QuicPacketHeader();
305 explicit QuicPacketHeader(const QuicPacketPublicHeader& header); 323 explicit QuicPacketHeader(const QuicPacketPublicHeader& header);
306 324
307 NET_EXPORT_PRIVATE friend std::ostream& operator<<( 325 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
308 std::ostream& os, const QuicPacketHeader& s); 326 std::ostream& os, const QuicPacketHeader& s);
309 327
310 QuicPacketPublicHeader public_header; 328 QuicPacketPublicHeader public_header;
311 bool fec_flag; 329 bool fec_flag;
312 bool fec_entropy_flag;
313 bool entropy_flag; 330 bool entropy_flag;
314 QuicPacketEntropyHash entropy_hash; 331 QuicPacketEntropyHash entropy_hash;
315 QuicPacketSequenceNumber packet_sequence_number; 332 QuicPacketSequenceNumber packet_sequence_number;
333 InFecGroup is_in_fec_group;
316 QuicFecGroupNumber fec_group; 334 QuicFecGroupNumber fec_group;
317 }; 335 };
318 336
319 struct NET_EXPORT_PRIVATE QuicPublicResetPacket { 337 struct NET_EXPORT_PRIVATE QuicPublicResetPacket {
320 QuicPublicResetPacket() {} 338 QuicPublicResetPacket() {}
321 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header) 339 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header)
322 : public_header(header) {} 340 : public_header(header) {}
323 QuicPacketPublicHeader public_header; 341 QuicPacketPublicHeader public_header;
324 QuicPacketSequenceNumber rejected_sequence_number; 342 QuicPacketSequenceNumber rejected_sequence_number;
325 QuicPublicResetNonceProof nonce_proof; 343 QuicPublicResetNonceProof nonce_proof;
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 bool owns_buffer_; 617 bool owns_buffer_;
600 618
601 DISALLOW_COPY_AND_ASSIGN(QuicData); 619 DISALLOW_COPY_AND_ASSIGN(QuicData);
602 }; 620 };
603 621
604 class NET_EXPORT_PRIVATE QuicPacket : public QuicData { 622 class NET_EXPORT_PRIVATE QuicPacket : public QuicData {
605 public: 623 public:
606 static QuicPacket* NewDataPacket(char* buffer, 624 static QuicPacket* NewDataPacket(char* buffer,
607 size_t length, 625 size_t length,
608 bool owns_buffer, 626 bool owns_buffer,
627 QuicGuidLength guid_length,
609 bool includes_version) { 628 bool includes_version) {
610 return new QuicPacket(buffer, length, owns_buffer, includes_version, false); 629 return new QuicPacket(
630 buffer, length, owns_buffer, guid_length, includes_version, false);
611 } 631 }
612 632
613 static QuicPacket* NewFecPacket(char* buffer, 633 static QuicPacket* NewFecPacket(char* buffer,
614 size_t length, 634 size_t length,
615 bool owns_buffer, 635 bool owns_buffer,
636 QuicGuidLength guid_length,
616 bool includes_version) { 637 bool includes_version) {
617 return new QuicPacket(buffer, length, owns_buffer, includes_version, true); 638 return new QuicPacket(
639 buffer, length, owns_buffer, guid_length, includes_version, true);
618 } 640 }
619 641
620 base::StringPiece FecProtectedData() const; 642 base::StringPiece FecProtectedData() const;
621 base::StringPiece AssociatedData() const; 643 base::StringPiece AssociatedData() const;
622 base::StringPiece BeforePlaintext() const; 644 base::StringPiece BeforePlaintext() const;
623 base::StringPiece Plaintext() const; 645 base::StringPiece Plaintext() const;
624 646
625 bool is_fec_packet() const { return is_fec_packet_; } 647 bool is_fec_packet() const { return is_fec_packet_; }
626 648
627 bool includes_version() const { return includes_version_; } 649 bool includes_version() const { return includes_version_; }
628 650
629 char* mutable_data() { return buffer_; } 651 char* mutable_data() { return buffer_; }
630 652
631 private: 653 private:
632 QuicPacket(char* buffer, 654 QuicPacket(char* buffer,
633 size_t length, 655 size_t length,
634 bool owns_buffer, 656 bool owns_buffer,
657 QuicGuidLength guid_length,
635 bool includes_version, 658 bool includes_version,
636 bool is_fec_packet) 659 bool is_fec_packet)
637 : QuicData(buffer, length, owns_buffer), 660 : QuicData(buffer, length, owns_buffer),
638 buffer_(buffer), 661 buffer_(buffer),
639 is_fec_packet_(is_fec_packet), 662 is_fec_packet_(is_fec_packet),
663 guid_length_(guid_length),
640 includes_version_(includes_version) {} 664 includes_version_(includes_version) {}
641 665
642 char* buffer_; 666 char* buffer_;
643 const bool is_fec_packet_; 667 const bool is_fec_packet_;
668 const QuicGuidLength guid_length_;
644 const bool includes_version_; 669 const bool includes_version_;
645 670
646 DISALLOW_COPY_AND_ASSIGN(QuicPacket); 671 DISALLOW_COPY_AND_ASSIGN(QuicPacket);
647 }; 672 };
648 673
649 class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData { 674 class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData {
650 public: 675 public:
651 QuicEncryptedPacket(const char* buffer, size_t length) 676 QuicEncryptedPacket(const char* buffer, size_t length)
652 : QuicData(buffer, length) {} 677 : QuicData(buffer, length) {}
653 678
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 NET_EXPORT_PRIVATE friend std::ostream& operator<<( 748 NET_EXPORT_PRIVATE friend std::ostream& operator<<(
724 std::ostream& os, const QuicConsumedData& s); 749 std::ostream& os, const QuicConsumedData& s);
725 750
726 size_t bytes_consumed; 751 size_t bytes_consumed;
727 bool fin_consumed; 752 bool fin_consumed;
728 }; 753 };
729 754
730 } // namespace net 755 } // namespace net
731 756
732 #endif // NET_QUIC_QUIC_PROTOCOL_H_ 757 #endif // NET_QUIC_QUIC_PROTOCOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698