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 82 matching lines...) Loading... |
93 "TESTICEPWD00000000000002", | 93 "TESTICEPWD00000000000002", |
94 "TESTICEPWD00000000000003"}; | 94 "TESTICEPWD00000000000003"}; |
95 | 95 |
96 static const uint64 kTiebreaker1 = 11111; | 96 static const uint64 kTiebreaker1 = 11111; |
97 static const uint64 kTiebreaker2 = 22222; | 97 static const uint64 kTiebreaker2 = 22222; |
98 | 98 |
99 enum { | 99 enum { |
100 MSG_CANDIDATE | 100 MSG_CANDIDATE |
101 }; | 101 }; |
102 | 102 |
| 103 static cricket::IceConfig CreateIceConfig(int receiving_timeout_ms, |
| 104 bool gather_continually) { |
| 105 cricket::IceConfig config; |
| 106 config.receiving_timeout_ms = receiving_timeout_ms; |
| 107 config.gather_continually = gather_continually; |
| 108 return config; |
| 109 } |
| 110 |
103 // This test simulates 2 P2P endpoints that want to establish connectivity | 111 // This test simulates 2 P2P endpoints that want to establish connectivity |
104 // with each other over various network topologies and conditions, which can be | 112 // with each other over various network topologies and conditions, which can be |
105 // specified in each individial test. | 113 // specified in each individial test. |
106 // A virtual network (via VirtualSocketServer) along with virtual firewalls and | 114 // A virtual network (via VirtualSocketServer) along with virtual firewalls and |
107 // NATs (via Firewall/NATSocketServer) are used to simulate the various network | 115 // NATs (via Firewall/NATSocketServer) are used to simulate the various network |
108 // conditions. We can configure the IP addresses of the endpoints, | 116 // conditions. We can configure the IP addresses of the endpoints, |
109 // block various types of connectivity, or add arbitrary levels of NAT. | 117 // block various types of connectivity, or add arbitrary levels of NAT. |
110 // We also run a STUN server and a relay server on the virtual network to allow | 118 // We also run a STUN server and a relay server on the virtual network to allow |
111 // our typical P2P mechanisms to do their thing. | 119 // our typical P2P mechanisms to do their thing. |
112 // For each case, we expect the P2P stack to eventually settle on a specific | 120 // For each case, we expect the P2P stack to eventually settle on a specific |
(...skipping 266 matching lines...) Loading... |
379 } | 387 } |
380 bool GetRoleConflict(int endpoint) { | 388 bool GetRoleConflict(int endpoint) { |
381 return GetEndpoint(endpoint)->role_conflict(); | 389 return GetEndpoint(endpoint)->role_conflict(); |
382 } | 390 } |
383 void SetAllocationStepDelay(int endpoint, uint32 delay) { | 391 void SetAllocationStepDelay(int endpoint, uint32 delay) { |
384 return GetEndpoint(endpoint)->SetAllocationStepDelay(delay); | 392 return GetEndpoint(endpoint)->SetAllocationStepDelay(delay); |
385 } | 393 } |
386 void SetAllowTcpListen(int endpoint, bool allow_tcp_listen) { | 394 void SetAllowTcpListen(int endpoint, bool allow_tcp_listen) { |
387 return GetEndpoint(endpoint)->SetAllowTcpListen(allow_tcp_listen); | 395 return GetEndpoint(endpoint)->SetAllowTcpListen(allow_tcp_listen); |
388 } | 396 } |
389 | |
390 bool IsLocalToPrflxOrTheReverse(const Result& expected) { | 397 bool IsLocalToPrflxOrTheReverse(const Result& expected) { |
391 return ( | 398 return ( |
392 (expected.local_type == "local" && expected.remote_type == "prflx") || | 399 (expected.local_type == "local" && expected.remote_type == "prflx") || |
393 (expected.local_type == "prflx" && expected.remote_type == "local")); | 400 (expected.local_type == "prflx" && expected.remote_type == "local")); |
394 } | 401 } |
395 | 402 |
396 // Return true if the approprite parts of the expected Result, based | 403 // Return true if the approprite parts of the expected Result, based |
397 // on the local and remote candidate of ep1_ch1, match. This can be | 404 // on the local and remote candidate of ep1_ch1, match. This can be |
398 // used in an EXPECT_TRUE_WAIT. | 405 // used in an EXPECT_TRUE_WAIT. |
399 bool CheckCandidate1(const Result& expected) { | 406 bool CheckCandidate1(const Result& expected) { |
(...skipping 1091 matching lines...) Loading... |
1491 AddAddress(1, kPublicAddrs[1]); | 1498 AddAddress(1, kPublicAddrs[1]); |
1492 | 1499 |
1493 // Use only local ports for simplicity. | 1500 // Use only local ports for simplicity. |
1494 SetAllocatorFlags(0, kOnlyLocalPorts); | 1501 SetAllocatorFlags(0, kOnlyLocalPorts); |
1495 SetAllocatorFlags(1, kOnlyLocalPorts); | 1502 SetAllocatorFlags(1, kOnlyLocalPorts); |
1496 | 1503 |
1497 // Create channels and let them go writable, as usual. | 1504 // Create channels and let them go writable, as usual. |
1498 CreateChannels(1); | 1505 CreateChannels(1); |
1499 | 1506 |
1500 // Make the receiving timeout shorter for testing. | 1507 // Make the receiving timeout shorter for testing. |
1501 ep1_ch1()->SetReceivingTimeout(1000); | 1508 cricket::IceConfig config = CreateIceConfig(1000, false); |
1502 ep2_ch1()->SetReceivingTimeout(1000); | 1509 ep1_ch1()->SetIceConfig(config); |
| 1510 ep2_ch1()->SetIceConfig(config); |
1503 | 1511 |
1504 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1512 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1505 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1513 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1506 1000); | 1514 1000); |
1507 EXPECT_TRUE( | 1515 EXPECT_TRUE( |
1508 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1516 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
1509 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1517 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1510 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1518 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1511 | 1519 |
1512 // Blackhole any traffic to or from the public addrs. | 1520 // Blackhole any traffic to or from the public addrs. |
(...skipping 29 matching lines...) Loading... |
1542 AddAddress(0, kPublicAddrs[0]); | 1550 AddAddress(0, kPublicAddrs[0]); |
1543 AddAddress(1, kPublicAddrs[1]); | 1551 AddAddress(1, kPublicAddrs[1]); |
1544 | 1552 |
1545 // Use only local ports for simplicity. | 1553 // Use only local ports for simplicity. |
1546 SetAllocatorFlags(0, kOnlyLocalPorts); | 1554 SetAllocatorFlags(0, kOnlyLocalPorts); |
1547 SetAllocatorFlags(1, kOnlyLocalPorts); | 1555 SetAllocatorFlags(1, kOnlyLocalPorts); |
1548 | 1556 |
1549 // Create channels and let them go writable, as usual. | 1557 // Create channels and let them go writable, as usual. |
1550 CreateChannels(1); | 1558 CreateChannels(1); |
1551 // Make the receiving timeout shorter for testing. | 1559 // Make the receiving timeout shorter for testing. |
1552 ep1_ch1()->SetReceivingTimeout(1000); | 1560 cricket::IceConfig config = CreateIceConfig(1000, false); |
1553 ep2_ch1()->SetReceivingTimeout(1000); | 1561 ep1_ch1()->SetIceConfig(config); |
| 1562 ep2_ch1()->SetIceConfig(config); |
1554 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1563 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1555 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1564 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1556 1000); | 1565 1000); |
1557 EXPECT_TRUE( | 1566 EXPECT_TRUE( |
1558 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1567 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
1559 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1568 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
1560 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1569 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
1561 | 1570 |
1562 // Blackhole any traffic to or from the public addrs. | 1571 // Blackhole any traffic to or from the public addrs. |
1563 LOG(LS_INFO) << "Failing over..."; | 1572 LOG(LS_INFO) << "Failing over..."; |
(...skipping 225 matching lines...) Loading... |
1789 } | 1798 } |
1790 | 1799 |
1791 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { | 1800 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { |
1792 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1801 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
1793 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); | 1802 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); |
1794 PrepareChannel(&ch); | 1803 PrepareChannel(&ch); |
1795 // Default receiving timeout and checking receiving delay should not be too | 1804 // Default receiving timeout and checking receiving delay should not be too |
1796 // small. | 1805 // small. |
1797 EXPECT_LE(1000, ch.receiving_timeout()); | 1806 EXPECT_LE(1000, ch.receiving_timeout()); |
1798 EXPECT_LE(200, ch.check_receiving_delay()); | 1807 EXPECT_LE(200, ch.check_receiving_delay()); |
1799 ch.SetReceivingTimeout(500); | 1808 ch.SetIceConfig(CreateIceConfig(500, false)); |
1800 EXPECT_EQ(500, ch.receiving_timeout()); | 1809 EXPECT_EQ(500, ch.receiving_timeout()); |
1801 EXPECT_EQ(50, ch.check_receiving_delay()); | 1810 EXPECT_EQ(50, ch.check_receiving_delay()); |
1802 ch.Connect(); | 1811 ch.Connect(); |
1803 ch.MaybeStartGathering(); | 1812 ch.MaybeStartGathering(); |
1804 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1813 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
1805 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1814 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
1806 ASSERT_TRUE(conn1 != nullptr); | 1815 ASSERT_TRUE(conn1 != nullptr); |
1807 | 1816 |
1808 conn1->ReceivedPing(); | 1817 conn1->ReceivedPing(); |
1809 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 1818 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
(...skipping 201 matching lines...) Loading... |
2011 // When a higher-priority, nominated candidate comes in, the connections with | 2020 // When a higher-priority, nominated candidate comes in, the connections with |
2012 // lower-priority are pruned. | 2021 // lower-priority are pruned. |
2013 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 10)); | 2022 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 10)); |
2014 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2023 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2015 ASSERT_TRUE(conn2 != nullptr); | 2024 ASSERT_TRUE(conn2 != nullptr); |
2016 conn2->ReceivedPingResponse(); // Becomes writable and receiving | 2025 conn2->ReceivedPingResponse(); // Becomes writable and receiving |
2017 conn2->set_nominated(true); | 2026 conn2->set_nominated(true); |
2018 conn2->SignalNominated(conn2); | 2027 conn2->SignalNominated(conn2); |
2019 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); | 2028 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); |
2020 | 2029 |
2021 ch.SetReceivingTimeout(500); | 2030 ch.SetIceConfig(CreateIceConfig(500, false)); |
2022 // Wait until conn2 becomes not receiving. | 2031 // Wait until conn2 becomes not receiving. |
2023 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); | 2032 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); |
2024 | 2033 |
2025 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1)); | 2034 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1)); |
2026 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2035 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
2027 ASSERT_TRUE(conn3 != nullptr); | 2036 ASSERT_TRUE(conn3 != nullptr); |
2028 // The best connection should still be conn2. Even through conn3 has lower | 2037 // The best connection should still be conn2. Even through conn3 has lower |
2029 // priority and is not receiving/writable, it is not pruned because the best | 2038 // priority and is not receiving/writable, it is not pruned because the best |
2030 // connection is not receiving. | 2039 // connection is not receiving. |
2031 WAIT(conn3->pruned(), 1000); | 2040 WAIT(conn3->pruned(), 1000); |
2032 EXPECT_FALSE(conn3->pruned()); | 2041 EXPECT_FALSE(conn3->pruned()); |
2033 } | 2042 } |
OLD | NEW |