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