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/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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 namespace { | 64 namespace { |
| 65 | 65 |
| 66 enum CreateSessionFailure { | 66 enum CreateSessionFailure { |
| 67 CREATION_ERROR_CONNECTING_SOCKET, | 67 CREATION_ERROR_CONNECTING_SOCKET, |
| 68 CREATION_ERROR_SETTING_RECEIVE_BUFFER, | 68 CREATION_ERROR_SETTING_RECEIVE_BUFFER, |
| 69 CREATION_ERROR_SETTING_SEND_BUFFER, | 69 CREATION_ERROR_SETTING_SEND_BUFFER, |
| 70 CREATION_ERROR_SETTING_DO_NOT_FRAGMENT, | 70 CREATION_ERROR_SETTING_DO_NOT_FRAGMENT, |
| 71 CREATION_ERROR_MAX | 71 CREATION_ERROR_MAX |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 enum QuicConnectionMigrationStatus { | |
| 75 MIGRATION_STATUS_NO_MIGRATABLE_STREAMS, | |
| 76 MIGRATION_STATUS_ALREADY_MIGRATED, | |
| 77 MIGRATION_STATUS_INTERNAL_ERROR, | |
| 78 MIGRATION_STATUS_TOO_MANY_CHANGES, | |
| 79 MIGRATION_STATUS_SUCCESS, | |
| 80 MIGRATION_STATUS_NON_MIGRATABLE_STREAM, | |
| 81 MIGRATION_STATUS_DISABLED, | |
| 82 MIGRATION_STATUS_NO_ALTERNATE_NETWORK, | |
| 83 MIGRATION_STATUS_MAX | |
| 84 }; | |
| 85 | |
| 86 // The maximum receive window sizes for QUIC sessions and streams. | 74 // The maximum receive window sizes for QUIC sessions and streams. |
| 87 const int32_t kQuicSessionMaxRecvWindowSize = 15 * 1024 * 1024; // 15 MB | 75 const int32_t kQuicSessionMaxRecvWindowSize = 15 * 1024 * 1024; // 15 MB |
| 88 const int32_t kQuicStreamMaxRecvWindowSize = 6 * 1024 * 1024; // 6 MB | 76 const int32_t kQuicStreamMaxRecvWindowSize = 6 * 1024 * 1024; // 6 MB |
| 89 | 77 |
| 90 // Set the maximum number of undecryptable packets the connection will store. | 78 // Set the maximum number of undecryptable packets the connection will store. |
| 91 const int32_t kMaxUndecryptablePackets = 100; | 79 const int32_t kMaxUndecryptablePackets = 100; |
| 92 | 80 |
| 93 std::unique_ptr<base::Value> NetLogQuicConnectionMigrationTriggerCallback( | 81 std::unique_ptr<base::Value> NetLogQuicConnectionMigrationTriggerCallback( |
| 94 std::string trigger, | 82 std::string trigger, |
| 95 NetLogCaptureMode capture_mode) { | 83 NetLogCaptureMode capture_mode) { |
| (...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1437 void QuicStreamFactory::OnIPAddressChanged() { | 1425 void QuicStreamFactory::OnIPAddressChanged() { |
| 1438 num_timeouts_with_open_streams_ = 0; | 1426 num_timeouts_with_open_streams_ = 0; |
| 1439 status_ = OPEN; | 1427 status_ = OPEN; |
| 1440 CloseAllSessions(ERR_NETWORK_CHANGED, QUIC_IP_ADDRESS_CHANGED); | 1428 CloseAllSessions(ERR_NETWORK_CHANGED, QUIC_IP_ADDRESS_CHANGED); |
| 1441 set_require_confirmation(true); | 1429 set_require_confirmation(true); |
| 1442 } | 1430 } |
| 1443 | 1431 |
| 1444 void QuicStreamFactory::OnNetworkConnected(NetworkHandle network) { | 1432 void QuicStreamFactory::OnNetworkConnected(NetworkHandle network) { |
| 1445 num_timeouts_with_open_streams_ = 0; | 1433 num_timeouts_with_open_streams_ = 0; |
| 1446 status_ = OPEN; | 1434 status_ = OPEN; |
| 1435 ScopedConnectionMigrationEventLog scoped_event_log(net_log_, | |
| 1436 "OnNetworkConnected"); | |
| 1437 for (auto session : all_sessions_) { | |
| 1438 session.first->OnNetworkConnected(network, scoped_event_log.net_log()); | |
| 1439 } | |
|
Ryan Hamilton
2016/09/12 03:42:01
I expected this to call MigrateOrCloseSessions(),
Ryan Hamilton
2016/09/13 00:33:18
ping
Jana
2016/09/13 01:12:18
OnNetworkConnected can be called from the NCN when
| |
| 1447 } | 1440 } |
| 1448 | 1441 |
| 1449 void QuicStreamFactory::OnNetworkMadeDefault(NetworkHandle network) { | 1442 void QuicStreamFactory::OnNetworkMadeDefault(NetworkHandle network) { |
| 1450 ScopedConnectionMigrationEventLog scoped_event_log(net_log_, | 1443 ScopedConnectionMigrationEventLog scoped_event_log(net_log_, |
| 1451 "OnNetworkMadeDefault"); | 1444 "OnNetworkMadeDefault"); |
| 1452 DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network); | 1445 DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network); |
| 1453 MaybeMigrateOrCloseSessions(network, /*close_if_cannot_migrate=*/false, | 1446 MaybeMigrateOrCloseSessions(network, /*close_if_cannot_migrate=*/false, |
| 1454 scoped_event_log.net_log()); | 1447 scoped_event_log.net_log()); |
| 1455 set_require_confirmation(true); | 1448 set_require_confirmation(true); |
| 1456 } | 1449 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1472 // Find a new network that sessions bound to |old_network| can be migrated to. | 1465 // Find a new network that sessions bound to |old_network| can be migrated to. |
| 1473 NetworkChangeNotifier::NetworkList network_list; | 1466 NetworkChangeNotifier::NetworkList network_list; |
| 1474 NetworkChangeNotifier::GetConnectedNetworks(&network_list); | 1467 NetworkChangeNotifier::GetConnectedNetworks(&network_list); |
| 1475 for (NetworkHandle new_network : network_list) { | 1468 for (NetworkHandle new_network : network_list) { |
| 1476 if (new_network != old_network) | 1469 if (new_network != old_network) |
| 1477 return new_network; | 1470 return new_network; |
| 1478 } | 1471 } |
| 1479 return NetworkChangeNotifier::kInvalidNetworkHandle; | 1472 return NetworkChangeNotifier::kInvalidNetworkHandle; |
| 1480 } | 1473 } |
| 1481 | 1474 |
| 1475 // @@@ look at other cl for changes here. | |
|
Ryan Hamilton
2016/09/12 03:42:01
?
Jana
2016/09/13 01:12:18
Leftover comment, removed.
| |
| 1482 void QuicStreamFactory::MaybeMigrateOrCloseSessions( | 1476 void QuicStreamFactory::MaybeMigrateOrCloseSessions( |
| 1483 NetworkHandle new_network, | 1477 NetworkHandle new_network, |
| 1484 bool close_if_cannot_migrate, | 1478 bool close_if_cannot_migrate, |
| 1485 const BoundNetLog& bound_net_log) { | 1479 const BoundNetLog& bound_net_log) { |
| 1486 QuicStreamFactory::SessionIdMap::iterator it = all_sessions_.begin(); | 1480 QuicStreamFactory::SessionIdMap::iterator it = all_sessions_.begin(); |
| 1487 while (it != all_sessions_.end()) { | 1481 while (it != all_sessions_.end()) { |
| 1488 QuicChromiumClientSession* session = it->first; | 1482 QuicChromiumClientSession* session = it->first; |
| 1489 ++it; | 1483 ++it; |
| 1490 | 1484 |
| 1491 // Migration attempted, but no new network was found. Close session. | |
| 1492 if (new_network == NetworkChangeNotifier::kInvalidNetworkHandle) { | |
| 1493 HistogramAndLogMigrationFailure( | |
| 1494 bound_net_log, MIGRATION_STATUS_NO_ALTERNATE_NETWORK, | |
| 1495 session->connection_id(), "No alternate network found"); | |
| 1496 session->CloseSessionOnError(ERR_NETWORK_CHANGED, | |
| 1497 QUIC_CONNECTION_MIGRATION_NO_NEW_NETWORK); | |
| 1498 continue; | |
| 1499 } | |
| 1500 | |
| 1501 // If session is already bound to |new_network|, move on. | 1485 // If session is already bound to |new_network|, move on. |
| 1502 if (session->GetDefaultSocket()->GetBoundNetwork() == new_network) { | 1486 if (session->GetDefaultSocket()->GetBoundNetwork() == new_network) { |
| 1503 HistogramAndLogMigrationFailure( | 1487 HistogramAndLogMigrationFailure( |
| 1504 bound_net_log, MIGRATION_STATUS_ALREADY_MIGRATED, | 1488 bound_net_log, MIGRATION_STATUS_ALREADY_MIGRATED, |
| 1505 session->connection_id(), "Already bound to new network"); | 1489 session->connection_id(), "Already bound to new network"); |
| 1506 continue; | 1490 continue; |
| 1507 } | 1491 } |
| 1508 | 1492 |
| 1509 // Close idle sessions. | 1493 // Close idle sessions. |
| 1510 if (session->GetNumActiveStreams() == 0) { | 1494 if (session->GetNumActiveStreams() == 0) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1537 bound_net_log, MIGRATION_STATUS_NON_MIGRATABLE_STREAM, | 1521 bound_net_log, MIGRATION_STATUS_NON_MIGRATABLE_STREAM, |
| 1538 session->connection_id(), "Non-migratable stream"); | 1522 session->connection_id(), "Non-migratable stream"); |
| 1539 if (close_if_cannot_migrate) { | 1523 if (close_if_cannot_migrate) { |
| 1540 session->CloseSessionOnError( | 1524 session->CloseSessionOnError( |
| 1541 ERR_NETWORK_CHANGED, | 1525 ERR_NETWORK_CHANGED, |
| 1542 QUIC_CONNECTION_MIGRATION_NON_MIGRATABLE_STREAM); | 1526 QUIC_CONNECTION_MIGRATION_NON_MIGRATABLE_STREAM); |
| 1543 } | 1527 } |
| 1544 continue; | 1528 continue; |
| 1545 } | 1529 } |
| 1546 | 1530 |
| 1531 // No new network was found. Notify session, so it can wait for a | |
| 1532 // new network. | |
| 1533 if (new_network == NetworkChangeNotifier::kInvalidNetworkHandle) { | |
| 1534 session->OnNoNewNetwork(); | |
| 1535 continue; | |
| 1536 } | |
| 1537 | |
| 1547 MigrateSessionToNewNetwork(session, new_network, | 1538 MigrateSessionToNewNetwork(session, new_network, |
| 1548 /*close_session_on_error=*/true, bound_net_log); | 1539 /*close_session_on_error=*/true, bound_net_log); |
| 1549 } | 1540 } |
| 1550 } | 1541 } |
| 1551 | 1542 |
| 1552 MigrationResult QuicStreamFactory::MaybeMigrateSingleSession( | 1543 MigrationResult QuicStreamFactory::MaybeMigrateSingleSession( |
| 1553 QuicChromiumClientSession* session, | 1544 QuicChromiumClientSession* session, |
| 1554 MigrationCause migration_cause) { | 1545 MigrationCause migration_cause) { |
| 1555 ScopedConnectionMigrationEventLog scoped_event_log( | 1546 ScopedConnectionMigrationEventLog scoped_event_log( |
| 1556 net_log_, | 1547 net_log_, |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1841 socket_performance_watcher = | 1832 socket_performance_watcher = |
| 1842 socket_performance_watcher_factory_->CreateSocketPerformanceWatcher( | 1833 socket_performance_watcher_factory_->CreateSocketPerformanceWatcher( |
| 1843 SocketPerformanceWatcherFactory::PROTOCOL_QUIC); | 1834 SocketPerformanceWatcherFactory::PROTOCOL_QUIC); |
| 1844 } | 1835 } |
| 1845 | 1836 |
| 1846 *session = new QuicChromiumClientSession( | 1837 *session = new QuicChromiumClientSession( |
| 1847 connection, std::move(socket), this, quic_crypto_client_stream_factory_, | 1838 connection, std::move(socket), this, quic_crypto_client_stream_factory_, |
| 1848 clock_.get(), transport_security_state_, std::move(server_info), | 1839 clock_.get(), transport_security_state_, std::move(server_info), |
| 1849 server_id, yield_after_packets_, yield_after_duration_, cert_verify_flags, | 1840 server_id, yield_after_packets_, yield_after_duration_, cert_verify_flags, |
| 1850 config, &crypto_config_, network_connection_.GetDescription(), | 1841 config, &crypto_config_, network_connection_.GetDescription(), |
| 1851 dns_resolution_end_time, &push_promise_index_, | 1842 dns_resolution_end_time, &push_promise_index_, task_runner_, |
| 1852 base::ThreadTaskRunnerHandle::Get().get(), | |
| 1853 std::move(socket_performance_watcher), net_log.net_log()); | 1843 std::move(socket_performance_watcher), net_log.net_log()); |
| 1854 | 1844 |
| 1855 all_sessions_[*session] = key; // owning pointer | 1845 all_sessions_[*session] = key; // owning pointer |
| 1856 writer->set_delegate(*session); | 1846 writer->set_delegate(*session); |
| 1857 | 1847 |
| 1858 (*session)->Initialize(); | 1848 (*session)->Initialize(); |
| 1859 bool closed_during_initialize = !base::ContainsKey(all_sessions_, *session) || | 1849 bool closed_during_initialize = !base::ContainsKey(all_sessions_, *session) || |
| 1860 !(*session)->connection()->connected(); | 1850 !(*session)->connection()->connected(); |
| 1861 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ClosedDuringInitializeSession", | 1851 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ClosedDuringInitializeSession", |
| 1862 closed_during_initialize); | 1852 closed_during_initialize); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2046 // Since the session was active, there's no longer an | 2036 // Since the session was active, there's no longer an |
| 2047 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 2037 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
| 2048 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 2038 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
| 2049 // it as recently broken, which means that 0-RTT will be disabled but we'll | 2039 // it as recently broken, which means that 0-RTT will be disabled but we'll |
| 2050 // still race. | 2040 // still race. |
| 2051 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 2041 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
| 2052 alternative_service); | 2042 alternative_service); |
| 2053 } | 2043 } |
| 2054 | 2044 |
| 2055 } // namespace net | 2045 } // namespace net |
| OLD | NEW |