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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 /* | 183 /* |
184 if (FLAGS_fake_packet_loss_percentage > 0) { | 184 if (FLAGS_fake_packet_loss_percentage > 0) { |
185 int32 seed = RandomBase::WeakSeed32(); | 185 int32 seed = RandomBase::WeakSeed32(); |
186 LOG(INFO) << ENDPOINT << "Seeding packet loss with " << seed; | 186 LOG(INFO) << ENDPOINT << "Seeding packet loss with " << seed; |
187 random_.reset(new MTRandom(seed)); | 187 random_.reset(new MTRandom(seed)); |
188 } | 188 } |
189 */ | 189 */ |
190 } | 190 } |
191 | 191 |
192 QuicConnection::~QuicConnection() { | 192 QuicConnection::~QuicConnection() { |
| 193 STLDeleteElements(&ack_notifiers_); |
193 STLDeleteElements(&undecryptable_packets_); | 194 STLDeleteElements(&undecryptable_packets_); |
194 STLDeleteValues(&unacked_packets_); | 195 STLDeleteValues(&unacked_packets_); |
195 STLDeleteValues(&group_map_); | 196 STLDeleteValues(&group_map_); |
196 for (QueuedPacketList::iterator it = queued_packets_.begin(); | 197 for (QueuedPacketList::iterator it = queued_packets_.begin(); |
197 it != queued_packets_.end(); ++it) { | 198 it != queued_packets_.end(); ++it) { |
198 delete it->packet; | 199 delete it->packet; |
199 } | 200 } |
200 } | 201 } |
201 | 202 |
202 bool QuicConnection::SelectMutualVersion( | 203 bool QuicConnection::SelectMutualVersion( |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 CloseFecGroupsBefore(incoming_ack.sent_info.least_unacked + 1); | 450 CloseFecGroupsBefore(incoming_ack.sent_info.least_unacked + 1); |
450 | 451 |
451 sent_entropy_manager_.ClearEntropyBefore( | 452 sent_entropy_manager_.ClearEntropyBefore( |
452 received_packet_manager_.least_packet_awaited_by_peer() - 1); | 453 received_packet_manager_.least_packet_awaited_by_peer() - 1); |
453 | 454 |
454 SequenceNumberSet acked_packets; | 455 SequenceNumberSet acked_packets; |
455 HandleAckForSentPackets(incoming_ack, &acked_packets); | 456 HandleAckForSentPackets(incoming_ack, &acked_packets); |
456 HandleAckForSentFecPackets(incoming_ack, &acked_packets); | 457 HandleAckForSentFecPackets(incoming_ack, &acked_packets); |
457 if (acked_packets.size() > 0) { | 458 if (acked_packets.size() > 0) { |
458 visitor_->OnAck(acked_packets); | 459 visitor_->OnAck(acked_packets); |
| 460 |
| 461 // Inform all the registered AckNotifiers of the new ACKs. |
| 462 // TODO(rjshade): Make this more efficient by maintaining a mapping of |
| 463 // <sequence number, set<AckNotifierList>> so that OnAck |
| 464 // is only called on AckNotifiers that care about the |
| 465 // packets being ACKed. |
| 466 AckNotifierList::iterator it = ack_notifiers_.begin(); |
| 467 while (it != ack_notifiers_.end()) { |
| 468 if ((*it)->OnAck(acked_packets)) { |
| 469 // The QuicAckNotifier has seen all the ACKs it was interested in, and |
| 470 // has triggered its callback. No more use for it. |
| 471 delete *it; |
| 472 it = ack_notifiers_.erase(it); |
| 473 } else { |
| 474 ++it; |
| 475 } |
| 476 } |
459 } | 477 } |
460 congestion_manager_.OnIncomingAckFrame(incoming_ack, | 478 congestion_manager_.OnIncomingAckFrame(incoming_ack, |
461 time_of_last_received_packet_); | 479 time_of_last_received_packet_); |
462 } | 480 } |
463 | 481 |
464 bool QuicConnection::OnCongestionFeedbackFrame( | 482 bool QuicConnection::OnCongestionFeedbackFrame( |
465 const QuicCongestionFeedbackFrame& feedback) { | 483 const QuicCongestionFeedbackFrame& feedback) { |
466 DCHECK(connected_); | 484 DCHECK(connected_); |
467 if (debug_visitor_) { | 485 if (debug_visitor_) { |
468 debug_visitor_->OnCongestionFeedbackFrame(feedback); | 486 debug_visitor_->OnCongestionFeedbackFrame(feedback); |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 } | 832 } |
815 QuicConsumedData consumed_data = | 833 QuicConsumedData consumed_data = |
816 packet_generator_.ConsumeData(id, data, offset, fin); | 834 packet_generator_.ConsumeData(id, data, offset, fin); |
817 if (crypto_frame_while_batch_mode) { | 835 if (crypto_frame_while_batch_mode) { |
818 // Restore batch mode. | 836 // Restore batch mode. |
819 packet_generator_.StartBatchOperations(); | 837 packet_generator_.StartBatchOperations(); |
820 } | 838 } |
821 return consumed_data; | 839 return consumed_data; |
822 } | 840 } |
823 | 841 |
| 842 QuicConsumedData QuicConnection::SendStreamDataAndNotifyWhenAcked( |
| 843 QuicStreamId id, |
| 844 StringPiece data, |
| 845 QuicStreamOffset offset, |
| 846 bool fin, |
| 847 QuicAckNotifier::DelegateInterface* delegate) { |
| 848 // This notifier will be deleted in ProcessAckFrame once it has seen ACKs for |
| 849 // all the consumed data (or below if no data was consumed). |
| 850 QuicAckNotifier* notifier = new QuicAckNotifier(delegate); |
| 851 QuicConsumedData consumed_data = |
| 852 packet_generator_.ConsumeData(id, data, offset, fin, notifier); |
| 853 |
| 854 if (consumed_data.bytes_consumed > 0) { |
| 855 // If some data was consumed, then the delegate should be registered for |
| 856 // notification when the data is ACKed. |
| 857 ack_notifiers_.push_back(notifier); |
| 858 } else { |
| 859 // No data was consumed, delete the notifier. |
| 860 delete notifier; |
| 861 } |
| 862 |
| 863 return consumed_data; |
| 864 } |
| 865 |
824 void QuicConnection::SendRstStream(QuicStreamId id, | 866 void QuicConnection::SendRstStream(QuicStreamId id, |
825 QuicRstStreamErrorCode error) { | 867 QuicRstStreamErrorCode error) { |
826 LOG(INFO) << "Sending RST_STREAM: " << id << " code: " << error; | 868 LOG(INFO) << "Sending RST_STREAM: " << id << " code: " << error; |
827 packet_generator_.AddControlFrame( | 869 packet_generator_.AddControlFrame( |
828 QuicFrame(new QuicRstStreamFrame(id, error))); | 870 QuicFrame(new QuicRstStreamFrame(id, error))); |
829 } | 871 } |
830 | 872 |
831 const QuicConnectionStats& QuicConnection::GetStats() { | 873 const QuicConnectionStats& QuicConnection::GetStats() { |
832 // Update rtt and estimated bandwidth. | 874 // Update rtt and estimated bandwidth. |
833 stats_.rtt = congestion_manager_.SmoothedRtt().ToMicroseconds(); | 875 stats_.rtt = congestion_manager_.SmoothedRtt().ToMicroseconds(); |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 packet_creator_.ReserializeAllFrames(unacked->frames(), | 1097 packet_creator_.ReserializeAllFrames(unacked->frames(), |
1056 original_sequence_number_length); | 1098 original_sequence_number_length); |
1057 RetransmissionInfo retransmission_info( | 1099 RetransmissionInfo retransmission_info( |
1058 serialized_packet.sequence_number, | 1100 serialized_packet.sequence_number, |
1059 serialized_packet.sequence_number_length); | 1101 serialized_packet.sequence_number_length); |
1060 retransmission_info.number_retransmissions = | 1102 retransmission_info.number_retransmissions = |
1061 retransmission_it->second.number_retransmissions + 1; | 1103 retransmission_it->second.number_retransmissions + 1; |
1062 // Remove info with old sequence number. | 1104 // Remove info with old sequence number. |
1063 unacked_packets_.erase(unacked_it); | 1105 unacked_packets_.erase(unacked_it); |
1064 retransmission_map_.erase(retransmission_it); | 1106 retransmission_map_.erase(retransmission_it); |
1065 DVLOG(1) << ENDPOINT << "Retransmitting unacked packet " << sequence_number | 1107 DLOG(INFO) << ENDPOINT << "Retransmitting unacked packet " << sequence_number |
1066 << " as " << serialized_packet.sequence_number; | 1108 << " as " << serialized_packet.sequence_number; |
1067 DCHECK(unacked_packets_.empty() || | 1109 DCHECK(unacked_packets_.empty() || |
1068 unacked_packets_.rbegin()->first < serialized_packet.sequence_number); | 1110 unacked_packets_.rbegin()->first < serialized_packet.sequence_number); |
1069 unacked_packets_.insert(make_pair(serialized_packet.sequence_number, | 1111 unacked_packets_.insert(make_pair(serialized_packet.sequence_number, |
1070 unacked)); | 1112 unacked)); |
1071 retransmission_map_.insert(make_pair(serialized_packet.sequence_number, | 1113 retransmission_map_.insert(make_pair(serialized_packet.sequence_number, |
1072 retransmission_info)); | 1114 retransmission_info)); |
| 1115 |
| 1116 // A notifier may be waiting to hear about ACKs for the original sequence |
| 1117 // number. Inform them that the sequence number has changed. |
| 1118 for (AckNotifierList::iterator notifier_it = ack_notifiers_.begin(); |
| 1119 notifier_it != ack_notifiers_.end(); ++notifier_it) { |
| 1120 (*notifier_it)->UpdateSequenceNumber(sequence_number, |
| 1121 serialized_packet.sequence_number); |
| 1122 } |
| 1123 |
1073 if (debug_visitor_) { | 1124 if (debug_visitor_) { |
1074 debug_visitor_->OnPacketRetransmitted(sequence_number, | 1125 debug_visitor_->OnPacketRetransmitted(sequence_number, |
1075 serialized_packet.sequence_number); | 1126 serialized_packet.sequence_number); |
1076 } | 1127 } |
1077 SendOrQueuePacket(unacked->encryption_level(), | 1128 SendOrQueuePacket(unacked->encryption_level(), |
1078 serialized_packet.sequence_number, | 1129 serialized_packet.sequence_number, |
1079 serialized_packet.packet, | 1130 serialized_packet.packet, |
1080 serialized_packet.entropy_hash, | 1131 serialized_packet.entropy_hash, |
1081 HAS_RETRANSMITTABLE_DATA); | 1132 HAS_RETRANSMITTABLE_DATA); |
1082 } | 1133 } |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1729 timeout = connection_timeout; | 1780 timeout = connection_timeout; |
1730 } | 1781 } |
1731 } | 1782 } |
1732 | 1783 |
1733 timeout_alarm_->Cancel(); | 1784 timeout_alarm_->Cancel(); |
1734 timeout_alarm_->Set(clock_->ApproximateNow().Add(timeout)); | 1785 timeout_alarm_->Set(clock_->ApproximateNow().Add(timeout)); |
1735 return false; | 1786 return false; |
1736 } | 1787 } |
1737 | 1788 |
1738 } // namespace net | 1789 } // namespace net |
OLD | NEW |