| 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_server_session_base.h" | 5 #include "net/quic/quic_server_session_base.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "net/quic/proto/cached_network_parameters.pb.h" | 8 #include "net/quic/proto/cached_network_parameters.pb.h" |
| 9 #include "net/quic/quic_bug_tracker.h" | 9 #include "net/quic/quic_bug_tracker.h" |
| 10 #include "net/quic/quic_connection.h" | 10 #include "net/quic/quic_connection.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 int64_t packets_since_last_scup = | 120 int64_t packets_since_last_scup = |
| 121 connection()->packet_number_of_last_sent_packet() - | 121 connection()->packet_number_of_last_sent_packet() - |
| 122 last_scup_packet_number_; | 122 last_scup_packet_number_; |
| 123 if (now_ms < (kMinIntervalBetweenServerConfigUpdatesRTTs * srtt_ms) || | 123 if (now_ms < (kMinIntervalBetweenServerConfigUpdatesRTTs * srtt_ms) || |
| 124 now_ms < kMinIntervalBetweenServerConfigUpdatesMs || | 124 now_ms < kMinIntervalBetweenServerConfigUpdatesMs || |
| 125 packets_since_last_scup < kMinPacketsBetweenServerConfigUpdates) { | 125 packets_since_last_scup < kMinPacketsBetweenServerConfigUpdates) { |
| 126 return; | 126 return; |
| 127 } | 127 } |
| 128 | 128 |
| 129 // If the bandwidth recorder does not have a valid estimate, return early. | 129 // If the bandwidth recorder does not have a valid estimate, return early. |
| 130 const QuicSustainedBandwidthRecorder& bandwidth_recorder = | 130 const QuicSustainedBandwidthRecorder* bandwidth_recorder = |
| 131 sent_packet_manager.SustainedBandwidthRecorder(); | 131 sent_packet_manager.SustainedBandwidthRecorder(); |
| 132 if (!bandwidth_recorder.HasEstimate()) { | 132 if (bandwidth_recorder == nullptr || !bandwidth_recorder->HasEstimate()) { |
| 133 return; | 133 return; |
| 134 } | 134 } |
| 135 | 135 |
| 136 // The bandwidth recorder has recorded at least one sustained bandwidth | 136 // The bandwidth recorder has recorded at least one sustained bandwidth |
| 137 // estimate. Check that it's substantially different from the last one that | 137 // estimate. Check that it's substantially different from the last one that |
| 138 // we sent to the client, and if so, send the new one. | 138 // we sent to the client, and if so, send the new one. |
| 139 QuicBandwidth new_bandwidth_estimate = bandwidth_recorder.BandwidthEstimate(); | 139 QuicBandwidth new_bandwidth_estimate = |
| 140 bandwidth_recorder->BandwidthEstimate(); |
| 140 | 141 |
| 141 int64_t bandwidth_delta = | 142 int64_t bandwidth_delta = |
| 142 std::abs(new_bandwidth_estimate.ToBitsPerSecond() - | 143 std::abs(new_bandwidth_estimate.ToBitsPerSecond() - |
| 143 bandwidth_estimate_sent_to_client_.ToBitsPerSecond()); | 144 bandwidth_estimate_sent_to_client_.ToBitsPerSecond()); |
| 144 | 145 |
| 145 // Define "substantial" difference as a 50% increase or decrease from the | 146 // Define "substantial" difference as a 50% increase or decrease from the |
| 146 // last estimate. | 147 // last estimate. |
| 147 bool substantial_difference = | 148 bool substantial_difference = |
| 148 bandwidth_delta > | 149 bandwidth_delta > |
| 149 0.5 * bandwidth_estimate_sent_to_client_.ToBitsPerSecond(); | 150 0.5 * bandwidth_estimate_sent_to_client_.ToBitsPerSecond(); |
| 150 if (!substantial_difference) { | 151 if (!substantial_difference) { |
| 151 return; | 152 return; |
| 152 } | 153 } |
| 153 | 154 |
| 154 bandwidth_estimate_sent_to_client_ = new_bandwidth_estimate; | 155 bandwidth_estimate_sent_to_client_ = new_bandwidth_estimate; |
| 155 DVLOG(1) << "Server: sending new bandwidth estimate (KBytes/s): " | 156 DVLOG(1) << "Server: sending new bandwidth estimate (KBytes/s): " |
| 156 << bandwidth_estimate_sent_to_client_.ToKBytesPerSecond(); | 157 << bandwidth_estimate_sent_to_client_.ToKBytesPerSecond(); |
| 157 | 158 |
| 158 // Include max bandwidth in the update. | 159 // Include max bandwidth in the update. |
| 159 QuicBandwidth max_bandwidth_estimate = | 160 QuicBandwidth max_bandwidth_estimate = |
| 160 bandwidth_recorder.MaxBandwidthEstimate(); | 161 bandwidth_recorder->MaxBandwidthEstimate(); |
| 161 int32_t max_bandwidth_timestamp = bandwidth_recorder.MaxBandwidthTimestamp(); | 162 int32_t max_bandwidth_timestamp = bandwidth_recorder->MaxBandwidthTimestamp(); |
| 162 | 163 |
| 163 // Fill the proto before passing it to the crypto stream to send. | 164 // Fill the proto before passing it to the crypto stream to send. |
| 164 const int32_t bw_estimate_bytes_per_second = | 165 const int32_t bw_estimate_bytes_per_second = |
| 165 BandwidthToCachedParameterBytesPerSecond( | 166 BandwidthToCachedParameterBytesPerSecond( |
| 166 bandwidth_estimate_sent_to_client_); | 167 bandwidth_estimate_sent_to_client_); |
| 167 const int32_t max_bw_estimate_bytes_per_second = | 168 const int32_t max_bw_estimate_bytes_per_second = |
| 168 BandwidthToCachedParameterBytesPerSecond(max_bandwidth_estimate); | 169 BandwidthToCachedParameterBytesPerSecond(max_bandwidth_estimate); |
| 169 QUIC_BUG_IF(max_bw_estimate_bytes_per_second < 0) | 170 QUIC_BUG_IF(max_bw_estimate_bytes_per_second < 0) |
| 170 << max_bw_estimate_bytes_per_second; | 171 << max_bw_estimate_bytes_per_second; |
| 171 QUIC_BUG_IF(bw_estimate_bytes_per_second < 0) << bw_estimate_bytes_per_second; | 172 QUIC_BUG_IF(bw_estimate_bytes_per_second < 0) << bw_estimate_bytes_per_second; |
| 172 | 173 |
| 173 CachedNetworkParameters cached_network_params; | 174 CachedNetworkParameters cached_network_params; |
| 174 cached_network_params.set_bandwidth_estimate_bytes_per_second( | 175 cached_network_params.set_bandwidth_estimate_bytes_per_second( |
| 175 bw_estimate_bytes_per_second); | 176 bw_estimate_bytes_per_second); |
| 176 cached_network_params.set_max_bandwidth_estimate_bytes_per_second( | 177 cached_network_params.set_max_bandwidth_estimate_bytes_per_second( |
| 177 max_bw_estimate_bytes_per_second); | 178 max_bw_estimate_bytes_per_second); |
| 178 cached_network_params.set_max_bandwidth_timestamp_seconds( | 179 cached_network_params.set_max_bandwidth_timestamp_seconds( |
| 179 max_bandwidth_timestamp); | 180 max_bandwidth_timestamp); |
| 180 cached_network_params.set_min_rtt_ms( | 181 cached_network_params.set_min_rtt_ms( |
| 181 sent_packet_manager.GetRttStats()->min_rtt().ToMilliseconds()); | 182 sent_packet_manager.GetRttStats()->min_rtt().ToMilliseconds()); |
| 182 cached_network_params.set_previous_connection_state( | 183 cached_network_params.set_previous_connection_state( |
| 183 bandwidth_recorder.EstimateRecordedDuringSlowStart() | 184 bandwidth_recorder->EstimateRecordedDuringSlowStart() |
| 184 ? CachedNetworkParameters::SLOW_START | 185 ? CachedNetworkParameters::SLOW_START |
| 185 : CachedNetworkParameters::CONGESTION_AVOIDANCE); | 186 : CachedNetworkParameters::CONGESTION_AVOIDANCE); |
| 186 cached_network_params.set_timestamp( | 187 cached_network_params.set_timestamp( |
| 187 connection()->clock()->WallNow().ToUNIXSeconds()); | 188 connection()->clock()->WallNow().ToUNIXSeconds()); |
| 188 if (!serving_region_.empty()) { | 189 if (!serving_region_.empty()) { |
| 189 cached_network_params.set_serving_region(serving_region_); | 190 cached_network_params.set_serving_region(serving_region_); |
| 190 } | 191 } |
| 191 | 192 |
| 192 crypto_stream_->SendServerConfigUpdate(&cached_network_params); | 193 crypto_stream_->SendServerConfigUpdate(&cached_network_params); |
| 193 | 194 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 | 249 |
| 249 int32_t QuicServerSessionBase::BandwidthToCachedParameterBytesPerSecond( | 250 int32_t QuicServerSessionBase::BandwidthToCachedParameterBytesPerSecond( |
| 250 const QuicBandwidth& bandwidth) { | 251 const QuicBandwidth& bandwidth) { |
| 251 int64_t bytes_per_second = bandwidth.ToBytesPerSecond(); | 252 int64_t bytes_per_second = bandwidth.ToBytesPerSecond(); |
| 252 return (bytes_per_second > static_cast<int64_t>(INT32_MAX) | 253 return (bytes_per_second > static_cast<int64_t>(INT32_MAX) |
| 253 ? INT32_MAX | 254 ? INT32_MAX |
| 254 : static_cast<int32_t>(bytes_per_second)); | 255 : static_cast<int32_t>(bytes_per_second)); |
| 255 } | 256 } |
| 256 | 257 |
| 257 } // namespace net | 258 } // namespace net |
| OLD | NEW |