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

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

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

Powered by Google App Engine
This is Rietveld 408576698