| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "net/quic/congestion_control/pacing_sender.h" | 9 #include "net/quic/congestion_control/pacing_sender.h" |
| 10 #include "net/quic/crypto/crypto_protocol.h" | 10 #include "net/quic/crypto/crypto_protocol.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 static const size_t kDefaultMaxTailLossProbes = 2; | 56 static const size_t kDefaultMaxTailLossProbes = 2; |
| 57 static const int64 kMinTailLossProbeTimeoutMs = 10; | 57 static const int64 kMinTailLossProbeTimeoutMs = 10; |
| 58 | 58 |
| 59 COMPILE_ASSERT(kHistoryPeriodMs >= kBitrateSmoothingPeriodMs, | 59 COMPILE_ASSERT(kHistoryPeriodMs >= kBitrateSmoothingPeriodMs, |
| 60 history_must_be_longer_or_equal_to_the_smoothing_period); | 60 history_must_be_longer_or_equal_to_the_smoothing_period); |
| 61 | 61 |
| 62 } // namespace | 62 } // namespace |
| 63 | 63 |
| 64 #define ENDPOINT (is_server_ ? "Server: " : " Client: ") | 64 #define ENDPOINT (is_server_ ? "Server: " : " Client: ") |
| 65 | 65 |
| 66 |
| 67 QuicSentPacketManager::TransmissionInfo::TransmissionInfo() |
| 68 : retransmittable_frames(NULL), |
| 69 sequence_number_length(PACKET_1BYTE_SEQUENCE_NUMBER), |
| 70 sent_time(QuicTime::Zero()), |
| 71 all_transmissions(NULL), |
| 72 pending(false) { } |
| 73 |
| 74 QuicSentPacketManager::TransmissionInfo::TransmissionInfo( |
| 75 RetransmittableFrames* retransmittable_frames, |
| 76 QuicPacketSequenceNumber sequence_number, |
| 77 QuicSequenceNumberLength sequence_number_length) |
| 78 : retransmittable_frames(retransmittable_frames), |
| 79 sequence_number_length(sequence_number_length), |
| 80 sent_time(QuicTime::Zero()), |
| 81 all_transmissions(new SequenceNumberSet), |
| 82 pending(false) { |
| 83 all_transmissions->insert(sequence_number); |
| 84 } |
| 85 |
| 86 QuicSentPacketManager::TransmissionInfo::TransmissionInfo( |
| 87 RetransmittableFrames* retransmittable_frames, |
| 88 QuicPacketSequenceNumber sequence_number, |
| 89 QuicSequenceNumberLength sequence_number_length, |
| 90 SequenceNumberSet* all_transmissions) |
| 91 : retransmittable_frames(retransmittable_frames), |
| 92 sequence_number_length(sequence_number_length), |
| 93 sent_time(QuicTime::Zero()), |
| 94 all_transmissions(all_transmissions), |
| 95 pending(false) { |
| 96 all_transmissions->insert(sequence_number); |
| 97 } |
| 98 |
| 66 QuicSentPacketManager::QuicSentPacketManager(bool is_server, | 99 QuicSentPacketManager::QuicSentPacketManager(bool is_server, |
| 67 const QuicClock* clock, | 100 const QuicClock* clock, |
| 68 QuicConnectionStats* stats, | 101 QuicConnectionStats* stats, |
| 69 CongestionFeedbackType type) | 102 CongestionFeedbackType type) |
| 70 : is_server_(is_server), | 103 : is_server_(is_server), |
| 71 clock_(clock), | 104 clock_(clock), |
| 72 stats_(stats), | 105 stats_(stats), |
| 73 send_algorithm_(SendAlgorithmInterface::Create(clock, type)), | 106 send_algorithm_(SendAlgorithmInterface::Create(clock, type)), |
| 74 rtt_sample_(QuicTime::Delta::Infinite()), | 107 rtt_sample_(QuicTime::Delta::Infinite()), |
| 75 pending_crypto_packet_count_(0), | 108 pending_crypto_packet_count_(0), |
| 76 consecutive_rto_count_(0), | 109 consecutive_rto_count_(0), |
| 77 consecutive_tlp_count_(0), | 110 consecutive_tlp_count_(0), |
| 78 consecutive_crypto_retransmission_count_(0), | 111 consecutive_crypto_retransmission_count_(0), |
| 79 max_tail_loss_probes_(kDefaultMaxTailLossProbes), | 112 max_tail_loss_probes_(kDefaultMaxTailLossProbes), |
| 80 using_pacing_(false) { | 113 using_pacing_(false) { |
| 81 } | 114 } |
| 82 | 115 |
| 83 QuicSentPacketManager::~QuicSentPacketManager() { | 116 QuicSentPacketManager::~QuicSentPacketManager() { |
| 84 for (UnackedPacketMap::iterator it = unacked_packets_.begin(); | 117 for (UnackedPacketMap::iterator it = unacked_packets_.begin(); |
| 85 it != unacked_packets_.end(); ++it) { | 118 it != unacked_packets_.end(); ++it) { |
| 86 delete it->second.retransmittable_frames; | 119 delete it->second.retransmittable_frames; |
| 87 // Only delete previous_transmissions once, for the newest packet. | 120 // Only delete all_transmissions once, for the newest packet. |
| 88 if (it->second.previous_transmissions != NULL && | 121 if (it->first == *it->second.all_transmissions->rbegin()) { |
| 89 it->first == *it->second.previous_transmissions->rbegin()) { | 122 delete it->second.all_transmissions; |
| 90 delete it->second.previous_transmissions; | |
| 91 } | 123 } |
| 92 } | 124 } |
| 93 STLDeleteValues(&packet_history_map_); | 125 STLDeleteValues(&packet_history_map_); |
| 94 } | 126 } |
| 95 | 127 |
| 96 void QuicSentPacketManager::SetFromConfig(const QuicConfig& config) { | 128 void QuicSentPacketManager::SetFromConfig(const QuicConfig& config) { |
| 97 if (config.initial_round_trip_time_us() > 0 && | 129 if (config.initial_round_trip_time_us() > 0 && |
| 98 rtt_sample_.IsInfinite()) { | 130 rtt_sample_.IsInfinite()) { |
| 99 // The initial rtt should already be set on the client side. | 131 // The initial rtt should already be set on the client side. |
| 100 DVLOG_IF(1, !is_server_) | 132 DVLOG_IF(1, !is_server_) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 119 const SerializedPacket& serialized_packet) { | 151 const SerializedPacket& serialized_packet) { |
| 120 if (serialized_packet.retransmittable_frames) { | 152 if (serialized_packet.retransmittable_frames) { |
| 121 ack_notifier_manager_.OnSerializedPacket(serialized_packet); | 153 ack_notifier_manager_.OnSerializedPacket(serialized_packet); |
| 122 | 154 |
| 123 if (serialized_packet.retransmittable_frames->HasCryptoHandshake() | 155 if (serialized_packet.retransmittable_frames->HasCryptoHandshake() |
| 124 == IS_HANDSHAKE) { | 156 == IS_HANDSHAKE) { |
| 125 ++pending_crypto_packet_count_; | 157 ++pending_crypto_packet_count_; |
| 126 } | 158 } |
| 127 } | 159 } |
| 128 | 160 |
| 161 QuicPacketSequenceNumber sequence_number = serialized_packet.sequence_number; |
| 129 DCHECK(unacked_packets_.empty() || | 162 DCHECK(unacked_packets_.empty() || |
| 130 unacked_packets_.rbegin()->first < serialized_packet.sequence_number); | 163 unacked_packets_.rbegin()->first < sequence_number); |
| 131 unacked_packets_[serialized_packet.sequence_number] = | 164 unacked_packets_[sequence_number] = |
| 132 TransmissionInfo(serialized_packet.retransmittable_frames, | 165 TransmissionInfo(serialized_packet.retransmittable_frames, |
| 166 serialized_packet.sequence_number, |
| 133 serialized_packet.sequence_number_length); | 167 serialized_packet.sequence_number_length); |
| 134 } | 168 } |
| 135 | 169 |
| 136 void QuicSentPacketManager::OnRetransmittedPacket( | 170 void QuicSentPacketManager::OnRetransmittedPacket( |
| 137 QuicPacketSequenceNumber old_sequence_number, | 171 QuicPacketSequenceNumber old_sequence_number, |
| 138 QuicPacketSequenceNumber new_sequence_number) { | 172 QuicPacketSequenceNumber new_sequence_number) { |
| 139 DCHECK(ContainsKey(unacked_packets_, old_sequence_number)); | 173 DCHECK(ContainsKey(unacked_packets_, old_sequence_number)); |
| 140 DCHECK(ContainsKey(pending_retransmissions_, old_sequence_number)); | 174 DCHECK(ContainsKey(pending_retransmissions_, old_sequence_number)); |
| 141 DCHECK(unacked_packets_.empty() || | 175 DCHECK(unacked_packets_.empty() || |
| 142 unacked_packets_.rbegin()->first < new_sequence_number); | 176 unacked_packets_.rbegin()->first < new_sequence_number); |
| 143 | 177 |
| 144 pending_retransmissions_.erase(old_sequence_number); | 178 pending_retransmissions_.erase(old_sequence_number); |
| 145 // TODO(ianswett): Discard and lose the packet lazily instead of immediately. | 179 // TODO(ianswett): Discard and lose the packet lazily instead of immediately. |
| 146 TransmissionInfo* transmission_info = | 180 TransmissionInfo* transmission_info = |
| 147 FindOrNull(unacked_packets_, old_sequence_number); | 181 FindOrNull(unacked_packets_, old_sequence_number); |
| 148 RetransmittableFrames* frames = transmission_info->retransmittable_frames; | 182 RetransmittableFrames* frames = transmission_info->retransmittable_frames; |
| 149 DCHECK(frames); | 183 DCHECK(frames); |
| 150 | 184 |
| 151 // A notifier may be waiting to hear about ACKs for the original sequence | 185 // A notifier may be waiting to hear about ACKs for the original sequence |
| 152 // number. Inform them that the sequence number has changed. | 186 // number. Inform them that the sequence number has changed. |
| 153 ack_notifier_manager_.UpdateSequenceNumber(old_sequence_number, | 187 ack_notifier_manager_.UpdateSequenceNumber(old_sequence_number, |
| 154 new_sequence_number); | 188 new_sequence_number); |
| 155 | 189 |
| 156 // We keep the old packet in the unacked packet list until it, or one of | 190 // We keep the old packet in the unacked packet list until it, or one of |
| 157 // the retransmissions of it are acked. | 191 // the retransmissions of it are acked. |
| 158 transmission_info->retransmittable_frames = NULL; | 192 transmission_info->retransmittable_frames = NULL; |
| 159 unacked_packets_[new_sequence_number] = | 193 unacked_packets_[new_sequence_number] = |
| 160 TransmissionInfo(frames, transmission_info->sequence_number_length); | 194 TransmissionInfo(frames, new_sequence_number, |
| 161 | 195 transmission_info->sequence_number_length, |
| 162 // Keep track of all sequence numbers that this packet | 196 transmission_info->all_transmissions); |
| 163 // has been transmitted as. | |
| 164 SequenceNumberSet* previous_transmissions = | |
| 165 transmission_info->previous_transmissions; | |
| 166 if (previous_transmissions == NULL) { | |
| 167 // This is the first retransmission of this packet, so create a new entry. | |
| 168 previous_transmissions = new SequenceNumberSet; | |
| 169 transmission_info->previous_transmissions = previous_transmissions; | |
| 170 previous_transmissions->insert(old_sequence_number); | |
| 171 } | |
| 172 previous_transmissions->insert(new_sequence_number); | |
| 173 unacked_packets_[new_sequence_number].previous_transmissions = | |
| 174 previous_transmissions; | |
| 175 } | 197 } |
| 176 | 198 |
| 177 bool QuicSentPacketManager::OnIncomingAck( | 199 bool QuicSentPacketManager::OnIncomingAck( |
| 178 const ReceivedPacketInfo& received_info, QuicTime ack_receive_time) { | 200 const ReceivedPacketInfo& received_info, QuicTime ack_receive_time) { |
| 179 // We rely on delta_time_largest_observed to compute an RTT estimate, so | 201 // We rely on delta_time_largest_observed to compute an RTT estimate, so |
| 180 // we only update rtt when the largest observed gets acked. | 202 // we only update rtt when the largest observed gets acked. |
| 181 bool largest_observed_acked = | 203 bool largest_observed_acked = |
| 182 ContainsKey(unacked_packets_, received_info.largest_observed); | 204 ContainsKey(unacked_packets_, received_info.largest_observed); |
| 183 MaybeUpdateRTT(received_info, ack_receive_time); | 205 MaybeUpdateRTT(received_info, ack_receive_time); |
| 184 HandleAckForSentPackets(received_info); | 206 HandleAckForSentPackets(received_info); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 } | 260 } |
| 239 } | 261 } |
| 240 | 262 |
| 241 void QuicSentPacketManager::ClearPreviousRetransmissions(size_t num_to_clear) { | 263 void QuicSentPacketManager::ClearPreviousRetransmissions(size_t num_to_clear) { |
| 242 UnackedPacketMap::iterator it = unacked_packets_.begin(); | 264 UnackedPacketMap::iterator it = unacked_packets_.begin(); |
| 243 while (it != unacked_packets_.end() && num_to_clear > 0) { | 265 while (it != unacked_packets_.end() && num_to_clear > 0) { |
| 244 QuicPacketSequenceNumber sequence_number = it->first; | 266 QuicPacketSequenceNumber sequence_number = it->first; |
| 245 // If this is not a previous transmission then there is no point | 267 // If this is not a previous transmission then there is no point |
| 246 // in clearing out any further packets, because it will not affect | 268 // in clearing out any further packets, because it will not affect |
| 247 // the high water mark. | 269 // the high water mark. |
| 248 SequenceNumberSet* previous_transmissions = | 270 SequenceNumberSet* all_transmissions = it->second.all_transmissions; |
| 249 it->second.previous_transmissions; | 271 if (all_transmissions->size() == 1) { |
| 250 if (previous_transmissions == NULL) { | |
| 251 if (it->second.retransmittable_frames == NULL) { | 272 if (it->second.retransmittable_frames == NULL) { |
| 252 // This is a current transmission, but a previous transmission has | 273 // This is a current transmission, but a previous transmission has |
| 253 // been acked, so it's safe to remove. | 274 // been acked, so it's safe to remove. |
| 254 it = MarkPacketHandled(sequence_number, NOT_RECEIVED_BY_PEER); | 275 it = MarkPacketHandled(sequence_number, NOT_RECEIVED_BY_PEER); |
| 255 --num_to_clear; | 276 --num_to_clear; |
| 256 continue; | 277 continue; |
| 257 } | 278 } |
| 258 break; | 279 break; |
| 259 } | 280 } |
| 260 QuicPacketSequenceNumber newest_transmission = | 281 QuicPacketSequenceNumber newest_transmission = *all_transmissions->rbegin(); |
| 261 *previous_transmissions->rbegin(); | |
| 262 if (sequence_number == newest_transmission) { | 282 if (sequence_number == newest_transmission) { |
| 263 break; | 283 break; |
| 264 } | 284 } |
| 265 if (it->second.pending) { | 285 if (it->second.pending) { |
| 266 break; | 286 break; |
| 267 } | 287 } |
| 268 | 288 |
| 269 DCHECK(it->second.retransmittable_frames == NULL); | 289 DCHECK(it->second.retransmittable_frames == NULL); |
| 270 previous_transmissions->erase(sequence_number); | 290 DCHECK_LT(1u, all_transmissions->size()); |
| 271 if (previous_transmissions->size() == 1) { | 291 ++it; |
| 272 unacked_packets_[newest_transmission].previous_transmissions = NULL; | 292 RemovePacket(sequence_number); |
| 273 delete previous_transmissions; | |
| 274 } | |
| 275 unacked_packets_.erase(it++); | |
| 276 --num_to_clear; | 293 --num_to_clear; |
| 277 } | 294 } |
| 278 } | 295 } |
| 279 | 296 |
| 280 bool QuicSentPacketManager::HasRetransmittableFrames( | 297 bool QuicSentPacketManager::HasRetransmittableFrames( |
| 281 QuicPacketSequenceNumber sequence_number) const { | 298 QuicPacketSequenceNumber sequence_number) const { |
| 282 const TransmissionInfo* transmission_info = | 299 const TransmissionInfo* transmission_info = |
| 283 FindOrNull(unacked_packets_, sequence_number); | 300 FindOrNull(unacked_packets_, sequence_number); |
| 284 if (transmission_info == NULL) { | 301 if (transmission_info == NULL) { |
| 285 return false; | 302 return false; |
| 286 } | 303 } |
| 287 | 304 |
| 288 return transmission_info->retransmittable_frames != NULL; | 305 return transmission_info->retransmittable_frames != NULL; |
| 289 } | 306 } |
| 290 | 307 |
| 291 void QuicSentPacketManager::RetransmitUnackedPackets( | 308 void QuicSentPacketManager::RetransmitUnackedPackets( |
| 292 RetransmissionType retransmission_type) { | 309 RetransmissionType retransmission_type) { |
| 293 UnackedPacketMap::iterator unacked_it = unacked_packets_.begin(); | 310 UnackedPacketMap::iterator unacked_it = unacked_packets_.begin(); |
| 294 while (unacked_it != unacked_packets_.end()) { | 311 while (unacked_it != unacked_packets_.end()) { |
| 295 const RetransmittableFrames* frames = | 312 const RetransmittableFrames* frames = |
| 296 unacked_it->second.retransmittable_frames; | 313 unacked_it->second.retransmittable_frames; |
| 297 // Only mark it as handled if it can't be retransmitted and there are no | 314 // Only mark it as handled if it can't be retransmitted and there are no |
| 298 // pending retransmissions which would be cleared. | 315 // pending retransmissions which would be cleared. |
| 299 if (frames == NULL && unacked_it->second.previous_transmissions == NULL && | 316 if (frames == NULL && unacked_it->second.all_transmissions->size() == 1 && |
| 300 retransmission_type == ALL_PACKETS) { | 317 retransmission_type == ALL_PACKETS) { |
| 301 unacked_it = MarkPacketHandled(unacked_it->first, NOT_RECEIVED_BY_PEER); | 318 unacked_it = MarkPacketHandled(unacked_it->first, NOT_RECEIVED_BY_PEER); |
| 302 continue; | 319 continue; |
| 303 } | 320 } |
| 304 // If it had no other transmissions, we handle it above. If it has | 321 // If it had no other transmissions, we handle it above. If it has |
| 305 // other transmissions, one of them must have retransmittable frames, | 322 // other transmissions, one of them must have retransmittable frames, |
| 306 // so that gets resolved the same way as other retransmissions. | 323 // so that gets resolved the same way as other retransmissions. |
| 307 // TODO(ianswett): Consider adding a new retransmission type which removes | 324 // TODO(ianswett): Consider adding a new retransmission type which removes |
| 308 // all these old packets from unacked and retransmits them as new sequence | 325 // all these old packets from unacked and retransmits them as new sequence |
| 309 // numbers with no connection to the previous ones. | 326 // numbers with no connection to the previous ones. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 size_t bytes_sent = packet_history_map_[sequence_number]->bytes_sent(); | 397 size_t bytes_sent = packet_history_map_[sequence_number]->bytes_sent(); |
| 381 if (received_by_peer == RECEIVED_BY_PEER) { | 398 if (received_by_peer == RECEIVED_BY_PEER) { |
| 382 send_algorithm_->OnPacketAcked(sequence_number, bytes_sent); | 399 send_algorithm_->OnPacketAcked(sequence_number, bytes_sent); |
| 383 } else { | 400 } else { |
| 384 // It's been abandoned. | 401 // It's been abandoned. |
| 385 send_algorithm_->OnPacketAbandoned(sequence_number, bytes_sent); | 402 send_algorithm_->OnPacketAbandoned(sequence_number, bytes_sent); |
| 386 } | 403 } |
| 387 it->second.pending = false; | 404 it->second.pending = false; |
| 388 } | 405 } |
| 389 | 406 |
| 390 SequenceNumberSet* previous_transmissions = it->second.previous_transmissions; | 407 SequenceNumberSet* all_transmissions = it->second.all_transmissions; |
| 391 if (previous_transmissions == NULL) { | 408 DCHECK(!all_transmissions->empty()); |
| 392 previous_transmissions = new SequenceNumberSet; | 409 SequenceNumberSet::reverse_iterator all_transmissions_it = |
| 393 previous_transmissions->insert(sequence_number); | 410 all_transmissions->rbegin(); |
| 394 } | 411 QuicPacketSequenceNumber newest_transmission = *all_transmissions_it; |
| 395 DCHECK(!previous_transmissions->empty()); | |
| 396 SequenceNumberSet::reverse_iterator previous_transmissions_it = | |
| 397 previous_transmissions->rbegin(); | |
| 398 QuicPacketSequenceNumber newest_transmission = *previous_transmissions_it; | |
| 399 if (newest_transmission != sequence_number) { | 412 if (newest_transmission != sequence_number) { |
| 400 ++stats_->packets_spuriously_retransmitted; | 413 ++stats_->packets_spuriously_retransmitted; |
| 401 } | 414 } |
| 402 | 415 |
| 403 bool has_cryto_handshake = HasCryptoHandshake( | 416 bool has_cryto_handshake = HasCryptoHandshake( |
| 404 *FindOrNull(unacked_packets_, newest_transmission)); | 417 *FindOrNull(unacked_packets_, newest_transmission)); |
| 405 if (has_cryto_handshake) { | 418 if (has_cryto_handshake) { |
| 406 --pending_crypto_packet_count_; | 419 --pending_crypto_packet_count_; |
| 407 } | 420 } |
| 408 while (previous_transmissions_it != previous_transmissions->rend()) { | 421 while (all_transmissions_it != all_transmissions->rend()) { |
| 409 QuicPacketSequenceNumber previous_transmission = *previous_transmissions_it; | 422 QuicPacketSequenceNumber previous_transmission = *all_transmissions_it; |
| 410 TransmissionInfo* transmission_info = | 423 TransmissionInfo* transmission_info = |
| 411 FindOrNull(unacked_packets_, previous_transmission); | 424 FindOrNull(unacked_packets_, previous_transmission); |
| 412 if (transmission_info->retransmittable_frames != NULL) { | 425 if (transmission_info->retransmittable_frames != NULL) { |
| 413 // Since some version of this packet has been acked, ensure that | 426 // Since some version of this packet has been acked, ensure that |
| 414 // the data is not retransmitted again. | 427 // the data is not retransmitted again. |
| 415 delete transmission_info->retransmittable_frames; | 428 delete transmission_info->retransmittable_frames; |
| 416 transmission_info->retransmittable_frames = NULL; | 429 transmission_info->retransmittable_frames = NULL; |
| 417 } | 430 } |
| 418 if (ContainsKey(pending_retransmissions_, previous_transmission)) { | 431 if (ContainsKey(pending_retransmissions_, previous_transmission)) { |
| 419 // Don't bother retransmitting this packet, if it has been | 432 // Don't bother retransmitting this packet, if it has been |
| 420 // marked for retransmission. | 433 // marked for retransmission. |
| 421 pending_retransmissions_.erase(previous_transmission); | 434 pending_retransmissions_.erase(previous_transmission); |
| 422 } | 435 } |
| 423 if (has_cryto_handshake) { | 436 if (has_cryto_handshake) { |
| 424 // If it's a crypto handshake packet, discard it and all retransmissions, | 437 // If it's a crypto handshake packet, discard it and all retransmissions, |
| 425 // since they won't be acked now that one has been processed. | 438 // since they won't be acked now that one has been processed. |
| 426 if (transmission_info->pending) { | 439 if (transmission_info->pending) { |
| 427 OnPacketAbandoned(unacked_packets_.find(newest_transmission)); | 440 OnPacketAbandoned(unacked_packets_.find(newest_transmission)); |
| 428 } | 441 } |
| 429 transmission_info->pending = false; | 442 transmission_info->pending = false; |
| 430 } | 443 } |
| 431 if (!transmission_info->pending) { | 444 if (!transmission_info->pending) { |
| 432 unacked_packets_.erase(previous_transmission); | 445 unacked_packets_.erase(previous_transmission); |
| 433 } else { | 446 } else { |
| 434 transmission_info->previous_transmissions = NULL; | 447 transmission_info->all_transmissions = new SequenceNumberSet; |
| 448 transmission_info->all_transmissions->insert(previous_transmission); |
| 435 } | 449 } |
| 436 ++previous_transmissions_it; | 450 ++all_transmissions_it; |
| 437 } | 451 } |
| 438 delete previous_transmissions; | 452 delete all_transmissions; |
| 439 | 453 |
| 440 UnackedPacketMap::iterator next_unacked = unacked_packets_.begin(); | 454 UnackedPacketMap::iterator next_unacked = unacked_packets_.begin(); |
| 441 while (next_unacked != unacked_packets_.end() && | 455 while (next_unacked != unacked_packets_.end() && |
| 442 next_unacked->first < sequence_number) { | 456 next_unacked->first < sequence_number) { |
| 443 ++next_unacked; | 457 ++next_unacked; |
| 444 } | 458 } |
| 445 return next_unacked; | 459 return next_unacked; |
| 446 } | 460 } |
| 447 | 461 |
| 462 void QuicSentPacketManager::RemovePacket( |
| 463 QuicPacketSequenceNumber sequence_number) { |
| 464 UnackedPacketMap::iterator it = unacked_packets_.find(sequence_number); |
| 465 if (it == unacked_packets_.end()) { |
| 466 LOG(DFATAL) << "packet is not unacked: " << sequence_number; |
| 467 return; |
| 468 } |
| 469 const TransmissionInfo& transmission_info = it->second; |
| 470 transmission_info.all_transmissions->erase(sequence_number); |
| 471 if (transmission_info.all_transmissions->empty()) { |
| 472 delete transmission_info.all_transmissions; |
| 473 } |
| 474 unacked_packets_.erase(it); |
| 475 } |
| 476 |
| 448 bool QuicSentPacketManager::IsUnacked( | 477 bool QuicSentPacketManager::IsUnacked( |
| 449 QuicPacketSequenceNumber sequence_number) const { | 478 QuicPacketSequenceNumber sequence_number) const { |
| 450 return ContainsKey(unacked_packets_, sequence_number); | 479 return ContainsKey(unacked_packets_, sequence_number); |
| 451 } | 480 } |
| 452 | 481 |
| 453 bool QuicSentPacketManager::HasUnackedPackets() const { | 482 bool QuicSentPacketManager::HasUnackedPackets() const { |
| 454 return !unacked_packets_.empty(); | 483 return !unacked_packets_.empty(); |
| 455 } | 484 } |
| 456 | 485 |
| 457 bool QuicSentPacketManager::HasPendingPackets() const { | 486 bool QuicSentPacketManager::HasPendingPackets() const { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 if (it == unacked_packets_.end()) { | 536 if (it == unacked_packets_.end()) { |
| 508 return false; | 537 return false; |
| 509 } | 538 } |
| 510 DCHECK(!it->second.pending); | 539 DCHECK(!it->second.pending); |
| 511 | 540 |
| 512 // Only track packets the send algorithm wants us to track. | 541 // Only track packets the send algorithm wants us to track. |
| 513 if (!send_algorithm_->OnPacketSent(sent_time, sequence_number, bytes, | 542 if (!send_algorithm_->OnPacketSent(sent_time, sequence_number, bytes, |
| 514 transmission_type, | 543 transmission_type, |
| 515 has_retransmittable_data)) { | 544 has_retransmittable_data)) { |
| 516 DCHECK(it->second.retransmittable_frames == NULL); | 545 DCHECK(it->second.retransmittable_frames == NULL); |
| 517 unacked_packets_.erase(it); | 546 RemovePacket(sequence_number); |
| 518 // Do not reset the retransmission timer, since the packet isn't tracked. | 547 // Do not reset the retransmission timer, since the packet isn't tracked. |
| 519 return false; | 548 return false; |
| 520 } | 549 } |
| 521 | 550 |
| 522 const bool set_retransmission_timer = !HasPendingPackets(); | 551 const bool set_retransmission_timer = !HasPendingPackets(); |
| 523 it->second.sent_time = sent_time; | 552 it->second.sent_time = sent_time; |
| 524 it->second.pending = true; | 553 it->second.pending = true; |
| 525 packet_history_map_[sequence_number] = | 554 packet_history_map_[sequence_number] = |
| 526 new SendAlgorithmInterface::SentPacket(bytes, sent_time); | 555 new SendAlgorithmInterface::SentPacket(bytes, sent_time); |
| 527 CleanupPacketHistory(); | 556 CleanupPacketHistory(); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 OnPacketAbandoned(it); | 745 OnPacketAbandoned(it); |
| 717 | 746 |
| 718 if (transmission_info.retransmittable_frames) { | 747 if (transmission_info.retransmittable_frames) { |
| 719 MarkForRetransmission(sequence_number, NACK_RETRANSMISSION); | 748 MarkForRetransmission(sequence_number, NACK_RETRANSMISSION); |
| 720 ++it; | 749 ++it; |
| 721 } else { | 750 } else { |
| 722 // Since we will not retransmit this, we need to remove it from | 751 // Since we will not retransmit this, we need to remove it from |
| 723 // unacked_packets_. This is either the current transmission of | 752 // unacked_packets_. This is either the current transmission of |
| 724 // a packet whose previous transmission has been acked, or it | 753 // a packet whose previous transmission has been acked, or it |
| 725 // is a packet that has been TLP retransmitted. | 754 // is a packet that has been TLP retransmitted. |
| 726 RemovePreviousTransmission(sequence_number); | 755 ++it; |
| 727 unacked_packets_.erase(it++); | 756 RemovePacket(sequence_number); |
| 728 } | 757 } |
| 729 } | 758 } |
| 730 } | 759 } |
| 731 | 760 |
| 732 void QuicSentPacketManager::MaybeUpdateRTT( | 761 void QuicSentPacketManager::MaybeUpdateRTT( |
| 733 const ReceivedPacketInfo& received_info, | 762 const ReceivedPacketInfo& received_info, |
| 734 const QuicTime& ack_receive_time) { | 763 const QuicTime& ack_receive_time) { |
| 735 // We calculate the RTT based on the highest ACKed sequence number, the lower | 764 // We calculate the RTT based on the highest ACKed sequence number, the lower |
| 736 // sequence numbers will include the ACK aggregation delay. | 765 // sequence numbers will include the ACK aggregation delay. |
| 737 const TransmissionInfo* transmission_info = | 766 const TransmissionInfo* transmission_info = |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 if (using_pacing_) { | 951 if (using_pacing_) { |
| 923 return; | 952 return; |
| 924 } | 953 } |
| 925 | 954 |
| 926 using_pacing_ = true; | 955 using_pacing_ = true; |
| 927 send_algorithm_.reset( | 956 send_algorithm_.reset( |
| 928 new PacingSender(send_algorithm_.release(), | 957 new PacingSender(send_algorithm_.release(), |
| 929 QuicTime::Delta::FromMicroseconds(1))); | 958 QuicTime::Delta::FromMicroseconds(1))); |
| 930 } | 959 } |
| 931 | 960 |
| 932 void QuicSentPacketManager::RemovePreviousTransmission( | |
| 933 QuicPacketSequenceNumber sequence_number) { | |
| 934 SequenceNumberSet* previous_transmissions = | |
| 935 unacked_packets_[sequence_number].previous_transmissions; | |
| 936 if (!previous_transmissions) { | |
| 937 return; | |
| 938 } | |
| 939 previous_transmissions->erase(sequence_number); | |
| 940 if (previous_transmissions->size() == 1) { | |
| 941 QuicPacketSequenceNumber current = *previous_transmissions->begin(); | |
| 942 unacked_packets_[current].previous_transmissions = NULL; | |
| 943 delete previous_transmissions; | |
| 944 } | |
| 945 } | |
| 946 | |
| 947 } // namespace net | 961 } // namespace net |
| OLD | NEW |