Chromium Code Reviews| 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 1710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1721 | 1721 |
| 1722 protected: | 1722 protected: |
| 1723 void PrepareChannel(cricket::P2PTransportChannel* ch) { | 1723 void PrepareChannel(cricket::P2PTransportChannel* ch) { |
| 1724 ch->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1724 ch->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1725 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); | 1725 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); |
| 1726 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 1726 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
| 1727 } | 1727 } |
| 1728 | 1728 |
| 1729 cricket::Candidate CreateCandidate(const std::string& ip, | 1729 cricket::Candidate CreateCandidate(const std::string& ip, |
| 1730 int port, | 1730 int port, |
| 1731 int priority) { | 1731 int priority, |
| 1732 const std::string& ufrag = "") { | |
| 1732 cricket::Candidate c; | 1733 cricket::Candidate c; |
| 1733 c.set_address(rtc::SocketAddress(ip, port)); | 1734 c.set_address(rtc::SocketAddress(ip, port)); |
| 1734 c.set_component(1); | 1735 c.set_component(1); |
| 1735 c.set_protocol(cricket::UDP_PROTOCOL_NAME); | 1736 c.set_protocol(cricket::UDP_PROTOCOL_NAME); |
| 1736 c.set_priority(priority); | 1737 c.set_priority(priority); |
| 1738 c.set_username(ufrag); | |
| 1737 return c; | 1739 return c; |
| 1738 } | 1740 } |
| 1739 | 1741 |
| 1740 cricket::Connection* WaitForConnectionTo(cricket::P2PTransportChannel* ch, | 1742 cricket::Connection* WaitForConnectionTo(cricket::P2PTransportChannel* ch, |
| 1741 const std::string& ip, | 1743 const std::string& ip, |
| 1742 int port_num) { | 1744 int port_num) { |
| 1743 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000); | 1745 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000); |
| 1744 return GetConnectionTo(ch, ip, port_num); | 1746 return GetConnectionTo(ch, ip, port_num); |
| 1745 } | 1747 } |
| 1746 | 1748 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1810 conn1->ReceivedPingResponse(); | 1812 conn1->ReceivedPingResponse(); |
| 1811 ASSERT_TRUE(conn1->writable()); | 1813 ASSERT_TRUE(conn1->writable()); |
| 1812 conn1->ReceivedPing(); | 1814 conn1->ReceivedPing(); |
| 1813 | 1815 |
| 1814 // Ping received, but the connection is already writable, so no | 1816 // Ping received, but the connection is already writable, so no |
| 1815 // "triggered check" and conn2 is pinged before conn1 because it has | 1817 // "triggered check" and conn2 is pinged before conn1 because it has |
| 1816 // a higher priority. | 1818 // a higher priority. |
| 1817 EXPECT_EQ(conn2, ch.FindNextPingableConnection()); | 1819 EXPECT_EQ(conn2, ch.FindNextPingableConnection()); |
| 1818 } | 1820 } |
| 1819 | 1821 |
| 1822 // Test that if a remote candidate is added with an old ufrag, it will be | |
| 1823 // discarded, and if it is added with a ufrag that was not seen before, it will | |
| 1824 // be used to create connections where the ICE pwd will be set when the ICE | |
| 1825 // credentials arrive. | |
| 1826 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { | |
| 1827 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | |
| 1828 cricket::P2PTransportChannel ch("add candidate", 1, nullptr, &pa); | |
| 1829 PrepareChannel(&ch); | |
| 1830 ch.Connect(); | |
| 1831 ch.MaybeStartGathering(); | |
| 1832 // Add a candidate with a future ufrag. | |
| 1833 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1, kIceUfrag[2])); | |
| 1834 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | |
| 1835 ASSERT_TRUE(conn1 != nullptr); | |
| 1836 const cricket::Candidate& candidate = conn1->remote_candidate(); | |
| 1837 EXPECT_EQ(kIceUfrag[2], candidate.username()); | |
| 1838 EXPECT_TRUE(candidate.password().empty()); | |
| 1839 EXPECT_TRUE(ch.FindNextPingableConnection() == nullptr); | |
| 1840 | |
| 1841 // Set the remote credentials with the "future" ufrag. | |
| 1842 // This should set the ICE pwd in the remote candidate of |conn1|, making | |
| 1843 // it pingable. | |
| 1844 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); | |
| 1845 EXPECT_EQ(kIceUfrag[2], candidate.username()); | |
| 1846 EXPECT_EQ(kIcePwd[2], candidate.password()); | |
| 1847 EXPECT_TRUE(ch.FindNextPingableConnection() != nullptr); | |
| 1848 | |
| 1849 // Now add a candidate with an old ufrag. No connection will be created. | |
| 1850 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2, kIceUfrag[1])); | |
| 1851 rtc::Thread::Current()->ProcessMessages(500); | |
| 1852 EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr); | |
|
pthatcher1
2015/12/04 20:43:50
Do we also need a test to make sure that if genera
honghaiz3
2015/12/09 23:57:54
Done.
| |
| 1853 } | |
| 1854 | |
| 1820 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { | 1855 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { |
| 1821 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1856 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 1822 cricket::P2PTransportChannel ch("connection resurrection", 1, nullptr, &pa); | 1857 cricket::P2PTransportChannel ch("connection resurrection", 1, nullptr, &pa); |
| 1823 PrepareChannel(&ch); | 1858 PrepareChannel(&ch); |
| 1824 ch.Connect(); | 1859 ch.Connect(); |
| 1825 ch.MaybeStartGathering(); | 1860 ch.MaybeStartGathering(); |
| 1826 | 1861 |
| 1827 // Create conn1 and keep track of original candidate priority. | 1862 // Create conn1 and keep track of original candidate priority. |
| 1828 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1863 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
| 1829 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1864 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2238 // It should stop getting ports after a new connection becomes strongly | 2273 // It should stop getting ports after a new connection becomes strongly |
| 2239 // connected. | 2274 // connected. |
| 2240 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); | 2275 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); |
| 2241 ch.MaybeStartGathering(); | 2276 ch.MaybeStartGathering(); |
| 2242 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100)); | 2277 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100)); |
| 2243 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 2278 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 2244 ASSERT_TRUE(conn2 != nullptr); | 2279 ASSERT_TRUE(conn2 != nullptr); |
| 2245 conn2->ReceivedPingResponse(); // Becomes writable and receiving | 2280 conn2->ReceivedPingResponse(); // Becomes writable and receiving |
| 2246 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 2281 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
| 2247 } | 2282 } |
| OLD | NEW |