Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 close_sessions_on_ip_change_(close_sessions_on_ip_change), | 639 close_sessions_on_ip_change_(close_sessions_on_ip_change), |
| 640 migrate_sessions_on_network_change_( | 640 migrate_sessions_on_network_change_( |
| 641 migrate_sessions_on_network_change && | 641 migrate_sessions_on_network_change && |
| 642 NetworkChangeNotifier::AreNetworkHandlesSupported()), | 642 NetworkChangeNotifier::AreNetworkHandlesSupported()), |
| 643 migrate_sessions_early_(migrate_sessions_early && | 643 migrate_sessions_early_(migrate_sessions_early && |
| 644 migrate_sessions_on_network_change_), | 644 migrate_sessions_on_network_change_), |
| 645 port_seed_(random_generator_->RandUint64()), | 645 port_seed_(random_generator_->RandUint64()), |
| 646 check_persisted_supports_quic_(true), | 646 check_persisted_supports_quic_(true), |
| 647 has_initialized_data_(false), | 647 has_initialized_data_(false), |
| 648 num_push_streams_created_(0), | 648 num_push_streams_created_(0), |
| 649 status_(OPEN), | |
| 649 task_runner_(nullptr), | 650 task_runner_(nullptr), |
| 650 weak_factory_(this) { | 651 weak_factory_(this) { |
| 651 if (disable_quic_on_timeout_with_open_streams) | 652 if (disable_quic_on_timeout_with_open_streams) |
| 652 threshold_timeouts_with_open_streams_ = 1; | 653 threshold_timeouts_with_open_streams_ = 1; |
| 653 DCHECK(transport_security_state_); | 654 DCHECK(transport_security_state_); |
| 654 DCHECK(http_server_properties_); | 655 DCHECK(http_server_properties_); |
| 655 crypto_config_.set_user_agent_id(user_agent_id); | 656 crypto_config_.set_user_agent_id(user_agent_id); |
| 656 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); | 657 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); |
| 657 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); | 658 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); |
| 658 crypto_config_.AddCanonicalSuffix(".googleusercontent.com"); | 659 crypto_config_.AddCanonicalSuffix(".googleusercontent.com"); |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 991 return "Bad packet loss rate."; | 992 return "Bad packet loss rate."; |
| 992 case QuicChromiumClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE: | 993 case QuicChromiumClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE: |
| 993 return "Public resets after successful handshakes."; | 994 return "Public resets after successful handshakes."; |
| 994 case QuicChromiumClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS: | 995 case QuicChromiumClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS: |
| 995 return "Connection timeouts with streams open."; | 996 return "Connection timeouts with streams open."; |
| 996 default: | 997 default: |
| 997 return ""; | 998 return ""; |
| 998 } | 999 } |
| 999 } | 1000 } |
| 1000 | 1001 |
| 1001 bool QuicStreamFactory::IsQuicDisabled(uint16_t port) { | 1002 bool QuicStreamFactory::IsQuicDisabled(uint16_t port) const { |
| 1002 return QuicDisabledReason(port) != | 1003 return status_ != OPEN; |
| 1003 QuicChromiumClientSession::QUIC_DISABLED_NOT; | |
| 1004 } | 1004 } |
| 1005 | 1005 |
| 1006 bool QuicStreamFactory::OnHandshakeConfirmed(QuicChromiumClientSession* session, | 1006 bool QuicStreamFactory::OnHandshakeConfirmed(QuicChromiumClientSession* session, |
| 1007 float packet_loss_rate) { | 1007 float packet_loss_rate) { |
| 1008 DCHECK(session); | 1008 DCHECK(session); |
| 1009 uint16_t port = session->server_id().port(); | 1009 uint16_t port = session->server_id().port(); |
| 1010 if (packet_loss_rate < packet_loss_threshold_) { | 1010 if (packet_loss_rate < packet_loss_threshold_) { |
| 1011 number_of_lossy_connections_[port] = 0; | 1011 number_of_lossy_connections_[port] = 0; |
| 1012 return false; | 1012 return false; |
| 1013 } | 1013 } |
| 1014 | 1014 |
| 1015 // We mark it as recently broken, which means that 0-RTT will be disabled | 1015 // We mark it as recently broken, which means that 0-RTT will be disabled |
| 1016 // but we'll still race. | 1016 // but we'll still race. |
| 1017 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1017 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
| 1018 AlternativeService(QUIC, session->server_id().host(), port)); | 1018 AlternativeService(QUIC, session->server_id().host(), port)); |
| 1019 | 1019 |
| 1020 bool was_quic_disabled = IsQuicDisabled(port); | 1020 bool was_quic_disabled = IsQuicDisabled(port); |
| 1021 ++number_of_lossy_connections_[port]; | 1021 ++number_of_lossy_connections_[port]; |
| 1022 | 1022 |
| 1023 // Collect data for port 443 for packet loss events. | 1023 // Collect data for port 443 for packet loss events. |
| 1024 if (port == 443 && max_number_of_lossy_connections_ > 0) { | 1024 if (port == 443 && max_number_of_lossy_connections_ > 0) { |
| 1025 UMA_HISTOGRAM_SPARSE_SLOWLY( | 1025 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 1026 base::StringPrintf("Net.QuicStreamFactory.BadPacketLossEvents%d", | 1026 base::StringPrintf("Net.QuicStreamFactory.BadPacketLossEvents%d", |
| 1027 max_number_of_lossy_connections_), | 1027 max_number_of_lossy_connections_), |
| 1028 std::min(number_of_lossy_connections_[port], | 1028 std::min(number_of_lossy_connections_[port], |
| 1029 max_number_of_lossy_connections_)); | 1029 max_number_of_lossy_connections_)); |
| 1030 } | 1030 } |
| 1031 | 1031 |
| 1032 MaybeDisableQuic(port); | |
| 1033 | |
| 1032 bool is_quic_disabled = IsQuicDisabled(port); | 1034 bool is_quic_disabled = IsQuicDisabled(port); |
| 1033 if (is_quic_disabled) { | 1035 if (is_quic_disabled) { |
| 1034 // Close QUIC connection if Quic is disabled for this port. | 1036 // Close QUIC connection if Quic is disabled for this port. |
| 1035 session->CloseSessionOnErrorAndNotifyFactoryLater( | 1037 session->CloseSessionOnErrorAndNotifyFactoryLater( |
| 1036 ERR_ABORTED, QUIC_BAD_PACKET_LOSS_RATE); | 1038 ERR_ABORTED, QUIC_BAD_PACKET_LOSS_RATE); |
| 1037 | 1039 |
| 1038 // If this bad packet loss rate disabled the QUIC, then record it. | 1040 // If this bad packet loss rate disabled the QUIC, then record it. |
| 1039 if (!was_quic_disabled) | 1041 if (!was_quic_disabled) |
| 1040 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicStreamFactory.QuicIsDisabled", port); | 1042 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicStreamFactory.QuicIsDisabled", port); |
| 1041 } | 1043 } |
| 1042 return is_quic_disabled; | 1044 return is_quic_disabled; |
| 1043 } | 1045 } |
| 1044 | 1046 |
| 1047 void QuicStreamFactory::OnTcpJobCompleted(bool succeeded) { | |
| 1048 if (status_ != CLOSED) | |
| 1049 return; | |
| 1050 | |
| 1051 // If QUIC connections are failing while TCP connections are working, | |
| 1052 // then stop using QUIC. On the other hand if both QUIC and TCP are | |
| 1053 // failing, then attempt to use QUIC again. | |
| 1054 if (succeeded) { | |
| 1055 status_ = DISABLED; | |
| 1056 return; | |
| 1057 } | |
| 1058 | |
| 1059 status_ = OPEN; | |
| 1060 num_timeouts_with_open_streams_ = 0; | |
| 1061 } | |
| 1062 | |
| 1045 void QuicStreamFactory::OnIdleSession(QuicChromiumClientSession* session) {} | 1063 void QuicStreamFactory::OnIdleSession(QuicChromiumClientSession* session) {} |
| 1046 | 1064 |
| 1047 void QuicStreamFactory::OnSessionGoingAway(QuicChromiumClientSession* session) { | 1065 void QuicStreamFactory::OnSessionGoingAway(QuicChromiumClientSession* session) { |
| 1048 const AliasSet& aliases = session_aliases_[session]; | 1066 const AliasSet& aliases = session_aliases_[session]; |
| 1049 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); | 1067 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); |
| 1050 ++it) { | 1068 ++it) { |
| 1051 DCHECK(active_sessions_.count(*it)); | 1069 DCHECK(active_sessions_.count(*it)); |
| 1052 DCHECK_EQ(session, active_sessions_[*it]); | 1070 DCHECK_EQ(session, active_sessions_[*it]); |
| 1053 // Track sessions which have recently gone away so that we can disable | 1071 // Track sessions which have recently gone away so that we can disable |
| 1054 // port suggestions. | 1072 // port suggestions. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1105 num_timeouts_with_open_streams_, 0, 20, 10); | 1123 num_timeouts_with_open_streams_, 0, 20, 10); |
| 1106 } | 1124 } |
| 1107 | 1125 |
| 1108 if (num_public_resets_post_handshake_ > max_public_resets_post_handshake_) { | 1126 if (num_public_resets_post_handshake_ > max_public_resets_post_handshake_) { |
| 1109 max_public_resets_post_handshake_ = num_public_resets_post_handshake_; | 1127 max_public_resets_post_handshake_ = num_public_resets_post_handshake_; |
| 1110 UMA_HISTOGRAM_CUSTOM_COUNTS( | 1128 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 1111 "Net.QuicStreamFactory.PublicResetsPostHandshake", | 1129 "Net.QuicStreamFactory.PublicResetsPostHandshake", |
| 1112 num_public_resets_post_handshake_, 0, 20, 10); | 1130 num_public_resets_post_handshake_, 0, 20, 10); |
| 1113 } | 1131 } |
| 1114 | 1132 |
| 1133 MaybeDisableQuic(port); | |
| 1115 if (IsQuicDisabled(port)) { | 1134 if (IsQuicDisabled(port)) { |
| 1116 if (disabled_reason == | 1135 if (disabled_reason == |
| 1117 QuicChromiumClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE) { | 1136 QuicChromiumClientSession::QUIC_DISABLED_PUBLIC_RESET_POST_HANDSHAKE) { |
| 1118 session->CloseSessionOnErrorAndNotifyFactoryLater( | 1137 session->CloseSessionOnErrorAndNotifyFactoryLater( |
| 1119 ERR_ABORTED, QUIC_PUBLIC_RESETS_POST_HANDSHAKE); | 1138 ERR_ABORTED, QUIC_PUBLIC_RESETS_POST_HANDSHAKE); |
| 1120 } else if (disabled_reason == QuicChromiumClientSession:: | 1139 } else if (disabled_reason == QuicChromiumClientSession:: |
| 1121 QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS) { | 1140 QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS) { |
| 1122 session->CloseSessionOnErrorAndNotifyFactoryLater( | 1141 session->CloseSessionOnErrorAndNotifyFactoryLater( |
| 1123 ERR_ABORTED, QUIC_TIMEOUTS_WITH_OPEN_STREAMS); | 1142 ERR_ABORTED, QUIC_TIMEOUTS_WITH_OPEN_STREAMS); |
| 1124 } | 1143 } |
| 1125 UMA_HISTOGRAM_ENUMERATION("Net.QuicStreamFactory.DisabledReasons", | 1144 UMA_HISTOGRAM_ENUMERATION("Net.QuicStreamFactory.DisabledReasons", |
| 1126 disabled_reason, | 1145 disabled_reason, |
| 1127 QuicChromiumClientSession::QUIC_DISABLED_MAX); | 1146 QuicChromiumClientSession::QUIC_DISABLED_MAX); |
| 1128 } | 1147 } |
| 1129 } | 1148 } |
| 1130 | 1149 |
| 1150 void QuicStreamFactory::MaybeDisableQuic(uint16_t port) { | |
| 1151 if (status_ == DISABLED) | |
| 1152 return; | |
| 1153 | |
| 1154 QuicChromiumClientSession::QuicDisabledReason disabled_reason = | |
| 1155 QuicDisabledReason(port); | |
| 1156 if (disabled_reason == QuicChromiumClientSession::QUIC_DISABLED_NOT) | |
|
ramant (doing other things)
2016/03/05 00:55:18
nit: a small question when "disabled_reason == Qui
Ryan Hamilton
2016/03/05 00:59:50
Yes, I believe status_ must be OPEN there. I've ad
| |
| 1157 return; | |
| 1158 | |
| 1159 if (disabled_reason == | |
| 1160 QuicChromiumClientSession::QUIC_DISABLED_TIMEOUT_WITH_OPEN_STREAMS) { | |
| 1161 // When QUIC there are too many timeouts with open stream, the factory | |
| 1162 // should be closed. When TCP jobs complete, they will move the factory | |
| 1163 // to either fully disabled or back to open | |
|
ramant (doing other things)
2016/03/05 00:55:18
overly nit. "." at the end of line#1163.
Ryan Hamilton
2016/03/05 00:59:50
Done.
| |
| 1164 status_ = CLOSED; | |
| 1165 DCHECK(IsQuicDisabled(port)); | |
| 1166 DCHECK_NE(QuicChromiumClientSession::QuicDisabledReason(port), | |
| 1167 QuicChromiumClientSession::QUIC_DISABLED_NOT); | |
| 1168 return; | |
| 1169 } | |
| 1170 | |
| 1171 status_ = DISABLED; | |
| 1172 DCHECK(IsQuicDisabled(port)); | |
| 1173 DCHECK_NE(QuicChromiumClientSession::QuicDisabledReason(port), | |
| 1174 QuicChromiumClientSession::QUIC_DISABLED_NOT); | |
| 1175 } | |
| 1176 | |
| 1131 void QuicStreamFactory::OnSessionClosed(QuicChromiumClientSession* session) { | 1177 void QuicStreamFactory::OnSessionClosed(QuicChromiumClientSession* session) { |
| 1132 DCHECK_EQ(0u, session->GetNumActiveStreams()); | 1178 DCHECK_EQ(0u, session->GetNumActiveStreams()); |
| 1133 MaybeDisableQuic(session); | 1179 MaybeDisableQuic(session); |
| 1134 OnSessionGoingAway(session); | 1180 OnSessionGoingAway(session); |
| 1135 delete session; | 1181 delete session; |
| 1136 all_sessions_.erase(session); | 1182 all_sessions_.erase(session); |
| 1137 } | 1183 } |
| 1138 | 1184 |
| 1139 void QuicStreamFactory::OnSessionConnectTimeout( | 1185 void QuicStreamFactory::OnSessionConnectTimeout( |
| 1140 QuicChromiumClientSession* session) { | 1186 QuicChromiumClientSession* session) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1207 } | 1253 } |
| 1208 return std::move(list); | 1254 return std::move(list); |
| 1209 } | 1255 } |
| 1210 | 1256 |
| 1211 void QuicStreamFactory::ClearCachedStatesInCryptoConfig() { | 1257 void QuicStreamFactory::ClearCachedStatesInCryptoConfig() { |
| 1212 crypto_config_.ClearCachedStates(); | 1258 crypto_config_.ClearCachedStates(); |
| 1213 } | 1259 } |
| 1214 | 1260 |
| 1215 void QuicStreamFactory::OnIPAddressChanged() { | 1261 void QuicStreamFactory::OnIPAddressChanged() { |
| 1216 num_timeouts_with_open_streams_ = 0; | 1262 num_timeouts_with_open_streams_ = 0; |
| 1263 status_ = OPEN; | |
| 1217 CloseAllSessions(ERR_NETWORK_CHANGED, QUIC_IP_ADDRESS_CHANGED); | 1264 CloseAllSessions(ERR_NETWORK_CHANGED, QUIC_IP_ADDRESS_CHANGED); |
| 1218 set_require_confirmation(true); | 1265 set_require_confirmation(true); |
| 1219 } | 1266 } |
| 1220 | 1267 |
| 1221 void QuicStreamFactory::OnNetworkConnected(NetworkHandle network) { | 1268 void QuicStreamFactory::OnNetworkConnected(NetworkHandle network) { |
| 1222 num_timeouts_with_open_streams_ = 0; | 1269 num_timeouts_with_open_streams_ = 0; |
| 1270 status_ = OPEN; | |
| 1223 } | 1271 } |
| 1224 | 1272 |
| 1225 void QuicStreamFactory::OnNetworkMadeDefault(NetworkHandle network) {} | 1273 void QuicStreamFactory::OnNetworkMadeDefault(NetworkHandle network) {} |
| 1226 | 1274 |
| 1227 void QuicStreamFactory::OnNetworkDisconnected(NetworkHandle network) { | 1275 void QuicStreamFactory::OnNetworkDisconnected(NetworkHandle network) { |
| 1228 MaybeMigrateOrCloseSessions(network, /*force_close=*/true); | 1276 MaybeMigrateOrCloseSessions(network, /*force_close=*/true); |
| 1229 set_require_confirmation(true); | 1277 set_require_confirmation(true); |
| 1230 } | 1278 } |
| 1231 | 1279 |
| 1232 // This method is expected to only be called when migrating from Cellular to | 1280 // This method is expected to only be called when migrating from Cellular to |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1672 // Since the session was active, there's no longer an | 1720 // Since the session was active, there's no longer an |
| 1673 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 1721 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
| 1674 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 1722 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
| 1675 // it as recently broken, which means that 0-RTT will be disabled but we'll | 1723 // it as recently broken, which means that 0-RTT will be disabled but we'll |
| 1676 // still race. | 1724 // still race. |
| 1677 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1725 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
| 1678 alternative_service); | 1726 alternative_service); |
| 1679 } | 1727 } |
| 1680 | 1728 |
| 1681 } // namespace net | 1729 } // namespace net |
| OLD | NEW |