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...) 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, NULL, GetAllocator(endpoint)); | 309 "test content name", component, 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 1583 matching lines...) Loading... |
1903 } | 1903 } |
1904 | 1904 |
1905 private: | 1905 private: |
1906 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; | 1906 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
1907 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; | 1907 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; |
1908 rtc::SocketServerScope ss_scope_; | 1908 rtc::SocketServerScope ss_scope_; |
1909 }; | 1909 }; |
1910 | 1910 |
1911 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { | 1911 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { |
1912 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1912 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
1913 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); | 1913 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); |
1914 PrepareChannel(&ch); | 1914 PrepareChannel(&ch); |
1915 ch.Connect(); | 1915 ch.Connect(); |
1916 ch.MaybeStartGathering(); | 1916 ch.MaybeStartGathering(); |
1917 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1917 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
1918 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 1918 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); |
1919 | 1919 |
1920 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1920 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
1921 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1921 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
1922 ASSERT_TRUE(conn1 != nullptr); | 1922 ASSERT_TRUE(conn1 != nullptr); |
1923 ASSERT_TRUE(conn2 != nullptr); | 1923 ASSERT_TRUE(conn2 != nullptr); |
1924 | 1924 |
1925 // Before a triggered check, the first connection to ping is the | 1925 // Before a triggered check, the first connection to ping is the |
1926 // highest priority one. | 1926 // highest priority one. |
1927 EXPECT_EQ(conn2, ch.FindNextPingableConnection()); | 1927 EXPECT_EQ(conn2, ch.FindNextPingableConnection()); |
1928 | 1928 |
1929 // Receiving a ping causes a triggered check which should make conn1 | 1929 // Receiving a ping causes a triggered check which should make conn1 |
1930 // be pinged first instead of conn2, even though conn2 has a higher | 1930 // be pinged first instead of conn2, even though conn2 has a higher |
1931 // priority. | 1931 // priority. |
1932 conn1->ReceivedPing(); | 1932 conn1->ReceivedPing(); |
1933 EXPECT_EQ(conn1, ch.FindNextPingableConnection()); | 1933 EXPECT_EQ(conn1, ch.FindNextPingableConnection()); |
1934 } | 1934 } |
1935 | 1935 |
1936 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { | 1936 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { |
1937 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1937 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
1938 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); | 1938 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); |
1939 PrepareChannel(&ch); | 1939 PrepareChannel(&ch); |
1940 ch.Connect(); | 1940 ch.Connect(); |
1941 ch.MaybeStartGathering(); | 1941 ch.MaybeStartGathering(); |
1942 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1942 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
1943 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 1943 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); |
1944 | 1944 |
1945 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1945 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
1946 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1946 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
1947 ASSERT_TRUE(conn1 != nullptr); | 1947 ASSERT_TRUE(conn1 != nullptr); |
1948 ASSERT_TRUE(conn2 != nullptr); | 1948 ASSERT_TRUE(conn2 != nullptr); |
(...skipping 10 matching lines...) Loading... |
1959 } | 1959 } |
1960 | 1960 |
1961 // Test adding remote candidates with different ufrags. If a remote candidate | 1961 // Test adding remote candidates with different ufrags. If a remote candidate |
1962 // is added with an old ufrag, it will be discarded. If it is added with a | 1962 // is added with an old ufrag, it will be discarded. If it is added with a |
1963 // ufrag that was not seen before, it will be used to create connections | 1963 // ufrag that was not seen before, it will be used to create connections |
1964 // although the ICE pwd in the remote candidate will be set when the ICE | 1964 // although the ICE pwd in the remote candidate will be set when the ICE |
1965 // credentials arrive. If a remote candidate is added with the current ICE | 1965 // credentials arrive. If a remote candidate is added with the current ICE |
1966 // ufrag, its pwd and generation will be set properly. | 1966 // ufrag, its pwd and generation will be set properly. |
1967 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { | 1967 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { |
1968 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1968 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
1969 cricket::P2PTransportChannel ch("add candidate", 1, nullptr, &pa); | 1969 cricket::P2PTransportChannel ch("add candidate", 1, &pa); |
1970 PrepareChannel(&ch); | 1970 PrepareChannel(&ch); |
1971 ch.Connect(); | 1971 ch.Connect(); |
1972 ch.MaybeStartGathering(); | 1972 ch.MaybeStartGathering(); |
1973 // Add a candidate with a future ufrag. | 1973 // Add a candidate with a future ufrag. |
1974 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1, kIceUfrag[2])); | 1974 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1, kIceUfrag[2])); |
1975 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1975 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
1976 ASSERT_TRUE(conn1 != nullptr); | 1976 ASSERT_TRUE(conn1 != nullptr); |
1977 const cricket::Candidate& candidate = conn1->remote_candidate(); | 1977 const cricket::Candidate& candidate = conn1->remote_candidate(); |
1978 EXPECT_EQ(kIceUfrag[2], candidate.username()); | 1978 EXPECT_EQ(kIceUfrag[2], candidate.username()); |
1979 EXPECT_TRUE(candidate.password().empty()); | 1979 EXPECT_TRUE(candidate.password().empty()); |
(...skipping 29 matching lines...) Loading... |
2009 if (candidate.username() == kIceUfrag[1]) { | 2009 if (candidate.username() == kIceUfrag[1]) { |
2010 EXPECT_EQ(kIcePwd[1], candidate.password()); | 2010 EXPECT_EQ(kIcePwd[1], candidate.password()); |
2011 } else if (candidate.username() == kIceUfrag[2]) { | 2011 } else if (candidate.username() == kIceUfrag[2]) { |
2012 EXPECT_EQ(kIcePwd[2], candidate.password()); | 2012 EXPECT_EQ(kIcePwd[2], candidate.password()); |
2013 } | 2013 } |
2014 } | 2014 } |
2015 } | 2015 } |
2016 | 2016 |
2017 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { | 2017 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { |
2018 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2018 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2019 cricket::P2PTransportChannel ch("connection resurrection", 1, nullptr, &pa); | 2019 cricket::P2PTransportChannel ch("connection resurrection", 1, &pa); |
2020 PrepareChannel(&ch); | 2020 PrepareChannel(&ch); |
2021 ch.Connect(); | 2021 ch.Connect(); |
2022 ch.MaybeStartGathering(); | 2022 ch.MaybeStartGathering(); |
2023 | 2023 |
2024 // Create conn1 and keep track of original candidate priority. | 2024 // Create conn1 and keep track of original candidate priority. |
2025 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 2025 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
2026 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2026 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2027 ASSERT_TRUE(conn1 != nullptr); | 2027 ASSERT_TRUE(conn1 != nullptr); |
2028 uint32_t remote_priority = conn1->remote_candidate().priority(); | 2028 uint32_t remote_priority = conn1->remote_candidate().priority(); |
2029 | 2029 |
(...skipping 32 matching lines...) Loading... |
2062 // conn3, a real prflx connection, should have prflx priority. | 2062 // conn3, a real prflx connection, should have prflx priority. |
2063 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), | 2063 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), |
2064 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2064 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
2065 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1); | 2065 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1); |
2066 ASSERT_TRUE(conn3 != nullptr); | 2066 ASSERT_TRUE(conn3 != nullptr); |
2067 EXPECT_EQ(conn3->remote_candidate().priority(), prflx_priority); | 2067 EXPECT_EQ(conn3->remote_candidate().priority(), prflx_priority); |
2068 } | 2068 } |
2069 | 2069 |
2070 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { | 2070 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { |
2071 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2071 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2072 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); | 2072 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); |
2073 PrepareChannel(&ch); | 2073 PrepareChannel(&ch); |
2074 // Default receiving timeout and checking receiving delay should not be too | 2074 // Default receiving timeout and checking receiving delay should not be too |
2075 // small. | 2075 // small. |
2076 EXPECT_LE(1000, ch.receiving_timeout()); | 2076 EXPECT_LE(1000, ch.receiving_timeout()); |
2077 EXPECT_LE(200, ch.check_receiving_delay()); | 2077 EXPECT_LE(200, ch.check_receiving_delay()); |
2078 ch.SetIceConfig(CreateIceConfig(500, false)); | 2078 ch.SetIceConfig(CreateIceConfig(500, false)); |
2079 EXPECT_EQ(500, ch.receiving_timeout()); | 2079 EXPECT_EQ(500, ch.receiving_timeout()); |
2080 EXPECT_EQ(50, ch.check_receiving_delay()); | 2080 EXPECT_EQ(50, ch.check_receiving_delay()); |
2081 ch.Connect(); | 2081 ch.Connect(); |
2082 ch.MaybeStartGathering(); | 2082 ch.MaybeStartGathering(); |
2083 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 2083 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
2084 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2084 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2085 ASSERT_TRUE(conn1 != nullptr); | 2085 ASSERT_TRUE(conn1 != nullptr); |
2086 | 2086 |
2087 conn1->ReceivedPing(); | 2087 conn1->ReceivedPing(); |
2088 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 2088 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
2089 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); | 2089 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); |
2090 EXPECT_TRUE_WAIT(ch.receiving(), 1000); | 2090 EXPECT_TRUE_WAIT(ch.receiving(), 1000); |
2091 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); | 2091 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); |
2092 } | 2092 } |
2093 | 2093 |
2094 // The controlled side will select a connection as the "best connection" based | 2094 // The controlled side will select a connection as the "best connection" based |
2095 // on priority until the controlling side nominates a connection, at which | 2095 // on priority until the controlling side nominates a connection, at which |
2096 // point the controlled side will select that connection as the | 2096 // point the controlled side will select that connection as the |
2097 // "best connection". | 2097 // "best connection". |
2098 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { | 2098 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { |
2099 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2099 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2100 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); | 2100 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); |
2101 PrepareChannel(&ch); | 2101 PrepareChannel(&ch); |
2102 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2102 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
2103 ch.Connect(); | 2103 ch.Connect(); |
2104 ch.MaybeStartGathering(); | 2104 ch.MaybeStartGathering(); |
2105 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 2105 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
2106 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2106 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2107 ASSERT_TRUE(conn1 != nullptr); | 2107 ASSERT_TRUE(conn1 != nullptr); |
2108 EXPECT_EQ(conn1, ch.best_connection()); | 2108 EXPECT_EQ(conn1, ch.best_connection()); |
2109 | 2109 |
2110 // When a higher priority candidate comes in, the new connection is chosen | 2110 // When a higher priority candidate comes in, the new connection is chosen |
(...skipping 36 matching lines...) Loading... |
2147 EXPECT_EQ(conn4, ch.best_connection()); | 2147 EXPECT_EQ(conn4, ch.best_connection()); |
2148 } | 2148 } |
2149 | 2149 |
2150 // The controlled side will select a connection as the "best connection" based | 2150 // The controlled side will select a connection as the "best connection" based |
2151 // on requests from an unknown address before the controlling side nominates | 2151 // on requests from an unknown address before the controlling side nominates |
2152 // a connection, and will nominate a connection from an unknown address if the | 2152 // a connection, and will nominate a connection from an unknown address if the |
2153 // request contains the use_candidate attribute. Plus, it will also sends back | 2153 // request contains the use_candidate attribute. Plus, it will also sends back |
2154 // a ping response and set the ICE pwd in the remote candidate appropriately. | 2154 // a ping response and set the ICE pwd in the remote candidate appropriately. |
2155 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { | 2155 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { |
2156 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2156 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2157 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); | 2157 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); |
2158 PrepareChannel(&ch); | 2158 PrepareChannel(&ch); |
2159 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2159 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
2160 ch.Connect(); | 2160 ch.Connect(); |
2161 ch.MaybeStartGathering(); | 2161 ch.MaybeStartGathering(); |
2162 // A minimal STUN message with prflx priority. | 2162 // A minimal STUN message with prflx priority. |
2163 cricket::IceMessage request; | 2163 cricket::IceMessage request; |
2164 request.SetType(cricket::STUN_BINDING_REQUEST); | 2164 request.SetType(cricket::STUN_BINDING_REQUEST); |
2165 request.AddAttribute(new cricket::StunByteStringAttribute( | 2165 request.AddAttribute(new cricket::StunByteStringAttribute( |
2166 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); | 2166 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); |
2167 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; | 2167 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; |
(...skipping 61 matching lines...) Loading... |
2229 EXPECT_TRUE(port->sent_binding_response()); | 2229 EXPECT_TRUE(port->sent_binding_response()); |
2230 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password()); | 2230 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password()); |
2231 } | 2231 } |
2232 | 2232 |
2233 // The controlled side will select a connection as the "best connection" | 2233 // The controlled side will select a connection as the "best connection" |
2234 // based on media received until the controlling side nominates a connection, | 2234 // based on media received until the controlling side nominates a connection, |
2235 // at which point the controlled side will select that connection as | 2235 // at which point the controlled side will select that connection as |
2236 // the "best connection". | 2236 // the "best connection". |
2237 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { | 2237 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { |
2238 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2238 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2239 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); | 2239 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); |
2240 PrepareChannel(&ch); | 2240 PrepareChannel(&ch); |
2241 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2241 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
2242 ch.Connect(); | 2242 ch.Connect(); |
2243 ch.MaybeStartGathering(); | 2243 ch.MaybeStartGathering(); |
2244 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 10)); | 2244 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 10)); |
2245 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2245 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2246 ASSERT_TRUE(conn1 != nullptr); | 2246 ASSERT_TRUE(conn1 != nullptr); |
2247 EXPECT_EQ(conn1, ch.best_connection()); | 2247 EXPECT_EQ(conn1, ch.best_connection()); |
2248 | 2248 |
2249 // If a data packet is received on conn2, the best connection should | 2249 // If a data packet is received on conn2, the best connection should |
(...skipping 37 matching lines...) Loading... |
2287 conn2->ReceivedPing(); | 2287 conn2->ReceivedPing(); |
2288 conn2->ReceivedPingResponse(); | 2288 conn2->ReceivedPingResponse(); |
2289 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 2289 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
2290 EXPECT_EQ(conn3, ch.best_connection()); | 2290 EXPECT_EQ(conn3, ch.best_connection()); |
2291 } | 2291 } |
2292 | 2292 |
2293 // When the current best connection is strong, lower-priority connections will | 2293 // When the current best connection is strong, lower-priority connections will |
2294 // be pruned. Otherwise, lower-priority connections are kept. | 2294 // be pruned. Otherwise, lower-priority connections are kept. |
2295 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { | 2295 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { |
2296 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2296 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2297 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa); | 2297 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
2298 PrepareChannel(&ch); | 2298 PrepareChannel(&ch); |
2299 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2299 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
2300 ch.Connect(); | 2300 ch.Connect(); |
2301 ch.MaybeStartGathering(); | 2301 ch.MaybeStartGathering(); |
2302 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 2302 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
2303 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2303 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2304 ASSERT_TRUE(conn1 != nullptr); | 2304 ASSERT_TRUE(conn1 != nullptr); |
2305 EXPECT_EQ(conn1, ch.best_connection()); | 2305 EXPECT_EQ(conn1, ch.best_connection()); |
2306 conn1->ReceivedPingResponse(); // Becomes writable and receiving | 2306 conn1->ReceivedPingResponse(); // Becomes writable and receiving |
2307 | 2307 |
(...skipping 17 matching lines...) Loading... |
2325 // The best connection should still be conn2. Even through conn3 has lower | 2325 // The best connection should still be conn2. Even through conn3 has lower |
2326 // priority and is not receiving/writable, it is not pruned because the best | 2326 // priority and is not receiving/writable, it is not pruned because the best |
2327 // connection is not receiving. | 2327 // connection is not receiving. |
2328 WAIT(conn3->pruned(), 1000); | 2328 WAIT(conn3->pruned(), 1000); |
2329 EXPECT_FALSE(conn3->pruned()); | 2329 EXPECT_FALSE(conn3->pruned()); |
2330 } | 2330 } |
2331 | 2331 |
2332 // Test that GetState returns the state correctly. | 2332 // Test that GetState returns the state correctly. |
2333 TEST_F(P2PTransportChannelPingTest, TestGetState) { | 2333 TEST_F(P2PTransportChannelPingTest, TestGetState) { |
2334 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2334 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2335 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa); | 2335 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
2336 PrepareChannel(&ch); | 2336 PrepareChannel(&ch); |
2337 ch.Connect(); | 2337 ch.Connect(); |
2338 ch.MaybeStartGathering(); | 2338 ch.MaybeStartGathering(); |
2339 EXPECT_EQ(cricket::TransportChannelState::STATE_INIT, ch.GetState()); | 2339 EXPECT_EQ(cricket::TransportChannelState::STATE_INIT, ch.GetState()); |
2340 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); | 2340 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); |
2341 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); | 2341 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); |
2342 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2342 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2343 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2343 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2344 ASSERT_TRUE(conn1 != nullptr); | 2344 ASSERT_TRUE(conn1 != nullptr); |
2345 ASSERT_TRUE(conn2 != nullptr); | 2345 ASSERT_TRUE(conn2 != nullptr); |
2346 // Now there are two connections, so the transport channel is connecting. | 2346 // Now there are two connections, so the transport channel is connecting. |
2347 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); | 2347 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); |
2348 // |conn1| becomes writable and receiving; it then should prune |conn2|. | 2348 // |conn1| becomes writable and receiving; it then should prune |conn2|. |
2349 conn1->ReceivedPingResponse(); | 2349 conn1->ReceivedPingResponse(); |
2350 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); | 2350 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); |
2351 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | 2351 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); |
2352 conn1->Prune(); // All connections are pruned. | 2352 conn1->Prune(); // All connections are pruned. |
2353 // Need to wait until the channel state is updated. | 2353 // Need to wait until the channel state is updated. |
2354 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_FAILED, ch.GetState(), | 2354 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_FAILED, ch.GetState(), |
2355 1000); | 2355 1000); |
2356 } | 2356 } |
2357 | 2357 |
2358 // Test that when a low-priority connection is pruned, it is not deleted | 2358 // Test that when a low-priority connection is pruned, it is not deleted |
2359 // right away, and it can become active and be pruned again. | 2359 // right away, and it can become active and be pruned again. |
2360 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { | 2360 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { |
2361 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2361 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2362 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa); | 2362 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
2363 PrepareChannel(&ch); | 2363 PrepareChannel(&ch); |
2364 ch.SetIceConfig(CreateIceConfig(1000, false)); | 2364 ch.SetIceConfig(CreateIceConfig(1000, false)); |
2365 ch.Connect(); | 2365 ch.Connect(); |
2366 ch.MaybeStartGathering(); | 2366 ch.MaybeStartGathering(); |
2367 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); | 2367 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); |
2368 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2368 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2369 ASSERT_TRUE(conn1 != nullptr); | 2369 ASSERT_TRUE(conn1 != nullptr); |
2370 EXPECT_EQ(conn1, ch.best_connection()); | 2370 EXPECT_EQ(conn1, ch.best_connection()); |
2371 conn1->ReceivedPingResponse(); // Becomes writable and receiving | 2371 conn1->ReceivedPingResponse(); // Becomes writable and receiving |
2372 | 2372 |
(...skipping 22 matching lines...) Loading... |
2395 conn1->ReceivedPingResponse(); | 2395 conn1->ReceivedPingResponse(); |
2396 EXPECT_EQ_WAIT(conn1, ch.best_connection(), 1000); | 2396 EXPECT_EQ_WAIT(conn1, ch.best_connection(), 1000); |
2397 EXPECT_TRUE_WAIT(!conn2->active(), 1000); | 2397 EXPECT_TRUE_WAIT(!conn2->active(), 1000); |
2398 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | 2398 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); |
2399 } | 2399 } |
2400 | 2400 |
2401 // Test that if all connections in a channel has timed out on writing, they | 2401 // Test that if all connections in a channel has timed out on writing, they |
2402 // will all be deleted. We use Prune to simulate write_time_out. | 2402 // will all be deleted. We use Prune to simulate write_time_out. |
2403 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { | 2403 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { |
2404 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2404 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2405 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa); | 2405 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
2406 PrepareChannel(&ch); | 2406 PrepareChannel(&ch); |
2407 ch.Connect(); | 2407 ch.Connect(); |
2408 ch.MaybeStartGathering(); | 2408 ch.MaybeStartGathering(); |
2409 // Have one connection only but later becomes write-time-out. | 2409 // Have one connection only but later becomes write-time-out. |
2410 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); | 2410 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); |
2411 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2411 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2412 ASSERT_TRUE(conn1 != nullptr); | 2412 ASSERT_TRUE(conn1 != nullptr); |
2413 conn1->ReceivedPing(); // Becomes receiving | 2413 conn1->ReceivedPing(); // Becomes receiving |
2414 conn1->Prune(); | 2414 conn1->Prune(); |
2415 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); | 2415 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); |
(...skipping 11 matching lines...) Loading... |
2427 conn2->Prune(); | 2427 conn2->Prune(); |
2428 conn3->Prune(); | 2428 conn3->Prune(); |
2429 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); | 2429 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); |
2430 } | 2430 } |
2431 | 2431 |
2432 // Test that after a port allocator session is started, it will be stopped | 2432 // Test that after a port allocator session is started, it will be stopped |
2433 // when a new connection becomes writable and receiving. Also test that this | 2433 // when a new connection becomes writable and receiving. Also test that this |
2434 // holds even if the transport channel did not lose the writability. | 2434 // holds even if the transport channel did not lose the writability. |
2435 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { | 2435 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { |
2436 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2436 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2437 cricket::P2PTransportChannel ch("test channel", 1, nullptr, &pa); | 2437 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
2438 PrepareChannel(&ch); | 2438 PrepareChannel(&ch); |
2439 ch.SetIceConfig(CreateIceConfig(2000, false)); | 2439 ch.SetIceConfig(CreateIceConfig(2000, false)); |
2440 ch.Connect(); | 2440 ch.Connect(); |
2441 ch.MaybeStartGathering(); | 2441 ch.MaybeStartGathering(); |
2442 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); | 2442 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); |
2443 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2443 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2444 ASSERT_TRUE(conn1 != nullptr); | 2444 ASSERT_TRUE(conn1 != nullptr); |
2445 conn1->ReceivedPingResponse(); // Becomes writable and receiving | 2445 conn1->ReceivedPingResponse(); // Becomes writable and receiving |
2446 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 2446 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
2447 | 2447 |
2448 // Restart gathering even if the transport channel is still writable. | 2448 // Restart gathering even if the transport channel is still writable. |
2449 // It should stop getting ports after a new connection becomes strongly | 2449 // It should stop getting ports after a new connection becomes strongly |
2450 // connected. | 2450 // connected. |
2451 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); | 2451 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); |
2452 ch.MaybeStartGathering(); | 2452 ch.MaybeStartGathering(); |
2453 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100)); | 2453 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100)); |
2454 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2454 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2455 ASSERT_TRUE(conn2 != nullptr); | 2455 ASSERT_TRUE(conn2 != nullptr); |
2456 conn2->ReceivedPingResponse(); // Becomes writable and receiving | 2456 conn2->ReceivedPingResponse(); // Becomes writable and receiving |
2457 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 2457 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
2458 } | 2458 } |
OLD | NEW |