| 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 1990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2001 | 2001 |
| 2002 protected: | 2002 protected: |
| 2003 void PrepareChannel(cricket::P2PTransportChannel* ch) { | 2003 void PrepareChannel(cricket::P2PTransportChannel* ch) { |
| 2004 ch->SetIceRole(cricket::ICEROLE_CONTROLLING); | 2004 ch->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 2005 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); | 2005 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); |
| 2006 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 2006 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
| 2007 ch->SignalSelectedCandidatePairChanged.connect( | 2007 ch->SignalSelectedCandidatePairChanged.connect( |
| 2008 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged); | 2008 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged); |
| 2009 ch->SignalReadyToSend.connect(this, | 2009 ch->SignalReadyToSend.connect(this, |
| 2010 &P2PTransportChannelPingTest::OnReadyToSend); | 2010 &P2PTransportChannelPingTest::OnReadyToSend); |
| 2011 ch->SignalStateChanged.connect( |
| 2012 this, &P2PTransportChannelPingTest::OnChannelStateChanged); |
| 2011 } | 2013 } |
| 2012 | 2014 |
| 2013 cricket::Candidate CreateHostCandidate(const std::string& ip, | 2015 cricket::Candidate CreateHostCandidate(const std::string& ip, |
| 2014 int port, | 2016 int port, |
| 2015 int priority, | 2017 int priority, |
| 2016 const std::string& ufrag = "") { | 2018 const std::string& ufrag = "") { |
| 2017 cricket::Candidate c; | 2019 cricket::Candidate c; |
| 2018 c.set_address(rtc::SocketAddress(ip, port)); | 2020 c.set_address(rtc::SocketAddress(ip, port)); |
| 2019 c.set_component(1); | 2021 c.set_component(1); |
| 2020 c.set_protocol(cricket::UDP_PROTOCOL_NAME); | 2022 c.set_protocol(cricket::UDP_PROTOCOL_NAME); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2070 cricket::TransportChannel* transport_channel, | 2072 cricket::TransportChannel* transport_channel, |
| 2071 cricket::CandidatePairInterface* selected_candidate_pair, | 2073 cricket::CandidatePairInterface* selected_candidate_pair, |
| 2072 int last_sent_packet_id) { | 2074 int last_sent_packet_id) { |
| 2073 last_selected_candidate_pair_ = selected_candidate_pair; | 2075 last_selected_candidate_pair_ = selected_candidate_pair; |
| 2074 last_sent_packet_id_ = last_sent_packet_id; | 2076 last_sent_packet_id_ = last_sent_packet_id; |
| 2075 } | 2077 } |
| 2076 | 2078 |
| 2077 void OnReadyToSend(cricket::TransportChannel* channel) { | 2079 void OnReadyToSend(cricket::TransportChannel* channel) { |
| 2078 channel_ready_to_send_ = true; | 2080 channel_ready_to_send_ = true; |
| 2079 } | 2081 } |
| 2082 void OnChannelStateChanged(cricket::TransportChannelImpl* channel) { |
| 2083 channel_state_ = channel->GetState(); |
| 2084 } |
| 2080 | 2085 |
| 2081 cricket::CandidatePairInterface* last_selected_candidate_pair() { | 2086 cricket::CandidatePairInterface* last_selected_candidate_pair() { |
| 2082 return last_selected_candidate_pair_; | 2087 return last_selected_candidate_pair_; |
| 2083 } | 2088 } |
| 2084 int last_sent_packet_id() { return last_sent_packet_id_; } | 2089 int last_sent_packet_id() { return last_sent_packet_id_; } |
| 2085 bool channel_ready_to_send() { return channel_ready_to_send_; } | 2090 bool channel_ready_to_send() { return channel_ready_to_send_; } |
| 2086 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } | 2091 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } |
| 2092 cricket::TransportChannelState channel_state() { return channel_state_; } |
| 2087 | 2093 |
| 2088 private: | 2094 private: |
| 2089 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 2095 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
| 2090 std::unique_ptr<rtc::VirtualSocketServer> vss_; | 2096 std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 2091 rtc::SocketServerScope ss_scope_; | 2097 rtc::SocketServerScope ss_scope_; |
| 2092 cricket::CandidatePairInterface* last_selected_candidate_pair_ = nullptr; | 2098 cricket::CandidatePairInterface* last_selected_candidate_pair_ = nullptr; |
| 2093 int last_sent_packet_id_ = -1; | 2099 int last_sent_packet_id_ = -1; |
| 2094 bool channel_ready_to_send_ = false; | 2100 bool channel_ready_to_send_ = false; |
| 2101 cricket::TransportChannelState channel_state_ = cricket::STATE_INIT; |
| 2095 }; | 2102 }; |
| 2096 | 2103 |
| 2097 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { | 2104 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { |
| 2098 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2105 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2099 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); | 2106 cricket::P2PTransportChannel ch("trigger checks", 1, &pa); |
| 2100 PrepareChannel(&ch); | 2107 PrepareChannel(&ch); |
| 2101 ch.Connect(); | 2108 ch.Connect(); |
| 2102 ch.MaybeStartGathering(); | 2109 ch.MaybeStartGathering(); |
| 2103 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); | 2110 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
| 2104 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); | 2111 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2138 conn1->ReceivedPingResponse(); | 2145 conn1->ReceivedPingResponse(); |
| 2139 ASSERT_TRUE(conn1->writable()); | 2146 ASSERT_TRUE(conn1->writable()); |
| 2140 conn1->ReceivedPing(); | 2147 conn1->ReceivedPing(); |
| 2141 | 2148 |
| 2142 // Ping received, but the connection is already writable, so no | 2149 // Ping received, but the connection is already writable, so no |
| 2143 // "triggered check" and conn2 is pinged before conn1 because it has | 2150 // "triggered check" and conn2 is pinged before conn1 because it has |
| 2144 // a higher priority. | 2151 // a higher priority. |
| 2145 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); | 2152 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); |
| 2146 } | 2153 } |
| 2147 | 2154 |
| 2155 TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) { |
| 2156 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2157 cricket::P2PTransportChannel ch("state change", 1, &pa); |
| 2158 PrepareChannel(&ch); |
| 2159 ch.Connect(); |
| 2160 ch.MaybeStartGathering(); |
| 2161 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1)); |
| 2162 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2163 ASSERT_TRUE(conn1 != nullptr); |
| 2164 // Pruning the connection reduces the set of active connections and changes |
| 2165 // the channel state. |
| 2166 conn1->Prune(); |
| 2167 EXPECT_EQ_WAIT(cricket::STATE_FAILED, channel_state(), kDefaultTimeout); |
| 2168 } |
| 2169 |
| 2148 // Test adding remote candidates with different ufrags. If a remote candidate | 2170 // Test adding remote candidates with different ufrags. If a remote candidate |
| 2149 // is added with an old ufrag, it will be discarded. If it is added with a | 2171 // is added with an old ufrag, it will be discarded. If it is added with a |
| 2150 // ufrag that was not seen before, it will be used to create connections | 2172 // ufrag that was not seen before, it will be used to create connections |
| 2151 // although the ICE pwd in the remote candidate will be set when the ICE | 2173 // although the ICE pwd in the remote candidate will be set when the ICE |
| 2152 // credentials arrive. If a remote candidate is added with the current ICE | 2174 // credentials arrive. If a remote candidate is added with the current ICE |
| 2153 // ufrag, its pwd and generation will be set properly. | 2175 // ufrag, its pwd and generation will be set properly. |
| 2154 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { | 2176 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { |
| 2155 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2177 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2156 cricket::P2PTransportChannel ch("add candidate", 1, &pa); | 2178 cricket::P2PTransportChannel ch("add candidate", 1, &pa); |
| 2157 PrepareChannel(&ch); | 2179 PrepareChannel(&ch); |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2894 | 2916 |
| 2895 // TCP Relay/Relay is the next. | 2917 // TCP Relay/Relay is the next. |
| 2896 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 2918 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
| 2897 cricket::RELAY_PORT_TYPE, | 2919 cricket::RELAY_PORT_TYPE, |
| 2898 cricket::TCP_PROTOCOL_NAME); | 2920 cricket::TCP_PROTOCOL_NAME); |
| 2899 | 2921 |
| 2900 // Finally, Local/Relay will be pinged. | 2922 // Finally, Local/Relay will be pinged. |
| 2901 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, | 2923 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, |
| 2902 cricket::RELAY_PORT_TYPE); | 2924 cricket::RELAY_PORT_TYPE); |
| 2903 } | 2925 } |
| OLD | NEW |