OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_connection.h" | 5 #include "net/quic/quic_connection.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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 */ | 118 */ |
119 } | 119 } |
120 | 120 |
121 QuicConnection::~QuicConnection() { | 121 QuicConnection::~QuicConnection() { |
122 STLDeleteValues(&unacked_packets_); | 122 STLDeleteValues(&unacked_packets_); |
123 STLDeleteValues(&group_map_); | 123 STLDeleteValues(&group_map_); |
124 for (QueuedPacketList::iterator it = queued_packets_.begin(); | 124 for (QueuedPacketList::iterator it = queued_packets_.begin(); |
125 it != queued_packets_.end(); ++it) { | 125 it != queued_packets_.end(); ++it) { |
126 delete it->packet; | 126 delete it->packet; |
127 } | 127 } |
128 DLOG(INFO) << ENDPOINT << "write_blocked: " << write_blocked_; | 128 LOG(ERROR) << "Quic connection " << write_blocked_; |
129 } | 129 } |
130 | 130 |
131 bool QuicConnection::SelectMutualVersion( | 131 bool QuicConnection::SelectMutualVersion( |
132 const QuicTagVector& available_versions) { | 132 const QuicTagVector& available_versions) { |
133 // TODO(satyamshekhar): Make this generic. | 133 // TODO(satyamshekhar): Make this generic. |
134 if (std::find(available_versions.begin(), available_versions.end(), | 134 if (std::find(available_versions.begin(), available_versions.end(), |
135 kQuicVersion1) == available_versions.end()) { | 135 kQuicVersion1) == available_versions.end()) { |
136 return false; | 136 return false; |
137 } | 137 } |
138 | 138 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 DLOG(WARNING) << ENDPOINT << "The server already supports our version. " | 235 DLOG(WARNING) << ENDPOINT << "The server already supports our version. " |
236 << "It should have accepted our connection."; | 236 << "It should have accepted our connection."; |
237 // Just drop the connection. | 237 // Just drop the connection. |
238 CloseConnection(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, false); | 238 CloseConnection(QUIC_INVALID_VERSION_NEGOTIATION_PACKET, false); |
239 return; | 239 return; |
240 } | 240 } |
241 | 241 |
242 if (!SelectMutualVersion(packet.versions)) { | 242 if (!SelectMutualVersion(packet.versions)) { |
243 SendConnectionCloseWithDetails(QUIC_INVALID_VERSION, | 243 SendConnectionCloseWithDetails(QUIC_INVALID_VERSION, |
244 "no common version found"); | 244 "no common version found"); |
245 return; | |
246 } | 245 } |
247 | 246 |
248 version_negotiation_state_ = NEGOTIATED_VERSION; | 247 version_negotiation_state_ = NEGOTIATED_VERSION; |
249 RetransmitUnackedPackets(ALL_PACKETS); | 248 RetransmitUnackedPackets(ALL_PACKETS); |
250 } | 249 } |
251 | 250 |
252 void QuicConnection::OnRevivedPacket() { | 251 void QuicConnection::OnRevivedPacket() { |
253 } | 252 } |
254 | 253 |
255 bool QuicConnection::OnPacketHeader(const QuicPacketHeader& header) { | 254 bool QuicConnection::OnPacketHeader(const QuicPacketHeader& header) { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 | 354 |
356 received_truncated_ack_ = | 355 received_truncated_ack_ = |
357 incoming_ack.received_info.missing_packets.size() >= | 356 incoming_ack.received_info.missing_packets.size() >= |
358 QuicFramer::GetMaxUnackedPackets(last_header_); | 357 QuicFramer::GetMaxUnackedPackets(last_header_); |
359 | 358 |
360 UpdatePacketInformationReceivedByPeer(incoming_ack); | 359 UpdatePacketInformationReceivedByPeer(incoming_ack); |
361 UpdatePacketInformationSentByPeer(incoming_ack); | 360 UpdatePacketInformationSentByPeer(incoming_ack); |
362 congestion_manager_.OnIncomingAckFrame(incoming_ack, | 361 congestion_manager_.OnIncomingAckFrame(incoming_ack, |
363 time_of_last_received_packet_); | 362 time_of_last_received_packet_); |
364 | 363 |
365 // Now the we have received an ack, we might be able to send packets which are | 364 // Now the we have received an ack, we might be able to send queued packets. |
366 // queued locally, or drain streams which are blocked. | 365 if (!queued_packets_.empty()) { |
367 QuicTime::Delta delay = congestion_manager_.TimeUntilSend( | 366 QuicTime::Delta delay = congestion_manager_.TimeUntilSend( |
368 time_of_last_received_packet_, NOT_RETRANSMISSION, | 367 time_of_last_received_packet_, NOT_RETRANSMISSION, |
369 HAS_RETRANSMITTABLE_DATA); | 368 HAS_RETRANSMITTABLE_DATA); |
370 if (delay.IsZero()) { | 369 if (delay.IsZero()) { |
371 helper_->UnregisterSendAlarmIfRegistered(); | 370 helper_->UnregisterSendAlarmIfRegistered(); |
372 if (!write_blocked_) { | 371 if (!write_blocked_) { |
373 OnCanWrite(); | 372 OnCanWrite(); |
| 373 } |
| 374 } else if (!delay.IsInfinite()) { |
| 375 helper_->SetSendAlarm(time_of_last_received_packet_.Add(delay)); |
374 } | 376 } |
375 } else if (!delay.IsInfinite()) { | |
376 helper_->SetSendAlarm(time_of_last_received_packet_.Add(delay)); | |
377 } | 377 } |
378 return connected_; | 378 return connected_; |
379 } | 379 } |
380 | 380 |
381 bool QuicConnection::OnCongestionFeedbackFrame( | 381 bool QuicConnection::OnCongestionFeedbackFrame( |
382 const QuicCongestionFeedbackFrame& feedback) { | 382 const QuicCongestionFeedbackFrame& feedback) { |
383 DCHECK(connected_); | 383 DCHECK(connected_); |
384 if (debug_visitor_) { | 384 if (debug_visitor_) { |
385 debug_visitor_->OnCongestionFeedbackFrame(feedback); | 385 debug_visitor_->OnCongestionFeedbackFrame(feedback); |
386 } | 386 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 incoming_ack.received_info.largest_observed, | 454 incoming_ack.received_info.largest_observed, |
455 incoming_ack.received_info.missing_packets, | 455 incoming_ack.received_info.missing_packets, |
456 incoming_ack.received_info.entropy_hash)) { | 456 incoming_ack.received_info.entropy_hash)) { |
457 DLOG(ERROR) << ENDPOINT << "Peer sent invalid entropy."; | 457 DLOG(ERROR) << ENDPOINT << "Peer sent invalid entropy."; |
458 return false; | 458 return false; |
459 } | 459 } |
460 | 460 |
461 return true; | 461 return true; |
462 } | 462 } |
463 | 463 |
464 void QuicConnection::HandleAckForSentPackets(const QuicAckFrame& incoming_ack, | 464 void QuicConnection::UpdatePacketInformationReceivedByPeer( |
465 SequenceNumberSet* acked_packets) { | 465 const QuicAckFrame& incoming_ack) { |
| 466 SequenceNumberSet acked_packets; |
| 467 |
| 468 // ValidateAck should fail if largest_observed ever shrinks. |
| 469 DCHECK_LE(peer_largest_observed_packet_, |
| 470 incoming_ack.received_info.largest_observed); |
| 471 peer_largest_observed_packet_ = incoming_ack.received_info.largest_observed; |
| 472 |
| 473 if (incoming_ack.received_info.missing_packets.empty()) { |
| 474 least_packet_awaited_by_peer_ = peer_largest_observed_packet_ + 1; |
| 475 } else { |
| 476 least_packet_awaited_by_peer_ = |
| 477 *(incoming_ack.received_info.missing_packets.begin()); |
| 478 } |
| 479 |
| 480 entropy_manager_.ClearSentEntropyBefore(least_packet_awaited_by_peer_ - 1); |
| 481 |
466 int retransmitted_packets = 0; | 482 int retransmitted_packets = 0; |
467 // Go through the packets we have not received an ack for and see if this | 483 // Go through the packets we have not received an ack for and see if this |
468 // incoming_ack shows they've been seen by the peer. | 484 // incoming_ack shows they've been seen by the peer. |
469 UnackedPacketMap::iterator it = unacked_packets_.begin(); | 485 UnackedPacketMap::iterator it = unacked_packets_.begin(); |
470 while (it != unacked_packets_.end()) { | 486 while (it != unacked_packets_.end()) { |
471 QuicPacketSequenceNumber sequence_number = it->first; | 487 QuicPacketSequenceNumber sequence_number = it->first; |
472 if (sequence_number > peer_largest_observed_packet_) { | 488 if (sequence_number > peer_largest_observed_packet_) { |
473 break; | 489 break; |
474 } | 490 } |
475 RetransmittableFrames* unacked = it->second; | 491 RetransmittableFrames* unacked = it->second; |
476 if (!IsAwaitingPacket(incoming_ack.received_info, sequence_number)) { | 492 if (!IsAwaitingPacket(incoming_ack.received_info, sequence_number)) { |
477 // Packet was acked, so remove it from our unacked packet list. | 493 // Packet was acked, so remove it from our unacked packet list. |
478 DVLOG(1) << ENDPOINT <<"Got an ack for packet " << sequence_number; | 494 DVLOG(1) << ENDPOINT <<"Got an ack for packet " << sequence_number; |
479 acked_packets->insert(sequence_number); | 495 acked_packets.insert(sequence_number); |
480 delete unacked; | 496 delete unacked; |
481 unacked_packets_.erase(it++); | 497 UnackedPacketMap::iterator it_tmp = it; |
| 498 ++it; |
| 499 unacked_packets_.erase(it_tmp); |
482 retransmission_map_.erase(sequence_number); | 500 retransmission_map_.erase(sequence_number); |
483 } else { | 501 } else { |
484 // This is a packet which we planned on retransmitting and has not been | 502 // This is a packet which we planned on retransmitting and has not been |
485 // seen at the time of this ack being sent out. See if it's our new | 503 // seen at the time of this ack being sent out. See if it's our new |
486 // lowest unacked packet. | 504 // lowest unacked packet. |
487 DVLOG(1) << ENDPOINT << "still missing packet " << sequence_number; | 505 DVLOG(1) << ENDPOINT << "still missing packet " << sequence_number; |
488 ++it; | 506 ++it; |
489 // The peer got packets after this sequence number. This is an explicit | 507 // The peer got packets after this sequence number. This is an explicit |
490 // nack. | 508 // nack. |
491 RetransmissionMap::iterator retransmission_it = | 509 RetransmissionMap::iterator retransmission_it = |
492 retransmission_map_.find(sequence_number); | 510 retransmission_map_.find(sequence_number); |
493 ++(retransmission_it->second.number_nacks); | 511 ++(retransmission_it->second.number_nacks); |
494 if (retransmission_it->second.number_nacks >= | 512 if (retransmission_it->second.number_nacks >= |
495 kNumberOfNacksBeforeRetransmission && | 513 kNumberOfNacksBeforeRetransmission && |
496 retransmitted_packets < kMaxRetransmissionsPerAck) { | 514 retransmitted_packets < kMaxRetransmissionsPerAck) { |
497 ++retransmitted_packets; | 515 ++retransmitted_packets; |
498 DVLOG(1) << ENDPOINT << "Trying to retransmit packet " | 516 DVLOG(1) << ENDPOINT << "Trying to retransmit packet " |
499 << sequence_number | 517 << sequence_number |
500 << " as it has been nacked 3 or more times."; | 518 << " as it has been nacked 3 or more times."; |
501 // TODO(satyamshekhar): save in a vector and retransmit after the | 519 // TODO(satyamshekhar): save in a vector and retransmit after the |
502 // loop. | 520 // loop. |
503 RetransmitPacket(sequence_number); | 521 RetransmitPacket(sequence_number); |
504 } | 522 } |
505 } | 523 } |
506 } | 524 } |
507 } | |
508 | |
509 void QuicConnection::HandleAckForSentFecPackets( | |
510 const QuicAckFrame& incoming_ack, SequenceNumberSet* acked_packets) { | |
511 UnackedPacketMap::iterator it = unacked_fec_packets_.begin(); | |
512 while (it != unacked_fec_packets_.end()) { | |
513 QuicPacketSequenceNumber sequence_number = it->first; | |
514 if (sequence_number > peer_largest_observed_packet_) { | |
515 break; | |
516 } | |
517 if (!IsAwaitingPacket(incoming_ack.received_info, sequence_number)) { | |
518 DVLOG(1) << ENDPOINT << "Got an ack for fec packet: " << sequence_number; | |
519 acked_packets->insert(sequence_number); | |
520 unacked_fec_packets_.erase(it++); | |
521 } else { | |
522 DVLOG(1) << ENDPOINT << "Still missing ack for fec packet: " | |
523 << sequence_number; | |
524 ++it; | |
525 } | |
526 } | |
527 } | |
528 | |
529 void QuicConnection::UpdatePacketInformationReceivedByPeer( | |
530 const QuicAckFrame& incoming_ack) { | |
531 // ValidateAck should fail if largest_observed ever shrinks. | |
532 DCHECK_LE(peer_largest_observed_packet_, | |
533 incoming_ack.received_info.largest_observed); | |
534 peer_largest_observed_packet_ = incoming_ack.received_info.largest_observed; | |
535 | |
536 if (incoming_ack.received_info.missing_packets.empty()) { | |
537 least_packet_awaited_by_peer_ = peer_largest_observed_packet_ + 1; | |
538 } else { | |
539 least_packet_awaited_by_peer_ = | |
540 *(incoming_ack.received_info.missing_packets.begin()); | |
541 } | |
542 | |
543 entropy_manager_.ClearSentEntropyBefore(least_packet_awaited_by_peer_ - 1); | |
544 | |
545 SequenceNumberSet acked_packets; | |
546 HandleAckForSentPackets(incoming_ack, &acked_packets); | |
547 HandleAckForSentFecPackets(incoming_ack, &acked_packets); | |
548 | |
549 if (acked_packets.size() > 0) { | 525 if (acked_packets.size() > 0) { |
550 visitor_->OnAck(acked_packets); | 526 visitor_->OnAck(acked_packets); |
551 } | 527 } |
552 } | 528 } |
553 | 529 |
554 bool QuicConnection::DontWaitForPacketsBefore( | 530 bool QuicConnection::DontWaitForPacketsBefore( |
555 QuicPacketSequenceNumber least_unacked) { | 531 QuicPacketSequenceNumber least_unacked) { |
556 size_t missing_packets_count = | 532 size_t missing_packets_count = |
557 outgoing_ack_.received_info.missing_packets.size(); | 533 outgoing_ack_.received_info.missing_packets.size(); |
558 outgoing_ack_.received_info.missing_packets.erase( | 534 outgoing_ack_.received_info.missing_packets.erase( |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 return true; | 953 return true; |
978 } | 954 } |
979 | 955 |
980 bool QuicConnection::IsRetransmission( | 956 bool QuicConnection::IsRetransmission( |
981 QuicPacketSequenceNumber sequence_number) { | 957 QuicPacketSequenceNumber sequence_number) { |
982 RetransmissionMap::iterator it = retransmission_map_.find(sequence_number); | 958 RetransmissionMap::iterator it = retransmission_map_.find(sequence_number); |
983 return it != retransmission_map_.end() && | 959 return it != retransmission_map_.end() && |
984 it->second.number_retransmissions > 0; | 960 it->second.number_retransmissions > 0; |
985 } | 961 } |
986 | 962 |
987 void QuicConnection::SetupRetransmission( | 963 void QuicConnection::MaybeSetupRetransmission( |
988 QuicPacketSequenceNumber sequence_number) { | 964 QuicPacketSequenceNumber sequence_number) { |
989 RetransmissionMap::iterator it = retransmission_map_.find(sequence_number); | 965 RetransmissionMap::iterator it = retransmission_map_.find(sequence_number); |
990 if (it == retransmission_map_.end()) { | 966 if (it == retransmission_map_.end()) { |
991 DVLOG(1) << ENDPOINT << "Will not retransmit packet " << sequence_number; | 967 DVLOG(1) << ENDPOINT << "Will not retransmit packet " << sequence_number; |
992 return; | 968 return; |
993 } | 969 } |
994 | 970 |
995 RetransmissionInfo retransmission_info = it->second; | 971 RetransmissionInfo retransmission_info = it->second; |
996 QuicTime::Delta retransmission_delay = | 972 QuicTime::Delta retransmission_delay = |
997 congestion_manager_.GetRetransmissionDelay( | 973 congestion_manager_.GetRetransmissionDelay( |
998 unacked_packets_.size(), | 974 unacked_packets_.size(), |
999 retransmission_info.number_retransmissions); | 975 retransmission_info.number_retransmissions); |
1000 | 976 retransmission_info.scheduled_time = |
1001 retransmission_timeouts_.push(RetransmissionTime( | 977 clock_->ApproximateNow().Add(retransmission_delay); |
1002 sequence_number, | 978 retransmission_timeouts_.push(retransmission_info); |
1003 clock_->ApproximateNow().Add(retransmission_delay), | |
1004 false)); | |
1005 | 979 |
1006 // Do not set the retransmisson alarm if we're already handling the | 980 // Do not set the retransmisson alarm if we're already handling the |
1007 // retransmission alarm because the retransmission alarm will be reset when | 981 // retransmission alarm because the retransmission alarm will be reset when |
1008 // OnRetransmissionTimeout completes. | 982 // OnRetransmissionTimeout completes. |
1009 if (!handling_retransmission_timeout_) { | 983 if (!handling_retransmission_timeout_) { |
1010 helper_->SetRetransmissionAlarm(retransmission_delay); | 984 helper_->SetRetransmissionAlarm(retransmission_delay); |
1011 } | 985 } |
1012 // TODO(satyamshekhar): restore packet reordering with Ian's TODO in | 986 // TODO(satyamshekhar): restore packet reordering with Ian's TODO in |
1013 // SendStreamData(). | 987 // SendStreamData(). |
1014 } | 988 } |
1015 | 989 |
1016 void QuicConnection::SetupAbandonFecTimer( | |
1017 QuicPacketSequenceNumber sequence_number) { | |
1018 DCHECK(ContainsKey(unacked_fec_packets_, sequence_number)); | |
1019 QuicTime::Delta retransmission_delay = | |
1020 QuicTime::Delta::FromMilliseconds( | |
1021 congestion_manager_.DefaultRetransmissionTime().ToMilliseconds() * 3); | |
1022 retransmission_timeouts_.push(RetransmissionTime( | |
1023 sequence_number, | |
1024 clock_->ApproximateNow().Add(retransmission_delay), | |
1025 true)); | |
1026 } | |
1027 | |
1028 void QuicConnection::DropPacket(QuicPacketSequenceNumber sequence_number) { | 990 void QuicConnection::DropPacket(QuicPacketSequenceNumber sequence_number) { |
1029 UnackedPacketMap::iterator unacked_it = | 991 UnackedPacketMap::iterator unacked_it = |
1030 unacked_packets_.find(sequence_number); | 992 unacked_packets_.find(sequence_number); |
1031 // Packet was not meant to be retransmitted. | 993 // Packet was not meant to be retransmitted. |
1032 if (unacked_it == unacked_packets_.end()) { | 994 if (unacked_it == unacked_packets_.end()) { |
1033 DCHECK(!ContainsKey(retransmission_map_, sequence_number)); | 995 DCHECK(!ContainsKey(retransmission_map_, sequence_number)); |
1034 return; | 996 return; |
1035 } | 997 } |
1036 // Delete the unacked packet. | 998 // Delete the unacked packet. |
1037 delete unacked_it->second; | 999 delete unacked_it->second; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1108 } | 1070 } |
1109 if (!retransmission) { | 1071 if (!retransmission) { |
1110 time_of_last_sent_packet_ = now; | 1072 time_of_last_sent_packet_ = now; |
1111 } | 1073 } |
1112 DVLOG(1) << ENDPOINT << "time of last sent packet: " | 1074 DVLOG(1) << ENDPOINT << "time of last sent packet: " |
1113 << now.ToDebuggingValue(); | 1075 << now.ToDebuggingValue(); |
1114 | 1076 |
1115 // Set the retransmit alarm only when we have sent the packet to the client | 1077 // Set the retransmit alarm only when we have sent the packet to the client |
1116 // and not when it goes to the pending queue, otherwise we will end up adding | 1078 // and not when it goes to the pending queue, otherwise we will end up adding |
1117 // an entry to retransmission_timeout_ every time we attempt a write. | 1079 // an entry to retransmission_timeout_ every time we attempt a write. |
1118 if (retransmittable == HAS_RETRANSMITTABLE_DATA) { | 1080 MaybeSetupRetransmission(sequence_number); |
1119 SetupRetransmission(sequence_number); | |
1120 } else if (packet->is_fec_packet()) { | |
1121 SetupAbandonFecTimer(sequence_number); | |
1122 } | |
1123 | 1081 |
1124 congestion_manager_.SentPacket(sequence_number, now, packet->length(), | 1082 congestion_manager_.SentPacket(sequence_number, now, packet->length(), |
1125 retransmission); | 1083 retransmission); |
1126 | 1084 |
1127 stats_.bytes_sent += encrypted->length(); | 1085 stats_.bytes_sent += encrypted->length(); |
1128 ++stats_.packets_sent; | 1086 ++stats_.packets_sent; |
1129 | 1087 |
1130 if (retransmission == IS_RETRANSMISSION) { | 1088 if (retransmission == IS_RETRANSMISSION) { |
1131 stats_.bytes_retransmitted += encrypted->length(); | 1089 stats_.bytes_retransmitted += encrypted->length(); |
1132 ++stats_.packets_retransmitted; | 1090 ++stats_.packets_retransmitted; |
(...skipping 13 matching lines...) Expand all Loading... |
1146 // original. | 1104 // original. |
1147 serialized_packet.retransmittable_frames->set_encryption_level( | 1105 serialized_packet.retransmittable_frames->set_encryption_level( |
1148 encryption_level_); | 1106 encryption_level_); |
1149 unacked_packets_.insert( | 1107 unacked_packets_.insert( |
1150 make_pair(serialized_packet.sequence_number, | 1108 make_pair(serialized_packet.sequence_number, |
1151 serialized_packet.retransmittable_frames)); | 1109 serialized_packet.retransmittable_frames)); |
1152 // All unacked packets might be retransmitted. | 1110 // All unacked packets might be retransmitted. |
1153 retransmission_map_.insert( | 1111 retransmission_map_.insert( |
1154 make_pair(serialized_packet.sequence_number, | 1112 make_pair(serialized_packet.sequence_number, |
1155 RetransmissionInfo(serialized_packet.sequence_number))); | 1113 RetransmissionInfo(serialized_packet.sequence_number))); |
1156 } else if (serialized_packet.packet->is_fec_packet()) { | |
1157 unacked_fec_packets_.insert(make_pair( | |
1158 serialized_packet.sequence_number, | |
1159 serialized_packet.retransmittable_frames)); | |
1160 } | 1114 } |
1161 return SendOrQueuePacket(encryption_level_, | 1115 return SendOrQueuePacket(encryption_level_, |
1162 serialized_packet.sequence_number, | 1116 serialized_packet.sequence_number, |
1163 serialized_packet.packet, | 1117 serialized_packet.packet, |
1164 serialized_packet.entropy_hash, | 1118 serialized_packet.entropy_hash, |
1165 serialized_packet.retransmittable_frames != NULL ? | 1119 serialized_packet.retransmittable_frames != NULL ? |
1166 HAS_RETRANSMITTABLE_DATA : | 1120 HAS_RETRANSMITTABLE_DATA : |
1167 NO_RETRANSMITTABLE_DATA); | 1121 NO_RETRANSMITTABLE_DATA); |
1168 } | 1122 } |
1169 | 1123 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 if (congestion_manager_.GenerateCongestionFeedback( | 1173 if (congestion_manager_.GenerateCongestionFeedback( |
1220 &outgoing_congestion_feedback_)) { | 1174 &outgoing_congestion_feedback_)) { |
1221 DVLOG(1) << ENDPOINT << "Sending feedback " | 1175 DVLOG(1) << ENDPOINT << "Sending feedback " |
1222 << outgoing_congestion_feedback_; | 1176 << outgoing_congestion_feedback_; |
1223 send_feedback = true; | 1177 send_feedback = true; |
1224 } | 1178 } |
1225 | 1179 |
1226 packet_generator_.SetShouldSendAck(send_feedback); | 1180 packet_generator_.SetShouldSendAck(send_feedback); |
1227 } | 1181 } |
1228 | 1182 |
1229 void QuicConnection::MaybeAbandonFecPacket( | |
1230 QuicPacketSequenceNumber sequence_number) { | |
1231 if (!ContainsKey(unacked_fec_packets_, sequence_number)) { | |
1232 DVLOG(2) << ENDPOINT << "no need to abandon fec packet: " | |
1233 << sequence_number << "; it's already acked'"; | |
1234 return; | |
1235 } | |
1236 congestion_manager_.AbandoningPacket(sequence_number); | |
1237 // TODO(satyashekhar): Should this decrease the congestion window? | |
1238 } | |
1239 | |
1240 QuicTime QuicConnection::OnRetransmissionTimeout() { | 1183 QuicTime QuicConnection::OnRetransmissionTimeout() { |
1241 // This guards against registering the alarm later than we should. | 1184 // This guards against registering the alarm later than we should. |
1242 // | 1185 // |
1243 // If we have packet A and B in the list and we call | 1186 // If we have packet A and B in the list and we call |
1244 // MaybeRetransmitPacketForRTO on A, that may trigger a call to | 1187 // MaybeRetransmitPacketForRTO on A, that may trigger a call to |
1245 // SetRetransmissionAlarm if A is retransmitted as C. In that case we | 1188 // SetRetransmissionAlarm if A is retransmitted as C. In that case we |
1246 // don't want to register the alarm under SetRetransmissionAlarm; we | 1189 // don't want to register the alarm under SetRetransmissionAlarm; we |
1247 // want to set it to the RTO of B when we return from this function. | 1190 // want to set it to the RTO of B when we return from this function. |
1248 handling_retransmission_timeout_ = true; | 1191 handling_retransmission_timeout_ = true; |
1249 | 1192 |
1250 for (size_t i = 0; i < max_packets_per_retransmission_alarm_ && | 1193 for (size_t i = 0; i < max_packets_per_retransmission_alarm_ && |
1251 !retransmission_timeouts_.empty(); ++i) { | 1194 !retransmission_timeouts_.empty(); ++i) { |
1252 RetransmissionTime retransmission_time = retransmission_timeouts_.top(); | 1195 RetransmissionInfo retransmission_info = retransmission_timeouts_.top(); |
1253 DCHECK(retransmission_time.scheduled_time.IsInitialized()); | 1196 DCHECK(retransmission_info.scheduled_time.IsInitialized()); |
1254 if (retransmission_time.scheduled_time > clock_->ApproximateNow()) { | 1197 if (retransmission_info.scheduled_time > clock_->ApproximateNow()) { |
1255 break; | 1198 break; |
1256 } | 1199 } |
1257 retransmission_timeouts_.pop(); | 1200 retransmission_timeouts_.pop(); |
1258 | 1201 if (!MaybeRetransmitPacketForRTO(retransmission_info.sequence_number)) { |
1259 if (retransmission_time.for_fec) { | |
1260 MaybeAbandonFecPacket(retransmission_time.sequence_number); | |
1261 continue; | |
1262 } else if ( | |
1263 !MaybeRetransmitPacketForRTO(retransmission_time.sequence_number)) { | |
1264 DLOG(INFO) << ENDPOINT << "MaybeRetransmitPacketForRTO failed: " | 1202 DLOG(INFO) << ENDPOINT << "MaybeRetransmitPacketForRTO failed: " |
1265 << "adding an extra delay for " | 1203 << "adding an extra delay for " |
1266 << retransmission_time.sequence_number; | 1204 << retransmission_info.sequence_number; |
1267 retransmission_time.scheduled_time = clock_->ApproximateNow().Add( | 1205 retransmission_info.scheduled_time = clock_->ApproximateNow().Add( |
1268 congestion_manager_.DefaultRetransmissionTime()); | 1206 congestion_manager_.DefaultRetransmissionTime()); |
1269 retransmission_timeouts_.push(retransmission_time); | 1207 retransmission_timeouts_.push(retransmission_info); |
1270 } | 1208 } |
1271 } | 1209 } |
1272 | 1210 |
1273 handling_retransmission_timeout_ = false; | 1211 handling_retransmission_timeout_ = false; |
1274 | 1212 |
1275 if (retransmission_timeouts_.empty()) { | 1213 if (retransmission_timeouts_.empty()) { |
1276 return QuicTime::Zero(); | 1214 return QuicTime::Zero(); |
1277 } | 1215 } |
1278 | 1216 |
1279 // We have packets remaining. Return the absolute RTO of the oldest packet | 1217 // We have packets remaining. Return the absolute RTO of the oldest packet |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1432 delete fec_group; | 1370 delete fec_group; |
1433 it = next; | 1371 it = next; |
1434 } | 1372 } |
1435 } | 1373 } |
1436 | 1374 |
1437 bool QuicConnection::HasQueuedData() const { | 1375 bool QuicConnection::HasQueuedData() const { |
1438 return !queued_packets_.empty() || packet_generator_.HasQueuedFrames(); | 1376 return !queued_packets_.empty() || packet_generator_.HasQueuedFrames(); |
1439 } | 1377 } |
1440 | 1378 |
1441 void QuicConnection::SetIdleNetworkTimeout(QuicTime::Delta timeout) { | 1379 void QuicConnection::SetIdleNetworkTimeout(QuicTime::Delta timeout) { |
1442 if (timeout < idle_network_timeout_) { | 1380 // if (timeout < idle_network_timeout_) { |
1443 idle_network_timeout_ = timeout; | 1381 idle_network_timeout_ = timeout; |
1444 CheckForTimeout(); | 1382 CheckForTimeout(); |
1445 } else { | 1383 // } else { |
1446 idle_network_timeout_ = timeout; | 1384 // idle_network_timeout_ = timeout; |
1447 } | 1385 // } |
1448 } | 1386 } |
1449 | 1387 |
1450 void QuicConnection::SetOverallConnectionTimeout(QuicTime::Delta timeout) { | 1388 void QuicConnection::SetOverallConnectionTimeout(QuicTime::Delta timeout) { |
1451 if (timeout < overall_connection_timeout_) { | 1389 // if (timeout < overall_connection_timeout_) { |
1452 overall_connection_timeout_ = timeout; | 1390 overall_connection_timeout_ = timeout; |
1453 CheckForTimeout(); | 1391 CheckForTimeout(); |
1454 } else { | 1392 // } else { |
1455 overall_connection_timeout_ = timeout; | 1393 // overall_connection_timeout_ = timeout; |
1456 } | 1394 // } |
1457 } | 1395 } |
1458 | 1396 |
1459 bool QuicConnection::CheckForTimeout() { | 1397 bool QuicConnection::CheckForTimeout() { |
1460 QuicTime now = clock_->ApproximateNow(); | 1398 QuicTime now = clock_->ApproximateNow(); |
1461 QuicTime time_of_last_packet = std::max(time_of_last_received_packet_, | 1399 QuicTime time_of_last_packet = std::max(time_of_last_received_packet_, |
1462 time_of_last_sent_packet_); | 1400 time_of_last_sent_packet_); |
1463 | 1401 |
1464 // |delta| can be < 0 as |now| is approximate time but |time_of_last_packet| | |
1465 // is accurate time. However, this should not change the behavior of | |
1466 // timeout handling. | |
1467 QuicTime::Delta delta = now.Subtract(time_of_last_packet); | 1402 QuicTime::Delta delta = now.Subtract(time_of_last_packet); |
1468 DVLOG(1) << ENDPOINT << "last packet " | 1403 DVLOG(1) << ENDPOINT << "last packet " |
1469 << time_of_last_packet.ToDebuggingValue() | 1404 << time_of_last_packet.ToDebuggingValue() |
1470 << " now:" << now.ToDebuggingValue() | 1405 << " now:" << now.ToDebuggingValue() |
1471 << " delta:" << delta.ToMicroseconds() | 1406 << " delta:" << delta.ToMicroseconds() |
1472 << " network_timeout: " << idle_network_timeout_.ToMicroseconds(); | 1407 << " network_timeout: " << idle_network_timeout_.ToMicroseconds(); |
1473 if (delta >= idle_network_timeout_) { | 1408 if (delta >= idle_network_timeout_) { |
1474 DVLOG(1) << ENDPOINT << "Connection timedout due to no network activity."; | 1409 DVLOG(1) << ENDPOINT << "Connection timedout due to no network activity."; |
1475 SendConnectionClose(QUIC_CONNECTION_TIMED_OUT); | 1410 SendConnectionClose(QUIC_CONNECTION_TIMED_OUT); |
1476 return true; | 1411 return true; |
(...skipping 20 matching lines...) Expand all Loading... |
1497 if (connection_timeout < timeout) { | 1432 if (connection_timeout < timeout) { |
1498 timeout = connection_timeout; | 1433 timeout = connection_timeout; |
1499 } | 1434 } |
1500 } | 1435 } |
1501 | 1436 |
1502 helper_->SetTimeoutAlarm(timeout); | 1437 helper_->SetTimeoutAlarm(timeout); |
1503 return false; | 1438 return false; |
1504 } | 1439 } |
1505 | 1440 |
1506 } // namespace net | 1441 } // namespace net |
OLD | NEW |