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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // Maximum size in bytes of a QUIC packet. | 46 // Maximum size in bytes of a QUIC packet. |
47 const QuicByteCount kMaxPacketSize = 1200; | 47 const QuicByteCount kMaxPacketSize = 1200; |
48 | 48 |
49 // Maximum number of open streams per connection. | 49 // Maximum number of open streams per connection. |
50 const size_t kDefaultMaxStreamsPerConnection = 100; | 50 const size_t kDefaultMaxStreamsPerConnection = 100; |
51 | 51 |
52 // Number of bytes reserved for public flags in the packet header. | 52 // Number of bytes reserved for public flags in the packet header. |
53 const size_t kPublicFlagsSize = 1; | 53 const size_t kPublicFlagsSize = 1; |
54 // Number of bytes reserved for version number in the packet header. | 54 // Number of bytes reserved for version number in the packet header. |
55 const size_t kQuicVersionSize = 4; | 55 const size_t kQuicVersionSize = 4; |
| 56 // Number of bytes reserved for sequence number in the packet header. |
| 57 const size_t kSequenceNumberSize = 6; |
56 // Number of bytes reserved for private flags in the packet header. | 58 // Number of bytes reserved for private flags in the packet header. |
57 const size_t kPrivateFlagsSize = 1; | 59 const size_t kPrivateFlagsSize = 1; |
58 // Number of bytes reserved for FEC group in the packet header. | 60 // Number of bytes reserved for FEC group in the packet header. |
59 const size_t kFecGroupSize = 1; | 61 const size_t kFecGroupSize = 1; |
60 // 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. |
61 const size_t kPublicResetNonceSize = 8; | 63 const size_t kPublicResetNonceSize = 8; |
62 | 64 |
63 // Signifies that the QuicPacket will contain version of the protocol. | 65 // Signifies that the QuicPacket will contain version of the protocol. |
64 const bool kIncludeVersion = true; | 66 const bool kIncludeVersion = true; |
65 | 67 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 PACKET_1BYTE_GUID = 1, | 112 PACKET_1BYTE_GUID = 1, |
111 PACKET_4BYTE_GUID = 4, | 113 PACKET_4BYTE_GUID = 4, |
112 PACKET_8BYTE_GUID = 8 | 114 PACKET_8BYTE_GUID = 8 |
113 }; | 115 }; |
114 | 116 |
115 enum InFecGroup { | 117 enum InFecGroup { |
116 NOT_IN_FEC_GROUP, | 118 NOT_IN_FEC_GROUP, |
117 IN_FEC_GROUP, | 119 IN_FEC_GROUP, |
118 }; | 120 }; |
119 | 121 |
120 enum QuicSequenceNumberLength { | |
121 PACKET_1BYTE_SEQUENCE_NUMBER = 1, | |
122 PACKET_2BYTE_SEQUENCE_NUMBER = 2, | |
123 PACKET_4BYTE_SEQUENCE_NUMBER = 4, | |
124 PACKET_6BYTE_SEQUENCE_NUMBER = 6 | |
125 }; | |
126 | |
127 enum QuicPacketPublicFlags { | 122 enum QuicPacketPublicFlags { |
128 PACKET_PUBLIC_FLAGS_NONE = 0, | 123 PACKET_PUBLIC_FLAGS_NONE = 0, |
129 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0, // Packet header contains version info. | 124 PACKET_PUBLIC_FLAGS_VERSION = 1 << 0, // Packet header contains version info. |
130 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. |
131 // Packet header guid length in bytes. | 126 // Packet header guid length in bytes. |
132 PACKET_PUBLIC_FLAGS_0BYTE_GUID = 0, | 127 PACKET_PUBLIC_FLAGS_0BYTE_GUID = 0, |
133 PACKET_PUBLIC_FLAGS_1BYTE_GUID = 1 << 2, | 128 PACKET_PUBLIC_FLAGS_1BYTE_GUID = 1 << 2, |
134 PACKET_PUBLIC_FLAGS_4BYTE_GUID = 1 << 3, | 129 PACKET_PUBLIC_FLAGS_4BYTE_GUID = 1 << 3, |
135 PACKET_PUBLIC_FLAGS_8BYTE_GUID = 1 << 3 | 1 << 2, | 130 PACKET_PUBLIC_FLAGS_8BYTE_GUID = 1 << 3 | 1 << 2, |
136 // Packet sequence number length in bytes. | 131 PACKET_PUBLIC_FLAGS_MAX = (1 << 4) - 1 // All bits set. |
137 PACKET_PUBLIC_FLAGS_1BYTE_SEQUENCE = 0, | |
138 PACKET_PUBLIC_FLAGS_2BYTE_SEQUENCE = 1 << 4, | |
139 PACKET_PUBLIC_FLAGS_4BYTE_SEQUENCE = 1 << 5, | |
140 PACKET_PUBLIC_FLAGS_6BYTE_SEQUENCE = 1 << 5 | 1 << 4, | |
141 PACKET_PUBLIC_FLAGS_MAX = (1 << 6) - 1 // All bits set. | |
142 }; | 132 }; |
143 | 133 |
144 enum QuicPacketPrivateFlags { | 134 enum QuicPacketPrivateFlags { |
145 PACKET_PRIVATE_FLAGS_NONE = 0, | 135 PACKET_PRIVATE_FLAGS_NONE = 0, |
146 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0, | 136 PACKET_PRIVATE_FLAGS_ENTROPY = 1 << 0, |
147 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1, // Payload is part of an FEC group. | 137 PACKET_PRIVATE_FLAGS_FEC_GROUP = 1 << 1, // Payload is part of an FEC group. |
148 PACKET_PRIVATE_FLAGS_FEC = 1 << 2, // Payload is FEC as opposed to frames. | 138 PACKET_PRIVATE_FLAGS_FEC = 1 << 2, // Payload is FEC as opposed to frames. |
149 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1 // All bits set. | 139 PACKET_PRIVATE_FLAGS_MAX = (1 << 3) - 1 // All bits set. |
150 }; | 140 }; |
151 | 141 |
152 // Size in bytes of the data or fec packet header. | 142 // Size in bytes of the data or fec packet header. |
153 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicPacketHeader header); | 143 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicPacketHeader header); |
154 | 144 |
155 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize( | 145 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicGuidLength guid_length, |
156 QuicGuidLength guid_length, | 146 bool include_version, |
157 bool include_version, | 147 InFecGroup is_in_fec_group); |
158 QuicSequenceNumberLength sequence_number_length, | |
159 InFecGroup is_in_fec_group); | |
160 | 148 |
161 // Size in bytes of the public reset packet. | 149 // Size in bytes of the public reset packet. |
162 NET_EXPORT_PRIVATE size_t GetPublicResetPacketSize(); | 150 NET_EXPORT_PRIVATE size_t GetPublicResetPacketSize(); |
163 | 151 |
164 // Index of the first byte in a QUIC packet of FEC protected data. | 152 // Index of the first byte in a QUIC packet of FEC protected data. |
165 NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData( | 153 NET_EXPORT_PRIVATE size_t GetStartOfFecProtectedData(QuicGuidLength guid_length, |
166 QuicGuidLength guid_length, | 154 bool include_version); |
167 bool include_version, | |
168 QuicSequenceNumberLength sequence_number_length); | |
169 // Index of the first byte in a QUIC packet of encrypted data. | 155 // Index of the first byte in a QUIC packet of encrypted data. |
170 NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData( | 156 NET_EXPORT_PRIVATE size_t GetStartOfEncryptedData(QuicGuidLength guid_length, |
171 QuicGuidLength guid_length, | 157 bool include_version); |
172 bool include_version, | |
173 QuicSequenceNumberLength sequence_number_length); | |
174 | 158 |
175 enum QuicRstStreamErrorCode { | 159 enum QuicRstStreamErrorCode { |
176 QUIC_STREAM_NO_ERROR = 0, | 160 QUIC_STREAM_NO_ERROR = 0, |
177 | 161 |
178 // There was some server error which halted stream processing. | 162 // There was some server error which halted stream processing. |
179 QUIC_SERVER_ERROR_PROCESSING_STREAM, | 163 QUIC_SERVER_ERROR_PROCESSING_STREAM, |
180 // We got two fin or reset offsets which did not match. | 164 // We got two fin or reset offsets which did not match. |
181 QUIC_MULTIPLE_TERMINATION_OFFSETS, | 165 QUIC_MULTIPLE_TERMINATION_OFFSETS, |
182 // 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. |
183 QUIC_BAD_APPLICATION_PAYLOAD, | 167 QUIC_BAD_APPLICATION_PAYLOAD, |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 // stored in memory as a little endian uint32, we need | 288 // stored in memory as a little endian uint32, we need |
305 // to reverse the order of the bytes. | 289 // to reverse the order of the bytes. |
306 // | 290 // |
307 // 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 |
308 // initialisers. In normal code, the MakeQuicTag function should be used. | 292 // initialisers. In normal code, the MakeQuicTag function should be used. |
309 #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) |
310 const QuicTag kUnsupportedVersion = -1; | 294 const QuicTag kUnsupportedVersion = -1; |
311 // 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. |
312 // 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 |
313 // version number, but this works for now. | 297 // version number, but this works for now. |
314 const QuicTag kQuicVersion1 = TAG('Q', '0', '0', '6'); | 298 const QuicTag kQuicVersion1 = TAG('Q', '0', '0', '5'); |
315 #undef TAG | 299 #undef TAG |
316 | 300 |
317 // MakeQuicTag returns a value given the four bytes. For example: | 301 // MakeQuicTag returns a value given the four bytes. For example: |
318 // MakeQuicTag('C', 'H', 'L', 'O'); | 302 // MakeQuicTag('C', 'H', 'L', 'O'); |
319 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); |
320 | 304 |
321 struct NET_EXPORT_PRIVATE QuicPacketPublicHeader { | 305 struct NET_EXPORT_PRIVATE QuicPacketPublicHeader { |
322 QuicPacketPublicHeader(); | 306 QuicPacketPublicHeader(); |
323 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other); | 307 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other); |
324 ~QuicPacketPublicHeader(); | 308 ~QuicPacketPublicHeader(); |
325 | 309 |
326 QuicPacketPublicHeader& operator=(const QuicPacketPublicHeader& other); | 310 QuicPacketPublicHeader& operator=(const QuicPacketPublicHeader& other); |
327 | 311 |
328 // 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. |
329 QuicGuid guid; | 313 QuicGuid guid; |
330 QuicGuidLength guid_length; | 314 QuicGuidLength guid_length; |
331 bool reset_flag; | 315 bool reset_flag; |
332 bool version_flag; | 316 bool version_flag; |
333 QuicSequenceNumberLength sequence_number_length; | |
334 QuicTagVector versions; | 317 QuicTagVector versions; |
335 }; | 318 }; |
336 | 319 |
337 // Header for Data or FEC packets. | 320 // Header for Data or FEC packets. |
338 struct NET_EXPORT_PRIVATE QuicPacketHeader { | 321 struct NET_EXPORT_PRIVATE QuicPacketHeader { |
339 QuicPacketHeader(); | 322 QuicPacketHeader(); |
340 explicit QuicPacketHeader(const QuicPacketPublicHeader& header); | 323 explicit QuicPacketHeader(const QuicPacketPublicHeader& header); |
341 | 324 |
342 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | 325 NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
343 std::ostream& os, const QuicPacketHeader& s); | 326 std::ostream& os, const QuicPacketHeader& s); |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 QuicConnectionCloseFrame* connection_close_frame; | 570 QuicConnectionCloseFrame* connection_close_frame; |
588 QuicGoAwayFrame* goaway_frame; | 571 QuicGoAwayFrame* goaway_frame; |
589 }; | 572 }; |
590 }; | 573 }; |
591 | 574 |
592 typedef std::vector<QuicFrame> QuicFrames; | 575 typedef std::vector<QuicFrame> QuicFrames; |
593 | 576 |
594 struct NET_EXPORT_PRIVATE QuicFecData { | 577 struct NET_EXPORT_PRIVATE QuicFecData { |
595 QuicFecData(); | 578 QuicFecData(); |
596 | 579 |
| 580 bool operator==(const QuicFecData& other) const; |
| 581 |
597 // The FEC group number is also the sequence number of the first | 582 // The FEC group number is also the sequence number of the first |
598 // FEC protected packet. The last protected packet's sequence number will | 583 // FEC protected packet. The last protected packet's sequence number will |
599 // be one less than the sequence number of the FEC packet. | 584 // be one less than the sequence number of the FEC packet. |
600 QuicFecGroupNumber fec_group; | 585 QuicFecGroupNumber fec_group; |
601 base::StringPiece redundancy; | 586 base::StringPiece redundancy; |
602 }; | 587 }; |
603 | 588 |
604 struct NET_EXPORT_PRIVATE QuicPacketData { | 589 struct NET_EXPORT_PRIVATE QuicPacketData { |
605 std::string data; | 590 std::string data; |
606 }; | 591 }; |
(...skipping 22 matching lines...) Expand all Loading... |
629 private: | 614 private: |
630 const char* buffer_; | 615 const char* buffer_; |
631 size_t length_; | 616 size_t length_; |
632 bool owns_buffer_; | 617 bool owns_buffer_; |
633 | 618 |
634 DISALLOW_COPY_AND_ASSIGN(QuicData); | 619 DISALLOW_COPY_AND_ASSIGN(QuicData); |
635 }; | 620 }; |
636 | 621 |
637 class NET_EXPORT_PRIVATE QuicPacket : public QuicData { | 622 class NET_EXPORT_PRIVATE QuicPacket : public QuicData { |
638 public: | 623 public: |
639 static QuicPacket* NewDataPacket( | 624 static QuicPacket* NewDataPacket(char* buffer, |
640 char* buffer, | 625 size_t length, |
641 size_t length, | 626 bool owns_buffer, |
642 bool owns_buffer, | 627 QuicGuidLength guid_length, |
643 QuicGuidLength guid_length, | 628 bool includes_version) { |
644 bool includes_version, | 629 return new QuicPacket( |
645 QuicSequenceNumberLength sequence_number_length) { | 630 buffer, length, owns_buffer, guid_length, includes_version, false); |
646 return new QuicPacket(buffer, length, owns_buffer, guid_length, | |
647 includes_version, sequence_number_length, false); | |
648 } | 631 } |
649 | 632 |
650 static QuicPacket* NewFecPacket( | 633 static QuicPacket* NewFecPacket(char* buffer, |
651 char* buffer, | 634 size_t length, |
652 size_t length, | 635 bool owns_buffer, |
653 bool owns_buffer, | 636 QuicGuidLength guid_length, |
654 QuicGuidLength guid_length, | 637 bool includes_version) { |
655 bool includes_version, | 638 return new QuicPacket( |
656 QuicSequenceNumberLength sequence_number_length) { | 639 buffer, length, owns_buffer, guid_length, includes_version, true); |
657 return new QuicPacket(buffer, length, owns_buffer, guid_length, | |
658 includes_version, sequence_number_length, true); | |
659 } | 640 } |
660 | 641 |
661 base::StringPiece FecProtectedData() const; | 642 base::StringPiece FecProtectedData() const; |
662 base::StringPiece AssociatedData() const; | 643 base::StringPiece AssociatedData() const; |
663 base::StringPiece BeforePlaintext() const; | 644 base::StringPiece BeforePlaintext() const; |
664 base::StringPiece Plaintext() const; | 645 base::StringPiece Plaintext() const; |
665 | 646 |
666 bool is_fec_packet() const { return is_fec_packet_; } | 647 bool is_fec_packet() const { return is_fec_packet_; } |
667 | 648 |
668 bool includes_version() const { return includes_version_; } | 649 bool includes_version() const { return includes_version_; } |
669 | 650 |
670 char* mutable_data() { return buffer_; } | 651 char* mutable_data() { return buffer_; } |
671 | 652 |
672 private: | 653 private: |
673 QuicPacket(char* buffer, | 654 QuicPacket(char* buffer, |
674 size_t length, | 655 size_t length, |
675 bool owns_buffer, | 656 bool owns_buffer, |
676 QuicGuidLength guid_length, | 657 QuicGuidLength guid_length, |
677 bool includes_version, | 658 bool includes_version, |
678 QuicSequenceNumberLength sequence_number_length, | |
679 bool is_fec_packet) | 659 bool is_fec_packet) |
680 : QuicData(buffer, length, owns_buffer), | 660 : QuicData(buffer, length, owns_buffer), |
681 buffer_(buffer), | 661 buffer_(buffer), |
682 is_fec_packet_(is_fec_packet), | 662 is_fec_packet_(is_fec_packet), |
683 guid_length_(guid_length), | 663 guid_length_(guid_length), |
684 includes_version_(includes_version), | 664 includes_version_(includes_version) {} |
685 sequence_number_length_(sequence_number_length) {} | |
686 | 665 |
687 char* buffer_; | 666 char* buffer_; |
688 const bool is_fec_packet_; | 667 const bool is_fec_packet_; |
689 const QuicGuidLength guid_length_; | 668 const QuicGuidLength guid_length_; |
690 const bool includes_version_; | 669 const bool includes_version_; |
691 const QuicSequenceNumberLength sequence_number_length_; | |
692 | 670 |
693 DISALLOW_COPY_AND_ASSIGN(QuicPacket); | 671 DISALLOW_COPY_AND_ASSIGN(QuicPacket); |
694 }; | 672 }; |
695 | 673 |
696 class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData { | 674 class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData { |
697 public: | 675 public: |
698 QuicEncryptedPacket(const char* buffer, size_t length) | 676 QuicEncryptedPacket(const char* buffer, size_t length) |
699 : QuicData(buffer, length) {} | 677 : QuicData(buffer, length) {} |
700 | 678 |
701 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer) | 679 QuicEncryptedPacket(char* buffer, size_t length, bool owns_buffer) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | 748 NET_EXPORT_PRIVATE friend std::ostream& operator<<( |
771 std::ostream& os, const QuicConsumedData& s); | 749 std::ostream& os, const QuicConsumedData& s); |
772 | 750 |
773 size_t bytes_consumed; | 751 size_t bytes_consumed; |
774 bool fin_consumed; | 752 bool fin_consumed; |
775 }; | 753 }; |
776 | 754 |
777 } // namespace net | 755 } // namespace net |
778 | 756 |
779 #endif // NET_QUIC_QUIC_PROTOCOL_H_ | 757 #endif // NET_QUIC_QUIC_PROTOCOL_H_ |
OLD | NEW |