| 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 // Accumulates frames for the next packet until more frames no longer fit or | 5 // Accumulates frames for the next packet until more frames no longer fit or |
| 6 // it's time to create a packet from them. | 6 // it's time to create a packet from them. |
| 7 | 7 |
| 8 #ifndef NET_QUIC_CORE_QUIC_PACKET_CREATOR_H_ | 8 #ifndef NET_QUIC_CORE_QUIC_PACKET_CREATOR_H_ |
| 9 #define NET_QUIC_CORE_QUIC_PACKET_CREATOR_H_ | 9 #define NET_QUIC_CORE_QUIC_PACKET_CREATOR_H_ |
| 10 | 10 |
| 11 #include <cstddef> | 11 #include <cstddef> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <unordered_map> | 14 #include <unordered_map> |
| 15 #include <utility> | 15 #include <utility> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "net/quic/core/quic_connection_close_delegate_interface.h" | 19 #include "net/quic/core/quic_connection_close_delegate_interface.h" |
| 20 #include "net/quic/core/quic_framer.h" | 20 #include "net/quic/core/quic_framer.h" |
| 21 #include "net/quic/core/quic_iovector.h" | 21 #include "net/quic/core/quic_iovector.h" |
| 22 #include "net/quic/core/quic_packets.h" | 22 #include "net/quic/core/quic_packets.h" |
| 23 #include "net/quic/core/quic_pending_retransmission.h" | 23 #include "net/quic/core/quic_pending_retransmission.h" |
| 24 #include "net/quic/core/quic_stream_frame_data_producer.h" |
| 24 #include "net/quic/platform/api/quic_export.h" | 25 #include "net/quic/platform/api/quic_export.h" |
| 25 | 26 |
| 26 namespace net { | 27 namespace net { |
| 27 namespace test { | 28 namespace test { |
| 28 class QuicPacketCreatorPeer; | 29 class QuicPacketCreatorPeer; |
| 29 } | 30 } |
| 30 | 31 |
| 31 class QUIC_EXPORT_PRIVATE QuicPacketCreator { | 32 class QUIC_EXPORT_PRIVATE QuicPacketCreator { |
| 32 public: | 33 public: |
| 33 // A delegate interface for further processing serialized packet. | 34 // A delegate interface for further processing serialized packet. |
| 34 class QUIC_EXPORT_PRIVATE DelegateInterface | 35 class QUIC_EXPORT_PRIVATE DelegateInterface |
| 35 : public QuicConnectionCloseDelegateInterface { | 36 : public QuicConnectionCloseDelegateInterface, |
| 37 public QuicStreamFrameDataProducer { |
| 36 public: | 38 public: |
| 37 ~DelegateInterface() override {} | 39 ~DelegateInterface() override {} |
| 38 // Called when a packet is serialized. Delegate does not take the ownership | 40 // Called when a packet is serialized. Delegate does not take the ownership |
| 39 // of |serialized_packet|, but takes ownership of any frames it removes | 41 // of |serialized_packet|, but takes ownership of any frames it removes |
| 40 // from |packet.retransmittable_frames|. | 42 // from |packet.retransmittable_frames|. |
| 41 virtual void OnSerializedPacket(SerializedPacket* serialized_packet) = 0; | 43 virtual void OnSerializedPacket(SerializedPacket* serialized_packet) = 0; |
| 42 }; | 44 }; |
| 43 | 45 |
| 44 // Interface which gets callbacks from the QuicPacketCreator at interesting | 46 // Interface which gets callbacks from the QuicPacketCreator at interesting |
| 45 // points. Implementations must not mutate the state of the creator | 47 // points. Implementations must not mutate the state of the creator |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 void set_debug_delegate(DebugDelegate* debug_delegate) { | 211 void set_debug_delegate(DebugDelegate* debug_delegate) { |
| 210 debug_delegate_ = debug_delegate; | 212 debug_delegate_ = debug_delegate; |
| 211 } | 213 } |
| 212 | 214 |
| 213 bool latched_flag_no_stop_waiting_frames() const { | 215 bool latched_flag_no_stop_waiting_frames() const { |
| 214 return latched_flag_no_stop_waiting_frames_; | 216 return latched_flag_no_stop_waiting_frames_; |
| 215 } | 217 } |
| 216 | 218 |
| 217 QuicByteCount pending_padding_bytes() const { return pending_padding_bytes_; } | 219 QuicByteCount pending_padding_bytes() const { return pending_padding_bytes_; } |
| 218 | 220 |
| 221 void set_delegate_saves_data(bool delegate_saves_data) { |
| 222 delegate_saves_data_ = delegate_saves_data; |
| 223 } |
| 224 |
| 219 private: | 225 private: |
| 220 friend class test::QuicPacketCreatorPeer; | 226 friend class test::QuicPacketCreatorPeer; |
| 221 | 227 |
| 222 static bool ShouldRetransmit(const QuicFrame& frame); | 228 static bool ShouldRetransmit(const QuicFrame& frame); |
| 223 | 229 |
| 224 // Converts a raw payload to a frame which fits into the current open | 230 // Converts a raw payload to a frame which fits into the current open |
| 225 // packet. The payload begins at |iov_offset| into the |iov|. | 231 // packet. The payload begins at |iov_offset| into the |iov|. |
| 226 // If data is empty and fin is true, the expected behavior is to consume the | 232 // If data is empty and fin is true, the expected behavior is to consume the |
| 227 // fin but return 0. If any data is consumed, it will be copied into a | 233 // fin but return 0. If any data is consumed, it will be copied into a |
| 228 // new buffer that |frame| will point to and own. | 234 // new buffer that |frame| will point to and own. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 254 // OnSerializedPacket and reset state. | 260 // OnSerializedPacket and reset state. |
| 255 void OnSerializedPacket(); | 261 void OnSerializedPacket(); |
| 256 | 262 |
| 257 // Clears all fields of packet_ that should be cleared between serializations. | 263 // Clears all fields of packet_ that should be cleared between serializations. |
| 258 void ClearPacket(); | 264 void ClearPacket(); |
| 259 | 265 |
| 260 // Returns true if a diversification nonce should be included in the current | 266 // Returns true if a diversification nonce should be included in the current |
| 261 // packet's public header. | 267 // packet's public header. |
| 262 bool IncludeNonceInPublicHeader(); | 268 bool IncludeNonceInPublicHeader(); |
| 263 | 269 |
| 270 // Returns true if |frame| starts with CHLO. |
| 271 bool StreamFrameStartsWithChlo(QuicIOVector iov, |
| 272 size_t iov_offset, |
| 273 const QuicStreamFrame& frame) const; |
| 274 |
| 264 // Does not own these delegates or the framer. | 275 // Does not own these delegates or the framer. |
| 265 DelegateInterface* delegate_; | 276 DelegateInterface* delegate_; |
| 266 DebugDelegate* debug_delegate_; | 277 DebugDelegate* debug_delegate_; |
| 267 QuicFramer* framer_; | 278 QuicFramer* framer_; |
| 268 | 279 |
| 269 QuicBufferAllocator* const buffer_allocator_; | 280 QuicBufferAllocator* const buffer_allocator_; |
| 270 | 281 |
| 271 // Controls whether version should be included while serializing the packet. | 282 // Controls whether version should be included while serializing the packet. |
| 272 bool send_version_in_packet_; | 283 bool send_version_in_packet_; |
| 273 // Staging variable to hold next packet number length. When sequence | 284 // Staging variable to hold next packet number length. When sequence |
| (...skipping 29 matching lines...) Expand all Loading... |
| 303 // Pending padding bytes to send. Pending padding bytes will be sent in next | 314 // Pending padding bytes to send. Pending padding bytes will be sent in next |
| 304 // packet(s) (after all other frames) if current constructed packet does not | 315 // packet(s) (after all other frames) if current constructed packet does not |
| 305 // have room to send all of them. | 316 // have room to send all of them. |
| 306 QuicByteCount pending_padding_bytes_; | 317 QuicByteCount pending_padding_bytes_; |
| 307 | 318 |
| 308 // Indicates whether current constructed packet needs full padding to max | 319 // Indicates whether current constructed packet needs full padding to max |
| 309 // packet size. Please note, full padding does not consume pending padding | 320 // packet size. Please note, full padding does not consume pending padding |
| 310 // bytes. | 321 // bytes. |
| 311 bool needs_full_padding_; | 322 bool needs_full_padding_; |
| 312 | 323 |
| 324 // Indicates whether frame data is saved by delegate_. TODO(fayang): Remove |
| 325 // this boolean when deprecating quic_reloadable_flag_quic_stream_owns_data. |
| 326 bool delegate_saves_data_; |
| 327 |
| 313 DISALLOW_COPY_AND_ASSIGN(QuicPacketCreator); | 328 DISALLOW_COPY_AND_ASSIGN(QuicPacketCreator); |
| 314 }; | 329 }; |
| 315 | 330 |
| 316 } // namespace net | 331 } // namespace net |
| 317 | 332 |
| 318 #endif // NET_QUIC_CORE_QUIC_PACKET_CREATOR_H_ | 333 #endif // NET_QUIC_CORE_QUIC_PACKET_CREATOR_H_ |
| OLD | NEW |