| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 private: | 215 private: |
| 216 void OnSentPacket(rtc::AsyncPacketSocket* socket, | 216 void OnSentPacket(rtc::AsyncPacketSocket* socket, |
| 217 const rtc::SentPacket& sent_packet) { | 217 const rtc::SentPacket& sent_packet) { |
| 218 PortInterface::SignalSentPacket(sent_packet); | 218 PortInterface::SignalSentPacket(sent_packet); |
| 219 } | 219 } |
| 220 std::unique_ptr<Buffer> last_stun_buf_; | 220 std::unique_ptr<Buffer> last_stun_buf_; |
| 221 std::unique_ptr<IceMessage> last_stun_msg_; | 221 std::unique_ptr<IceMessage> last_stun_msg_; |
| 222 int type_preference_ = 0; | 222 int type_preference_ = 0; |
| 223 }; | 223 }; |
| 224 | 224 |
| 225 static void SendPingAndReceiveResponse( |
| 226 Connection* lconn, TestPort* lport, Connection* rconn, TestPort* rport, |
| 227 rtc::ScopedFakeClock* clock, int64_t ms) { |
| 228 lconn->Ping(rtc::TimeMillis()); |
| 229 ASSERT_TRUE_WAIT(lport->last_stun_msg(), kDefaultTimeout); |
| 230 ASSERT_TRUE(lport->last_stun_buf()); |
| 231 rconn->OnReadPacket(lport->last_stun_buf()->data<char>(), |
| 232 lport->last_stun_buf()->size(), |
| 233 rtc::PacketTime()); |
| 234 clock->AdvanceTime(rtc::TimeDelta::FromMilliseconds(ms)); |
| 235 ASSERT_TRUE_WAIT(rport->last_stun_msg(), kDefaultTimeout); |
| 236 ASSERT_TRUE(rport->last_stun_buf()); |
| 237 lconn->OnReadPacket(rport->last_stun_buf()->data<char>(), |
| 238 rport->last_stun_buf()->size(), |
| 239 rtc::PacketTime()); |
| 240 } |
| 241 |
| 225 class TestChannel : public sigslot::has_slots<> { | 242 class TestChannel : public sigslot::has_slots<> { |
| 226 public: | 243 public: |
| 227 // Takes ownership of |p1| (but not |p2|). | 244 // Takes ownership of |p1| (but not |p2|). |
| 228 TestChannel(Port* p1) | 245 TestChannel(Port* p1) |
| 229 : ice_mode_(ICEMODE_FULL), | 246 : ice_mode_(ICEMODE_FULL), |
| 230 port_(p1), | 247 port_(p1), |
| 231 complete_count_(0), | 248 complete_count_(0), |
| 232 conn_(NULL), | 249 conn_(NULL), |
| 233 remote_request_(), | 250 remote_request_(), |
| 234 nominated_(false) { | 251 nominated_(false) { |
| (...skipping 1602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1837 lconn->OnReadPacket(rport->last_stun_buf()->data<char>(), | 1854 lconn->OnReadPacket(rport->last_stun_buf()->data<char>(), |
| 1838 rport->last_stun_buf()->size(), | 1855 rport->last_stun_buf()->size(), |
| 1839 rtc::PacketTime()); | 1856 rtc::PacketTime()); |
| 1840 EXPECT_EQ(nomination, lconn->acked_nomination()); | 1857 EXPECT_EQ(nomination, lconn->acked_nomination()); |
| 1841 EXPECT_TRUE(lconn->nominated()); | 1858 EXPECT_TRUE(lconn->nominated()); |
| 1842 EXPECT_TRUE(rconn->nominated()); | 1859 EXPECT_TRUE(rconn->nominated()); |
| 1843 EXPECT_EQ(lconn->nominated(), lconn->stats().nominated); | 1860 EXPECT_EQ(lconn->nominated(), lconn->stats().nominated); |
| 1844 EXPECT_EQ(rconn->nominated(), rconn->stats().nominated); | 1861 EXPECT_EQ(rconn->nominated(), rconn->stats().nominated); |
| 1845 } | 1862 } |
| 1846 | 1863 |
| 1864 TEST_F(PortTest, TestRoundTripTime) { |
| 1865 rtc::ScopedFakeClock clock; |
| 1866 |
| 1867 std::unique_ptr<TestPort> lport( |
| 1868 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
| 1869 std::unique_ptr<TestPort> rport( |
| 1870 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1871 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1872 lport->SetIceTiebreaker(kTiebreaker1); |
| 1873 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 1874 rport->SetIceTiebreaker(kTiebreaker2); |
| 1875 |
| 1876 lport->PrepareAddress(); |
| 1877 rport->PrepareAddress(); |
| 1878 ASSERT_FALSE(lport->Candidates().empty()); |
| 1879 ASSERT_FALSE(rport->Candidates().empty()); |
| 1880 Connection* lconn = lport->CreateConnection(rport->Candidates()[0], |
| 1881 Port::ORIGIN_MESSAGE); |
| 1882 Connection* rconn = rport->CreateConnection(lport->Candidates()[0], |
| 1883 Port::ORIGIN_MESSAGE); |
| 1884 |
| 1885 EXPECT_EQ(0u, lconn->stats().total_round_trip_time_ms); |
| 1886 EXPECT_FALSE(lconn->stats().current_round_trip_time_ms); |
| 1887 |
| 1888 SendPingAndReceiveResponse( |
| 1889 lconn, lport.get(), rconn, rport.get(), &clock, 10); |
| 1890 EXPECT_EQ(10u, lconn->stats().total_round_trip_time_ms); |
| 1891 ASSERT_TRUE(lconn->stats().current_round_trip_time_ms); |
| 1892 EXPECT_EQ(10u, *lconn->stats().current_round_trip_time_ms); |
| 1893 |
| 1894 SendPingAndReceiveResponse( |
| 1895 lconn, lport.get(), rconn, rport.get(), &clock, 20); |
| 1896 EXPECT_EQ(30u, lconn->stats().total_round_trip_time_ms); |
| 1897 ASSERT_TRUE(lconn->stats().current_round_trip_time_ms); |
| 1898 EXPECT_EQ(20u, *lconn->stats().current_round_trip_time_ms); |
| 1899 |
| 1900 SendPingAndReceiveResponse( |
| 1901 lconn, lport.get(), rconn, rport.get(), &clock, 30); |
| 1902 EXPECT_EQ(60u, lconn->stats().total_round_trip_time_ms); |
| 1903 ASSERT_TRUE(lconn->stats().current_round_trip_time_ms); |
| 1904 EXPECT_EQ(30u, *lconn->stats().current_round_trip_time_ms); |
| 1905 } |
| 1906 |
| 1847 TEST_F(PortTest, TestUseCandidateAttribute) { | 1907 TEST_F(PortTest, TestUseCandidateAttribute) { |
| 1848 std::unique_ptr<TestPort> lport( | 1908 std::unique_ptr<TestPort> lport( |
| 1849 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); | 1909 CreateTestPort(kLocalAddr1, "lfrag", "lpass")); |
| 1850 std::unique_ptr<TestPort> rport( | 1910 std::unique_ptr<TestPort> rport( |
| 1851 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); | 1911 CreateTestPort(kLocalAddr2, "rfrag", "rpass")); |
| 1852 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1912 lport->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1853 lport->SetIceTiebreaker(kTiebreaker1); | 1913 lport->SetIceTiebreaker(kTiebreaker1); |
| 1854 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); | 1914 rport->SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 1855 rport->SetIceTiebreaker(kTiebreaker2); | 1915 rport->SetIceTiebreaker(kTiebreaker2); |
| 1856 | 1916 |
| (...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2818 port->CreateConnection(candidate, Port::ORIGIN_MESSAGE); | 2878 port->CreateConnection(candidate, Port::ORIGIN_MESSAGE); |
| 2819 EXPECT_NE(conn1, conn2); | 2879 EXPECT_NE(conn1, conn2); |
| 2820 conn_in_use = port->GetConnection(address); | 2880 conn_in_use = port->GetConnection(address); |
| 2821 EXPECT_EQ(conn2, conn_in_use); | 2881 EXPECT_EQ(conn2, conn_in_use); |
| 2822 EXPECT_EQ(2u, conn_in_use->remote_candidate().generation()); | 2882 EXPECT_EQ(2u, conn_in_use->remote_candidate().generation()); |
| 2823 | 2883 |
| 2824 // Make sure the new connection was not deleted. | 2884 // Make sure the new connection was not deleted. |
| 2825 rtc::Thread::Current()->ProcessMessages(300); | 2885 rtc::Thread::Current()->ProcessMessages(300); |
| 2826 EXPECT_TRUE(port->GetConnection(address) != nullptr); | 2886 EXPECT_TRUE(port->GetConnection(address) != nullptr); |
| 2827 } | 2887 } |
| OLD | NEW |