| 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 { | |
| 70 public: | 69 public: |
| 71 class NET_EXPORT_PRIVATE DelegateInterface { | 70 class NET_EXPORT_PRIVATE DelegateInterface |
| 71 : public QuicPacketCreator::DelegateInterface { |
| 72 public: | 72 public: |
| 73 virtual ~DelegateInterface() {} | 73 ~DelegateInterface() override {} |
| 74 // Consults delegate whether a packet should be generated. | 74 // Consults delegate whether a packet should be generated. |
| 75 virtual bool ShouldGeneratePacket(HasRetransmittableData retransmittable, | 75 virtual bool ShouldGeneratePacket(HasRetransmittableData retransmittable, |
| 76 IsHandshake handshake) = 0; | 76 IsHandshake handshake) = 0; |
| 77 virtual void PopulateAckFrame(QuicAckFrame* ack) = 0; | 77 virtual void PopulateAckFrame(QuicAckFrame* ack) = 0; |
| 78 virtual void PopulateStopWaitingFrame( | 78 virtual void PopulateStopWaitingFrame( |
| 79 QuicStopWaitingFrame* stop_waiting) = 0; | 79 QuicStopWaitingFrame* stop_waiting) = 0; |
| 80 // Takes ownership of |packet.packet| and |packet.retransmittable_frames|. | |
| 81 virtual void OnSerializedPacket(const SerializedPacket& packet) = 0; | |
| 82 virtual void CloseConnection(QuicErrorCode error, bool from_peer) = 0; | |
| 83 // Called when a FEC Group is reset (closed). | |
| 84 virtual void OnResetFecGroup() = 0; | |
| 85 }; | 80 }; |
| 86 | 81 |
| 87 QuicPacketGenerator(QuicConnectionId connection_id, | 82 QuicPacketGenerator(QuicConnectionId connection_id, |
| 88 QuicFramer* framer, | 83 QuicFramer* framer, |
| 89 QuicRandom* random_generator, | 84 QuicRandom* random_generator, |
| 90 DelegateInterface* delegate); | 85 DelegateInterface* delegate); |
| 91 | 86 |
| 92 ~QuicPacketGenerator() override; | 87 ~QuicPacketGenerator(); |
| 93 | 88 |
| 94 // Called by the connection in the event of the congestion window changing. | 89 // Called by the connection in the event of the congestion window changing. |
| 95 void OnCongestionWindowChange(QuicPacketCount max_packets_in_flight); | 90 void OnCongestionWindowChange(QuicPacketCount max_packets_in_flight); |
| 96 | 91 |
| 97 // Called by the connection when the RTT may have changed. | 92 // Called by the connection when the RTT may have changed. |
| 98 void OnRttChange(QuicTime::Delta rtt); | 93 void OnRttChange(QuicTime::Delta rtt); |
| 99 | 94 |
| 100 // Indicates that an ACK frame should be sent. | 95 // Indicates that an ACK frame should be sent. |
| 101 // If |also_send_stop_waiting| is true, then it also indicates that a | 96 // If |also_send_stop_waiting| is true, then it also indicates that a |
| 102 // STOP_WAITING frame should be sent as well. | 97 // STOP_WAITING frame should be sent as well. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 // Called after sending |packet_number| to determine whether an FEC alarm | 164 // Called after sending |packet_number| to determine whether an FEC alarm |
| 170 // should be set for sending out an FEC packet. Returns a positive and finite | 165 // should be set for sending out an FEC packet. Returns a positive and finite |
| 171 // timeout if an FEC alarm should be set, and infinite if no alarm should be | 166 // timeout if an FEC alarm should be set, and infinite if no alarm should be |
| 172 // set. OnFecTimeout should be called to send the FEC packet when the alarm | 167 // set. OnFecTimeout should be called to send the FEC packet when the alarm |
| 173 // fires. | 168 // fires. |
| 174 QuicTime::Delta GetFecTimeout(QuicPacketNumber packet_number); | 169 QuicTime::Delta GetFecTimeout(QuicPacketNumber packet_number); |
| 175 | 170 |
| 176 // Sets the encrypter to use for the encryption level. | 171 // Sets the encrypter to use for the encryption level. |
| 177 void SetEncrypter(EncryptionLevel level, QuicEncrypter* encrypter); | 172 void SetEncrypter(EncryptionLevel level, QuicEncrypter* encrypter); |
| 178 | 173 |
| 179 // QuicPacketCreator::DelegateInterface. | |
| 180 void OnSerializedPacket(SerializedPacket* serialized_packet) override; | |
| 181 void OnResetFecGroup() override; | |
| 182 | |
| 183 // Sets the encryption level that will be applied to new packets. | 174 // Sets the encryption level that will be applied to new packets. |
| 184 void set_encryption_level(EncryptionLevel level); | 175 void set_encryption_level(EncryptionLevel level); |
| 185 | 176 |
| 186 // packet number of the last created packet, or 0 if no packets have been | 177 // packet number of the last created packet, or 0 if no packets have been |
| 187 // created. | 178 // created. |
| 188 QuicPacketNumber packet_number() const; | 179 QuicPacketNumber packet_number() const; |
| 189 | 180 |
| 190 // Returns the maximum packet length. Note that this is the long-term maximum | 181 // Returns the maximum packet length. Note that this is the long-term maximum |
| 191 // packet length, and it may not be the maximum length of the current packet, | 182 // packet length, and it may not be the maximum length of the current packet, |
| 192 // if the generator is in the middle of the packet (in batch mode) or FEC | 183 // if the generator is in the middle of the packet (in batch mode) or FEC |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 // Flags to indicate the need for just-in-time construction of a frame. | 232 // Flags to indicate the need for just-in-time construction of a frame. |
| 242 bool should_send_ack_; | 233 bool should_send_ack_; |
| 243 bool should_send_stop_waiting_; | 234 bool should_send_stop_waiting_; |
| 244 // If we put a non-retransmittable frame in this packet, then we have to hold | 235 // If we put a non-retransmittable frame in this packet, then we have to hold |
| 245 // a reference to it until we flush (and serialize it). Retransmittable frames | 236 // a reference to it until we flush (and serialize it). Retransmittable frames |
| 246 // are referenced elsewhere so that they can later be (optionally) | 237 // are referenced elsewhere so that they can later be (optionally) |
| 247 // retransmitted. | 238 // retransmitted. |
| 248 QuicAckFrame pending_ack_frame_; | 239 QuicAckFrame pending_ack_frame_; |
| 249 QuicStopWaitingFrame pending_stop_waiting_frame_; | 240 QuicStopWaitingFrame pending_stop_waiting_frame_; |
| 250 | 241 |
| 251 // Stores ack listeners that should be attached to the next packet. | |
| 252 std::list<AckListenerWrapper> ack_listeners_; | |
| 253 | |
| 254 // Stores the maximum packet size we are allowed to send. This might not be | 242 // Stores the maximum packet size we are allowed to send. This might not be |
| 255 // the maximum size we are actually using now, if we are in the middle of the | 243 // the maximum size we are actually using now, if we are in the middle of the |
| 256 // packet. | 244 // packet. |
| 257 QuicByteCount max_packet_length_; | 245 QuicByteCount max_packet_length_; |
| 258 | 246 |
| 259 DISALLOW_COPY_AND_ASSIGN(QuicPacketGenerator); | 247 DISALLOW_COPY_AND_ASSIGN(QuicPacketGenerator); |
| 260 }; | 248 }; |
| 261 | 249 |
| 262 } // namespace net | 250 } // namespace net |
| 263 | 251 |
| 264 #endif // NET_QUIC_QUIC_PACKET_GENERATOR_H_ | 252 #endif // NET_QUIC_QUIC_PACKET_GENERATOR_H_ |
| OLD | NEW |