Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1063)

Side by Side Diff: webrtc/p2p/base/p2ptransportchannel_unittest.cc

Issue 1498993002: Add ufrag to the ICE candidate signaling. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1749 matching lines...) Expand 10 before | Expand all | Expand 10 after
1760 1760
1761 protected: 1761 protected:
1762 void PrepareChannel(cricket::P2PTransportChannel* ch) { 1762 void PrepareChannel(cricket::P2PTransportChannel* ch) {
1763 ch->SetIceRole(cricket::ICEROLE_CONTROLLING); 1763 ch->SetIceRole(cricket::ICEROLE_CONTROLLING);
1764 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); 1764 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]);
1765 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 1765 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]);
1766 } 1766 }
1767 1767
1768 cricket::Candidate CreateCandidate(const std::string& ip, 1768 cricket::Candidate CreateCandidate(const std::string& ip,
1769 int port, 1769 int port,
1770 int priority) { 1770 int priority,
1771 const std::string& ufrag = "") {
1771 cricket::Candidate c; 1772 cricket::Candidate c;
1772 c.set_address(rtc::SocketAddress(ip, port)); 1773 c.set_address(rtc::SocketAddress(ip, port));
1773 c.set_component(1); 1774 c.set_component(1);
1774 c.set_protocol(cricket::UDP_PROTOCOL_NAME); 1775 c.set_protocol(cricket::UDP_PROTOCOL_NAME);
1775 c.set_priority(priority); 1776 c.set_priority(priority);
1777 c.set_username(ufrag);
1776 return c; 1778 return c;
1777 } 1779 }
1778 1780
1779 cricket::Connection* WaitForConnectionTo(cricket::P2PTransportChannel* ch, 1781 cricket::Connection* WaitForConnectionTo(cricket::P2PTransportChannel* ch,
1780 const std::string& ip, 1782 const std::string& ip,
1781 int port_num) { 1783 int port_num) {
1782 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000); 1784 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000);
1783 return GetConnectionTo(ch, ip, port_num); 1785 return GetConnectionTo(ch, ip, port_num);
1784 } 1786 }
1785 1787
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1849 conn1->ReceivedPingResponse(); 1851 conn1->ReceivedPingResponse();
1850 ASSERT_TRUE(conn1->writable()); 1852 ASSERT_TRUE(conn1->writable());
1851 conn1->ReceivedPing(); 1853 conn1->ReceivedPing();
1852 1854
1853 // Ping received, but the connection is already writable, so no 1855 // Ping received, but the connection is already writable, so no
1854 // "triggered check" and conn2 is pinged before conn1 because it has 1856 // "triggered check" and conn2 is pinged before conn1 because it has
1855 // a higher priority. 1857 // a higher priority.
1856 EXPECT_EQ(conn2, ch.FindNextPingableConnection()); 1858 EXPECT_EQ(conn2, ch.FindNextPingableConnection());
1857 } 1859 }
1858 1860
1861 // Test adding remote candidates with different ufrags. If a remote candidate
1862 // is added with an old ufrag, it will be discarded. If it is added with a
1863 // ufrag that was not seen before, it will be used to create connections
1864 // although the ICE pwd in the remote candidate will be set when the ICE
1865 // credentials arrive. If a remote candidate is added with the current ICE
1866 // ufrag, its pwd and generation will be set properly.
1867 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) {
1868 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
1869 cricket::P2PTransportChannel ch("add candidate", 1, nullptr, &pa);
1870 PrepareChannel(&ch);
1871 ch.Connect();
1872 ch.MaybeStartGathering();
1873 // Add a candidate with a future ufrag.
1874 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1, kIceUfrag[2]));
1875 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
1876 ASSERT_TRUE(conn1 != nullptr);
1877 const cricket::Candidate& candidate = conn1->remote_candidate();
1878 EXPECT_EQ(kIceUfrag[2], candidate.username());
1879 EXPECT_TRUE(candidate.password().empty());
1880 EXPECT_TRUE(ch.FindNextPingableConnection() == nullptr);
1881
1882 // Set the remote credentials with the "future" ufrag.
1883 // This should set the ICE pwd in the remote candidate of |conn1|, making
1884 // it pingable.
1885 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]);
1886 EXPECT_EQ(kIceUfrag[2], candidate.username());
1887 EXPECT_EQ(kIcePwd[2], candidate.password());
1888 EXPECT_EQ(conn1, ch.FindNextPingableConnection());
1889
1890 // Add a candidate with an old ufrag. No connection will be created.
1891 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2, kIceUfrag[1]));
1892 rtc::Thread::Current()->ProcessMessages(500);
1893 EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr);
1894
1895 // Add a candidate with the current ufrag, its pwd and generation will be
1896 // assigned, even if the generation is not set.
1897 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 0, kIceUfrag[2]));
1898 cricket::Connection* conn3 = nullptr;
1899 ASSERT_TRUE_WAIT((conn3 = GetConnectionTo(&ch, "3.3.3.3", 3)) != nullptr,
1900 3000);
1901 const cricket::Candidate& new_candidate = conn3->remote_candidate();
1902 EXPECT_EQ(kIcePwd[2], new_candidate.password());
1903 EXPECT_EQ(1U, new_candidate.generation());
1904 }
1905
1859 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { 1906 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) {
1860 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); 1907 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
1861 cricket::P2PTransportChannel ch("connection resurrection", 1, nullptr, &pa); 1908 cricket::P2PTransportChannel ch("connection resurrection", 1, nullptr, &pa);
1862 PrepareChannel(&ch); 1909 PrepareChannel(&ch);
1863 ch.Connect(); 1910 ch.Connect();
1864 ch.MaybeStartGathering(); 1911 ch.MaybeStartGathering();
1865 1912
1866 // Create conn1 and keep track of original candidate priority. 1913 // Create conn1 and keep track of original candidate priority.
1867 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); 1914 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1));
1868 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 1915 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
2279 // It should stop getting ports after a new connection becomes strongly 2326 // It should stop getting ports after a new connection becomes strongly
2280 // connected. 2327 // connected.
2281 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); 2328 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]);
2282 ch.MaybeStartGathering(); 2329 ch.MaybeStartGathering();
2283 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100)); 2330 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 100));
2284 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2331 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2285 ASSERT_TRUE(conn2 != nullptr); 2332 ASSERT_TRUE(conn2 != nullptr);
2286 conn2->ReceivedPingResponse(); // Becomes writable and receiving 2333 conn2->ReceivedPingResponse(); // Becomes writable and receiving
2287 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); 2334 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
2288 } 2335 }
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698