OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_sent_packet_manager.h" | 5 #include "net/quic/quic_sent_packet_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 } | 137 } |
138 } | 138 } |
139 | 139 |
140 // TODO(ianswett): Combine this method with OnPacketSent once packets are always | 140 // TODO(ianswett): Combine this method with OnPacketSent once packets are always |
141 // sent in order and the connection tracks RetransmittableFrames for longer. | 141 // sent in order and the connection tracks RetransmittableFrames for longer. |
142 void QuicSentPacketManager::OnSerializedPacket( | 142 void QuicSentPacketManager::OnSerializedPacket( |
143 const SerializedPacket& serialized_packet) { | 143 const SerializedPacket& serialized_packet) { |
144 if (serialized_packet.retransmittable_frames) { | 144 if (serialized_packet.retransmittable_frames) { |
145 ack_notifier_manager_.OnSerializedPacket(serialized_packet); | 145 ack_notifier_manager_.OnSerializedPacket(serialized_packet); |
146 } | 146 } |
| 147 unacked_packets_.AddPacket(serialized_packet); |
147 | 148 |
148 unacked_packets_.AddPacket(serialized_packet); | 149 if (debug_delegate_ != NULL) { |
| 150 debug_delegate_->OnSerializedPacket(serialized_packet); |
| 151 } |
149 } | 152 } |
150 | 153 |
151 void QuicSentPacketManager::OnRetransmittedPacket( | 154 void QuicSentPacketManager::OnRetransmittedPacket( |
152 QuicPacketSequenceNumber old_sequence_number, | 155 QuicPacketSequenceNumber old_sequence_number, |
153 QuicPacketSequenceNumber new_sequence_number) { | 156 QuicPacketSequenceNumber new_sequence_number) { |
154 TransmissionType transmission_type; | 157 TransmissionType transmission_type; |
155 PendingRetransmissionMap::iterator it = | 158 PendingRetransmissionMap::iterator it = |
156 pending_retransmissions_.find(old_sequence_number); | 159 pending_retransmissions_.find(old_sequence_number); |
157 if (it != pending_retransmissions_.end()) { | 160 if (it != pending_retransmissions_.end()) { |
158 transmission_type = it->second; | 161 transmission_type = it->second; |
(...skipping 28 matching lines...) Expand all Loading... |
187 UpdatePacketInformationReceivedByPeer(ack_frame); | 190 UpdatePacketInformationReceivedByPeer(ack_frame); |
188 // We rely on delta_time_largest_observed to compute an RTT estimate, so | 191 // We rely on delta_time_largest_observed to compute an RTT estimate, so |
189 // we only update rtt when the largest observed gets acked. | 192 // we only update rtt when the largest observed gets acked. |
190 bool largest_observed_acked = MaybeUpdateRTT(ack_frame, ack_receive_time); | 193 bool largest_observed_acked = MaybeUpdateRTT(ack_frame, ack_receive_time); |
191 DCHECK_GE(ack_frame.largest_observed, unacked_packets_.largest_observed()); | 194 DCHECK_GE(ack_frame.largest_observed, unacked_packets_.largest_observed()); |
192 unacked_packets_.IncreaseLargestObserved(ack_frame.largest_observed); | 195 unacked_packets_.IncreaseLargestObserved(ack_frame.largest_observed); |
193 | 196 |
194 HandleAckForSentPackets(ack_frame); | 197 HandleAckForSentPackets(ack_frame); |
195 InvokeLossDetection(ack_receive_time); | 198 InvokeLossDetection(ack_receive_time); |
196 MaybeInvokeCongestionEvent(largest_observed_acked, bytes_in_flight); | 199 MaybeInvokeCongestionEvent(largest_observed_acked, bytes_in_flight); |
| 200 unacked_packets_.RemoveObsoletePackets(); |
197 | 201 |
198 sustained_bandwidth_recorder_.RecordEstimate( | 202 sustained_bandwidth_recorder_.RecordEstimate( |
199 send_algorithm_->InRecovery(), | 203 send_algorithm_->InRecovery(), |
200 send_algorithm_->InSlowStart(), | 204 send_algorithm_->InSlowStart(), |
201 send_algorithm_->BandwidthEstimate(), | 205 send_algorithm_->BandwidthEstimate(), |
202 ack_receive_time, | 206 ack_receive_time, |
203 clock_->WallNow(), | 207 clock_->WallNow(), |
204 rtt_stats_.SmoothedRtt()); | 208 rtt_stats_.SmoothedRtt()); |
205 | 209 |
206 // If we have received a truncated ack, then we need to clear out some | 210 // If we have received a truncated ack, then we need to clear out some |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 network_change_visitor_->OnCongestionWindowChange(GetCongestionWindow()); | 254 network_change_visitor_->OnCongestionWindowChange(GetCongestionWindow()); |
251 } | 255 } |
252 } | 256 } |
253 | 257 |
254 void QuicSentPacketManager::HandleAckForSentPackets( | 258 void QuicSentPacketManager::HandleAckForSentPackets( |
255 const QuicAckFrame& ack_frame) { | 259 const QuicAckFrame& ack_frame) { |
256 // Go through the packets we have not received an ack for and see if this | 260 // Go through the packets we have not received an ack for and see if this |
257 // incoming_ack shows they've been seen by the peer. | 261 // incoming_ack shows they've been seen by the peer. |
258 QuicTime::Delta delta_largest_observed = | 262 QuicTime::Delta delta_largest_observed = |
259 ack_frame.delta_time_largest_observed; | 263 ack_frame.delta_time_largest_observed; |
260 QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); | 264 QuicPacketSequenceNumber sequence_number = unacked_packets_.GetLeastUnacked(); |
261 while (it != unacked_packets_.end()) { | 265 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
262 QuicPacketSequenceNumber sequence_number = it->first; | 266 it != unacked_packets_.end(); ++it, ++sequence_number) { |
263 if (sequence_number > ack_frame.largest_observed) { | 267 if (sequence_number > ack_frame.largest_observed) { |
264 // These packets are still in flight. | 268 // These packets are still in flight. |
265 break; | 269 break; |
266 } | 270 } |
267 | 271 |
268 if (IsAwaitingPacket(ack_frame, sequence_number)) { | 272 if (ContainsKey(ack_frame.missing_packets, sequence_number)) { |
269 // Consider it multiple nacks when there is a gap between the missing | 273 // Consider it multiple nacks when there is a gap between the missing |
270 // packet and the largest observed, since the purpose of a nack | 274 // packet and the largest observed, since the purpose of a nack |
271 // threshold is to tolerate re-ordering. This handles both StretchAcks | 275 // threshold is to tolerate re-ordering. This handles both StretchAcks |
272 // and Forward Acks. | 276 // and Forward Acks. |
273 // The nack count only increases when the largest observed increases. | 277 // The nack count only increases when the largest observed increases. |
274 size_t min_nacks = ack_frame.largest_observed - sequence_number; | 278 size_t min_nacks = ack_frame.largest_observed - sequence_number; |
275 // Truncated acks can nack the largest observed, so use a min of 1. | 279 // Truncated acks can nack the largest observed, so use a min of 1. |
276 if (min_nacks == 0) { | 280 if (min_nacks == 0) { |
277 min_nacks = 1; | 281 min_nacks = 1; |
278 } | 282 } |
279 unacked_packets_.NackPacket(sequence_number, min_nacks); | 283 unacked_packets_.NackPacket(sequence_number, min_nacks); |
280 ++it; | |
281 continue; | 284 continue; |
282 } | 285 } |
283 // Packet was acked, so remove it from our unacked packet list. | 286 // Packet was acked, so remove it from our unacked packet list. |
284 DVLOG(1) << ENDPOINT << "Got an ack for packet " << sequence_number; | 287 DVLOG(1) << ENDPOINT << "Got an ack for packet " << sequence_number; |
285 // If data is associated with the most recent transmission of this | 288 // If data is associated with the most recent transmission of this |
286 // packet, then inform the caller. | 289 // packet, then inform the caller. |
287 if (it->second.in_flight) { | 290 if (it->in_flight) { |
288 packets_acked_[sequence_number] = it->second; | 291 packets_acked_[sequence_number] = *it; |
289 } | 292 } |
290 it = MarkPacketHandled(it, delta_largest_observed); | 293 MarkPacketHandled(sequence_number, *it, delta_largest_observed); |
291 } | 294 } |
292 | 295 |
293 // Discard any retransmittable frames associated with revived packets. | 296 // Discard any retransmittable frames associated with revived packets. |
294 for (SequenceNumberSet::const_iterator revived_it = | 297 for (SequenceNumberSet::const_iterator revived_it = |
295 ack_frame.revived_packets.begin(); | 298 ack_frame.revived_packets.begin(); |
296 revived_it != ack_frame.revived_packets.end(); ++revived_it) { | 299 revived_it != ack_frame.revived_packets.end(); ++revived_it) { |
297 MarkPacketRevived(*revived_it, delta_largest_observed); | 300 MarkPacketRevived(*revived_it, delta_largest_observed); |
298 } | 301 } |
299 } | 302 } |
300 | 303 |
301 bool QuicSentPacketManager::HasRetransmittableFrames( | 304 bool QuicSentPacketManager::HasRetransmittableFrames( |
302 QuicPacketSequenceNumber sequence_number) const { | 305 QuicPacketSequenceNumber sequence_number) const { |
303 return unacked_packets_.HasRetransmittableFrames(sequence_number); | 306 return unacked_packets_.HasRetransmittableFrames(sequence_number); |
304 } | 307 } |
305 | 308 |
306 void QuicSentPacketManager::RetransmitUnackedPackets( | 309 void QuicSentPacketManager::RetransmitUnackedPackets( |
307 RetransmissionType retransmission_type) { | 310 RetransmissionType retransmission_type) { |
308 QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); | 311 QuicPacketSequenceNumber sequence_number = unacked_packets_.GetLeastUnacked(); |
309 while (it != unacked_packets_.end()) { | 312 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
310 const RetransmittableFrames* frames = it->second.retransmittable_frames; | 313 it != unacked_packets_.end(); ++it, ++sequence_number) { |
| 314 const RetransmittableFrames* frames = it->retransmittable_frames; |
311 // TODO(ianswett): Consider adding a new retransmission type which removes | 315 // TODO(ianswett): Consider adding a new retransmission type which removes |
312 // all these old packets from unacked and retransmits them as new sequence | 316 // all these old packets from unacked and retransmits them as new sequence |
313 // numbers with no connection to the previous ones. | 317 // numbers with no connection to the previous ones. |
314 if (frames != NULL && (retransmission_type == ALL_PACKETS || | 318 if (frames != NULL && (retransmission_type == ALL_PACKETS || |
315 frames->encryption_level() == ENCRYPTION_INITIAL)) { | 319 frames->encryption_level() == ENCRYPTION_INITIAL)) { |
316 MarkForRetransmission(it->first, ALL_UNACKED_RETRANSMISSION); | 320 MarkForRetransmission(sequence_number, ALL_UNACKED_RETRANSMISSION); |
317 } | 321 } |
318 ++it; | |
319 } | 322 } |
320 } | 323 } |
321 | 324 |
322 void QuicSentPacketManager::NeuterUnencryptedPackets() { | 325 void QuicSentPacketManager::NeuterUnencryptedPackets() { |
323 QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); | 326 QuicPacketSequenceNumber sequence_number = unacked_packets_.GetLeastUnacked(); |
324 while (it != unacked_packets_.end()) { | 327 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
325 const RetransmittableFrames* frames = it->second.retransmittable_frames; | 328 it != unacked_packets_.end(); ++it, ++sequence_number) { |
326 QuicPacketSequenceNumber sequence_number = it->first; | 329 const RetransmittableFrames* frames = it->retransmittable_frames; |
327 ++it; | |
328 if (frames != NULL && frames->encryption_level() == ENCRYPTION_NONE) { | 330 if (frames != NULL && frames->encryption_level() == ENCRYPTION_NONE) { |
329 // Once you're forward secure, no unencrypted packets will be sent, crypto | 331 // Once you're forward secure, no unencrypted packets will be sent, crypto |
330 // or otherwise. Unencrypted packets are neutered and abandoned, to ensure | 332 // or otherwise. Unencrypted packets are neutered and abandoned, to ensure |
331 // they are not retransmitted or considered lost from a congestion control | 333 // they are not retransmitted or considered lost from a congestion control |
332 // perspective. | 334 // perspective. |
333 pending_retransmissions_.erase(sequence_number); | 335 pending_retransmissions_.erase(sequence_number); |
334 unacked_packets_.RemoveFromInFlight(sequence_number); | 336 unacked_packets_.RemoveFromInFlight(sequence_number); |
335 // RemoveRetransmittibility is safe because only the newest sequence | |
336 // number can have frames. | |
337 unacked_packets_.RemoveRetransmittability(sequence_number); | 337 unacked_packets_.RemoveRetransmittability(sequence_number); |
338 } | 338 } |
339 } | 339 } |
340 } | 340 } |
341 | 341 |
342 void QuicSentPacketManager::MarkForRetransmission( | 342 void QuicSentPacketManager::MarkForRetransmission( |
343 QuicPacketSequenceNumber sequence_number, | 343 QuicPacketSequenceNumber sequence_number, |
344 TransmissionType transmission_type) { | 344 TransmissionType transmission_type) { |
345 const TransmissionInfo& transmission_info = | 345 const TransmissionInfo& transmission_info = |
346 unacked_packets_.GetTransmissionInfo(sequence_number); | 346 unacked_packets_.GetTransmissionInfo(sequence_number); |
347 LOG_IF(DFATAL, transmission_info.retransmittable_frames == NULL); | 347 LOG_IF(DFATAL, transmission_info.retransmittable_frames == NULL); |
348 if (transmission_type != TLP_RETRANSMISSION) { | 348 if (transmission_type != TLP_RETRANSMISSION) { |
349 unacked_packets_.RemoveFromInFlight(sequence_number); | 349 unacked_packets_.RemoveFromInFlight(sequence_number); |
350 } | 350 } |
351 // TODO(ianswett): Currently the RTO can fire while there are pending NACK | 351 // TODO(ianswett): Currently the RTO can fire while there are pending NACK |
352 // retransmissions for the same data, which is not ideal. | 352 // retransmissions for the same data, which is not ideal. |
353 if (ContainsKey(pending_retransmissions_, sequence_number)) { | 353 if (ContainsKey(pending_retransmissions_, sequence_number)) { |
354 return; | 354 return; |
355 } | 355 } |
356 | 356 |
357 pending_retransmissions_[sequence_number] = transmission_type; | 357 pending_retransmissions_[sequence_number] = transmission_type; |
358 } | 358 } |
359 | 359 |
360 void QuicSentPacketManager::RecordSpuriousRetransmissions( | 360 void QuicSentPacketManager::RecordSpuriousRetransmissions( |
361 const SequenceNumberSet& all_transmissions, | 361 const SequenceNumberList& all_transmissions, |
362 QuicPacketSequenceNumber acked_sequence_number) { | 362 QuicPacketSequenceNumber acked_sequence_number) { |
363 if (acked_sequence_number < first_rto_transmission_) { | 363 if (acked_sequence_number < first_rto_transmission_) { |
364 // Cancel all pending RTO transmissions and restore their in flight status. | 364 // Cancel all pending RTO transmissions and restore their in flight status. |
365 // Replace SRTT with latest_rtt and increase the variance to prevent | 365 // Replace SRTT with latest_rtt and increase the variance to prevent |
366 // a spurious RTO from happening again. | 366 // a spurious RTO from happening again. |
367 rtt_stats_.ExpireSmoothedMetrics(); | 367 rtt_stats_.ExpireSmoothedMetrics(); |
368 for (PendingRetransmissionMap::const_iterator it = | 368 for (PendingRetransmissionMap::const_iterator it = |
369 pending_retransmissions_.begin(); | 369 pending_retransmissions_.begin(); |
370 it != pending_retransmissions_.end(); ++it) { | 370 it != pending_retransmissions_.end(); ++it) { |
371 DCHECK_EQ(it->second, RTO_RETRANSMISSION); | 371 DCHECK_EQ(it->second, RTO_RETRANSMISSION); |
372 unacked_packets_.RestoreInFlight(it->first); | 372 unacked_packets_.RestoreInFlight(it->first); |
373 } | 373 } |
374 pending_retransmissions_.clear(); | 374 pending_retransmissions_.clear(); |
375 send_algorithm_->RevertRetransmissionTimeout(); | 375 send_algorithm_->RevertRetransmissionTimeout(); |
376 first_rto_transmission_ = 0; | 376 first_rto_transmission_ = 0; |
377 ++stats_->spurious_rto_count; | 377 ++stats_->spurious_rto_count; |
378 } | 378 } |
379 for (SequenceNumberSet::const_iterator | 379 for (SequenceNumberList::const_reverse_iterator it = |
380 it = all_transmissions.upper_bound(acked_sequence_number), | 380 all_transmissions.rbegin(); |
381 end = all_transmissions.end(); | 381 it != all_transmissions.rend() && *it > acked_sequence_number; ++it) { |
382 it != end; | |
383 ++it) { | |
384 const TransmissionInfo& retransmit_info = | 382 const TransmissionInfo& retransmit_info = |
385 unacked_packets_.GetTransmissionInfo(*it); | 383 unacked_packets_.GetTransmissionInfo(*it); |
386 | 384 |
387 stats_->bytes_spuriously_retransmitted += retransmit_info.bytes_sent; | 385 stats_->bytes_spuriously_retransmitted += retransmit_info.bytes_sent; |
388 ++stats_->packets_spuriously_retransmitted; | 386 ++stats_->packets_spuriously_retransmitted; |
389 if (debug_delegate_ != NULL) { | 387 if (debug_delegate_ != NULL) { |
390 debug_delegate_->OnSpuriousPacketRetransmition( | 388 debug_delegate_->OnSpuriousPacketRetransmition( |
391 retransmit_info.transmission_type, | 389 retransmit_info.transmission_type, |
392 retransmit_info.bytes_sent); | 390 retransmit_info.bytes_sent); |
393 } | 391 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 void QuicSentPacketManager::MarkPacketRevived( | 429 void QuicSentPacketManager::MarkPacketRevived( |
432 QuicPacketSequenceNumber sequence_number, | 430 QuicPacketSequenceNumber sequence_number, |
433 QuicTime::Delta delta_largest_observed) { | 431 QuicTime::Delta delta_largest_observed) { |
434 if (!unacked_packets_.IsUnacked(sequence_number)) { | 432 if (!unacked_packets_.IsUnacked(sequence_number)) { |
435 return; | 433 return; |
436 } | 434 } |
437 | 435 |
438 const TransmissionInfo& transmission_info = | 436 const TransmissionInfo& transmission_info = |
439 unacked_packets_.GetTransmissionInfo(sequence_number); | 437 unacked_packets_.GetTransmissionInfo(sequence_number); |
440 QuicPacketSequenceNumber newest_transmission = | 438 QuicPacketSequenceNumber newest_transmission = |
441 *transmission_info.all_transmissions->rbegin(); | 439 transmission_info.all_transmissions == NULL ? |
| 440 sequence_number : *transmission_info.all_transmissions->rbegin(); |
442 // This packet has been revived at the receiver. If we were going to | 441 // This packet has been revived at the receiver. If we were going to |
443 // retransmit it, do not retransmit it anymore. | 442 // retransmit it, do not retransmit it anymore. |
444 pending_retransmissions_.erase(newest_transmission); | 443 pending_retransmissions_.erase(newest_transmission); |
445 | 444 |
446 // The AckNotifierManager needs to be notified for revived packets, | 445 // The AckNotifierManager needs to be notified for revived packets, |
447 // since it indicates the packet arrived from the appliction's perspective. | 446 // since it indicates the packet arrived from the appliction's perspective. |
448 if (transmission_info.retransmittable_frames) { | 447 if (transmission_info.retransmittable_frames) { |
449 ack_notifier_manager_.OnPacketAcked( | 448 ack_notifier_manager_.OnPacketAcked( |
450 newest_transmission, delta_largest_observed); | 449 newest_transmission, delta_largest_observed); |
451 } | 450 } |
452 | 451 |
453 unacked_packets_.RemoveRetransmittability(sequence_number); | 452 unacked_packets_.RemoveRetransmittability(sequence_number); |
454 } | 453 } |
455 | 454 |
456 QuicUnackedPacketMap::const_iterator QuicSentPacketManager::MarkPacketHandled( | 455 void QuicSentPacketManager::MarkPacketHandled( |
457 QuicUnackedPacketMap::const_iterator it, | 456 QuicPacketSequenceNumber sequence_number, |
| 457 const TransmissionInfo& info, |
458 QuicTime::Delta delta_largest_observed) { | 458 QuicTime::Delta delta_largest_observed) { |
459 LOG_IF(DFATAL, it == unacked_packets_.end()) | |
460 << "MarkPacketHandled must be passed a valid iterator entry."; | |
461 const QuicPacketSequenceNumber sequence_number = it->first; | |
462 const TransmissionInfo& transmission_info = it->second; | |
463 | |
464 QuicPacketSequenceNumber newest_transmission = | 459 QuicPacketSequenceNumber newest_transmission = |
465 *transmission_info.all_transmissions->rbegin(); | 460 info.all_transmissions == NULL ? |
| 461 sequence_number : *info.all_transmissions->rbegin(); |
466 // Remove the most recent packet, if it is pending retransmission. | 462 // Remove the most recent packet, if it is pending retransmission. |
467 pending_retransmissions_.erase(newest_transmission); | 463 pending_retransmissions_.erase(newest_transmission); |
468 | 464 |
469 // Notify observers about the ACKed packet. | 465 // The AckNotifierManager needs to be notified about the most recent |
470 { | 466 // transmission, since that's the one only one it tracks. |
471 // The AckNotifierManager needs to be notified about the most recent | 467 ack_notifier_manager_.OnPacketAcked(newest_transmission, |
472 // transmission, since that's the one only one it tracks. | 468 delta_largest_observed); |
473 ack_notifier_manager_.OnPacketAcked(newest_transmission, | 469 if (newest_transmission != sequence_number) { |
474 delta_largest_observed); | 470 RecordSpuriousRetransmissions(*info.all_transmissions, sequence_number); |
475 if (newest_transmission != sequence_number) { | 471 // Remove the most recent packet from flight if it's a crypto handshake |
476 RecordSpuriousRetransmissions(*transmission_info.all_transmissions, | 472 // packet, since they won't be acked now that one has been processed. |
477 sequence_number); | 473 // Other crypto handshake packets won't be in flight, only the newest |
| 474 // transmission of a crypto packet is in flight at once. |
| 475 // TODO(ianswett): Instead of handling all crypto packets special, |
| 476 // only handle NULL encrypted packets in a special way. |
| 477 if (HasCryptoHandshake( |
| 478 unacked_packets_.GetTransmissionInfo(newest_transmission))) { |
| 479 unacked_packets_.RemoveFromInFlight(newest_transmission); |
478 } | 480 } |
479 } | 481 } |
480 | 482 |
481 // Two cases for MarkPacketHandled: | |
482 // 1) Handle the most recent or a crypto packet, so remove all transmissions. | |
483 // 2) Handle old transmission, keep all other pending transmissions, | |
484 // but disassociate them from one another. | |
485 | |
486 // If it's a crypto handshake packet, discard it and all retransmissions, | |
487 // since they won't be acked now that one has been processed. | |
488 // TODO(ianswett): Instead of handling all crypto packets in a special way, | |
489 // only handle NULL encrypted packets in a special way. | |
490 if (HasCryptoHandshake( | |
491 unacked_packets_.GetTransmissionInfo(newest_transmission))) { | |
492 unacked_packets_.RemoveFromInFlight(newest_transmission); | |
493 } | |
494 unacked_packets_.RemoveFromInFlight(sequence_number); | 483 unacked_packets_.RemoveFromInFlight(sequence_number); |
495 unacked_packets_.RemoveRetransmittability(sequence_number); | 484 unacked_packets_.RemoveRetransmittability(sequence_number); |
496 | |
497 QuicUnackedPacketMap::const_iterator next_unacked = unacked_packets_.begin(); | |
498 while (next_unacked != unacked_packets_.end() && | |
499 next_unacked->first <= sequence_number) { | |
500 ++next_unacked; | |
501 } | |
502 return next_unacked; | |
503 } | 485 } |
504 | 486 |
505 bool QuicSentPacketManager::IsUnacked( | 487 bool QuicSentPacketManager::IsUnacked( |
506 QuicPacketSequenceNumber sequence_number) const { | 488 QuicPacketSequenceNumber sequence_number) const { |
507 return unacked_packets_.IsUnacked(sequence_number); | 489 return unacked_packets_.IsUnacked(sequence_number); |
508 } | 490 } |
509 | 491 |
510 bool QuicSentPacketManager::HasUnackedPackets() const { | 492 bool QuicSentPacketManager::HasUnackedPackets() const { |
511 return unacked_packets_.HasUnackedPackets(); | 493 return unacked_packets_.HasUnackedPackets(); |
512 } | 494 } |
513 | 495 |
514 QuicPacketSequenceNumber | 496 QuicPacketSequenceNumber |
515 QuicSentPacketManager::GetLeastUnackedSentPacket() const { | 497 QuicSentPacketManager::GetLeastUnackedSentPacket() const { |
516 return unacked_packets_.GetLeastUnackedSentPacket(); | 498 return unacked_packets_.GetLeastUnacked(); |
517 } | 499 } |
518 | 500 |
519 bool QuicSentPacketManager::OnPacketSent( | 501 bool QuicSentPacketManager::OnPacketSent( |
520 QuicPacketSequenceNumber sequence_number, | 502 QuicPacketSequenceNumber sequence_number, |
521 QuicTime sent_time, | 503 QuicTime sent_time, |
522 QuicByteCount bytes, | 504 QuicByteCount bytes, |
523 TransmissionType transmission_type, | 505 TransmissionType transmission_type, |
524 HasRetransmittableData has_retransmittable_data) { | 506 HasRetransmittableData has_retransmittable_data) { |
525 DCHECK_LT(0u, sequence_number); | 507 DCHECK_LT(0u, sequence_number); |
526 DCHECK(unacked_packets_.IsUnacked(sequence_number)); | 508 DCHECK(unacked_packets_.IsUnacked(sequence_number)); |
(...skipping 13 matching lines...) Expand all Loading... |
540 // Only track packets as in flight that the send algorithm wants us to track. | 522 // Only track packets as in flight that the send algorithm wants us to track. |
541 const bool in_flight = | 523 const bool in_flight = |
542 send_algorithm_->OnPacketSent(sent_time, | 524 send_algorithm_->OnPacketSent(sent_time, |
543 unacked_packets_.bytes_in_flight(), | 525 unacked_packets_.bytes_in_flight(), |
544 sequence_number, | 526 sequence_number, |
545 bytes, | 527 bytes, |
546 has_retransmittable_data); | 528 has_retransmittable_data); |
547 unacked_packets_.SetSent(sequence_number, sent_time, bytes, in_flight); | 529 unacked_packets_.SetSent(sequence_number, sent_time, bytes, in_flight); |
548 | 530 |
549 if (debug_delegate_ != NULL) { | 531 if (debug_delegate_ != NULL) { |
550 debug_delegate_->OnSentPacket(sequence_number, sent_time, bytes); | 532 debug_delegate_->OnSentPacket( |
| 533 sequence_number, sent_time, bytes, transmission_type); |
551 } | 534 } |
552 | 535 |
553 // Reset the retransmission timer anytime a pending packet is sent. | 536 // Reset the retransmission timer anytime a pending packet is sent. |
554 return in_flight; | 537 return in_flight; |
555 } | 538 } |
556 | 539 |
557 void QuicSentPacketManager::OnRetransmissionTimeout() { | 540 void QuicSentPacketManager::OnRetransmissionTimeout() { |
558 DCHECK(unacked_packets_.HasInFlightPackets()); | 541 DCHECK(unacked_packets_.HasInFlightPackets()); |
559 DCHECK_EQ(0u, pending_timer_transmission_count_); | 542 DCHECK_EQ(0u, pending_timer_transmission_count_); |
560 // Handshake retransmission, timer based loss detection, TLP, and RTO are | 543 // Handshake retransmission, timer based loss detection, TLP, and RTO are |
(...skipping 29 matching lines...) Expand all Loading... |
590 } | 573 } |
591 } | 574 } |
592 | 575 |
593 void QuicSentPacketManager::RetransmitCryptoPackets() { | 576 void QuicSentPacketManager::RetransmitCryptoPackets() { |
594 DCHECK_EQ(HANDSHAKE_MODE, GetRetransmissionMode()); | 577 DCHECK_EQ(HANDSHAKE_MODE, GetRetransmissionMode()); |
595 // TODO(ianswett): Typical TCP implementations only retransmit 5 times. | 578 // TODO(ianswett): Typical TCP implementations only retransmit 5 times. |
596 consecutive_crypto_retransmission_count_ = | 579 consecutive_crypto_retransmission_count_ = |
597 min(kMaxHandshakeRetransmissionBackoffs, | 580 min(kMaxHandshakeRetransmissionBackoffs, |
598 consecutive_crypto_retransmission_count_ + 1); | 581 consecutive_crypto_retransmission_count_ + 1); |
599 bool packet_retransmitted = false; | 582 bool packet_retransmitted = false; |
| 583 QuicPacketSequenceNumber sequence_number = unacked_packets_.GetLeastUnacked(); |
600 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); | 584 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
601 it != unacked_packets_.end(); ++it) { | 585 it != unacked_packets_.end(); ++it, ++sequence_number) { |
602 QuicPacketSequenceNumber sequence_number = it->first; | |
603 const RetransmittableFrames* frames = it->second.retransmittable_frames; | |
604 // Only retransmit frames which are in flight, and therefore have been sent. | 586 // Only retransmit frames which are in flight, and therefore have been sent. |
605 if (!it->second.in_flight || frames == NULL || | 587 if (!it->in_flight || it->retransmittable_frames == NULL || |
606 frames->HasCryptoHandshake() != IS_HANDSHAKE) { | 588 it->retransmittable_frames->HasCryptoHandshake() != IS_HANDSHAKE) { |
607 continue; | 589 continue; |
608 } | 590 } |
609 packet_retransmitted = true; | 591 packet_retransmitted = true; |
610 MarkForRetransmission(sequence_number, HANDSHAKE_RETRANSMISSION); | 592 MarkForRetransmission(sequence_number, HANDSHAKE_RETRANSMISSION); |
611 ++pending_timer_transmission_count_; | 593 ++pending_timer_transmission_count_; |
612 } | 594 } |
613 DCHECK(packet_retransmitted) << "No crypto packets found to retransmit."; | 595 DCHECK(packet_retransmitted) << "No crypto packets found to retransmit."; |
614 } | 596 } |
615 | 597 |
616 bool QuicSentPacketManager::MaybeRetransmitTailLossProbe() { | 598 bool QuicSentPacketManager::MaybeRetransmitTailLossProbe() { |
617 if (pending_timer_transmission_count_ == 0) { | 599 if (pending_timer_transmission_count_ == 0) { |
618 return false; | 600 return false; |
619 } | 601 } |
| 602 QuicPacketSequenceNumber sequence_number = unacked_packets_.GetLeastUnacked(); |
620 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); | 603 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
621 it != unacked_packets_.end(); ++it) { | 604 it != unacked_packets_.end(); ++it, ++sequence_number) { |
622 QuicPacketSequenceNumber sequence_number = it->first; | |
623 const RetransmittableFrames* frames = it->second.retransmittable_frames; | |
624 // Only retransmit frames which are in flight, and therefore have been sent. | 605 // Only retransmit frames which are in flight, and therefore have been sent. |
625 if (!it->second.in_flight || frames == NULL) { | 606 if (!it->in_flight || it->retransmittable_frames == NULL) { |
626 continue; | 607 continue; |
627 } | 608 } |
628 if (!handshake_confirmed_) { | 609 if (!handshake_confirmed_) { |
629 DCHECK_NE(IS_HANDSHAKE, frames->HasCryptoHandshake()); | 610 DCHECK_NE(IS_HANDSHAKE, it->retransmittable_frames->HasCryptoHandshake()); |
630 } | 611 } |
631 MarkForRetransmission(sequence_number, TLP_RETRANSMISSION); | 612 MarkForRetransmission(sequence_number, TLP_RETRANSMISSION); |
632 return true; | 613 return true; |
633 } | 614 } |
634 DLOG(FATAL) | 615 DLOG(FATAL) |
635 << "No retransmittable packets, so RetransmitOldestPacket failed."; | 616 << "No retransmittable packets, so RetransmitOldestPacket failed."; |
636 return false; | 617 return false; |
637 } | 618 } |
638 | 619 |
639 void QuicSentPacketManager::RetransmitAllPackets() { | 620 void QuicSentPacketManager::RetransmitAllPackets() { |
640 DVLOG(1) << "RetransmitAllPackets() called with " | 621 DVLOG(1) << "RetransmitAllPackets() called with " |
641 << unacked_packets_.GetNumUnackedPackets() << " unacked packets."; | 622 << unacked_packets_.GetNumUnackedPacketsDebugOnly() |
| 623 << " unacked packets."; |
642 // Request retransmission of all retransmittable packets when the RTO | 624 // Request retransmission of all retransmittable packets when the RTO |
643 // fires, and let the congestion manager decide how many to send | 625 // fires, and let the congestion manager decide how many to send |
644 // immediately and the remaining packets will be queued. | 626 // immediately and the remaining packets will be queued. |
645 // Abandon any non-retransmittable packets that are sufficiently old. | 627 // Abandon any non-retransmittable packets that are sufficiently old. |
646 bool packets_retransmitted = false; | 628 bool packets_retransmitted = false; |
647 QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); | 629 QuicPacketSequenceNumber sequence_number = unacked_packets_.GetLeastUnacked(); |
648 while (it != unacked_packets_.end()) { | 630 for (QuicUnackedPacketMap::const_iterator it = unacked_packets_.begin(); |
649 const RetransmittableFrames* frames = it->second.retransmittable_frames; | 631 it != unacked_packets_.end(); ++it, ++sequence_number) { |
650 QuicPacketSequenceNumber sequence_number = it->first; | 632 if (it->retransmittable_frames != NULL) { |
651 ++it; | |
652 if (frames != NULL) { | |
653 packets_retransmitted = true; | 633 packets_retransmitted = true; |
654 MarkForRetransmission(sequence_number, RTO_RETRANSMISSION); | 634 MarkForRetransmission(sequence_number, RTO_RETRANSMISSION); |
655 } else { | 635 } else { |
656 unacked_packets_.RemoveFromInFlight(sequence_number); | 636 unacked_packets_.RemoveFromInFlight(sequence_number); |
657 } | 637 } |
658 } | 638 } |
659 | 639 |
660 send_algorithm_->OnRetransmissionTimeout(packets_retransmitted); | 640 send_algorithm_->OnRetransmissionTimeout(packets_retransmitted); |
661 if (packets_retransmitted) { | 641 if (packets_retransmitted) { |
662 if (consecutive_rto_count_ == 0) { | 642 if (consecutive_rto_count_ == 0) { |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 | 869 |
890 // Set up a pacing sender with a 5 millisecond alarm granularity. | 870 // Set up a pacing sender with a 5 millisecond alarm granularity. |
891 using_pacing_ = true; | 871 using_pacing_ = true; |
892 send_algorithm_.reset( | 872 send_algorithm_.reset( |
893 new PacingSender(send_algorithm_.release(), | 873 new PacingSender(send_algorithm_.release(), |
894 QuicTime::Delta::FromMilliseconds(5), | 874 QuicTime::Delta::FromMilliseconds(5), |
895 kInitialUnpacedBurst)); | 875 kInitialUnpacedBurst)); |
896 } | 876 } |
897 | 877 |
898 } // namespace net | 878 } // namespace net |
OLD | NEW |