QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef QUICHE_QUIC_CORE_QUIC_PACKETS_H_ |
| 6 | #define QUICHE_QUIC_CORE_QUIC_PACKETS_H_ |
| 7 | |
| 8 | #include <cstddef> |
| 9 | #include <cstdint> |
| 10 | #include <limits> |
| 11 | #include <list> |
| 12 | #include <memory> |
| 13 | #include <ostream> |
| 14 | #include <utility> |
| 15 | #include <vector> |
| 16 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 17 | #include "net/third_party/quiche/src/quic/core/frames/quic_frame.h" |
| 18 | #include "net/third_party/quiche/src/quic/core/quic_ack_listener_interface.h" |
| 19 | #include "net/third_party/quiche/src/quic/core/quic_bandwidth.h" |
| 20 | #include "net/third_party/quiche/src/quic/core/quic_constants.h" |
| 21 | #include "net/third_party/quiche/src/quic/core/quic_error_codes.h" |
| 22 | #include "net/third_party/quiche/src/quic/core/quic_time.h" |
| 23 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
| 24 | #include "net/third_party/quiche/src/quic/core/quic_versions.h" |
| 25 | #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" |
| 26 | #include "net/third_party/quiche/src/quic/platform/api/quic_socket_address.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 27 | #include "net/third_party/quiche/src/quic/platform/api/quic_uint128.h" |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 28 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 29 | |
| 30 | namespace quic { |
| 31 | |
| 32 | class QuicPacket; |
| 33 | struct QuicPacketHeader; |
| 34 | |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 35 | // Returns the destination connection ID of |header| when |perspective| is |
| 36 | // server, and the source connection ID when |perspective| is client. |
| 37 | QUIC_EXPORT_PRIVATE QuicConnectionId |
| 38 | GetServerConnectionIdAsRecipient(const QuicPacketHeader& header, |
| 39 | Perspective perspective); |
| 40 | |
| 41 | // Returns the destination connection ID of |header| when |perspective| is |
| 42 | // client, and the source connection ID when |perspective| is server. |
| 43 | QUIC_EXPORT_PRIVATE QuicConnectionId |
dschinazi | ac6805d | 2019-05-30 09:44:27 -0700 | [diff] [blame] | 44 | GetClientConnectionIdAsRecipient(const QuicPacketHeader& header, |
| 45 | Perspective perspective); |
| 46 | |
| 47 | // Returns the destination connection ID of |header| when |perspective| is |
| 48 | // client, and the source connection ID when |perspective| is server. |
| 49 | QUIC_EXPORT_PRIVATE QuicConnectionId |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 50 | GetServerConnectionIdAsSender(const QuicPacketHeader& header, |
| 51 | Perspective perspective); |
| 52 | |
| 53 | // Returns the destination connection ID included of |header| when |perspective| |
| 54 | // is client, and the source connection ID included when |perspective| is |
| 55 | // server. |
| 56 | QUIC_EXPORT_PRIVATE QuicConnectionIdIncluded |
| 57 | GetServerConnectionIdIncludedAsSender(const QuicPacketHeader& header, |
| 58 | Perspective perspective); |
| 59 | |
dschinazi | ac6805d | 2019-05-30 09:44:27 -0700 | [diff] [blame] | 60 | // Returns the destination connection ID of |header| when |perspective| is |
| 61 | // server, and the source connection ID when |perspective| is client. |
| 62 | QUIC_EXPORT_PRIVATE QuicConnectionId |
| 63 | GetClientConnectionIdAsSender(const QuicPacketHeader& header, |
| 64 | Perspective perspective); |
| 65 | |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 66 | // Returns the destination connection ID included of |header| when |perspective| |
| 67 | // is server, and the source connection ID included when |perspective| is |
| 68 | // client. |
| 69 | QUIC_EXPORT_PRIVATE QuicConnectionIdIncluded |
| 70 | GetClientConnectionIdIncludedAsSender(const QuicPacketHeader& header, |
| 71 | Perspective perspective); |
| 72 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 73 | // Number of connection ID bytes that are actually included over the wire. |
| 74 | QUIC_EXPORT_PRIVATE QuicConnectionIdLength |
| 75 | GetIncludedConnectionIdLength(QuicConnectionId connection_id, |
| 76 | QuicConnectionIdIncluded connection_id_included); |
| 77 | |
| 78 | // Number of destination connection ID bytes that are actually included over the |
| 79 | // wire for this particular header. |
| 80 | QUIC_EXPORT_PRIVATE QuicConnectionIdLength |
| 81 | GetIncludedDestinationConnectionIdLength(const QuicPacketHeader& header); |
| 82 | |
| 83 | // Number of source connection ID bytes that are actually included over the |
| 84 | // wire for this particular header. |
| 85 | QUIC_EXPORT_PRIVATE QuicConnectionIdLength |
| 86 | GetIncludedSourceConnectionIdLength(const QuicPacketHeader& header); |
| 87 | |
| 88 | // Size in bytes of the data packet header. |
| 89 | QUIC_EXPORT_PRIVATE size_t GetPacketHeaderSize(QuicTransportVersion version, |
| 90 | const QuicPacketHeader& header); |
| 91 | |
| 92 | QUIC_EXPORT_PRIVATE size_t |
| 93 | GetPacketHeaderSize(QuicTransportVersion version, |
| 94 | QuicConnectionIdLength destination_connection_id_length, |
| 95 | QuicConnectionIdLength source_connection_id_length, |
| 96 | bool include_version, |
| 97 | bool include_diversification_nonce, |
| 98 | QuicPacketNumberLength packet_number_length, |
| 99 | QuicVariableLengthIntegerLength retry_token_length_length, |
| 100 | QuicByteCount retry_token_length, |
| 101 | QuicVariableLengthIntegerLength length_length); |
| 102 | |
| 103 | // Index of the first byte in a QUIC packet of encrypted data. |
| 104 | QUIC_EXPORT_PRIVATE size_t |
| 105 | GetStartOfEncryptedData(QuicTransportVersion version, |
| 106 | const QuicPacketHeader& header); |
| 107 | |
| 108 | QUIC_EXPORT_PRIVATE size_t GetStartOfEncryptedData( |
| 109 | QuicTransportVersion version, |
| 110 | QuicConnectionIdLength destination_connection_id_length, |
| 111 | QuicConnectionIdLength source_connection_id_length, |
| 112 | bool include_version, |
| 113 | bool include_diversification_nonce, |
| 114 | QuicPacketNumberLength packet_number_length, |
| 115 | QuicVariableLengthIntegerLength retry_token_length_length, |
| 116 | QuicByteCount retry_token_length, |
| 117 | QuicVariableLengthIntegerLength length_length); |
| 118 | |
| 119 | struct QUIC_EXPORT_PRIVATE QuicPacketHeader { |
| 120 | QuicPacketHeader(); |
| 121 | QuicPacketHeader(const QuicPacketHeader& other); |
| 122 | ~QuicPacketHeader(); |
| 123 | |
danzh | ddf023a | 2019-12-20 13:33:36 -0800 | [diff] [blame] | 124 | QuicPacketHeader& operator=(const QuicPacketHeader& other); |
| 125 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 126 | QUIC_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 127 | std::ostream& os, |
| 128 | const QuicPacketHeader& header); |
| 129 | |
| 130 | // Universal header. All QuicPacket headers will have a connection_id and |
| 131 | // public flags. |
| 132 | QuicConnectionId destination_connection_id; |
| 133 | QuicConnectionIdIncluded destination_connection_id_included; |
| 134 | QuicConnectionId source_connection_id; |
| 135 | QuicConnectionIdIncluded source_connection_id_included; |
| 136 | // This is only used for Google QUIC. |
| 137 | bool reset_flag; |
| 138 | // For Google QUIC, version flag in packets from the server means version |
| 139 | // negotiation packet. For IETF QUIC, version flag means long header. |
| 140 | bool version_flag; |
| 141 | // Indicates whether |possible_stateless_reset_token| contains a valid value |
| 142 | // parsed from the packet buffer. IETF QUIC only, always false for GQUIC. |
| 143 | bool has_possible_stateless_reset_token; |
| 144 | QuicPacketNumberLength packet_number_length; |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 145 | uint8_t type_byte; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 146 | ParsedQuicVersion version; |
| 147 | // nonce contains an optional, 32-byte nonce value. If not included in the |
| 148 | // packet, |nonce| will be empty. |
| 149 | DiversificationNonce* nonce; |
| 150 | QuicPacketNumber packet_number; |
| 151 | // Format of this header. |
| 152 | PacketHeaderFormat form; |
| 153 | // Short packet type is reflected in packet_number_length. |
| 154 | QuicLongHeaderType long_packet_type; |
| 155 | // Only valid if |has_possible_stateless_reset_token| is true. |
| 156 | // Stores last 16 bytes of a this packet, used to check whether this packet is |
| 157 | // a stateless reset packet on decryption failure. |
| 158 | QuicUint128 possible_stateless_reset_token; |
| 159 | // Length of the retry token length variable length integer field, |
| 160 | // carried only by v99 IETF Initial packets. |
| 161 | QuicVariableLengthIntegerLength retry_token_length_length; |
| 162 | // Retry token, carried only by v99 IETF Initial packets. |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 163 | quiche::QuicheStringPiece retry_token; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 164 | // Length of the length variable length integer field, |
| 165 | // carried only by v99 IETF Initial, 0-RTT and Handshake packets. |
| 166 | QuicVariableLengthIntegerLength length_length; |
| 167 | // Length of the packet number and payload, carried only by v99 IETF Initial, |
| 168 | // 0-RTT and Handshake packets. Also includes the length of the |
| 169 | // diversification nonce in server to client 0-RTT packets. |
| 170 | QuicByteCount remaining_packet_length; |
| 171 | }; |
| 172 | |
| 173 | struct QUIC_EXPORT_PRIVATE QuicPublicResetPacket { |
| 174 | QuicPublicResetPacket(); |
| 175 | explicit QuicPublicResetPacket(QuicConnectionId connection_id); |
| 176 | |
| 177 | QuicConnectionId connection_id; |
| 178 | QuicPublicResetNonceProof nonce_proof; |
| 179 | QuicSocketAddress client_address; |
| 180 | // An arbitrary string to identify an endpoint. Used by clients to |
| 181 | // differentiate traffic from Google servers vs Non-google servers. |
| 182 | // Will not be used if empty(). |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 183 | std::string endpoint_id; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 184 | }; |
| 185 | |
| 186 | struct QUIC_EXPORT_PRIVATE QuicVersionNegotiationPacket { |
| 187 | QuicVersionNegotiationPacket(); |
| 188 | explicit QuicVersionNegotiationPacket(QuicConnectionId connection_id); |
| 189 | QuicVersionNegotiationPacket(const QuicVersionNegotiationPacket& other); |
| 190 | ~QuicVersionNegotiationPacket(); |
| 191 | |
| 192 | QuicConnectionId connection_id; |
| 193 | ParsedQuicVersionVector versions; |
| 194 | }; |
| 195 | |
| 196 | struct QUIC_EXPORT_PRIVATE QuicIetfStatelessResetPacket { |
| 197 | QuicIetfStatelessResetPacket(); |
| 198 | QuicIetfStatelessResetPacket(const QuicPacketHeader& header, |
| 199 | QuicUint128 token); |
| 200 | QuicIetfStatelessResetPacket(const QuicIetfStatelessResetPacket& other); |
| 201 | ~QuicIetfStatelessResetPacket(); |
| 202 | |
| 203 | QuicPacketHeader header; |
| 204 | QuicUint128 stateless_reset_token; |
| 205 | }; |
| 206 | |
| 207 | class QUIC_EXPORT_PRIVATE QuicData { |
| 208 | public: |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 209 | // Creates a QuicData from a buffer and length. Does not own the buffer. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 210 | QuicData(const char* buffer, size_t length); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 211 | // Creates a QuicData from a buffer and length, |
| 212 | // optionally taking ownership of the buffer. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 213 | QuicData(const char* buffer, size_t length, bool owns_buffer); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 214 | // Creates a QuicData from a quiche::QuicheStringPiece. Does not own the |
| 215 | // buffer. |
| 216 | QuicData(quiche::QuicheStringPiece data); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 217 | QuicData(const QuicData&) = delete; |
| 218 | QuicData& operator=(const QuicData&) = delete; |
| 219 | virtual ~QuicData(); |
| 220 | |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 221 | quiche::QuicheStringPiece AsStringPiece() const { |
| 222 | return quiche::QuicheStringPiece(data(), length()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | const char* data() const { return buffer_; } |
| 226 | size_t length() const { return length_; } |
| 227 | |
| 228 | private: |
| 229 | const char* buffer_; |
| 230 | size_t length_; |
| 231 | bool owns_buffer_; |
| 232 | }; |
| 233 | |
| 234 | class QUIC_EXPORT_PRIVATE QuicPacket : public QuicData { |
| 235 | public: |
| 236 | QuicPacket(char* buffer, |
| 237 | size_t length, |
| 238 | bool owns_buffer, |
| 239 | QuicConnectionIdLength destination_connection_id_length, |
| 240 | QuicConnectionIdLength source_connection_id_length, |
| 241 | bool includes_version, |
| 242 | bool includes_diversification_nonce, |
| 243 | QuicPacketNumberLength packet_number_length, |
| 244 | QuicVariableLengthIntegerLength retry_token_length_length, |
| 245 | QuicByteCount retry_token_length, |
| 246 | QuicVariableLengthIntegerLength length_length); |
| 247 | QuicPacket(QuicTransportVersion version, |
| 248 | char* buffer, |
| 249 | size_t length, |
| 250 | bool owns_buffer, |
| 251 | const QuicPacketHeader& header); |
| 252 | QuicPacket(const QuicPacket&) = delete; |
| 253 | QuicPacket& operator=(const QuicPacket&) = delete; |
| 254 | |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 255 | quiche::QuicheStringPiece AssociatedData(QuicTransportVersion version) const; |
| 256 | quiche::QuicheStringPiece Plaintext(QuicTransportVersion version) const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 257 | |
| 258 | char* mutable_data() { return buffer_; } |
| 259 | |
| 260 | private: |
| 261 | char* buffer_; |
| 262 | const QuicConnectionIdLength destination_connection_id_length_; |
| 263 | const QuicConnectionIdLength source_connection_id_length_; |
| 264 | const bool includes_version_; |
| 265 | const bool includes_diversification_nonce_; |
| 266 | const QuicPacketNumberLength packet_number_length_; |
| 267 | const QuicVariableLengthIntegerLength retry_token_length_length_; |
| 268 | const QuicByteCount retry_token_length_; |
| 269 | const QuicVariableLengthIntegerLength length_length_; |
| 270 | }; |
| 271 | |
| 272 | class QUIC_EXPORT_PRIVATE QuicEncryptedPacket : public QuicData { |
| 273 | public: |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 274 | // Creates a QuicEncryptedPacket from a buffer and length. |
| 275 | // Does not own the buffer. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 276 | QuicEncryptedPacket(const char* buffer, size_t length); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 277 | // Creates a QuicEncryptedPacket from a buffer and length, |
| 278 | // optionally taking ownership of the buffer. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 279 | QuicEncryptedPacket(const char* buffer, size_t length, bool owns_buffer); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 280 | // Creates a QuicEncryptedPacket from a quiche::QuicheStringPiece. |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 281 | // Does not own the buffer. |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 282 | QuicEncryptedPacket(quiche::QuicheStringPiece data); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 283 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 284 | QuicEncryptedPacket(const QuicEncryptedPacket&) = delete; |
| 285 | QuicEncryptedPacket& operator=(const QuicEncryptedPacket&) = delete; |
| 286 | |
| 287 | // Clones the packet into a new packet which owns the buffer. |
| 288 | std::unique_ptr<QuicEncryptedPacket> Clone() const; |
| 289 | |
| 290 | // By default, gtest prints the raw bytes of an object. The bool data |
| 291 | // member (in the base class QuicData) causes this object to have padding |
| 292 | // bytes, which causes the default gtest object printer to read |
| 293 | // uninitialize memory. So we need to teach gtest how to print this object. |
| 294 | QUIC_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 295 | std::ostream& os, |
| 296 | const QuicEncryptedPacket& s); |
| 297 | }; |
| 298 | |
| 299 | // A received encrypted QUIC packet, with a recorded time of receipt. |
| 300 | class QUIC_EXPORT_PRIVATE QuicReceivedPacket : public QuicEncryptedPacket { |
| 301 | public: |
| 302 | QuicReceivedPacket(const char* buffer, size_t length, QuicTime receipt_time); |
| 303 | QuicReceivedPacket(const char* buffer, |
| 304 | size_t length, |
| 305 | QuicTime receipt_time, |
| 306 | bool owns_buffer); |
| 307 | QuicReceivedPacket(const char* buffer, |
| 308 | size_t length, |
| 309 | QuicTime receipt_time, |
| 310 | bool owns_buffer, |
| 311 | int ttl, |
| 312 | bool ttl_valid); |
| 313 | QuicReceivedPacket(const char* buffer, |
| 314 | size_t length, |
| 315 | QuicTime receipt_time, |
| 316 | bool owns_buffer, |
| 317 | int ttl, |
| 318 | bool ttl_valid, |
| 319 | char* packet_headers, |
| 320 | size_t headers_length, |
| 321 | bool owns_header_buffer); |
| 322 | ~QuicReceivedPacket(); |
| 323 | QuicReceivedPacket(const QuicReceivedPacket&) = delete; |
| 324 | QuicReceivedPacket& operator=(const QuicReceivedPacket&) = delete; |
| 325 | |
| 326 | // Clones the packet into a new packet which owns the buffer. |
| 327 | std::unique_ptr<QuicReceivedPacket> Clone() const; |
| 328 | |
| 329 | // Returns the time at which the packet was received. |
| 330 | QuicTime receipt_time() const { return receipt_time_; } |
| 331 | |
| 332 | // This is the TTL of the packet, assuming ttl_vaild_ is true. |
| 333 | int ttl() const { return ttl_; } |
| 334 | |
| 335 | // Start of packet headers. |
| 336 | char* packet_headers() const { return packet_headers_; } |
| 337 | |
| 338 | // Length of packet headers. |
| 339 | int headers_length() const { return headers_length_; } |
| 340 | |
| 341 | // By default, gtest prints the raw bytes of an object. The bool data |
| 342 | // member (in the base class QuicData) causes this object to have padding |
| 343 | // bytes, which causes the default gtest object printer to read |
| 344 | // uninitialize memory. So we need to teach gtest how to print this object. |
| 345 | QUIC_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 346 | std::ostream& os, |
| 347 | const QuicReceivedPacket& s); |
| 348 | |
| 349 | private: |
| 350 | const QuicTime receipt_time_; |
| 351 | int ttl_; |
| 352 | // Points to the start of packet headers. |
| 353 | char* packet_headers_; |
| 354 | // Length of packet headers. |
| 355 | int headers_length_; |
| 356 | // Whether owns the buffer for packet headers. |
| 357 | bool owns_header_buffer_; |
| 358 | }; |
| 359 | |
| 360 | struct QUIC_EXPORT_PRIVATE SerializedPacket { |
| 361 | SerializedPacket(QuicPacketNumber packet_number, |
| 362 | QuicPacketNumberLength packet_number_length, |
| 363 | const char* encrypted_buffer, |
| 364 | QuicPacketLength encrypted_length, |
| 365 | bool has_ack, |
| 366 | bool has_stop_waiting); |
| 367 | SerializedPacket(const SerializedPacket& other); |
| 368 | SerializedPacket& operator=(const SerializedPacket& other); |
| 369 | SerializedPacket(SerializedPacket&& other); |
| 370 | ~SerializedPacket(); |
| 371 | |
| 372 | // Not owned. |
| 373 | const char* encrypted_buffer; |
| 374 | QuicPacketLength encrypted_length; |
| 375 | QuicFrames retransmittable_frames; |
fayang | 51152fd | 2019-10-21 06:48:09 -0700 | [diff] [blame] | 376 | QuicFrames nonretransmittable_frames; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 377 | IsHandshake has_crypto_handshake; |
| 378 | // -1: full padding to the end of a max-sized packet |
| 379 | // 0: no padding |
| 380 | // otherwise: only pad up to num_padding_bytes bytes |
| 381 | int16_t num_padding_bytes; |
| 382 | QuicPacketNumber packet_number; |
| 383 | QuicPacketNumberLength packet_number_length; |
| 384 | EncryptionLevel encryption_level; |
fayang | 02a2874 | 2019-12-04 07:09:38 -0800 | [diff] [blame] | 385 | // TODO(fayang): Remove has_ack and has_stop_waiting. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 386 | bool has_ack; |
| 387 | bool has_stop_waiting; |
| 388 | TransmissionType transmission_type; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 389 | // The largest acked of the AckFrame in this packet if has_ack is true, |
| 390 | // 0 otherwise. |
| 391 | QuicPacketNumber largest_acked; |
fayang | fb5fb61 | 2019-10-21 13:19:14 -0700 | [diff] [blame] | 392 | // Indicates whether this packet has a copy of ack frame in |
| 393 | // nonretransmittable_frames. |
| 394 | bool has_ack_frame_copy; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 395 | }; |
| 396 | |
fayang | fb5fb61 | 2019-10-21 13:19:14 -0700 | [diff] [blame] | 397 | // Make a copy of |serialized| (including the underlying frames). |copy_buffer| |
| 398 | // indicates whether the encrypted buffer should be copied. |
| 399 | QUIC_EXPORT_PRIVATE SerializedPacket* CopySerializedPacket( |
| 400 | const SerializedPacket& serialized, |
| 401 | QuicBufferAllocator* allocator, |
| 402 | bool copy_buffer); |
| 403 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 404 | // Deletes and clears all the frames and the packet from serialized packet. |
| 405 | QUIC_EXPORT_PRIVATE void ClearSerializedPacket( |
| 406 | SerializedPacket* serialized_packet); |
| 407 | |
| 408 | // Allocates a new char[] of size |packet.encrypted_length| and copies in |
| 409 | // |packet.encrypted_buffer|. |
| 410 | QUIC_EXPORT_PRIVATE char* CopyBuffer(const SerializedPacket& packet); |
fayang | 58f7107 | 2019-11-05 08:47:02 -0800 | [diff] [blame] | 411 | // Allocates a new char[] of size |encrypted_length| and copies in |
| 412 | // |encrypted_buffer|. |
| 413 | QUIC_EXPORT_PRIVATE char* CopyBuffer(const char* encrypted_buffer, |
| 414 | QuicPacketLength encrypted_length); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 415 | |
| 416 | struct QUIC_EXPORT_PRIVATE SerializedPacketDeleter { |
| 417 | void operator()(SerializedPacket* packet) { |
| 418 | if (packet->encrypted_buffer != nullptr) { |
| 419 | delete[] packet->encrypted_buffer; |
| 420 | } |
| 421 | delete packet; |
| 422 | } |
| 423 | }; |
| 424 | |
| 425 | // On destruction, OwningSerializedPacketPointer deletes a packet's (on-heap) |
| 426 | // encrypted_buffer before deleting the (also on-heap) packet itself. |
| 427 | // TODO(wub): Maybe delete retransmittable_frames too? |
| 428 | typedef std::unique_ptr<SerializedPacket, SerializedPacketDeleter> |
| 429 | OwningSerializedPacketPointer; |
| 430 | |
| 431 | // Context for an incoming packet. |
| 432 | struct QUIC_EXPORT_PRIVATE QuicPerPacketContext { |
| 433 | virtual ~QuicPerPacketContext() {} |
| 434 | }; |
| 435 | |
fayang | 1ed1f76 | 2019-06-24 11:40:04 -0700 | [diff] [blame] | 436 | // ReceivedPacketInfo comprises information obtained by parsing the unencrypted |
| 437 | // bytes of a received packet. |
| 438 | struct QUIC_EXPORT_PRIVATE ReceivedPacketInfo { |
| 439 | ReceivedPacketInfo(const QuicSocketAddress& self_address, |
| 440 | const QuicSocketAddress& peer_address, |
| 441 | const QuicReceivedPacket& packet); |
| 442 | ReceivedPacketInfo(const ReceivedPacketInfo& other) = default; |
| 443 | |
| 444 | ~ReceivedPacketInfo(); |
| 445 | |
| 446 | std::string ToString() const; |
| 447 | |
| 448 | QUIC_EXPORT_PRIVATE friend std::ostream& operator<<( |
| 449 | std::ostream& os, |
| 450 | const ReceivedPacketInfo& packet_info); |
| 451 | |
| 452 | const QuicSocketAddress& self_address; |
| 453 | const QuicSocketAddress& peer_address; |
| 454 | const QuicReceivedPacket& packet; |
| 455 | |
fayang | 1ed1f76 | 2019-06-24 11:40:04 -0700 | [diff] [blame] | 456 | PacketHeaderFormat form; |
fayang | e3f2f7b | 2019-09-19 17:01:57 -0700 | [diff] [blame] | 457 | // This is only used if the form is IETF_QUIC_LONG_HEADER_PACKET. |
| 458 | QuicLongHeaderType long_packet_type; |
fayang | 1ed1f76 | 2019-06-24 11:40:04 -0700 | [diff] [blame] | 459 | bool version_flag; |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 460 | bool use_length_prefix; |
fayang | 1ed1f76 | 2019-06-24 11:40:04 -0700 | [diff] [blame] | 461 | QuicVersionLabel version_label; |
| 462 | ParsedQuicVersion version; |
| 463 | QuicConnectionId destination_connection_id; |
| 464 | QuicConnectionId source_connection_id; |
| 465 | }; |
| 466 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 467 | } // namespace quic |
| 468 | |
| 469 | #endif // QUICHE_QUIC_CORE_QUIC_PACKETS_H_ |