OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 831 matching lines...) Loading... |
842 // On the candidate itself, or through SetIceCredentials? | 842 // On the candidate itself, or through SetIceCredentials? |
843 // Goes through the candidate itself by default. | 843 // Goes through the candidate itself by default. |
844 void set_remote_ice_credential_source(RemoteIceCredentialSource source) { | 844 void set_remote_ice_credential_source(RemoteIceCredentialSource source) { |
845 remote_ice_credential_source_ = source; | 845 remote_ice_credential_source_ = source; |
846 } | 846 } |
847 | 847 |
848 void set_force_relay(bool relay) { | 848 void set_force_relay(bool relay) { |
849 force_relay_ = relay; | 849 force_relay_ = relay; |
850 } | 850 } |
851 | 851 |
| 852 void ConnectSignalNominated(Connection* conn) { |
| 853 conn->SignalNominated.connect(this, |
| 854 &P2PTransportChannelTestBase::OnNominated); |
| 855 } |
| 856 |
| 857 void OnNominated(Connection* conn) { nominated_ = true; } |
| 858 bool nominated() { return nominated_; } |
| 859 |
852 private: | 860 private: |
853 rtc::Thread* main_; | 861 rtc::Thread* main_; |
854 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 862 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
855 std::unique_ptr<rtc::VirtualSocketServer> vss_; | 863 std::unique_ptr<rtc::VirtualSocketServer> vss_; |
856 std::unique_ptr<rtc::NATSocketServer> nss_; | 864 std::unique_ptr<rtc::NATSocketServer> nss_; |
857 std::unique_ptr<rtc::FirewallSocketServer> ss_; | 865 std::unique_ptr<rtc::FirewallSocketServer> ss_; |
858 rtc::SocketServerScope ss_scope_; | 866 rtc::SocketServerScope ss_scope_; |
859 std::unique_ptr<TestStunServer> stun_server_; | 867 std::unique_ptr<TestStunServer> stun_server_; |
860 TestTurnServer turn_server_; | 868 TestTurnServer turn_server_; |
861 TestRelayServer relay_server_; | 869 TestRelayServer relay_server_; |
862 rtc::SocksProxyServer socks_server1_; | 870 rtc::SocksProxyServer socks_server1_; |
863 rtc::SocksProxyServer socks_server2_; | 871 rtc::SocksProxyServer socks_server2_; |
864 Endpoint ep1_; | 872 Endpoint ep1_; |
865 Endpoint ep2_; | 873 Endpoint ep2_; |
866 RemoteIceCredentialSource remote_ice_credential_source_ = FROM_CANDIDATE; | 874 RemoteIceCredentialSource remote_ice_credential_source_ = FROM_CANDIDATE; |
867 bool force_relay_; | 875 bool force_relay_; |
868 int selected_candidate_pair_switches_ = 0; | 876 int selected_candidate_pair_switches_ = 0; |
| 877 |
| 878 bool nominated_ = false; |
869 }; | 879 }; |
870 | 880 |
871 // The tests have only a few outcomes, which we predefine. | 881 // The tests have only a few outcomes, which we predefine. |
872 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: | 882 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: |
873 kLocalUdpToLocalUdp("local", "udp", "local", "udp", | 883 kLocalUdpToLocalUdp("local", "udp", "local", "udp", |
874 "local", "udp", "local", "udp", 1000); | 884 "local", "udp", "local", "udp", 1000); |
875 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: | 885 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: |
876 kLocalUdpToStunUdp("local", "udp", "stun", "udp", | 886 kLocalUdpToStunUdp("local", "udp", "stun", "udp", |
877 "local", "udp", "stun", "udp", 1000); | 887 "local", "udp", "stun", "udp", 1000); |
878 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: | 888 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: |
(...skipping 976 matching lines...) Loading... |
1855 const SocketAddress& address) { | 1865 const SocketAddress& address) { |
1856 for (cricket::Connection* conn : channel->connections()) { | 1866 for (cricket::Connection* conn : channel->connections()) { |
1857 if (conn->local_candidate().address().EqualIPs(address)) { | 1867 if (conn->local_candidate().address().EqualIPs(address)) { |
1858 return conn; | 1868 return conn; |
1859 } | 1869 } |
1860 } | 1870 } |
1861 return nullptr; | 1871 return nullptr; |
1862 } | 1872 } |
1863 | 1873 |
1864 void DestroyAllButBestConnection(cricket::P2PTransportChannel* channel) { | 1874 void DestroyAllButBestConnection(cricket::P2PTransportChannel* channel) { |
1865 const cricket::Connection* best_connection = channel->best_connection(); | 1875 const cricket::Connection* selected_connection = |
| 1876 channel->selected_connection(); |
1866 for (cricket::Connection* conn : channel->connections()) { | 1877 for (cricket::Connection* conn : channel->connections()) { |
1867 if (conn != best_connection) { | 1878 if (conn != selected_connection) { |
1868 conn->Destroy(); | 1879 conn->Destroy(); |
1869 } | 1880 } |
1870 } | 1881 } |
1871 } | 1882 } |
1872 }; | 1883 }; |
1873 | 1884 |
1874 // Test that we can establish connectivity when both peers are multihomed. | 1885 // Test that we can establish connectivity when both peers are multihomed. |
1875 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) { | 1886 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) { |
1876 AddAddress(0, kPublicAddrs[0]); | 1887 AddAddress(0, kPublicAddrs[0]); |
1877 AddAddress(0, kAlternateAddrs[0]); | 1888 AddAddress(0, kAlternateAddrs[0]); |
(...skipping 106 matching lines...) Loading... |
1984 3000, clock); | 1995 3000, clock); |
1985 EXPECT_TRUE( | 1996 EXPECT_TRUE( |
1986 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0])); | 1997 LocalCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0])); |
1987 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1998 EXPECT_TRUE(RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1988 EXPECT_TRUE( | 1999 EXPECT_TRUE( |
1989 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0])); | 2000 RemoteCandidate(ep2_ch1())->address().EqualIPs(kAlternateAddrs[0])); |
1990 | 2001 |
1991 DestroyChannels(); | 2002 DestroyChannels(); |
1992 } | 2003 } |
1993 | 2004 |
| 2005 // Test that when the controlling side switches the selected connection, |
| 2006 // the nomination of the selected connection on the controlled side will |
| 2007 // increase. |
| 2008 TEST_F(P2PTransportChannelMultihomedTest, TestIceRenomination) { |
| 2009 rtc::ScopedFakeClock clock; |
| 2010 // Adding alternate address will make sure |kPublicAddrs| has the higher |
| 2011 // priority than others. This is due to FakeNetwork::AddInterface method. |
| 2012 AddAddress(0, kAlternateAddrs[0]); |
| 2013 AddAddress(0, kPublicAddrs[0]); |
| 2014 AddAddress(1, kPublicAddrs[1]); |
| 2015 |
| 2016 // Use only local ports for simplicity. |
| 2017 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 2018 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 2019 |
| 2020 // Create channels and let them go writable, as usual. |
| 2021 CreateChannels(1); |
| 2022 ep1_ch1()->set_remote_supports_renomination(true); |
| 2023 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 2024 ep2_ch1()->receiving() && |
| 2025 ep2_ch1()->writable(), |
| 2026 3000, clock); |
| 2027 EXPECT_TRUE_SIMULATED_WAIT( |
| 2028 ep2_ch1()->selected_connection()->remote_nomination() > 0 && |
| 2029 ep1_ch1()->selected_connection()->acked_nomination() > 0, |
| 2030 kDefaultTimeout, clock); |
| 2031 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); |
| 2032 Connection* selected_connection2 = |
| 2033 const_cast<Connection*>(ep2_ch1()->selected_connection()); |
| 2034 uint32_t remote_nomination2 = selected_connection2->remote_nomination(); |
| 2035 // |selected_connection2| should not be nominated any more since the previous |
| 2036 // nomination has been acknowledged. |
| 2037 ConnectSignalNominated(selected_connection2); |
| 2038 SIMULATED_WAIT(nominated(), 3000, clock); |
| 2039 EXPECT_FALSE(nominated()); |
| 2040 |
| 2041 // Make the receiving timeout shorter for testing. |
| 2042 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); |
| 2043 ep1_ch1()->SetIceConfig(config); |
| 2044 ep2_ch1()->SetIceConfig(config); |
| 2045 |
| 2046 // Blackhole any traffic to or from the public addrs. |
| 2047 LOG(LS_INFO) << "Failing over..."; |
| 2048 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); |
| 2049 |
| 2050 // The selected connection on the controlling side should switch. |
| 2051 EXPECT_TRUE_SIMULATED_WAIT( |
| 2052 ep1_ch1()->selected_connection() != selected_connection1, 3000, clock); |
| 2053 // The connection on the controlled side should be nominated again |
| 2054 // and have an increased nomination. |
| 2055 EXPECT_TRUE_SIMULATED_WAIT( |
| 2056 ep2_ch1()->selected_connection()->remote_nomination() > |
| 2057 remote_nomination2, |
| 2058 kDefaultTimeout, clock); |
| 2059 |
| 2060 DestroyChannels(); |
| 2061 } |
| 2062 |
1994 // Test that if an interface fails temporarily and then recovers quickly, | 2063 // Test that if an interface fails temporarily and then recovers quickly, |
1995 // the selected connection will not switch. | 2064 // the selected connection will not switch. |
1996 // The case that it will switch over to the backup connection if the selected | 2065 // The case that it will switch over to the backup connection if the selected |
1997 // connection does not recover after enough time is covered in | 2066 // connection does not recover after enough time is covered in |
1998 // TestFailoverControlledSide and TestFailoverControllingSide. | 2067 // TestFailoverControlledSide and TestFailoverControllingSide. |
1999 TEST_F(P2PTransportChannelMultihomedTest, | 2068 TEST_F(P2PTransportChannelMultihomedTest, |
2000 TestConnectionSwitchDampeningControlledSide) { | 2069 TestConnectionSwitchDampeningControlledSide) { |
2001 rtc::ScopedFakeClock clock; | 2070 rtc::ScopedFakeClock clock; |
2002 AddAddress(0, kPublicAddrs[0]); | 2071 AddAddress(0, kPublicAddrs[0]); |
2003 // Adding alternate address will make sure |kPublicAddrs| has the higher | 2072 // Adding alternate address will make sure |kPublicAddrs| has the higher |
(...skipping 284 matching lines...) Loading... |
2288 SetAllocatorFlags(0, kOnlyLocalPorts); | 2357 SetAllocatorFlags(0, kOnlyLocalPorts); |
2289 SetAllocatorFlags(1, kOnlyLocalPorts); | 2358 SetAllocatorFlags(1, kOnlyLocalPorts); |
2290 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 2359 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
2291 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 2360 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
2292 kDefaultTimeout, kDefaultTimeout); | 2361 kDefaultTimeout, kDefaultTimeout); |
2293 | 2362 |
2294 // Add a new wifi interface on end point 2. We should expect a new connection | 2363 // Add a new wifi interface on end point 2. We should expect a new connection |
2295 // to be created and the new one will be the best connection. | 2364 // to be created and the new one will be the best connection. |
2296 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI); | 2365 AddAddress(1, wifi[1], "test_wifi1", rtc::ADAPTER_TYPE_WIFI); |
2297 const cricket::Connection* conn; | 2366 const cricket::Connection* conn; |
2298 EXPECT_TRUE_WAIT((conn = ep1_ch1()->best_connection()) != nullptr && | 2367 EXPECT_TRUE_WAIT((conn = ep1_ch1()->selected_connection()) != nullptr && |
2299 conn->remote_candidate().address().EqualIPs(wifi[1]), | 2368 conn->remote_candidate().address().EqualIPs(wifi[1]), |
2300 kDefaultTimeout); | 2369 kDefaultTimeout); |
2301 EXPECT_TRUE_WAIT((conn = ep2_ch1()->best_connection()) != nullptr && | 2370 EXPECT_TRUE_WAIT((conn = ep2_ch1()->selected_connection()) != nullptr && |
2302 conn->local_candidate().address().EqualIPs(wifi[1]), | 2371 conn->local_candidate().address().EqualIPs(wifi[1]), |
2303 kDefaultTimeout); | 2372 kDefaultTimeout); |
2304 | 2373 |
2305 // Add a new cellular interface on end point 1, we should expect a new | 2374 // Add a new cellular interface on end point 1, we should expect a new |
2306 // backup connection created using this new interface. | 2375 // backup connection created using this new interface. |
2307 AddAddress(0, cellular[0], "test_cellular0", rtc::ADAPTER_TYPE_CELLULAR); | 2376 AddAddress(0, cellular[0], "test_cellular0", rtc::ADAPTER_TYPE_CELLULAR); |
2308 EXPECT_TRUE_WAIT(ep1_ch1()->GetState() == cricket::STATE_COMPLETED && | 2377 EXPECT_TRUE_WAIT( |
2309 (conn = GetConnectionWithLocalAddress( | 2378 ep1_ch1()->GetState() == cricket::STATE_COMPLETED && |
2310 ep1_ch1(), cellular[0])) != nullptr && | 2379 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) != |
2311 conn != ep1_ch1()->best_connection() && conn->writable(), | 2380 nullptr && |
2312 kDefaultTimeout); | 2381 conn != ep1_ch1()->selected_connection() && conn->writable(), |
| 2382 kDefaultTimeout); |
2313 EXPECT_TRUE_WAIT( | 2383 EXPECT_TRUE_WAIT( |
2314 ep2_ch1()->GetState() == cricket::STATE_COMPLETED && | 2384 ep2_ch1()->GetState() == cricket::STATE_COMPLETED && |
2315 (conn = GetConnectionWithRemoteAddress(ep2_ch1(), cellular[0])) != | 2385 (conn = GetConnectionWithRemoteAddress(ep2_ch1(), cellular[0])) != |
2316 nullptr && | 2386 nullptr && |
2317 conn != ep2_ch1()->best_connection() && conn->receiving(), | 2387 conn != ep2_ch1()->selected_connection() && conn->receiving(), |
2318 kDefaultTimeout); | 2388 kDefaultTimeout); |
2319 | 2389 |
2320 DestroyChannels(); | 2390 DestroyChannels(); |
2321 } | 2391 } |
2322 | 2392 |
2323 // Tests that we can switch links via continual gathering. | 2393 // Tests that we can switch links via continual gathering. |
2324 TEST_F(P2PTransportChannelMultihomedTest, | 2394 TEST_F(P2PTransportChannelMultihomedTest, |
2325 TestSwitchLinksViaContinualGathering) { | 2395 TestSwitchLinksViaContinualGathering) { |
2326 rtc::ScopedFakeClock clock; | 2396 rtc::ScopedFakeClock clock; |
2327 AddAddress(0, kPublicAddrs[0]); | 2397 AddAddress(0, kPublicAddrs[0]); |
(...skipping 25 matching lines...) Loading... |
2353 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && | 2423 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && |
2354 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 2424 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
2355 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), | 2425 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), |
2356 3000, clock); | 2426 3000, clock); |
2357 | 2427 |
2358 // Remove one address first and then add another address. | 2428 // Remove one address first and then add another address. |
2359 LOG(LS_INFO) << "Draining again..."; | 2429 LOG(LS_INFO) << "Draining again..."; |
2360 RemoveAddress(1, kAlternateAddrs[1]); | 2430 RemoveAddress(1, kAlternateAddrs[1]); |
2361 AddAddress(1, kAlternateAddrs[0]); | 2431 AddAddress(1, kAlternateAddrs[0]); |
2362 EXPECT_TRUE_SIMULATED_WAIT( | 2432 EXPECT_TRUE_SIMULATED_WAIT( |
2363 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 2433 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && |
2364 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 2434 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
2365 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]), | 2435 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[0]), |
2366 3000, clock); | 2436 3000, clock); |
2367 | 2437 |
2368 DestroyChannels(); | 2438 DestroyChannels(); |
2369 } | 2439 } |
2370 | 2440 |
2371 /* | 2441 /* |
2372 TODO(honghaiz) Once continual gathering fully supports | 2442 TODO(honghaiz) Once continual gathering fully supports |
2373 GATHER_CONTINUALLY_AND_RECOVER, put this test back. | 2443 GATHER_CONTINUALLY_AND_RECOVER, put this test back. |
(...skipping 16 matching lines...) Loading... |
2390 | 2460 |
2391 // Create channels and let them go writable, as usual. | 2461 // Create channels and let them go writable, as usual. |
2392 CreateChannels(1); | 2462 CreateChannels(1); |
2393 // Set continual gathering policy. | 2463 // Set continual gathering policy. |
2394 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY_AND_RECOVER); | 2464 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY_AND_RECOVER); |
2395 ep1_ch1()->SetIceConfig(config); | 2465 ep1_ch1()->SetIceConfig(config); |
2396 ep2_ch1()->SetIceConfig(config); | 2466 ep2_ch1()->SetIceConfig(config); |
2397 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 2467 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
2398 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 2468 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
2399 3000, clock); | 2469 3000, clock); |
2400 EXPECT_TRUE(ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 2470 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
| 2471 ep2_ch1()->selected_connection() && |
2401 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && | 2472 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && |
2402 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1])); | 2473 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1])); |
2403 | 2474 |
2404 // First destroy all backup connection. | 2475 // First destroy all backup connection. |
2405 DestroyAllButBestConnection(ep1_ch1()); | 2476 DestroyAllButBestConnection(ep1_ch1()); |
2406 | 2477 |
2407 SIMULATED_WAIT(false, 10, clock); | 2478 SIMULATED_WAIT(false, 10, clock); |
2408 // Then the interface of the best connection goes away. | 2479 // Then the interface of the best connection goes away. |
2409 RemoveAddress(0, wifi[0]); | 2480 RemoveAddress(0, wifi[0]); |
2410 EXPECT_TRUE_SIMULATED_WAIT( | 2481 EXPECT_TRUE_SIMULATED_WAIT( |
2411 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 2482 ep1_ch1()->selected_connection() && ep2_ch1()->selected_connection() && |
2412 LocalCandidate(ep1_ch1())->address().EqualIPs(cellular[0]) && | 2483 LocalCandidate(ep1_ch1())->address().EqualIPs(cellular[0]) && |
2413 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), | 2484 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1]), |
2414 3000, clock); | 2485 3000, clock); |
2415 | 2486 |
2416 DestroyChannels(); | 2487 DestroyChannels(); |
2417 } | 2488 } |
2418 */ | 2489 */ |
2419 | 2490 |
2420 // Tests that the backup connection will be restored after it is destroyed. | 2491 // Tests that the backup connection will be restored after it is destroyed. |
2421 TEST_F(P2PTransportChannelMultihomedTest, TestRestoreBackupConnection) { | 2492 TEST_F(P2PTransportChannelMultihomedTest, TestRestoreBackupConnection) { |
(...skipping 11 matching lines...) Loading... |
2433 // Create channels and let them go writable, as usual. | 2504 // Create channels and let them go writable, as usual. |
2434 CreateChannels(1); | 2505 CreateChannels(1); |
2435 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); | 2506 IceConfig config = CreateIceConfig(1000, GATHER_CONTINUALLY); |
2436 config.regather_on_failed_networks_interval = rtc::Optional<int>(2000); | 2507 config.regather_on_failed_networks_interval = rtc::Optional<int>(2000); |
2437 ep1_ch1()->SetIceConfig(config); | 2508 ep1_ch1()->SetIceConfig(config); |
2438 ep2_ch1()->SetIceConfig(config); | 2509 ep2_ch1()->SetIceConfig(config); |
2439 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 2510 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
2440 ep2_ch1()->receiving() && | 2511 ep2_ch1()->receiving() && |
2441 ep2_ch1()->writable(), | 2512 ep2_ch1()->writable(), |
2442 3000, clock); | 2513 3000, clock); |
2443 EXPECT_TRUE(ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 2514 EXPECT_TRUE(ep1_ch1()->selected_connection() && |
| 2515 ep2_ch1()->selected_connection() && |
2444 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && | 2516 LocalCandidate(ep1_ch1())->address().EqualIPs(wifi[0]) && |
2445 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1])); | 2517 RemoteCandidate(ep1_ch1())->address().EqualIPs(wifi[1])); |
2446 | 2518 |
2447 // Destroy all backup connections. | 2519 // Destroy all backup connections. |
2448 DestroyAllButBestConnection(ep1_ch1()); | 2520 DestroyAllButBestConnection(ep1_ch1()); |
2449 // Ensure the backup connection is removed first. | 2521 // Ensure the backup connection is removed first. |
2450 EXPECT_TRUE_SIMULATED_WAIT( | 2522 EXPECT_TRUE_SIMULATED_WAIT( |
2451 GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]) == nullptr, | 2523 GetConnectionWithLocalAddress(ep1_ch1(), cellular[0]) == nullptr, |
2452 kDefaultTimeout, clock); | 2524 kDefaultTimeout, clock); |
2453 const cricket::Connection* conn; | 2525 const cricket::Connection* conn; |
2454 EXPECT_TRUE_SIMULATED_WAIT( | 2526 EXPECT_TRUE_SIMULATED_WAIT( |
2455 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) != | 2527 (conn = GetConnectionWithLocalAddress(ep1_ch1(), cellular[0])) != |
2456 nullptr && | 2528 nullptr && |
2457 conn != ep1_ch1()->best_connection() && conn->writable(), | 2529 conn != ep1_ch1()->selected_connection() && conn->writable(), |
2458 5000, clock); | 2530 5000, clock); |
2459 | 2531 |
2460 DestroyChannels(); | 2532 DestroyChannels(); |
2461 } | 2533 } |
2462 | 2534 |
2463 // A collection of tests which tests a single P2PTransportChannel by sending | 2535 // A collection of tests which tests a single P2PTransportChannel by sending |
2464 // pings. | 2536 // pings. |
2465 class P2PTransportChannelPingTest : public testing::Test, | 2537 class P2PTransportChannelPingTest : public testing::Test, |
2466 public sigslot::has_slots<> { | 2538 public sigslot::has_slots<> { |
2467 public: | 2539 public: |
(...skipping 69 matching lines...) Loading... |
2537 int port, | 2609 int port, |
2538 int priority, | 2610 int priority, |
2539 bool writable) { | 2611 bool writable) { |
2540 channel.AddRemoteCandidate( | 2612 channel.AddRemoteCandidate( |
2541 CreateUdpCandidate(LOCAL_PORT_TYPE, ip_addr, port, priority)); | 2613 CreateUdpCandidate(LOCAL_PORT_TYPE, ip_addr, port, priority)); |
2542 EXPECT_TRUE_SIMULATED_WAIT( | 2614 EXPECT_TRUE_SIMULATED_WAIT( |
2543 GetConnectionTo(&channel, ip_addr, port) != nullptr, 3000, clock); | 2615 GetConnectionTo(&channel, ip_addr, port) != nullptr, 3000, clock); |
2544 Connection* conn = GetConnectionTo(&channel, ip_addr, port); | 2616 Connection* conn = GetConnectionTo(&channel, ip_addr, port); |
2545 | 2617 |
2546 if (conn && writable) { | 2618 if (conn && writable) { |
2547 conn->ReceivedPingResponse(LOW_RTT); // make it writable | 2619 conn->ReceivedPingResponse(LOW_RTT, "id"); // make it writable |
2548 } | 2620 } |
2549 return conn; | 2621 return conn; |
2550 } | 2622 } |
2551 | 2623 |
2552 void NominateConnection(Connection* conn) { | 2624 void NominateConnection(Connection* conn, uint32_t remote_nomination = 1U) { |
2553 conn->set_nominated(true); | 2625 conn->set_remote_nomination(remote_nomination); |
2554 conn->SignalNominated(conn); | 2626 conn->SignalNominated(conn); |
2555 } | 2627 } |
2556 | 2628 |
2557 void OnSelectedCandidatePairChanged( | 2629 void OnSelectedCandidatePairChanged( |
2558 TransportChannel* transport_channel, | 2630 TransportChannel* transport_channel, |
2559 CandidatePairInterface* selected_candidate_pair, | 2631 CandidatePairInterface* selected_candidate_pair, |
2560 int last_sent_packet_id, | 2632 int last_sent_packet_id, |
2561 bool ready_to_send) { | 2633 bool ready_to_send) { |
2562 last_selected_candidate_pair_ = selected_candidate_pair; | 2634 last_selected_candidate_pair_ = selected_candidate_pair; |
2563 last_sent_packet_id_ = last_sent_packet_id; | 2635 last_sent_packet_id_ = last_sent_packet_id; |
2564 ++selected_candidate_pair_switches_; | 2636 ++selected_candidate_pair_switches_; |
2565 } | 2637 } |
2566 | 2638 |
2567 void ReceivePingOnConnection(Connection* conn, | 2639 void ReceivePingOnConnection(Connection* conn, |
2568 const std::string& remote_ufrag, | 2640 const std::string& remote_ufrag, |
2569 int priority) { | 2641 int priority, |
| 2642 uint32_t nomination = 0) { |
2570 IceMessage msg; | 2643 IceMessage msg; |
2571 msg.SetType(STUN_BINDING_REQUEST); | 2644 msg.SetType(STUN_BINDING_REQUEST); |
2572 msg.AddAttribute(new StunByteStringAttribute( | 2645 msg.AddAttribute(new StunByteStringAttribute( |
2573 STUN_ATTR_USERNAME, | 2646 STUN_ATTR_USERNAME, |
2574 conn->local_candidate().username() + ":" + remote_ufrag)); | 2647 conn->local_candidate().username() + ":" + remote_ufrag)); |
2575 msg.AddAttribute(new StunUInt32Attribute(STUN_ATTR_PRIORITY, priority)); | 2648 msg.AddAttribute(new StunUInt32Attribute(STUN_ATTR_PRIORITY, priority)); |
| 2649 if (nomination != 0) { |
| 2650 msg.AddAttribute( |
| 2651 new StunUInt32Attribute(STUN_ATTR_NOMINATION, nomination)); |
| 2652 } |
2576 msg.SetTransactionID(rtc::CreateRandomString(kStunTransactionIdLength)); | 2653 msg.SetTransactionID(rtc::CreateRandomString(kStunTransactionIdLength)); |
2577 msg.AddMessageIntegrity(conn->local_candidate().password()); | 2654 msg.AddMessageIntegrity(conn->local_candidate().password()); |
2578 msg.AddFingerprint(); | 2655 msg.AddFingerprint(); |
2579 rtc::ByteBufferWriter buf; | 2656 rtc::ByteBufferWriter buf; |
2580 msg.Write(&buf); | 2657 msg.Write(&buf); |
2581 conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0)); | 2658 conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0)); |
2582 } | 2659 } |
2583 | 2660 |
2584 void OnReadyToSend(TransportChannel* channel) { | 2661 void OnReadyToSend(TransportChannel* channel) { |
2585 channel_ready_to_send_ = true; | 2662 channel_ready_to_send_ = true; |
(...skipping 58 matching lines...) Loading... |
2644 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); | 2721 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
2645 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); | 2722 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); |
2646 | 2723 |
2647 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2724 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2648 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2725 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2649 ASSERT_TRUE(conn1 != nullptr); | 2726 ASSERT_TRUE(conn1 != nullptr); |
2650 ASSERT_TRUE(conn2 != nullptr); | 2727 ASSERT_TRUE(conn2 != nullptr); |
2651 | 2728 |
2652 // Low-priority connection becomes writable so that the other connection | 2729 // Low-priority connection becomes writable so that the other connection |
2653 // is not pruned. | 2730 // is not pruned. |
2654 conn1->ReceivedPingResponse(LOW_RTT); | 2731 conn1->ReceivedPingResponse(LOW_RTT, "id"); |
2655 EXPECT_TRUE_WAIT( | 2732 EXPECT_TRUE_WAIT( |
2656 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL && | 2733 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL && |
2657 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, | 2734 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, |
2658 kDefaultTimeout); | 2735 kDefaultTimeout); |
2659 } | 2736 } |
2660 | 2737 |
2661 // Verify that the connections are pinged at the right time. | 2738 // Verify that the connections are pinged at the right time. |
2662 TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) { | 2739 TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) { |
2663 rtc::ScopedFakeClock clock; | 2740 rtc::ScopedFakeClock clock; |
2664 int RTT_RATIO = 4; | 2741 int RTT_RATIO = 4; |
(...skipping 15 matching lines...) Loading... |
2680 int64_t start = clock.TimeNanos(); | 2757 int64_t start = clock.TimeNanos(); |
2681 SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, | 2758 SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, |
2682 kDefaultTimeout, clock); | 2759 kDefaultTimeout, clock); |
2683 int64_t ping_interval_ms = (clock.TimeNanos() - start) / | 2760 int64_t ping_interval_ms = (clock.TimeNanos() - start) / |
2684 rtc::kNumNanosecsPerMillisec / | 2761 rtc::kNumNanosecsPerMillisec / |
2685 (MIN_PINGS_AT_WEAK_PING_INTERVAL - 1); | 2762 (MIN_PINGS_AT_WEAK_PING_INTERVAL - 1); |
2686 EXPECT_EQ(ping_interval_ms, WEAK_PING_INTERVAL); | 2763 EXPECT_EQ(ping_interval_ms, WEAK_PING_INTERVAL); |
2687 | 2764 |
2688 // Stabilizing. | 2765 // Stabilizing. |
2689 | 2766 |
2690 conn->ReceivedPingResponse(LOW_RTT); | 2767 conn->ReceivedPingResponse(LOW_RTT, "id"); |
2691 int ping_sent_before = conn->num_pings_sent(); | 2768 int ping_sent_before = conn->num_pings_sent(); |
2692 start = clock.TimeNanos(); | 2769 start = clock.TimeNanos(); |
2693 // The connection becomes strong but not stable because we haven't been able | 2770 // The connection becomes strong but not stable because we haven't been able |
2694 // to converge the RTT. | 2771 // to converge the RTT. |
2695 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); | 2772 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); |
2696 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; | 2773 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; |
2697 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); | 2774 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); |
2698 EXPECT_LE(ping_interval_ms, | 2775 EXPECT_LE(ping_interval_ms, |
2699 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); | 2776 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); |
2700 | 2777 |
2701 // Stabilized. | 2778 // Stabilized. |
2702 | 2779 |
2703 // The connection becomes stable after receiving more than RTT_RATIO rtt | 2780 // The connection becomes stable after receiving more than RTT_RATIO rtt |
2704 // samples. | 2781 // samples. |
2705 for (int i = 0; i < RTT_RATIO; i++) { | 2782 for (int i = 0; i < RTT_RATIO; i++) { |
2706 conn->ReceivedPingResponse(LOW_RTT); | 2783 conn->ReceivedPingResponse(LOW_RTT, "id"); |
2707 } | 2784 } |
2708 ping_sent_before = conn->num_pings_sent(); | 2785 ping_sent_before = conn->num_pings_sent(); |
2709 start = clock.TimeNanos(); | 2786 start = clock.TimeNanos(); |
2710 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); | 2787 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); |
2711 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; | 2788 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; |
2712 EXPECT_GE(ping_interval_ms, STABLE_WRITABLE_CONNECTION_PING_INTERVAL); | 2789 EXPECT_GE(ping_interval_ms, STABLE_WRITABLE_CONNECTION_PING_INTERVAL); |
2713 EXPECT_LE(ping_interval_ms, | 2790 EXPECT_LE(ping_interval_ms, |
2714 STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); | 2791 STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); |
2715 | 2792 |
2716 // Destabilized. | 2793 // Destabilized. |
2717 | 2794 |
2718 conn->ReceivedPingResponse(LOW_RTT); | 2795 conn->ReceivedPingResponse(LOW_RTT, "id"); |
2719 // Create a in-flight ping. | 2796 // Create a in-flight ping. |
2720 conn->Ping(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec); | 2797 conn->Ping(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec); |
2721 start = clock.TimeNanos(); | 2798 start = clock.TimeNanos(); |
2722 // In-flight ping timeout and the connection will be unstable. | 2799 // In-flight ping timeout and the connection will be unstable. |
2723 SIMULATED_WAIT( | 2800 SIMULATED_WAIT( |
2724 !conn->stable(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec), 3000, | 2801 !conn->stable(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec), 3000, |
2725 clock); | 2802 clock); |
2726 int64_t duration_ms = | 2803 int64_t duration_ms = |
2727 (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; | 2804 (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; |
2728 EXPECT_GE(duration_ms, 2 * conn->rtt() - RTT_RANGE); | 2805 EXPECT_GE(duration_ms, 2 * conn->rtt() - RTT_RANGE); |
(...skipping 61 matching lines...) Loading... |
2790 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); | 2867 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
2791 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); | 2868 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); |
2792 | 2869 |
2793 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2870 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2794 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2871 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2795 ASSERT_TRUE(conn1 != nullptr); | 2872 ASSERT_TRUE(conn1 != nullptr); |
2796 ASSERT_TRUE(conn2 != nullptr); | 2873 ASSERT_TRUE(conn2 != nullptr); |
2797 | 2874 |
2798 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); | 2875 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); |
2799 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); | 2876 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); |
2800 conn1->ReceivedPingResponse(LOW_RTT); | 2877 conn1->ReceivedPingResponse(LOW_RTT, "id"); |
2801 ASSERT_TRUE(conn1->writable()); | 2878 ASSERT_TRUE(conn1->writable()); |
2802 conn1->ReceivedPing(); | 2879 conn1->ReceivedPing(); |
2803 | 2880 |
2804 // Ping received, but the connection is already writable, so no | 2881 // Ping received, but the connection is already writable, so no |
2805 // "triggered check" and conn2 is pinged before conn1 because it has | 2882 // "triggered check" and conn2 is pinged before conn1 because it has |
2806 // a higher priority. | 2883 // a higher priority. |
2807 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); | 2884 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); |
2808 } | 2885 } |
2809 | 2886 |
2810 TEST_F(P2PTransportChannelPingTest, TestFailedConnectionNotPingable) { | 2887 TEST_F(P2PTransportChannelPingTest, TestFailedConnectionNotPingable) { |
(...skipping 96 matching lines...) Loading... |
2907 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2984 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2908 ASSERT_TRUE(conn1 != nullptr); | 2985 ASSERT_TRUE(conn1 != nullptr); |
2909 uint32_t remote_priority = conn1->remote_candidate().priority(); | 2986 uint32_t remote_priority = conn1->remote_candidate().priority(); |
2910 | 2987 |
2911 // Create a higher priority candidate and make the connection | 2988 // Create a higher priority candidate and make the connection |
2912 // receiving/writable. This will prune conn1. | 2989 // receiving/writable. This will prune conn1. |
2913 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); | 2990 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); |
2914 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2991 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2915 ASSERT_TRUE(conn2 != nullptr); | 2992 ASSERT_TRUE(conn2 != nullptr); |
2916 conn2->ReceivedPing(); | 2993 conn2->ReceivedPing(); |
2917 conn2->ReceivedPingResponse(LOW_RTT); | 2994 conn2->ReceivedPingResponse(LOW_RTT, "id"); |
2918 | 2995 |
2919 // Wait for conn1 to be pruned. | 2996 // Wait for conn1 to be pruned. |
2920 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); | 2997 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); |
2921 // Destroy the connection to test SignalUnknownAddress. | 2998 // Destroy the connection to test SignalUnknownAddress. |
2922 conn1->Destroy(); | 2999 conn1->Destroy(); |
2923 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000); | 3000 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000); |
2924 | 3001 |
2925 // Create a minimal STUN message with prflx priority. | 3002 // Create a minimal STUN message with prflx priority. |
2926 IceMessage request; | 3003 IceMessage request; |
2927 request.SetType(STUN_BINDING_REQUEST); | 3004 request.SetType(STUN_BINDING_REQUEST); |
(...skipping 80 matching lines...) Loading... |
3008 | 3085 |
3009 // If a stun request with use-candidate attribute arrives, the receiving | 3086 // If a stun request with use-candidate attribute arrives, the receiving |
3010 // connection will be set as the selected connection, even though | 3087 // connection will be set as the selected connection, even though |
3011 // its priority is lower. | 3088 // its priority is lower. |
3012 EXPECT_EQ(-1, SendData(ch, data, len, ++last_packet_id)); | 3089 EXPECT_EQ(-1, SendData(ch, data, len, ++last_packet_id)); |
3013 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); | 3090 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); |
3014 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 3091 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
3015 ASSERT_TRUE(conn3 != nullptr); | 3092 ASSERT_TRUE(conn3 != nullptr); |
3016 // Because it has a lower priority, the selected connection is still conn2. | 3093 // Because it has a lower priority, the selected connection is still conn2. |
3017 EXPECT_EQ(conn2, ch.selected_connection()); | 3094 EXPECT_EQ(conn2, ch.selected_connection()); |
3018 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. | 3095 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. |
3019 // But if it is nominated via use_candidate, it is chosen as the selected | 3096 // But if it is nominated via use_candidate, it is chosen as the selected |
3020 // connection. | 3097 // connection. |
3021 conn3->set_nominated(true); | 3098 NominateConnection(conn3); |
3022 conn3->SignalNominated(conn3); | |
3023 EXPECT_EQ(conn3, ch.selected_connection()); | 3099 EXPECT_EQ(conn3, ch.selected_connection()); |
3024 EXPECT_EQ(conn3, last_selected_candidate_pair()); | 3100 EXPECT_EQ(conn3, last_selected_candidate_pair()); |
3025 EXPECT_EQ(-1, last_sent_packet_id()); | 3101 EXPECT_EQ(-1, last_sent_packet_id()); |
3026 EXPECT_TRUE(channel_ready_to_send()); | 3102 EXPECT_TRUE(channel_ready_to_send()); |
3027 | 3103 |
3028 // Even if another higher priority candidate arrives, it will not be set as | 3104 // Even if another higher priority candidate arrives, it will not be set as |
3029 // the selected connection because the selected connection is nominated by | 3105 // the selected connection because the selected connection is nominated by |
3030 // the controlling side. | 3106 // the controlling side. |
3031 EXPECT_EQ(len, SendData(ch, data, len, ++last_packet_id)); | 3107 EXPECT_EQ(len, SendData(ch, data, len, ++last_packet_id)); |
3032 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100)); | 3108 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100)); |
3033 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); | 3109 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); |
3034 ASSERT_TRUE(conn4 != nullptr); | 3110 ASSERT_TRUE(conn4 != nullptr); |
3035 EXPECT_EQ(conn3, ch.selected_connection()); | 3111 EXPECT_EQ(conn3, ch.selected_connection()); |
3036 // But if it is nominated via use_candidate and writable, it will be set as | 3112 // But if it is nominated via use_candidate and writable, it will be set as |
3037 // the selected connection. | 3113 // the selected connection. |
3038 conn4->set_nominated(true); | 3114 NominateConnection(conn4); |
3039 conn4->SignalNominated(conn4); | |
3040 // Not switched yet because conn4 is not writable. | 3115 // Not switched yet because conn4 is not writable. |
3041 EXPECT_EQ(conn3, ch.selected_connection()); | 3116 EXPECT_EQ(conn3, ch.selected_connection()); |
3042 reset_channel_ready_to_send(); | 3117 reset_channel_ready_to_send(); |
3043 // The selected connection switches after conn4 becomes writable. | 3118 // The selected connection switches after conn4 becomes writable. |
3044 conn4->ReceivedPingResponse(LOW_RTT); | 3119 conn4->ReceivedPingResponse(LOW_RTT, "id"); |
3045 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); | 3120 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); |
3046 EXPECT_EQ(conn4, last_selected_candidate_pair()); | 3121 EXPECT_EQ(conn4, last_selected_candidate_pair()); |
3047 EXPECT_EQ(last_packet_id, last_sent_packet_id()); | 3122 EXPECT_EQ(last_packet_id, last_sent_packet_id()); |
3048 // SignalReadyToSend is fired again because conn4 is writable. | 3123 // SignalReadyToSend is fired again because conn4 is writable. |
3049 EXPECT_TRUE(channel_ready_to_send()); | 3124 EXPECT_TRUE(channel_ready_to_send()); |
3050 } | 3125 } |
3051 | 3126 |
3052 // The controlled side will select a connection as the "selected connection" | 3127 // The controlled side will select a connection as the "selected connection" |
3053 // based on requests from an unknown address before the controlling side | 3128 // based on requests from an unknown address before the controlling side |
3054 // nominates a connection, and will nominate a connection from an unknown | 3129 // nominates a connection, and will nominate a connection from an unknown |
(...skipping 14 matching lines...) Loading... |
3069 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; | 3144 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; |
3070 request.AddAttribute( | 3145 request.AddAttribute( |
3071 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); | 3146 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); |
3072 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch)); | 3147 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch)); |
3073 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, | 3148 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, |
3074 &request, kIceUfrag[1], false); | 3149 &request, kIceUfrag[1], false); |
3075 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3150 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
3076 ASSERT_TRUE(conn1 != nullptr); | 3151 ASSERT_TRUE(conn1 != nullptr); |
3077 EXPECT_TRUE(port->sent_binding_response()); | 3152 EXPECT_TRUE(port->sent_binding_response()); |
3078 EXPECT_EQ(conn1, ch.selected_connection()); | 3153 EXPECT_EQ(conn1, ch.selected_connection()); |
3079 conn1->ReceivedPingResponse(LOW_RTT); | 3154 conn1->ReceivedPingResponse(LOW_RTT, "id"); |
3080 EXPECT_EQ(conn1, ch.selected_connection()); | 3155 EXPECT_EQ(conn1, ch.selected_connection()); |
3081 port->set_sent_binding_response(false); | 3156 port->set_sent_binding_response(false); |
3082 | 3157 |
3083 // Another connection is nominated via use_candidate. | 3158 // Another connection is nominated via use_candidate. |
3084 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); | 3159 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); |
3085 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3160 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
3086 ASSERT_TRUE(conn2 != nullptr); | 3161 ASSERT_TRUE(conn2 != nullptr); |
3087 // Because it has a lower priority, the selected connection is still conn1. | 3162 // Because it has a lower priority, the selected connection is still conn1. |
3088 EXPECT_EQ(conn1, ch.selected_connection()); | 3163 EXPECT_EQ(conn1, ch.selected_connection()); |
3089 // When it is nominated via use_candidate and writable, it is chosen as the | 3164 // When it is nominated via use_candidate and writable, it is chosen as the |
3090 // selected connection. | 3165 // selected connection. |
3091 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. | 3166 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. |
3092 conn2->set_nominated(true); | 3167 NominateConnection(conn2); |
3093 conn2->SignalNominated(conn2); | |
3094 EXPECT_EQ(conn2, ch.selected_connection()); | 3168 EXPECT_EQ(conn2, ch.selected_connection()); |
3095 | 3169 |
3096 // Another request with unknown address, it will not be set as the selected | 3170 // Another request with unknown address, it will not be set as the selected |
3097 // connection because the selected connection was nominated by the controlling | 3171 // connection because the selected connection was nominated by the controlling |
3098 // side. | 3172 // side. |
3099 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP, | 3173 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP, |
3100 &request, kIceUfrag[1], false); | 3174 &request, kIceUfrag[1], false); |
3101 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 3175 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
3102 ASSERT_TRUE(conn3 != nullptr); | 3176 ASSERT_TRUE(conn3 != nullptr); |
3103 EXPECT_TRUE(port->sent_binding_response()); | 3177 EXPECT_TRUE(port->sent_binding_response()); |
3104 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. | 3178 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. |
3105 EXPECT_EQ(conn2, ch.selected_connection()); | 3179 EXPECT_EQ(conn2, ch.selected_connection()); |
3106 port->set_sent_binding_response(false); | 3180 port->set_sent_binding_response(false); |
3107 | 3181 |
3108 // However if the request contains use_candidate attribute, it will be | 3182 // However if the request contains use_candidate attribute, it will be |
3109 // selected as the selected connection. | 3183 // selected as the selected connection. |
3110 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); | 3184 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); |
3111 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), PROTO_UDP, | 3185 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), PROTO_UDP, |
3112 &request, kIceUfrag[1], false); | 3186 &request, kIceUfrag[1], false); |
3113 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); | 3187 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); |
3114 ASSERT_TRUE(conn4 != nullptr); | 3188 ASSERT_TRUE(conn4 != nullptr); |
3115 EXPECT_TRUE(port->sent_binding_response()); | 3189 EXPECT_TRUE(port->sent_binding_response()); |
3116 // conn4 is not the selected connection yet because it is not writable. | 3190 // conn4 is not the selected connection yet because it is not writable. |
3117 EXPECT_EQ(conn2, ch.selected_connection()); | 3191 EXPECT_EQ(conn2, ch.selected_connection()); |
3118 conn4->ReceivedPingResponse(LOW_RTT); // Become writable. | 3192 conn4->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. |
3119 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); | 3193 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); |
3120 | 3194 |
3121 // Test that the request from an unknown address contains a ufrag from an old | 3195 // Test that the request from an unknown address contains a ufrag from an old |
3122 // generation. | 3196 // generation. |
3123 port->set_sent_binding_response(false); | 3197 port->set_sent_binding_response(false); |
3124 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); | 3198 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); |
3125 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 3199 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
3126 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP, | 3200 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP, |
3127 &request, kIceUfrag[2], false); | 3201 &request, kIceUfrag[2], false); |
3128 Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); | 3202 Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); |
(...skipping 19 matching lines...) Loading... |
3148 | 3222 |
3149 // If a data packet is received on conn2, the selected connection should | 3223 // If a data packet is received on conn2, the selected connection should |
3150 // switch to conn2 because the controlled side must mirror the media path | 3224 // switch to conn2 because the controlled side must mirror the media path |
3151 // chosen by the controlling side. | 3225 // chosen by the controlling side. |
3152 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); | 3226 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); |
3153 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3227 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
3154 ASSERT_TRUE(conn2 != nullptr); | 3228 ASSERT_TRUE(conn2 != nullptr); |
3155 conn2->ReceivedPing(); // Start receiving. | 3229 conn2->ReceivedPing(); // Start receiving. |
3156 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 3230 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
3157 EXPECT_EQ(conn2, ch.selected_connection()); | 3231 EXPECT_EQ(conn2, ch.selected_connection()); |
3158 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. | 3232 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. |
3159 | 3233 |
3160 // Now another STUN message with an unknown address and use_candidate will | 3234 // Now another STUN message with an unknown address and use_candidate will |
3161 // nominate the selected connection. | 3235 // nominate the selected connection. |
3162 IceMessage request; | 3236 IceMessage request; |
3163 request.SetType(STUN_BINDING_REQUEST); | 3237 request.SetType(STUN_BINDING_REQUEST); |
3164 request.AddAttribute( | 3238 request.AddAttribute( |
3165 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); | 3239 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); |
3166 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; | 3240 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; |
3167 request.AddAttribute( | 3241 request.AddAttribute( |
3168 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); | 3242 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); |
3169 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); | 3243 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); |
3170 Port* port = GetPort(&ch); | 3244 Port* port = GetPort(&ch); |
3171 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP, | 3245 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP, |
3172 &request, kIceUfrag[1], false); | 3246 &request, kIceUfrag[1], false); |
3173 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 3247 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
3174 ASSERT_TRUE(conn3 != nullptr); | 3248 ASSERT_TRUE(conn3 != nullptr); |
3175 EXPECT_EQ(conn2, ch.selected_connection()); // Not writable yet. | 3249 EXPECT_EQ(conn2, ch.selected_connection()); // Not writable yet. |
3176 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. | 3250 conn3->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. |
3177 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); | 3251 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); |
3178 | 3252 |
3179 // Now another data packet will not switch the selected connection because the | 3253 // Now another data packet will not switch the selected connection because the |
3180 // selected connection was nominated by the controlling side. | 3254 // selected connection was nominated by the controlling side. |
3181 conn2->ReceivedPing(); | 3255 conn2->ReceivedPing(); |
3182 conn2->ReceivedPingResponse(LOW_RTT); | 3256 conn2->ReceivedPingResponse(LOW_RTT, "id"); |
3183 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 3257 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
3184 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); | 3258 EXPECT_EQ_WAIT(conn3, ch.selected_connection(), kDefaultTimeout); |
3185 } | 3259 } |
3186 | 3260 |
3187 TEST_F(P2PTransportChannelPingTest, | 3261 TEST_F(P2PTransportChannelPingTest, |
3188 TestControlledAgentDataReceivingTakesHigherPrecedenceThanPriority) { | 3262 TestControlledAgentDataReceivingTakesHigherPrecedenceThanPriority) { |
3189 rtc::ScopedFakeClock clock; | 3263 rtc::ScopedFakeClock clock; |
3190 | 3264 |
3191 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3265 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3192 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); | 3266 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); |
(...skipping 69 matching lines...) Loading... |
3262 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 3336 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
3263 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); | 3337 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
3264 EXPECT_EQ(conn2, last_selected_candidate_pair()); | 3338 EXPECT_EQ(conn2, last_selected_candidate_pair()); |
3265 | 3339 |
3266 // Make sure sorting won't reselect candidate pair. | 3340 // Make sure sorting won't reselect candidate pair. |
3267 SIMULATED_WAIT(false, 10, clock); | 3341 SIMULATED_WAIT(false, 10, clock); |
3268 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); | 3342 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); |
3269 } | 3343 } |
3270 | 3344 |
3271 TEST_F(P2PTransportChannelPingTest, | 3345 TEST_F(P2PTransportChannelPingTest, |
| 3346 TestControlledAgentSelectsConnectionWithHigherNomination) { |
| 3347 rtc::ScopedFakeClock clock; |
| 3348 |
| 3349 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 3350 P2PTransportChannel ch("test", 1, &pa); |
| 3351 PrepareChannel(&ch); |
| 3352 ch.SetIceRole(ICEROLE_CONTROLLED); |
| 3353 ch.MaybeStartGathering(); |
| 3354 // The connections have decreasing priority. |
| 3355 Connection* conn1 = |
| 3356 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); |
| 3357 ASSERT_TRUE(conn1 != nullptr); |
| 3358 Connection* conn2 = |
| 3359 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); |
| 3360 ASSERT_TRUE(conn2 != nullptr); |
| 3361 |
| 3362 // conn1 is the selected connection because it has a higher priority, |
| 3363 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(), |
| 3364 kDefaultTimeout, clock); |
| 3365 reset_selected_candidate_pair_switches(); |
| 3366 |
| 3367 // conn2 is nominated; it becomes selected. |
| 3368 NominateConnection(conn2); |
| 3369 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
| 3370 EXPECT_EQ(conn2, last_selected_candidate_pair()); |
| 3371 |
| 3372 // conn1 is selected because of its priority. |
| 3373 NominateConnection(conn1); |
| 3374 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
| 3375 EXPECT_EQ(conn1, last_selected_candidate_pair()); |
| 3376 |
| 3377 // conn2 gets higher remote nomination; it is selected again. |
| 3378 NominateConnection(conn2, 2U); |
| 3379 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
| 3380 EXPECT_EQ(conn2, last_selected_candidate_pair()); |
| 3381 |
| 3382 // Make sure sorting won't reselect candidate pair. |
| 3383 SIMULATED_WAIT(false, 100, clock); |
| 3384 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); |
| 3385 } |
| 3386 |
| 3387 TEST_F(P2PTransportChannelPingTest, |
| 3388 TestControlledAgentIgnoresSmallerNomination) { |
| 3389 rtc::ScopedFakeClock clock; |
| 3390 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 3391 P2PTransportChannel ch("test", 1, &pa); |
| 3392 PrepareChannel(&ch); |
| 3393 ch.SetIceRole(ICEROLE_CONTROLLED); |
| 3394 ch.MaybeStartGathering(); |
| 3395 Connection* conn = |
| 3396 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); |
| 3397 ReceivePingOnConnection(conn, kIceUfrag[1], 1, 2U); |
| 3398 EXPECT_EQ(2U, conn->remote_nomination()); |
| 3399 // Smaller nomination is ignored. |
| 3400 ReceivePingOnConnection(conn, kIceUfrag[1], 1, 1U); |
| 3401 EXPECT_EQ(2U, conn->remote_nomination()); |
| 3402 } |
| 3403 |
| 3404 TEST_F(P2PTransportChannelPingTest, |
3272 TestControlledAgentWriteStateTakesHigherPrecedenceThanNomination) { | 3405 TestControlledAgentWriteStateTakesHigherPrecedenceThanNomination) { |
3273 rtc::ScopedFakeClock clock; | 3406 rtc::ScopedFakeClock clock; |
3274 | 3407 |
3275 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3408 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3276 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); | 3409 P2PTransportChannel ch("SwitchSelectedConnection", 1, &pa); |
3277 PrepareChannel(&ch); | 3410 PrepareChannel(&ch); |
3278 ch.SetIceRole(ICEROLE_CONTROLLED); | 3411 ch.SetIceRole(ICEROLE_CONTROLLED); |
3279 ch.MaybeStartGathering(); | 3412 ch.MaybeStartGathering(); |
3280 // The connections have decreasing priority. | 3413 // The connections have decreasing priority. |
3281 Connection* conn1 = | 3414 Connection* conn1 = |
3282 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); | 3415 CreateConnectionWithCandidate(ch, clock, "1.1.1.1", 1, 10, false); |
3283 ASSERT_TRUE(conn1 != nullptr); | 3416 ASSERT_TRUE(conn1 != nullptr); |
3284 Connection* conn2 = | 3417 Connection* conn2 = |
3285 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); | 3418 CreateConnectionWithCandidate(ch, clock, "2.2.2.2", 2, 9, false); |
3286 ASSERT_TRUE(conn2 != nullptr); | 3419 ASSERT_TRUE(conn2 != nullptr); |
3287 | 3420 |
3288 NominateConnection(conn1); | 3421 NominateConnection(conn1); |
3289 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); | 3422 EXPECT_EQ(1, reset_selected_candidate_pair_switches()); |
3290 | 3423 |
3291 // conn2 becomes writable; it is selected even though it is not nominated. | 3424 // conn2 becomes writable; it is selected even though it is not nominated. |
3292 conn2->ReceivedPingResponse(LOW_RTT); | 3425 conn2->ReceivedPingResponse(LOW_RTT, "id"); |
3293 | 3426 |
3294 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), | 3427 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), |
3295 kDefaultTimeout, clock); | 3428 kDefaultTimeout, clock); |
3296 EXPECT_EQ_SIMULATED_WAIT(conn2, last_selected_candidate_pair(), | 3429 EXPECT_EQ_SIMULATED_WAIT(conn2, last_selected_candidate_pair(), |
3297 kDefaultTimeout, clock); | 3430 kDefaultTimeout, clock); |
3298 | 3431 |
3299 // If conn1 is also writable, it will become selected. | 3432 // If conn1 is also writable, it will become selected. |
3300 conn1->ReceivedPingResponse(LOW_RTT); | 3433 conn1->ReceivedPingResponse(LOW_RTT, "id"); |
3301 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), | 3434 EXPECT_EQ_SIMULATED_WAIT(1, reset_selected_candidate_pair_switches(), |
3302 kDefaultTimeout, clock); | 3435 kDefaultTimeout, clock); |
3303 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(), | 3436 EXPECT_EQ_SIMULATED_WAIT(conn1, last_selected_candidate_pair(), |
3304 kDefaultTimeout, clock); | 3437 kDefaultTimeout, clock); |
3305 | 3438 |
3306 // Make sure sorting won't reselect candidate pair. | 3439 // Make sure sorting won't reselect candidate pair. |
3307 SIMULATED_WAIT(false, 10, clock); | 3440 SIMULATED_WAIT(false, 10, clock); |
3308 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); | 3441 EXPECT_EQ(0, reset_selected_candidate_pair_switches()); |
3309 } | 3442 } |
3310 | 3443 |
(...skipping 40 matching lines...) Loading... |
3351 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { | 3484 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { |
3352 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3485 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3353 P2PTransportChannel ch("test channel", 1, &pa); | 3486 P2PTransportChannel ch("test channel", 1, &pa); |
3354 PrepareChannel(&ch); | 3487 PrepareChannel(&ch); |
3355 ch.SetIceRole(ICEROLE_CONTROLLED); | 3488 ch.SetIceRole(ICEROLE_CONTROLLED); |
3356 ch.MaybeStartGathering(); | 3489 ch.MaybeStartGathering(); |
3357 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); | 3490 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
3358 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3491 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
3359 ASSERT_TRUE(conn1 != nullptr); | 3492 ASSERT_TRUE(conn1 != nullptr); |
3360 EXPECT_EQ(conn1, ch.selected_connection()); | 3493 EXPECT_EQ(conn1, ch.selected_connection()); |
3361 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 3494 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving |
3362 | 3495 |
3363 // When a higher-priority, nominated candidate comes in, the connections with | 3496 // When a higher-priority, nominated candidate comes in, the connections with |
3364 // lower-priority are pruned. | 3497 // lower-priority are pruned. |
3365 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); | 3498 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); |
3366 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3499 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
3367 ASSERT_TRUE(conn2 != nullptr); | 3500 ASSERT_TRUE(conn2 != nullptr); |
3368 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 3501 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving |
3369 conn2->set_nominated(true); | 3502 NominateConnection(conn2); |
3370 conn2->SignalNominated(conn2); | |
3371 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); | 3503 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); |
3372 | 3504 |
3373 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); | 3505 ch.SetIceConfig(CreateIceConfig(500, GATHER_ONCE)); |
3374 // Wait until conn2 becomes not receiving. | 3506 // Wait until conn2 becomes not receiving. |
3375 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); | 3507 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); |
3376 | 3508 |
3377 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); | 3509 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); |
3378 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 3510 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
3379 ASSERT_TRUE(conn3 != nullptr); | 3511 ASSERT_TRUE(conn3 != nullptr); |
3380 // The selected connection should still be conn2. Even through conn3 has lower | 3512 // The selected connection should still be conn2. Even through conn3 has lower |
(...skipping 34 matching lines...) Loading... |
3415 EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState()); | 3547 EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState()); |
3416 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); | 3548 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); |
3417 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); | 3549 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); |
3418 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3550 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
3419 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3551 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
3420 ASSERT_TRUE(conn1 != nullptr); | 3552 ASSERT_TRUE(conn1 != nullptr); |
3421 ASSERT_TRUE(conn2 != nullptr); | 3553 ASSERT_TRUE(conn2 != nullptr); |
3422 // Now there are two connections, so the transport channel is connecting. | 3554 // Now there are two connections, so the transport channel is connecting. |
3423 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); | 3555 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); |
3424 // |conn1| becomes writable and receiving; it then should prune |conn2|. | 3556 // |conn1| becomes writable and receiving; it then should prune |conn2|. |
3425 conn1->ReceivedPingResponse(LOW_RTT); | 3557 conn1->ReceivedPingResponse(LOW_RTT, "id"); |
3426 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); | 3558 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); |
3427 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); | 3559 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); |
3428 conn1->Prune(); // All connections are pruned. | 3560 conn1->Prune(); // All connections are pruned. |
3429 // Need to wait until the channel state is updated. | 3561 // Need to wait until the channel state is updated. |
3430 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); | 3562 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); |
3431 } | 3563 } |
3432 | 3564 |
3433 // Test that when a low-priority connection is pruned, it is not deleted | 3565 // Test that when a low-priority connection is pruned, it is not deleted |
3434 // right away, and it can become active and be pruned again. | 3566 // right away, and it can become active and be pruned again. |
3435 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { | 3567 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { |
3436 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3568 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3437 P2PTransportChannel ch("test channel", 1, &pa); | 3569 P2PTransportChannel ch("test channel", 1, &pa); |
3438 PrepareChannel(&ch); | 3570 PrepareChannel(&ch); |
3439 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); | 3571 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); |
3440 config.receiving_switching_delay = rtc::Optional<int>(800); | 3572 config.receiving_switching_delay = rtc::Optional<int>(800); |
3441 ch.SetIceConfig(config); | 3573 ch.SetIceConfig(config); |
3442 ch.MaybeStartGathering(); | 3574 ch.MaybeStartGathering(); |
3443 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); | 3575 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); |
3444 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3576 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
3445 ASSERT_TRUE(conn1 != nullptr); | 3577 ASSERT_TRUE(conn1 != nullptr); |
3446 EXPECT_EQ(conn1, ch.selected_connection()); | 3578 EXPECT_EQ(conn1, ch.selected_connection()); |
3447 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 3579 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving |
3448 | 3580 |
3449 // Add a low-priority connection |conn2|, which will be pruned, but it will | 3581 // Add a low-priority connection |conn2|, which will be pruned, but it will |
3450 // not be deleted right away. Once the current selected connection becomes not | 3582 // not be deleted right away. Once the current selected connection becomes not |
3451 // receiving, |conn2| will start to ping and upon receiving the ping response, | 3583 // receiving, |conn2| will start to ping and upon receiving the ping response, |
3452 // it will become the selected connection. | 3584 // it will become the selected connection. |
3453 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); | 3585 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); |
3454 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3586 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
3455 ASSERT_TRUE(conn2 != nullptr); | 3587 ASSERT_TRUE(conn2 != nullptr); |
3456 EXPECT_TRUE_WAIT(!conn2->active(), 1000); | 3588 EXPECT_TRUE_WAIT(!conn2->active(), 1000); |
3457 // |conn2| should not send a ping yet. | 3589 // |conn2| should not send a ping yet. |
3458 EXPECT_EQ(Connection::STATE_WAITING, conn2->state()); | 3590 EXPECT_EQ(Connection::STATE_WAITING, conn2->state()); |
3459 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); | 3591 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); |
3460 // Wait for |conn1| becoming not receiving. | 3592 // Wait for |conn1| becoming not receiving. |
3461 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); | 3593 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); |
3462 // Make sure conn2 is not deleted. | 3594 // Make sure conn2 is not deleted. |
3463 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3595 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
3464 ASSERT_TRUE(conn2 != nullptr); | 3596 ASSERT_TRUE(conn2 != nullptr); |
3465 EXPECT_EQ_WAIT(Connection::STATE_INPROGRESS, conn2->state(), 1000); | 3597 EXPECT_EQ_WAIT(Connection::STATE_INPROGRESS, conn2->state(), 1000); |
3466 conn2->ReceivedPingResponse(LOW_RTT); | 3598 conn2->ReceivedPingResponse(LOW_RTT, "id"); |
3467 EXPECT_EQ_WAIT(conn2, ch.selected_connection(), 1000); | 3599 EXPECT_EQ_WAIT(conn2, ch.selected_connection(), 1000); |
3468 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); | 3600 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); |
3469 | 3601 |
3470 // When |conn1| comes back again, |conn2| will be pruned again. | 3602 // When |conn1| comes back again, |conn2| will be pruned again. |
3471 conn1->ReceivedPingResponse(LOW_RTT); | 3603 conn1->ReceivedPingResponse(LOW_RTT, "id"); |
3472 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), 1000); | 3604 EXPECT_EQ_WAIT(conn1, ch.selected_connection(), 1000); |
3473 EXPECT_TRUE_WAIT(!conn2->active(), 1000); | 3605 EXPECT_TRUE_WAIT(!conn2->active(), 1000); |
3474 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); | 3606 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); |
3475 } | 3607 } |
3476 | 3608 |
3477 // Test that if all connections in a channel has timed out on writing, they | 3609 // Test that if all connections in a channel has timed out on writing, they |
3478 // will all be deleted. We use Prune to simulate write_time_out. | 3610 // will all be deleted. We use Prune to simulate write_time_out. |
3479 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { | 3611 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { |
3480 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3612 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3481 P2PTransportChannel ch("test channel", 1, &pa); | 3613 P2PTransportChannel ch("test channel", 1, &pa); |
(...skipping 28 matching lines...) Loading... |
3510 // the current port allocator session. | 3642 // the current port allocator session. |
3511 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { | 3643 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { |
3512 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3644 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3513 P2PTransportChannel ch("test channel", 1, &pa); | 3645 P2PTransportChannel ch("test channel", 1, &pa); |
3514 PrepareChannel(&ch); | 3646 PrepareChannel(&ch); |
3515 ch.SetIceConfig(CreateIceConfig(2000, GATHER_ONCE)); | 3647 ch.SetIceConfig(CreateIceConfig(2000, GATHER_ONCE)); |
3516 ch.MaybeStartGathering(); | 3648 ch.MaybeStartGathering(); |
3517 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); | 3649 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); |
3518 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3650 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
3519 ASSERT_TRUE(conn1 != nullptr); | 3651 ASSERT_TRUE(conn1 != nullptr); |
3520 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 3652 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving |
3521 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 3653 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
3522 | 3654 |
3523 // Start a new session. Even though conn1, which belongs to an older | 3655 // Start a new session. Even though conn1, which belongs to an older |
3524 // session, becomes unwritable and writable again, it should not stop the | 3656 // session, becomes unwritable and writable again, it should not stop the |
3525 // current session. | 3657 // current session. |
3526 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); | 3658 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); |
3527 ch.MaybeStartGathering(); | 3659 ch.MaybeStartGathering(); |
3528 conn1->Prune(); | 3660 conn1->Prune(); |
3529 conn1->ReceivedPingResponse(LOW_RTT); | 3661 conn1->ReceivedPingResponse(LOW_RTT, "id"); |
3530 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); | 3662 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); |
3531 | 3663 |
3532 // But if a new connection created from the new session becomes writable, | 3664 // But if a new connection created from the new session becomes writable, |
3533 // it will stop the current session. | 3665 // it will stop the current session. |
3534 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100)); | 3666 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100)); |
3535 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3667 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
3536 ASSERT_TRUE(conn2 != nullptr); | 3668 ASSERT_TRUE(conn2 != nullptr); |
3537 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving | 3669 conn2->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving |
3538 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 3670 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
3539 } | 3671 } |
3540 | 3672 |
3541 // Test that the ICE role is updated even on ports that has been removed. | 3673 // Test that the ICE role is updated even on ports that has been removed. |
3542 // These ports may still have connections that need a correct role, in case that | 3674 // These ports may still have connections that need a correct role, in case that |
3543 // the connections on it may still receive stun pings. | 3675 // the connections on it may still receive stun pings. |
3544 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnRemovedPort) { | 3676 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnRemovedPort) { |
3545 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 3677 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
3546 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); | 3678 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); |
3547 // Starts with ICEROLE_CONTROLLING. | 3679 // Starts with ICEROLE_CONTROLLING. |
(...skipping 152 matching lines...) Loading... |
3700 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3832 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
3701 EXPECT_EQ(conn2->local_candidate().type(), LOCAL_PORT_TYPE); | 3833 EXPECT_EQ(conn2->local_candidate().type(), LOCAL_PORT_TYPE); |
3702 EXPECT_EQ(conn2->remote_candidate().type(), LOCAL_PORT_TYPE); | 3834 EXPECT_EQ(conn2->remote_candidate().type(), LOCAL_PORT_TYPE); |
3703 conn2->ReceivedPing(); | 3835 conn2->ReceivedPing(); |
3704 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); | 3836 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); |
3705 | 3837 |
3706 // Make conn3 the selected connection. | 3838 // Make conn3 the selected connection. |
3707 Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3839 Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
3708 EXPECT_EQ(conn3->local_candidate().type(), LOCAL_PORT_TYPE); | 3840 EXPECT_EQ(conn3->local_candidate().type(), LOCAL_PORT_TYPE); |
3709 EXPECT_EQ(conn3->remote_candidate().type(), RELAY_PORT_TYPE); | 3841 EXPECT_EQ(conn3->remote_candidate().type(), RELAY_PORT_TYPE); |
3710 conn3->ReceivedPingResponse(LOW_RTT); | 3842 conn3->ReceivedPingResponse(LOW_RTT, "id"); |
3711 ASSERT_TRUE(conn3->writable()); | 3843 ASSERT_TRUE(conn3->writable()); |
3712 conn3->ReceivedPing(); | 3844 conn3->ReceivedPing(); |
3713 | 3845 |
3714 /* | 3846 /* |
3715 | 3847 |
3716 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix | 3848 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix |
3717 the flakiness. The following test becomes flaky because we now ping the | 3849 the flakiness. The following test becomes flaky because we now ping the |
3718 connections with fast rates until every connection is pinged at least three | 3850 connections with fast rates until every connection is pinged at least three |
3719 times. The selected connection may have been pinged before | 3851 times. The selected connection may have been pinged before |
3720 |max_strong_interval|, so it may not be the next connection to be pinged as | 3852 |max_strong_interval|, so it may not be the next connection to be pinged as |
3721 expected in the test. | 3853 expected in the test. |
3722 | 3854 |
3723 // Verify that conn3 will be the "selected connection" since it is readable | 3855 // Verify that conn3 will be the "selected connection" since it is readable |
3724 // and writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next | 3856 // and writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next |
3725 // pingable connection. | 3857 // pingable connection. |
3726 EXPECT_TRUE_WAIT(conn3 == ch.selected_connection(), 5000); | 3858 EXPECT_TRUE_WAIT(conn3 == ch.selected_connection(), 5000); |
3727 WAIT(false, max_strong_interval + 100); | 3859 WAIT(false, max_strong_interval + 100); |
3728 conn3->ReceivedPingResponse(LOW_RTT); | 3860 conn3->ReceivedPingResponse(LOW_RTT, "id"); |
3729 ASSERT_TRUE(conn3->writable()); | 3861 ASSERT_TRUE(conn3->writable()); |
3730 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); | 3862 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); |
3731 | 3863 |
3732 */ | 3864 */ |
3733 } | 3865 } |
3734 | 3866 |
3735 // Test that Relay/Relay connections will be pinged first when everything has | 3867 // Test that Relay/Relay connections will be pinged first when everything has |
3736 // been pinged even if the Relay/Relay connection wasn't the first to be pinged | 3868 // been pinged even if the Relay/Relay connection wasn't the first to be pinged |
3737 // in the first round. | 3869 // in the first round. |
3738 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, | 3870 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, |
(...skipping 83 matching lines...) Loading... |
3822 | 3954 |
3823 // TCP Relay/Relay is the next. | 3955 // TCP Relay/Relay is the next. |
3824 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, | 3956 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, |
3825 TCP_PROTOCOL_NAME); | 3957 TCP_PROTOCOL_NAME); |
3826 | 3958 |
3827 // Finally, Local/Relay will be pinged. | 3959 // Finally, Local/Relay will be pinged. |
3828 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); | 3960 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
3829 } | 3961 } |
3830 | 3962 |
3831 } // namespace cricket { | 3963 } // namespace cricket { |
OLD | NEW |