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/crypto/source_address_token.h" | 8 #include "net/quic/crypto/source_address_token.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" |
11 #include "net/quic/reliable_quic_stream.h" | 11 #include "net/quic/reliable_quic_stream.h" |
12 #include "net/tools/quic/quic_spdy_server_stream.h" | 12 #include "net/tools/quic/quic_spdy_server_stream.h" |
13 | 13 |
14 namespace net { | 14 namespace net { |
15 namespace tools { | 15 namespace tools { |
16 | 16 |
17 QuicServerSession::QuicServerSession(const QuicConfig& config, | 17 QuicServerSession::QuicServerSession(const QuicConfig& config, |
18 QuicConnection* connection, | 18 QuicConnection* connection, |
19 QuicServerSessionVisitor* visitor) | 19 QuicServerSessionVisitor* visitor) |
20 : QuicSession(connection, config), | 20 : QuicSession(connection, config), |
21 visitor_(visitor), | 21 visitor_(visitor), |
22 bandwidth_estimate_sent_to_client_(QuicBandwidth::Zero()), | 22 bandwidth_estimate_sent_to_client_(QuicBandwidth::Zero()), |
23 last_server_config_update_time_(QuicTime::Zero()) {} | 23 last_scup_time_(QuicTime::Zero()), |
| 24 last_scup_sequence_number_(0) {} |
24 | 25 |
25 QuicServerSession::~QuicServerSession() {} | 26 QuicServerSession::~QuicServerSession() {} |
26 | 27 |
27 void QuicServerSession::InitializeSession( | 28 void QuicServerSession::InitializeSession( |
28 const QuicCryptoServerConfig& crypto_config) { | 29 const QuicCryptoServerConfig& crypto_config) { |
29 QuicSession::InitializeSession(); | 30 QuicSession::InitializeSession(); |
30 crypto_stream_.reset(CreateQuicCryptoServerStream(crypto_config)); | 31 crypto_stream_.reset(CreateQuicCryptoServerStream(crypto_config)); |
31 } | 32 } |
32 | 33 |
33 QuicCryptoServerStream* QuicServerSession::CreateQuicCryptoServerStream( | 34 QuicCryptoServerStream* QuicServerSession::CreateQuicCryptoServerStream( |
(...skipping 28 matching lines...) Expand all Loading... |
62 QuicSession::OnWriteBlocked(); | 63 QuicSession::OnWriteBlocked(); |
63 visitor_->OnWriteBlocked(connection()); | 64 visitor_->OnWriteBlocked(connection()); |
64 } | 65 } |
65 | 66 |
66 void QuicServerSession::OnCongestionWindowChange(QuicTime now) { | 67 void QuicServerSession::OnCongestionWindowChange(QuicTime now) { |
67 if (connection()->version() <= QUIC_VERSION_21) { | 68 if (connection()->version() <= QUIC_VERSION_21) { |
68 return; | 69 return; |
69 } | 70 } |
70 | 71 |
71 // If not enough time has passed since the last time we sent an update to the | 72 // If not enough time has passed since the last time we sent an update to the |
72 // client, then return early. | 73 // client, or not enough packets have been sent, then return early. |
73 const QuicSentPacketManager& sent_packet_manager = | 74 const QuicSentPacketManager& sent_packet_manager = |
74 connection()->sent_packet_manager(); | 75 connection()->sent_packet_manager(); |
75 int64 srtt_ms = | 76 int64 srtt_ms = |
76 sent_packet_manager.GetRttStats()->SmoothedRtt().ToMilliseconds(); | 77 sent_packet_manager.GetRttStats()->SmoothedRtt().ToMilliseconds(); |
77 int64 now_ms = now.Subtract(last_server_config_update_time_).ToMilliseconds(); | 78 int64 now_ms = now.Subtract(last_scup_time_).ToMilliseconds(); |
| 79 int64 packets_since_last_scup = |
| 80 connection()->sequence_number_of_last_sent_packet() - |
| 81 last_scup_sequence_number_; |
78 if (now_ms < (kMinIntervalBetweenServerConfigUpdatesRTTs * srtt_ms) || | 82 if (now_ms < (kMinIntervalBetweenServerConfigUpdatesRTTs * srtt_ms) || |
79 now_ms < kMinIntervalBetweenServerConfigUpdatesMs) { | 83 now_ms < kMinIntervalBetweenServerConfigUpdatesMs || |
| 84 packets_since_last_scup < kMinPacketsBetweenServerConfigUpdates) { |
80 return; | 85 return; |
81 } | 86 } |
82 | 87 |
83 // If the bandwidth recorder does not have a valid estimate, return early. | 88 // If the bandwidth recorder does not have a valid estimate, return early. |
84 const QuicSustainedBandwidthRecorder& bandwidth_recorder = | 89 const QuicSustainedBandwidthRecorder& bandwidth_recorder = |
85 sent_packet_manager.SustainedBandwidthRecorder(); | 90 sent_packet_manager.SustainedBandwidthRecorder(); |
86 if (!bandwidth_recorder.HasEstimate()) { | 91 if (!bandwidth_recorder.HasEstimate()) { |
87 return; | 92 return; |
88 } | 93 } |
89 | 94 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 bandwidth_recorder.EstimateRecordedDuringSlowStart() | 133 bandwidth_recorder.EstimateRecordedDuringSlowStart() |
129 ? CachedNetworkParameters::SLOW_START | 134 ? CachedNetworkParameters::SLOW_START |
130 : CachedNetworkParameters::CONGESTION_AVOIDANCE); | 135 : CachedNetworkParameters::CONGESTION_AVOIDANCE); |
131 cached_network_params.set_timestamp( | 136 cached_network_params.set_timestamp( |
132 connection()->clock()->WallNow().ToUNIXSeconds()); | 137 connection()->clock()->WallNow().ToUNIXSeconds()); |
133 if (!serving_region_.empty()) { | 138 if (!serving_region_.empty()) { |
134 cached_network_params.set_serving_region(serving_region_); | 139 cached_network_params.set_serving_region(serving_region_); |
135 } | 140 } |
136 | 141 |
137 crypto_stream_->SendServerConfigUpdate(&cached_network_params); | 142 crypto_stream_->SendServerConfigUpdate(&cached_network_params); |
138 last_server_config_update_time_ = now; | 143 last_scup_time_ = now; |
| 144 last_scup_sequence_number_ = |
| 145 connection()->sequence_number_of_last_sent_packet(); |
139 } | 146 } |
140 | 147 |
141 bool QuicServerSession::ShouldCreateIncomingDataStream(QuicStreamId id) { | 148 bool QuicServerSession::ShouldCreateIncomingDataStream(QuicStreamId id) { |
142 if (id % 2 == 0) { | 149 if (id % 2 == 0) { |
143 DVLOG(1) << "Invalid incoming even stream_id:" << id; | 150 DVLOG(1) << "Invalid incoming even stream_id:" << id; |
144 connection()->SendConnectionClose(QUIC_INVALID_STREAM_ID); | 151 connection()->SendConnectionClose(QUIC_INVALID_STREAM_ID); |
145 return false; | 152 return false; |
146 } | 153 } |
147 if (GetNumOpenStreams() >= get_max_open_streams()) { | 154 if (GetNumOpenStreams() >= get_max_open_streams()) { |
148 DVLOG(1) << "Failed to create a new incoming stream with id:" << id | 155 DVLOG(1) << "Failed to create a new incoming stream with id:" << id |
(...skipping 18 matching lines...) Expand all Loading... |
167 DLOG(ERROR) << "Server push not yet supported"; | 174 DLOG(ERROR) << "Server push not yet supported"; |
168 return nullptr; | 175 return nullptr; |
169 } | 176 } |
170 | 177 |
171 QuicCryptoServerStream* QuicServerSession::GetCryptoStream() { | 178 QuicCryptoServerStream* QuicServerSession::GetCryptoStream() { |
172 return crypto_stream_.get(); | 179 return crypto_stream_.get(); |
173 } | 180 } |
174 | 181 |
175 } // namespace tools | 182 } // namespace tools |
176 } // namespace net | 183 } // namespace net |
OLD | NEW |