Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Side by Side Diff: net/quic/core/congestion_control/pacing_sender.cc

Issue 2228783004: Fix memory corruption from SetMaxPacingRate by inlining PacingSender. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@129351671
Patch Set: git pull from upper stream Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/core/congestion_control/pacing_sender.h" 5 #include "net/quic/core/congestion_control/pacing_sender.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "net/quic/core/quic_flags.h" 9 #include "net/quic/core/quic_flags.h"
10 10
11 using std::min; 11 using std::min;
12 12
13 namespace net { 13 namespace net {
14 namespace {
14 15
15 PacingSender::PacingSender(SendAlgorithmInterface* sender, 16 // The estimated system alarm granularity.
16 QuicTime::Delta alarm_granularity, 17 static const QuicTime::Delta kAlarmGranularity =
17 uint32_t initial_packet_burst) 18 QuicTime::Delta::FromMilliseconds(1);
18 : sender_(sender), 19
19 alarm_granularity_(alarm_granularity), 20 // Configured maximum size of the burst coming out of quiescence. The burst
20 initial_packet_burst_(initial_packet_burst), 21 // is never larger than the current CWND in packets.
22 static const uint32_t kInitialUnpacedBurst = 10;
23
24 } // namespace
25
26 PacingSender::PacingSender()
27 : sender_(nullptr),
21 max_pacing_rate_(QuicBandwidth::Zero()), 28 max_pacing_rate_(QuicBandwidth::Zero()),
22 burst_tokens_(initial_packet_burst), 29 burst_tokens_(kInitialUnpacedBurst),
23 last_delayed_packet_sent_time_(QuicTime::Zero()), 30 last_delayed_packet_sent_time_(QuicTime::Zero()),
24 ideal_next_packet_send_time_(QuicTime::Zero()), 31 ideal_next_packet_send_time_(QuicTime::Zero()),
25 was_last_send_delayed_(false) {} 32 was_last_send_delayed_(false) {}
26 33
27 PacingSender::~PacingSender() {} 34 PacingSender::~PacingSender() {}
28 35
29 void PacingSender::SetFromConfig(const QuicConfig& config, 36 void PacingSender::set_sender(SendAlgorithmInterface* sender) {
30 Perspective perspective) { 37 DCHECK(sender != nullptr);
31 sender_->SetFromConfig(config, perspective); 38 sender_ = sender;
32 } 39 }
33 40
34 void PacingSender::ResumeConnectionState( 41 void PacingSender::OnCongestionEvent(
35 const CachedNetworkParameters& cached_network_params, 42 bool rtt_updated,
36 bool max_bandwidth_resumption) { 43 QuicByteCount bytes_in_flight,
37 sender_->ResumeConnectionState(cached_network_params, 44 const SendAlgorithmInterface::CongestionVector& acked_packets,
38 max_bandwidth_resumption); 45 const SendAlgorithmInterface::CongestionVector& lost_packets) {
39 } 46 DCHECK(sender_ != nullptr);
40
41 void PacingSender::SetNumEmulatedConnections(int num_connections) {
42 sender_->SetNumEmulatedConnections(num_connections);
43 }
44
45 void PacingSender::SetMaxPacingRate(QuicBandwidth max_pacing_rate) {
46 max_pacing_rate_ = max_pacing_rate;
47 }
48
49 void PacingSender::OnCongestionEvent(bool rtt_updated,
50 QuicByteCount bytes_in_flight,
51 const CongestionVector& acked_packets,
52 const CongestionVector& lost_packets) {
53 if (!lost_packets.empty()) { 47 if (!lost_packets.empty()) {
54 // Clear any burst tokens when entering recovery. 48 // Clear any burst tokens when entering recovery.
55 burst_tokens_ = 0; 49 burst_tokens_ = 0;
56 } 50 }
57 sender_->OnCongestionEvent(rtt_updated, bytes_in_flight, acked_packets, 51 sender_->OnCongestionEvent(rtt_updated, bytes_in_flight, acked_packets,
58 lost_packets); 52 lost_packets);
59 } 53 }
60 54
61 bool PacingSender::OnPacketSent( 55 bool PacingSender::OnPacketSent(
62 QuicTime sent_time, 56 QuicTime sent_time,
63 QuicByteCount bytes_in_flight, 57 QuicByteCount bytes_in_flight,
64 QuicPacketNumber packet_number, 58 QuicPacketNumber packet_number,
65 QuicByteCount bytes, 59 QuicByteCount bytes,
66 HasRetransmittableData has_retransmittable_data) { 60 HasRetransmittableData has_retransmittable_data) {
61 DCHECK(sender_ != nullptr);
67 const bool in_flight = 62 const bool in_flight =
68 sender_->OnPacketSent(sent_time, bytes_in_flight, packet_number, bytes, 63 sender_->OnPacketSent(sent_time, bytes_in_flight, packet_number, bytes,
69 has_retransmittable_data); 64 has_retransmittable_data);
70 if (has_retransmittable_data != HAS_RETRANSMITTABLE_DATA) { 65 if (has_retransmittable_data != HAS_RETRANSMITTABLE_DATA) {
71 return in_flight; 66 return in_flight;
72 } 67 }
73 // If in recovery, the connection is not coming out of quiescence. 68 // If in recovery, the connection is not coming out of quiescence.
74 if (bytes_in_flight == 0 && !sender_->InRecovery()) { 69 if (bytes_in_flight == 0 && !sender_->InRecovery()) {
75 // Add more burst tokens anytime the connection is leaving quiescence, but 70 // Add more burst tokens anytime the connection is leaving quiescence, but
76 // limit it to the equivalent of a single bulk write, not exceeding the 71 // limit it to the equivalent of a single bulk write, not exceeding the
77 // current CWND in packets. 72 // current CWND in packets.
78 burst_tokens_ = min( 73 burst_tokens_ = min(
79 initial_packet_burst_, 74 kInitialUnpacedBurst,
80 static_cast<uint32_t>(sender_->GetCongestionWindow() / kDefaultTCPMSS)); 75 static_cast<uint32_t>(sender_->GetCongestionWindow() / kDefaultTCPMSS));
81 } 76 }
82 if (burst_tokens_ > 0) { 77 if (burst_tokens_ > 0) {
83 --burst_tokens_; 78 --burst_tokens_;
84 was_last_send_delayed_ = false; 79 was_last_send_delayed_ = false;
85 last_delayed_packet_sent_time_ = QuicTime::Zero(); 80 last_delayed_packet_sent_time_ = QuicTime::Zero();
86 ideal_next_packet_send_time_ = QuicTime::Zero(); 81 ideal_next_packet_send_time_ = QuicTime::Zero();
87 return in_flight; 82 return in_flight;
88 } 83 }
89 // The next packet should be sent as soon as the current packet has been 84 // The next packet should be sent as soon as the current packet has been
(...skipping 20 matching lines...) Expand all
110 was_last_send_delayed_ = false; 105 was_last_send_delayed_ = false;
111 last_delayed_packet_sent_time_ = QuicTime::Zero(); 106 last_delayed_packet_sent_time_ = QuicTime::Zero();
112 } 107 }
113 } else { 108 } else {
114 ideal_next_packet_send_time_ = 109 ideal_next_packet_send_time_ =
115 std::max(ideal_next_packet_send_time_ + delay, sent_time + delay); 110 std::max(ideal_next_packet_send_time_ + delay, sent_time + delay);
116 } 111 }
117 return in_flight; 112 return in_flight;
118 } 113 }
119 114
120 void PacingSender::OnRetransmissionTimeout(bool packets_retransmitted) {
121 sender_->OnRetransmissionTimeout(packets_retransmitted);
122 }
123
124 void PacingSender::OnConnectionMigration() {
125 sender_->OnConnectionMigration();
126 }
127
128 QuicTime::Delta PacingSender::TimeUntilSend( 115 QuicTime::Delta PacingSender::TimeUntilSend(
129 QuicTime now, 116 QuicTime now,
130 QuicByteCount bytes_in_flight) const { 117 QuicByteCount bytes_in_flight) const {
118 DCHECK(sender_ != nullptr);
131 QuicTime::Delta time_until_send = 119 QuicTime::Delta time_until_send =
132 sender_->TimeUntilSend(now, bytes_in_flight); 120 sender_->TimeUntilSend(now, bytes_in_flight);
133 if (burst_tokens_ > 0 || bytes_in_flight == 0) { 121 if (burst_tokens_ > 0 || bytes_in_flight == 0) {
134 // Don't pace if we have burst tokens available or leaving quiescence. 122 // Don't pace if we have burst tokens available or leaving quiescence.
135 return time_until_send; 123 return time_until_send;
136 } 124 }
137 125
138 if (!time_until_send.IsZero()) { 126 if (!time_until_send.IsZero()) {
139 DCHECK(time_until_send.IsInfinite()); 127 DCHECK(time_until_send.IsInfinite());
140 // The underlying sender prevents sending. 128 // The underlying sender prevents sending.
141 return time_until_send; 129 return time_until_send;
142 } 130 }
143 131
144 // If the next send time is within the alarm granularity, send immediately. 132 // If the next send time is within the alarm granularity, send immediately.
145 if (ideal_next_packet_send_time_ > now + alarm_granularity_) { 133 if (ideal_next_packet_send_time_ > now + kAlarmGranularity) {
146 DVLOG(1) << "Delaying packet: " 134 DVLOG(1) << "Delaying packet: "
147 << (ideal_next_packet_send_time_ - now).ToMicroseconds(); 135 << (ideal_next_packet_send_time_ - now).ToMicroseconds();
148 was_last_send_delayed_ = true; 136 was_last_send_delayed_ = true;
149 return ideal_next_packet_send_time_ - now; 137 return ideal_next_packet_send_time_ - now;
150 } 138 }
151 139
152 DVLOG(1) << "Sending packet now"; 140 DVLOG(1) << "Sending packet now";
153 return QuicTime::Delta::Zero(); 141 return QuicTime::Delta::Zero();
154 } 142 }
155 143
156 QuicBandwidth PacingSender::PacingRate(QuicByteCount bytes_in_flight) const { 144 QuicBandwidth PacingSender::PacingRate(QuicByteCount bytes_in_flight) const {
145 DCHECK(sender_ != nullptr);
157 if (!max_pacing_rate_.IsZero()) { 146 if (!max_pacing_rate_.IsZero()) {
158 return QuicBandwidth::FromBitsPerSecond( 147 return QuicBandwidth::FromBitsPerSecond(
159 min(max_pacing_rate_.ToBitsPerSecond(), 148 min(max_pacing_rate_.ToBitsPerSecond(),
160 sender_->PacingRate(bytes_in_flight).ToBitsPerSecond())); 149 sender_->PacingRate(bytes_in_flight).ToBitsPerSecond()));
161 } 150 }
162 return sender_->PacingRate(bytes_in_flight); 151 return sender_->PacingRate(bytes_in_flight);
163 } 152 }
164 153
165 QuicBandwidth PacingSender::BandwidthEstimate() const {
166 return sender_->BandwidthEstimate();
167 }
168
169 QuicTime::Delta PacingSender::RetransmissionDelay() const {
170 return sender_->RetransmissionDelay();
171 }
172
173 QuicByteCount PacingSender::GetCongestionWindow() const {
174 return sender_->GetCongestionWindow();
175 }
176
177 bool PacingSender::InSlowStart() const {
178 return sender_->InSlowStart();
179 }
180
181 bool PacingSender::InRecovery() const {
182 return sender_->InRecovery();
183 }
184
185 QuicByteCount PacingSender::GetSlowStartThreshold() const {
186 return sender_->GetSlowStartThreshold();
187 }
188
189 CongestionControlType PacingSender::GetCongestionControlType() const {
190 return sender_->GetCongestionControlType();
191 }
192
193 std::string PacingSender::GetDebugState() const {
194 return sender_->GetDebugState();
195 }
196
197 void PacingSender::OnApplicationLimited(QuicByteCount bytes_in_flight) {}
198
199 } // namespace net 154 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/congestion_control/pacing_sender.h ('k') | net/quic/core/congestion_control/pacing_sender_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698