| 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_CORE_QUIC_PACKETS_H_ | 5 #ifndef NET_QUIC_CORE_QUIC_PACKETS_H_ |
| 6 #define NET_QUIC_CORE_QUIC_PACKETS_H_ | 6 #define NET_QUIC_CORE_QUIC_PACKETS_H_ |
| 7 | 7 |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <ostream> | 11 #include <ostream> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <utility> | 13 #include <utility> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 19 #include "base/strings/string_piece.h" | 19 #include "base/strings/string_piece.h" |
| 20 #include "net/base/int128.h" | 20 #include "net/base/int128.h" |
| 21 #include "net/base/iovec.h" | 21 #include "net/base/iovec.h" |
| 22 #include "net/base/net_export.h" | |
| 23 #include "net/quic/core/frames/quic_frame.h" | 22 #include "net/quic/core/frames/quic_frame.h" |
| 24 #include "net/quic/core/quic_ack_listener_interface.h" | 23 #include "net/quic/core/quic_ack_listener_interface.h" |
| 25 #include "net/quic/core/quic_bandwidth.h" | 24 #include "net/quic/core/quic_bandwidth.h" |
| 26 #include "net/quic/core/quic_constants.h" | 25 #include "net/quic/core/quic_constants.h" |
| 27 #include "net/quic/core/quic_error_codes.h" | 26 #include "net/quic/core/quic_error_codes.h" |
| 28 #include "net/quic/core/quic_time.h" | 27 #include "net/quic/core/quic_time.h" |
| 29 #include "net/quic/core/quic_types.h" | 28 #include "net/quic/core/quic_types.h" |
| 30 #include "net/quic/core/quic_versions.h" | 29 #include "net/quic/core/quic_versions.h" |
| 30 #include "net/quic/platform/api/quic_export.h" |
| 31 #include "net/quic/platform/api/quic_socket_address.h" | 31 #include "net/quic/platform/api/quic_socket_address.h" |
| 32 | 32 |
| 33 namespace net { | 33 namespace net { |
| 34 | 34 |
| 35 class QuicPacket; | 35 class QuicPacket; |
| 36 struct QuicPacketHeader; | 36 struct QuicPacketHeader; |
| 37 | 37 |
| 38 // Size in bytes of the data packet header. | 38 // Size in bytes of the data packet header. |
| 39 NET_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicVersion version, | 39 QUIC_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicVersion version, |
| 40 const QuicPacketHeader& header); | 40 const QuicPacketHeader& header); |
| 41 | 41 |
| 42 NET_EXPORT_PRIVATE size_t | 42 QUIC_EXPORT_PRIVATE size_t |
| 43 GetPacketHeaderSize(QuicVersion version, | 43 GetPacketHeaderSize(QuicVersion version, |
| 44 QuicConnectionIdLength connection_id_length, | 44 QuicConnectionIdLength connection_id_length, |
| 45 bool include_version, | 45 bool include_version, |
| 46 bool include_path_id, | 46 bool include_path_id, |
| 47 bool include_diversification_nonce, | 47 bool include_diversification_nonce, |
| 48 QuicPacketNumberLength packet_number_length); | 48 QuicPacketNumberLength packet_number_length); |
| 49 | 49 |
| 50 // Index of the first byte in a QUIC packet of encrypted data. | 50 // Index of the first byte in a QUIC packet of encrypted data. |
| 51 NET_EXPORT_PRIVATE size_t | 51 QUIC_EXPORT_PRIVATE size_t |
| 52 GetStartOfEncryptedData(QuicVersion version, const QuicPacketHeader& header); | 52 GetStartOfEncryptedData(QuicVersion version, const QuicPacketHeader& header); |
| 53 | 53 |
| 54 NET_EXPORT_PRIVATE size_t | 54 QUIC_EXPORT_PRIVATE size_t |
| 55 GetStartOfEncryptedData(QuicVersion version, | 55 GetStartOfEncryptedData(QuicVersion version, |
| 56 QuicConnectionIdLength connection_id_length, | 56 QuicConnectionIdLength connection_id_length, |
| 57 bool include_version, | 57 bool include_version, |
| 58 bool include_path_id, | 58 bool include_path_id, |
| 59 bool include_diversification_nonce, | 59 bool include_diversification_nonce, |
| 60 QuicPacketNumberLength packet_number_length); | 60 QuicPacketNumberLength packet_number_length); |
| 61 | 61 |
| 62 struct NET_EXPORT_PRIVATE QuicPacketPublicHeader { | 62 struct QUIC_EXPORT_PRIVATE QuicPacketPublicHeader { |
| 63 QuicPacketPublicHeader(); | 63 QuicPacketPublicHeader(); |
| 64 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other); | 64 explicit QuicPacketPublicHeader(const QuicPacketPublicHeader& other); |
| 65 ~QuicPacketPublicHeader(); | 65 ~QuicPacketPublicHeader(); |
| 66 | 66 |
| 67 // Universal header. All QuicPacket headers will have a connection_id and | 67 // Universal header. All QuicPacket headers will have a connection_id and |
| 68 // public flags. | 68 // public flags. |
| 69 QuicConnectionId connection_id; | 69 QuicConnectionId connection_id; |
| 70 QuicConnectionIdLength connection_id_length; | 70 QuicConnectionIdLength connection_id_length; |
| 71 bool multipath_flag; | 71 bool multipath_flag; |
| 72 bool reset_flag; | 72 bool reset_flag; |
| 73 bool version_flag; | 73 bool version_flag; |
| 74 QuicPacketNumberLength packet_number_length; | 74 QuicPacketNumberLength packet_number_length; |
| 75 QuicVersionVector versions; | 75 QuicVersionVector versions; |
| 76 // nonce contains an optional, 32-byte nonce value. If not included in the | 76 // nonce contains an optional, 32-byte nonce value. If not included in the |
| 77 // packet, |nonce| will be empty. | 77 // packet, |nonce| will be empty. |
| 78 DiversificationNonce* nonce; | 78 DiversificationNonce* nonce; |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 // Header for Data packets. | 81 // Header for Data packets. |
| 82 struct NET_EXPORT_PRIVATE QuicPacketHeader { | 82 struct QUIC_EXPORT_PRIVATE QuicPacketHeader { |
| 83 QuicPacketHeader(); | 83 QuicPacketHeader(); |
| 84 explicit QuicPacketHeader(const QuicPacketPublicHeader& header); | 84 explicit QuicPacketHeader(const QuicPacketPublicHeader& header); |
| 85 QuicPacketHeader(const QuicPacketHeader& other); | 85 QuicPacketHeader(const QuicPacketHeader& other); |
| 86 | 86 |
| 87 NET_EXPORT_PRIVATE friend std::ostream& operator<<(std::ostream& os, | 87 QUIC_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 88 const QuicPacketHeader& s); | 88 std::ostream& os, |
| 89 const QuicPacketHeader& s); |
| 89 | 90 |
| 90 QuicPacketPublicHeader public_header; | 91 QuicPacketPublicHeader public_header; |
| 91 QuicPacketNumber packet_number; | 92 QuicPacketNumber packet_number; |
| 92 QuicPathId path_id; | 93 QuicPathId path_id; |
| 93 }; | 94 }; |
| 94 | 95 |
| 95 struct NET_EXPORT_PRIVATE QuicPublicResetPacket { | 96 struct QUIC_EXPORT_PRIVATE QuicPublicResetPacket { |
| 96 QuicPublicResetPacket(); | 97 QuicPublicResetPacket(); |
| 97 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header); | 98 explicit QuicPublicResetPacket(const QuicPacketPublicHeader& header); |
| 98 | 99 |
| 99 QuicPacketPublicHeader public_header; | 100 QuicPacketPublicHeader public_header; |
| 100 QuicPublicResetNonceProof nonce_proof; | 101 QuicPublicResetNonceProof nonce_proof; |
| 101 // TODO(fayang): remove rejected_packet_number when deprecating | 102 // TODO(fayang): remove rejected_packet_number when deprecating |
| 102 // FLAGS_quic_remove_packet_number_from_public_reset. | 103 // FLAGS_quic_remove_packet_number_from_public_reset. |
| 103 QuicPacketNumber rejected_packet_number; | 104 QuicPacketNumber rejected_packet_number; |
| 104 QuicSocketAddress client_address; | 105 QuicSocketAddress client_address; |
| 105 }; | 106 }; |
| 106 | 107 |
| 107 typedef QuicPacketPublicHeader QuicVersionNegotiationPacket; | 108 typedef QuicPacketPublicHeader QuicVersionNegotiationPacket; |
| 108 | 109 |
| 109 class NET_EXPORT_PRIVATE QuicData { | 110 class QUIC_EXPORT_PRIVATE QuicData { |
| 110 public: | 111 public: |
| 111 QuicData(const char* buffer, size_t length); | 112 QuicData(const char* buffer, size_t length); |
| 112 QuicData(const char* buffer, size_t length, bool owns_buffer); | 113 QuicData(const char* buffer, size_t length, bool owns_buffer); |
| 113 virtual ~QuicData(); | 114 virtual ~QuicData(); |
| 114 | 115 |
| 115 base::StringPiece AsStringPiece() const { | 116 base::StringPiece AsStringPiece() const { |
| 116 return base::StringPiece(data(), length()); | 117 return base::StringPiece(data(), length()); |
| 117 } | 118 } |
| 118 | 119 |
| 119 const char* data() const { return buffer_; } | 120 const char* data() const { return buffer_; } |
| 120 size_t length() const { return length_; } | 121 size_t length() const { return length_; } |
| 121 | 122 |
| 122 private: | 123 private: |
| 123 const char* buffer_; | 124 const char* buffer_; |
| 124 size_t length_; | 125 size_t length_; |
| 125 bool owns_buffer_; | 126 bool owns_buffer_; |
| 126 | 127 |
| 127 DISALLOW_COPY_AND_ASSIGN(QuicData); | 128 DISALLOW_COPY_AND_ASSIGN(QuicData); |
| 128 }; | 129 }; |
| 129 | 130 |
| 130 class NET_EXPORT_PRIVATE QuicPacket : public QuicData { | 131 class QUIC_EXPORT_PRIVATE QuicPacket : public QuicData { |
| 131 public: | 132 public: |
| 132 // TODO(fayang): 4 fields from public header are passed in as arguments. | 133 // TODO(fayang): 4 fields from public header are passed in as arguments. |
| 133 // Consider to add a convenience method which directly accepts the entire | 134 // Consider to add a convenience method which directly accepts the entire |
| 134 // public header. | 135 // public header. |
| 135 QuicPacket(char* buffer, | 136 QuicPacket(char* buffer, |
| 136 size_t length, | 137 size_t length, |
| 137 bool owns_buffer, | 138 bool owns_buffer, |
| 138 QuicConnectionIdLength connection_id_length, | 139 QuicConnectionIdLength connection_id_length, |
| 139 bool includes_version, | 140 bool includes_version, |
| 140 bool includes_path_id, | 141 bool includes_path_id, |
| 141 bool includes_diversification_nonce, | 142 bool includes_diversification_nonce, |
| 142 QuicPacketNumberLength packet_number_length); | 143 QuicPacketNumberLength packet_number_length); |
| 143 | 144 |
| 144 base::StringPiece AssociatedData(QuicVersion version) const; | 145 base::StringPiece AssociatedData(QuicVersion version) const; |
| 145 base::StringPiece Plaintext(QuicVersion version) const; | 146 base::StringPiece Plaintext(QuicVersion version) const; |
| 146 | 147 |
| 147 char* mutable_data() { return buffer_; } | 148 char* mutable_data() { return buffer_; } |
| 148 | 149 |
| 149 private: | 150 private: |
| 150 char* buffer_; | 151 char* buffer_; |
| 151 const QuicConnectionIdLength connection_id_length_; | 152 const QuicConnectionIdLength connection_id_length_; |
| 152 const bool includes_version_; | 153 const bool includes_version_; |
| 153 const bool includes_path_id_; | 154 const bool includes_path_id_; |
| 154 const bool includes_diversification_nonce_; | 155 const bool includes_diversification_nonce_; |
| 155 const QuicPacketNumberLength packet_number_length_; | 156 const QuicPacketNumberLength packet_number_length_; |
| 156 | 157 |
| 157 DISALLOW_COPY_AND_ASSIGN(QuicPacket); | 158 DISALLOW_COPY_AND_ASSIGN(QuicPacket); |
| 158 }; | 159 }; |
| 159 | 160 |
| 160 class NET_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData { | 161 class QUIC_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData { |
| 161 public: | 162 public: |
| 162 QuicEncryptedPacket(const char* buffer, size_t length); | 163 QuicEncryptedPacket(const char* buffer, size_t length); |
| 163 QuicEncryptedPacket(const char* buffer, size_t length, bool owns_buffer); | 164 QuicEncryptedPacket(const char* buffer, size_t length, bool owns_buffer); |
| 164 | 165 |
| 165 // Clones the packet into a new packet which owns the buffer. | 166 // Clones the packet into a new packet which owns the buffer. |
| 166 std::unique_ptr<QuicEncryptedPacket> Clone() const; | 167 std::unique_ptr<QuicEncryptedPacket> Clone() const; |
| 167 | 168 |
| 168 // By default, gtest prints the raw bytes of an object. The bool data | 169 // By default, gtest prints the raw bytes of an object. The bool data |
| 169 // member (in the base class QuicData) causes this object to have padding | 170 // member (in the base class QuicData) causes this object to have padding |
| 170 // bytes, which causes the default gtest object printer to read | 171 // bytes, which causes the default gtest object printer to read |
| 171 // uninitialize memory. So we need to teach gtest how to print this object. | 172 // uninitialize memory. So we need to teach gtest how to print this object. |
| 172 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | 173 QUIC_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 173 std::ostream& os, | 174 std::ostream& os, |
| 174 const QuicEncryptedPacket& s); | 175 const QuicEncryptedPacket& s); |
| 175 | 176 |
| 176 private: | 177 private: |
| 177 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket); | 178 DISALLOW_COPY_AND_ASSIGN(QuicEncryptedPacket); |
| 178 }; | 179 }; |
| 179 | 180 |
| 180 // A received encrypted QUIC packet, with a recorded time of receipt. | 181 // A received encrypted QUIC packet, with a recorded time of receipt. |
| 181 class NET_EXPORT_PRIVATE QuicReceivedPacket : public QuicEncryptedPacket { | 182 class QUIC_EXPORT_PRIVATE QuicReceivedPacket : public QuicEncryptedPacket { |
| 182 public: | 183 public: |
| 183 QuicReceivedPacket(const char* buffer, size_t length, QuicTime receipt_time); | 184 QuicReceivedPacket(const char* buffer, size_t length, QuicTime receipt_time); |
| 184 QuicReceivedPacket(const char* buffer, | 185 QuicReceivedPacket(const char* buffer, |
| 185 size_t length, | 186 size_t length, |
| 186 QuicTime receipt_time, | 187 QuicTime receipt_time, |
| 187 bool owns_buffer); | 188 bool owns_buffer); |
| 188 QuicReceivedPacket(const char* buffer, | 189 QuicReceivedPacket(const char* buffer, |
| 189 size_t length, | 190 size_t length, |
| 190 QuicTime receipt_time, | 191 QuicTime receipt_time, |
| 191 bool owns_buffer, | 192 bool owns_buffer, |
| 192 int ttl, | 193 int ttl, |
| 193 bool ttl_valid); | 194 bool ttl_valid); |
| 194 | 195 |
| 195 // Clones the packet into a new packet which owns the buffer. | 196 // Clones the packet into a new packet which owns the buffer. |
| 196 std::unique_ptr<QuicReceivedPacket> Clone() const; | 197 std::unique_ptr<QuicReceivedPacket> Clone() const; |
| 197 | 198 |
| 198 // Returns the time at which the packet was received. | 199 // Returns the time at which the packet was received. |
| 199 QuicTime receipt_time() const { return receipt_time_; } | 200 QuicTime receipt_time() const { return receipt_time_; } |
| 200 | 201 |
| 201 // This is the TTL of the packet, assuming ttl_vaild_ is true. | 202 // This is the TTL of the packet, assuming ttl_vaild_ is true. |
| 202 int ttl() const { return ttl_; } | 203 int ttl() const { return ttl_; } |
| 203 | 204 |
| 204 // By default, gtest prints the raw bytes of an object. The bool data | 205 // By default, gtest prints the raw bytes of an object. The bool data |
| 205 // member (in the base class QuicData) causes this object to have padding | 206 // member (in the base class QuicData) causes this object to have padding |
| 206 // bytes, which causes the default gtest object printer to read | 207 // bytes, which causes the default gtest object printer to read |
| 207 // uninitialize memory. So we need to teach gtest how to print this object. | 208 // uninitialize memory. So we need to teach gtest how to print this object. |
| 208 NET_EXPORT_PRIVATE friend std::ostream& operator<<( | 209 QUIC_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 209 std::ostream& os, | 210 std::ostream& os, |
| 210 const QuicReceivedPacket& s); | 211 const QuicReceivedPacket& s); |
| 211 | 212 |
| 212 private: | 213 private: |
| 213 const QuicTime receipt_time_; | 214 const QuicTime receipt_time_; |
| 214 int ttl_; | 215 int ttl_; |
| 215 | 216 |
| 216 DISALLOW_COPY_AND_ASSIGN(QuicReceivedPacket); | 217 DISALLOW_COPY_AND_ASSIGN(QuicReceivedPacket); |
| 217 }; | 218 }; |
| 218 | 219 |
| 219 struct NET_EXPORT_PRIVATE SerializedPacket { | 220 struct QUIC_EXPORT_PRIVATE SerializedPacket { |
| 220 SerializedPacket(QuicPathId path_id, | 221 SerializedPacket(QuicPathId path_id, |
| 221 QuicPacketNumber packet_number, | 222 QuicPacketNumber packet_number, |
| 222 QuicPacketNumberLength packet_number_length, | 223 QuicPacketNumberLength packet_number_length, |
| 223 const char* encrypted_buffer, | 224 const char* encrypted_buffer, |
| 224 QuicPacketLength encrypted_length, | 225 QuicPacketLength encrypted_length, |
| 225 bool has_ack, | 226 bool has_ack, |
| 226 bool has_stop_waiting); | 227 bool has_stop_waiting); |
| 227 SerializedPacket(const SerializedPacket& other); | 228 SerializedPacket(const SerializedPacket& other); |
| 228 ~SerializedPacket(); | 229 ~SerializedPacket(); |
| 229 | 230 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 244 bool has_stop_waiting; | 245 bool has_stop_waiting; |
| 245 TransmissionType transmission_type; | 246 TransmissionType transmission_type; |
| 246 QuicPathId original_path_id; | 247 QuicPathId original_path_id; |
| 247 QuicPacketNumber original_packet_number; | 248 QuicPacketNumber original_packet_number; |
| 248 | 249 |
| 249 // Optional notifiers which will be informed when this packet has been ACKed. | 250 // Optional notifiers which will be informed when this packet has been ACKed. |
| 250 std::list<AckListenerWrapper> listeners; | 251 std::list<AckListenerWrapper> listeners; |
| 251 }; | 252 }; |
| 252 | 253 |
| 253 // Deletes and clears all the frames and the packet from serialized packet. | 254 // Deletes and clears all the frames and the packet from serialized packet. |
| 254 NET_EXPORT_PRIVATE void ClearSerializedPacket( | 255 QUIC_EXPORT_PRIVATE void ClearSerializedPacket( |
| 255 SerializedPacket* serialized_packet); | 256 SerializedPacket* serialized_packet); |
| 256 | 257 |
| 257 // Allocates a new char[] of size |packet.encrypted_length| and copies in | 258 // Allocates a new char[] of size |packet.encrypted_length| and copies in |
| 258 // |packet.encrypted_buffer|. | 259 // |packet.encrypted_buffer|. |
| 259 NET_EXPORT_PRIVATE char* CopyBuffer(const SerializedPacket& packet); | 260 QUIC_EXPORT_PRIVATE char* CopyBuffer(const SerializedPacket& packet); |
| 260 | 261 |
| 261 } // namespace net | 262 } // namespace net |
| 262 | 263 |
| 263 #endif // NET_QUIC_CORE_QUIC_PACKETS_H_ | 264 #endif // NET_QUIC_CORE_QUIC_PACKETS_H_ |
| OLD | NEW |