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 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1761 uint32 remote_priority = conn1->remote_candidate().priority(); | 1761 uint32 remote_priority = conn1->remote_candidate().priority(); |
1762 | 1762 |
1763 // Create a higher priority candidate and make the connection | 1763 // Create a higher priority candidate and make the connection |
1764 // receiving/writable. This will prune conn1. | 1764 // receiving/writable. This will prune conn1. |
1765 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 1765 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); |
1766 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1766 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
1767 ASSERT_TRUE(conn2 != nullptr); | 1767 ASSERT_TRUE(conn2 != nullptr); |
1768 conn2->ReceivedPing(); | 1768 conn2->ReceivedPing(); |
1769 conn2->ReceivedPingResponse(); | 1769 conn2->ReceivedPingResponse(); |
1770 | 1770 |
1771 // Wait for conn1 to be destroyed. | 1771 // Wait for conn1 to be pruned. |
1772 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 3000); | 1772 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); |
1773 cricket::Port* port = GetPort(&ch); | 1773 // Destroy the connection to test SignalUnknownAddress. |
1774 conn1->Destroy(); | |
1775 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000); | |
1774 | 1776 |
1775 // Create a minimal STUN message with prflx priority. | 1777 // Create a minimal STUN message with prflx priority. |
1776 cricket::IceMessage request; | 1778 cricket::IceMessage request; |
1777 request.SetType(cricket::STUN_BINDING_REQUEST); | 1779 request.SetType(cricket::STUN_BINDING_REQUEST); |
1778 request.AddAttribute(new cricket::StunByteStringAttribute( | 1780 request.AddAttribute(new cricket::StunByteStringAttribute( |
1779 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); | 1781 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); |
1780 uint32 prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; | 1782 uint32 prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; |
1781 request.AddAttribute(new cricket::StunUInt32Attribute( | 1783 request.AddAttribute(new cricket::StunUInt32Attribute( |
1782 cricket::STUN_ATTR_PRIORITY, prflx_priority)); | 1784 cricket::STUN_ATTR_PRIORITY, prflx_priority)); |
1783 EXPECT_NE(prflx_priority, remote_priority); | 1785 EXPECT_NE(prflx_priority, remote_priority); |
1784 | 1786 |
1787 cricket::Port* port = GetPort(&ch); | |
1785 // conn1 should be resurrected with original priority. | 1788 // conn1 should be resurrected with original priority. |
1786 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), | 1789 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), |
1787 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 1790 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
1788 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1791 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
1789 ASSERT_TRUE(conn1 != nullptr); | 1792 ASSERT_TRUE(conn1 != nullptr); |
1790 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority); | 1793 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority); |
1791 | 1794 |
1792 // conn3, a real prflx connection, should have prflx priority. | 1795 // conn3, a real prflx connection, should have prflx priority. |
1793 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), | 1796 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), |
1794 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 1797 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2033 | 2036 |
2034 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1)); | 2037 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1)); |
2035 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2038 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
2036 ASSERT_TRUE(conn3 != nullptr); | 2039 ASSERT_TRUE(conn3 != nullptr); |
2037 // The best connection should still be conn2. Even through conn3 has lower | 2040 // The best connection should still be conn2. Even through conn3 has lower |
2038 // priority and is not receiving/writable, it is not pruned because the best | 2041 // priority and is not receiving/writable, it is not pruned because the best |
2039 // connection is not receiving. | 2042 // connection is not receiving. |
2040 WAIT(conn3->pruned(), 1000); | 2043 WAIT(conn3->pruned(), 1000); |
2041 EXPECT_FALSE(conn3->pruned()); | 2044 EXPECT_FALSE(conn3->pruned()); |
2042 } | 2045 } |
2046 | |
2047 // Test that when a low-priority connection is pruned, it will not be deleted | |
2048 // right away. | |
2049 TEST_F(P2PTransportChannelPingTest, TestDontDeleteRightAwayWhenPrune) { | |
pthatcher1
2015/09/28 23:07:27
...WhenPrune => ...WhenPruned
honghaiz3
2015/09/29 18:47:49
Done.
| |
2050 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | |
2051 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa); | |
2052 PrepareChannel(&ch); | |
2053 ch.Connect(); | |
2054 ch.MaybeStartGathering(); | |
2055 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); | |
2056 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | |
2057 ASSERT_TRUE(conn1 != nullptr); | |
2058 EXPECT_EQ(conn1, ch.best_connection()); | |
2059 conn1->ReceivedPingResponse(); // Becomes writable and receiving | |
2060 | |
2061 // Add a low-priority connection, which will be pruned right away, but it | |
2062 // will not be deleted right away. | |
2063 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); | |
2064 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | |
2065 ASSERT_TRUE(conn2 != nullptr); | |
2066 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); | |
2067 LOG(LS_INFO) << "A connection is pruned"; | |
2068 WAIT((conn2 = GetConnectionTo(&ch, "2.2.2.2", 2)) == nullptr, 1000); | |
2069 EXPECT_FALSE(conn2 == nullptr); | |
pthatcher1
2015/09/28 23:07:27
I think that what we really want to test is that w
honghaiz3
2015/09/29 18:47:49
Done. conn2 will start to ping once conn1 is not r
| |
2070 } | |
2071 | |
2072 // Test that GetState returns the state correctly. | |
2073 TEST_F(P2PTransportChannelPingTest, TestGetState) { | |
2074 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | |
2075 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa); | |
2076 PrepareChannel(&ch); | |
2077 ch.Connect(); | |
2078 ch.MaybeStartGathering(); | |
2079 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); | |
2080 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); | |
2081 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | |
2082 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | |
2083 ASSERT_TRUE(conn1 != nullptr); | |
2084 ASSERT_TRUE(conn2 != nullptr); | |
2085 // Now there are two connections, so the transport channel is connecting. | |
pthatcher1
2015/09/28 23:07:27
We need to check STATE_INIT before there are any c
honghaiz3
2015/09/29 18:47:49
Done.
| |
2086 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); | |
2087 // |conn1| becomes writable and receiving; it then should prune |conn2|. | |
2088 conn1->ReceivedPingResponse(); | |
2089 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); | |
2090 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | |
pthatcher1
2015/09/28 23:07:27
To be more complete, I think we need to test the m
honghaiz3
2015/09/29 18:47:49
Added GetState tests in the MultihomedTest.
| |
2091 conn1->Prune(); // All connections are pruned. | |
2092 EXPECT_EQ(cricket::TransportChannelState::STATE_FAILED, ch.GetState()); | |
pthatcher1
2015/09/28 23:07:27
We should also test that not only Prune() get us i
honghaiz3
2015/09/29 18:47:49
Prune is used to emulate losing writability.
If w
pthatcher1
2015/09/29 19:51:32
Is there a way we can just set_write_state(WRITE_T
honghaiz3
2015/09/29 20:40:42
Yes although set_write_state() is protected. We ca
| |
2093 } | |
OLD | NEW |