| 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/tools/quic/quic_server_session.h" | 5 #include "net/tools/quic/quic_server_session.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_connection.h" | 9 #include "net/quic/quic_connection.h" |
| 10 #include "net/quic/quic_flags.h" | 10 #include "net/quic/quic_flags.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 const CachedNetworkParameters* cached_network_params = | 53 const CachedNetworkParameters* cached_network_params = |
| 54 crypto_stream_->PreviousCachedNetworkParams(); | 54 crypto_stream_->PreviousCachedNetworkParams(); |
| 55 const bool last_bandwidth_resumption = | 55 const bool last_bandwidth_resumption = |
| 56 ContainsQuicTag(config()->ReceivedConnectionOptions(), kBWRE); | 56 ContainsQuicTag(config()->ReceivedConnectionOptions(), kBWRE); |
| 57 const bool max_bandwidth_resumption = | 57 const bool max_bandwidth_resumption = |
| 58 ContainsQuicTag(config()->ReceivedConnectionOptions(), kBWMX); | 58 ContainsQuicTag(config()->ReceivedConnectionOptions(), kBWMX); |
| 59 bandwidth_resumption_enabled_ = | 59 bandwidth_resumption_enabled_ = |
| 60 last_bandwidth_resumption || max_bandwidth_resumption; | 60 last_bandwidth_resumption || max_bandwidth_resumption; |
| 61 if (cached_network_params != nullptr && bandwidth_resumption_enabled_ && | 61 if (cached_network_params != nullptr && bandwidth_resumption_enabled_ && |
| 62 cached_network_params->serving_region() == serving_region_) { | 62 cached_network_params->serving_region() == serving_region_) { |
| 63 int64 seconds_since_estimate = | 63 int64_t seconds_since_estimate = |
| 64 connection()->clock()->WallNow().ToUNIXSeconds() - | 64 connection()->clock()->WallNow().ToUNIXSeconds() - |
| 65 cached_network_params->timestamp(); | 65 cached_network_params->timestamp(); |
| 66 bool estimate_within_last_hour = | 66 bool estimate_within_last_hour = |
| 67 seconds_since_estimate <= kNumSecondsPerHour; | 67 seconds_since_estimate <= kNumSecondsPerHour; |
| 68 if (estimate_within_last_hour) { | 68 if (estimate_within_last_hour) { |
| 69 connection()->ResumeConnectionState(*cached_network_params, | 69 connection()->ResumeConnectionState(*cached_network_params, |
| 70 max_bandwidth_resumption); | 70 max_bandwidth_resumption); |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 101 } | 101 } |
| 102 // Only send updates when the application has no data to write. | 102 // Only send updates when the application has no data to write. |
| 103 if (HasDataToWrite()) { | 103 if (HasDataToWrite()) { |
| 104 return; | 104 return; |
| 105 } | 105 } |
| 106 | 106 |
| 107 // If not enough time has passed since the last time we sent an update to the | 107 // If not enough time has passed since the last time we sent an update to the |
| 108 // client, or not enough packets have been sent, then return early. | 108 // client, or not enough packets have been sent, then return early. |
| 109 const QuicSentPacketManager& sent_packet_manager = | 109 const QuicSentPacketManager& sent_packet_manager = |
| 110 connection()->sent_packet_manager(); | 110 connection()->sent_packet_manager(); |
| 111 int64 srtt_ms = | 111 int64_t srtt_ms = |
| 112 sent_packet_manager.GetRttStats()->smoothed_rtt().ToMilliseconds(); | 112 sent_packet_manager.GetRttStats()->smoothed_rtt().ToMilliseconds(); |
| 113 int64 now_ms = now.Subtract(last_scup_time_).ToMilliseconds(); | 113 int64_t now_ms = now.Subtract(last_scup_time_).ToMilliseconds(); |
| 114 int64 packets_since_last_scup = | 114 int64_t packets_since_last_scup = |
| 115 connection()->packet_number_of_last_sent_packet() - | 115 connection()->packet_number_of_last_sent_packet() - |
| 116 last_scup_packet_number_; | 116 last_scup_packet_number_; |
| 117 if (now_ms < (kMinIntervalBetweenServerConfigUpdatesRTTs * srtt_ms) || | 117 if (now_ms < (kMinIntervalBetweenServerConfigUpdatesRTTs * srtt_ms) || |
| 118 now_ms < kMinIntervalBetweenServerConfigUpdatesMs || | 118 now_ms < kMinIntervalBetweenServerConfigUpdatesMs || |
| 119 packets_since_last_scup < kMinPacketsBetweenServerConfigUpdates) { | 119 packets_since_last_scup < kMinPacketsBetweenServerConfigUpdates) { |
| 120 return; | 120 return; |
| 121 } | 121 } |
| 122 | 122 |
| 123 // If the bandwidth recorder does not have a valid estimate, return early. | 123 // If the bandwidth recorder does not have a valid estimate, return early. |
| 124 const QuicSustainedBandwidthRecorder& bandwidth_recorder = | 124 const QuicSustainedBandwidthRecorder& bandwidth_recorder = |
| 125 sent_packet_manager.SustainedBandwidthRecorder(); | 125 sent_packet_manager.SustainedBandwidthRecorder(); |
| 126 if (!bandwidth_recorder.HasEstimate()) { | 126 if (!bandwidth_recorder.HasEstimate()) { |
| 127 return; | 127 return; |
| 128 } | 128 } |
| 129 | 129 |
| 130 // The bandwidth recorder has recorded at least one sustained bandwidth | 130 // The bandwidth recorder has recorded at least one sustained bandwidth |
| 131 // estimate. Check that it's substantially different from the last one that | 131 // estimate. Check that it's substantially different from the last one that |
| 132 // we sent to the client, and if so, send the new one. | 132 // we sent to the client, and if so, send the new one. |
| 133 QuicBandwidth new_bandwidth_estimate = bandwidth_recorder.BandwidthEstimate(); | 133 QuicBandwidth new_bandwidth_estimate = bandwidth_recorder.BandwidthEstimate(); |
| 134 | 134 |
| 135 int64 bandwidth_delta = | 135 int64_t bandwidth_delta = |
| 136 std::abs(new_bandwidth_estimate.ToBitsPerSecond() - | 136 std::abs(new_bandwidth_estimate.ToBitsPerSecond() - |
| 137 bandwidth_estimate_sent_to_client_.ToBitsPerSecond()); | 137 bandwidth_estimate_sent_to_client_.ToBitsPerSecond()); |
| 138 | 138 |
| 139 // Define "substantial" difference as a 50% increase or decrease from the | 139 // Define "substantial" difference as a 50% increase or decrease from the |
| 140 // last estimate. | 140 // last estimate. |
| 141 bool substantial_difference = | 141 bool substantial_difference = |
| 142 bandwidth_delta > | 142 bandwidth_delta > |
| 143 0.5 * bandwidth_estimate_sent_to_client_.ToBitsPerSecond(); | 143 0.5 * bandwidth_estimate_sent_to_client_.ToBitsPerSecond(); |
| 144 if (!substantial_difference) { | 144 if (!substantial_difference) { |
| 145 return; | 145 return; |
| 146 } | 146 } |
| 147 | 147 |
| 148 bandwidth_estimate_sent_to_client_ = new_bandwidth_estimate; | 148 bandwidth_estimate_sent_to_client_ = new_bandwidth_estimate; |
| 149 DVLOG(1) << "Server: sending new bandwidth estimate (KBytes/s): " | 149 DVLOG(1) << "Server: sending new bandwidth estimate (KBytes/s): " |
| 150 << bandwidth_estimate_sent_to_client_.ToKBytesPerSecond(); | 150 << bandwidth_estimate_sent_to_client_.ToKBytesPerSecond(); |
| 151 | 151 |
| 152 // Include max bandwidth in the update. | 152 // Include max bandwidth in the update. |
| 153 QuicBandwidth max_bandwidth_estimate = | 153 QuicBandwidth max_bandwidth_estimate = |
| 154 bandwidth_recorder.MaxBandwidthEstimate(); | 154 bandwidth_recorder.MaxBandwidthEstimate(); |
| 155 int32 max_bandwidth_timestamp = bandwidth_recorder.MaxBandwidthTimestamp(); | 155 int32_t max_bandwidth_timestamp = bandwidth_recorder.MaxBandwidthTimestamp(); |
| 156 | 156 |
| 157 // Fill the proto before passing it to the crypto stream to send. | 157 // Fill the proto before passing it to the crypto stream to send. |
| 158 CachedNetworkParameters cached_network_params; | 158 CachedNetworkParameters cached_network_params; |
| 159 cached_network_params.set_bandwidth_estimate_bytes_per_second( | 159 cached_network_params.set_bandwidth_estimate_bytes_per_second( |
| 160 bandwidth_estimate_sent_to_client_.ToBytesPerSecond()); | 160 bandwidth_estimate_sent_to_client_.ToBytesPerSecond()); |
| 161 cached_network_params.set_max_bandwidth_estimate_bytes_per_second( | 161 cached_network_params.set_max_bandwidth_estimate_bytes_per_second( |
| 162 max_bandwidth_estimate.ToBytesPerSecond()); | 162 max_bandwidth_estimate.ToBytesPerSecond()); |
| 163 cached_network_params.set_max_bandwidth_timestamp_seconds( | 163 cached_network_params.set_max_bandwidth_timestamp_seconds( |
| 164 max_bandwidth_timestamp); | 164 max_bandwidth_timestamp); |
| 165 cached_network_params.set_min_rtt_ms( | 165 cached_network_params.set_min_rtt_ms( |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 ActivateStream(stream); | 234 ActivateStream(stream); |
| 235 return stream; | 235 return stream; |
| 236 } | 236 } |
| 237 | 237 |
| 238 QuicCryptoServerStreamBase* QuicServerSession::GetCryptoStream() { | 238 QuicCryptoServerStreamBase* QuicServerSession::GetCryptoStream() { |
| 239 return crypto_stream_.get(); | 239 return crypto_stream_.get(); |
| 240 } | 240 } |
| 241 | 241 |
| 242 } // namespace tools | 242 } // namespace tools |
| 243 } // namespace net | 243 } // namespace net |
| OLD | NEW |