| 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 "net/quic/quic_flags.h" | 8 #include "net/quic/quic_flags.h" |
| 9 #include "net/quic/quic_utils.h" | 9 #include "net/quic/quic_utils.h" |
| 10 | 10 |
| 11 using base::StringPiece; | 11 using base::StringPiece; |
| 12 using std::map; | 12 using std::map; |
| 13 using std::numeric_limits; | 13 using std::numeric_limits; |
| 14 using std::ostream; | 14 using std::ostream; |
| 15 using std::string; | 15 using std::string; |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 const char* const kFinalOffsetHeaderKey = ":final-offset"; | 19 const char* const kFinalOffsetHeaderKey = ":final-offset"; |
| 20 | 20 |
| 21 size_t GetPacketHeaderSize(const QuicPacketHeader& header) { | 21 size_t GetPacketHeaderSize(const QuicPacketHeader& header) { |
| 22 return GetPacketHeaderSize( | 22 return GetPacketHeaderSize(header.public_header.connection_id_length, |
| 23 header.public_header.connection_id_length, | 23 header.public_header.version_flag, |
| 24 header.public_header.version_flag, header.public_header.multipath_flag, | 24 header.public_header.multipath_flag, |
| 25 header.public_header.packet_number_length, header.is_in_fec_group); | 25 header.public_header.packet_number_length); |
| 26 } | 26 } |
| 27 | 27 |
| 28 size_t GetPacketHeaderSize(QuicConnectionIdLength connection_id_length, | 28 size_t GetPacketHeaderSize(QuicConnectionIdLength connection_id_length, |
| 29 bool include_version, | 29 bool include_version, |
| 30 bool include_path_id, | 30 bool include_path_id, |
| 31 QuicPacketNumberLength packet_number_length, | 31 QuicPacketNumberLength packet_number_length) { |
| 32 InFecGroup is_in_fec_group) { | |
| 33 return kPublicFlagsSize + connection_id_length + | 32 return kPublicFlagsSize + connection_id_length + |
| 34 (include_version ? kQuicVersionSize : 0) + | 33 (include_version ? kQuicVersionSize : 0) + |
| 35 (include_path_id ? kQuicPathIdSize : 0) + packet_number_length + | 34 (include_path_id ? kQuicPathIdSize : 0) + packet_number_length + |
| 36 kPrivateFlagsSize + | 35 kPrivateFlagsSize; |
| 37 (is_in_fec_group == IN_FEC_GROUP ? kFecGroupSize : 0); | |
| 38 } | |
| 39 | |
| 40 size_t GetStartOfFecProtectedData(QuicConnectionIdLength connection_id_length, | |
| 41 bool include_version, | |
| 42 bool include_path_id, | |
| 43 QuicPacketNumberLength packet_number_length) { | |
| 44 return GetPacketHeaderSize(connection_id_length, include_version, | |
| 45 include_path_id, packet_number_length, | |
| 46 IN_FEC_GROUP); | |
| 47 } | 36 } |
| 48 | 37 |
| 49 size_t GetStartOfEncryptedData(QuicConnectionIdLength connection_id_length, | 38 size_t GetStartOfEncryptedData(QuicConnectionIdLength connection_id_length, |
| 50 bool include_version, | 39 bool include_version, |
| 51 bool include_path_id, | 40 bool include_path_id, |
| 52 QuicPacketNumberLength packet_number_length) { | 41 QuicPacketNumberLength packet_number_length) { |
| 53 // Don't include the fec size, since encryption starts before private flags. | 42 // Don't include the fec size, since encryption starts before private flags. |
| 54 return GetPacketHeaderSize(connection_id_length, include_version, | 43 return GetPacketHeaderSize(connection_id_length, include_version, |
| 55 include_path_id, packet_number_length, | 44 include_path_id, packet_number_length) - |
| 56 NOT_IN_FEC_GROUP) - | |
| 57 kPrivateFlagsSize; | 45 kPrivateFlagsSize; |
| 58 } | 46 } |
| 59 | 47 |
| 60 QuicPacketPublicHeader::QuicPacketPublicHeader() | 48 QuicPacketPublicHeader::QuicPacketPublicHeader() |
| 61 : connection_id(0), | 49 : connection_id(0), |
| 62 connection_id_length(PACKET_8BYTE_CONNECTION_ID), | 50 connection_id_length(PACKET_8BYTE_CONNECTION_ID), |
| 63 multipath_flag(false), | 51 multipath_flag(false), |
| 64 reset_flag(false), | 52 reset_flag(false), |
| 65 version_flag(false), | 53 version_flag(false), |
| 66 packet_number_length(PACKET_6BYTE_PACKET_NUMBER) {} | 54 packet_number_length(PACKET_6BYTE_PACKET_NUMBER) {} |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 packet_number_length_(packet_number_length) {} | 683 packet_number_length_(packet_number_length) {} |
| 696 | 684 |
| 697 QuicEncryptedPacket::QuicEncryptedPacket(const char* buffer, size_t length) | 685 QuicEncryptedPacket::QuicEncryptedPacket(const char* buffer, size_t length) |
| 698 : QuicData(buffer, length) {} | 686 : QuicData(buffer, length) {} |
| 699 | 687 |
| 700 QuicEncryptedPacket::QuicEncryptedPacket(char* buffer, | 688 QuicEncryptedPacket::QuicEncryptedPacket(char* buffer, |
| 701 size_t length, | 689 size_t length, |
| 702 bool owns_buffer) | 690 bool owns_buffer) |
| 703 : QuicData(buffer, length, owns_buffer) {} | 691 : QuicData(buffer, length, owns_buffer) {} |
| 704 | 692 |
| 705 StringPiece QuicPacket::FecProtectedData() const { | |
| 706 const size_t start_of_fec = | |
| 707 GetStartOfFecProtectedData(connection_id_length_, includes_version_, | |
| 708 includes_path_id_, packet_number_length_); | |
| 709 return StringPiece(data() + start_of_fec, length() - start_of_fec); | |
| 710 } | |
| 711 | |
| 712 StringPiece QuicPacket::AssociatedData() const { | 693 StringPiece QuicPacket::AssociatedData() const { |
| 713 return StringPiece(data(), GetStartOfEncryptedData( | 694 return StringPiece(data(), GetStartOfEncryptedData( |
| 714 connection_id_length_, includes_version_, | 695 connection_id_length_, includes_version_, |
| 715 includes_path_id_, packet_number_length_)); | 696 includes_path_id_, packet_number_length_)); |
| 716 } | 697 } |
| 717 | 698 |
| 718 StringPiece QuicPacket::Plaintext() const { | 699 StringPiece QuicPacket::Plaintext() const { |
| 719 const size_t start_of_encrypted_data = | 700 const size_t start_of_encrypted_data = |
| 720 GetStartOfEncryptedData(connection_id_length_, includes_version_, | 701 GetStartOfEncryptedData(connection_id_length_, includes_version_, |
| 721 includes_path_id_, packet_number_length_); | 702 includes_path_id_, packet_number_length_); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 is_fec_packet(is_fec_packet), | 786 is_fec_packet(is_fec_packet), |
| 806 has_crypto_handshake(has_crypto_handshake), | 787 has_crypto_handshake(has_crypto_handshake), |
| 807 needs_padding(needs_padding), | 788 needs_padding(needs_padding), |
| 808 retransmission(0) {} | 789 retransmission(0) {} |
| 809 | 790 |
| 810 TransmissionInfo::TransmissionInfo(const TransmissionInfo& other) = default; | 791 TransmissionInfo::TransmissionInfo(const TransmissionInfo& other) = default; |
| 811 | 792 |
| 812 TransmissionInfo::~TransmissionInfo() {} | 793 TransmissionInfo::~TransmissionInfo() {} |
| 813 | 794 |
| 814 } // namespace net | 795 } // namespace net |
| OLD | NEW |