| 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 } | 299 } |
| 300 } | 300 } |
| 301 cricket::P2PTransportChannel* CreateChannel( | 301 cricket::P2PTransportChannel* CreateChannel( |
| 302 int endpoint, | 302 int endpoint, |
| 303 int component, | 303 int component, |
| 304 const std::string& local_ice_ufrag, | 304 const std::string& local_ice_ufrag, |
| 305 const std::string& local_ice_pwd, | 305 const std::string& local_ice_pwd, |
| 306 const std::string& remote_ice_ufrag, | 306 const std::string& remote_ice_ufrag, |
| 307 const std::string& remote_ice_pwd) { | 307 const std::string& remote_ice_pwd) { |
| 308 cricket::P2PTransportChannel* channel = new cricket::P2PTransportChannel( | 308 cricket::P2PTransportChannel* channel = new cricket::P2PTransportChannel( |
| 309 "test content name", component, GetAllocator(endpoint)); | 309 "test content name", component, NULL, GetAllocator(endpoint)); |
| 310 channel->SignalCandidateGathered.connect( | 310 channel->SignalCandidateGathered.connect( |
| 311 this, &P2PTransportChannelTestBase::OnCandidate); | 311 this, &P2PTransportChannelTestBase::OnCandidate); |
| 312 channel->SignalReadPacket.connect( | 312 channel->SignalReadPacket.connect( |
| 313 this, &P2PTransportChannelTestBase::OnReadPacket); | 313 this, &P2PTransportChannelTestBase::OnReadPacket); |
| 314 channel->SignalRoleConflict.connect( | 314 channel->SignalRoleConflict.connect( |
| 315 this, &P2PTransportChannelTestBase::OnRoleConflict); | 315 this, &P2PTransportChannelTestBase::OnRoleConflict); |
| 316 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); | 316 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); |
| 317 if (clear_remote_candidates_ufrag_pwd_) { | 317 if (clear_remote_candidates_ufrag_pwd_) { |
| 318 // This only needs to be set if we're clearing them from the | 318 // This only needs to be set if we're clearing them from the |
| 319 // candidates. Some unit tests rely on this not being set. | 319 // candidates. Some unit tests rely on this not being set. |
| (...skipping 1483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1803 } | 1803 } |
| 1804 | 1804 |
| 1805 private: | 1805 private: |
| 1806 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; | 1806 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
| 1807 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; | 1807 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; |
| 1808 rtc::SocketServerScope ss_scope_; | 1808 rtc::SocketServerScope ss_scope_; |
| 1809 }; | 1809 }; |
| 1810 | 1810 |
| 1811 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { | 1811 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { |
| 1812 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1812 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 1813 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); | 1813 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); |
| 1814 PrepareChannel(&ch); | 1814 PrepareChannel(&ch); |
| 1815 ch.Connect(); | 1815 ch.Connect(); |
| 1816 ch.MaybeStartGathering(); | 1816 ch.MaybeStartGathering(); |
| 1817 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1817 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
| 1818 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 1818 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); |
| 1819 | 1819 |
| 1820 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1820 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 1821 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1821 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 1822 ASSERT_TRUE(conn1 != nullptr); | 1822 ASSERT_TRUE(conn1 != nullptr); |
| 1823 ASSERT_TRUE(conn2 != nullptr); | 1823 ASSERT_TRUE(conn2 != nullptr); |
| 1824 | 1824 |
| 1825 // Before a triggered check, the first connection to ping is the | 1825 // Before a triggered check, the first connection to ping is the |
| 1826 // highest priority one. | 1826 // highest priority one. |
| 1827 EXPECT_EQ(conn2, ch.FindNextPingableConnection()); | 1827 EXPECT_EQ(conn2, ch.FindNextPingableConnection()); |
| 1828 | 1828 |
| 1829 // Receiving a ping causes a triggered check which should make conn1 | 1829 // Receiving a ping causes a triggered check which should make conn1 |
| 1830 // be pinged first instead of conn2, even though conn2 has a higher | 1830 // be pinged first instead of conn2, even though conn2 has a higher |
| 1831 // priority. | 1831 // priority. |
| 1832 conn1->ReceivedPing(); | 1832 conn1->ReceivedPing(); |
| 1833 EXPECT_EQ(conn1, ch.FindNextPingableConnection()); | 1833 EXPECT_EQ(conn1, ch.FindNextPingableConnection()); |
| 1834 } | 1834 } |
| 1835 | 1835 |
| 1836 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { | 1836 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { |
| 1837 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1837 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 1838 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); | 1838 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); |
| 1839 PrepareChannel(&ch); | 1839 PrepareChannel(&ch); |
| 1840 ch.Connect(); | 1840 ch.Connect(); |
| 1841 ch.MaybeStartGathering(); | 1841 ch.MaybeStartGathering(); |
| 1842 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1842 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
| 1843 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 1843 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); |
| 1844 | 1844 |
| 1845 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1845 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 1846 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1846 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 1847 ASSERT_TRUE(conn1 != nullptr); | 1847 ASSERT_TRUE(conn1 != nullptr); |
| 1848 ASSERT_TRUE(conn2 != nullptr); | 1848 ASSERT_TRUE(conn2 != nullptr); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1859 } | 1859 } |
| 1860 | 1860 |
| 1861 // Test adding remote candidates with different ufrags. If a remote candidate | 1861 // Test adding remote candidates with different ufrags. If a remote candidate |
| 1862 // is added with an old ufrag, it will be discarded. If it is added with a | 1862 // is added with an old ufrag, it will be discarded. If it is added with a |
| 1863 // ufrag that was not seen before, it will be used to create connections | 1863 // ufrag that was not seen before, it will be used to create connections |
| 1864 // although the ICE pwd in the remote candidate will be set when the ICE | 1864 // although the ICE pwd in the remote candidate will be set when the ICE |
| 1865 // credentials arrive. If a remote candidate is added with the current ICE | 1865 // credentials arrive. If a remote candidate is added with the current ICE |
| 1866 // ufrag, its pwd and generation will be set properly. | 1866 // ufrag, its pwd and generation will be set properly. |
| 1867 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { | 1867 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { |
| 1868 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1868 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 1869 cricket::P2PTransportChannel ch("add candidate", 1, &pa); | 1869 cricket::P2PTransportChannel ch("add candidate", 1, nullptr, &pa); |
| 1870 PrepareChannel(&ch); | 1870 PrepareChannel(&ch); |
| 1871 ch.Connect(); | 1871 ch.Connect(); |
| 1872 ch.MaybeStartGathering(); | 1872 ch.MaybeStartGathering(); |
| 1873 // Add a candidate with a future ufrag. | 1873 // Add a candidate with a future ufrag. |
| 1874 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1, kIceUfrag[2])); | 1874 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1, kIceUfrag[2])); |
| 1875 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1875 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 1876 ASSERT_TRUE(conn1 != nullptr); | 1876 ASSERT_TRUE(conn1 != nullptr); |
| 1877 const cricket::Candidate& candidate = conn1->remote_candidate(); | 1877 const cricket::Candidate& candidate = conn1->remote_candidate(); |
| 1878 EXPECT_EQ(kIceUfrag[2], candidate.username()); | 1878 EXPECT_EQ(kIceUfrag[2], candidate.username()); |
| 1879 EXPECT_TRUE(candidate.password().empty()); | 1879 EXPECT_TRUE(candidate.password().empty()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1909 if (candidate.username() == kIceUfrag[1]) { | 1909 if (candidate.username() == kIceUfrag[1]) { |
| 1910 EXPECT_EQ(kIcePwd[1], candidate.password()); | 1910 EXPECT_EQ(kIcePwd[1], candidate.password()); |
| 1911 } else if (candidate.username() == kIceUfrag[2]) { | 1911 } else if (candidate.username() == kIceUfrag[2]) { |
| 1912 EXPECT_EQ(kIcePwd[2], candidate.password()); | 1912 EXPECT_EQ(kIcePwd[2], candidate.password()); |
| 1913 } | 1913 } |
| 1914 } | 1914 } |
| 1915 } | 1915 } |
| 1916 | 1916 |
| 1917 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { | 1917 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { |
| 1918 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1918 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 1919 cricket::P2PTransportChannel ch("connection resurrection", 1, &pa); | 1919 cricket::P2PTransportChannel ch("connection resurrection", 1, nullptr, &pa); |
| 1920 PrepareChannel(&ch); | 1920 PrepareChannel(&ch); |
| 1921 ch.Connect(); | 1921 ch.Connect(); |
| 1922 ch.MaybeStartGathering(); | 1922 ch.MaybeStartGathering(); |
| 1923 | 1923 |
| 1924 // Create conn1 and keep track of original candidate priority. | 1924 // Create conn1 and keep track of original candidate priority. |
| 1925 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1925 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
| 1926 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1926 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 1927 ASSERT_TRUE(conn1 != nullptr); | 1927 ASSERT_TRUE(conn1 != nullptr); |
| 1928 uint32_t remote_priority = conn1->remote_candidate().priority(); | 1928 uint32_t remote_priority = conn1->remote_candidate().priority(); |
| 1929 | 1929 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1962 // conn3, a real prflx connection, should have prflx priority. | 1962 // conn3, a real prflx connection, should have prflx priority. |
| 1963 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), | 1963 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), |
| 1964 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 1964 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
| 1965 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1); | 1965 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1); |
| 1966 ASSERT_TRUE(conn3 != nullptr); | 1966 ASSERT_TRUE(conn3 != nullptr); |
| 1967 EXPECT_EQ(conn3->remote_candidate().priority(), prflx_priority); | 1967 EXPECT_EQ(conn3->remote_candidate().priority(), prflx_priority); |
| 1968 } | 1968 } |
| 1969 | 1969 |
| 1970 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { | 1970 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { |
| 1971 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1971 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 1972 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 1972 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); |
| 1973 PrepareChannel(&ch); | 1973 PrepareChannel(&ch); |
| 1974 // Default receiving timeout and checking receiving delay should not be too | 1974 // Default receiving timeout and checking receiving delay should not be too |
| 1975 // small. | 1975 // small. |
| 1976 EXPECT_LE(1000, ch.receiving_timeout()); | 1976 EXPECT_LE(1000, ch.receiving_timeout()); |
| 1977 EXPECT_LE(200, ch.check_receiving_delay()); | 1977 EXPECT_LE(200, ch.check_receiving_delay()); |
| 1978 ch.SetIceConfig(CreateIceConfig(500, false)); | 1978 ch.SetIceConfig(CreateIceConfig(500, false)); |
| 1979 EXPECT_EQ(500, ch.receiving_timeout()); | 1979 EXPECT_EQ(500, ch.receiving_timeout()); |
| 1980 EXPECT_EQ(50, ch.check_receiving_delay()); | 1980 EXPECT_EQ(50, ch.check_receiving_delay()); |
| 1981 ch.Connect(); | 1981 ch.Connect(); |
| 1982 ch.MaybeStartGathering(); | 1982 ch.MaybeStartGathering(); |
| 1983 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1983 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
| 1984 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1984 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 1985 ASSERT_TRUE(conn1 != nullptr); | 1985 ASSERT_TRUE(conn1 != nullptr); |
| 1986 | 1986 |
| 1987 conn1->ReceivedPing(); | 1987 conn1->ReceivedPing(); |
| 1988 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 1988 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
| 1989 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); | 1989 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); |
| 1990 EXPECT_TRUE_WAIT(ch.receiving(), 1000); | 1990 EXPECT_TRUE_WAIT(ch.receiving(), 1000); |
| 1991 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); | 1991 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); |
| 1992 } | 1992 } |
| 1993 | 1993 |
| 1994 // The controlled side will select a connection as the "best connection" based | 1994 // The controlled side will select a connection as the "best connection" based |
| 1995 // on priority until the controlling side nominates a connection, at which | 1995 // on priority until the controlling side nominates a connection, at which |
| 1996 // point the controlled side will select that connection as the | 1996 // point the controlled side will select that connection as the |
| 1997 // "best connection". | 1997 // "best connection". |
| 1998 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { | 1998 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { |
| 1999 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1999 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2000 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 2000 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); |
| 2001 PrepareChannel(&ch); | 2001 PrepareChannel(&ch); |
| 2002 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2002 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2003 ch.Connect(); | 2003 ch.Connect(); |
| 2004 ch.MaybeStartGathering(); | 2004 ch.MaybeStartGathering(); |
| 2005 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 2005 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
| 2006 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2006 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2007 ASSERT_TRUE(conn1 != nullptr); | 2007 ASSERT_TRUE(conn1 != nullptr); |
| 2008 EXPECT_EQ(conn1, ch.best_connection()); | 2008 EXPECT_EQ(conn1, ch.best_connection()); |
| 2009 | 2009 |
| 2010 // When a higher priority candidate comes in, the new connection is chosen | 2010 // When a higher priority candidate comes in, the new connection is chosen |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2047 EXPECT_EQ(conn4, ch.best_connection()); | 2047 EXPECT_EQ(conn4, ch.best_connection()); |
| 2048 } | 2048 } |
| 2049 | 2049 |
| 2050 // The controlled side will select a connection as the "best connection" based | 2050 // The controlled side will select a connection as the "best connection" based |
| 2051 // on requests from an unknown address before the controlling side nominates | 2051 // on requests from an unknown address before the controlling side nominates |
| 2052 // a connection, and will nominate a connection from an unknown address if the | 2052 // a connection, and will nominate a connection from an unknown address if the |
| 2053 // request contains the use_candidate attribute. Plus, it will also sends back | 2053 // request contains the use_candidate attribute. Plus, it will also sends back |
| 2054 // a ping response and set the ICE pwd in the remote candidate appropriately. | 2054 // a ping response and set the ICE pwd in the remote candidate appropriately. |
| 2055 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { | 2055 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { |
| 2056 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2056 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2057 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 2057 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); |
| 2058 PrepareChannel(&ch); | 2058 PrepareChannel(&ch); |
| 2059 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2059 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2060 ch.Connect(); | 2060 ch.Connect(); |
| 2061 ch.MaybeStartGathering(); | 2061 ch.MaybeStartGathering(); |
| 2062 // A minimal STUN message with prflx priority. | 2062 // A minimal STUN message with prflx priority. |
| 2063 cricket::IceMessage request; | 2063 cricket::IceMessage request; |
| 2064 request.SetType(cricket::STUN_BINDING_REQUEST); | 2064 request.SetType(cricket::STUN_BINDING_REQUEST); |
| 2065 request.AddAttribute(new cricket::StunByteStringAttribute( | 2065 request.AddAttribute(new cricket::StunByteStringAttribute( |
| 2066 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); | 2066 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); |
| 2067 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; | 2067 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2129 EXPECT_TRUE(port->sent_binding_response()); | 2129 EXPECT_TRUE(port->sent_binding_response()); |
| 2130 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password()); | 2130 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password()); |
| 2131 } | 2131 } |
| 2132 | 2132 |
| 2133 // The controlled side will select a connection as the "best connection" | 2133 // The controlled side will select a connection as the "best connection" |
| 2134 // based on media received until the controlling side nominates a connection, | 2134 // based on media received until the controlling side nominates a connection, |
| 2135 // at which point the controlled side will select that connection as | 2135 // at which point the controlled side will select that connection as |
| 2136 // the "best connection". | 2136 // the "best connection". |
| 2137 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { | 2137 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { |
| 2138 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2138 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2139 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 2139 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); |
| 2140 PrepareChannel(&ch); | 2140 PrepareChannel(&ch); |
| 2141 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2141 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2142 ch.Connect(); | 2142 ch.Connect(); |
| 2143 ch.MaybeStartGathering(); | 2143 ch.MaybeStartGathering(); |
| 2144 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 10)); | 2144 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 10)); |
| 2145 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2145 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2146 ASSERT_TRUE(conn1 != nullptr); | 2146 ASSERT_TRUE(conn1 != nullptr); |
| 2147 EXPECT_EQ(conn1, ch.best_connection()); | 2147 EXPECT_EQ(conn1, ch.best_connection()); |
| 2148 | 2148 |
| 2149 // If a data packet is received on conn2, the best connection should | 2149 // If a data packet is received on conn2, the best connection should |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2187 conn2->ReceivedPing(); | 2187 conn2->ReceivedPing(); |
| 2188 conn2->ReceivedPingResponse(); | 2188 conn2->ReceivedPingResponse(); |
| 2189 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 2189 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
| 2190 EXPECT_EQ(conn3, ch.best_connection()); | 2190 EXPECT_EQ(conn3, ch.best_connection()); |
| 2191 } | 2191 } |
| 2192 | 2192 |
| 2193 // When the current best connection is strong, lower-priority connections will | 2193 // When the current best connection is strong, lower-priority connections will |
| 2194 // be pruned. Otherwise, lower-priority connections are kept. | 2194 // be pruned. Otherwise, lower-priority connections are kept. |
| 2195 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { | 2195 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { |
| 2196 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2196 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2197 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2197 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa); |
| 2198 PrepareChannel(&ch); | 2198 PrepareChannel(&ch); |
| 2199 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2199 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 2200 ch.Connect(); | 2200 ch.Connect(); |
| 2201 ch.MaybeStartGathering(); | 2201 ch.MaybeStartGathering(); |
| 2202 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 2202 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
| 2203 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2203 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2204 ASSERT_TRUE(conn1 != nullptr); | 2204 ASSERT_TRUE(conn1 != nullptr); |
| 2205 EXPECT_EQ(conn1, ch.best_connection()); | 2205 EXPECT_EQ(conn1, ch.best_connection()); |
| 2206 conn1->ReceivedPingResponse(); // Becomes writable and receiving | 2206 conn1->ReceivedPingResponse(); // Becomes writable and receiving |
| 2207 | 2207 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2225 // The best connection should still be conn2. Even through conn3 has lower | 2225 // The best connection should still be conn2. Even through conn3 has lower |
| 2226 // priority and is not receiving/writable, it is not pruned because the best | 2226 // priority and is not receiving/writable, it is not pruned because the best |
| 2227 // connection is not receiving. | 2227 // connection is not receiving. |
| 2228 WAIT(conn3->pruned(), 1000); | 2228 WAIT(conn3->pruned(), 1000); |
| 2229 EXPECT_FALSE(conn3->pruned()); | 2229 EXPECT_FALSE(conn3->pruned()); |
| 2230 } | 2230 } |
| 2231 | 2231 |
| 2232 // Test that GetState returns the state correctly. | 2232 // Test that GetState returns the state correctly. |
| 2233 TEST_F(P2PTransportChannelPingTest, TestGetState) { | 2233 TEST_F(P2PTransportChannelPingTest, TestGetState) { |
| 2234 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2234 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2235 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2235 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa); |
| 2236 PrepareChannel(&ch); | 2236 PrepareChannel(&ch); |
| 2237 ch.Connect(); | 2237 ch.Connect(); |
| 2238 ch.MaybeStartGathering(); | 2238 ch.MaybeStartGathering(); |
| 2239 EXPECT_EQ(cricket::TransportChannelState::STATE_INIT, ch.GetState()); | 2239 EXPECT_EQ(cricket::TransportChannelState::STATE_INIT, ch.GetState()); |
| 2240 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); | 2240 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); |
| 2241 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); | 2241 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); |
| 2242 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2242 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2243 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2243 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 2244 ASSERT_TRUE(conn1 != nullptr); | 2244 ASSERT_TRUE(conn1 != nullptr); |
| 2245 ASSERT_TRUE(conn2 != nullptr); | 2245 ASSERT_TRUE(conn2 != nullptr); |
| 2246 // Now there are two connections, so the transport channel is connecting. | 2246 // Now there are two connections, so the transport channel is connecting. |
| 2247 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); | 2247 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); |
| 2248 // |conn1| becomes writable and receiving; it then should prune |conn2|. | 2248 // |conn1| becomes writable and receiving; it then should prune |conn2|. |
| 2249 conn1->ReceivedPingResponse(); | 2249 conn1->ReceivedPingResponse(); |
| 2250 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); | 2250 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); |
| 2251 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | 2251 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); |
| 2252 conn1->Prune(); // All connections are pruned. | 2252 conn1->Prune(); // All connections are pruned. |
| 2253 // Need to wait until the channel state is updated. | 2253 // Need to wait until the channel state is updated. |
| 2254 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_FAILED, ch.GetState(), | 2254 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_FAILED, ch.GetState(), |
| 2255 1000); | 2255 1000); |
| 2256 } | 2256 } |
| 2257 | 2257 |
| 2258 // Test that when a low-priority connection is pruned, it is not deleted | 2258 // Test that when a low-priority connection is pruned, it is not deleted |
| 2259 // right away, and it can become active and be pruned again. | 2259 // right away, and it can become active and be pruned again. |
| 2260 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { | 2260 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { |
| 2261 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2261 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2262 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2262 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa); |
| 2263 PrepareChannel(&ch); | 2263 PrepareChannel(&ch); |
| 2264 ch.SetIceConfig(CreateIceConfig(1000, false)); | 2264 ch.SetIceConfig(CreateIceConfig(1000, false)); |
| 2265 ch.Connect(); | 2265 ch.Connect(); |
| 2266 ch.MaybeStartGathering(); | 2266 ch.MaybeStartGathering(); |
| 2267 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); | 2267 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); |
| 2268 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2268 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2269 ASSERT_TRUE(conn1 != nullptr); | 2269 ASSERT_TRUE(conn1 != nullptr); |
| 2270 EXPECT_EQ(conn1, ch.best_connection()); | 2270 EXPECT_EQ(conn1, ch.best_connection()); |
| 2271 conn1->ReceivedPingResponse(); // Becomes writable and receiving | 2271 conn1->ReceivedPingResponse(); // Becomes writable and receiving |
| 2272 | 2272 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2295 conn1->ReceivedPingResponse(); | 2295 conn1->ReceivedPingResponse(); |
| 2296 EXPECT_EQ_WAIT(conn1, ch.best_connection(), 1000); | 2296 EXPECT_EQ_WAIT(conn1, ch.best_connection(), 1000); |
| 2297 EXPECT_TRUE_WAIT(!conn2->active(), 1000); | 2297 EXPECT_TRUE_WAIT(!conn2->active(), 1000); |
| 2298 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | 2298 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); |
| 2299 } | 2299 } |
| 2300 | 2300 |
| 2301 // Test that if all connections in a channel has timed out on writing, they | 2301 // Test that if all connections in a channel has timed out on writing, they |
| 2302 // will all be deleted. We use Prune to simulate write_time_out. | 2302 // will all be deleted. We use Prune to simulate write_time_out. |
| 2303 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { | 2303 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { |
| 2304 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2304 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2305 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2305 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa); |
| 2306 PrepareChannel(&ch); | 2306 PrepareChannel(&ch); |
| 2307 ch.Connect(); | 2307 ch.Connect(); |
| 2308 ch.MaybeStartGathering(); | 2308 ch.MaybeStartGathering(); |
| 2309 // Have one connection only but later becomes write-time-out. | 2309 // Have one connection only but later becomes write-time-out. |
| 2310 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); | 2310 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); |
| 2311 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2311 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2312 ASSERT_TRUE(conn1 != nullptr); | 2312 ASSERT_TRUE(conn1 != nullptr); |
| 2313 conn1->ReceivedPing(); // Becomes receiving | 2313 conn1->ReceivedPing(); // Becomes receiving |
| 2314 conn1->Prune(); | 2314 conn1->Prune(); |
| 2315 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); | 2315 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2327 conn2->Prune(); | 2327 conn2->Prune(); |
| 2328 conn3->Prune(); | 2328 conn3->Prune(); |
| 2329 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); | 2329 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); |
| 2330 } | 2330 } |
| 2331 | 2331 |
| 2332 // Test that after a port allocator session is started, it will be stopped | 2332 // Test that after a port allocator session is started, it will be stopped |
| 2333 // when a new connection becomes writable and receiving. Also test that this | 2333 // when a new connection becomes writable and receiving. Also test that this |
| 2334 // holds even if the transport channel did not lose the writability. | 2334 // holds even if the transport channel did not lose the writability. |
| 2335 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { | 2335 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { |
| 2336 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2336 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2337 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2337 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa); |
| 2338 PrepareChannel(&ch); | 2338 PrepareChannel(&ch); |
| 2339 ch.SetIceConfig(CreateIceConfig(2000, false)); | 2339 ch.SetIceConfig(CreateIceConfig(2000, false)); |
| 2340 ch.Connect(); | 2340 ch.Connect(); |
| 2341 ch.MaybeStartGathering(); | 2341 ch.MaybeStartGathering(); |
| 2342 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); | 2342 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); |
| 2343 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2343 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2344 ASSERT_TRUE(conn1 != nullptr); | 2344 ASSERT_TRUE(conn1 != nullptr); |
| 2345 conn1->ReceivedPingResponse(); // Becomes writable and receiving | 2345 conn1->ReceivedPingResponse(); // Becomes writable and receiving |
| 2346 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 2346 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
| 2347 | 2347 |
| 2348 // Restart gathering even if the transport channel is still writable. | 2348 // Restart gathering even if the transport channel is still writable. |
| 2349 // It should stop getting ports after a new connection becomes strongly | 2349 // It should stop getting ports after a new connection becomes strongly |
| 2350 // connected. | 2350 // connected. |
| 2351 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); | 2351 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); |
| 2352 ch.MaybeStartGathering(); | 2352 ch.MaybeStartGathering(); |
| 2353 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100)); | 2353 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100)); |
| 2354 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2354 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 2355 ASSERT_TRUE(conn2 != nullptr); | 2355 ASSERT_TRUE(conn2 != nullptr); |
| 2356 conn2->ReceivedPingResponse(); // Becomes writable and receiving | 2356 conn2->ReceivedPingResponse(); // Becomes writable and receiving |
| 2357 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 2357 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
| 2358 } | 2358 } |
| OLD | NEW |