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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // The addresses for the public relay server. | 74 // The addresses for the public relay server. |
75 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); | 75 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); |
76 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); | 76 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); |
77 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); | 77 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); |
78 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); | 78 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); |
79 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); | 79 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); |
80 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); | 80 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); |
81 // The addresses for the public turn server. | 81 // The addresses for the public turn server. |
82 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", | 82 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", |
83 cricket::STUN_SERVER_PORT); | 83 cricket::STUN_SERVER_PORT); |
| 84 static const SocketAddress kTurnTcpIntAddr("99.99.99.4", |
| 85 cricket::STUN_SERVER_PORT + 1); |
84 static const SocketAddress kTurnUdpExtAddr("99.99.99.5", 0); | 86 static const SocketAddress kTurnUdpExtAddr("99.99.99.5", 0); |
85 static const cricket::RelayCredentials kRelayCredentials("test", "test"); | 87 static const cricket::RelayCredentials kRelayCredentials("test", "test"); |
86 | 88 |
87 // Based on ICE_UFRAG_LENGTH | 89 // Based on ICE_UFRAG_LENGTH |
88 static const char* kIceUfrag[4] = {"TESTICEUFRAG0000", "TESTICEUFRAG0001", | 90 static const char* kIceUfrag[4] = {"TESTICEUFRAG0000", "TESTICEUFRAG0001", |
89 "TESTICEUFRAG0002", "TESTICEUFRAG0003"}; | 91 "TESTICEUFRAG0002", "TESTICEUFRAG0003"}; |
90 // Based on ICE_PWD_LENGTH | 92 // Based on ICE_PWD_LENGTH |
91 static const char* kIcePwd[4] = {"TESTICEPWD00000000000000", | 93 static const char* kIcePwd[4] = {"TESTICEPWD00000000000000", |
92 "TESTICEPWD00000000000001", | 94 "TESTICEPWD00000000000001", |
93 "TESTICEPWD00000000000002", | 95 "TESTICEPWD00000000000002", |
(...skipping 1764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1858 vss_(new rtc::VirtualSocketServer(pss_.get())), | 1860 vss_(new rtc::VirtualSocketServer(pss_.get())), |
1859 ss_scope_(vss_.get()) {} | 1861 ss_scope_(vss_.get()) {} |
1860 | 1862 |
1861 protected: | 1863 protected: |
1862 void PrepareChannel(cricket::P2PTransportChannel* ch) { | 1864 void PrepareChannel(cricket::P2PTransportChannel* ch) { |
1863 ch->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1865 ch->SetIceRole(cricket::ICEROLE_CONTROLLING); |
1864 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); | 1866 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); |
1865 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 1867 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
1866 } | 1868 } |
1867 | 1869 |
1868 cricket::Candidate CreateCandidate(const std::string& ip, | 1870 cricket::Candidate CreateHostCandidate(const std::string& ip, |
1869 int port, | 1871 int port, |
1870 int priority, | 1872 int priority, |
1871 const std::string& ufrag = "") { | 1873 const std::string& ufrag = "") { |
1872 cricket::Candidate c; | 1874 cricket::Candidate c; |
1873 c.set_address(rtc::SocketAddress(ip, port)); | 1875 c.set_address(rtc::SocketAddress(ip, port)); |
1874 c.set_component(1); | 1876 c.set_component(1); |
1875 c.set_protocol(cricket::UDP_PROTOCOL_NAME); | 1877 c.set_protocol(cricket::UDP_PROTOCOL_NAME); |
1876 c.set_priority(priority); | 1878 c.set_priority(priority); |
1877 c.set_username(ufrag); | 1879 c.set_username(ufrag); |
| 1880 c.set_type(cricket::LOCAL_PORT_TYPE); |
1878 return c; | 1881 return c; |
1879 } | 1882 } |
1880 | 1883 |
1881 cricket::Connection* WaitForConnectionTo(cricket::P2PTransportChannel* ch, | 1884 cricket::Connection* WaitForConnectionTo(cricket::P2PTransportChannel* ch, |
1882 const std::string& ip, | 1885 const std::string& ip, |
1883 int port_num) { | 1886 int port_num) { |
1884 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000); | 1887 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000); |
1885 return GetConnectionTo(ch, ip, port_num); | 1888 return GetConnectionTo(ch, ip, port_num); |
1886 } | 1889 } |
1887 | 1890 |
1888 cricket::Port* GetPort(cricket::P2PTransportChannel* ch) { | 1891 cricket::Port* GetPort(cricket::P2PTransportChannel* ch) { |
1889 if (ch->ports().empty()) { | 1892 if (ch->ports().empty()) { |
1890 return nullptr; | 1893 return nullptr; |
1891 } | 1894 } |
1892 return static_cast<cricket::Port*>(ch->ports()[0]); | 1895 return static_cast<cricket::Port*>(ch->ports()[0]); |
1893 } | 1896 } |
1894 | 1897 |
1895 cricket::Connection* GetConnectionTo(cricket::P2PTransportChannel* ch, | 1898 cricket::Connection* GetConnectionTo(cricket::P2PTransportChannel* ch, |
1896 const std::string& ip, | 1899 const std::string& ip, |
1897 int port_num) { | 1900 int port_num) { |
1898 cricket::Port* port = GetPort(ch); | 1901 cricket::Port* port = GetPort(ch); |
1899 if (!port) { | 1902 if (!port) { |
1900 return nullptr; | 1903 return nullptr; |
1901 } | 1904 } |
1902 return port->GetConnection(rtc::SocketAddress(ip, port_num)); | 1905 return port->GetConnection(rtc::SocketAddress(ip, port_num)); |
1903 } | 1906 } |
1904 | 1907 |
| 1908 cricket::Connection* FindNextPingableConnectionAndPingIt( |
| 1909 cricket::P2PTransportChannel* ch) { |
| 1910 cricket::Connection* conn = ch->FindNextPingableConnection(); |
| 1911 if (conn) { |
| 1912 ch->MarkConnectionPinged(conn); |
| 1913 } |
| 1914 return conn; |
| 1915 } |
| 1916 |
1905 private: | 1917 private: |
1906 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; | 1918 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
1907 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; | 1919 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; |
1908 rtc::SocketServerScope ss_scope_; | 1920 rtc::SocketServerScope ss_scope_; |
1909 }; | 1921 }; |
1910 | 1922 |
1911 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { | 1923 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { |
1912 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1924 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
1913 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); | 1925 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); |
1914 PrepareChannel(&ch); | 1926 PrepareChannel(&ch); |
1915 ch.Connect(); | 1927 ch.Connect(); |
1916 ch.MaybeStartGathering(); | 1928 ch.MaybeStartGathering(); |
1917 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1929 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
1918 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 1930 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); |
1919 | 1931 |
1920 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1932 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
1921 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1933 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
1922 ASSERT_TRUE(conn1 != nullptr); | 1934 ASSERT_TRUE(conn1 != nullptr); |
1923 ASSERT_TRUE(conn2 != nullptr); | 1935 ASSERT_TRUE(conn2 != nullptr); |
1924 | 1936 |
1925 // Before a triggered check, the first connection to ping is the | 1937 // Before a triggered check, the first connection to ping is the |
1926 // highest priority one. | 1938 // highest priority one. |
1927 EXPECT_EQ(conn2, ch.FindNextPingableConnection()); | 1939 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); |
1928 | 1940 |
1929 // Receiving a ping causes a triggered check which should make conn1 | 1941 // Receiving a ping causes a triggered check which should make conn1 |
1930 // be pinged first instead of conn2, even though conn2 has a higher | 1942 // be pinged first instead of conn2, even though conn2 has a higher |
1931 // priority. | 1943 // priority. |
1932 conn1->ReceivedPing(); | 1944 conn1->ReceivedPing(); |
1933 EXPECT_EQ(conn1, ch.FindNextPingableConnection()); | 1945 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); |
1934 } | 1946 } |
1935 | 1947 |
1936 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { | 1948 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { |
1937 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1949 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
1938 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); | 1950 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); |
1939 PrepareChannel(&ch); | 1951 PrepareChannel(&ch); |
1940 ch.Connect(); | 1952 ch.Connect(); |
1941 ch.MaybeStartGathering(); | 1953 ch.MaybeStartGathering(); |
1942 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1954 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
1943 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 1955 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); |
1944 | 1956 |
1945 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1957 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
1946 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1958 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
1947 ASSERT_TRUE(conn1 != nullptr); | 1959 ASSERT_TRUE(conn1 != nullptr); |
1948 ASSERT_TRUE(conn2 != nullptr); | 1960 ASSERT_TRUE(conn2 != nullptr); |
1949 | 1961 |
1950 EXPECT_EQ(conn2, ch.FindNextPingableConnection()); | 1962 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); |
| 1963 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); |
1951 conn1->ReceivedPingResponse(); | 1964 conn1->ReceivedPingResponse(); |
1952 ASSERT_TRUE(conn1->writable()); | 1965 ASSERT_TRUE(conn1->writable()); |
1953 conn1->ReceivedPing(); | 1966 conn1->ReceivedPing(); |
1954 | 1967 |
1955 // Ping received, but the connection is already writable, so no | 1968 // Ping received, but the connection is already writable, so no |
1956 // "triggered check" and conn2 is pinged before conn1 because it has | 1969 // "triggered check" and conn2 is pinged before conn1 because it has |
1957 // a higher priority. | 1970 // a higher priority. |
1958 EXPECT_EQ(conn2, ch.FindNextPingableConnection()); | 1971 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); |
1959 } | 1972 } |
1960 | 1973 |
1961 // Test adding remote candidates with different ufrags. If a remote candidate | 1974 // 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 | 1975 // 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 | 1976 // 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 | 1977 // 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 | 1978 // credentials arrive. If a remote candidate is added with the current ICE |
1966 // ufrag, its pwd and generation will be set properly. | 1979 // ufrag, its pwd and generation will be set properly. |
1967 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { | 1980 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { |
1968 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1981 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
1969 cricket::P2PTransportChannel ch("add candidate", 1, &pa); | 1982 cricket::P2PTransportChannel ch("add candidate", 1, &pa); |
1970 PrepareChannel(&ch); | 1983 PrepareChannel(&ch); |
1971 ch.Connect(); | 1984 ch.Connect(); |
1972 ch.MaybeStartGathering(); | 1985 ch.MaybeStartGathering(); |
1973 // Add a candidate with a future ufrag. | 1986 // Add a candidate with a future ufrag. |
1974 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1, kIceUfrag[2])); | 1987 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1, kIceUfrag[2])); |
1975 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1988 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
1976 ASSERT_TRUE(conn1 != nullptr); | 1989 ASSERT_TRUE(conn1 != nullptr); |
1977 const cricket::Candidate& candidate = conn1->remote_candidate(); | 1990 const cricket::Candidate& candidate = conn1->remote_candidate(); |
1978 EXPECT_EQ(kIceUfrag[2], candidate.username()); | 1991 EXPECT_EQ(kIceUfrag[2], candidate.username()); |
1979 EXPECT_TRUE(candidate.password().empty()); | 1992 EXPECT_TRUE(candidate.password().empty()); |
1980 EXPECT_TRUE(ch.FindNextPingableConnection() == nullptr); | 1993 EXPECT_TRUE(FindNextPingableConnectionAndPingIt(&ch) == nullptr); |
1981 | 1994 |
1982 // Set the remote credentials with the "future" ufrag. | 1995 // Set the remote credentials with the "future" ufrag. |
1983 // This should set the ICE pwd in the remote candidate of |conn1|, making | 1996 // This should set the ICE pwd in the remote candidate of |conn1|, making |
1984 // it pingable. | 1997 // it pingable. |
1985 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); | 1998 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); |
1986 EXPECT_EQ(kIceUfrag[2], candidate.username()); | 1999 EXPECT_EQ(kIceUfrag[2], candidate.username()); |
1987 EXPECT_EQ(kIcePwd[2], candidate.password()); | 2000 EXPECT_EQ(kIcePwd[2], candidate.password()); |
1988 EXPECT_EQ(conn1, ch.FindNextPingableConnection()); | 2001 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); |
1989 | 2002 |
1990 // Add a candidate with an old ufrag. No connection will be created. | 2003 // Add a candidate with an old ufrag. No connection will be created. |
1991 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2, kIceUfrag[1])); | 2004 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2, kIceUfrag[1])); |
1992 rtc::Thread::Current()->ProcessMessages(500); | 2005 rtc::Thread::Current()->ProcessMessages(500); |
1993 EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr); | 2006 EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr); |
1994 | 2007 |
1995 // Add a candidate with the current ufrag, its pwd and generation will be | 2008 // Add a candidate with the current ufrag, its pwd and generation will be |
1996 // assigned, even if the generation is not set. | 2009 // assigned, even if the generation is not set. |
1997 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 0, kIceUfrag[2])); | 2010 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 0, kIceUfrag[2])); |
1998 cricket::Connection* conn3 = nullptr; | 2011 cricket::Connection* conn3 = nullptr; |
1999 ASSERT_TRUE_WAIT((conn3 = GetConnectionTo(&ch, "3.3.3.3", 3)) != nullptr, | 2012 ASSERT_TRUE_WAIT((conn3 = GetConnectionTo(&ch, "3.3.3.3", 3)) != nullptr, |
2000 3000); | 2013 3000); |
2001 const cricket::Candidate& new_candidate = conn3->remote_candidate(); | 2014 const cricket::Candidate& new_candidate = conn3->remote_candidate(); |
2002 EXPECT_EQ(kIcePwd[2], new_candidate.password()); | 2015 EXPECT_EQ(kIcePwd[2], new_candidate.password()); |
2003 EXPECT_EQ(1U, new_candidate.generation()); | 2016 EXPECT_EQ(1U, new_candidate.generation()); |
2004 | 2017 |
2005 // Check that the pwd of all remote candidates are properly assigned. | 2018 // Check that the pwd of all remote candidates are properly assigned. |
2006 for (const cricket::RemoteCandidate& candidate : ch.remote_candidates()) { | 2019 for (const cricket::RemoteCandidate& candidate : ch.remote_candidates()) { |
2007 EXPECT_TRUE(candidate.username() == kIceUfrag[1] || | 2020 EXPECT_TRUE(candidate.username() == kIceUfrag[1] || |
2008 candidate.username() == kIceUfrag[2]); | 2021 candidate.username() == kIceUfrag[2]); |
2009 if (candidate.username() == kIceUfrag[1]) { | 2022 if (candidate.username() == kIceUfrag[1]) { |
2010 EXPECT_EQ(kIcePwd[1], candidate.password()); | 2023 EXPECT_EQ(kIcePwd[1], candidate.password()); |
2011 } else if (candidate.username() == kIceUfrag[2]) { | 2024 } else if (candidate.username() == kIceUfrag[2]) { |
2012 EXPECT_EQ(kIcePwd[2], candidate.password()); | 2025 EXPECT_EQ(kIcePwd[2], candidate.password()); |
2013 } | 2026 } |
2014 } | 2027 } |
2015 } | 2028 } |
2016 | 2029 |
2017 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { | 2030 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { |
2018 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2031 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2019 cricket::P2PTransportChannel ch("connection resurrection", 1, &pa); | 2032 cricket::P2PTransportChannel ch("connection resurrection", 1, &pa); |
2020 PrepareChannel(&ch); | 2033 PrepareChannel(&ch); |
2021 ch.Connect(); | 2034 ch.Connect(); |
2022 ch.MaybeStartGathering(); | 2035 ch.MaybeStartGathering(); |
2023 | 2036 |
2024 // Create conn1 and keep track of original candidate priority. | 2037 // Create conn1 and keep track of original candidate priority. |
2025 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 2038 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
2026 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2039 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2027 ASSERT_TRUE(conn1 != nullptr); | 2040 ASSERT_TRUE(conn1 != nullptr); |
2028 uint32_t remote_priority = conn1->remote_candidate().priority(); | 2041 uint32_t remote_priority = conn1->remote_candidate().priority(); |
2029 | 2042 |
2030 // Create a higher priority candidate and make the connection | 2043 // Create a higher priority candidate and make the connection |
2031 // receiving/writable. This will prune conn1. | 2044 // receiving/writable. This will prune conn1. |
2032 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 2045 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); |
2033 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2046 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2034 ASSERT_TRUE(conn2 != nullptr); | 2047 ASSERT_TRUE(conn2 != nullptr); |
2035 conn2->ReceivedPing(); | 2048 conn2->ReceivedPing(); |
2036 conn2->ReceivedPingResponse(); | 2049 conn2->ReceivedPingResponse(); |
2037 | 2050 |
2038 // Wait for conn1 to be pruned. | 2051 // Wait for conn1 to be pruned. |
2039 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); | 2052 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); |
2040 // Destroy the connection to test SignalUnknownAddress. | 2053 // Destroy the connection to test SignalUnknownAddress. |
2041 conn1->Destroy(); | 2054 conn1->Destroy(); |
2042 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000); | 2055 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000); |
(...skipping 30 matching lines...) Expand all Loading... |
2073 PrepareChannel(&ch); | 2086 PrepareChannel(&ch); |
2074 // Default receiving timeout and checking receiving delay should not be too | 2087 // Default receiving timeout and checking receiving delay should not be too |
2075 // small. | 2088 // small. |
2076 EXPECT_LE(1000, ch.receiving_timeout()); | 2089 EXPECT_LE(1000, ch.receiving_timeout()); |
2077 EXPECT_LE(200, ch.check_receiving_delay()); | 2090 EXPECT_LE(200, ch.check_receiving_delay()); |
2078 ch.SetIceConfig(CreateIceConfig(500, false)); | 2091 ch.SetIceConfig(CreateIceConfig(500, false)); |
2079 EXPECT_EQ(500, ch.receiving_timeout()); | 2092 EXPECT_EQ(500, ch.receiving_timeout()); |
2080 EXPECT_EQ(50, ch.check_receiving_delay()); | 2093 EXPECT_EQ(50, ch.check_receiving_delay()); |
2081 ch.Connect(); | 2094 ch.Connect(); |
2082 ch.MaybeStartGathering(); | 2095 ch.MaybeStartGathering(); |
2083 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 2096 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
2084 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2097 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2085 ASSERT_TRUE(conn1 != nullptr); | 2098 ASSERT_TRUE(conn1 != nullptr); |
2086 | 2099 |
2087 conn1->ReceivedPing(); | 2100 conn1->ReceivedPing(); |
2088 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 2101 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
2089 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); | 2102 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); |
2090 EXPECT_TRUE_WAIT(ch.receiving(), 1000); | 2103 EXPECT_TRUE_WAIT(ch.receiving(), 1000); |
2091 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); | 2104 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); |
2092 } | 2105 } |
2093 | 2106 |
2094 // The controlled side will select a connection as the "best connection" based | 2107 // The controlled side will select a connection as the "best connection" based |
2095 // on priority until the controlling side nominates a connection, at which | 2108 // on priority until the controlling side nominates a connection, at which |
2096 // point the controlled side will select that connection as the | 2109 // point the controlled side will select that connection as the |
2097 // "best connection". | 2110 // "best connection". |
2098 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { | 2111 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { |
2099 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2112 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2100 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 2113 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); |
2101 PrepareChannel(&ch); | 2114 PrepareChannel(&ch); |
2102 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2115 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
2103 ch.Connect(); | 2116 ch.Connect(); |
2104 ch.MaybeStartGathering(); | 2117 ch.MaybeStartGathering(); |
2105 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 2118 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
2106 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2119 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2107 ASSERT_TRUE(conn1 != nullptr); | 2120 ASSERT_TRUE(conn1 != nullptr); |
2108 EXPECT_EQ(conn1, ch.best_connection()); | 2121 EXPECT_EQ(conn1, ch.best_connection()); |
2109 | 2122 |
2110 // When a higher priority candidate comes in, the new connection is chosen | 2123 // When a higher priority candidate comes in, the new connection is chosen |
2111 // as the best connection. | 2124 // as the best connection. |
2112 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 10)); | 2125 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); |
2113 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2126 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2114 ASSERT_TRUE(conn2 != nullptr); | 2127 ASSERT_TRUE(conn2 != nullptr); |
2115 EXPECT_EQ(conn2, ch.best_connection()); | 2128 EXPECT_EQ(conn2, ch.best_connection()); |
2116 | 2129 |
2117 // If a stun request with use-candidate attribute arrives, the receiving | 2130 // If a stun request with use-candidate attribute arrives, the receiving |
2118 // connection will be set as the best connection, even though | 2131 // connection will be set as the best connection, even though |
2119 // its priority is lower. | 2132 // its priority is lower. |
2120 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1)); | 2133 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); |
2121 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2134 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
2122 ASSERT_TRUE(conn3 != nullptr); | 2135 ASSERT_TRUE(conn3 != nullptr); |
2123 // Because it has a lower priority, the best connection is still conn2. | 2136 // Because it has a lower priority, the best connection is still conn2. |
2124 EXPECT_EQ(conn2, ch.best_connection()); | 2137 EXPECT_EQ(conn2, ch.best_connection()); |
2125 conn3->ReceivedPingResponse(); // Become writable. | 2138 conn3->ReceivedPingResponse(); // Become writable. |
2126 // But if it is nominated via use_candidate, it is chosen as the best | 2139 // But if it is nominated via use_candidate, it is chosen as the best |
2127 // connection. | 2140 // connection. |
2128 conn3->set_nominated(true); | 2141 conn3->set_nominated(true); |
2129 conn3->SignalNominated(conn3); | 2142 conn3->SignalNominated(conn3); |
2130 EXPECT_EQ(conn3, ch.best_connection()); | 2143 EXPECT_EQ(conn3, ch.best_connection()); |
2131 | 2144 |
2132 // Even if another higher priority candidate arrives, | 2145 // Even if another higher priority candidate arrives, |
2133 // it will not be set as the best connection because the best connection | 2146 // it will not be set as the best connection because the best connection |
2134 // is nominated by the controlling side. | 2147 // is nominated by the controlling side. |
2135 ch.AddRemoteCandidate(CreateCandidate("4.4.4.4", 4, 100)); | 2148 ch.AddRemoteCandidate(CreateHostCandidate("4.4.4.4", 4, 100)); |
2136 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); | 2149 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); |
2137 ASSERT_TRUE(conn4 != nullptr); | 2150 ASSERT_TRUE(conn4 != nullptr); |
2138 EXPECT_EQ(conn3, ch.best_connection()); | 2151 EXPECT_EQ(conn3, ch.best_connection()); |
2139 // But if it is nominated via use_candidate and writable, it will be set as | 2152 // But if it is nominated via use_candidate and writable, it will be set as |
2140 // the best connection. | 2153 // the best connection. |
2141 conn4->set_nominated(true); | 2154 conn4->set_nominated(true); |
2142 conn4->SignalNominated(conn4); | 2155 conn4->SignalNominated(conn4); |
2143 // Not switched yet because conn4 is not writable. | 2156 // Not switched yet because conn4 is not writable. |
2144 EXPECT_EQ(conn3, ch.best_connection()); | 2157 EXPECT_EQ(conn3, ch.best_connection()); |
2145 // The best connection switches after conn4 becomes writable. | 2158 // The best connection switches after conn4 becomes writable. |
(...skipping 26 matching lines...) Expand all Loading... |
2172 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 2185 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
2173 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2186 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2174 ASSERT_TRUE(conn1 != nullptr); | 2187 ASSERT_TRUE(conn1 != nullptr); |
2175 EXPECT_TRUE(port->sent_binding_response()); | 2188 EXPECT_TRUE(port->sent_binding_response()); |
2176 EXPECT_EQ(conn1, ch.best_connection()); | 2189 EXPECT_EQ(conn1, ch.best_connection()); |
2177 conn1->ReceivedPingResponse(); | 2190 conn1->ReceivedPingResponse(); |
2178 EXPECT_EQ(conn1, ch.best_connection()); | 2191 EXPECT_EQ(conn1, ch.best_connection()); |
2179 port->set_sent_binding_response(false); | 2192 port->set_sent_binding_response(false); |
2180 | 2193 |
2181 // Another connection is nominated via use_candidate. | 2194 // Another connection is nominated via use_candidate. |
2182 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); | 2195 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); |
2183 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2196 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2184 ASSERT_TRUE(conn2 != nullptr); | 2197 ASSERT_TRUE(conn2 != nullptr); |
2185 // Because it has a lower priority, the best connection is still conn1. | 2198 // Because it has a lower priority, the best connection is still conn1. |
2186 EXPECT_EQ(conn1, ch.best_connection()); | 2199 EXPECT_EQ(conn1, ch.best_connection()); |
2187 // When it is nominated via use_candidate and writable, it is chosen as the | 2200 // When it is nominated via use_candidate and writable, it is chosen as the |
2188 // best connection. | 2201 // best connection. |
2189 conn2->ReceivedPingResponse(); // Become writable. | 2202 conn2->ReceivedPingResponse(); // Become writable. |
2190 conn2->set_nominated(true); | 2203 conn2->set_nominated(true); |
2191 conn2->SignalNominated(conn2); | 2204 conn2->SignalNominated(conn2); |
2192 EXPECT_EQ(conn2, ch.best_connection()); | 2205 EXPECT_EQ(conn2, ch.best_connection()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2234 // based on media received until the controlling side nominates a connection, | 2247 // based on media received until the controlling side nominates a connection, |
2235 // at which point the controlled side will select that connection as | 2248 // at which point the controlled side will select that connection as |
2236 // the "best connection". | 2249 // the "best connection". |
2237 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { | 2250 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { |
2238 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2251 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2239 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); | 2252 cricket::P2PTransportChannel ch("receiving state change", 1, &pa); |
2240 PrepareChannel(&ch); | 2253 PrepareChannel(&ch); |
2241 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2254 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
2242 ch.Connect(); | 2255 ch.Connect(); |
2243 ch.MaybeStartGathering(); | 2256 ch.MaybeStartGathering(); |
2244 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 10)); | 2257 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 10)); |
2245 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2258 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2246 ASSERT_TRUE(conn1 != nullptr); | 2259 ASSERT_TRUE(conn1 != nullptr); |
2247 EXPECT_EQ(conn1, ch.best_connection()); | 2260 EXPECT_EQ(conn1, ch.best_connection()); |
2248 | 2261 |
2249 // If a data packet is received on conn2, the best connection should | 2262 // If a data packet is received on conn2, the best connection should |
2250 // switch to conn2 because the controlled side must mirror the media path | 2263 // switch to conn2 because the controlled side must mirror the media path |
2251 // chosen by the controlling side. | 2264 // chosen by the controlling side. |
2252 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); | 2265 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); |
2253 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2266 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2254 ASSERT_TRUE(conn2 != nullptr); | 2267 ASSERT_TRUE(conn2 != nullptr); |
2255 conn2->ReceivedPing(); // Start receiving. | 2268 conn2->ReceivedPing(); // Start receiving. |
2256 // Do not switch because it is not writable. | 2269 // Do not switch because it is not writable. |
2257 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 2270 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
2258 EXPECT_EQ(conn1, ch.best_connection()); | 2271 EXPECT_EQ(conn1, ch.best_connection()); |
2259 | 2272 |
2260 conn2->ReceivedPingResponse(); // Become writable. | 2273 conn2->ReceivedPingResponse(); // Become writable. |
2261 // Switch because it is writable. | 2274 // Switch because it is writable. |
2262 conn2->OnReadPacket("DEF", 3, rtc::CreatePacketTime(0)); | 2275 conn2->OnReadPacket("DEF", 3, rtc::CreatePacketTime(0)); |
(...skipping 29 matching lines...) Expand all Loading... |
2292 | 2305 |
2293 // When the current best connection is strong, lower-priority connections will | 2306 // When the current best connection is strong, lower-priority connections will |
2294 // be pruned. Otherwise, lower-priority connections are kept. | 2307 // be pruned. Otherwise, lower-priority connections are kept. |
2295 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { | 2308 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { |
2296 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2309 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2297 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2310 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
2298 PrepareChannel(&ch); | 2311 PrepareChannel(&ch); |
2299 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 2312 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
2300 ch.Connect(); | 2313 ch.Connect(); |
2301 ch.MaybeStartGathering(); | 2314 ch.MaybeStartGathering(); |
2302 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 2315 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
2303 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2316 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2304 ASSERT_TRUE(conn1 != nullptr); | 2317 ASSERT_TRUE(conn1 != nullptr); |
2305 EXPECT_EQ(conn1, ch.best_connection()); | 2318 EXPECT_EQ(conn1, ch.best_connection()); |
2306 conn1->ReceivedPingResponse(); // Becomes writable and receiving | 2319 conn1->ReceivedPingResponse(); // Becomes writable and receiving |
2307 | 2320 |
2308 // When a higher-priority, nominated candidate comes in, the connections with | 2321 // When a higher-priority, nominated candidate comes in, the connections with |
2309 // lower-priority are pruned. | 2322 // lower-priority are pruned. |
2310 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 10)); | 2323 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10)); |
2311 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2324 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2312 ASSERT_TRUE(conn2 != nullptr); | 2325 ASSERT_TRUE(conn2 != nullptr); |
2313 conn2->ReceivedPingResponse(); // Becomes writable and receiving | 2326 conn2->ReceivedPingResponse(); // Becomes writable and receiving |
2314 conn2->set_nominated(true); | 2327 conn2->set_nominated(true); |
2315 conn2->SignalNominated(conn2); | 2328 conn2->SignalNominated(conn2); |
2316 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); | 2329 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); |
2317 | 2330 |
2318 ch.SetIceConfig(CreateIceConfig(500, false)); | 2331 ch.SetIceConfig(CreateIceConfig(500, false)); |
2319 // Wait until conn2 becomes not receiving. | 2332 // Wait until conn2 becomes not receiving. |
2320 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); | 2333 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); |
2321 | 2334 |
2322 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1)); | 2335 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1)); |
2323 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2336 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
2324 ASSERT_TRUE(conn3 != nullptr); | 2337 ASSERT_TRUE(conn3 != nullptr); |
2325 // The best connection should still be conn2. Even through conn3 has lower | 2338 // 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 | 2339 // priority and is not receiving/writable, it is not pruned because the best |
2327 // connection is not receiving. | 2340 // connection is not receiving. |
2328 WAIT(conn3->pruned(), 1000); | 2341 WAIT(conn3->pruned(), 1000); |
2329 EXPECT_FALSE(conn3->pruned()); | 2342 EXPECT_FALSE(conn3->pruned()); |
2330 } | 2343 } |
2331 | 2344 |
2332 // Test that GetState returns the state correctly. | 2345 // Test that GetState returns the state correctly. |
2333 TEST_F(P2PTransportChannelPingTest, TestGetState) { | 2346 TEST_F(P2PTransportChannelPingTest, TestGetState) { |
2334 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2347 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2335 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2348 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
2336 PrepareChannel(&ch); | 2349 PrepareChannel(&ch); |
2337 ch.Connect(); | 2350 ch.Connect(); |
2338 ch.MaybeStartGathering(); | 2351 ch.MaybeStartGathering(); |
2339 EXPECT_EQ(cricket::TransportChannelState::STATE_INIT, ch.GetState()); | 2352 EXPECT_EQ(cricket::TransportChannelState::STATE_INIT, ch.GetState()); |
2340 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); | 2353 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); |
2341 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); | 2354 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); |
2342 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2355 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2343 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2356 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2344 ASSERT_TRUE(conn1 != nullptr); | 2357 ASSERT_TRUE(conn1 != nullptr); |
2345 ASSERT_TRUE(conn2 != nullptr); | 2358 ASSERT_TRUE(conn2 != nullptr); |
2346 // Now there are two connections, so the transport channel is connecting. | 2359 // Now there are two connections, so the transport channel is connecting. |
2347 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); | 2360 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState()); |
2348 // |conn1| becomes writable and receiving; it then should prune |conn2|. | 2361 // |conn1| becomes writable and receiving; it then should prune |conn2|. |
2349 conn1->ReceivedPingResponse(); | 2362 conn1->ReceivedPingResponse(); |
2350 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); | 2363 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); |
2351 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | 2364 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); |
2352 conn1->Prune(); // All connections are pruned. | 2365 conn1->Prune(); // All connections are pruned. |
2353 // Need to wait until the channel state is updated. | 2366 // Need to wait until the channel state is updated. |
2354 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_FAILED, ch.GetState(), | 2367 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_FAILED, ch.GetState(), |
2355 1000); | 2368 1000); |
2356 } | 2369 } |
2357 | 2370 |
2358 // Test that when a low-priority connection is pruned, it is not deleted | 2371 // 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. | 2372 // right away, and it can become active and be pruned again. |
2360 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { | 2373 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { |
2361 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2374 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2362 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2375 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
2363 PrepareChannel(&ch); | 2376 PrepareChannel(&ch); |
2364 ch.SetIceConfig(CreateIceConfig(1000, false)); | 2377 ch.SetIceConfig(CreateIceConfig(1000, false)); |
2365 ch.Connect(); | 2378 ch.Connect(); |
2366 ch.MaybeStartGathering(); | 2379 ch.MaybeStartGathering(); |
2367 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); | 2380 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); |
2368 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2381 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2369 ASSERT_TRUE(conn1 != nullptr); | 2382 ASSERT_TRUE(conn1 != nullptr); |
2370 EXPECT_EQ(conn1, ch.best_connection()); | 2383 EXPECT_EQ(conn1, ch.best_connection()); |
2371 conn1->ReceivedPingResponse(); // Becomes writable and receiving | 2384 conn1->ReceivedPingResponse(); // Becomes writable and receiving |
2372 | 2385 |
2373 // Add a low-priority connection |conn2|, which will be pruned, but it will | 2386 // Add a low-priority connection |conn2|, which will be pruned, but it will |
2374 // not be deleted right away. Once the current best connection becomes not | 2387 // not be deleted right away. Once the current best connection becomes not |
2375 // receiving, |conn2| will start to ping and upon receiving the ping response, | 2388 // receiving, |conn2| will start to ping and upon receiving the ping response, |
2376 // it will become the best connection. | 2389 // it will become the best connection. |
2377 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); | 2390 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); |
2378 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2391 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2379 ASSERT_TRUE(conn2 != nullptr); | 2392 ASSERT_TRUE(conn2 != nullptr); |
2380 EXPECT_TRUE_WAIT(!conn2->active(), 1000); | 2393 EXPECT_TRUE_WAIT(!conn2->active(), 1000); |
2381 // |conn2| should not send a ping yet. | 2394 // |conn2| should not send a ping yet. |
2382 EXPECT_EQ(cricket::Connection::STATE_WAITING, conn2->state()); | 2395 EXPECT_EQ(cricket::Connection::STATE_WAITING, conn2->state()); |
2383 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); | 2396 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState()); |
2384 // Wait for |conn1| becoming not receiving. | 2397 // Wait for |conn1| becoming not receiving. |
2385 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); | 2398 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); |
2386 // Make sure conn2 is not deleted. | 2399 // Make sure conn2 is not deleted. |
2387 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2400 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
(...skipping 12 matching lines...) Expand all Loading... |
2400 | 2413 |
2401 // Test that if all connections in a channel has timed out on writing, they | 2414 // 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. | 2415 // will all be deleted. We use Prune to simulate write_time_out. |
2403 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { | 2416 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { |
2404 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2417 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2405 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2418 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
2406 PrepareChannel(&ch); | 2419 PrepareChannel(&ch); |
2407 ch.Connect(); | 2420 ch.Connect(); |
2408 ch.MaybeStartGathering(); | 2421 ch.MaybeStartGathering(); |
2409 // Have one connection only but later becomes write-time-out. | 2422 // Have one connection only but later becomes write-time-out. |
2410 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); | 2423 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); |
2411 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2424 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2412 ASSERT_TRUE(conn1 != nullptr); | 2425 ASSERT_TRUE(conn1 != nullptr); |
2413 conn1->ReceivedPing(); // Becomes receiving | 2426 conn1->ReceivedPing(); // Becomes receiving |
2414 conn1->Prune(); | 2427 conn1->Prune(); |
2415 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); | 2428 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); |
2416 | 2429 |
2417 // Have two connections but both become write-time-out later. | 2430 // Have two connections but both become write-time-out later. |
2418 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); | 2431 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1)); |
2419 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2432 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2420 ASSERT_TRUE(conn2 != nullptr); | 2433 ASSERT_TRUE(conn2 != nullptr); |
2421 conn2->ReceivedPing(); // Becomes receiving | 2434 conn2->ReceivedPing(); // Becomes receiving |
2422 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 2)); | 2435 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 2)); |
2423 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 2436 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
2424 ASSERT_TRUE(conn3 != nullptr); | 2437 ASSERT_TRUE(conn3 != nullptr); |
2425 conn3->ReceivedPing(); // Becomes receiving | 2438 conn3->ReceivedPing(); // Becomes receiving |
2426 // Now prune both conn2 and conn3; they will be deleted soon. | 2439 // Now prune both conn2 and conn3; they will be deleted soon. |
2427 conn2->Prune(); | 2440 conn2->Prune(); |
2428 conn3->Prune(); | 2441 conn3->Prune(); |
2429 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); | 2442 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); |
2430 } | 2443 } |
2431 | 2444 |
2432 // Test that after a port allocator session is started, it will be stopped | 2445 // 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 | 2446 // when a new connection becomes writable and receiving. Also test that this |
2434 // holds even if the transport channel did not lose the writability. | 2447 // holds even if the transport channel did not lose the writability. |
2435 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { | 2448 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { |
2436 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2449 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
2437 cricket::P2PTransportChannel ch("test channel", 1, &pa); | 2450 cricket::P2PTransportChannel ch("test channel", 1, &pa); |
2438 PrepareChannel(&ch); | 2451 PrepareChannel(&ch); |
2439 ch.SetIceConfig(CreateIceConfig(2000, false)); | 2452 ch.SetIceConfig(CreateIceConfig(2000, false)); |
2440 ch.Connect(); | 2453 ch.Connect(); |
2441 ch.MaybeStartGathering(); | 2454 ch.MaybeStartGathering(); |
2442 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 100)); | 2455 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100)); |
2443 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2456 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
2444 ASSERT_TRUE(conn1 != nullptr); | 2457 ASSERT_TRUE(conn1 != nullptr); |
2445 conn1->ReceivedPingResponse(); // Becomes writable and receiving | 2458 conn1->ReceivedPingResponse(); // Becomes writable and receiving |
2446 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 2459 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
2447 | 2460 |
2448 // Restart gathering even if the transport channel is still writable. | 2461 // Restart gathering even if the transport channel is still writable. |
2449 // It should stop getting ports after a new connection becomes strongly | 2462 // It should stop getting ports after a new connection becomes strongly |
2450 // connected. | 2463 // connected. |
2451 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); | 2464 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); |
2452 ch.MaybeStartGathering(); | 2465 ch.MaybeStartGathering(); |
2453 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100)); | 2466 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 100)); |
2454 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2467 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2455 ASSERT_TRUE(conn2 != nullptr); | 2468 ASSERT_TRUE(conn2 != nullptr); |
2456 conn2->ReceivedPingResponse(); // Becomes writable and receiving | 2469 conn2->ReceivedPingResponse(); // Becomes writable and receiving |
2457 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 2470 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
2458 } | 2471 } |
| 2472 |
| 2473 class P2PTransportChannelMostLikelyToWorkFirstTest |
| 2474 : public P2PTransportChannelPingTest { |
| 2475 public: |
| 2476 P2PTransportChannelMostLikelyToWorkFirstTest() |
| 2477 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) { |
| 2478 network_manager_.AddInterface(kPublicAddrs[0]); |
| 2479 allocator_.reset(new cricket::BasicPortAllocator( |
| 2480 &network_manager_, ServerAddresses(), rtc::SocketAddress(), |
| 2481 rtc::SocketAddress(), rtc::SocketAddress())); |
| 2482 allocator_->set_flags(allocator_->flags() | |
| 2483 cricket::PORTALLOCATOR_DISABLE_STUN | |
| 2484 cricket::PORTALLOCATOR_DISABLE_TCP); |
| 2485 cricket::RelayServerConfig config(cricket::RELAY_TURN); |
| 2486 config.credentials = kRelayCredentials; |
| 2487 config.ports.push_back( |
| 2488 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); |
| 2489 allocator_->AddTurnServer(config); |
| 2490 allocator_->set_step_delay(kMinimumStepDelay); |
| 2491 } |
| 2492 |
| 2493 cricket::P2PTransportChannel& StartTransportChannel( |
| 2494 bool prioritize_most_likely_to_work, |
| 2495 uint32_t max_strong_delay) { |
| 2496 channel_.reset( |
| 2497 new cricket::P2PTransportChannel("checks", 1, nullptr, allocator())); |
| 2498 cricket::IceConfig config = channel_->config(); |
| 2499 config.prioritize_most_likely_candidate_pairs = |
| 2500 prioritize_most_likely_to_work; |
| 2501 config.max_strong_delay = max_strong_delay; |
| 2502 channel_->SetIceConfig(config); |
| 2503 PrepareChannel(channel_.get()); |
| 2504 channel_->Connect(); |
| 2505 channel_->MaybeStartGathering(); |
| 2506 return *channel_.get(); |
| 2507 } |
| 2508 |
| 2509 cricket::BasicPortAllocator* allocator() { return allocator_.get(); } |
| 2510 cricket::TestTurnServer* turn_server() { return &turn_server_; } |
| 2511 |
| 2512 // This verifies the next pingable connection has the expected candidates' |
| 2513 // types and, for relay local candidate, the expected relay protocol and ping |
| 2514 // it. |
| 2515 void VerifyNextPingableConnection( |
| 2516 const std::string& local_candidate_type, |
| 2517 const std::string& remote_candidate_type, |
| 2518 const std::string& relay_protocol_type = cricket::UDP_PROTOCOL_NAME) { |
| 2519 cricket::Connection* conn = |
| 2520 FindNextPingableConnectionAndPingIt(channel_.get()); |
| 2521 EXPECT_EQ(conn->local_candidate().type(), local_candidate_type); |
| 2522 if (conn->local_candidate().type() == cricket::RELAY_PORT_TYPE) { |
| 2523 EXPECT_EQ(conn->local_candidate().relay_protocol(), relay_protocol_type); |
| 2524 } |
| 2525 EXPECT_EQ(conn->remote_candidate().type(), remote_candidate_type); |
| 2526 } |
| 2527 |
| 2528 cricket::Candidate CreateRelayCandidate(const std::string& ip, |
| 2529 int port, |
| 2530 int priority, |
| 2531 const std::string& ufrag = "") { |
| 2532 cricket::Candidate c = CreateHostCandidate(ip, port, priority, ufrag); |
| 2533 c.set_type(cricket::RELAY_PORT_TYPE); |
| 2534 return c; |
| 2535 } |
| 2536 |
| 2537 private: |
| 2538 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_; |
| 2539 rtc::FakeNetworkManager network_manager_; |
| 2540 cricket::TestTurnServer turn_server_; |
| 2541 rtc::scoped_ptr<cricket::P2PTransportChannel> channel_; |
| 2542 }; |
| 2543 |
| 2544 // Test that Relay/Relay connections will be pinged first when no other |
| 2545 // connections have been pinged yet, unless we need to ping a trigger check or |
| 2546 // we have a best connection. |
| 2547 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, |
| 2548 TestRelayRelayFirstWhenNothingPingedYet) { |
| 2549 const uint32_t max_strong_delay = 100; |
| 2550 cricket::P2PTransportChannel& ch = |
| 2551 StartTransportChannel(true, max_strong_delay); |
| 2552 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); |
| 2553 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE); |
| 2554 EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE); |
| 2555 |
| 2556 ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1)); |
| 2557 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); |
| 2558 |
| 2559 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); |
| 2560 |
| 2561 // Relay/Relay should be the first pingable connection. |
| 2562 cricket::Connection* conn = FindNextPingableConnectionAndPingIt(&ch); |
| 2563 EXPECT_EQ(conn->local_candidate().type(), cricket::RELAY_PORT_TYPE); |
| 2564 EXPECT_EQ(conn->remote_candidate().type(), cricket::RELAY_PORT_TYPE); |
| 2565 |
| 2566 // Unless that we have a trigger check waiting to be pinged. |
| 2567 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 2568 EXPECT_EQ(conn2->local_candidate().type(), cricket::LOCAL_PORT_TYPE); |
| 2569 EXPECT_EQ(conn2->remote_candidate().type(), cricket::LOCAL_PORT_TYPE); |
| 2570 conn2->ReceivedPing(); |
| 2571 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); |
| 2572 |
| 2573 // Make conn3 the best connection. |
| 2574 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2575 EXPECT_EQ(conn3->local_candidate().type(), cricket::LOCAL_PORT_TYPE); |
| 2576 EXPECT_EQ(conn3->remote_candidate().type(), cricket::RELAY_PORT_TYPE); |
| 2577 conn3->ReceivedPingResponse(); |
| 2578 ASSERT_TRUE(conn3->writable()); |
| 2579 conn3->ReceivedPing(); |
| 2580 |
| 2581 // Verify that conn3 will be the "best connection" since it is readable and |
| 2582 // writable. After |MAX_CURRENT_STRONG_DELAY|, it should be the next pingable |
| 2583 // connection. |
| 2584 EXPECT_TRUE_WAIT(conn3 == ch.best_connection(), 5000); |
| 2585 WAIT(false, max_strong_delay + 100); |
| 2586 conn3->ReceivedPingResponse(); |
| 2587 ASSERT_TRUE(conn3->writable()); |
| 2588 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); |
| 2589 } |
| 2590 |
| 2591 // Test that Relay/Relay connections will be pinged first when everything has |
| 2592 // been pinged even if the Relay/Relay connection wasn't the first to be pinged |
| 2593 // in the first round. |
| 2594 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, |
| 2595 TestRelayRelayFirstWhenEverythingPinged) { |
| 2596 cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100); |
| 2597 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); |
| 2598 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE); |
| 2599 EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE); |
| 2600 |
| 2601 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
| 2602 EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000); |
| 2603 |
| 2604 // Initially, only have Local/Local and Local/Relay. |
| 2605 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, |
| 2606 cricket::LOCAL_PORT_TYPE); |
| 2607 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
| 2608 cricket::LOCAL_PORT_TYPE); |
| 2609 |
| 2610 // Remote Relay candidate arrives. |
| 2611 ch.AddRemoteCandidate(CreateRelayCandidate("2.2.2.2", 2, 2)); |
| 2612 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); |
| 2613 |
| 2614 // Relay/Relay should be the first since it hasn't been pinged before. |
| 2615 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
| 2616 cricket::RELAY_PORT_TYPE); |
| 2617 |
| 2618 // Local/Relay is the final one. |
| 2619 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, |
| 2620 cricket::RELAY_PORT_TYPE); |
| 2621 |
| 2622 // Now, every connection has been pinged once. The next one should be |
| 2623 // Relay/Relay. |
| 2624 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
| 2625 cricket::RELAY_PORT_TYPE); |
| 2626 } |
| 2627 |
| 2628 // Test that when we receive a new remote candidate, they will be tried first |
| 2629 // before we re-ping Relay/Relay connections again. |
| 2630 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, |
| 2631 TestNoStarvationOnNonRelayConnection) { |
| 2632 cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100); |
| 2633 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); |
| 2634 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE); |
| 2635 EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE); |
| 2636 |
| 2637 ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1)); |
| 2638 EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000); |
| 2639 |
| 2640 // Initially, only have Relay/Relay and Local/Relay. Ping Relay/Relay first. |
| 2641 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
| 2642 cricket::RELAY_PORT_TYPE); |
| 2643 |
| 2644 // Next, ping Local/Relay. |
| 2645 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, |
| 2646 cricket::RELAY_PORT_TYPE); |
| 2647 |
| 2648 // Remote Local candidate arrives. |
| 2649 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); |
| 2650 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); |
| 2651 |
| 2652 // Local/Local should be the first since it hasn't been pinged before. |
| 2653 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, |
| 2654 cricket::LOCAL_PORT_TYPE); |
| 2655 |
| 2656 // Relay/Local is the final one. |
| 2657 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
| 2658 cricket::LOCAL_PORT_TYPE); |
| 2659 |
| 2660 // Now, every connection has been pinged once. The next one should be |
| 2661 // Relay/Relay. |
| 2662 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
| 2663 cricket::RELAY_PORT_TYPE); |
| 2664 } |
| 2665 |
| 2666 // Test the ping sequence is UDP Relay/Relay followed by TCP Relay/Relay, |
| 2667 // followed by the rest. |
| 2668 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestTcpTurn) { |
| 2669 // Add a Tcp Turn server. |
| 2670 turn_server()->AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); |
| 2671 cricket::RelayServerConfig config(cricket::RELAY_TURN); |
| 2672 config.credentials = kRelayCredentials; |
| 2673 config.ports.push_back( |
| 2674 cricket::ProtocolAddress(kTurnTcpIntAddr, cricket::PROTO_TCP, false)); |
| 2675 allocator()->AddTurnServer(config); |
| 2676 |
| 2677 cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100); |
| 2678 EXPECT_TRUE_WAIT(ch.ports().size() == 3, 5000); |
| 2679 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE); |
| 2680 EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE); |
| 2681 EXPECT_EQ(ch.ports()[2]->Type(), cricket::RELAY_PORT_TYPE); |
| 2682 |
| 2683 // Remote Relay candidate arrives. |
| 2684 ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1)); |
| 2685 EXPECT_TRUE_WAIT(ch.connections().size() == 3, 5000); |
| 2686 |
| 2687 // UDP Relay/Relay should be pinged first. |
| 2688 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
| 2689 cricket::RELAY_PORT_TYPE); |
| 2690 |
| 2691 // TCP Relay/Relay is the next. |
| 2692 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
| 2693 cricket::RELAY_PORT_TYPE, |
| 2694 cricket::TCP_PROTOCOL_NAME); |
| 2695 |
| 2696 // Finally, Local/Relay will be pinged. |
| 2697 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, |
| 2698 cricket::RELAY_PORT_TYPE); |
| 2699 } |
OLD | NEW |