| 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 // Responsible for generating packets on behalf of a QuicConnection. | 5 // Responsible for generating packets on behalf of a QuicConnection. |
| 6 // Packets are serialized just-in-time. Control frames are queued. | 6 // Packets are serialized just-in-time. Control frames are queued. |
| 7 // Ack and Feedback frames will be requested from the Connection | 7 // Ack and Feedback frames will be requested from the Connection |
| 8 // just-in-time. When a packet needs to be sent, the Generator | 8 // just-in-time. When a packet needs to be sent, the Generator |
| 9 // will serialize a packet and pass it to QuicConnection::SendOrQueuePacket() | 9 // will serialize a packet and pass it to QuicConnection::SendOrQueuePacket() |
| 10 // | 10 // |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 #include "net/quic/quic_packet_creator.h" | 58 #include "net/quic/quic_packet_creator.h" |
| 59 #include "net/quic/quic_sent_packet_manager.h" | 59 #include "net/quic/quic_sent_packet_manager.h" |
| 60 #include "net/quic/quic_types.h" | 60 #include "net/quic/quic_types.h" |
| 61 | 61 |
| 62 namespace net { | 62 namespace net { |
| 63 | 63 |
| 64 namespace test { | 64 namespace test { |
| 65 class QuicPacketGeneratorPeer; | 65 class QuicPacketGeneratorPeer; |
| 66 } // namespace test | 66 } // namespace test |
| 67 | 67 |
| 68 class NET_EXPORT_PRIVATE QuicPacketGenerator { | 68 class NET_EXPORT_PRIVATE QuicPacketGenerator |
| 69 : public QuicPacketCreator::DelegateInterface { |
| 69 public: | 70 public: |
| 70 class NET_EXPORT_PRIVATE DelegateInterface { | 71 class NET_EXPORT_PRIVATE DelegateInterface { |
| 71 public: | 72 public: |
| 72 virtual ~DelegateInterface() {} | 73 virtual ~DelegateInterface() {} |
| 73 virtual bool ShouldGeneratePacket(HasRetransmittableData retransmittable, | 74 virtual bool ShouldGeneratePacket(HasRetransmittableData retransmittable, |
| 74 IsHandshake handshake) = 0; | 75 IsHandshake handshake) = 0; |
| 75 virtual void PopulateAckFrame(QuicAckFrame* ack) = 0; | 76 virtual void PopulateAckFrame(QuicAckFrame* ack) = 0; |
| 76 virtual void PopulateStopWaitingFrame( | 77 virtual void PopulateStopWaitingFrame( |
| 77 QuicStopWaitingFrame* stop_waiting) = 0; | 78 QuicStopWaitingFrame* stop_waiting) = 0; |
| 78 // Takes ownership of |packet.packet| and |packet.retransmittable_frames|. | 79 // Takes ownership of |packet.packet| and |packet.retransmittable_frames|. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 91 | 92 |
| 92 // Called when a frame has been added to the current packet. | 93 // Called when a frame has been added to the current packet. |
| 93 virtual void OnFrameAddedToPacket(const QuicFrame& frame) {} | 94 virtual void OnFrameAddedToPacket(const QuicFrame& frame) {} |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 QuicPacketGenerator(QuicConnectionId connection_id, | 97 QuicPacketGenerator(QuicConnectionId connection_id, |
| 97 QuicFramer* framer, | 98 QuicFramer* framer, |
| 98 QuicRandom* random_generator, | 99 QuicRandom* random_generator, |
| 99 DelegateInterface* delegate); | 100 DelegateInterface* delegate); |
| 100 | 101 |
| 101 virtual ~QuicPacketGenerator(); | 102 ~QuicPacketGenerator() override; |
| 102 | 103 |
| 103 // Called by the connection in the event of the congestion window changing. | 104 // Called by the connection in the event of the congestion window changing. |
| 104 void OnCongestionWindowChange(QuicPacketCount max_packets_in_flight); | 105 void OnCongestionWindowChange(QuicPacketCount max_packets_in_flight); |
| 105 | 106 |
| 106 // Called by the connection when the RTT may have changed. | 107 // Called by the connection when the RTT may have changed. |
| 107 void OnRttChange(QuicTime::Delta rtt); | 108 void OnRttChange(QuicTime::Delta rtt); |
| 108 | 109 |
| 109 // Indicates that an ACK frame should be sent. | 110 // Indicates that an ACK frame should be sent. |
| 110 // If |also_send_stop_waiting| is true, then it also indicates that a | 111 // If |also_send_stop_waiting| is true, then it also indicates that a |
| 111 // STOP_WAITING frame should be sent as well. | 112 // STOP_WAITING frame should be sent as well. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 // Called after sending |packet_number| to determine whether an FEC alarm | 177 // Called after sending |packet_number| to determine whether an FEC alarm |
| 177 // should be set for sending out an FEC packet. Returns a positive and finite | 178 // should be set for sending out an FEC packet. Returns a positive and finite |
| 178 // timeout if an FEC alarm should be set, and infinite if no alarm should be | 179 // timeout if an FEC alarm should be set, and infinite if no alarm should be |
| 179 // set. OnFecTimeout should be called to send the FEC packet when the alarm | 180 // set. OnFecTimeout should be called to send the FEC packet when the alarm |
| 180 // fires. | 181 // fires. |
| 181 QuicTime::Delta GetFecTimeout(QuicPacketNumber packet_number); | 182 QuicTime::Delta GetFecTimeout(QuicPacketNumber packet_number); |
| 182 | 183 |
| 183 // Sets the encrypter to use for the encryption level. | 184 // Sets the encrypter to use for the encryption level. |
| 184 void SetEncrypter(EncryptionLevel level, QuicEncrypter* encrypter); | 185 void SetEncrypter(EncryptionLevel level, QuicEncrypter* encrypter); |
| 185 | 186 |
| 187 // QuicPacketCreator::DelegateInterface. |
| 188 void OnSerializedPacket(SerializedPacket* serialized_packet) override; |
| 189 |
| 186 // Sets the encryption level that will be applied to new packets. | 190 // Sets the encryption level that will be applied to new packets. |
| 187 void set_encryption_level(EncryptionLevel level); | 191 void set_encryption_level(EncryptionLevel level); |
| 188 | 192 |
| 189 // packet number of the last created packet, or 0 if no packets have been | 193 // packet number of the last created packet, or 0 if no packets have been |
| 190 // created. | 194 // created. |
| 191 QuicPacketNumber packet_number() const; | 195 QuicPacketNumber packet_number() const; |
| 192 | 196 |
| 193 // Returns the maximum packet length. Note that this is the long-term maximum | 197 // Returns the maximum packet length. Note that this is the long-term maximum |
| 194 // packet length, and it may not be the maximum length of the current packet, | 198 // packet length, and it may not be the maximum length of the current packet, |
| 195 // if the generator is in the middle of the packet (in batch mode) or FEC | 199 // if the generator is in the middle of the packet (in batch mode) or FEC |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 void ResetFecGroup(); | 253 void ResetFecGroup(); |
| 250 | 254 |
| 251 void SendQueuedFrames(bool flush, bool is_fec_timeout); | 255 void SendQueuedFrames(bool flush, bool is_fec_timeout); |
| 252 | 256 |
| 253 // Test to see if we have pending ack, or control frames. | 257 // Test to see if we have pending ack, or control frames. |
| 254 bool HasPendingFrames() const; | 258 bool HasPendingFrames() const; |
| 255 // Test to see if the addition of a pending frame (which might be | 259 // Test to see if the addition of a pending frame (which might be |
| 256 // retransmittable) would still allow the resulting packet to be sent now. | 260 // retransmittable) would still allow the resulting packet to be sent now. |
| 257 bool CanSendWithNextPendingFrameAddition() const; | 261 bool CanSendWithNextPendingFrameAddition() const; |
| 258 // Add exactly one pending frame, preferring ack frames over control frames. | 262 // Add exactly one pending frame, preferring ack frames over control frames. |
| 263 // Returns true if a pending frame is successfully added. |
| 264 // Returns false and flushes current open packet if the pending frame cannot |
| 265 // fit into current open packet. |
| 259 bool AddNextPendingFrame(); | 266 bool AddNextPendingFrame(); |
| 260 // Adds a frame and takes ownership of the underlying buffer. | 267 // Adds a frame and takes ownership of the underlying buffer. |
| 261 bool AddFrame(const QuicFrame& frame, | 268 bool AddFrame(const QuicFrame& frame, |
| 262 UniqueStreamBuffer buffer, | 269 UniqueStreamBuffer buffer, |
| 263 bool needs_padding); | 270 bool needs_padding); |
| 264 | 271 |
| 265 void SerializeAndSendPacket(); | |
| 266 | |
| 267 DelegateInterface* delegate_; | 272 DelegateInterface* delegate_; |
| 268 DebugDelegate* debug_delegate_; | 273 DebugDelegate* debug_delegate_; |
| 269 | 274 |
| 270 QuicPacketCreator packet_creator_; | 275 QuicPacketCreator packet_creator_; |
| 271 QuicFrames queued_control_frames_; | 276 QuicFrames queued_control_frames_; |
| 272 | 277 |
| 273 // True if batch mode is currently enabled. | 278 // True if batch mode is currently enabled. |
| 274 bool batch_mode_; | 279 bool batch_mode_; |
| 275 | 280 |
| 276 // Timeout used for FEC alarm. Can be set to zero initially or if the SRTT has | 281 // Timeout used for FEC alarm. Can be set to zero initially or if the SRTT has |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 // the maximum size we are actually using now, if we are in the middle of the | 314 // the maximum size we are actually using now, if we are in the middle of the |
| 310 // packet. | 315 // packet. |
| 311 QuicByteCount max_packet_length_; | 316 QuicByteCount max_packet_length_; |
| 312 | 317 |
| 313 DISALLOW_COPY_AND_ASSIGN(QuicPacketGenerator); | 318 DISALLOW_COPY_AND_ASSIGN(QuicPacketGenerator); |
| 314 }; | 319 }; |
| 315 | 320 |
| 316 } // namespace net | 321 } // namespace net |
| 317 | 322 |
| 318 #endif // NET_QUIC_QUIC_PACKET_GENERATOR_H_ | 323 #endif // NET_QUIC_QUIC_PACKET_GENERATOR_H_ |
| OLD | NEW |