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/chromium/quic_stream_factory.h" | 5 #include "net/quic/chromium/quic_stream_factory.h" |
6 | 6 |
7 #include <openssl/aead.h> | 7 #include <openssl/aead.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <tuple> | 10 #include <tuple> |
(...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1447 status_ = OPEN; | 1447 status_ = OPEN; |
1448 CloseAllSessions(ERR_NETWORK_CHANGED, QUIC_IP_ADDRESS_CHANGED); | 1448 CloseAllSessions(ERR_NETWORK_CHANGED, QUIC_IP_ADDRESS_CHANGED); |
1449 set_require_confirmation(true); | 1449 set_require_confirmation(true); |
1450 } | 1450 } |
1451 | 1451 |
1452 void QuicStreamFactory::OnNetworkConnected(NetworkHandle network) { | 1452 void QuicStreamFactory::OnNetworkConnected(NetworkHandle network) { |
1453 num_timeouts_with_open_streams_ = 0; | 1453 num_timeouts_with_open_streams_ = 0; |
1454 status_ = OPEN; | 1454 status_ = OPEN; |
1455 } | 1455 } |
1456 | 1456 |
1457 void QuicStreamFactory::OnNetworkMadeDefault(NetworkHandle network) {} | 1457 void QuicStreamFactory::OnNetworkMadeDefault(NetworkHandle network) { |
1458 ScopedConnectionMigrationEventLog scoped_event_log(net_log_, | |
1459 "OnNetworkMadeDefault"); | |
1460 DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network); | |
1461 MaybeMigrateOrCloseSessions(network, /*force_close=*/false, | |
1462 scoped_event_log.net_log()); | |
1463 set_require_confirmation(true); | |
1464 } | |
1458 | 1465 |
1459 void QuicStreamFactory::OnNetworkDisconnected(NetworkHandle network) { | 1466 void QuicStreamFactory::OnNetworkDisconnected(NetworkHandle network) { |
1460 ScopedConnectionMigrationEventLog scoped_event_log(net_log_, | 1467 ScopedConnectionMigrationEventLog scoped_event_log(net_log_, |
1461 "OnNetworkDisconnected"); | 1468 "OnNetworkDisconnected"); |
1462 MaybeMigrateOrCloseSessions(network, /*force_close=*/true, | 1469 NetworkHandle new_network = FindAlternateNetwork(network); |
1470 MaybeMigrateOrCloseSessions(new_network, /*force_close=*/true, | |
1463 scoped_event_log.net_log()); | 1471 scoped_event_log.net_log()); |
1464 set_require_confirmation(true); | |
1465 } | 1472 } |
1466 | 1473 |
1467 // This method is expected to only be called when migrating from Cellular to | 1474 // This method is expected to only be called when migrating from Cellular to |
1468 // WiFi on Android. | 1475 // WiFi on Android, and should always be preceded by OnNetworkMadeDefault(). |
1469 void QuicStreamFactory::OnNetworkSoonToDisconnect(NetworkHandle network) { | 1476 void QuicStreamFactory::OnNetworkSoonToDisconnect(NetworkHandle network) {} |
1470 ScopedConnectionMigrationEventLog scoped_event_log( | |
1471 net_log_, "OnNetworkSoonToDisconnect"); | |
1472 MaybeMigrateOrCloseSessions(network, /*force_close=*/false, | |
1473 scoped_event_log.net_log()); | |
1474 } | |
1475 | 1477 |
1476 NetworkHandle QuicStreamFactory::FindAlternateNetwork( | 1478 NetworkHandle QuicStreamFactory::FindAlternateNetwork( |
1477 NetworkHandle old_network) { | 1479 NetworkHandle old_network) { |
1478 // Find a new network that sessions bound to |old_network| can be migrated to. | 1480 // Find a new network that sessions bound to |old_network| can be migrated to. |
1479 NetworkChangeNotifier::NetworkList network_list; | 1481 NetworkChangeNotifier::NetworkList network_list; |
1480 NetworkChangeNotifier::GetConnectedNetworks(&network_list); | 1482 NetworkChangeNotifier::GetConnectedNetworks(&network_list); |
1481 for (NetworkHandle new_network : network_list) { | 1483 for (NetworkHandle new_network : network_list) { |
1482 if (new_network != old_network) | 1484 if (new_network != old_network) |
1483 return new_network; | 1485 return new_network; |
1484 } | 1486 } |
1485 return NetworkChangeNotifier::kInvalidNetworkHandle; | 1487 return NetworkChangeNotifier::kInvalidNetworkHandle; |
1486 } | 1488 } |
1487 | 1489 |
1488 void QuicStreamFactory::MaybeMigrateOrCloseSessions( | 1490 void QuicStreamFactory::MaybeMigrateOrCloseSessions( |
1489 NetworkHandle network, | 1491 NetworkHandle new_network, |
1490 bool force_close, | 1492 bool force_close, |
1491 const BoundNetLog& bound_net_log) { | 1493 const BoundNetLog& bound_net_log) { |
1492 DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network); | |
1493 NetworkHandle new_network = FindAlternateNetwork(network); | |
1494 | |
1495 QuicStreamFactory::SessionIdMap::iterator it = all_sessions_.begin(); | 1494 QuicStreamFactory::SessionIdMap::iterator it = all_sessions_.begin(); |
1496 while (it != all_sessions_.end()) { | 1495 while (it != all_sessions_.end()) { |
1497 QuicChromiumClientSession* session = it->first; | 1496 QuicChromiumClientSession* session = it->first; |
1498 ++it; | 1497 ++it; |
1499 | 1498 |
1500 if (session->GetDefaultSocket()->GetBoundNetwork() != network) { | 1499 if (session->GetDefaultSocket()->GetBoundNetwork() == new_network) { |
1501 // If session is not bound to |network|, move on. | 1500 // If session is already bound to |new_network|, move on. |
1502 HistogramAndLogMigrationFailure( | 1501 HistogramAndLogMigrationFailure( |
1503 bound_net_log, MIGRATION_STATUS_ALREADY_MIGRATED, | 1502 bound_net_log, MIGRATION_STATUS_ALREADY_MIGRATED, |
1504 session->connection_id(), "Not bound to network"); | 1503 session->connection_id(), "Already bound to new network"); |
1505 continue; | 1504 continue; |
1506 } | 1505 } |
1507 if (session->GetNumActiveStreams() == 0) { | 1506 if (session->GetNumActiveStreams() == 0) { |
1508 // Close idle sessions. | 1507 // Close idle sessions. |
1509 HistogramAndLogMigrationFailure( | 1508 HistogramAndLogMigrationFailure( |
1510 bound_net_log, MIGRATION_STATUS_NO_MIGRATABLE_STREAMS, | 1509 bound_net_log, MIGRATION_STATUS_NO_MIGRATABLE_STREAMS, |
1511 session->connection_id(), "No active sessions"); | 1510 session->connection_id(), "No active sessions"); |
1512 session->CloseSessionOnError( | 1511 session->CloseSessionOnError( |
1513 ERR_NETWORK_CHANGED, QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS); | 1512 ERR_NETWORK_CHANGED, QUIC_CONNECTION_MIGRATION_NO_MIGRATABLE_STREAMS); |
1514 continue; | 1513 continue; |
1515 } | 1514 } |
1516 // If session has active streams, mark it as going away. | 1515 // If session has active streams, mark it as going away. |
1517 OnSessionGoingAway(session); | 1516 OnSessionGoingAway(session); |
1518 | 1517 |
1519 if (new_network == NetworkChangeNotifier::kInvalidNetworkHandle) { | 1518 if (new_network == NetworkChangeNotifier::kInvalidNetworkHandle) { |
1520 // No new network was found. | 1519 // No new network was found. |
1521 // TODO (jri): Add histogram for this failure case. | 1520 // TODO (jri): Add histogram for this failure case. |
1522 bound_net_log.AddEvent( | 1521 bound_net_log.AddEvent( |
1523 NetLog::TYPE_QUIC_CONNECTION_MIGRATION_FAILURE, | 1522 NetLog::TYPE_QUIC_CONNECTION_MIGRATION_FAILURE, |
1524 base::Bind(&NetLogQuicConnectionMigrationFailureCallback, | 1523 base::Bind(&NetLogQuicConnectionMigrationFailureCallback, |
1525 session->connection_id(), "No new network")); | 1524 session->connection_id(), "No new network")); |
1526 if (force_close) { | 1525 session->CloseSessionOnError(ERR_NETWORK_CHANGED, |
Ryan Hamilton
2016/08/19 20:05:02
This looks like a change in behavior, but I might
Jana
2016/08/19 21:44:08
I've moved the code around a bit, hopefully it'll
| |
1527 session->CloseSessionOnError(ERR_NETWORK_CHANGED, | 1526 QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK); |
1528 QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK); | |
1529 } | |
1530 continue; | 1527 continue; |
1531 } | 1528 } |
1532 if (session->config()->DisableConnectionMigration()) { | 1529 if (session->config()->DisableConnectionMigration()) { |
1533 // Do not migrate sessions where connection migration is disabled by | 1530 // Do not migrate sessions where connection migration is disabled. |
1534 // config. | |
1535 HistogramAndLogMigrationFailure(bound_net_log, MIGRATION_STATUS_DISABLED, | 1531 HistogramAndLogMigrationFailure(bound_net_log, MIGRATION_STATUS_DISABLED, |
1536 session->connection_id(), | 1532 session->connection_id(), |
1537 "Migration disabled"); | 1533 "Migration disabled"); |
1538 if (force_close) { | 1534 if (force_close) { |
1539 // Close sessions where connection migration is disabled. | |
1540 session->CloseSessionOnError(ERR_NETWORK_CHANGED, | 1535 session->CloseSessionOnError(ERR_NETWORK_CHANGED, |
1541 QUIC_IP_ADDRESS_CHANGED); | 1536 QUIC_IP_ADDRESS_CHANGED); |
1542 } | 1537 } |
1543 continue; | 1538 continue; |
1544 } | 1539 } |
1545 if (session->HasNonMigratableStreams()) { | 1540 if (session->HasNonMigratableStreams()) { |
1546 // Do not migrate sessions with non-migratable streams. | 1541 // Do not migrate sessions with non-migratable streams. |
1547 HistogramAndLogMigrationFailure( | 1542 HistogramAndLogMigrationFailure( |
1548 bound_net_log, MIGRATION_STATUS_NON_MIGRATABLE_STREAM, | 1543 bound_net_log, MIGRATION_STATUS_NON_MIGRATABLE_STREAM, |
1549 session->connection_id(), "Non-migratable stream"); | 1544 session->connection_id(), "Non-migratable stream"); |
1550 if (force_close) { | 1545 if (force_close) { |
1551 // Close sessions with non-migratable streams. | |
1552 session->CloseSessionOnError( | 1546 session->CloseSessionOnError( |
1553 ERR_NETWORK_CHANGED, | 1547 ERR_NETWORK_CHANGED, |
1554 QUIC_CONNECTION_MIGRATION_NON_MIGRATABLE_STREAM); | 1548 QUIC_CONNECTION_MIGRATION_NON_MIGRATABLE_STREAM); |
1555 } | 1549 } |
1556 continue; | 1550 continue; |
1557 } | 1551 } |
1558 | 1552 |
1559 MigrateSessionToNewNetwork(session, new_network, bound_net_log, nullptr); | 1553 MigrateSessionToNewNetwork(session, new_network, bound_net_log, nullptr); |
1560 } | 1554 } |
1561 } | 1555 } |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2038 // Since the session was active, there's no longer an | 2032 // Since the session was active, there's no longer an |
2039 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 2033 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
2040 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 2034 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
2041 // it as recently broken, which means that 0-RTT will be disabled but we'll | 2035 // it as recently broken, which means that 0-RTT will be disabled but we'll |
2042 // still race. | 2036 // still race. |
2043 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 2037 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
2044 alternative_service); | 2038 alternative_service); |
2045 } | 2039 } |
2046 | 2040 |
2047 } // namespace net | 2041 } // namespace net |
OLD | NEW |