| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 // Packet was acked, so remove it from our unacked packet list. | 245 // Packet was acked, so remove it from our unacked packet list. |
| 224 DVLOG(1) << ENDPOINT <<"Got an ack for packet " << sequence_number; | 246 DVLOG(1) << ENDPOINT <<"Got an ack for packet " << sequence_number; |
| 225 // If data is associated with the most recent transmission of this | 247 // If data is associated with the most recent transmission of this |
| 226 // packet, then inform the caller. | 248 // packet, then inform the caller. |
| 227 it = MarkPacketHandled(sequence_number, RECEIVED_BY_PEER); | 249 it = MarkPacketHandled(sequence_number, RECEIVED_BY_PEER); |
| 228 | 250 |
| 229 // The AckNotifierManager is informed of every ACKed sequence number. | 251 // The AckNotifierManager is informed of every ACKed sequence number. |
| 230 ack_notifier_manager_.OnPacketAcked(sequence_number); | 252 ack_notifier_manager_.OnPacketAcked(sequence_number); |
| 231 } | 253 } |
| 232 | 254 |
| 255 // Discard any retransmittable frames associated with revived packets. |
| 256 for (SequenceNumberSet::const_iterator revived_it = |
| 257 received_info.revived_packets.begin(); |
| 258 revived_it != received_info.revived_packets.end(); ++revived_it) { |
| 259 TransmissionInfo* transmission_info = |
| 260 FindOrNull(unacked_packets_, *revived_it); |
| 261 if (transmission_info == NULL) { |
| 262 continue; |
| 263 } |
| 264 // The retransmittable frames are removed from the most recent transmission. |
| 265 transmission_info = |
| 266 FindOrNull(unacked_packets_, |
| 267 *transmission_info->all_transmissions->rbegin()); |
| 268 if (transmission_info->retransmittable_frames == NULL) { |
| 269 continue; |
| 270 } |
| 271 delete transmission_info->retransmittable_frames; |
| 272 transmission_info->retransmittable_frames = NULL; |
| 273 } |
| 274 |
| 233 // If we have received a truncated ack, then we need to | 275 // If we have received a truncated ack, then we need to |
| 234 // clear out some previous transmissions to allow the peer | 276 // clear out some previous transmissions to allow the peer |
| 235 // to actually ACK new packets. | 277 // to actually ACK new packets. |
| 236 if (received_info.is_truncated) { | 278 if (received_info.is_truncated) { |
| 237 ClearPreviousRetransmissions(received_info.missing_packets.size() / 2); | 279 ClearPreviousRetransmissions(received_info.missing_packets.size() / 2); |
| 238 } | 280 } |
| 239 } | 281 } |
| 240 | 282 |
| 241 void QuicSentPacketManager::ClearPreviousRetransmissions(size_t num_to_clear) { | 283 void QuicSentPacketManager::ClearPreviousRetransmissions(size_t num_to_clear) { |
| 242 UnackedPacketMap::iterator it = unacked_packets_.begin(); | 284 UnackedPacketMap::iterator it = unacked_packets_.begin(); |
| 243 while (it != unacked_packets_.end() && num_to_clear > 0) { | 285 while (it != unacked_packets_.end() && num_to_clear > 0) { |
| 244 QuicPacketSequenceNumber sequence_number = it->first; | 286 QuicPacketSequenceNumber sequence_number = it->first; |
| 245 // If this is not a previous transmission then there is no point | 287 // If this is a pending packet, or has retransmittable data, then there is |
| 246 // in clearing out any further packets, because it will not affect | 288 // no point in clearing out any further packets, because they would not |
| 247 // the high water mark. | 289 // affect the high water mark. |
| 248 SequenceNumberSet* previous_transmissions = | 290 if (it->second.pending || it->second.retransmittable_frames != NULL) { |
| 249 it->second.previous_transmissions; | |
| 250 if (previous_transmissions == NULL) { | |
| 251 if (it->second.retransmittable_frames == NULL) { | |
| 252 // This is a current transmission, but a previous transmission has | |
| 253 // been acked, so it's safe to remove. | |
| 254 it = MarkPacketHandled(sequence_number, NOT_RECEIVED_BY_PEER); | |
| 255 --num_to_clear; | |
| 256 continue; | |
| 257 } | |
| 258 break; | |
| 259 } | |
| 260 QuicPacketSequenceNumber newest_transmission = | |
| 261 *previous_transmissions->rbegin(); | |
| 262 if (sequence_number == newest_transmission) { | |
| 263 break; | |
| 264 } | |
| 265 if (it->second.pending) { | |
| 266 break; | 291 break; |
| 267 } | 292 } |
| 268 | 293 |
| 269 DCHECK(it->second.retransmittable_frames == NULL); | 294 ++it; |
| 270 previous_transmissions->erase(sequence_number); | 295 RemovePacket(sequence_number); |
| 271 if (previous_transmissions->size() == 1) { | |
| 272 unacked_packets_[newest_transmission].previous_transmissions = NULL; | |
| 273 delete previous_transmissions; | |
| 274 } | |
| 275 unacked_packets_.erase(it++); | |
| 276 --num_to_clear; | 296 --num_to_clear; |
| 277 } | 297 } |
| 278 } | 298 } |
| 279 | 299 |
| 280 bool QuicSentPacketManager::HasRetransmittableFrames( | 300 bool QuicSentPacketManager::HasRetransmittableFrames( |
| 281 QuicPacketSequenceNumber sequence_number) const { | 301 QuicPacketSequenceNumber sequence_number) const { |
| 282 const TransmissionInfo* transmission_info = | 302 const TransmissionInfo* transmission_info = |
| 283 FindOrNull(unacked_packets_, sequence_number); | 303 FindOrNull(unacked_packets_, sequence_number); |
| 284 if (transmission_info == NULL) { | 304 if (transmission_info == NULL) { |
| 285 return false; | 305 return false; |
| 286 } | 306 } |
| 287 | 307 |
| 288 return transmission_info->retransmittable_frames != NULL; | 308 return transmission_info->retransmittable_frames != NULL; |
| 289 } | 309 } |
| 290 | 310 |
| 291 void QuicSentPacketManager::RetransmitUnackedPackets( | 311 void QuicSentPacketManager::RetransmitUnackedPackets( |
| 292 RetransmissionType retransmission_type) { | 312 RetransmissionType retransmission_type) { |
| 293 UnackedPacketMap::iterator unacked_it = unacked_packets_.begin(); | 313 UnackedPacketMap::iterator unacked_it = unacked_packets_.begin(); |
| 294 while (unacked_it != unacked_packets_.end()) { | 314 while (unacked_it != unacked_packets_.end()) { |
| 295 const RetransmittableFrames* frames = | 315 const RetransmittableFrames* frames = |
| 296 unacked_it->second.retransmittable_frames; | 316 unacked_it->second.retransmittable_frames; |
| 297 // Only mark it as handled if it can't be retransmitted and there are no | 317 // Only mark it as handled if it can't be retransmitted and there are no |
| 298 // pending retransmissions which would be cleared. | 318 // pending retransmissions which would be cleared. |
| 299 if (frames == NULL && unacked_it->second.previous_transmissions == NULL && | 319 if (frames == NULL && unacked_it->second.all_transmissions->size() == 1 && |
| 300 retransmission_type == ALL_PACKETS) { | 320 retransmission_type == ALL_PACKETS) { |
| 301 unacked_it = MarkPacketHandled(unacked_it->first, NOT_RECEIVED_BY_PEER); | 321 unacked_it = MarkPacketHandled(unacked_it->first, NOT_RECEIVED_BY_PEER); |
| 302 continue; | 322 continue; |
| 303 } | 323 } |
| 304 // If it had no other transmissions, we handle it above. If it has | 324 // If it had no other transmissions, we handle it above. If it has |
| 305 // other transmissions, one of them must have retransmittable frames, | 325 // other transmissions, one of them must have retransmittable frames, |
| 306 // so that gets resolved the same way as other retransmissions. | 326 // so that gets resolved the same way as other retransmissions. |
| 307 // TODO(ianswett): Consider adding a new retransmission type which removes | 327 // TODO(ianswett): Consider adding a new retransmission type which removes |
| 308 // all these old packets from unacked and retransmits them as new sequence | 328 // all these old packets from unacked and retransmits them as new sequence |
| 309 // numbers with no connection to the previous ones. | 329 // numbers with no connection to the previous ones. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 const TransmissionInfo& transmission_info) { | 381 const TransmissionInfo& transmission_info) { |
| 362 if (transmission_info.retransmittable_frames == NULL) { | 382 if (transmission_info.retransmittable_frames == NULL) { |
| 363 return false; | 383 return false; |
| 364 } | 384 } |
| 365 return transmission_info.retransmittable_frames->HasCryptoHandshake() == | 385 return transmission_info.retransmittable_frames->HasCryptoHandshake() == |
| 366 IS_HANDSHAKE; | 386 IS_HANDSHAKE; |
| 367 } | 387 } |
| 368 | 388 |
| 369 QuicSentPacketManager::UnackedPacketMap::iterator | 389 QuicSentPacketManager::UnackedPacketMap::iterator |
| 370 QuicSentPacketManager::MarkPacketHandled( | 390 QuicSentPacketManager::MarkPacketHandled( |
| 371 QuicPacketSequenceNumber sequence_number, ReceivedByPeer received_by_peer) { | 391 QuicPacketSequenceNumber sequence_number, |
| 372 DCHECK(ContainsKey(unacked_packets_, sequence_number)); | 392 ReceivedByPeer received_by_peer) { |
| 373 | 393 UnackedPacketMap::iterator it = unacked_packets_.find(sequence_number); |
| 394 if (it == unacked_packets_.end()) { |
| 395 LOG(DFATAL) << "Packet is not unacked: " << sequence_number; |
| 396 return it; |
| 397 } |
| 374 // If this packet is pending, remove it and inform the send algorithm. | 398 // If this packet is pending, remove it and inform the send algorithm. |
| 375 UnackedPacketMap::iterator it = unacked_packets_.find(sequence_number); | |
| 376 if (it->second.pending) { | 399 if (it->second.pending) { |
| 377 size_t bytes_sent = packet_history_map_[sequence_number]->bytes_sent(); | 400 size_t bytes_sent = packet_history_map_[sequence_number]->bytes_sent(); |
| 378 if (received_by_peer == RECEIVED_BY_PEER) { | 401 if (received_by_peer == RECEIVED_BY_PEER) { |
| 379 send_algorithm_->OnPacketAcked(sequence_number, bytes_sent); | 402 send_algorithm_->OnPacketAcked(sequence_number, bytes_sent); |
| 380 } else { | 403 } else { |
| 381 // It's been abandoned. | 404 // It's been abandoned. |
| 382 send_algorithm_->OnPacketAbandoned(sequence_number, bytes_sent); | 405 send_algorithm_->OnPacketAbandoned(sequence_number, bytes_sent); |
| 383 } | 406 } |
| 384 it->second.pending = false; | 407 it->second.pending = false; |
| 385 } | 408 } |
| 386 | 409 |
| 387 // If this packet has never been retransmitted, then simply drop it. | 410 SequenceNumberSet* all_transmissions = it->second.all_transmissions; |
| 388 if (it->second.previous_transmissions == NULL) { | 411 DCHECK(!all_transmissions->empty()); |
| 389 ++it; | 412 SequenceNumberSet::reverse_iterator all_transmissions_it = |
| 390 DiscardPacket(sequence_number); | 413 all_transmissions->rbegin(); |
| 391 return it; | 414 QuicPacketSequenceNumber newest_transmission = *all_transmissions_it; |
| 392 } | |
| 393 | |
| 394 SequenceNumberSet* previous_transmissions = it->second.previous_transmissions; | |
| 395 DCHECK(!previous_transmissions->empty()); | |
| 396 SequenceNumberSet::reverse_iterator previous_transmissions_it = | |
| 397 previous_transmissions->rbegin(); | |
| 398 QuicPacketSequenceNumber newest_transmission = *previous_transmissions_it; | |
| 399 TransmissionInfo* transmission_info = | |
| 400 FindOrNull(unacked_packets_, newest_transmission); | |
| 401 if (newest_transmission != sequence_number) { | 415 if (newest_transmission != sequence_number) { |
| 402 ++stats_->packets_spuriously_retransmitted; | 416 ++stats_->packets_spuriously_retransmitted; |
| 403 } | 417 } |
| 404 if (newest_transmission == sequence_number) { | 418 |
| 405 DiscardPacket(newest_transmission); | 419 bool has_cryto_handshake = HasCryptoHandshake( |
| 406 } else if (HasCryptoHandshake(*transmission_info)) { | 420 *FindOrNull(unacked_packets_, newest_transmission)); |
| 407 // If it's a crypto handshake packet, discard it and all retransmissions, | 421 if (has_cryto_handshake) { |
| 408 // since they won't be acked now that one has been processed. | 422 --pending_crypto_packet_count_; |
| 409 if (transmission_info->pending) { | 423 } |
| 410 OnPacketAbandoned(unacked_packets_.find(newest_transmission)); | 424 while (all_transmissions_it != all_transmissions->rend()) { |
| 425 QuicPacketSequenceNumber previous_transmission = *all_transmissions_it; |
| 426 TransmissionInfo* transmission_info = |
| 427 FindOrNull(unacked_packets_, previous_transmission); |
| 428 if (transmission_info->retransmittable_frames != NULL) { |
| 429 // Since some version of this packet has been acked, ensure that |
| 430 // the data is not retransmitted again. |
| 431 delete transmission_info->retransmittable_frames; |
| 432 transmission_info->retransmittable_frames = NULL; |
| 411 } | 433 } |
| 412 DiscardPacket(newest_transmission); | 434 if (ContainsKey(pending_retransmissions_, previous_transmission)) { |
| 413 } else { | 435 // Don't bother retransmitting this packet, if it has been |
| 414 // If we have received an ack for a previous transmission of a packet, | 436 // marked for retransmission. |
| 415 // we want to keep the "new" transmission of the packet unacked, | 437 pending_retransmissions_.erase(previous_transmission); |
| 416 // but prevent the data from being retransmitted. | 438 } |
| 417 delete transmission_info->retransmittable_frames; | 439 if (has_cryto_handshake) { |
| 418 transmission_info->retransmittable_frames = NULL; | 440 // If it's a crypto handshake packet, discard it and all retransmissions, |
| 419 transmission_info->previous_transmissions = NULL; | 441 // since they won't be acked now that one has been processed. |
| 442 if (transmission_info->pending) { |
| 443 OnPacketAbandoned(unacked_packets_.find(newest_transmission)); |
| 444 } |
| 445 transmission_info->pending = false; |
| 446 } |
| 447 if (!transmission_info->pending) { |
| 448 unacked_packets_.erase(previous_transmission); |
| 449 } else { |
| 450 transmission_info->all_transmissions = new SequenceNumberSet; |
| 451 transmission_info->all_transmissions->insert(previous_transmission); |
| 452 } |
| 453 ++all_transmissions_it; |
| 420 } | 454 } |
| 421 | 455 delete all_transmissions; |
| 422 // Clear out information all previous transmissions unless they're pending. | |
| 423 ++previous_transmissions_it; | |
| 424 while (previous_transmissions_it != previous_transmissions->rend()) { | |
| 425 QuicPacketSequenceNumber previous_transmission = *previous_transmissions_it; | |
| 426 ++previous_transmissions_it; | |
| 427 // If the packet was TLP retransmitted, the old copy is still pending. | |
| 428 // Keep it until it is lost or acked. | |
| 429 if (unacked_packets_[previous_transmission].pending) { | |
| 430 // Previous transmissions will be deleted, so set it to NULL. | |
| 431 unacked_packets_[previous_transmission].previous_transmissions = NULL; | |
| 432 } else { | |
| 433 DiscardPacket(previous_transmission); | |
| 434 } | |
| 435 } | |
| 436 | |
| 437 delete previous_transmissions; | |
| 438 | |
| 439 if (ContainsKey(pending_retransmissions_, newest_transmission)) { | |
| 440 pending_retransmissions_.erase(newest_transmission); | |
| 441 if (!unacked_packets_[newest_transmission].pending) { | |
| 442 // If the newest transmission has already been marked for retransmission | |
| 443 // and has already been abandoned, then we should remove it from | |
| 444 // unacked_packets_, as well as cancel the retransmission. | |
| 445 DCHECK(ContainsKey(unacked_packets_, newest_transmission)); | |
| 446 DCHECK(!unacked_packets_[newest_transmission].previous_transmissions); | |
| 447 unacked_packets_.erase(newest_transmission); | |
| 448 } | |
| 449 } | |
| 450 | 456 |
| 451 UnackedPacketMap::iterator next_unacked = unacked_packets_.begin(); | 457 UnackedPacketMap::iterator next_unacked = unacked_packets_.begin(); |
| 452 while (next_unacked != unacked_packets_.end() && | 458 while (next_unacked != unacked_packets_.end() && |
| 453 next_unacked->first < sequence_number) { | 459 next_unacked->first < sequence_number) { |
| 454 ++next_unacked; | 460 ++next_unacked; |
| 455 } | 461 } |
| 456 return next_unacked; | 462 return next_unacked; |
| 457 } | 463 } |
| 458 | 464 |
| 459 void QuicSentPacketManager::DiscardPacket( | 465 void QuicSentPacketManager::RemovePacket( |
| 460 QuicPacketSequenceNumber sequence_number) { | 466 QuicPacketSequenceNumber sequence_number) { |
| 461 UnackedPacketMap::iterator unacked_it = | 467 UnackedPacketMap::iterator it = unacked_packets_.find(sequence_number); |
| 462 unacked_packets_.find(sequence_number); | 468 if (it == unacked_packets_.end()) { |
| 463 DCHECK(unacked_it != unacked_packets_.end()); | 469 LOG(DFATAL) << "packet is not unacked: " << sequence_number; |
| 464 // Ensure the packet is no longer pending when it's discarded. | 470 return; |
| 465 DCHECK(!unacked_it->second.pending); | |
| 466 | |
| 467 RetransmittableFrames* retransmittable_frames = | |
| 468 unacked_it->second.retransmittable_frames; | |
| 469 if (HasCryptoHandshake(unacked_it->second)) { | |
| 470 --pending_crypto_packet_count_; | |
| 471 } | 471 } |
| 472 | 472 const TransmissionInfo& transmission_info = it->second; |
| 473 // Delete the retransmittable frames. | 473 transmission_info.all_transmissions->erase(sequence_number); |
| 474 delete retransmittable_frames; | 474 if (transmission_info.all_transmissions->empty()) { |
| 475 unacked_packets_.erase(unacked_it); | 475 delete transmission_info.all_transmissions; |
| 476 pending_retransmissions_.erase(sequence_number); | 476 } |
| 477 return; | 477 unacked_packets_.erase(it); |
| 478 } | 478 } |
| 479 | 479 |
| 480 bool QuicSentPacketManager::IsUnacked( | 480 bool QuicSentPacketManager::IsUnacked( |
| 481 QuicPacketSequenceNumber sequence_number) const { | 481 QuicPacketSequenceNumber sequence_number) const { |
| 482 return ContainsKey(unacked_packets_, sequence_number); | 482 return ContainsKey(unacked_packets_, sequence_number); |
| 483 } | 483 } |
| 484 | 484 |
| 485 bool QuicSentPacketManager::HasUnackedPackets() const { | 485 bool QuicSentPacketManager::HasUnackedPackets() const { |
| 486 return !unacked_packets_.empty(); | 486 return !unacked_packets_.empty(); |
| 487 } | 487 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 if (it == unacked_packets_.end()) { | 539 if (it == unacked_packets_.end()) { |
| 540 return false; | 540 return false; |
| 541 } | 541 } |
| 542 DCHECK(!it->second.pending); | 542 DCHECK(!it->second.pending); |
| 543 | 543 |
| 544 // Only track packets the send algorithm wants us to track. | 544 // Only track packets the send algorithm wants us to track. |
| 545 if (!send_algorithm_->OnPacketSent(sent_time, sequence_number, bytes, | 545 if (!send_algorithm_->OnPacketSent(sent_time, sequence_number, bytes, |
| 546 transmission_type, | 546 transmission_type, |
| 547 has_retransmittable_data)) { | 547 has_retransmittable_data)) { |
| 548 DCHECK(it->second.retransmittable_frames == NULL); | 548 DCHECK(it->second.retransmittable_frames == NULL); |
| 549 unacked_packets_.erase(it); | 549 RemovePacket(sequence_number); |
| 550 // Do not reset the retransmission timer, since the packet isn't tracked. | 550 // Do not reset the retransmission timer, since the packet isn't tracked. |
| 551 return false; | 551 return false; |
| 552 } | 552 } |
| 553 | 553 |
| 554 const bool set_retransmission_timer = !HasPendingPackets(); | 554 const bool set_retransmission_timer = !HasPendingPackets(); |
| 555 it->second.sent_time = sent_time; | 555 it->second.sent_time = sent_time; |
| 556 it->second.pending = true; | 556 it->second.pending = true; |
| 557 packet_history_map_[sequence_number] = | 557 packet_history_map_[sequence_number] = |
| 558 new SendAlgorithmInterface::SentPacket(bytes, sent_time); | 558 new SendAlgorithmInterface::SentPacket(bytes, sent_time); |
| 559 CleanupPacketHistory(); | 559 CleanupPacketHistory(); |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 OnPacketAbandoned(it); | 748 OnPacketAbandoned(it); |
| 749 | 749 |
| 750 if (transmission_info.retransmittable_frames) { | 750 if (transmission_info.retransmittable_frames) { |
| 751 MarkForRetransmission(sequence_number, NACK_RETRANSMISSION); | 751 MarkForRetransmission(sequence_number, NACK_RETRANSMISSION); |
| 752 ++it; | 752 ++it; |
| 753 } else { | 753 } else { |
| 754 // Since we will not retransmit this, we need to remove it from | 754 // Since we will not retransmit this, we need to remove it from |
| 755 // unacked_packets_. This is either the current transmission of | 755 // unacked_packets_. This is either the current transmission of |
| 756 // a packet whose previous transmission has been acked, or it | 756 // a packet whose previous transmission has been acked, or it |
| 757 // is a packet that has been TLP retransmitted. | 757 // is a packet that has been TLP retransmitted. |
| 758 RemovePreviousTransmission(sequence_number); | 758 ++it; |
| 759 unacked_packets_.erase(it++); | 759 RemovePacket(sequence_number); |
| 760 } | 760 } |
| 761 } | 761 } |
| 762 } | 762 } |
| 763 | 763 |
| 764 void QuicSentPacketManager::MaybeUpdateRTT( | 764 void QuicSentPacketManager::MaybeUpdateRTT( |
| 765 const ReceivedPacketInfo& received_info, | 765 const ReceivedPacketInfo& received_info, |
| 766 const QuicTime& ack_receive_time) { | 766 const QuicTime& ack_receive_time) { |
| 767 // We calculate the RTT based on the highest ACKed sequence number, the lower | 767 // We calculate the RTT based on the highest ACKed sequence number, the lower |
| 768 // sequence numbers will include the ACK aggregation delay. | 768 // sequence numbers will include the ACK aggregation delay. |
| 769 const TransmissionInfo* transmission_info = | 769 const TransmissionInfo* transmission_info = |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 if (using_pacing_) { | 954 if (using_pacing_) { |
| 955 return; | 955 return; |
| 956 } | 956 } |
| 957 | 957 |
| 958 using_pacing_ = true; | 958 using_pacing_ = true; |
| 959 send_algorithm_.reset( | 959 send_algorithm_.reset( |
| 960 new PacingSender(send_algorithm_.release(), | 960 new PacingSender(send_algorithm_.release(), |
| 961 QuicTime::Delta::FromMicroseconds(1))); | 961 QuicTime::Delta::FromMicroseconds(1))); |
| 962 } | 962 } |
| 963 | 963 |
| 964 void QuicSentPacketManager::RemovePreviousTransmission( | |
| 965 QuicPacketSequenceNumber sequence_number) { | |
| 966 SequenceNumberSet* previous_transmissions = | |
| 967 unacked_packets_[sequence_number].previous_transmissions; | |
| 968 if (!previous_transmissions) { | |
| 969 return; | |
| 970 } | |
| 971 previous_transmissions->erase(sequence_number); | |
| 972 if (previous_transmissions->size() == 1) { | |
| 973 QuicPacketSequenceNumber current = *previous_transmissions->begin(); | |
| 974 unacked_packets_[current].previous_transmissions = NULL; | |
| 975 delete previous_transmissions; | |
| 976 } | |
| 977 } | |
| 978 | |
| 979 } // namespace net | 964 } // namespace net |
| OLD | NEW |