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

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

Issue 1172483002: Connection resurrected with incorrect candidate type. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 6 months 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
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 1703 matching lines...) Expand 10 before | Expand all | Expand 10 after
1714 // an exchange of pings. 1714 // an exchange of pings.
1715 EXPECT_TRUE_WAIT( 1715 EXPECT_TRUE_WAIT(
1716 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && 1716 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() &&
1717 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 1717 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
1718 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), 1718 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]),
1719 3000); 1719 3000);
1720 1720
1721 DestroyChannels(); 1721 DestroyChannels();
1722 } 1722 }
1723 1723
1724 class P2PTransportChannelPingOrderTest : public testing::Test, 1724 // A collection of tests which tests a single P2PTransportChannel by sending
1725 public sigslot::has_slots<> { 1725 // pings.
1726 class P2PTransportChannelPingTest : public testing::Test,
1727 public sigslot::has_slots<> {
1726 public: 1728 public:
1727 P2PTransportChannelPingOrderTest() : 1729 P2PTransportChannelPingTest()
1728 pss_(new rtc::PhysicalSocketServer), 1730 : pss_(new rtc::PhysicalSocketServer),
1729 vss_(new rtc::VirtualSocketServer(pss_.get())), 1731 vss_(new rtc::VirtualSocketServer(pss_.get())),
1730 ss_scope_(vss_.get()) { 1732 ss_scope_(vss_.get()) {}
1731 }
1732 1733
1733 protected: 1734 protected:
1734 void PrepareChannel(cricket::P2PTransportChannel* ch) { 1735 void PrepareChannel(cricket::P2PTransportChannel* ch) {
1735 ch->SignalRequestSignaling.connect( 1736 ch->SignalRequestSignaling.connect(
1736 this, &P2PTransportChannelPingOrderTest::OnChannelRequestSignaling); 1737 this, &P2PTransportChannelPingTest::OnChannelRequestSignaling);
1737 ch->SetIceProtocolType(cricket::ICEPROTO_RFC5245); 1738 ch->SetIceProtocolType(cricket::ICEPROTO_RFC5245);
1738 ch->SetIceRole(cricket::ICEROLE_CONTROLLING); 1739 ch->SetIceRole(cricket::ICEROLE_CONTROLLING);
1739 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); 1740 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]);
1740 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 1741 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]);
1741 } 1742 }
1742 1743
1743 void OnChannelRequestSignaling(cricket::TransportChannelImpl* channel) { 1744 void OnChannelRequestSignaling(cricket::TransportChannelImpl* channel) {
1744 channel->OnSignalingReady(); 1745 channel->OnSignalingReady();
1745 } 1746 }
1746 1747
1747 cricket::Candidate CreateCandidate(const std::string& ip, 1748 cricket::Candidate CreateCandidate(const std::string& ip,
1748 int port, 1749 int port,
1749 int priority) { 1750 int priority) {
1750 cricket::Candidate c; 1751 cricket::Candidate c;
1751 c.set_address(rtc::SocketAddress(ip, port)); 1752 c.set_address(rtc::SocketAddress(ip, port));
1752 c.set_component(1); 1753 c.set_component(1);
1753 c.set_protocol(cricket::UDP_PROTOCOL_NAME); 1754 c.set_protocol(cricket::UDP_PROTOCOL_NAME);
1754 c.set_priority(priority); 1755 c.set_priority(priority);
1755 return c; 1756 return c;
1756 } 1757 }
1757 1758
1758 cricket::Connection* WaitForConnectionTo(cricket::P2PTransportChannel* ch, 1759 cricket::Connection* WaitForConnectionTo(cricket::P2PTransportChannel* ch,
1759 const std::string& ip, 1760 const std::string& ip,
1760 int port_num) { 1761 int port_num) {
1761 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000); 1762 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000);
1762 return GetConnectionTo(ch, ip, port_num); 1763 return GetConnectionTo(ch, ip, port_num);
1763 } 1764 }
1764 1765
1766 cricket::Port* GetPort(cricket::P2PTransportChannel* ch) {
1767 if (ch->ports().empty()) {
1768 return nullptr;
1769 }
1770 return static_cast<cricket::Port*>(ch->ports()[0]);
1771 }
1772
1765 cricket::Connection* GetConnectionTo(cricket::P2PTransportChannel* ch, 1773 cricket::Connection* GetConnectionTo(cricket::P2PTransportChannel* ch,
1766 const std::string& ip, 1774 const std::string& ip,
1767 int port_num) { 1775 int port_num) {
1768 if (ch->ports().empty()) { 1776 cricket::Port* port = GetPort(ch);
1769 return nullptr;
1770 }
1771 cricket::Port* port = static_cast<cricket::Port*>(ch->ports()[0]);
1772 if (!port) { 1777 if (!port) {
1773 return nullptr; 1778 return nullptr;
1774 } 1779 }
1775 return port->GetConnection(rtc::SocketAddress(ip, port_num)); 1780 return port->GetConnection(rtc::SocketAddress(ip, port_num));
1776 } 1781 }
1777 1782
1778 uint32 WaitForFirstPing(cricket::Connection* conn) { 1783 uint32 WaitForFirstPing(cricket::Connection* conn) {
1779 EXPECT_TRUE_WAIT(conn->last_ping_sent() > 0, 3000); 1784 EXPECT_TRUE_WAIT(conn->last_ping_sent() > 0, 3000);
1780 return conn->last_ping_sent(); 1785 return conn->last_ping_sent();
1781 } 1786 }
1782 1787
1783 private: 1788 private:
1784 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; 1789 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1785 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; 1790 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1786 rtc::SocketServerScope ss_scope_; 1791 rtc::SocketServerScope ss_scope_;
1787 }; 1792 };
1788 1793
1789 TEST_F(P2PTransportChannelPingOrderTest, TestTriggeredChecks) { 1794 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) {
1790 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); 1795 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
1791 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); 1796 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa);
1792 PrepareChannel(&ch); 1797 PrepareChannel(&ch);
1793 ch.Connect(); 1798 ch.Connect();
1794 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); 1799 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1));
1795 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); 1800 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2));
1796 1801
1797 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 1802 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
1798 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 1803 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
1799 ASSERT_TRUE(conn1 != nullptr); 1804 ASSERT_TRUE(conn1 != nullptr);
1800 ASSERT_TRUE(conn2 != nullptr); 1805 ASSERT_TRUE(conn2 != nullptr);
1801 1806
1802 // Receiving a ping causes a "triggered check" which should make conn1 1807 // Receiving a ping causes a "triggered check" which should make conn1
1803 // be pinged first instead of conn2, even though conn2 has a higher priority. 1808 // be pinged first instead of conn2, even though conn2 has a higher priority.
1804 conn1->ReceivedPing(); 1809 conn1->ReceivedPing();
1805 uint32 ping1 = WaitForFirstPing(conn1); 1810 uint32 ping1 = WaitForFirstPing(conn1);
1806 uint32 ping2 = WaitForFirstPing(conn2); 1811 uint32 ping2 = WaitForFirstPing(conn2);
1807 EXPECT_LT(ping1, ping2); 1812 EXPECT_LT(ping1, ping2);
1808 } 1813 }
1809 1814
1810 TEST_F(P2PTransportChannelPingOrderTest, 1815 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWithoutIncomingPing) {
1811 TestNoTriggeredChecksWithoutIncomingPing) {
1812 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); 1816 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
1813 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); 1817 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa);
1814 PrepareChannel(&ch); 1818 PrepareChannel(&ch);
1815 ch.Connect(); 1819 ch.Connect();
1816 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); 1820 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1));
1817 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); 1821 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2));
1818 1822
1819 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 1823 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
1820 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 1824 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
1821 ASSERT_TRUE(conn1 != nullptr); 1825 ASSERT_TRUE(conn1 != nullptr);
1822 ASSERT_TRUE(conn2 != nullptr); 1826 ASSERT_TRUE(conn2 != nullptr);
1823 1827
1824 // No ping received, so no "triggered check" so conn2 is pinged 1828 // No ping received, so no "triggered check" so conn2 is pinged
1825 // before conn1 because it has a higher priority. 1829 // before conn1 because it has a higher priority.
1826 uint32 ping2 = WaitForFirstPing(conn2); 1830 uint32 ping2 = WaitForFirstPing(conn2);
1827 uint32 ping1 = WaitForFirstPing(conn1); 1831 uint32 ping1 = WaitForFirstPing(conn1);
1828 EXPECT_LT(ping2, ping1); 1832 EXPECT_LT(ping2, ping1);
1829 } 1833 }
1830 1834
1831 TEST_F(P2PTransportChannelPingOrderTest, TestNoTriggeredChecksWhenWritable) { 1835 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
1832 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); 1836 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
1833 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); 1837 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa);
1834 PrepareChannel(&ch); 1838 PrepareChannel(&ch);
1835 ch.Connect(); 1839 ch.Connect();
1836 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); 1840 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1));
1837 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); 1841 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2));
1838 1842
1839 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 1843 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
1840 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 1844 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
1841 ASSERT_TRUE(conn1 != nullptr); 1845 ASSERT_TRUE(conn1 != nullptr);
(...skipping 12 matching lines...) Expand all
1854 if ((ping1 - before_pings) < 900) { 1858 if ((ping1 - before_pings) < 900) {
1855 // If ping2 takes longer than 900ms to send, then there's a chance 1859 // If ping2 takes longer than 900ms to send, then there's a chance
1856 // that ping1 will go out before ping2 because of the pings that 1860 // that ping1 will go out before ping2 because of the pings that
1857 // keep a connection writable, which come before triggered checks. 1861 // keep a connection writable, which come before triggered checks.
1858 // This would only happen if the tests are running very, very 1862 // This would only happen if the tests are running very, very
1859 // slowly. But to avoid the tests being flaky on very slow bots, 1863 // slowly. But to avoid the tests being flaky on very slow bots,
1860 // we add the check. 1864 // we add the check.
1861 EXPECT_LT(ping2, ping1); 1865 EXPECT_LT(ping2, ping1);
1862 } 1866 }
1863 } 1867 }
1868
1869 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) {
1870 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
1871 cricket::P2PTransportChannel ch("connection resurrection", 1, nullptr, &pa);
1872 PrepareChannel(&ch);
1873 ch.Connect();
1874
1875 // Create conn1 and keep track of original candidate priority.
1876 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1));
1877 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
1878 ASSERT_TRUE(conn1 != nullptr);
1879 uint32 remote_priority = conn1->remote_candidate().priority();
1880
1881 // Create a higher priority candidate and make the connection
1882 // readable/writable. This will prune conn1.
1883 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2));
1884 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
1885 ASSERT_TRUE(conn2 != nullptr);
1886 conn2->ReceivedPing();
1887 conn2->ReceivedPingResponse();
1888
1889 // Wait for conn1 being destroyed.
1890 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 3000);
1891 cricket::Port* port = GetPort(&ch);
1892
1893 // Create a minimal STUN message with prflx priority.
1894 cricket::IceMessage request;
1895 request.SetType(cricket::STUN_BINDING_REQUEST);
1896 request.AddAttribute(new cricket::StunByteStringAttribute(
1897 cricket::STUN_ATTR_USERNAME, kIceUfrag[1]));
1898 uint32 prflx_priority = conn1->remote_candidate().GetPriority(
1899 cricket::ICE_TYPE_PREFERENCE_PRFLX, 0, 0);
1900 request.AddAttribute(new cricket::StunUInt32Attribute(
1901 cricket::STUN_ATTR_PRIORITY, prflx_priority));
1902 EXPECT_NE(prflx_priority, remote_priority);
1903
1904 // conn1 should be resurrected with original priority.
1905 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1),
1906 cricket::PROTO_UDP, &request, kIceUfrag[1], false);
1907 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
1908 ASSERT_TRUE(conn1 != nullptr);
1909 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority);
1910
1911 // conn3, a real prflx connection, should have prflx priority.
1912 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1),
1913 cricket::PROTO_UDP, &request, kIceUfrag[1], false);
1914 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1);
1915 ASSERT_TRUE(conn3 != nullptr);
1916 EXPECT_EQ(conn3->remote_candidate().priority(), prflx_priority);
1917 }
OLDNEW
« webrtc/p2p/base/p2ptransportchannel.cc ('K') | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698