| 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 #include "net/quic/quic_protocol.h" | 5 #include "net/quic/quic_protocol.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "base/strings/string_number_conversions.h" |
| 8 #include "net/quic/quic_flags.h" | 9 #include "net/quic/quic_flags.h" |
| 9 #include "net/quic/quic_utils.h" | 10 #include "net/quic/quic_utils.h" |
| 10 | 11 |
| 11 using base::StringPiece; | 12 using base::StringPiece; |
| 12 using std::map; | 13 using std::map; |
| 13 using std::numeric_limits; | 14 using std::numeric_limits; |
| 14 using std::ostream; | 15 using std::ostream; |
| 15 using std::string; | 16 using std::string; |
| 16 | 17 |
| 17 namespace net { | 18 namespace net { |
| 18 | 19 |
| 19 const char* const kFinalOffsetHeaderKey = ":final-offset"; | 20 const char* const kFinalOffsetHeaderKey = ":final-offset"; |
| 20 | 21 |
| 21 size_t GetPacketHeaderSize(const QuicPacketHeader& header) { | 22 size_t GetPacketHeaderSize(const QuicPacketHeader& header) { |
| 22 return GetPacketHeaderSize(header.public_header.connection_id_length, | 23 return GetPacketHeaderSize(header.public_header.connection_id_length, |
| 23 header.public_header.version_flag, | 24 header.public_header.version_flag, |
| 24 header.public_header.multipath_flag, | 25 header.public_header.multipath_flag, |
| 26 header.public_header.nonce != nullptr, |
| 25 header.public_header.packet_number_length); | 27 header.public_header.packet_number_length); |
| 26 } | 28 } |
| 27 | 29 |
| 28 size_t GetPacketHeaderSize(QuicConnectionIdLength connection_id_length, | 30 size_t GetPacketHeaderSize(QuicConnectionIdLength connection_id_length, |
| 29 bool include_version, | 31 bool include_version, |
| 30 bool include_path_id, | 32 bool include_path_id, |
| 33 bool include_diversification_nonce, |
| 31 QuicPacketNumberLength packet_number_length) { | 34 QuicPacketNumberLength packet_number_length) { |
| 32 return kPublicFlagsSize + connection_id_length + | 35 return kPublicFlagsSize + connection_id_length + |
| 33 (include_version ? kQuicVersionSize : 0) + | 36 (include_version ? kQuicVersionSize : 0) + |
| 34 (include_path_id ? kQuicPathIdSize : 0) + packet_number_length + | 37 (include_path_id ? kQuicPathIdSize : 0) + packet_number_length + |
| 38 (include_diversification_nonce ? kDiversificationNonceSize : 0) + |
| 35 kPrivateFlagsSize; | 39 kPrivateFlagsSize; |
| 36 } | 40 } |
| 37 | 41 |
| 38 size_t GetStartOfEncryptedData(const QuicPacketHeader& header) { | 42 size_t GetStartOfEncryptedData(const QuicPacketHeader& header) { |
| 39 return GetPacketHeaderSize(header) - kPrivateFlagsSize; | 43 return GetPacketHeaderSize(header) - kPrivateFlagsSize; |
| 40 } | 44 } |
| 41 | 45 |
| 42 size_t GetStartOfEncryptedData(QuicConnectionIdLength connection_id_length, | 46 size_t GetStartOfEncryptedData(QuicConnectionIdLength connection_id_length, |
| 43 bool include_version, | 47 bool include_version, |
| 44 bool include_path_id, | 48 bool include_path_id, |
| 49 bool include_diversification_nonce, |
| 45 QuicPacketNumberLength packet_number_length) { | 50 QuicPacketNumberLength packet_number_length) { |
| 46 // Encryption starts before private flags. | 51 // Encryption starts before private flags. |
| 47 return GetPacketHeaderSize(connection_id_length, include_version, | 52 return GetPacketHeaderSize(connection_id_length, include_version, |
| 48 include_path_id, packet_number_length) - | 53 include_path_id, include_diversification_nonce, |
| 54 packet_number_length) - |
| 49 kPrivateFlagsSize; | 55 kPrivateFlagsSize; |
| 50 } | 56 } |
| 51 | 57 |
| 52 QuicPacketPublicHeader::QuicPacketPublicHeader() | 58 QuicPacketPublicHeader::QuicPacketPublicHeader() |
| 53 : connection_id(0), | 59 : connection_id(0), |
| 54 connection_id_length(PACKET_8BYTE_CONNECTION_ID), | 60 connection_id_length(PACKET_8BYTE_CONNECTION_ID), |
| 55 multipath_flag(false), | 61 multipath_flag(false), |
| 56 reset_flag(false), | 62 reset_flag(false), |
| 57 version_flag(false), | 63 version_flag(false), |
| 58 packet_number_length(PACKET_6BYTE_PACKET_NUMBER) {} | 64 packet_number_length(PACKET_6BYTE_PACKET_NUMBER), |
| 65 nonce(nullptr) {} |
| 59 | 66 |
| 60 QuicPacketPublicHeader::QuicPacketPublicHeader( | 67 QuicPacketPublicHeader::QuicPacketPublicHeader( |
| 61 const QuicPacketPublicHeader& other) | 68 const QuicPacketPublicHeader& other) = default; |
| 62 : connection_id(other.connection_id), | |
| 63 connection_id_length(other.connection_id_length), | |
| 64 multipath_flag(other.multipath_flag), | |
| 65 reset_flag(other.reset_flag), | |
| 66 version_flag(other.version_flag), | |
| 67 packet_number_length(other.packet_number_length), | |
| 68 versions(other.versions) {} | |
| 69 | 69 |
| 70 QuicPacketPublicHeader::~QuicPacketPublicHeader() {} | 70 QuicPacketPublicHeader::~QuicPacketPublicHeader() {} |
| 71 | 71 |
| 72 QuicPacketHeader::QuicPacketHeader() | 72 QuicPacketHeader::QuicPacketHeader() |
| 73 : packet_number(0), | 73 : packet_number(0), |
| 74 path_id(kDefaultPathId), | 74 path_id(kDefaultPathId), |
| 75 entropy_flag(false), | 75 entropy_flag(false), |
| 76 entropy_hash(0), | 76 entropy_hash(0), |
| 77 fec_flag(false), | 77 fec_flag(false), |
| 78 is_in_fec_group(NOT_IN_FEC_GROUP), | 78 is_in_fec_group(NOT_IN_FEC_GROUP), |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 case QUIC_VERSION_28: | 189 case QUIC_VERSION_28: |
| 190 return MakeQuicTag('Q', '0', '2', '8'); | 190 return MakeQuicTag('Q', '0', '2', '8'); |
| 191 case QUIC_VERSION_29: | 191 case QUIC_VERSION_29: |
| 192 return MakeQuicTag('Q', '0', '2', '9'); | 192 return MakeQuicTag('Q', '0', '2', '9'); |
| 193 case QUIC_VERSION_30: | 193 case QUIC_VERSION_30: |
| 194 return MakeQuicTag('Q', '0', '3', '0'); | 194 return MakeQuicTag('Q', '0', '3', '0'); |
| 195 case QUIC_VERSION_31: | 195 case QUIC_VERSION_31: |
| 196 return MakeQuicTag('Q', '0', '3', '1'); | 196 return MakeQuicTag('Q', '0', '3', '1'); |
| 197 case QUIC_VERSION_32: | 197 case QUIC_VERSION_32: |
| 198 return MakeQuicTag('Q', '0', '3', '2'); | 198 return MakeQuicTag('Q', '0', '3', '2'); |
| 199 case QUIC_VERSION_33: |
| 200 return MakeQuicTag('Q', '0', '3', '3'); |
| 199 default: | 201 default: |
| 200 // This shold be an ERROR because we should never attempt to convert an | 202 // This shold be an ERROR because we should never attempt to convert an |
| 201 // invalid QuicVersion to be written to the wire. | 203 // invalid QuicVersion to be written to the wire. |
| 202 LOG(ERROR) << "Unsupported QuicVersion: " << version; | 204 LOG(ERROR) << "Unsupported QuicVersion: " << version; |
| 203 return 0; | 205 return 0; |
| 204 } | 206 } |
| 205 } | 207 } |
| 206 | 208 |
| 207 QuicVersion QuicTagToQuicVersion(const QuicTag version_tag) { | 209 QuicVersion QuicTagToQuicVersion(const QuicTag version_tag) { |
| 208 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { | 210 for (size_t i = 0; i < arraysize(kSupportedQuicVersions); ++i) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 223 string QuicVersionToString(const QuicVersion version) { | 225 string QuicVersionToString(const QuicVersion version) { |
| 224 switch (version) { | 226 switch (version) { |
| 225 RETURN_STRING_LITERAL(QUIC_VERSION_25); | 227 RETURN_STRING_LITERAL(QUIC_VERSION_25); |
| 226 RETURN_STRING_LITERAL(QUIC_VERSION_26); | 228 RETURN_STRING_LITERAL(QUIC_VERSION_26); |
| 227 RETURN_STRING_LITERAL(QUIC_VERSION_27); | 229 RETURN_STRING_LITERAL(QUIC_VERSION_27); |
| 228 RETURN_STRING_LITERAL(QUIC_VERSION_28); | 230 RETURN_STRING_LITERAL(QUIC_VERSION_28); |
| 229 RETURN_STRING_LITERAL(QUIC_VERSION_29); | 231 RETURN_STRING_LITERAL(QUIC_VERSION_29); |
| 230 RETURN_STRING_LITERAL(QUIC_VERSION_30); | 232 RETURN_STRING_LITERAL(QUIC_VERSION_30); |
| 231 RETURN_STRING_LITERAL(QUIC_VERSION_31); | 233 RETURN_STRING_LITERAL(QUIC_VERSION_31); |
| 232 RETURN_STRING_LITERAL(QUIC_VERSION_32); | 234 RETURN_STRING_LITERAL(QUIC_VERSION_32); |
| 235 RETURN_STRING_LITERAL(QUIC_VERSION_33); |
| 233 default: | 236 default: |
| 234 return "QUIC_VERSION_UNSUPPORTED"; | 237 return "QUIC_VERSION_UNSUPPORTED"; |
| 235 } | 238 } |
| 236 } | 239 } |
| 237 | 240 |
| 238 string QuicVersionVectorToString(const QuicVersionVector& versions) { | 241 string QuicVersionVectorToString(const QuicVersionVector& versions) { |
| 239 string result = ""; | 242 string result = ""; |
| 240 for (size_t i = 0; i < versions.size(); ++i) { | 243 for (size_t i = 0; i < versions.size(); ++i) { |
| 241 if (i != 0) { | 244 if (i != 0) { |
| 242 result.append(","); | 245 result.append(","); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 261 << ", packet_number_length:" << header.public_header.packet_number_length | 264 << ", packet_number_length:" << header.public_header.packet_number_length |
| 262 << ", multipath_flag: " << header.public_header.multipath_flag | 265 << ", multipath_flag: " << header.public_header.multipath_flag |
| 263 << ", reset_flag: " << header.public_header.reset_flag | 266 << ", reset_flag: " << header.public_header.reset_flag |
| 264 << ", version_flag: " << header.public_header.version_flag; | 267 << ", version_flag: " << header.public_header.version_flag; |
| 265 if (header.public_header.version_flag) { | 268 if (header.public_header.version_flag) { |
| 266 os << " version: "; | 269 os << " version: "; |
| 267 for (size_t i = 0; i < header.public_header.versions.size(); ++i) { | 270 for (size_t i = 0; i < header.public_header.versions.size(); ++i) { |
| 268 os << header.public_header.versions[i] << " "; | 271 os << header.public_header.versions[i] << " "; |
| 269 } | 272 } |
| 270 } | 273 } |
| 274 os << ", diversification_nonce: " |
| 275 << (header.public_header.nonce == nullptr |
| 276 ? "none" |
| 277 : "0x" + base::HexEncode(*header.public_header.nonce, |
| 278 kDiversificationNonceSize)); |
| 271 os << ", fec_flag: " << header.fec_flag | 279 os << ", fec_flag: " << header.fec_flag |
| 272 << ", entropy_flag: " << header.entropy_flag | 280 << ", entropy_flag: " << header.entropy_flag |
| 273 << ", entropy hash: " << static_cast<int>(header.entropy_hash) | 281 << ", entropy hash: " << static_cast<int>(header.entropy_hash) |
| 274 << ", path_id: " << header.path_id | 282 << ", path_id: " << header.path_id |
| 275 << ", packet_number: " << header.packet_number | 283 << ", packet_number: " << header.packet_number |
| 276 << ", is_in_fec_group:" << header.is_in_fec_group | 284 << ", is_in_fec_group:" << header.is_in_fec_group |
| 277 << ", fec_group: " << header.fec_group << "}\n"; | 285 << ", fec_group: " << header.fec_group << "}\n"; |
| 278 return os; | 286 return os; |
| 279 } | 287 } |
| 280 | 288 |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 : stream_id(stream_id) {} | 683 : stream_id(stream_id) {} |
| 676 | 684 |
| 677 QuicPathCloseFrame::QuicPathCloseFrame(QuicPathId path_id) : path_id(path_id) {} | 685 QuicPathCloseFrame::QuicPathCloseFrame(QuicPathId path_id) : path_id(path_id) {} |
| 678 | 686 |
| 679 QuicPacket::QuicPacket(char* buffer, | 687 QuicPacket::QuicPacket(char* buffer, |
| 680 size_t length, | 688 size_t length, |
| 681 bool owns_buffer, | 689 bool owns_buffer, |
| 682 QuicConnectionIdLength connection_id_length, | 690 QuicConnectionIdLength connection_id_length, |
| 683 bool includes_version, | 691 bool includes_version, |
| 684 bool includes_path_id, | 692 bool includes_path_id, |
| 693 bool includes_diversification_nonce, |
| 685 QuicPacketNumberLength packet_number_length) | 694 QuicPacketNumberLength packet_number_length) |
| 686 : QuicData(buffer, length, owns_buffer), | 695 : QuicData(buffer, length, owns_buffer), |
| 687 buffer_(buffer), | 696 buffer_(buffer), |
| 688 connection_id_length_(connection_id_length), | 697 connection_id_length_(connection_id_length), |
| 689 includes_version_(includes_version), | 698 includes_version_(includes_version), |
| 690 includes_path_id_(includes_path_id), | 699 includes_path_id_(includes_path_id), |
| 700 includes_diversification_nonce_(includes_diversification_nonce), |
| 691 packet_number_length_(packet_number_length) {} | 701 packet_number_length_(packet_number_length) {} |
| 692 | 702 |
| 693 QuicEncryptedPacket::QuicEncryptedPacket(const char* buffer, size_t length) | 703 QuicEncryptedPacket::QuicEncryptedPacket(const char* buffer, size_t length) |
| 694 : QuicData(buffer, length) {} | 704 : QuicData(buffer, length) {} |
| 695 | 705 |
| 696 QuicEncryptedPacket::QuicEncryptedPacket(char* buffer, | 706 QuicEncryptedPacket::QuicEncryptedPacket(char* buffer, |
| 697 size_t length, | 707 size_t length, |
| 698 bool owns_buffer) | 708 bool owns_buffer) |
| 699 : QuicData(buffer, length, owns_buffer) {} | 709 : QuicData(buffer, length, owns_buffer) {} |
| 700 | 710 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 726 memcpy(buffer, this->data(), this->length()); | 736 memcpy(buffer, this->data(), this->length()); |
| 727 return new QuicReceivedPacket(buffer, this->length(), receipt_time(), true); | 737 return new QuicReceivedPacket(buffer, this->length(), receipt_time(), true); |
| 728 } | 738 } |
| 729 | 739 |
| 730 ostream& operator<<(ostream& os, const QuicReceivedPacket& s) { | 740 ostream& operator<<(ostream& os, const QuicReceivedPacket& s) { |
| 731 os << s.length() << "-byte data"; | 741 os << s.length() << "-byte data"; |
| 732 return os; | 742 return os; |
| 733 } | 743 } |
| 734 | 744 |
| 735 StringPiece QuicPacket::AssociatedData() const { | 745 StringPiece QuicPacket::AssociatedData() const { |
| 736 return StringPiece(data(), GetStartOfEncryptedData( | 746 return StringPiece( |
| 737 connection_id_length_, includes_version_, | 747 data(), GetStartOfEncryptedData( |
| 738 includes_path_id_, packet_number_length_)); | 748 connection_id_length_, includes_version_, includes_path_id_, |
| 749 includes_diversification_nonce_, packet_number_length_)); |
| 739 } | 750 } |
| 740 | 751 |
| 741 StringPiece QuicPacket::Plaintext() const { | 752 StringPiece QuicPacket::Plaintext() const { |
| 742 const size_t start_of_encrypted_data = | 753 const size_t start_of_encrypted_data = GetStartOfEncryptedData( |
| 743 GetStartOfEncryptedData(connection_id_length_, includes_version_, | 754 connection_id_length_, includes_version_, includes_path_id_, |
| 744 includes_path_id_, packet_number_length_); | 755 includes_diversification_nonce_, packet_number_length_); |
| 745 return StringPiece(data() + start_of_encrypted_data, | 756 return StringPiece(data() + start_of_encrypted_data, |
| 746 length() - start_of_encrypted_data); | 757 length() - start_of_encrypted_data); |
| 747 } | 758 } |
| 748 | 759 |
| 749 AckListenerWrapper::AckListenerWrapper(QuicAckListenerInterface* listener, | 760 AckListenerWrapper::AckListenerWrapper(QuicAckListenerInterface* listener, |
| 750 QuicPacketLength data_length) | 761 QuicPacketLength data_length) |
| 751 : ack_listener(listener), length(data_length) { | 762 : ack_listener(listener), length(data_length) { |
| 752 DCHECK(listener != nullptr); | 763 DCHECK(listener != nullptr); |
| 753 } | 764 } |
| 754 | 765 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 is_unackable(false), | 824 is_unackable(false), |
| 814 has_crypto_handshake(has_crypto_handshake), | 825 has_crypto_handshake(has_crypto_handshake), |
| 815 needs_padding(needs_padding), | 826 needs_padding(needs_padding), |
| 816 retransmission(0) {} | 827 retransmission(0) {} |
| 817 | 828 |
| 818 TransmissionInfo::TransmissionInfo(const TransmissionInfo& other) = default; | 829 TransmissionInfo::TransmissionInfo(const TransmissionInfo& other) = default; |
| 819 | 830 |
| 820 TransmissionInfo::~TransmissionInfo() {} | 831 TransmissionInfo::~TransmissionInfo() {} |
| 821 | 832 |
| 822 } // namespace net | 833 } // namespace net |
| OLD | NEW |