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 1914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1925 // Not switched yet because conn4 is not writable. | 1925 // Not switched yet because conn4 is not writable. |
1926 EXPECT_EQ(conn3, ch.best_connection()); | 1926 EXPECT_EQ(conn3, ch.best_connection()); |
1927 // The best connection switches after conn4 becomes writable. | 1927 // The best connection switches after conn4 becomes writable. |
1928 conn4->ReceivedPingResponse(); | 1928 conn4->ReceivedPingResponse(); |
1929 EXPECT_EQ(conn4, ch.best_connection()); | 1929 EXPECT_EQ(conn4, ch.best_connection()); |
1930 } | 1930 } |
1931 | 1931 |
1932 // The controlled side will select a connection as the "best connection" based | 1932 // The controlled side will select a connection as the "best connection" based |
1933 // on requests from an unknown address before the controlling side nominates | 1933 // on requests from an unknown address before the controlling side nominates |
1934 // a connection, and will nominate a connection from an unknown address if the | 1934 // a connection, and will nominate a connection from an unknown address if the |
1935 // request contains the use_candidate attribute. | 1935 // request contains the use_candidate attribute. Plus, it will also sends back |
| 1936 // a ping response. |
1936 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { | 1937 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { |
1937 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1938 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
1938 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); | 1939 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); |
1939 PrepareChannel(&ch); | 1940 PrepareChannel(&ch); |
1940 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 1941 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
1941 ch.Connect(); | 1942 ch.Connect(); |
1942 ch.MaybeStartGathering(); | 1943 ch.MaybeStartGathering(); |
1943 // A minimal STUN message with prflx priority. | 1944 // A minimal STUN message with prflx priority. |
1944 cricket::IceMessage request; | 1945 cricket::IceMessage request; |
1945 request.SetType(cricket::STUN_BINDING_REQUEST); | 1946 request.SetType(cricket::STUN_BINDING_REQUEST); |
1946 request.AddAttribute(new cricket::StunByteStringAttribute( | 1947 request.AddAttribute(new cricket::StunByteStringAttribute( |
1947 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); | 1948 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); |
1948 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; | 1949 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; |
1949 request.AddAttribute(new cricket::StunUInt32Attribute( | 1950 request.AddAttribute(new cricket::StunUInt32Attribute( |
1950 cricket::STUN_ATTR_PRIORITY, prflx_priority)); | 1951 cricket::STUN_ATTR_PRIORITY, prflx_priority)); |
1951 cricket::Port* port = GetPort(&ch); | 1952 cricket::TestUDPPort* port = static_cast<cricket::TestUDPPort*>(GetPort(&ch)); |
1952 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), | 1953 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), |
1953 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 1954 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
1954 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1955 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
1955 ASSERT_TRUE(conn1 != nullptr); | 1956 ASSERT_TRUE(conn1 != nullptr); |
| 1957 EXPECT_TRUE(port->sent_binding_response()); |
1956 EXPECT_EQ(conn1, ch.best_connection()); | 1958 EXPECT_EQ(conn1, ch.best_connection()); |
1957 conn1->ReceivedPingResponse(); | 1959 conn1->ReceivedPingResponse(); |
1958 EXPECT_EQ(conn1, ch.best_connection()); | 1960 EXPECT_EQ(conn1, ch.best_connection()); |
| 1961 port->set_sent_binding_response(false); |
1959 | 1962 |
1960 // Another connection is nominated via use_candidate. | 1963 // Another connection is nominated via use_candidate. |
1961 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); | 1964 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); |
1962 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1965 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
1963 ASSERT_TRUE(conn2 != nullptr); | 1966 ASSERT_TRUE(conn2 != nullptr); |
1964 // Because it has a lower priority, the best connection is still conn1. | 1967 // Because it has a lower priority, the best connection is still conn1. |
1965 EXPECT_EQ(conn1, ch.best_connection()); | 1968 EXPECT_EQ(conn1, ch.best_connection()); |
1966 // When it is nominated via use_candidate and writable, it is chosen as the | 1969 // When it is nominated via use_candidate and writable, it is chosen as the |
1967 // best connection. | 1970 // best connection. |
1968 conn2->ReceivedPingResponse(); // Become writable. | 1971 conn2->ReceivedPingResponse(); // Become writable. |
1969 conn2->set_nominated(true); | 1972 conn2->set_nominated(true); |
1970 conn2->SignalNominated(conn2); | 1973 conn2->SignalNominated(conn2); |
1971 EXPECT_EQ(conn2, ch.best_connection()); | 1974 EXPECT_EQ(conn2, ch.best_connection()); |
1972 | 1975 |
1973 // Another request with unknown address, it will not be set as the best | 1976 // Another request with unknown address, it will not be set as the best |
1974 // connection because the best connection was nominated by the controlling | 1977 // connection because the best connection was nominated by the controlling |
1975 // side. | 1978 // side. |
1976 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), | 1979 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), |
1977 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 1980 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
1978 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 1981 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
1979 ASSERT_TRUE(conn3 != nullptr); | 1982 ASSERT_TRUE(conn3 != nullptr); |
| 1983 EXPECT_TRUE(port->sent_binding_response()); |
1980 conn3->ReceivedPingResponse(); // Become writable. | 1984 conn3->ReceivedPingResponse(); // Become writable. |
1981 EXPECT_EQ(conn2, ch.best_connection()); | 1985 EXPECT_EQ(conn2, ch.best_connection()); |
| 1986 port->set_sent_binding_response(false); |
1982 | 1987 |
1983 // However if the request contains use_candidate attribute, it will be | 1988 // However if the request contains use_candidate attribute, it will be |
1984 // selected as the best connection. | 1989 // selected as the best connection. |
1985 request.AddAttribute( | 1990 request.AddAttribute( |
1986 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE)); | 1991 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE)); |
1987 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), | 1992 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), |
1988 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 1993 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
1989 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); | 1994 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); |
1990 ASSERT_TRUE(conn4 != nullptr); | 1995 ASSERT_TRUE(conn4 != nullptr); |
| 1996 EXPECT_TRUE(port->sent_binding_response()); |
1991 // conn4 is not the best connection yet because it is not writable. | 1997 // conn4 is not the best connection yet because it is not writable. |
1992 EXPECT_EQ(conn2, ch.best_connection()); | 1998 EXPECT_EQ(conn2, ch.best_connection()); |
1993 conn4->ReceivedPingResponse(); // Become writable. | 1999 conn4->ReceivedPingResponse(); // Become writable. |
1994 EXPECT_EQ(conn4, ch.best_connection()); | 2000 EXPECT_EQ(conn4, ch.best_connection()); |
1995 } | 2001 } |
1996 | 2002 |
1997 // The controlled side will select a connection as the "best connection" | 2003 // The controlled side will select a connection as the "best connection" |
1998 // based on media received until the controlling side nominates a connection, | 2004 // based on media received until the controlling side nominates a connection, |
1999 // at which point the controlled side will select that connection as | 2005 // at which point the controlled side will select that connection as |
2000 // the "best connection". | 2006 // the "best connection". |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2211 // It should stop getting ports after a new connection becomes strongly | 2217 // It should stop getting ports after a new connection becomes strongly |
2212 // connected. | 2218 // connected. |
2213 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); | 2219 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); |
2214 ch.MaybeStartGathering(); | 2220 ch.MaybeStartGathering(); |
2215 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100)); | 2221 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100)); |
2216 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2222 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
2217 ASSERT_TRUE(conn2 != nullptr); | 2223 ASSERT_TRUE(conn2 != nullptr); |
2218 conn2->ReceivedPingResponse(); // Becomes writable and receiving | 2224 conn2->ReceivedPingResponse(); // Becomes writable and receiving |
2219 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 2225 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
2220 } | 2226 } |
OLD | NEW |