| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 class NET_EXPORT_PRIVATE QuicPacketGenerator { | 68 class NET_EXPORT_PRIVATE QuicPacketGenerator { |
| 69 public: | 69 public: |
| 70 class NET_EXPORT_PRIVATE DelegateInterface { | 70 class NET_EXPORT_PRIVATE DelegateInterface { |
| 71 public: | 71 public: |
| 72 virtual ~DelegateInterface() {} | 72 virtual ~DelegateInterface() {} |
| 73 virtual bool ShouldGeneratePacket(TransmissionType transmission_type, | 73 virtual bool ShouldGeneratePacket(TransmissionType transmission_type, |
| 74 HasRetransmittableData retransmittable, | 74 HasRetransmittableData retransmittable, |
| 75 IsHandshake handshake) = 0; | 75 IsHandshake handshake) = 0; |
| 76 virtual QuicAckFrame* CreateAckFrame() = 0; | 76 virtual QuicAckFrame* CreateAckFrame() = 0; |
| 77 virtual QuicCongestionFeedbackFrame* CreateFeedbackFrame() = 0; | |
| 78 virtual QuicStopWaitingFrame* CreateStopWaitingFrame() = 0; | 77 virtual QuicStopWaitingFrame* CreateStopWaitingFrame() = 0; |
| 79 // Takes ownership of |packet.packet| and |packet.retransmittable_frames|. | 78 // Takes ownership of |packet.packet| and |packet.retransmittable_frames|. |
| 80 virtual void OnSerializedPacket(const SerializedPacket& packet) = 0; | 79 virtual void OnSerializedPacket(const SerializedPacket& packet) = 0; |
| 81 virtual void CloseConnection(QuicErrorCode error, bool from_peer) = 0; | 80 virtual void CloseConnection(QuicErrorCode error, bool from_peer) = 0; |
| 82 }; | 81 }; |
| 83 | 82 |
| 84 // Interface which gets callbacks from the QuicPacketGenerator at interesting | 83 // Interface which gets callbacks from the QuicPacketGenerator at interesting |
| 85 // points. Implementations must not mutate the state of the generator | 84 // points. Implementations must not mutate the state of the generator |
| 86 // as a result of these callbacks. | 85 // as a result of these callbacks. |
| 87 class NET_EXPORT_PRIVATE DebugDelegate { | 86 class NET_EXPORT_PRIVATE DebugDelegate { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 98 DelegateInterface* delegate); | 97 DelegateInterface* delegate); |
| 99 | 98 |
| 100 virtual ~QuicPacketGenerator(); | 99 virtual ~QuicPacketGenerator(); |
| 101 | 100 |
| 102 // Called by the connection in the event of the congestion window changing. | 101 // Called by the connection in the event of the congestion window changing. |
| 103 void OnCongestionWindowChange(QuicPacketCount max_packets_in_flight); | 102 void OnCongestionWindowChange(QuicPacketCount max_packets_in_flight); |
| 104 | 103 |
| 105 // Called by the connection when the RTT may have changed. | 104 // Called by the connection when the RTT may have changed. |
| 106 void OnRttChange(QuicTime::Delta rtt); | 105 void OnRttChange(QuicTime::Delta rtt); |
| 107 | 106 |
| 108 // Indicates that an ACK frame should be sent. If |also_send_feedback| is | 107 // Indicates that an ACK frame should be sent. |
| 109 // true, then it also indicates a CONGESTION_FEEDBACK frame should be sent. | |
| 110 // If |also_send_stop_waiting| is true, then it also indicates that a | 108 // If |also_send_stop_waiting| is true, then it also indicates that a |
| 111 // STOP_WAITING frame should be sent as well. | 109 // STOP_WAITING frame should be sent as well. |
| 112 // The contents of the frame(s) will be generated via a call to the delegates | 110 // The contents of the frame(s) will be generated via a call to the delegate |
| 113 // CreateAckFrame() and CreateFeedbackFrame() when the packet is serialized. | 111 // CreateAckFrame() when the packet is serialized. |
| 114 void SetShouldSendAck(bool also_send_feedback, | 112 void SetShouldSendAck(bool also_send_stop_waiting); |
| 115 bool also_send_stop_waiting); | |
| 116 | 113 |
| 117 // Indicates that a STOP_WAITING frame should be sent. | 114 // Indicates that a STOP_WAITING frame should be sent. |
| 118 void SetShouldSendStopWaiting(); | 115 void SetShouldSendStopWaiting(); |
| 119 | 116 |
| 120 void AddControlFrame(const QuicFrame& frame); | 117 void AddControlFrame(const QuicFrame& frame); |
| 121 | 118 |
| 122 // Given some data, may consume part or all of it and pass it to the | 119 // Given some data, may consume part or all of it and pass it to the |
| 123 // packet creator to be serialized into packets. If not in batch | 120 // packet creator to be serialized into packets. If not in batch |
| 124 // mode, these packets will also be sent during this call. | 121 // mode, these packets will also be sent during this call. |
| 125 // |delegate| (if not nullptr) will be informed once all packets sent as a | 122 // |delegate| (if not nullptr) will be informed once all packets sent as a |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 161 |
| 165 // Update the sequence number length to use in future packets as soon as it | 162 // Update the sequence number length to use in future packets as soon as it |
| 166 // can be safely changed. | 163 // can be safely changed. |
| 167 void UpdateSequenceNumberLength( | 164 void UpdateSequenceNumberLength( |
| 168 QuicPacketSequenceNumber least_packet_awaited_by_peer, | 165 QuicPacketSequenceNumber least_packet_awaited_by_peer, |
| 169 QuicPacketCount max_packets_in_flight); | 166 QuicPacketCount max_packets_in_flight); |
| 170 | 167 |
| 171 // Set the minimum number of bytes for the connection id length; | 168 // Set the minimum number of bytes for the connection id length; |
| 172 void SetConnectionIdLength(uint32 length); | 169 void SetConnectionIdLength(uint32 length); |
| 173 | 170 |
| 171 // Called when the FEC alarm fires. |
| 172 void OnFecTimeout(); |
| 173 |
| 174 // Called after sending |sequence_number| to determine whether an FEC alarm |
| 175 // should be set for sending out an FEC packet. Returns a positive and finite |
| 176 // timeout if an FEC alarm should be set, and infinite if no alarm should be |
| 177 // set. OnFecTimeout should be called to send the FEC packet when the alarm |
| 178 // fires. |
| 179 QuicTime::Delta GetFecTimeout(QuicPacketSequenceNumber sequence_number); |
| 180 |
| 174 // Sets the encryption level that will be applied to new packets. | 181 // Sets the encryption level that will be applied to new packets. |
| 175 void set_encryption_level(EncryptionLevel level); | 182 void set_encryption_level(EncryptionLevel level); |
| 176 | 183 |
| 177 // Sequence number of the last created packet, or 0 if no packets have been | 184 // Sequence number of the last created packet, or 0 if no packets have been |
| 178 // created. | 185 // created. |
| 179 QuicPacketSequenceNumber sequence_number() const; | 186 QuicPacketSequenceNumber sequence_number() const; |
| 180 | 187 |
| 181 QuicByteCount max_packet_length() const; | 188 QuicByteCount max_packet_length() const; |
| 182 | 189 |
| 183 void set_max_packet_length(QuicByteCount length); | 190 void set_max_packet_length(QuicByteCount length); |
| 184 | 191 |
| 185 void set_debug_delegate(DebugDelegate* debug_delegate) { | 192 void set_debug_delegate(DebugDelegate* debug_delegate) { |
| 186 debug_delegate_ = debug_delegate; | 193 debug_delegate_ = debug_delegate; |
| 187 } | 194 } |
| 188 | 195 |
| 189 QuicTime::Delta fec_timeout() { return fec_timeout_; } | |
| 190 | |
| 191 private: | 196 private: |
| 192 friend class test::QuicPacketGeneratorPeer; | 197 friend class test::QuicPacketGeneratorPeer; |
| 193 | 198 |
| 194 // Turn on FEC protection for subsequent packets in the generator. | 199 // Turn on FEC protection for subsequent packets in the generator. |
| 195 // If no FEC group is currently open in the creator, this method flushes any | 200 // If no FEC group is currently open in the creator, this method flushes any |
| 196 // queued frames in the generator and in the creator, and it then turns FEC on | 201 // queued frames in the generator and in the creator, and it then turns FEC on |
| 197 // in the creator. This method may be called with an open FEC group in the | 202 // in the creator. This method may be called with an open FEC group in the |
| 198 // creator, in which case, only the generator's state is altered. | 203 // creator, in which case, only the generator's state is altered. |
| 199 void MaybeStartFecProtection(); | 204 void MaybeStartFecProtection(); |
| 200 | 205 |
| 201 // Serializes and calls the delegate on an FEC packet if one was under | 206 // Serializes and calls the delegate on an FEC packet if one was under |
| 202 // construction in the creator. When |force| is false, it relies on the | 207 // construction in the creator. When |force| is false, it relies on the |
| 203 // creator being ready to send an FEC packet, otherwise FEC packet is sent | 208 // creator being ready to send an FEC packet, otherwise FEC packet is sent |
| 204 // as long as one is under construction in the creator. Also tries to turn | 209 // as long as one is under construction in the creator. Also tries to turn |
| 205 // off FEC protection in the creator if it's off in the generator. | 210 // off FEC protection in the creator if it's off in the generator. |
| 206 void MaybeSendFecPacketAndCloseGroup(bool force); | 211 void MaybeSendFecPacketAndCloseGroup(bool force); |
| 207 | 212 |
| 213 // Returns true if an FEC packet should be generated based on |force| and |
| 214 // current state of the generator and the creator. |
| 215 bool ShouldSendFecPacket(bool force); |
| 216 |
| 208 void SendQueuedFrames(bool flush); | 217 void SendQueuedFrames(bool flush); |
| 209 | 218 |
| 210 // Test to see if we have pending ack, feedback, or control frames. | 219 // Test to see if we have pending ack, or control frames. |
| 211 bool HasPendingFrames() const; | 220 bool HasPendingFrames() const; |
| 212 // Test to see if the addition of a pending frame (which might be | 221 // Test to see if the addition of a pending frame (which might be |
| 213 // retransmittable) would still allow the resulting packet to be sent now. | 222 // retransmittable) would still allow the resulting packet to be sent now. |
| 214 bool CanSendWithNextPendingFrameAddition() const; | 223 bool CanSendWithNextPendingFrameAddition() const; |
| 215 // Add exactly one pending frame, preferring ack over feedback over control | 224 // Add exactly one pending frame, preferring ack frames over control frames. |
| 216 // frames. | |
| 217 bool AddNextPendingFrame(); | 225 bool AddNextPendingFrame(); |
| 218 | 226 |
| 219 bool AddFrame(const QuicFrame& frame); | 227 bool AddFrame(const QuicFrame& frame); |
| 220 | 228 |
| 221 void SerializeAndSendPacket(); | 229 void SerializeAndSendPacket(); |
| 222 | 230 |
| 223 DelegateInterface* delegate_; | 231 DelegateInterface* delegate_; |
| 224 DebugDelegate* debug_delegate_; | 232 DebugDelegate* debug_delegate_; |
| 225 | 233 |
| 226 QuicPacketCreator packet_creator_; | 234 QuicPacketCreator packet_creator_; |
| 227 QuicFrames queued_control_frames_; | 235 QuicFrames queued_control_frames_; |
| 228 | 236 |
| 229 // True if batch mode is currently enabled. | 237 // True if batch mode is currently enabled. |
| 230 bool batch_mode_; | 238 bool batch_mode_; |
| 231 | 239 |
| 232 // Timeout used for FEC alarm. Can be set to zero. | 240 // Timeout used for FEC alarm. Can be set to zero initially or if the SRTT has |
| 241 // not yet been set. |
| 233 QuicTime::Delta fec_timeout_; | 242 QuicTime::Delta fec_timeout_; |
| 234 | 243 |
| 235 // True if FEC protection is on. The creator may have an open FEC group even | 244 // True if FEC protection is on. The creator may have an open FEC group even |
| 236 // if this variable is false. | 245 // if this variable is false. |
| 237 bool should_fec_protect_; | 246 bool should_fec_protect_; |
| 238 | 247 |
| 239 // Flags to indicate the need for just-in-time construction of a frame. | 248 // Flags to indicate the need for just-in-time construction of a frame. |
| 240 bool should_send_ack_; | 249 bool should_send_ack_; |
| 241 bool should_send_feedback_; | |
| 242 bool should_send_stop_waiting_; | 250 bool should_send_stop_waiting_; |
| 243 // If we put a non-retransmittable frame (namley ack or feedback frame) in | 251 // If we put a non-retransmittable frame (ack frame) in this packet, then we |
| 244 // this packet, then we have to hold a reference to it until we flush (and | 252 // have to hold a reference to it until we flush (and serialize it). |
| 245 // serialize it). Retransmittable frames are referenced elsewhere so that they | 253 // Retransmittable frames are referenced elsewhere so that they |
| 246 // can later be (optionally) retransmitted. | 254 // can later be (optionally) retransmitted. |
| 247 scoped_ptr<QuicAckFrame> pending_ack_frame_; | 255 scoped_ptr<QuicAckFrame> pending_ack_frame_; |
| 248 scoped_ptr<QuicCongestionFeedbackFrame> pending_feedback_frame_; | |
| 249 scoped_ptr<QuicStopWaitingFrame> pending_stop_waiting_frame_; | 256 scoped_ptr<QuicStopWaitingFrame> pending_stop_waiting_frame_; |
| 250 | 257 |
| 251 // Stores notifiers that should be attached to the next serialized packet. | 258 // Stores notifiers that should be attached to the next serialized packet. |
| 252 base::hash_set<QuicAckNotifier*> ack_notifiers_; | 259 base::hash_set<QuicAckNotifier*> ack_notifiers_; |
| 253 | 260 |
| 254 DISALLOW_COPY_AND_ASSIGN(QuicPacketGenerator); | 261 DISALLOW_COPY_AND_ASSIGN(QuicPacketGenerator); |
| 255 }; | 262 }; |
| 256 | 263 |
| 257 } // namespace net | 264 } // namespace net |
| 258 | 265 |
| 259 #endif // NET_QUIC_QUIC_PACKET_GENERATOR_H_ | 266 #endif // NET_QUIC_QUIC_PACKET_GENERATOR_H_ |
| OLD | NEW |