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

Side by Side Diff: net/quic/quic_server_session.cc

Issue 490263003: When talking >=QUIC_VERSION_22, regularly send updated bandwidth (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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.h" 5 #include "net/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/quic_connection.h" 9 #include "net/quic/quic_connection.h"
9 #include "net/quic/quic_flags.h" 10 #include "net/quic/quic_flags.h"
10 #include "net/quic/quic_spdy_server_stream.h" 11 #include "net/quic/quic_spdy_server_stream.h"
11 #include "net/quic/reliable_quic_stream.h" 12 #include "net/quic/reliable_quic_stream.h"
12 13
13 namespace net { 14 namespace net {
14 15
15 QuicServerSession::QuicServerSession( 16 QuicServerSession::QuicServerSession(
16 const QuicConfig& config, 17 const QuicConfig& config,
17 QuicConnection* connection, 18 QuicConnection* connection,
18 QuicPerConnectionPacketWriter* connection_packet_writer, 19 QuicPerConnectionPacketWriter* connection_packet_writer,
19 QuicServerSessionVisitor* visitor) 20 QuicServerSessionVisitor* visitor)
20 : QuicSession(connection, config), 21 : QuicSession(connection, config),
21 connection_packet_writer_(connection_packet_writer), 22 connection_packet_writer_(connection_packet_writer),
22 visitor_(visitor) {} 23 bandwidth_estimate_sent_to_client_(QuicBandwidth::Zero()),
24 last_server_config_update_time_(QuicTime::Zero()) {}
23 25
24 QuicServerSession::~QuicServerSession() {} 26 QuicServerSession::~QuicServerSession() {}
25 27
26 void QuicServerSession::InitializeSession( 28 void QuicServerSession::InitializeSession(
27 const QuicCryptoServerConfig& crypto_config) { 29 const QuicCryptoServerConfig& crypto_config) {
28 QuicSession::InitializeSession(); 30 QuicSession::InitializeSession();
29 crypto_stream_.reset(CreateQuicCryptoServerStream(crypto_config)); 31 crypto_stream_.reset(CreateQuicCryptoServerStream(crypto_config));
30 } 32 }
31 33
32 QuicCryptoServerStream* QuicServerSession::CreateQuicCryptoServerStream( 34 QuicCryptoServerStream* QuicServerSession::CreateQuicCryptoServerStream(
(...skipping 22 matching lines...) Expand all
55 crypto_stream_->CancelOutstandingCallbacks(); 57 crypto_stream_->CancelOutstandingCallbacks();
56 } 58 }
57 visitor_->OnConnectionClosed(connection()->connection_id(), error); 59 visitor_->OnConnectionClosed(connection()->connection_id(), error);
58 } 60 }
59 61
60 void QuicServerSession::OnWriteBlocked() { 62 void QuicServerSession::OnWriteBlocked() {
61 QuicSession::OnWriteBlocked(); 63 QuicSession::OnWriteBlocked();
62 visitor_->OnWriteBlocked(connection()); 64 visitor_->OnWriteBlocked(connection());
63 } 65 }
64 66
67 void QuicServerSession::OnCongestionWindowChange(QuicTime now) {
68 if (connection()->version() <= QUIC_VERSION_21) {
69 return;
70 }
71
72 // If not enough time has passed since the last time we sent an update to the
73 // client, then return early.
74 const QuicSentPacketManager& sent_packet_manager =
75 connection()->sent_packet_manager();
76 int64 srtt_ms =
77 sent_packet_manager.GetRttStats()->SmoothedRtt().ToMilliseconds();
78 int64 now_ms = now.Subtract(last_server_config_update_time_).ToMilliseconds();
79 if (now_ms < (kMinIntervalBetweenServerConfigUpdatesRTTs * srtt_ms) ||
80 now_ms < kMinIntervalBetweenServerConfigUpdatesMs) {
81 return;
82 }
83
84 // If the bandwidth recorder does not have a valid estimate, return early.
85 const QuicSustainedBandwidthRecorder& bandwidth_recorder =
86 sent_packet_manager.SustainedBandwidthRecorder();
87 if (!bandwidth_recorder.HasEstimate()) {
88 return;
89 }
90
91 // The bandwidth recorder has recorded at least one sustained bandwidth
92 // estimate. Check that it's substantially different from the last one that
93 // we sent to the client, and if so, send the new one.
94 QuicBandwidth new_bandwidth_estimate = bandwidth_recorder.BandwidthEstimate();
95
96 int64 bandwidth_delta =
97 std::abs(new_bandwidth_estimate.ToBitsPerSecond() -
98 bandwidth_estimate_sent_to_client_.ToBitsPerSecond());
99
100 // Define "substantial" difference as a 50% increase or decrease from the
101 // last estimate.
102 bool substantial_difference =
103 bandwidth_delta >
104 0.5 * bandwidth_estimate_sent_to_client_.ToBitsPerSecond();
105 if (!substantial_difference) {
106 return;
107 }
108
109 bandwidth_estimate_sent_to_client_ = new_bandwidth_estimate;
110 DVLOG(1) << "Server: sending new bandwidth estimate (KBytes/s): "
111 << bandwidth_estimate_sent_to_client_.ToKBytesPerSecond();
112
113 // Include max bandwidth in the update.
114 QuicBandwidth max_bandwidth_estimate =
115 bandwidth_recorder.MaxBandwidthEstimate();
116 int32 max_bandwidth_timestamp = bandwidth_recorder.MaxBandwidthTimestamp();
117
118 // Fill the proto before passing it to the crypto stream to send.
119 CachedNetworkParameters cached_network_params;
120 cached_network_params.set_bandwidth_estimate_bytes_per_second(
121 bandwidth_estimate_sent_to_client_.ToBytesPerSecond());
122 cached_network_params.set_max_bandwidth_estimate_bytes_per_second(
123 max_bandwidth_estimate.ToBytesPerSecond());
124 cached_network_params.set_max_bandwidth_timestamp_seconds(
125 max_bandwidth_timestamp);
126 cached_network_params.set_min_rtt_ms(
127 sent_packet_manager.GetRttStats()->min_rtt().ToMilliseconds());
128 cached_network_params.set_previous_connection_state(
129 bandwidth_recorder.EstimateRecordedDuringSlowStart()
130 ? CachedNetworkParameters::SLOW_START
131 : CachedNetworkParameters::CONGESTION_AVOIDANCE);
132 if (!serving_region_.empty()) {
133 cached_network_params.set_serving_region(serving_region_);
134 }
135
136 crypto_stream_->SendServerConfigUpdate(&cached_network_params);
137 last_server_config_update_time_ = now;
138 }
139
65 bool QuicServerSession::ShouldCreateIncomingDataStream(QuicStreamId id) { 140 bool QuicServerSession::ShouldCreateIncomingDataStream(QuicStreamId id) {
66 if (id % 2 == 0) { 141 if (id % 2 == 0) {
67 DVLOG(1) << "Invalid incoming even stream_id:" << id; 142 DVLOG(1) << "Invalid incoming even stream_id:" << id;
68 connection()->SendConnectionClose(QUIC_INVALID_STREAM_ID); 143 connection()->SendConnectionClose(QUIC_INVALID_STREAM_ID);
69 return false; 144 return false;
70 } 145 }
71 if (GetNumOpenStreams() >= get_max_open_streams()) { 146 if (GetNumOpenStreams() >= get_max_open_streams()) {
72 DVLOG(1) << "Failed to create a new incoming stream with id:" << id 147 DVLOG(1) << "Failed to create a new incoming stream with id:" << id
73 << " Already " << GetNumOpenStreams() << " open."; 148 << " Already " << GetNumOpenStreams() << " open.";
74 connection()->SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS); 149 connection()->SendConnectionClose(QUIC_TOO_MANY_OPEN_STREAMS);
(...skipping 14 matching lines...) Expand all
89 QuicDataStream* QuicServerSession::CreateOutgoingDataStream() { 164 QuicDataStream* QuicServerSession::CreateOutgoingDataStream() {
90 DLOG(ERROR) << "Server push not yet supported"; 165 DLOG(ERROR) << "Server push not yet supported";
91 return NULL; 166 return NULL;
92 } 167 }
93 168
94 QuicCryptoServerStream* QuicServerSession::GetCryptoStream() { 169 QuicCryptoServerStream* QuicServerSession::GetCryptoStream() {
95 return crypto_stream_.get(); 170 return crypto_stream_.get();
96 } 171 }
97 172
98 } // namespace net 173 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698