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