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 1753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1764 ch.MaybeStartGathering(); | 1764 ch.MaybeStartGathering(); |
1765 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1765 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
1766 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1766 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
1767 ASSERT_TRUE(conn1 != nullptr); | 1767 ASSERT_TRUE(conn1 != nullptr); |
1768 EXPECT_EQ(conn1, ch.best_connection()); | 1768 EXPECT_EQ(conn1, ch.best_connection()); |
1769 | 1769 |
1770 // When a higher priority candidate comes in, the new connection is chosen | 1770 // When a higher priority candidate comes in, the new connection is chosen |
1771 // as the best connection. | 1771 // as the best connection. |
1772 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 10)); | 1772 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 10)); |
1773 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1773 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
1774 ASSERT_TRUE(conn1 != nullptr); | 1774 ASSERT_TRUE(conn2 != nullptr); |
1775 EXPECT_EQ(conn2, ch.best_connection()); | 1775 EXPECT_EQ(conn2, ch.best_connection()); |
1776 | 1776 |
1777 // If a stun request with use-candidate attribute arrives, the receiving | 1777 // If a stun request with use-candidate attribute arrives, the receiving |
1778 // connection will be set as the best connection, even though | 1778 // connection will be set as the best connection, even though |
1779 // its priority is lower. | 1779 // its priority is lower. |
1780 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1)); | 1780 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1)); |
1781 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 1781 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
1782 ASSERT_TRUE(conn3 != nullptr); | 1782 ASSERT_TRUE(conn3 != nullptr); |
1783 // Because it has a lower priority, the best connection is still conn2. | 1783 // Because it has a lower priority, the best connection is still conn2. |
1784 EXPECT_EQ(conn2, ch.best_connection()); | 1784 EXPECT_EQ(conn2, ch.best_connection()); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1924 conn3->ReceivedPingResponse(); // Become writable. | 1924 conn3->ReceivedPingResponse(); // Become writable. |
1925 EXPECT_EQ(conn3, ch.best_connection()); | 1925 EXPECT_EQ(conn3, ch.best_connection()); |
1926 | 1926 |
1927 // Now another data packet will not switch the best connection because the | 1927 // Now another data packet will not switch the best connection because the |
1928 // best connection was nominated by the controlling side. | 1928 // best connection was nominated by the controlling side. |
1929 conn2->ReceivedPing(); | 1929 conn2->ReceivedPing(); |
1930 conn2->ReceivedPingResponse(); | 1930 conn2->ReceivedPingResponse(); |
1931 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 1931 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
1932 EXPECT_EQ(conn3, ch.best_connection()); | 1932 EXPECT_EQ(conn3, ch.best_connection()); |
1933 } | 1933 } |
1934 | |
1935 // When the current best connection is strong, lower-priority connections will | |
1936 // be pruned. Otherwise, lower-priority connections are kept. | |
1937 TEST_F(P2PTransportChannelPingTest, TestPruneConnections) { | |
pthatcher1
2015/09/24 06:35:21
Would a better name be TestDontPruneWhenWeak?
honghaiz3
2015/09/24 16:48:49
Done.
| |
1938 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | |
1939 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa); | |
1940 PrepareChannel(&ch); | |
1941 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | |
1942 ch.Connect(); | |
1943 ch.MaybeStartGathering(); | |
1944 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | |
1945 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | |
1946 ASSERT_TRUE(conn1 != nullptr); | |
1947 EXPECT_EQ(conn1, ch.best_connection()); | |
1948 conn1->ReceivedPingResponse(); // Becomes writable and receiving | |
1949 | |
1950 // When a higher-priority, nominated candidate comes in, the connections with | |
1951 // lower-priority are pruned. | |
1952 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 10)); | |
1953 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | |
1954 ASSERT_TRUE(conn2 != nullptr); | |
1955 conn2->ReceivedPingResponse(); // Becomes writable and receiving | |
1956 conn2->set_nominated(true); | |
1957 conn2->SignalNominated(conn2); | |
1958 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); | |
1959 | |
1960 ch.SetReceivingTimeout(500); | |
1961 // Wait until conn2 becomes not receiving. | |
1962 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); | |
1963 | |
1964 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1)); | |
1965 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | |
1966 ASSERT_TRUE(conn3 != nullptr); | |
1967 // The best connection should still be conn2. Even through conn3 has lower | |
1968 // priority and is not receiving/writable, it is not pruned because the best | |
1969 // connection is not receiving. | |
1970 WAIT(conn3->pruned(), 1000); | |
1971 EXPECT_FALSE(conn3->pruned()); | |
1972 } | |
OLD | NEW |