| 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 1682 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1693   // an exchange of pings. |  1693   // an exchange of pings. | 
|  1694   EXPECT_TRUE_WAIT( |  1694   EXPECT_TRUE_WAIT( | 
|  1695       ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |  1695       ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 
|  1696       LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |  1696       LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 
|  1697       RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), |  1697       RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), | 
|  1698       3000); |  1698       3000); | 
|  1699  |  1699  | 
|  1700   DestroyChannels(); |  1700   DestroyChannels(); | 
|  1701 } |  1701 } | 
|  1702  |  1702  | 
|  1703 class P2PTransportChannelPingOrderTest : public testing::Test, |  1703 // A collection of tests which tests a single P2PTransportChannel by sending | 
|  1704                                          public sigslot::has_slots<> { |  1704 // pings. | 
 |  1705 class P2PTransportChannelPingTest : public testing::Test, | 
 |  1706                                     public sigslot::has_slots<> { | 
|  1705  public: |  1707  public: | 
|  1706   P2PTransportChannelPingOrderTest() : |  1708   P2PTransportChannelPingTest() | 
|  1707       pss_(new rtc::PhysicalSocketServer), |  1709       : pss_(new rtc::PhysicalSocketServer), | 
|  1708       vss_(new rtc::VirtualSocketServer(pss_.get())), |  1710         vss_(new rtc::VirtualSocketServer(pss_.get())), | 
|  1709       ss_scope_(vss_.get()) { |  1711         ss_scope_(vss_.get()) {} | 
|  1710   } |  | 
|  1711  |  1712  | 
|  1712  protected: |  1713  protected: | 
|  1713   void PrepareChannel(cricket::P2PTransportChannel* ch) { |  1714   void PrepareChannel(cricket::P2PTransportChannel* ch) { | 
|  1714     ch->SignalRequestSignaling.connect( |  1715     ch->SignalRequestSignaling.connect( | 
|  1715         this, &P2PTransportChannelPingOrderTest::OnChannelRequestSignaling); |  1716         this, &P2PTransportChannelPingTest::OnChannelRequestSignaling); | 
|  1716     ch->SetIceProtocolType(cricket::ICEPROTO_RFC5245); |  1717     ch->SetIceProtocolType(cricket::ICEPROTO_RFC5245); | 
|  1717     ch->SetIceRole(cricket::ICEROLE_CONTROLLING); |  1718     ch->SetIceRole(cricket::ICEROLE_CONTROLLING); | 
|  1718     ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); |  1719     ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); | 
|  1719     ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |  1720     ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 
|  1720   } |  1721   } | 
|  1721  |  1722  | 
|  1722   void OnChannelRequestSignaling(cricket::TransportChannelImpl* channel) { |  1723   void OnChannelRequestSignaling(cricket::TransportChannelImpl* channel) { | 
|  1723     channel->OnSignalingReady(); |  1724     channel->OnSignalingReady(); | 
|  1724   } |  1725   } | 
|  1725  |  1726  | 
|  1726   cricket::Candidate CreateCandidate(const std::string& ip, |  1727   cricket::Candidate CreateCandidate(const std::string& ip, | 
|  1727                                      int port, |  1728                                      int port, | 
|  1728                                      int priority) { |  1729                                      int priority) { | 
|  1729     cricket::Candidate c; |  1730     cricket::Candidate c; | 
|  1730     c.set_address(rtc::SocketAddress(ip, port)); |  1731     c.set_address(rtc::SocketAddress(ip, port)); | 
|  1731     c.set_component(1); |  1732     c.set_component(1); | 
|  1732     c.set_protocol(cricket::UDP_PROTOCOL_NAME); |  1733     c.set_protocol(cricket::UDP_PROTOCOL_NAME); | 
|  1733     c.set_priority(priority); |  1734     c.set_priority(priority); | 
|  1734     return c; |  1735     return c; | 
|  1735   } |  1736   } | 
|  1736  |  1737  | 
|  1737   cricket::Connection* WaitForConnectionTo(cricket::P2PTransportChannel* ch, |  1738   cricket::Connection* WaitForConnectionTo(cricket::P2PTransportChannel* ch, | 
|  1738                                            const std::string& ip, |  1739                                            const std::string& ip, | 
|  1739                                            int port_num) { |  1740                                            int port_num) { | 
|  1740     EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000); |  1741     EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000); | 
|  1741     return GetConnectionTo(ch, ip, port_num); |  1742     return GetConnectionTo(ch, ip, port_num); | 
|  1742   } |  1743   } | 
|  1743  |  1744  | 
 |  1745   cricket::Port* GetPort(cricket::P2PTransportChannel* ch) { | 
 |  1746     if (ch->ports().empty()) { | 
 |  1747       return nullptr; | 
 |  1748     } | 
 |  1749     return static_cast<cricket::Port*>(ch->ports()[0]); | 
 |  1750   } | 
 |  1751  | 
|  1744   cricket::Connection* GetConnectionTo(cricket::P2PTransportChannel* ch, |  1752   cricket::Connection* GetConnectionTo(cricket::P2PTransportChannel* ch, | 
|  1745                                        const std::string& ip, |  1753                                        const std::string& ip, | 
|  1746                                        int port_num) { |  1754                                        int port_num) { | 
|  1747     if (ch->ports().empty()) { |  1755     cricket::Port* port = GetPort(ch); | 
|  1748       return nullptr; |  | 
|  1749     } |  | 
|  1750     cricket::Port* port = static_cast<cricket::Port*>(ch->ports()[0]); |  | 
|  1751     if (!port) { |  1756     if (!port) { | 
|  1752       return nullptr; |  1757       return nullptr; | 
|  1753     } |  1758     } | 
|  1754     return port->GetConnection(rtc::SocketAddress(ip, port_num)); |  1759     return port->GetConnection(rtc::SocketAddress(ip, port_num)); | 
|  1755   } |  1760   } | 
|  1756  |  1761  | 
|  1757  private: |  1762  private: | 
|  1758   rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |  1763   rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; | 
|  1759   rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; |  1764   rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; | 
|  1760   rtc::SocketServerScope ss_scope_; |  1765   rtc::SocketServerScope ss_scope_; | 
|  1761 }; |  1766 }; | 
|  1762  |  1767  | 
|  1763 TEST_F(P2PTransportChannelPingOrderTest, TestTriggeredChecks) { |  1768 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { | 
|  1764   cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |  1769   cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 
|  1765   cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); |  1770   cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); | 
|  1766   PrepareChannel(&ch); |  1771   PrepareChannel(&ch); | 
|  1767   ch.Connect(); |  1772   ch.Connect(); | 
|  1768   ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); |  1773   ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 
|  1769   ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); |  1774   ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 
|  1770  |  1775  | 
|  1771   cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |  1776   cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 
|  1772   cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |  1777   cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 
|  1773   ASSERT_TRUE(conn1 != nullptr); |  1778   ASSERT_TRUE(conn1 != nullptr); | 
|  1774   ASSERT_TRUE(conn2 != nullptr); |  1779   ASSERT_TRUE(conn2 != nullptr); | 
|  1775  |  1780  | 
|  1776   // Before a triggered check, the first connection to ping is the |  1781   // Before a triggered check, the first connection to ping is the | 
|  1777   // highest priority one. |  1782   // highest priority one. | 
|  1778   EXPECT_EQ(conn2, ch.FindNextPingableConnection()); |  1783   EXPECT_EQ(conn2, ch.FindNextPingableConnection()); | 
|  1779  |  1784  | 
|  1780   // Receiving a ping causes a triggered check which should make conn1 |  1785   // Receiving a ping causes a triggered check which should make conn1 | 
|  1781   // be pinged first instead of conn2, even though conn2 has a higher |  1786   // be pinged first instead of conn2, even though conn2 has a higher | 
|  1782   // priority. |  1787   // priority. | 
|  1783   conn1->ReceivedPing(); |  1788   conn1->ReceivedPing(); | 
|  1784   EXPECT_EQ(conn1, ch.FindNextPingableConnection()); |  1789   EXPECT_EQ(conn1, ch.FindNextPingableConnection()); | 
|  1785 } |  1790 } | 
|  1786  |  1791  | 
|  1787 TEST_F(P2PTransportChannelPingOrderTest, TestNoTriggeredChecksWhenWritable) { |  1792 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { | 
|  1788   cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |  1793   cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 
|  1789   cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); |  1794   cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); | 
|  1790   PrepareChannel(&ch); |  1795   PrepareChannel(&ch); | 
|  1791   ch.Connect(); |  1796   ch.Connect(); | 
|  1792   ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); |  1797   ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 
|  1793   ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); |  1798   ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 
|  1794  |  1799  | 
|  1795   cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |  1800   cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 
|  1796   cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |  1801   cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 
|  1797   ASSERT_TRUE(conn1 != nullptr); |  1802   ASSERT_TRUE(conn1 != nullptr); | 
|  1798   ASSERT_TRUE(conn2 != nullptr); |  1803   ASSERT_TRUE(conn2 != nullptr); | 
|  1799  |  1804  | 
|  1800   EXPECT_EQ(conn2, ch.FindNextPingableConnection()); |  1805   EXPECT_EQ(conn2, ch.FindNextPingableConnection()); | 
|  1801   conn1->ReceivedPingResponse(); |  1806   conn1->ReceivedPingResponse(); | 
|  1802   ASSERT_TRUE(conn1->writable()); |  1807   ASSERT_TRUE(conn1->writable()); | 
|  1803   conn1->ReceivedPing(); |  1808   conn1->ReceivedPing(); | 
|  1804  |  1809  | 
|  1805   // Ping received, but the connection is already writable, so no |  1810   // Ping received, but the connection is already writable, so no | 
|  1806   // "triggered check" and conn2 is pinged before conn1 because it has |  1811   // "triggered check" and conn2 is pinged before conn1 because it has | 
|  1807   // a higher priority. |  1812   // a higher priority. | 
|  1808   EXPECT_EQ(conn2, ch.FindNextPingableConnection()); |  1813   EXPECT_EQ(conn2, ch.FindNextPingableConnection()); | 
|  1809 } |  1814 } | 
 |  1815  | 
 |  1816 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { | 
 |  1817   cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 
 |  1818   cricket::P2PTransportChannel ch("connection resurrection", 1, nullptr, &pa); | 
 |  1819   PrepareChannel(&ch); | 
 |  1820   ch.Connect(); | 
 |  1821  | 
 |  1822   // Create conn1 and keep track of original candidate priority. | 
 |  1823   ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 
 |  1824   cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 
 |  1825   ASSERT_TRUE(conn1 != nullptr); | 
 |  1826   uint32 remote_priority = conn1->remote_candidate().priority(); | 
 |  1827  | 
 |  1828   // Create a higher priority candidate and make the connection | 
 |  1829   // readable/writable. This will prune conn1. | 
 |  1830   ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 
 |  1831   cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 
 |  1832   ASSERT_TRUE(conn2 != nullptr); | 
 |  1833   conn2->ReceivedPing(); | 
 |  1834   conn2->ReceivedPingResponse(); | 
 |  1835  | 
 |  1836   // Wait for conn1 being destroyed. | 
 |  1837   EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 3000); | 
 |  1838   cricket::Port* port = GetPort(&ch); | 
 |  1839  | 
 |  1840   // Create a minimal STUN message with prflx priority. | 
 |  1841   cricket::IceMessage request; | 
 |  1842   request.SetType(cricket::STUN_BINDING_REQUEST); | 
 |  1843   request.AddAttribute(new cricket::StunByteStringAttribute( | 
 |  1844       cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); | 
 |  1845   uint32 prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; | 
 |  1846   request.AddAttribute(new cricket::StunUInt32Attribute( | 
 |  1847       cricket::STUN_ATTR_PRIORITY, prflx_priority)); | 
 |  1848   EXPECT_NE(prflx_priority, remote_priority); | 
 |  1849  | 
 |  1850   // conn1 should be resurrected with original priority. | 
 |  1851   port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), | 
 |  1852                              cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 
 |  1853   conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 
 |  1854   ASSERT_TRUE(conn1 != nullptr); | 
 |  1855   EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority); | 
 |  1856  | 
 |  1857   // conn3, a real prflx connection, should have prflx priority. | 
 |  1858   port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), | 
 |  1859                              cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 
 |  1860   cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1); | 
 |  1861   ASSERT_TRUE(conn3 != nullptr); | 
 |  1862   EXPECT_EQ(conn3->remote_candidate().priority(), prflx_priority); | 
 |  1863 } | 
| OLD | NEW |