| 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_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/cpu.h" | 9 #include "base/cpu.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 56 |
| 57 // When a connection is idle for 30 seconds it will be closed. | 57 // When a connection is idle for 30 seconds it will be closed. |
| 58 const int kIdleConnectionTimeoutSeconds = 30; | 58 const int kIdleConnectionTimeoutSeconds = 30; |
| 59 | 59 |
| 60 // The initial receive window size for both streams and sessions. | 60 // The initial receive window size for both streams and sessions. |
| 61 const int32 kInitialReceiveWindowSize = 10 * 1024 * 1024; // 10MB | 61 const int32 kInitialReceiveWindowSize = 10 * 1024 * 1024; // 10MB |
| 62 | 62 |
| 63 // Set the maximum number of undecryptable packets the connection will store. | 63 // Set the maximum number of undecryptable packets the connection will store. |
| 64 const int32 kMaxUndecryptablePackets = 100; | 64 const int32 kMaxUndecryptablePackets = 100; |
| 65 | 65 |
| 66 const char kDummyHostname[] = "quic.global.props"; | |
| 67 const uint16 kDummyPort = 0; | |
| 68 | |
| 69 void HistogramCreateSessionFailure(enum CreateSessionFailure error) { | 66 void HistogramCreateSessionFailure(enum CreateSessionFailure error) { |
| 70 UMA_HISTOGRAM_ENUMERATION("Net.QuicSession.CreationError", error, | 67 UMA_HISTOGRAM_ENUMERATION("Net.QuicSession.CreationError", error, |
| 71 CREATION_ERROR_MAX); | 68 CREATION_ERROR_MAX); |
| 72 } | 69 } |
| 73 | 70 |
| 74 bool IsEcdsaSupported() { | 71 bool IsEcdsaSupported() { |
| 75 #if defined(OS_WIN) | 72 #if defined(OS_WIN) |
| 76 if (base::win::GetVersion() < base::win::VERSION_VISTA) | 73 if (base::win::GetVersion() < base::win::VERSION_VISTA) |
| 77 return false; | 74 return false; |
| 78 #endif | 75 #endif |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 while (!all_sessions_.empty()) { | 609 while (!all_sessions_.empty()) { |
| 613 delete all_sessions_.begin()->first; | 610 delete all_sessions_.begin()->first; |
| 614 all_sessions_.erase(all_sessions_.begin()); | 611 all_sessions_.erase(all_sessions_.begin()); |
| 615 } | 612 } |
| 616 STLDeleteValues(&active_jobs_); | 613 STLDeleteValues(&active_jobs_); |
| 617 } | 614 } |
| 618 | 615 |
| 619 void QuicStreamFactory::set_require_confirmation(bool require_confirmation) { | 616 void QuicStreamFactory::set_require_confirmation(bool require_confirmation) { |
| 620 require_confirmation_ = require_confirmation; | 617 require_confirmation_ = require_confirmation; |
| 621 if (http_server_properties_ && (!(local_address_ == IPEndPoint()))) { | 618 if (http_server_properties_ && (!(local_address_ == IPEndPoint()))) { |
| 622 // TODO(rtenneti): Delete host_port_pair and persist data in globals. | 619 http_server_properties_->SetSupportsQuic(!require_confirmation, |
| 623 HostPortPair host_port_pair(kDummyHostname, kDummyPort); | 620 local_address_.address()); |
| 624 http_server_properties_->SetSupportsQuic( | |
| 625 host_port_pair, !require_confirmation, | |
| 626 local_address_.ToStringWithoutPort()); | |
| 627 } | 621 } |
| 628 } | 622 } |
| 629 | 623 |
| 630 int QuicStreamFactory::Create(const HostPortPair& host_port_pair, | 624 int QuicStreamFactory::Create(const HostPortPair& host_port_pair, |
| 631 bool is_https, | 625 bool is_https, |
| 632 PrivacyMode privacy_mode, | 626 PrivacyMode privacy_mode, |
| 633 base::StringPiece method, | 627 base::StringPiece method, |
| 634 const BoundNetLog& net_log, | 628 const BoundNetLog& net_log, |
| 635 QuicStreamRequest* request) { | 629 QuicStreamRequest* request) { |
| 636 QuicServerId server_id(host_port_pair, is_https, privacy_mode); | 630 QuicServerId server_id(host_port_pair, is_https, privacy_mode); |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 // wrong encryption level, when the send buffer is full. | 989 // wrong encryption level, when the send buffer is full. |
| 996 rv = socket->SetSendBufferSize(kMaxPacketSize * 20); | 990 rv = socket->SetSendBufferSize(kMaxPacketSize * 20); |
| 997 if (rv != OK) { | 991 if (rv != OK) { |
| 998 HistogramCreateSessionFailure(CREATION_ERROR_SETTING_SEND_BUFFER); | 992 HistogramCreateSessionFailure(CREATION_ERROR_SETTING_SEND_BUFFER); |
| 999 return rv; | 993 return rv; |
| 1000 } | 994 } |
| 1001 | 995 |
| 1002 socket->GetLocalAddress(&local_address_); | 996 socket->GetLocalAddress(&local_address_); |
| 1003 if (check_persisted_supports_quic_ && http_server_properties_) { | 997 if (check_persisted_supports_quic_ && http_server_properties_) { |
| 1004 check_persisted_supports_quic_ = false; | 998 check_persisted_supports_quic_ = false; |
| 1005 // TODO(rtenneti): Delete host_port_pair and persist data in globals. | 999 IPAddressNumber last_address; |
| 1006 HostPortPair host_port_pair(kDummyHostname, kDummyPort); | 1000 if (http_server_properties_->GetSupportsQuic(&last_address) && |
| 1007 SupportsQuic supports_quic(true, local_address_.ToStringWithoutPort()); | 1001 last_address == local_address_.address()) { |
| 1008 if (http_server_properties_->GetSupportsQuic( | |
| 1009 host_port_pair).Equals(supports_quic)) { | |
| 1010 require_confirmation_ = false; | 1002 require_confirmation_ = false; |
| 1011 } | 1003 } |
| 1012 } | 1004 } |
| 1013 | 1005 |
| 1014 DefaultPacketWriterFactory packet_writer_factory(socket.get()); | 1006 DefaultPacketWriterFactory packet_writer_factory(socket.get()); |
| 1015 | 1007 |
| 1016 if (!helper_.get()) { | 1008 if (!helper_.get()) { |
| 1017 helper_.reset(new QuicConnectionHelper( | 1009 helper_.reset(new QuicConnectionHelper( |
| 1018 base::MessageLoop::current()->message_loop_proxy().get(), | 1010 base::MessageLoop::current()->message_loop_proxy().get(), |
| 1019 clock_.get(), random_generator_)); | 1011 clock_.get(), random_generator_)); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 | 1234 |
| 1243 UMA_HISTOGRAM_COUNTS("Net.QuicHandshakeNotConfirmedNumPacketsReceived", | 1235 UMA_HISTOGRAM_COUNTS("Net.QuicHandshakeNotConfirmedNumPacketsReceived", |
| 1244 stats.packets_received); | 1236 stats.packets_received); |
| 1245 | 1237 |
| 1246 if (!session_was_active) | 1238 if (!session_was_active) |
| 1247 return; | 1239 return; |
| 1248 | 1240 |
| 1249 const HostPortPair& server = server_id.host_port_pair(); | 1241 const HostPortPair& server = server_id.host_port_pair(); |
| 1250 // Don't try to change the alternate-protocol state, if the | 1242 // Don't try to change the alternate-protocol state, if the |
| 1251 // alternate-protocol state is unknown. | 1243 // alternate-protocol state is unknown. |
| 1252 if (!http_server_properties_->HasAlternateProtocol(server)) | 1244 const AlternateProtocolInfo alternate = |
| 1245 http_server_properties_->GetAlternateProtocol(server); |
| 1246 if (alternate.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) |
| 1253 return; | 1247 return; |
| 1254 | 1248 |
| 1255 // TODO(rch): In the special case where the session has received no | 1249 // TODO(rch): In the special case where the session has received no |
| 1256 // packets from the peer, we should consider blacklisting this | 1250 // packets from the peer, we should consider blacklisting this |
| 1257 // differently so that we still race TCP but we don't consider the | 1251 // differently so that we still race TCP but we don't consider the |
| 1258 // session connected until the handshake has been confirmed. | 1252 // session connected until the handshake has been confirmed. |
| 1259 HistogramBrokenAlternateProtocolLocation( | 1253 HistogramBrokenAlternateProtocolLocation( |
| 1260 BROKEN_ALTERNATE_PROTOCOL_LOCATION_QUIC_STREAM_FACTORY); | 1254 BROKEN_ALTERNATE_PROTOCOL_LOCATION_QUIC_STREAM_FACTORY); |
| 1261 AlternateProtocolInfo alternate = | |
| 1262 http_server_properties_->GetAlternateProtocol(server); | |
| 1263 DCHECK_EQ(QUIC, alternate.protocol); | 1255 DCHECK_EQ(QUIC, alternate.protocol); |
| 1264 | 1256 |
| 1265 // Since the session was active, there's no longer an | 1257 // Since the session was active, there's no longer an |
| 1266 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the | 1258 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the |
| 1267 // TCP job also fails. So to avoid not using QUIC when we otherwise could, | 1259 // TCP job also fails. So to avoid not using QUIC when we otherwise could, |
| 1268 // we mark it as broken, and then immediately re-enable it. This leaves | 1260 // we mark it as broken, and then immediately re-enable it. This leaves |
| 1269 // QUIC as "recently broken" which means that 0-RTT will be disabled but | 1261 // QUIC as "recently broken" which means that 0-RTT will be disabled but |
| 1270 // we'll still race. | 1262 // we'll still race. |
| 1271 http_server_properties_->SetBrokenAlternateProtocol(server); | 1263 http_server_properties_->SetBrokenAlternateProtocol(server); |
| 1272 http_server_properties_->ClearAlternateProtocol(server); | 1264 http_server_properties_->ClearAlternateProtocol(server); |
| 1273 http_server_properties_->SetAlternateProtocol( | 1265 http_server_properties_->SetAlternateProtocol( |
| 1274 server, alternate.port, alternate.protocol, 1); | 1266 server, alternate.port, alternate.protocol, 1); |
| 1275 DCHECK_EQ(QUIC, | 1267 DCHECK_EQ(QUIC, |
| 1276 http_server_properties_->GetAlternateProtocol(server).protocol); | 1268 http_server_properties_->GetAlternateProtocol(server).protocol); |
| 1277 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( | 1269 DCHECK(http_server_properties_->WasAlternateProtocolRecentlyBroken( |
| 1278 server)); | 1270 server)); |
| 1279 } | 1271 } |
| 1280 | 1272 |
| 1281 } // namespace net | 1273 } // namespace net |
| OLD | NEW |