| 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 #include "net/quic/quic_packet_generator.h" | 5 #include "net/quic/quic_packet_generator.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "net/quic/quic_ack_notifier.h" | 9 #include "net/quic/quic_ack_notifier.h" |
| 10 #include "net/quic/quic_fec_group.h" | 10 #include "net/quic/quic_fec_group.h" |
| 11 #include "net/quic/quic_flags.h" | 11 #include "net/quic/quic_flags.h" |
| 12 #include "net/quic/quic_utils.h" | 12 #include "net/quic/quic_utils.h" |
| 13 | 13 |
| 14 using base::StringPiece; | 14 using base::StringPiece; |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 // We want to put some space between a protected packet and the FEC packet to | 20 // We want to put some space between a protected packet and the FEC packet to |
| 21 // avoid losing them both within the same loss episode. On the other hand, | 21 // avoid losing them both within the same loss episode. On the other hand, we |
| 22 // we expect to be able to recover from any loss in about an RTT. | 22 // expect to be able to recover from any loss in about an RTT. We resolve this |
| 23 // We resolve this tradeoff by sending an FEC packet atmost half an RTT, | 23 // tradeoff by sending an FEC packet atmost half an RTT, or equivalently, half |
| 24 // or equivalently, half the max number of in-flight packets, the first | 24 // the max number of in-flight packets, the first protected packet. Since we |
| 25 // protected packet. Since we don't want to delay an FEC packet past half an | 25 // don't want to delay an FEC packet past half an RTT, we set the max FEC group |
| 26 // RTT, we set the max FEC group size to be half the current congestion window. | 26 // size to be half the current congestion window. |
| 27 const float kMaxPacketsInFlightMultiplierForFecGroupSize = 0.5; | 27 const float kMaxPacketsInFlightMultiplierForFecGroupSize = 0.5; |
| 28 const float kRttMultiplierForFecTimeout = 0.5; | 28 const float kRttMultiplierForFecTimeout = 0.5; |
| 29 | 29 |
| 30 // Minimum timeout for FEC alarm, set to half the minimum Tail Loss Probe |
| 31 // timeout of 10ms. |
| 32 const int64 kMinFecTimeoutMs = 5u; |
| 33 |
| 30 } // namespace | 34 } // namespace |
| 31 | 35 |
| 32 class QuicAckNotifier; | 36 class QuicAckNotifier; |
| 33 | 37 |
| 34 QuicPacketGenerator::QuicPacketGenerator(QuicConnectionId connection_id, | 38 QuicPacketGenerator::QuicPacketGenerator(QuicConnectionId connection_id, |
| 35 QuicFramer* framer, | 39 QuicFramer* framer, |
| 36 QuicRandom* random_generator, | 40 QuicRandom* random_generator, |
| 37 DelegateInterface* delegate) | 41 DelegateInterface* delegate) |
| 38 : delegate_(delegate), | 42 : delegate_(delegate), |
| 39 debug_delegate_(nullptr), | 43 debug_delegate_(nullptr), |
| 40 packet_creator_(connection_id, framer, random_generator), | 44 packet_creator_(connection_id, framer, random_generator), |
| 41 batch_mode_(false), | 45 batch_mode_(false), |
| 42 fec_timeout_(QuicTime::Delta::Zero()), | 46 fec_timeout_(QuicTime::Delta::Zero()), |
| 43 should_fec_protect_(false), | 47 should_fec_protect_(false), |
| 44 should_send_ack_(false), | 48 should_send_ack_(false), |
| 45 should_send_feedback_(false), | |
| 46 should_send_stop_waiting_(false) { | 49 should_send_stop_waiting_(false) { |
| 47 } | 50 } |
| 48 | 51 |
| 49 QuicPacketGenerator::~QuicPacketGenerator() { | 52 QuicPacketGenerator::~QuicPacketGenerator() { |
| 50 for (QuicFrames::iterator it = queued_control_frames_.begin(); | 53 for (QuicFrames::iterator it = queued_control_frames_.begin(); |
| 51 it != queued_control_frames_.end(); ++it) { | 54 it != queued_control_frames_.end(); ++it) { |
| 52 switch (it->type) { | 55 switch (it->type) { |
| 53 case PADDING_FRAME: | 56 case PADDING_FRAME: |
| 54 delete it->padding_frame; | 57 delete it->padding_frame; |
| 55 break; | 58 break; |
| 56 case STREAM_FRAME: | 59 case STREAM_FRAME: |
| 57 delete it->stream_frame; | 60 delete it->stream_frame; |
| 58 break; | 61 break; |
| 59 case ACK_FRAME: | 62 case ACK_FRAME: |
| 60 delete it->ack_frame; | 63 delete it->ack_frame; |
| 61 break; | 64 break; |
| 62 case CONGESTION_FEEDBACK_FRAME: | |
| 63 delete it->congestion_feedback_frame; | |
| 64 break; | |
| 65 case RST_STREAM_FRAME: | 65 case RST_STREAM_FRAME: |
| 66 delete it->rst_stream_frame; | 66 delete it->rst_stream_frame; |
| 67 break; | 67 break; |
| 68 case CONNECTION_CLOSE_FRAME: | 68 case CONNECTION_CLOSE_FRAME: |
| 69 delete it->connection_close_frame; | 69 delete it->connection_close_frame; |
| 70 break; | 70 break; |
| 71 case GOAWAY_FRAME: | 71 case GOAWAY_FRAME: |
| 72 delete it->goaway_frame; | 72 delete it->goaway_frame; |
| 73 break; | 73 break; |
| 74 case WINDOW_UPDATE_FRAME: | 74 case WINDOW_UPDATE_FRAME: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 93 QuicPacketCount max_packets_in_flight) { | 93 QuicPacketCount max_packets_in_flight) { |
| 94 packet_creator_.set_max_packets_per_fec_group( | 94 packet_creator_.set_max_packets_per_fec_group( |
| 95 static_cast<size_t>(kMaxPacketsInFlightMultiplierForFecGroupSize * | 95 static_cast<size_t>(kMaxPacketsInFlightMultiplierForFecGroupSize * |
| 96 max_packets_in_flight)); | 96 max_packets_in_flight)); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void QuicPacketGenerator::OnRttChange(QuicTime::Delta rtt) { | 99 void QuicPacketGenerator::OnRttChange(QuicTime::Delta rtt) { |
| 100 fec_timeout_ = rtt.Multiply(kRttMultiplierForFecTimeout); | 100 fec_timeout_ = rtt.Multiply(kRttMultiplierForFecTimeout); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void QuicPacketGenerator::SetShouldSendAck(bool also_send_feedback, | 103 void QuicPacketGenerator::SetShouldSendAck(bool also_send_stop_waiting) { |
| 104 bool also_send_stop_waiting) { | 104 if (pending_ack_frame_ != nullptr) { |
| 105 if (FLAGS_quic_disallow_multiple_pending_ack_frames) { | 105 // Ack already queued, nothing to do. |
| 106 if (pending_ack_frame_ != nullptr) { | 106 return; |
| 107 // Ack already queued, nothing to do. | 107 } |
| 108 return; | |
| 109 } | |
| 110 | 108 |
| 111 if (also_send_feedback && pending_feedback_frame_ != nullptr) { | 109 if (also_send_stop_waiting && pending_stop_waiting_frame_ != nullptr) { |
| 112 LOG(DFATAL) << "Should only ever be one pending feedback frame."; | 110 LOG(DFATAL) << "Should only ever be one pending stop waiting frame."; |
| 113 return; | 111 return; |
| 114 } | |
| 115 | |
| 116 if (also_send_stop_waiting && pending_stop_waiting_frame_ != nullptr) { | |
| 117 LOG(DFATAL) << "Should only ever be one pending stop waiting frame."; | |
| 118 return; | |
| 119 } | |
| 120 } | 112 } |
| 121 | 113 |
| 122 should_send_ack_ = true; | 114 should_send_ack_ = true; |
| 123 should_send_feedback_ = also_send_feedback; | |
| 124 should_send_stop_waiting_ = also_send_stop_waiting; | 115 should_send_stop_waiting_ = also_send_stop_waiting; |
| 125 SendQueuedFrames(false); | 116 SendQueuedFrames(false); |
| 126 } | 117 } |
| 127 | 118 |
| 128 void QuicPacketGenerator::SetShouldSendStopWaiting() { | 119 void QuicPacketGenerator::SetShouldSendStopWaiting() { |
| 129 should_send_stop_waiting_ = true; | 120 should_send_stop_waiting_ = true; |
| 130 SendQueuedFrames(false); | 121 SendQueuedFrames(false); |
| 131 } | 122 } |
| 132 | 123 |
| 133 void QuicPacketGenerator::AddControlFrame(const QuicFrame& frame) { | 124 void QuicPacketGenerator::AddControlFrame(const QuicFrame& frame) { |
| 134 queued_control_frames_.push_back(frame); | 125 queued_control_frames_.push_back(frame); |
| 135 SendQueuedFrames(false); | 126 SendQueuedFrames(false); |
| 136 } | 127 } |
| 137 | 128 |
| 138 QuicConsumedData QuicPacketGenerator::ConsumeData( | 129 QuicConsumedData QuicPacketGenerator::ConsumeData( |
| 139 QuicStreamId id, | 130 QuicStreamId id, |
| 140 const IOVector& data_to_write, | 131 const IOVector& data_to_write, |
| 141 QuicStreamOffset offset, | 132 QuicStreamOffset offset, |
| 142 bool fin, | 133 bool fin, |
| 143 FecProtection fec_protection, | 134 FecProtection fec_protection, |
| 144 QuicAckNotifier::DelegateInterface* delegate) { | 135 QuicAckNotifier::DelegateInterface* delegate) { |
| 145 IsHandshake handshake = id == kCryptoStreamId ? IS_HANDSHAKE : NOT_HANDSHAKE; | 136 bool has_handshake = id == kCryptoStreamId; |
| 146 // To make reasoning about crypto frames easier, we don't combine them with | 137 // To make reasoning about crypto frames easier, we don't combine them with |
| 147 // other retransmittable frames in a single packet. | 138 // other retransmittable frames in a single packet. |
| 148 const bool flush = handshake == IS_HANDSHAKE && | 139 const bool flush = |
| 149 packet_creator_.HasPendingRetransmittableFrames(); | 140 has_handshake && packet_creator_.HasPendingRetransmittableFrames(); |
| 150 SendQueuedFrames(flush); | 141 SendQueuedFrames(flush); |
| 151 | 142 |
| 152 size_t total_bytes_consumed = 0; | 143 size_t total_bytes_consumed = 0; |
| 153 bool fin_consumed = false; | 144 bool fin_consumed = false; |
| 154 | 145 |
| 155 if (!packet_creator_.HasRoomForStreamFrame(id, offset)) { | 146 if (!packet_creator_.HasRoomForStreamFrame(id, offset)) { |
| 156 SerializeAndSendPacket(); | 147 SerializeAndSendPacket(); |
| 157 } | 148 } |
| 158 | 149 |
| 159 if (fec_protection == MUST_FEC_PROTECT) { | 150 if (fec_protection == MUST_FEC_PROTECT) { |
| 160 MaybeStartFecProtection(); | 151 MaybeStartFecProtection(); |
| 161 } | 152 } |
| 162 | 153 |
| 163 // This notifier will be owned by the AckNotifierManager (or deleted below) if | 154 // This notifier will be owned by the AckNotifierManager (or deleted below) if |
| 164 // not attached to a packet. | 155 // not attached to a packet. |
| 165 QuicAckNotifier* notifier = nullptr; | 156 QuicAckNotifier* notifier = nullptr; |
| 166 if (delegate != nullptr) { | 157 if (delegate != nullptr) { |
| 167 notifier = new QuicAckNotifier(delegate); | 158 notifier = new QuicAckNotifier(delegate); |
| 168 } | 159 } |
| 169 | 160 |
| 170 IOVector data = data_to_write; | 161 IOVector data = data_to_write; |
| 171 size_t data_size = data.TotalBufferSize(); | 162 size_t data_size = data.TotalBufferSize(); |
| 172 if (FLAGS_quic_empty_data_no_fin_early_return && !fin && (data_size == 0)) { | 163 if (!fin && (data_size == 0)) { |
| 173 LOG(DFATAL) << "Attempt to consume empty data without FIN."; | 164 LOG(DFATAL) << "Attempt to consume empty data without FIN."; |
| 174 return QuicConsumedData(0, false); | 165 return QuicConsumedData(0, false); |
| 175 } | 166 } |
| 176 | 167 |
| 177 int frames_created = 0; | 168 int frames_created = 0; |
| 178 while (delegate_->ShouldGeneratePacket(NOT_RETRANSMISSION, | 169 while (delegate_->ShouldGeneratePacket( |
| 179 HAS_RETRANSMITTABLE_DATA, handshake)) { | 170 NOT_RETRANSMISSION, HAS_RETRANSMITTABLE_DATA, |
| 171 has_handshake ? IS_HANDSHAKE : NOT_HANDSHAKE)) { |
| 180 QuicFrame frame; | 172 QuicFrame frame; |
| 181 size_t bytes_consumed = packet_creator_.CreateStreamFrame( | 173 size_t bytes_consumed = packet_creator_.CreateStreamFrame( |
| 182 id, data, offset + total_bytes_consumed, fin, &frame); | 174 id, data, offset + total_bytes_consumed, fin, &frame); |
| 183 ++frames_created; | 175 ++frames_created; |
| 184 | 176 |
| 185 // We want to track which packet this stream frame ends up in. | 177 // We want to track which packet this stream frame ends up in. |
| 186 if (FLAGS_quic_attach_ack_notifiers_to_packets) { | 178 if (FLAGS_quic_attach_ack_notifiers_to_packets) { |
| 187 if (notifier != nullptr) { | 179 if (notifier != nullptr) { |
| 188 ack_notifiers_.insert(notifier); | 180 ack_notifiers_.insert(notifier); |
| 189 } | 181 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 break; | 214 break; |
| 223 } | 215 } |
| 224 } | 216 } |
| 225 | 217 |
| 226 if (notifier != nullptr && frames_created == 0) { | 218 if (notifier != nullptr && frames_created == 0) { |
| 227 // Safe to delete the AckNotifer as it was never attached to a packet. | 219 // Safe to delete the AckNotifer as it was never attached to a packet. |
| 228 delete notifier; | 220 delete notifier; |
| 229 } | 221 } |
| 230 | 222 |
| 231 // Don't allow the handshake to be bundled with other retransmittable frames. | 223 // Don't allow the handshake to be bundled with other retransmittable frames. |
| 232 if (handshake == IS_HANDSHAKE) { | 224 if (has_handshake) { |
| 233 SendQueuedFrames(true); | 225 SendQueuedFrames(true); |
| 234 } | 226 } |
| 235 | 227 |
| 236 // Try to close FEC group since we've either run out of data to send or we're | 228 // Try to close FEC group since we've either run out of data to send or we're |
| 237 // blocked. If not in batch mode, force close the group. | 229 // blocked. If not in batch mode, force close the group. |
| 238 // TODO(jri): This method should be called with flush=false here | 230 MaybeSendFecPacketAndCloseGroup(/*flush=*/false); |
| 239 // once the timer-based FEC sending is done, to separate FEC sending from | |
| 240 // the end of batch operations. | |
| 241 MaybeSendFecPacketAndCloseGroup(!InBatchMode()); | |
| 242 | 231 |
| 243 DCHECK(InBatchMode() || !packet_creator_.HasPendingFrames()); | 232 DCHECK(InBatchMode() || !packet_creator_.HasPendingFrames()); |
| 244 return QuicConsumedData(total_bytes_consumed, fin_consumed); | 233 return QuicConsumedData(total_bytes_consumed, fin_consumed); |
| 245 } | 234 } |
| 246 | 235 |
| 247 bool QuicPacketGenerator::CanSendWithNextPendingFrameAddition() const { | 236 bool QuicPacketGenerator::CanSendWithNextPendingFrameAddition() const { |
| 248 DCHECK(HasPendingFrames()); | 237 DCHECK(HasPendingFrames()); |
| 249 HasRetransmittableData retransmittable = | 238 HasRetransmittableData retransmittable = |
| 250 (should_send_ack_ || should_send_feedback_ || should_send_stop_waiting_) | 239 (should_send_ack_ || should_send_stop_waiting_) |
| 251 ? NO_RETRANSMITTABLE_DATA : HAS_RETRANSMITTABLE_DATA; | 240 ? NO_RETRANSMITTABLE_DATA |
| 241 : HAS_RETRANSMITTABLE_DATA; |
| 252 if (retransmittable == HAS_RETRANSMITTABLE_DATA) { | 242 if (retransmittable == HAS_RETRANSMITTABLE_DATA) { |
| 253 DCHECK(!queued_control_frames_.empty()); // These are retransmittable. | 243 DCHECK(!queued_control_frames_.empty()); // These are retransmittable. |
| 254 } | 244 } |
| 255 return delegate_->ShouldGeneratePacket(NOT_RETRANSMISSION, retransmittable, | 245 return delegate_->ShouldGeneratePacket(NOT_RETRANSMISSION, retransmittable, |
| 256 NOT_HANDSHAKE); | 246 NOT_HANDSHAKE); |
| 257 } | 247 } |
| 258 | 248 |
| 259 void QuicPacketGenerator::SendQueuedFrames(bool flush) { | 249 void QuicPacketGenerator::SendQueuedFrames(bool flush) { |
| 260 // Only add pending frames if we are SURE we can then send the whole packet. | 250 // Only add pending frames if we are SURE we can then send the whole packet. |
| 261 while (HasPendingFrames() && | 251 while (HasPendingFrames() && |
| 262 (flush || CanSendWithNextPendingFrameAddition())) { | 252 (flush || CanSendWithNextPendingFrameAddition())) { |
| 263 if (!AddNextPendingFrame()) { | 253 if (!AddNextPendingFrame()) { |
| 264 // Packet was full, so serialize and send it. | 254 // Packet was full, so serialize and send it. |
| 265 SerializeAndSendPacket(); | 255 SerializeAndSendPacket(); |
| 266 } | 256 } |
| 267 } | 257 } |
| 268 | 258 if (packet_creator_.HasPendingFrames() && (flush || !InBatchMode())) { |
| 269 if (!InBatchMode() || flush) { | 259 SerializeAndSendPacket(); |
| 270 if (packet_creator_.HasPendingFrames()) { | |
| 271 SerializeAndSendPacket(); | |
| 272 } | |
| 273 // Ensure the FEC group is closed at the end of this method unless other | |
| 274 // writes are pending. | |
| 275 MaybeSendFecPacketAndCloseGroup(true); | |
| 276 } | 260 } |
| 261 MaybeSendFecPacketAndCloseGroup(flush); |
| 277 } | 262 } |
| 278 | 263 |
| 279 void QuicPacketGenerator::MaybeStartFecProtection() { | 264 void QuicPacketGenerator::MaybeStartFecProtection() { |
| 280 if (!packet_creator_.IsFecEnabled()) { | 265 if (!packet_creator_.IsFecEnabled()) { |
| 281 return; | 266 return; |
| 282 } | 267 } |
| 283 DVLOG(1) << "Turning FEC protection ON"; | 268 DVLOG(1) << "Turning FEC protection ON"; |
| 284 should_fec_protect_ = true; | 269 should_fec_protect_ = true; |
| 285 if (packet_creator_.IsFecProtected()) { | 270 if (packet_creator_.IsFecProtected()) { |
| 286 // Only start creator's FEC protection if not already on. | 271 // Only start creator's FEC protection if not already on. |
| 287 return; | 272 return; |
| 288 } | 273 } |
| 289 if (HasQueuedFrames()) { | 274 if (HasQueuedFrames()) { |
| 290 // TODO(jri): This currently requires that the generator flush out any | 275 // TODO(jri): This currently requires that the generator flush out any |
| 291 // pending frames when FEC protection is turned on. If current packet can be | 276 // pending frames when FEC protection is turned on. If current packet can be |
| 292 // converted to an FEC protected packet, do it. This will require the | 277 // converted to an FEC protected packet, do it. This will require the |
| 293 // generator to check if the resulting expansion still allows the incoming | 278 // generator to check if the resulting expansion still allows the incoming |
| 294 // frame to be added to the packet. | 279 // frame to be added to the packet. |
| 295 SendQueuedFrames(true); | 280 SendQueuedFrames(true); |
| 296 } | 281 } |
| 297 packet_creator_.StartFecProtectingPackets(); | 282 packet_creator_.StartFecProtectingPackets(); |
| 298 DCHECK(packet_creator_.IsFecProtected()); | 283 DCHECK(packet_creator_.IsFecProtected()); |
| 299 } | 284 } |
| 300 | 285 |
| 301 void QuicPacketGenerator::MaybeSendFecPacketAndCloseGroup(bool force) { | 286 void QuicPacketGenerator::MaybeSendFecPacketAndCloseGroup(bool force) { |
| 302 if (!packet_creator_.IsFecProtected() || | 287 if (!ShouldSendFecPacket(force)) { |
| 303 packet_creator_.HasPendingFrames() || | |
| 304 !packet_creator_.ShouldSendFec(force)) { | |
| 305 return; | 288 return; |
| 306 } | 289 } |
| 307 // TODO(jri): SerializeFec can return a NULL packet, and this should | 290 // TODO(jri): SerializeFec can return a NULL packet, and this should |
| 308 // cause an early return, with a call to delegate_->OnPacketGenerationError. | 291 // cause an early return, with a call to delegate_->OnPacketGenerationError. |
| 309 SerializedPacket serialized_fec = packet_creator_.SerializeFec(); | 292 SerializedPacket serialized_fec = packet_creator_.SerializeFec(); |
| 310 DCHECK(serialized_fec.packet); | 293 DCHECK(serialized_fec.packet); |
| 311 delegate_->OnSerializedPacket(serialized_fec); | 294 delegate_->OnSerializedPacket(serialized_fec); |
| 312 // Turn FEC protection off if creator's protection is on and the creator | 295 // Turn FEC protection off if creator's protection is on and the creator |
| 313 // does not have an open FEC group. | 296 // does not have an open FEC group. |
| 314 // Note: We only wait until the frames queued in the creator are flushed; | 297 // Note: We only wait until the frames queued in the creator are flushed; |
| 315 // pending frames in the generator will not keep us from turning FEC off. | 298 // pending frames in the generator will not keep us from turning FEC off. |
| 316 if (!should_fec_protect_ && !packet_creator_.IsFecGroupOpen()) { | 299 if (!should_fec_protect_ && !packet_creator_.IsFecGroupOpen()) { |
| 317 packet_creator_.StopFecProtectingPackets(); | 300 packet_creator_.StopFecProtectingPackets(); |
| 318 DCHECK(!packet_creator_.IsFecProtected()); | 301 DCHECK(!packet_creator_.IsFecProtected()); |
| 319 } | 302 } |
| 320 } | 303 } |
| 321 | 304 |
| 305 bool QuicPacketGenerator::ShouldSendFecPacket(bool force) { |
| 306 return packet_creator_.IsFecProtected() && |
| 307 !packet_creator_.HasPendingFrames() && |
| 308 packet_creator_.ShouldSendFec(force); |
| 309 } |
| 310 |
| 311 void QuicPacketGenerator::OnFecTimeout() { |
| 312 DCHECK(!InBatchMode()); |
| 313 if (!ShouldSendFecPacket(true)) { |
| 314 LOG(DFATAL) << "No FEC packet to send on FEC timeout."; |
| 315 return; |
| 316 } |
| 317 // Flush out any pending frames in the generator and the creator, and then |
| 318 // send out FEC packet. |
| 319 SendQueuedFrames(true); |
| 320 MaybeSendFecPacketAndCloseGroup(/*flush=*/true); |
| 321 } |
| 322 |
| 323 QuicTime::Delta QuicPacketGenerator::GetFecTimeout( |
| 324 QuicPacketSequenceNumber sequence_number) { |
| 325 // Do not set up FEC alarm for |sequence_number| it is not the first packet in |
| 326 // the current group. |
| 327 if (packet_creator_.IsFecGroupOpen() && |
| 328 (sequence_number == packet_creator_.fec_group_number())) { |
| 329 return QuicTime::Delta::Max( |
| 330 fec_timeout_, QuicTime::Delta::FromMilliseconds(kMinFecTimeoutMs)); |
| 331 } |
| 332 return QuicTime::Delta::Infinite(); |
| 333 } |
| 334 |
| 322 bool QuicPacketGenerator::InBatchMode() { | 335 bool QuicPacketGenerator::InBatchMode() { |
| 323 return batch_mode_; | 336 return batch_mode_; |
| 324 } | 337 } |
| 325 | 338 |
| 326 void QuicPacketGenerator::StartBatchOperations() { | 339 void QuicPacketGenerator::StartBatchOperations() { |
| 327 batch_mode_ = true; | 340 batch_mode_ = true; |
| 328 } | 341 } |
| 329 | 342 |
| 330 void QuicPacketGenerator::FinishBatchOperations() { | 343 void QuicPacketGenerator::FinishBatchOperations() { |
| 331 batch_mode_ = false; | 344 batch_mode_ = false; |
| 332 SendQueuedFrames(false); | 345 SendQueuedFrames(false); |
| 333 } | 346 } |
| 334 | 347 |
| 335 void QuicPacketGenerator::FlushAllQueuedFrames() { | 348 void QuicPacketGenerator::FlushAllQueuedFrames() { |
| 336 SendQueuedFrames(true); | 349 SendQueuedFrames(true); |
| 337 } | 350 } |
| 338 | 351 |
| 339 bool QuicPacketGenerator::HasQueuedFrames() const { | 352 bool QuicPacketGenerator::HasQueuedFrames() const { |
| 340 return packet_creator_.HasPendingFrames() || HasPendingFrames(); | 353 return packet_creator_.HasPendingFrames() || HasPendingFrames(); |
| 341 } | 354 } |
| 342 | 355 |
| 343 bool QuicPacketGenerator::HasPendingFrames() const { | 356 bool QuicPacketGenerator::HasPendingFrames() const { |
| 344 return should_send_ack_ || should_send_feedback_ || | 357 return should_send_ack_ || should_send_stop_waiting_ || |
| 345 should_send_stop_waiting_ || !queued_control_frames_.empty(); | 358 !queued_control_frames_.empty(); |
| 346 } | 359 } |
| 347 | 360 |
| 348 bool QuicPacketGenerator::AddNextPendingFrame() { | 361 bool QuicPacketGenerator::AddNextPendingFrame() { |
| 349 if (should_send_ack_) { | 362 if (should_send_ack_) { |
| 350 pending_ack_frame_.reset(delegate_->CreateAckFrame()); | 363 pending_ack_frame_.reset(delegate_->CreateAckFrame()); |
| 351 // If we can't this add the frame now, then we still need to do so later. | 364 // If we can't this add the frame now, then we still need to do so later. |
| 352 should_send_ack_ = !AddFrame(QuicFrame(pending_ack_frame_.get())); | 365 should_send_ack_ = !AddFrame(QuicFrame(pending_ack_frame_.get())); |
| 353 // Return success if we have cleared out this flag (i.e., added the frame). | 366 // Return success if we have cleared out this flag (i.e., added the frame). |
| 354 // If we still need to send, then the frame is full, and we have failed. | 367 // If we still need to send, then the frame is full, and we have failed. |
| 355 return !should_send_ack_; | 368 return !should_send_ack_; |
| 356 } | 369 } |
| 357 | 370 |
| 358 if (should_send_feedback_) { | |
| 359 pending_feedback_frame_.reset(delegate_->CreateFeedbackFrame()); | |
| 360 // If we can't this add the frame now, then we still need to do so later. | |
| 361 should_send_feedback_ = !AddFrame(QuicFrame(pending_feedback_frame_.get())); | |
| 362 // Return success if we have cleared out this flag (i.e., added the frame). | |
| 363 // If we still need to send, then the frame is full, and we have failed. | |
| 364 return !should_send_feedback_; | |
| 365 } | |
| 366 | |
| 367 if (should_send_stop_waiting_) { | 371 if (should_send_stop_waiting_) { |
| 368 pending_stop_waiting_frame_.reset(delegate_->CreateStopWaitingFrame()); | 372 pending_stop_waiting_frame_.reset(delegate_->CreateStopWaitingFrame()); |
| 369 // If we can't this add the frame now, then we still need to do so later. | 373 // If we can't this add the frame now, then we still need to do so later. |
| 370 should_send_stop_waiting_ = | 374 should_send_stop_waiting_ = |
| 371 !AddFrame(QuicFrame(pending_stop_waiting_frame_.get())); | 375 !AddFrame(QuicFrame(pending_stop_waiting_frame_.get())); |
| 372 // Return success if we have cleared out this flag (i.e., added the frame). | 376 // Return success if we have cleared out this flag (i.e., added the frame). |
| 373 // If we still need to send, then the frame is full, and we have failed. | 377 // If we still need to send, then the frame is full, and we have failed. |
| 374 return !should_send_stop_waiting_; | 378 return !should_send_stop_waiting_; |
| 375 } | 379 } |
| 376 | 380 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 396 SerializedPacket serialized_packet = packet_creator_.SerializePacket(); | 400 SerializedPacket serialized_packet = packet_creator_.SerializePacket(); |
| 397 DCHECK(serialized_packet.packet); | 401 DCHECK(serialized_packet.packet); |
| 398 | 402 |
| 399 // There may be AckNotifiers interested in this packet. | 403 // There may be AckNotifiers interested in this packet. |
| 400 if (FLAGS_quic_attach_ack_notifiers_to_packets) { | 404 if (FLAGS_quic_attach_ack_notifiers_to_packets) { |
| 401 serialized_packet.notifiers.swap(ack_notifiers_); | 405 serialized_packet.notifiers.swap(ack_notifiers_); |
| 402 ack_notifiers_.clear(); | 406 ack_notifiers_.clear(); |
| 403 } | 407 } |
| 404 | 408 |
| 405 delegate_->OnSerializedPacket(serialized_packet); | 409 delegate_->OnSerializedPacket(serialized_packet); |
| 406 MaybeSendFecPacketAndCloseGroup(false); | 410 MaybeSendFecPacketAndCloseGroup(/*flush=*/false); |
| 407 | 411 |
| 408 // The packet has now been serialized, safe to delete pending frames. | 412 // The packet has now been serialized, safe to delete pending frames. |
| 409 if (FLAGS_quic_disallow_multiple_pending_ack_frames) { | 413 pending_ack_frame_.reset(); |
| 410 pending_ack_frame_.reset(); | 414 pending_stop_waiting_frame_.reset(); |
| 411 pending_feedback_frame_.reset(); | |
| 412 pending_stop_waiting_frame_.reset(); | |
| 413 } | |
| 414 } | 415 } |
| 415 | 416 |
| 416 void QuicPacketGenerator::StopSendingVersion() { | 417 void QuicPacketGenerator::StopSendingVersion() { |
| 417 packet_creator_.StopSendingVersion(); | 418 packet_creator_.StopSendingVersion(); |
| 418 } | 419 } |
| 419 | 420 |
| 420 QuicPacketSequenceNumber QuicPacketGenerator::sequence_number() const { | 421 QuicPacketSequenceNumber QuicPacketGenerator::sequence_number() const { |
| 421 return packet_creator_.sequence_number(); | 422 return packet_creator_.sequence_number(); |
| 422 } | 423 } |
| 423 | 424 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 packet_creator_.set_connection_id_length(PACKET_8BYTE_CONNECTION_ID); | 459 packet_creator_.set_connection_id_length(PACKET_8BYTE_CONNECTION_ID); |
| 459 } | 460 } |
| 460 } | 461 } |
| 461 | 462 |
| 462 | 463 |
| 463 void QuicPacketGenerator::set_encryption_level(EncryptionLevel level) { | 464 void QuicPacketGenerator::set_encryption_level(EncryptionLevel level) { |
| 464 packet_creator_.set_encryption_level(level); | 465 packet_creator_.set_encryption_level(level); |
| 465 } | 466 } |
| 466 | 467 |
| 467 } // namespace net | 468 } // namespace net |
| OLD | NEW |