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 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1176 set_require_confirmation(true); | 1176 set_require_confirmation(true); |
1177 } | 1177 } |
1178 | 1178 |
1179 // This method is expected to only be called when migrating from Cellular to | 1179 // This method is expected to only be called when migrating from Cellular to |
1180 // WiFi on Android. | 1180 // WiFi on Android. |
1181 void QuicStreamFactory::OnNetworkSoonToDisconnect( | 1181 void QuicStreamFactory::OnNetworkSoonToDisconnect( |
1182 NetworkChangeNotifier::NetworkHandle network) { | 1182 NetworkChangeNotifier::NetworkHandle network) { |
1183 MaybeMigrateOrCloseSessions(network, /*force_close=*/false); | 1183 MaybeMigrateOrCloseSessions(network, /*force_close=*/false); |
1184 } | 1184 } |
1185 | 1185 |
1186 void QuicStreamFactory::MaybeMigrateOrCloseSessions( | 1186 NetworkChangeNotifier::NetworkHandle QuicStreamFactory::FindAlternateNetwork( |
1187 NetworkChangeNotifier::NetworkHandle network, | 1187 NetworkChangeNotifier::NetworkHandle network) { |
1188 bool force_close) { | |
1189 DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network); | |
1190 | |
1191 // Find a new network that sessions bound to |network| can be migrated to. | 1188 // Find a new network that sessions bound to |network| can be migrated to. |
1192 NetworkChangeNotifier::NetworkList network_list; | 1189 NetworkChangeNotifier::NetworkList network_list; |
1193 NetworkChangeNotifier::GetConnectedNetworks(&network_list); | 1190 NetworkChangeNotifier::GetConnectedNetworks(&network_list); |
1194 NetworkChangeNotifier::NetworkHandle new_network = | 1191 NetworkChangeNotifier::NetworkHandle new_network = |
1195 NetworkChangeNotifier::kInvalidNetworkHandle; | 1192 NetworkChangeNotifier::kInvalidNetworkHandle; |
1196 for (NetworkChangeNotifier::NetworkHandle n : network_list) { | 1193 for (NetworkChangeNotifier::NetworkHandle n : network_list) { |
1197 if (n != network) { | 1194 if (n != network) { |
1198 new_network = n; | 1195 new_network = n; |
1199 break; | 1196 break; |
1200 } | 1197 } |
1201 } | 1198 } |
1199 return new_network; | |
1200 } | |
Ryan Hamilton
2016/01/21 15:16:02
This can now be simpler:
NetworkChangeNotifier::N
Jana
2016/01/21 18:25:50
Ah, right, of course. Done.
| |
1201 | |
1202 void QuicStreamFactory::MaybeMigrateOrCloseSessions( | |
1203 NetworkChangeNotifier::NetworkHandle network, | |
1204 bool force_close) { | |
1205 DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network); | |
1206 NetworkChangeNotifier::NetworkHandle new_network = | |
1207 FindAlternateNetwork(network); | |
1202 | 1208 |
1203 QuicStreamFactory::SessionIdMap::iterator it = all_sessions_.begin(); | 1209 QuicStreamFactory::SessionIdMap::iterator it = all_sessions_.begin(); |
1204 while (it != all_sessions_.end()) { | 1210 while (it != all_sessions_.end()) { |
1205 QuicChromiumClientSession* session = it->first; | 1211 QuicChromiumClientSession* session = it->first; |
1206 QuicServerId server_id = it->second; | 1212 QuicServerId server_id = it->second; |
1207 ++it; | 1213 ++it; |
1208 | 1214 |
1209 if (session->GetDefaultSocket()->GetBoundNetwork() != network) { | 1215 if (session->GetDefaultSocket()->GetBoundNetwork() != network) { |
1210 // If session is not bound to |network|, move on. | 1216 // If session is not bound to |network|, move on. |
1211 HistogramMigrationStatus(MIGRATION_STATUS_ALREADY_MIGRATED); | 1217 HistogramMigrationStatus(MIGRATION_STATUS_ALREADY_MIGRATED); |
1212 continue; | 1218 continue; |
1213 } | 1219 } |
1214 if (session->GetNumActiveStreams() == 0) { | 1220 if (session->GetNumActiveStreams() == 0) { |
1215 // Close idle sessions. | 1221 // Close idle sessions. |
1216 session->CloseSessionOnError( | 1222 session->CloseSessionOnError( |
1217 ERR_NETWORK_CHANGED, QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS); | 1223 ERR_NETWORK_CHANGED, QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS); |
1218 HistogramMigrationStatus(MIGRATION_STATUS_NO_MIGRATABLE_STREAMS); | 1224 HistogramMigrationStatus(MIGRATION_STATUS_NO_MIGRATABLE_STREAMS); |
1219 continue; | 1225 continue; |
1220 } | 1226 } |
1221 // If session has active streams, mark it as going away. | 1227 // If session has active streams, mark it as going away. |
1222 OnSessionGoingAway(session); | 1228 OnSessionGoingAway(session); |
1223 if (new_network == NetworkChangeNotifier::kInvalidNetworkHandle) { | 1229 if (new_network == NetworkChangeNotifier::kInvalidNetworkHandle) { |
1224 // No new network was found. | 1230 // No new network was found. |
1225 if (force_close) { | 1231 if (force_close) { |
1226 session->CloseSessionOnError(ERR_NETWORK_CHANGED, | 1232 session->CloseSessionOnError(ERR_NETWORK_CHANGED, |
1227 QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK); | 1233 QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK); |
1228 } | 1234 } |
1229 continue; | 1235 continue; |
1230 } | 1236 } |
1231 | 1237 MigrateSessionToNetwork(session, new_network); |
1232 // Use OS-specified port for socket (DEFAULT_BIND) instead of | |
1233 // using the PortSuggester since the connection is being migrated | |
1234 // and not being newly created. | |
1235 scoped_ptr<DatagramClientSocket> socket( | |
1236 client_socket_factory_->CreateDatagramClientSocket( | |
1237 DatagramSocket::DEFAULT_BIND, RandIntCallback(), | |
1238 session->net_log().net_log(), session->net_log().source())); | |
1239 | |
1240 QuicConnection* connection = session->connection(); | |
1241 if (ConfigureSocket(socket.get(), connection->peer_address(), | |
1242 new_network) != OK) { | |
1243 session->CloseSessionOnError(ERR_NETWORK_CHANGED, QUIC_INTERNAL_ERROR); | |
1244 HistogramMigrationStatus(MIGRATION_STATUS_INTERNAL_ERROR); | |
1245 continue; | |
1246 } | |
1247 | |
1248 scoped_ptr<QuicPacketReader> new_reader(new QuicPacketReader( | |
1249 socket.get(), clock_.get(), session, yield_after_packets_, | |
1250 yield_after_duration_, session->net_log())); | |
1251 scoped_ptr<QuicPacketWriter> new_writer( | |
1252 new QuicDefaultPacketWriter(socket.get())); | |
1253 | |
1254 if (!session->MigrateToSocket(std::move(socket), std::move(new_reader), | |
1255 std::move(new_writer))) { | |
1256 session->CloseSessionOnError(ERR_NETWORK_CHANGED, | |
1257 QUIC_CONNECTION_MIGRATION_TOO_MANY_CHANGES); | |
1258 HistogramMigrationStatus(MIGRATION_STATUS_TOO_MANY_CHANGES); | |
1259 } else { | |
1260 HistogramMigrationStatus(MIGRATION_STATUS_SUCCESS); | |
1261 } | |
1262 } | 1238 } |
1263 } | 1239 } |
1264 | 1240 |
1241 void QuicStreamFactory::MigrateSessionToNetwork( | |
1242 QuicChromiumClientSession* session, | |
1243 NetworkChangeNotifier::NetworkHandle new_network) { | |
1244 // Use OS-specified port for socket (DEFAULT_BIND) instead of | |
1245 // using the PortSuggester since the connection is being migrated | |
1246 // and not being newly created. | |
1247 scoped_ptr<DatagramClientSocket> socket( | |
1248 client_socket_factory_->CreateDatagramClientSocket( | |
1249 DatagramSocket::DEFAULT_BIND, RandIntCallback(), | |
1250 session->net_log().net_log(), session->net_log().source())); | |
1251 QuicConnection* connection = session->connection(); | |
1252 if (ConfigureSocket(socket.get(), connection->peer_address(), new_network) != | |
1253 OK) { | |
1254 session->CloseSessionOnError(ERR_NETWORK_CHANGED, QUIC_INTERNAL_ERROR); | |
1255 HistogramMigrationStatus(MIGRATION_STATUS_INTERNAL_ERROR); | |
1256 return; | |
1257 } | |
1258 scoped_ptr<QuicPacketReader> new_reader(new QuicPacketReader( | |
1259 socket.get(), clock_.get(), session, yield_after_packets_, | |
1260 yield_after_duration_, session->net_log())); | |
1261 scoped_ptr<QuicPacketWriter> new_writer( | |
1262 new QuicDefaultPacketWriter(socket.get())); | |
1263 | |
1264 if (!session->MigrateToSocket(std::move(socket), std::move(new_reader), | |
1265 std::move(new_writer))) { | |
1266 session->CloseSessionOnError(ERR_NETWORK_CHANGED, | |
1267 QUIC_CONNECTION_MIGRATION_TOO_MANY_CHANGES); | |
1268 HistogramMigrationStatus(MIGRATION_STATUS_TOO_MANY_CHANGES); | |
1269 return; | |
1270 } | |
1271 HistogramMigrationStatus(MIGRATION_STATUS_SUCCESS); | |
1272 } | |
1273 | |
1265 void QuicStreamFactory::OnSSLConfigChanged() { | 1274 void QuicStreamFactory::OnSSLConfigChanged() { |
1266 CloseAllSessions(ERR_CERT_DATABASE_CHANGED, QUIC_INTERNAL_ERROR); | 1275 CloseAllSessions(ERR_CERT_DATABASE_CHANGED, QUIC_INTERNAL_ERROR); |
1267 } | 1276 } |
1268 | 1277 |
1269 void QuicStreamFactory::OnCertAdded(const X509Certificate* cert) { | 1278 void QuicStreamFactory::OnCertAdded(const X509Certificate* cert) { |
1270 CloseAllSessions(ERR_CERT_DATABASE_CHANGED, QUIC_INTERNAL_ERROR); | 1279 CloseAllSessions(ERR_CERT_DATABASE_CHANGED, QUIC_INTERNAL_ERROR); |
1271 } | 1280 } |
1272 | 1281 |
1273 void QuicStreamFactory::OnCACertChanged(const X509Certificate* cert) { | 1282 void QuicStreamFactory::OnCACertChanged(const X509Certificate* cert) { |
1274 // We should flush the sessions if we removed trust from a | 1283 // We should flush the sessions if we removed trust from a |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1598 // Since the session was active, there's no longer an | 1607 // Since the session was active, there's no longer an |
1599 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 1608 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
1600 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 1609 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
1601 // it as recently broken, which means that 0-RTT will be disabled but we'll | 1610 // it as recently broken, which means that 0-RTT will be disabled but we'll |
1602 // still race. | 1611 // still race. |
1603 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1612 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
1604 alternative_service); | 1613 alternative_service); |
1605 } | 1614 } |
1606 | 1615 |
1607 } // namespace net | 1616 } // namespace net |
OLD | NEW |