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

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

Issue 2090823002: Revert of Adding IceConfig option to assume TURN/TURN candidate pairs will work. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 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
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/port.h » ('j') | 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 15 matching lines...) Expand all
26 #include "webrtc/base/logging.h" 26 #include "webrtc/base/logging.h"
27 #include "webrtc/base/natserver.h" 27 #include "webrtc/base/natserver.h"
28 #include "webrtc/base/natsocketfactory.h" 28 #include "webrtc/base/natsocketfactory.h"
29 #include "webrtc/base/physicalsocketserver.h" 29 #include "webrtc/base/physicalsocketserver.h"
30 #include "webrtc/base/proxyserver.h" 30 #include "webrtc/base/proxyserver.h"
31 #include "webrtc/base/socketaddress.h" 31 #include "webrtc/base/socketaddress.h"
32 #include "webrtc/base/ssladapter.h" 32 #include "webrtc/base/ssladapter.h"
33 #include "webrtc/base/thread.h" 33 #include "webrtc/base/thread.h"
34 #include "webrtc/base/virtualsocketserver.h" 34 #include "webrtc/base/virtualsocketserver.h"
35 35
36 namespace { 36 using cricket::kDefaultPortAllocatorFlags;
37 37 using cricket::kMinimumStepDelay;
38 using cricket::kDefaultStepDelay;
39 using cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET;
40 using cricket::ServerAddresses;
41 using cricket::MIN_PINGS_AT_WEAK_PING_INTERVAL;
38 using rtc::SocketAddress; 42 using rtc::SocketAddress;
39 43
40 // Default timeout for tests in this file. 44 static const int kDefaultTimeout = 1000;
41 // Should be large enough for slow buildbots to run the tests reliably.
42 static const int kDefaultTimeout = 10000;
43
44 static const int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN | 45 static const int kOnlyLocalPorts = cricket::PORTALLOCATOR_DISABLE_STUN |
45 cricket::PORTALLOCATOR_DISABLE_RELAY | 46 cricket::PORTALLOCATOR_DISABLE_RELAY |
46 cricket::PORTALLOCATOR_DISABLE_TCP; 47 cricket::PORTALLOCATOR_DISABLE_TCP;
47 static const int LOW_RTT = 20; 48 static const int LOW_RTT = 20;
48 // Addresses on the public internet. 49 // Addresses on the public internet.
49 static const SocketAddress kPublicAddrs[2] = 50 static const SocketAddress kPublicAddrs[2] =
50 { SocketAddress("11.11.11.11", 0), SocketAddress("22.22.22.22", 0) }; 51 { SocketAddress("11.11.11.11", 0), SocketAddress("22.22.22.22", 0) };
51 // IPv6 Addresses on the public internet. 52 // IPv6 Addresses on the public internet.
52 static const SocketAddress kIPv6PublicAddrs[2] = { 53 static const SocketAddress kIPv6PublicAddrs[2] = {
53 SocketAddress("2400:4030:1:2c00:be30:abcd:efab:cdef", 0), 54 SocketAddress("2400:4030:1:2c00:be30:abcd:efab:cdef", 0),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 static const char* kIcePwd[4] = {"TESTICEPWD00000000000000", 99 static const char* kIcePwd[4] = {"TESTICEPWD00000000000000",
99 "TESTICEPWD00000000000001", 100 "TESTICEPWD00000000000001",
100 "TESTICEPWD00000000000002", 101 "TESTICEPWD00000000000002",
101 "TESTICEPWD00000000000003"}; 102 "TESTICEPWD00000000000003"};
102 103
103 static const uint64_t kTiebreaker1 = 11111; 104 static const uint64_t kTiebreaker1 = 11111;
104 static const uint64_t kTiebreaker2 = 22222; 105 static const uint64_t kTiebreaker2 = 22222;
105 106
106 enum { MSG_ADD_CANDIDATES, MSG_REMOVE_CANDIDATES }; 107 enum { MSG_ADD_CANDIDATES, MSG_REMOVE_CANDIDATES };
107 108
108 cricket::IceConfig CreateIceConfig(int receiving_timeout, 109 static cricket::IceConfig CreateIceConfig(int receiving_timeout,
109 bool gather_continually, 110 bool gather_continually,
110 int backup_ping_interval = -1) { 111 int backup_ping_interval = -1) {
111 cricket::IceConfig config; 112 cricket::IceConfig config;
112 config.receiving_timeout = receiving_timeout; 113 config.receiving_timeout = receiving_timeout;
113 config.gather_continually = gather_continually; 114 config.gather_continually = gather_continually;
114 config.backup_connection_ping_interval = backup_ping_interval; 115 config.backup_connection_ping_interval = backup_ping_interval;
115 return config; 116 return config;
116 } 117 }
117 118
118 cricket::Candidate CreateUdpCandidate(const std::string& type,
119 const std::string& ip,
120 int port,
121 int priority,
122 const std::string& ufrag = "") {
123 cricket::Candidate c;
124 c.set_address(rtc::SocketAddress(ip, port));
125 c.set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT);
126 c.set_protocol(cricket::UDP_PROTOCOL_NAME);
127 c.set_priority(priority);
128 c.set_username(ufrag);
129 c.set_type(type);
130 return c;
131 }
132
133 } // namespace {
134
135 namespace cricket {
136
137 // This test simulates 2 P2P endpoints that want to establish connectivity 119 // This test simulates 2 P2P endpoints that want to establish connectivity
138 // with each other over various network topologies and conditions, which can be 120 // with each other over various network topologies and conditions, which can be
139 // specified in each individial test. 121 // specified in each individial test.
140 // A virtual network (via VirtualSocketServer) along with virtual firewalls and 122 // A virtual network (via VirtualSocketServer) along with virtual firewalls and
141 // NATs (via Firewall/NATSocketServer) are used to simulate the various network 123 // NATs (via Firewall/NATSocketServer) are used to simulate the various network
142 // conditions. We can configure the IP addresses of the endpoints, 124 // conditions. We can configure the IP addresses of the endpoints,
143 // block various types of connectivity, or add arbitrary levels of NAT. 125 // block various types of connectivity, or add arbitrary levels of NAT.
144 // We also run a STUN server and a relay server on the virtual network to allow 126 // We also run a STUN server and a relay server on the virtual network to allow
145 // our typical P2P mechanisms to do their thing. 127 // our typical P2P mechanisms to do their thing.
146 // For each case, we expect the P2P stack to eventually settle on a specific 128 // For each case, we expect the P2P stack to eventually settle on a specific
147 // form of connectivity to the other side. The test checks that the P2P 129 // form of connectivity to the other side. The test checks that the P2P
148 // negotiation successfully establishes connectivity within a certain time, 130 // negotiation successfully establishes connectivity within a certain time,
149 // and that the result is what we expect. 131 // and that the result is what we expect.
150 // Note that this class is a base class for use by other tests, who will provide 132 // Note that this class is a base class for use by other tests, who will provide
151 // specialized test behavior. 133 // specialized test behavior.
152 class P2PTransportChannelTestBase : public testing::Test, 134 class P2PTransportChannelTestBase : public testing::Test,
153 public rtc::MessageHandler, 135 public rtc::MessageHandler,
154 public sigslot::has_slots<> { 136 public sigslot::has_slots<> {
155 public: 137 public:
156 P2PTransportChannelTestBase() 138 P2PTransportChannelTestBase()
157 : main_(rtc::Thread::Current()), 139 : main_(rtc::Thread::Current()),
158 pss_(new rtc::PhysicalSocketServer), 140 pss_(new rtc::PhysicalSocketServer),
159 vss_(new rtc::VirtualSocketServer(pss_.get())), 141 vss_(new rtc::VirtualSocketServer(pss_.get())),
160 nss_(new rtc::NATSocketServer(vss_.get())), 142 nss_(new rtc::NATSocketServer(vss_.get())),
161 ss_(new rtc::FirewallSocketServer(nss_.get())), 143 ss_(new rtc::FirewallSocketServer(nss_.get())),
162 ss_scope_(ss_.get()), 144 ss_scope_(ss_.get()),
163 stun_server_(TestStunServer::Create(main_, kStunAddr)), 145 stun_server_(cricket::TestStunServer::Create(main_, kStunAddr)),
164 turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr), 146 turn_server_(main_, kTurnUdpIntAddr, kTurnUdpExtAddr),
165 relay_server_(main_, 147 relay_server_(main_, kRelayUdpIntAddr, kRelayUdpExtAddr,
166 kRelayUdpIntAddr, 148 kRelayTcpIntAddr, kRelayTcpExtAddr,
167 kRelayUdpExtAddr, 149 kRelaySslTcpIntAddr, kRelaySslTcpExtAddr),
168 kRelayTcpIntAddr, 150 socks_server1_(ss_.get(), kSocksProxyAddrs[0],
169 kRelayTcpExtAddr, 151 ss_.get(), kSocksProxyAddrs[0]),
170 kRelaySslTcpIntAddr, 152 socks_server2_(ss_.get(), kSocksProxyAddrs[1],
171 kRelaySslTcpExtAddr), 153 ss_.get(), kSocksProxyAddrs[1]),
172 socks_server1_(ss_.get(),
173 kSocksProxyAddrs[0],
174 ss_.get(),
175 kSocksProxyAddrs[0]),
176 socks_server2_(ss_.get(),
177 kSocksProxyAddrs[1],
178 ss_.get(),
179 kSocksProxyAddrs[1]),
180 force_relay_(false) { 154 force_relay_(false) {
181 ep1_.role_ = ICEROLE_CONTROLLING; 155 ep1_.role_ = cricket::ICEROLE_CONTROLLING;
182 ep2_.role_ = ICEROLE_CONTROLLED; 156 ep2_.role_ = cricket::ICEROLE_CONTROLLED;
183 157
184 ServerAddresses stun_servers; 158 ServerAddresses stun_servers;
185 stun_servers.insert(kStunAddr); 159 stun_servers.insert(kStunAddr);
186 ep1_.allocator_.reset(new BasicPortAllocator( 160 ep1_.allocator_.reset(new cricket::BasicPortAllocator(
187 &ep1_.network_manager_, stun_servers, kRelayUdpIntAddr, 161 &ep1_.network_manager_,
188 kRelayTcpIntAddr, kRelaySslTcpIntAddr)); 162 stun_servers, kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr));
189 ep2_.allocator_.reset(new BasicPortAllocator( 163 ep2_.allocator_.reset(new cricket::BasicPortAllocator(
190 &ep2_.network_manager_, stun_servers, kRelayUdpIntAddr, 164 &ep2_.network_manager_,
191 kRelayTcpIntAddr, kRelaySslTcpIntAddr)); 165 stun_servers, kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr));
192 } 166 }
193 167
194 protected: 168 protected:
195 enum Config { 169 enum Config {
196 OPEN, // Open to the Internet 170 OPEN, // Open to the Internet
197 NAT_FULL_CONE, // NAT, no filtering 171 NAT_FULL_CONE, // NAT, no filtering
198 NAT_ADDR_RESTRICTED, // NAT, must send to an addr to recv 172 NAT_ADDR_RESTRICTED, // NAT, must send to an addr to recv
199 NAT_PORT_RESTRICTED, // NAT, must send to an addr+port to recv 173 NAT_PORT_RESTRICTED, // NAT, must send to an addr+port to recv
200 NAT_SYMMETRIC, // NAT, endpoint-dependent bindings 174 NAT_SYMMETRIC, // NAT, endpoint-dependent bindings
201 NAT_DOUBLE_CONE, // Double NAT, both cone 175 NAT_DOUBLE_CONE, // Double NAT, both cone
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 if (!ch_packets_.empty()) { 209 if (!ch_packets_.empty()) {
236 std::string packet = ch_packets_.front(); 210 std::string packet = ch_packets_.front();
237 ret = (packet == std::string(data, len)); 211 ret = (packet == std::string(data, len));
238 ch_packets_.pop_front(); 212 ch_packets_.pop_front();
239 } 213 }
240 return ret; 214 return ret;
241 } 215 }
242 216
243 std::string name_; // TODO - Currently not used. 217 std::string name_; // TODO - Currently not used.
244 std::list<std::string> ch_packets_; 218 std::list<std::string> ch_packets_;
245 std::unique_ptr<P2PTransportChannel> ch_; 219 std::unique_ptr<cricket::P2PTransportChannel> ch_;
246 }; 220 };
247 221
248 struct CandidatesData : public rtc::MessageData { 222 struct CandidatesData : public rtc::MessageData {
249 CandidatesData(TransportChannel* ch, const Candidate& c) 223 CandidatesData(cricket::TransportChannel* ch, const cricket::Candidate& c)
250 : channel(ch), candidates(1, c) {} 224 : channel(ch), candidates(1, c) {}
251 CandidatesData(TransportChannel* ch, const std::vector<Candidate>& cc) 225 CandidatesData(cricket::TransportChannel* ch,
226 const std::vector<cricket::Candidate>& cc)
252 : channel(ch), candidates(cc) {} 227 : channel(ch), candidates(cc) {}
253 TransportChannel* channel; 228 cricket::TransportChannel* channel;
254 Candidates candidates; 229 cricket::Candidates candidates;
255 }; 230 };
256 231
257 struct Endpoint { 232 struct Endpoint {
258 Endpoint() 233 Endpoint()
259 : role_(ICEROLE_UNKNOWN), 234 : role_(cricket::ICEROLE_UNKNOWN),
260 tiebreaker_(0), 235 tiebreaker_(0),
261 role_conflict_(false), 236 role_conflict_(false),
262 save_candidates_(false) {} 237 save_candidates_(false) {}
263 bool HasChannel(TransportChannel* ch) { 238 bool HasChannel(cricket::TransportChannel* ch) {
264 return (ch == cd1_.ch_.get() || ch == cd2_.ch_.get()); 239 return (ch == cd1_.ch_.get() || ch == cd2_.ch_.get());
265 } 240 }
266 ChannelData* GetChannelData(TransportChannel* ch) { 241 ChannelData* GetChannelData(cricket::TransportChannel* ch) {
267 if (!HasChannel(ch)) return NULL; 242 if (!HasChannel(ch)) return NULL;
268 if (cd1_.ch_.get() == ch) 243 if (cd1_.ch_.get() == ch)
269 return &cd1_; 244 return &cd1_;
270 else 245 else
271 return &cd2_; 246 return &cd2_;
272 } 247 }
273 248
274 void SetIceRole(IceRole role) { role_ = role; } 249 void SetIceRole(cricket::IceRole role) { role_ = role; }
275 IceRole ice_role() { return role_; } 250 cricket::IceRole ice_role() { return role_; }
276 void SetIceTiebreaker(uint64_t tiebreaker) { tiebreaker_ = tiebreaker; } 251 void SetIceTiebreaker(uint64_t tiebreaker) { tiebreaker_ = tiebreaker; }
277 uint64_t GetIceTiebreaker() { return tiebreaker_; } 252 uint64_t GetIceTiebreaker() { return tiebreaker_; }
278 void OnRoleConflict(bool role_conflict) { role_conflict_ = role_conflict; } 253 void OnRoleConflict(bool role_conflict) { role_conflict_ = role_conflict; }
279 bool role_conflict() { return role_conflict_; } 254 bool role_conflict() { return role_conflict_; }
280 void SetAllocationStepDelay(uint32_t delay) { 255 void SetAllocationStepDelay(uint32_t delay) {
281 allocator_->set_step_delay(delay); 256 allocator_->set_step_delay(delay);
282 } 257 }
283 void SetAllowTcpListen(bool allow_tcp_listen) { 258 void SetAllowTcpListen(bool allow_tcp_listen) {
284 allocator_->set_allow_tcp_listen(allow_tcp_listen); 259 allocator_->set_allow_tcp_listen(allow_tcp_listen);
285 } 260 }
286 261
287 rtc::FakeNetworkManager network_manager_; 262 rtc::FakeNetworkManager network_manager_;
288 std::unique_ptr<BasicPortAllocator> allocator_; 263 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
289 ChannelData cd1_; 264 ChannelData cd1_;
290 ChannelData cd2_; 265 ChannelData cd2_;
291 IceRole role_; 266 cricket::IceRole role_;
292 uint64_t tiebreaker_; 267 uint64_t tiebreaker_;
293 bool role_conflict_; 268 bool role_conflict_;
294 bool save_candidates_; 269 bool save_candidates_;
295 std::vector<CandidatesData*> saved_candidates_; 270 std::vector<CandidatesData*> saved_candidates_;
296 bool ready_to_send_ = false;
297 }; 271 };
298 272
299 ChannelData* GetChannelData(TransportChannel* channel) { 273 ChannelData* GetChannelData(cricket::TransportChannel* channel) {
300 if (ep1_.HasChannel(channel)) 274 if (ep1_.HasChannel(channel))
301 return ep1_.GetChannelData(channel); 275 return ep1_.GetChannelData(channel);
302 else 276 else
303 return ep2_.GetChannelData(channel); 277 return ep2_.GetChannelData(channel);
304 } 278 }
305 279
306 void CreateChannels(int num) { 280 void CreateChannels(int num) {
307 std::string ice_ufrag_ep1_cd1_ch = kIceUfrag[0]; 281 std::string ice_ufrag_ep1_cd1_ch = kIceUfrag[0];
308 std::string ice_pwd_ep1_cd1_ch = kIcePwd[0]; 282 std::string ice_pwd_ep1_cd1_ch = kIcePwd[0];
309 std::string ice_ufrag_ep2_cd1_ch = kIceUfrag[1]; 283 std::string ice_ufrag_ep2_cd1_ch = kIceUfrag[1];
310 std::string ice_pwd_ep2_cd1_ch = kIcePwd[1]; 284 std::string ice_pwd_ep2_cd1_ch = kIcePwd[1];
311 ep1_.cd1_.ch_.reset(CreateChannel( 285 ep1_.cd1_.ch_.reset(CreateChannel(
312 0, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep1_cd1_ch, 286 0, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT,
313 ice_pwd_ep1_cd1_ch, ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch)); 287 ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch,
288 ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch));
314 ep2_.cd1_.ch_.reset(CreateChannel( 289 ep2_.cd1_.ch_.reset(CreateChannel(
315 1, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep2_cd1_ch, 290 1, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT,
316 ice_pwd_ep2_cd1_ch, ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch)); 291 ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch,
292 ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch));
317 ep1_.cd1_.ch_->MaybeStartGathering(); 293 ep1_.cd1_.ch_->MaybeStartGathering();
318 ep2_.cd1_.ch_->MaybeStartGathering(); 294 ep2_.cd1_.ch_->MaybeStartGathering();
319 if (num == 2) { 295 if (num == 2) {
320 std::string ice_ufrag_ep1_cd2_ch = kIceUfrag[2]; 296 std::string ice_ufrag_ep1_cd2_ch = kIceUfrag[2];
321 std::string ice_pwd_ep1_cd2_ch = kIcePwd[2]; 297 std::string ice_pwd_ep1_cd2_ch = kIcePwd[2];
322 std::string ice_ufrag_ep2_cd2_ch = kIceUfrag[3]; 298 std::string ice_ufrag_ep2_cd2_ch = kIceUfrag[3];
323 std::string ice_pwd_ep2_cd2_ch = kIcePwd[3]; 299 std::string ice_pwd_ep2_cd2_ch = kIcePwd[3];
324 ep1_.cd2_.ch_.reset(CreateChannel( 300 ep1_.cd2_.ch_.reset(CreateChannel(
325 0, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep1_cd2_ch, 301 0, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT,
326 ice_pwd_ep1_cd2_ch, ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch)); 302 ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch,
303 ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch));
327 ep2_.cd2_.ch_.reset(CreateChannel( 304 ep2_.cd2_.ch_.reset(CreateChannel(
328 1, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep2_cd2_ch, 305 1, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT,
329 ice_pwd_ep2_cd2_ch, ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch)); 306 ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch,
307 ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch));
330 ep1_.cd2_.ch_->MaybeStartGathering(); 308 ep1_.cd2_.ch_->MaybeStartGathering();
331 ep2_.cd2_.ch_->MaybeStartGathering(); 309 ep2_.cd2_.ch_->MaybeStartGathering();
332 } 310 }
333 } 311 }
334 P2PTransportChannel* CreateChannel(int endpoint, 312 cricket::P2PTransportChannel* CreateChannel(
335 int component, 313 int endpoint,
336 const std::string& local_ice_ufrag, 314 int component,
337 const std::string& local_ice_pwd, 315 const std::string& local_ice_ufrag,
338 const std::string& remote_ice_ufrag, 316 const std::string& local_ice_pwd,
339 const std::string& remote_ice_pwd) { 317 const std::string& remote_ice_ufrag,
340 P2PTransportChannel* channel = new P2PTransportChannel( 318 const std::string& remote_ice_pwd) {
319 cricket::P2PTransportChannel* channel = new cricket::P2PTransportChannel(
341 "test content name", component, GetAllocator(endpoint)); 320 "test content name", component, GetAllocator(endpoint));
342 channel->SignalReadyToSend.connect(
343 this, &P2PTransportChannelTestBase::OnReadyToSend);
344 channel->SignalCandidateGathered.connect( 321 channel->SignalCandidateGathered.connect(
345 this, &P2PTransportChannelTestBase::OnCandidateGathered); 322 this, &P2PTransportChannelTestBase::OnCandidateGathered);
346 channel->SignalCandidatesRemoved.connect( 323 channel->SignalCandidatesRemoved.connect(
347 this, &P2PTransportChannelTestBase::OnCandidatesRemoved); 324 this, &P2PTransportChannelTestBase::OnCandidatesRemoved);
348 channel->SignalReadPacket.connect( 325 channel->SignalReadPacket.connect(
349 this, &P2PTransportChannelTestBase::OnReadPacket); 326 this, &P2PTransportChannelTestBase::OnReadPacket);
350 channel->SignalRoleConflict.connect( 327 channel->SignalRoleConflict.connect(
351 this, &P2PTransportChannelTestBase::OnRoleConflict); 328 this, &P2PTransportChannelTestBase::OnRoleConflict);
352 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); 329 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd);
353 if (remote_ice_credential_source_ == FROM_SETICECREDENTIALS) { 330 if (remote_ice_credential_source_ == FROM_SETICECREDENTIALS) {
354 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd); 331 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd);
355 } 332 }
356 channel->SetIceRole(GetEndpoint(endpoint)->ice_role()); 333 channel->SetIceRole(GetEndpoint(endpoint)->ice_role());
357 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker()); 334 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker());
358 channel->Connect(); 335 channel->Connect();
359 return channel; 336 return channel;
360 } 337 }
361 void DestroyChannels() { 338 void DestroyChannels() {
362 ep1_.cd1_.ch_.reset(); 339 ep1_.cd1_.ch_.reset();
363 ep2_.cd1_.ch_.reset(); 340 ep2_.cd1_.ch_.reset();
364 ep1_.cd2_.ch_.reset(); 341 ep1_.cd2_.ch_.reset();
365 ep2_.cd2_.ch_.reset(); 342 ep2_.cd2_.ch_.reset();
366 } 343 }
367 P2PTransportChannel* ep1_ch1() { return ep1_.cd1_.ch_.get(); } 344 cricket::P2PTransportChannel* ep1_ch1() { return ep1_.cd1_.ch_.get(); }
368 P2PTransportChannel* ep1_ch2() { return ep1_.cd2_.ch_.get(); } 345 cricket::P2PTransportChannel* ep1_ch2() { return ep1_.cd2_.ch_.get(); }
369 P2PTransportChannel* ep2_ch1() { return ep2_.cd1_.ch_.get(); } 346 cricket::P2PTransportChannel* ep2_ch1() { return ep2_.cd1_.ch_.get(); }
370 P2PTransportChannel* ep2_ch2() { return ep2_.cd2_.ch_.get(); } 347 cricket::P2PTransportChannel* ep2_ch2() { return ep2_.cd2_.ch_.get(); }
371 348
372 // Common results. 349 // Common results.
373 static const Result kLocalUdpToLocalUdp; 350 static const Result kLocalUdpToLocalUdp;
374 static const Result kLocalUdpToStunUdp; 351 static const Result kLocalUdpToStunUdp;
375 static const Result kLocalUdpToPrflxUdp; 352 static const Result kLocalUdpToPrflxUdp;
376 static const Result kPrflxUdpToLocalUdp; 353 static const Result kPrflxUdpToLocalUdp;
377 static const Result kStunUdpToLocalUdp; 354 static const Result kStunUdpToLocalUdp;
378 static const Result kStunUdpToStunUdp; 355 static const Result kStunUdpToStunUdp;
379 static const Result kPrflxUdpToStunUdp; 356 static const Result kPrflxUdpToStunUdp;
380 static const Result kLocalUdpToRelayUdp; 357 static const Result kLocalUdpToRelayUdp;
381 static const Result kPrflxUdpToRelayUdp; 358 static const Result kPrflxUdpToRelayUdp;
382 static const Result kLocalTcpToLocalTcp; 359 static const Result kLocalTcpToLocalTcp;
383 static const Result kLocalTcpToPrflxTcp; 360 static const Result kLocalTcpToPrflxTcp;
384 static const Result kPrflxTcpToLocalTcp; 361 static const Result kPrflxTcpToLocalTcp;
385 362
386 rtc::NATSocketServer* nat() { return nss_.get(); } 363 rtc::NATSocketServer* nat() { return nss_.get(); }
387 rtc::FirewallSocketServer* fw() { return ss_.get(); } 364 rtc::FirewallSocketServer* fw() { return ss_.get(); }
388 365
389 Endpoint* GetEndpoint(int endpoint) { 366 Endpoint* GetEndpoint(int endpoint) {
390 if (endpoint == 0) { 367 if (endpoint == 0) {
391 return &ep1_; 368 return &ep1_;
392 } else if (endpoint == 1) { 369 } else if (endpoint == 1) {
393 return &ep2_; 370 return &ep2_;
394 } else { 371 } else {
395 return NULL; 372 return NULL;
396 } 373 }
397 } 374 }
398 PortAllocator* GetAllocator(int endpoint) { 375 cricket::PortAllocator* GetAllocator(int endpoint) {
399 return GetEndpoint(endpoint)->allocator_.get(); 376 return GetEndpoint(endpoint)->allocator_.get();
400 } 377 }
401 void AddAddress(int endpoint, const SocketAddress& addr) { 378 void AddAddress(int endpoint, const SocketAddress& addr) {
402 GetEndpoint(endpoint)->network_manager_.AddInterface(addr); 379 GetEndpoint(endpoint)->network_manager_.AddInterface(addr);
403 } 380 }
404 void AddAddress(int endpoint, 381 void AddAddress(int endpoint,
405 const SocketAddress& addr, 382 const SocketAddress& addr,
406 const std::string& ifname, 383 const std::string& ifname,
407 rtc::AdapterType adapter_type) { 384 rtc::AdapterType adapter_type) {
408 GetEndpoint(endpoint)->network_manager_.AddInterface(addr, ifname, 385 GetEndpoint(endpoint)->network_manager_.AddInterface(addr, ifname,
409 adapter_type); 386 adapter_type);
410 } 387 }
411 void RemoveAddress(int endpoint, const SocketAddress& addr) { 388 void RemoveAddress(int endpoint, const SocketAddress& addr) {
412 GetEndpoint(endpoint)->network_manager_.RemoveInterface(addr); 389 GetEndpoint(endpoint)->network_manager_.RemoveInterface(addr);
413 } 390 }
414 void SetProxy(int endpoint, rtc::ProxyType type) { 391 void SetProxy(int endpoint, rtc::ProxyType type) {
415 rtc::ProxyInfo info; 392 rtc::ProxyInfo info;
416 info.type = type; 393 info.type = type;
417 info.address = (type == rtc::PROXY_HTTPS) ? 394 info.address = (type == rtc::PROXY_HTTPS) ?
418 kHttpsProxyAddrs[endpoint] : kSocksProxyAddrs[endpoint]; 395 kHttpsProxyAddrs[endpoint] : kSocksProxyAddrs[endpoint];
419 GetAllocator(endpoint)->set_proxy("unittest/1.0", info); 396 GetAllocator(endpoint)->set_proxy("unittest/1.0", info);
420 } 397 }
421 void SetAllocatorFlags(int endpoint, int flags) { 398 void SetAllocatorFlags(int endpoint, int flags) {
422 GetAllocator(endpoint)->set_flags(flags); 399 GetAllocator(endpoint)->set_flags(flags);
423 } 400 }
424 void SetIceRole(int endpoint, IceRole role) { 401 void SetIceRole(int endpoint, cricket::IceRole role) {
425 GetEndpoint(endpoint)->SetIceRole(role); 402 GetEndpoint(endpoint)->SetIceRole(role);
426 } 403 }
427 void SetIceTiebreaker(int endpoint, uint64_t tiebreaker) { 404 void SetIceTiebreaker(int endpoint, uint64_t tiebreaker) {
428 GetEndpoint(endpoint)->SetIceTiebreaker(tiebreaker); 405 GetEndpoint(endpoint)->SetIceTiebreaker(tiebreaker);
429 } 406 }
430 bool GetRoleConflict(int endpoint) { 407 bool GetRoleConflict(int endpoint) {
431 return GetEndpoint(endpoint)->role_conflict(); 408 return GetEndpoint(endpoint)->role_conflict();
432 } 409 }
433 void SetAllocationStepDelay(int endpoint, uint32_t delay) { 410 void SetAllocationStepDelay(int endpoint, uint32_t delay) {
434 return GetEndpoint(endpoint)->SetAllocationStepDelay(delay); 411 return GetEndpoint(endpoint)->SetAllocationStepDelay(delay);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 // restart the ice gathering. Finally it waits for the transport to select a 583 // restart the ice gathering. Finally it waits for the transport to select a
607 // new connection using the newly generated ice candidates. 584 // new connection using the newly generated ice candidates.
608 // Before calling this function the end points must be configured. 585 // Before calling this function the end points must be configured.
609 void TestHandleIceUfragPasswordChanged() { 586 void TestHandleIceUfragPasswordChanged() {
610 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 587 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]);
611 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); 588 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]);
612 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && 589 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
613 ep2_ch1()->receiving() && ep2_ch1()->writable(), 590 ep2_ch1()->receiving() && ep2_ch1()->writable(),
614 1000, 1000); 591 1000, 1000);
615 592
616 const Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1()); 593 const cricket::Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1());
617 const Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1()); 594 const cricket::Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1());
618 const Candidate* old_remote_candidate1 = RemoteCandidate(ep1_ch1()); 595 const cricket::Candidate* old_remote_candidate1 =
619 const Candidate* old_remote_candidate2 = RemoteCandidate(ep2_ch1()); 596 RemoteCandidate(ep1_ch1());
597 const cricket::Candidate* old_remote_candidate2 =
598 RemoteCandidate(ep2_ch1());
620 599
621 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); 600 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]);
622 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 601 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]);
623 ep1_ch1()->MaybeStartGathering(); 602 ep1_ch1()->MaybeStartGathering();
624 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]); 603 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]);
625 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); 604 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]);
626 ep2_ch1()->MaybeStartGathering(); 605 ep2_ch1()->MaybeStartGathering();
627 606
628 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() != 607 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() !=
629 old_local_candidate1->generation(), 608 old_local_candidate1->generation(),
630 1000, 1000); 609 1000, 1000);
631 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep2_ch1())->generation() != 610 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep2_ch1())->generation() !=
632 old_local_candidate2->generation(), 611 old_local_candidate2->generation(),
633 1000, 1000); 612 1000, 1000);
634 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep1_ch1())->generation() != 613 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep1_ch1())->generation() !=
635 old_remote_candidate1->generation(), 614 old_remote_candidate1->generation(),
636 1000, 1000); 615 1000, 1000);
637 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep2_ch1())->generation() != 616 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep2_ch1())->generation() !=
638 old_remote_candidate2->generation(), 617 old_remote_candidate2->generation(),
639 1000, 1000); 618 1000, 1000);
640 EXPECT_EQ(1u, RemoteCandidate(ep2_ch1())->generation()); 619 EXPECT_EQ(1u, RemoteCandidate(ep2_ch1())->generation());
641 EXPECT_EQ(1u, RemoteCandidate(ep1_ch1())->generation()); 620 EXPECT_EQ(1u, RemoteCandidate(ep1_ch1())->generation());
642 } 621 }
643 622
644 void TestSignalRoleConflict() { 623 void TestSignalRoleConflict() {
645 SetIceTiebreaker(0, kTiebreaker1); // Default EP1 is in controlling state. 624 SetIceTiebreaker(0, kTiebreaker1); // Default EP1 is in controlling state.
646 625
647 SetIceRole(1, ICEROLE_CONTROLLING); 626 SetIceRole(1, cricket::ICEROLE_CONTROLLING);
648 SetIceTiebreaker(1, kTiebreaker2); 627 SetIceTiebreaker(1, kTiebreaker2);
649 628
650 // Creating channels with both channels role set to CONTROLLING. 629 // Creating channels with both channels role set to CONTROLLING.
651 CreateChannels(1); 630 CreateChannels(1);
652 // Since both the channels initiated with controlling state and channel2 631 // Since both the channels initiated with controlling state and channel2
653 // has higher tiebreaker value, channel1 should receive SignalRoleConflict. 632 // has higher tiebreaker value, channel1 should receive SignalRoleConflict.
654 EXPECT_TRUE_WAIT(GetRoleConflict(0), 1000); 633 EXPECT_TRUE_WAIT(GetRoleConflict(0), 1000);
655 EXPECT_FALSE(GetRoleConflict(1)); 634 EXPECT_FALSE(GetRoleConflict(1));
656 635
657 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && 636 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() &&
658 ep1_ch1()->writable() && 637 ep1_ch1()->writable() &&
659 ep2_ch1()->receiving() && 638 ep2_ch1()->receiving() &&
660 ep2_ch1()->writable(), 639 ep2_ch1()->writable(),
661 1000); 640 1000);
662 641
663 EXPECT_TRUE(ep1_ch1()->best_connection() && 642 EXPECT_TRUE(ep1_ch1()->best_connection() &&
664 ep2_ch1()->best_connection()); 643 ep2_ch1()->best_connection());
665 644
666 TestSendRecv(1); 645 TestSendRecv(1);
667 } 646 }
668 647
669 void OnReadyToSend(TransportChannel* ch) {
670 GetEndpoint(ch)->ready_to_send_ = true;
671 }
672
673 // We pass the candidates directly to the other side. 648 // We pass the candidates directly to the other side.
674 void OnCandidateGathered(TransportChannelImpl* ch, const Candidate& c) { 649 void OnCandidateGathered(cricket::TransportChannelImpl* ch,
675 if (force_relay_ && c.type() != RELAY_PORT_TYPE) 650 const cricket::Candidate& c) {
651 if (force_relay_ && c.type() != cricket::RELAY_PORT_TYPE)
676 return; 652 return;
677 653
678 if (GetEndpoint(ch)->save_candidates_) { 654 if (GetEndpoint(ch)->save_candidates_) {
679 GetEndpoint(ch)->saved_candidates_.push_back(new CandidatesData(ch, c)); 655 GetEndpoint(ch)->saved_candidates_.push_back(new CandidatesData(ch, c));
680 } else { 656 } else {
681 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, 657 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES,
682 new CandidatesData(ch, c)); 658 new CandidatesData(ch, c));
683 } 659 }
684 } 660 }
685 661
686 void PauseCandidates(int endpoint) { 662 void PauseCandidates(int endpoint) {
687 GetEndpoint(endpoint)->save_candidates_ = true; 663 GetEndpoint(endpoint)->save_candidates_ = true;
688 } 664 }
689 665
690 void OnCandidatesRemoved(TransportChannelImpl* ch, 666 void OnCandidatesRemoved(cricket::TransportChannelImpl* ch,
691 const std::vector<Candidate>& candidates) { 667 const std::vector<cricket::Candidate>& candidates) {
692 // Candidate removals are not paused. 668 // Candidate removals are not paused.
693 CandidatesData* candidates_data = new CandidatesData(ch, candidates); 669 CandidatesData* candidates_data = new CandidatesData(ch, candidates);
694 main_->Post(RTC_FROM_HERE, this, MSG_REMOVE_CANDIDATES, candidates_data); 670 main_->Post(RTC_FROM_HERE, this, MSG_REMOVE_CANDIDATES, candidates_data);
695 } 671 }
696 672
697 // Tcp candidate verification has to be done when they are generated. 673 // Tcp candidate verification has to be done when they are generated.
698 void VerifySavedTcpCandidates(int endpoint, const std::string& tcptype) { 674 void VerifySavedTcpCandidates(int endpoint, const std::string& tcptype) {
699 for (auto& data : GetEndpoint(endpoint)->saved_candidates_) { 675 for (auto& data : GetEndpoint(endpoint)->saved_candidates_) {
700 for (auto& candidate : data->candidates) { 676 for (auto& candidate : data->candidates) {
701 EXPECT_EQ(candidate.protocol(), TCP_PROTOCOL_NAME); 677 EXPECT_EQ(candidate.protocol(), cricket::TCP_PROTOCOL_NAME);
702 EXPECT_EQ(candidate.tcptype(), tcptype); 678 EXPECT_EQ(candidate.tcptype(), tcptype);
703 if (candidate.tcptype() == TCPTYPE_ACTIVE_STR) { 679 if (candidate.tcptype() == cricket::TCPTYPE_ACTIVE_STR) {
704 EXPECT_EQ(candidate.address().port(), DISCARD_PORT); 680 EXPECT_EQ(candidate.address().port(), cricket::DISCARD_PORT);
705 } else if (candidate.tcptype() == TCPTYPE_PASSIVE_STR) { 681 } else if (candidate.tcptype() == cricket::TCPTYPE_PASSIVE_STR) {
706 EXPECT_NE(candidate.address().port(), DISCARD_PORT); 682 EXPECT_NE(candidate.address().port(), cricket::DISCARD_PORT);
707 } else { 683 } else {
708 FAIL() << "Unknown tcptype: " << candidate.tcptype(); 684 FAIL() << "Unknown tcptype: " << candidate.tcptype();
709 } 685 }
710 } 686 }
711 } 687 }
712 } 688 }
713 689
714 void ResumeCandidates(int endpoint) { 690 void ResumeCandidates(int endpoint) {
715 Endpoint* ed = GetEndpoint(endpoint); 691 Endpoint* ed = GetEndpoint(endpoint);
716 std::vector<CandidatesData*>::iterator it = ed->saved_candidates_.begin(); 692 std::vector<CandidatesData*>::iterator it = ed->saved_candidates_.begin();
717 for (; it != ed->saved_candidates_.end(); ++it) { 693 for (; it != ed->saved_candidates_.end(); ++it) {
718 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, *it); 694 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, *it);
719 } 695 }
720 ed->saved_candidates_.clear(); 696 ed->saved_candidates_.clear();
721 ed->save_candidates_ = false; 697 ed->save_candidates_ = false;
722 } 698 }
723 699
724 void OnMessage(rtc::Message* msg) { 700 void OnMessage(rtc::Message* msg) {
725 switch (msg->message_id) { 701 switch (msg->message_id) {
726 case MSG_ADD_CANDIDATES: { 702 case MSG_ADD_CANDIDATES: {
727 std::unique_ptr<CandidatesData> data( 703 std::unique_ptr<CandidatesData> data(
728 static_cast<CandidatesData*>(msg->pdata)); 704 static_cast<CandidatesData*>(msg->pdata));
729 P2PTransportChannel* rch = GetRemoteChannel(data->channel); 705 cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel);
730 if (!rch) {
731 return;
732 }
733 for (auto& c : data->candidates) { 706 for (auto& c : data->candidates) {
734 if (remote_ice_credential_source_ != FROM_CANDIDATE) { 707 if (remote_ice_credential_source_ != FROM_CANDIDATE) {
735 c.set_username(""); 708 c.set_username("");
736 c.set_password(""); 709 c.set_password("");
737 } 710 }
738 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->" 711 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->"
739 << rch->component() << "): " << c.ToString(); 712 << rch->component() << "): " << c.ToString();
740 rch->AddRemoteCandidate(c); 713 rch->AddRemoteCandidate(c);
741 } 714 }
742 break; 715 break;
743 } 716 }
744 case MSG_REMOVE_CANDIDATES: { 717 case MSG_REMOVE_CANDIDATES: {
745 std::unique_ptr<CandidatesData> data( 718 std::unique_ptr<CandidatesData> data(
746 static_cast<CandidatesData*>(msg->pdata)); 719 static_cast<CandidatesData*>(msg->pdata));
747 P2PTransportChannel* rch = GetRemoteChannel(data->channel); 720 cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel);
748 if (!rch) { 721 for (cricket::Candidate& c : data->candidates) {
749 return;
750 }
751 for (Candidate& c : data->candidates) {
752 LOG(LS_INFO) << "Removed remote candidate " << c.ToString(); 722 LOG(LS_INFO) << "Removed remote candidate " << c.ToString();
753 rch->RemoveRemoteCandidate(c); 723 rch->RemoveRemoteCandidate(c);
754 } 724 }
755 break; 725 break;
756 } 726 }
757 } 727 }
758 } 728 }
759 void OnReadPacket(TransportChannel* channel, 729 void OnReadPacket(cricket::TransportChannel* channel, const char* data,
760 const char* data, 730 size_t len, const rtc::PacketTime& packet_time,
761 size_t len,
762 const rtc::PacketTime& packet_time,
763 int flags) { 731 int flags) {
764 std::list<std::string>& packets = GetPacketList(channel); 732 std::list<std::string>& packets = GetPacketList(channel);
765 packets.push_front(std::string(data, len)); 733 packets.push_front(std::string(data, len));
766 } 734 }
767 void OnRoleConflict(TransportChannelImpl* channel) { 735 void OnRoleConflict(cricket::TransportChannelImpl* channel) {
768 GetEndpoint(channel)->OnRoleConflict(true); 736 GetEndpoint(channel)->OnRoleConflict(true);
769 IceRole new_role = GetEndpoint(channel)->ice_role() == ICEROLE_CONTROLLING 737 cricket::IceRole new_role =
770 ? ICEROLE_CONTROLLED 738 GetEndpoint(channel)->ice_role() == cricket::ICEROLE_CONTROLLING ?
771 : ICEROLE_CONTROLLING; 739 cricket::ICEROLE_CONTROLLED : cricket::ICEROLE_CONTROLLING;
772 channel->SetIceRole(new_role); 740 channel->SetIceRole(new_role);
773 } 741 }
774 742
775 int SendData(TransportChannel* channel, const char* data, size_t len) { 743 int SendData(cricket::TransportChannel* channel,
744 const char* data, size_t len) {
776 rtc::PacketOptions options; 745 rtc::PacketOptions options;
777 return channel->SendPacket(data, len, options, 0); 746 return channel->SendPacket(data, len, options, 0);
778 } 747 }
779 bool CheckDataOnChannel(TransportChannel* channel, 748 bool CheckDataOnChannel(cricket::TransportChannel* channel,
780 const char* data, 749 const char* data, int len) {
781 int len) {
782 return GetChannelData(channel)->CheckData(data, len); 750 return GetChannelData(channel)->CheckData(data, len);
783 } 751 }
784 static const Candidate* LocalCandidate(P2PTransportChannel* ch) { 752 static const cricket::Candidate* LocalCandidate(
753 cricket::P2PTransportChannel* ch) {
785 return (ch && ch->best_connection()) ? 754 return (ch && ch->best_connection()) ?
786 &ch->best_connection()->local_candidate() : NULL; 755 &ch->best_connection()->local_candidate() : NULL;
787 } 756 }
788 static const Candidate* RemoteCandidate(P2PTransportChannel* ch) { 757 static const cricket::Candidate* RemoteCandidate(
758 cricket::P2PTransportChannel* ch) {
789 return (ch && ch->best_connection()) ? 759 return (ch && ch->best_connection()) ?
790 &ch->best_connection()->remote_candidate() : NULL; 760 &ch->best_connection()->remote_candidate() : NULL;
791 } 761 }
792 Endpoint* GetEndpoint(TransportChannel* ch) { 762 Endpoint* GetEndpoint(cricket::TransportChannel* ch) {
793 if (ep1_.HasChannel(ch)) { 763 if (ep1_.HasChannel(ch)) {
794 return &ep1_; 764 return &ep1_;
795 } else if (ep2_.HasChannel(ch)) { 765 } else if (ep2_.HasChannel(ch)) {
796 return &ep2_; 766 return &ep2_;
797 } else { 767 } else {
798 return NULL; 768 return NULL;
799 } 769 }
800 } 770 }
801 P2PTransportChannel* GetRemoteChannel(TransportChannel* ch) { 771 cricket::P2PTransportChannel* GetRemoteChannel(
772 cricket::TransportChannel* ch) {
802 if (ch == ep1_ch1()) 773 if (ch == ep1_ch1())
803 return ep2_ch1(); 774 return ep2_ch1();
804 else if (ch == ep1_ch2()) 775 else if (ch == ep1_ch2())
805 return ep2_ch2(); 776 return ep2_ch2();
806 else if (ch == ep2_ch1()) 777 else if (ch == ep2_ch1())
807 return ep1_ch1(); 778 return ep1_ch1();
808 else if (ch == ep2_ch2()) 779 else if (ch == ep2_ch2())
809 return ep1_ch2(); 780 return ep1_ch2();
810 else 781 else
811 return NULL; 782 return NULL;
812 } 783 }
813 std::list<std::string>& GetPacketList(TransportChannel* ch) { 784 std::list<std::string>& GetPacketList(cricket::TransportChannel* ch) {
814 return GetChannelData(ch)->ch_packets_; 785 return GetChannelData(ch)->ch_packets_;
815 } 786 }
816 787
817 enum RemoteIceCredentialSource { FROM_CANDIDATE, FROM_SETICECREDENTIALS }; 788 enum RemoteIceCredentialSource { FROM_CANDIDATE, FROM_SETICECREDENTIALS };
818 789
819 // How does the test pass ICE credentials to the P2PTransportChannel? 790 // How does the test pass ICE credentials to the P2PTransportChannel?
820 // On the candidate itself, or through SetIceCredentials? 791 // On the candidate itself, or through SetIceCredentials?
821 // Goes through the candidate itself by default. 792 // Goes through the candidate itself by default.
822 void set_remote_ice_credential_source(RemoteIceCredentialSource source) { 793 void set_remote_ice_credential_source(RemoteIceCredentialSource source) {
823 remote_ice_credential_source_ = source; 794 remote_ice_credential_source_ = source;
824 } 795 }
825 796
826 void set_force_relay(bool relay) { 797 void set_force_relay(bool relay) {
827 force_relay_ = relay; 798 force_relay_ = relay;
828 } 799 }
829 800
830 private: 801 private:
831 rtc::Thread* main_; 802 rtc::Thread* main_;
832 std::unique_ptr<rtc::PhysicalSocketServer> pss_; 803 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
833 std::unique_ptr<rtc::VirtualSocketServer> vss_; 804 std::unique_ptr<rtc::VirtualSocketServer> vss_;
834 std::unique_ptr<rtc::NATSocketServer> nss_; 805 std::unique_ptr<rtc::NATSocketServer> nss_;
835 std::unique_ptr<rtc::FirewallSocketServer> ss_; 806 std::unique_ptr<rtc::FirewallSocketServer> ss_;
836 rtc::SocketServerScope ss_scope_; 807 rtc::SocketServerScope ss_scope_;
837 std::unique_ptr<TestStunServer> stun_server_; 808 std::unique_ptr<cricket::TestStunServer> stun_server_;
838 TestTurnServer turn_server_; 809 cricket::TestTurnServer turn_server_;
839 TestRelayServer relay_server_; 810 cricket::TestRelayServer relay_server_;
840 rtc::SocksProxyServer socks_server1_; 811 rtc::SocksProxyServer socks_server1_;
841 rtc::SocksProxyServer socks_server2_; 812 rtc::SocksProxyServer socks_server2_;
842 Endpoint ep1_; 813 Endpoint ep1_;
843 Endpoint ep2_; 814 Endpoint ep2_;
844 RemoteIceCredentialSource remote_ice_credential_source_ = FROM_CANDIDATE; 815 RemoteIceCredentialSource remote_ice_credential_source_ = FROM_CANDIDATE;
845 bool force_relay_; 816 bool force_relay_;
846 }; 817 };
847 818
848 // The tests have only a few outcomes, which we predefine. 819 // The tests have only a few outcomes, which we predefine.
849 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: 820 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase::
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 // Just test every combination of the configs in the Config enum. 858 // Just test every combination of the configs in the Config enum.
888 class P2PTransportChannelTest : public P2PTransportChannelTestBase { 859 class P2PTransportChannelTest : public P2PTransportChannelTestBase {
889 protected: 860 protected:
890 static const Result* kMatrix[NUM_CONFIGS][NUM_CONFIGS]; 861 static const Result* kMatrix[NUM_CONFIGS][NUM_CONFIGS];
891 void ConfigureEndpoints(Config config1, 862 void ConfigureEndpoints(Config config1,
892 Config config2, 863 Config config2,
893 int allocator_flags1, 864 int allocator_flags1,
894 int allocator_flags2) { 865 int allocator_flags2) {
895 ServerAddresses stun_servers; 866 ServerAddresses stun_servers;
896 stun_servers.insert(kStunAddr); 867 stun_servers.insert(kStunAddr);
897 GetEndpoint(0)->allocator_.reset(new BasicPortAllocator( 868 GetEndpoint(0)->allocator_.reset(
898 &(GetEndpoint(0)->network_manager_), stun_servers, rtc::SocketAddress(), 869 new cricket::BasicPortAllocator(&(GetEndpoint(0)->network_manager_),
899 rtc::SocketAddress(), rtc::SocketAddress())); 870 stun_servers,
900 GetEndpoint(1)->allocator_.reset(new BasicPortAllocator( 871 rtc::SocketAddress(), rtc::SocketAddress(),
901 &(GetEndpoint(1)->network_manager_), stun_servers, rtc::SocketAddress(), 872 rtc::SocketAddress()));
902 rtc::SocketAddress(), rtc::SocketAddress())); 873 GetEndpoint(1)->allocator_.reset(
874 new cricket::BasicPortAllocator(&(GetEndpoint(1)->network_manager_),
875 stun_servers,
876 rtc::SocketAddress(), rtc::SocketAddress(),
877 rtc::SocketAddress()));
903 878
904 RelayServerConfig turn_server(RELAY_TURN); 879 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
905 turn_server.credentials = kRelayCredentials; 880 turn_server.credentials = kRelayCredentials;
906 turn_server.ports.push_back( 881 turn_server.ports.push_back(
907 ProtocolAddress(kTurnUdpIntAddr, PROTO_UDP, false)); 882 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
908 GetEndpoint(0)->allocator_->AddTurnServer(turn_server); 883 GetEndpoint(0)->allocator_->AddTurnServer(turn_server);
909 GetEndpoint(1)->allocator_->AddTurnServer(turn_server); 884 GetEndpoint(1)->allocator_->AddTurnServer(turn_server);
910 885
911 int delay = kMinimumStepDelay; 886 int delay = kMinimumStepDelay;
912 ConfigureEndpoint(0, config1); 887 ConfigureEndpoint(0, config1);
913 SetAllocatorFlags(0, allocator_flags1); 888 SetAllocatorFlags(0, allocator_flags1);
914 SetAllocationStepDelay(0, delay); 889 SetAllocationStepDelay(0, delay);
915 ConfigureEndpoint(1, config2); 890 ConfigureEndpoint(1, config2);
916 SetAllocatorFlags(1, allocator_flags2); 891 SetAllocatorFlags(1, allocator_flags2);
917 SetAllocationStepDelay(1, delay); 892 SetAllocationStepDelay(1, delay);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 1083
1109 // Test the operation of GetStats. 1084 // Test the operation of GetStats.
1110 TEST_F(P2PTransportChannelTest, GetStats) { 1085 TEST_F(P2PTransportChannelTest, GetStats) {
1111 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1086 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1112 kDefaultPortAllocatorFlags); 1087 kDefaultPortAllocatorFlags);
1113 CreateChannels(1); 1088 CreateChannels(1);
1114 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1089 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1115 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1090 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1116 1000, 1000); 1091 1000, 1000);
1117 TestSendRecv(1); 1092 TestSendRecv(1);
1118 ConnectionInfos infos; 1093 cricket::ConnectionInfos infos;
1119 ASSERT_TRUE(ep1_ch1()->GetStats(&infos)); 1094 ASSERT_TRUE(ep1_ch1()->GetStats(&infos));
1120 ASSERT_TRUE(infos.size() >= 1); 1095 ASSERT_TRUE(infos.size() >= 1);
1121 ConnectionInfo* best_conn_info = nullptr; 1096 cricket::ConnectionInfo* best_conn_info = nullptr;
1122 for (ConnectionInfo& info : infos) { 1097 for (cricket::ConnectionInfo& info : infos) {
1123 if (info.best_connection) { 1098 if (info.best_connection) {
1124 best_conn_info = &info; 1099 best_conn_info = &info;
1125 break; 1100 break;
1126 } 1101 }
1127 } 1102 }
1128 ASSERT_TRUE(best_conn_info != nullptr); 1103 ASSERT_TRUE(best_conn_info != nullptr);
1129 EXPECT_TRUE(best_conn_info->new_connection); 1104 EXPECT_TRUE(best_conn_info->new_connection);
1130 EXPECT_TRUE(best_conn_info->receiving); 1105 EXPECT_TRUE(best_conn_info->receiving);
1131 EXPECT_TRUE(best_conn_info->writable); 1106 EXPECT_TRUE(best_conn_info->writable);
1132 EXPECT_FALSE(best_conn_info->timeout); 1107 EXPECT_FALSE(best_conn_info->timeout);
(...skipping 15 matching lines...) Expand all
1148 CreateChannels(1); 1123 CreateChannels(1);
1149 // Only have remote credentials come in for ep2, not ep1. 1124 // Only have remote credentials come in for ep2, not ep1.
1150 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); 1125 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]);
1151 1126
1152 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive 1127 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive
1153 // candidate. 1128 // candidate.
1154 PauseCandidates(1); 1129 PauseCandidates(1);
1155 1130
1156 // The caller should have the best connection connected to the peer reflexive 1131 // The caller should have the best connection connected to the peer reflexive
1157 // candidate. 1132 // candidate.
1158 const Connection* best_connection = NULL; 1133 const cricket::Connection* best_connection = NULL;
1159 WAIT((best_connection = ep1_ch1()->best_connection()) != NULL, 2000); 1134 WAIT((best_connection = ep1_ch1()->best_connection()) != NULL, 2000);
1160 EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type()); 1135 EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type());
1161 1136
1162 // Because we don't have a remote pwd, we don't ping yet. 1137 // Because we don't have a remote pwd, we don't ping yet.
1163 EXPECT_EQ(kIceUfrag[1], 1138 EXPECT_EQ(kIceUfrag[1],
1164 ep1_ch1()->best_connection()->remote_candidate().username()); 1139 ep1_ch1()->best_connection()->remote_candidate().username());
1165 EXPECT_EQ("", ep1_ch1()->best_connection()->remote_candidate().password()); 1140 EXPECT_EQ("", ep1_ch1()->best_connection()->remote_candidate().password());
1166 // Because we don't have ICE credentials yet, we don't know the generation. 1141 // Because we don't have ICE credentials yet, we don't know the generation.
1167 EXPECT_EQ(0u, ep1_ch1()->best_connection()->remote_candidate().generation()); 1142 EXPECT_EQ(0u, ep1_ch1()->best_connection()->remote_candidate().generation());
1168 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); 1143 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 1197 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]);
1223 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 1198 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]);
1224 // After setting the remote ICE credentials, the password and generation 1199 // After setting the remote ICE credentials, the password and generation
1225 // of the peer reflexive candidate should be updated. 1200 // of the peer reflexive candidate should be updated.
1226 EXPECT_EQ(kIcePwd[1], 1201 EXPECT_EQ(kIcePwd[1],
1227 ep1_ch1()->best_connection()->remote_candidate().password()); 1202 ep1_ch1()->best_connection()->remote_candidate().password());
1228 EXPECT_EQ(1u, ep1_ch1()->best_connection()->remote_candidate().generation()); 1203 EXPECT_EQ(1u, ep1_ch1()->best_connection()->remote_candidate().generation());
1229 1204
1230 ResumeCandidates(1); 1205 ResumeCandidates(1);
1231 1206
1232 const Connection* best_connection = NULL; 1207 const cricket::Connection* best_connection = NULL;
1233 WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 2000); 1208 WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 2000);
1234 1209
1235 // Wait to verify the connection is not culled. 1210 // Wait to verify the connection is not culled.
1236 WAIT(ep1_ch1()->writable(), 2000); 1211 WAIT(ep1_ch1()->writable(), 2000);
1237 EXPECT_EQ(ep2_ch1()->best_connection(), best_connection); 1212 EXPECT_EQ(ep2_ch1()->best_connection(), best_connection);
1238 EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type()); 1213 EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type());
1239 DestroyChannels(); 1214 DestroyChannels();
1240 } 1215 }
1241 1216
1242 // Test that we properly create a connection on a STUN ping from unknown address 1217 // Test that we properly create a connection on a STUN ping from unknown address
1243 // when the signaling is slow, even if the new candidate is created due to the 1218 // when the signaling is slow, even if the new candidate is created due to the
1244 // remote peer doing an ICE restart, pairing this candidate across generations. 1219 // remote peer doing an ICE restart, pairing this candidate across generations.
1245 // 1220 //
1246 // Previously this wasn't working due to a bug where the peer reflexive 1221 // Previously this wasn't working due to a bug where the peer reflexive
1247 // candidate was only updated for the newest generation candidate pairs, and 1222 // candidate was only updated for the newest generation candidate pairs, and
1248 // not older-generation candidate pairs created by pairing candidates across 1223 // not older-generation candidate pairs created by pairing candidates across
1249 // generations. This resulted in the old-generation prflx candidate being 1224 // generations. This resulted in the old-generation prflx candidate being
1250 // prioritized above new-generation candidate pairs. 1225 // prioritized above new-generation candidate pairs.
1251 TEST_F(P2PTransportChannelTest, 1226 TEST_F(P2PTransportChannelTest,
1252 PeerReflexiveCandidateBeforeSignalingWithIceRestart) { 1227 PeerReflexiveCandidateBeforeSignalingWithIceRestart) {
1253 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1228 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1254 kDefaultPortAllocatorFlags); 1229 kDefaultPortAllocatorFlags);
1255 // Only gather relay candidates, so that when the prflx candidate arrives 1230 // Only gather relay candidates, so that when the prflx candidate arrives
1256 // it's prioritized above the current candidate pair. 1231 // it's prioritized above the current candidate pair.
1257 GetEndpoint(0)->allocator_->set_candidate_filter(CF_RELAY); 1232 GetEndpoint(0)->allocator_->set_candidate_filter(cricket::CF_RELAY);
1258 GetEndpoint(1)->allocator_->set_candidate_filter(CF_RELAY); 1233 GetEndpoint(1)->allocator_->set_candidate_filter(cricket::CF_RELAY);
1259 // Setting this allows us to control when SetRemoteIceCredentials is called. 1234 // Setting this allows us to control when SetRemoteIceCredentials is called.
1260 set_remote_ice_credential_source(FROM_CANDIDATE); 1235 set_remote_ice_credential_source(FROM_CANDIDATE);
1261 CreateChannels(1); 1236 CreateChannels(1);
1262 // Wait for the initial connection to be made. 1237 // Wait for the initial connection to be made.
1263 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 1238 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]);
1264 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); 1239 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]);
1265 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1240 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1266 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1241 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1267 kDefaultTimeout); 1242 kDefaultTimeout);
1268 1243
1269 // Simulate an ICE restart on ep2, but don't signal the candidate or new 1244 // Simulate an ICE restart on ep2, but don't signal the candidate or new
1270 // ICE credentials until after a prflx connection has been made. 1245 // ICE credentials until after a prflx connection has been made.
1271 PauseCandidates(1); 1246 PauseCandidates(1);
1272 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]); 1247 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]);
1273 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 1248 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]);
1274 ep2_ch1()->MaybeStartGathering(); 1249 ep2_ch1()->MaybeStartGathering();
1275 1250
1276 // The caller should have the best connection connected to the peer reflexive 1251 // The caller should have the best connection connected to the peer reflexive
1277 // candidate. 1252 // candidate.
1278 EXPECT_EQ_WAIT("prflx", 1253 EXPECT_EQ_WAIT("prflx",
1279 ep1_ch1()->best_connection()->remote_candidate().type(), 1254 ep1_ch1()->best_connection()->remote_candidate().type(),
1280 kDefaultTimeout); 1255 kDefaultTimeout);
1281 const Connection* prflx_best_connection = ep1_ch1()->best_connection(); 1256 const cricket::Connection* prflx_best_connection =
1257 ep1_ch1()->best_connection();
1282 1258
1283 // Now simulate the ICE restart on ep1. 1259 // Now simulate the ICE restart on ep1.
1284 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); 1260 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]);
1285 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); 1261 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]);
1286 ep1_ch1()->MaybeStartGathering(); 1262 ep1_ch1()->MaybeStartGathering();
1287 1263
1288 // Finally send the candidates from ep2's ICE restart and verify that ep1 uses 1264 // Finally send the candidates from ep2's ICE restart and verify that ep1 uses
1289 // their information to update the peer reflexive candidate. 1265 // their information to update the peer reflexive candidate.
1290 ResumeCandidates(1); 1266 ResumeCandidates(1);
1291 1267
1292 EXPECT_EQ_WAIT("relay", 1268 EXPECT_EQ_WAIT("relay",
1293 ep1_ch1()->best_connection()->remote_candidate().type(), 1269 ep1_ch1()->best_connection()->remote_candidate().type(),
1294 kDefaultTimeout); 1270 kDefaultTimeout);
1295 EXPECT_EQ(prflx_best_connection, ep1_ch1()->best_connection()); 1271 EXPECT_EQ(prflx_best_connection, ep1_ch1()->best_connection());
1296 DestroyChannels(); 1272 DestroyChannels();
1297 } 1273 }
1298 1274
1299 // Test that if remote candidates don't have ufrag and pwd, we still work. 1275 // Test that if remote candidates don't have ufrag and pwd, we still work.
1300 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) { 1276 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) {
1301 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); 1277 set_remote_ice_credential_source(FROM_SETICECREDENTIALS);
1302 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1278 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1303 kDefaultPortAllocatorFlags); 1279 kDefaultPortAllocatorFlags);
1304 CreateChannels(1); 1280 CreateChannels(1);
1305 const Connection* best_connection = NULL; 1281 const cricket::Connection* best_connection = NULL;
1306 // Wait until the callee's connections are created. 1282 // Wait until the callee's connections are created.
1307 WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 1000); 1283 WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 1000);
1308 // Wait to see if they get culled; they shouldn't. 1284 // Wait to see if they get culled; they shouldn't.
1309 WAIT(ep2_ch1()->best_connection() != best_connection, 1000); 1285 WAIT(ep2_ch1()->best_connection() != best_connection, 1000);
1310 EXPECT_TRUE(ep2_ch1()->best_connection() == best_connection); 1286 EXPECT_TRUE(ep2_ch1()->best_connection() == best_connection);
1311 DestroyChannels(); 1287 DestroyChannels();
1312 } 1288 }
1313 1289
1314 // Test that a host behind NAT cannot be reached when incoming_only 1290 // Test that a host behind NAT cannot be reached when incoming_only
1315 // is set to true. 1291 // is set to true.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 DestroyChannels(); 1326 DestroyChannels();
1351 } 1327 }
1352 1328
1353 TEST_F(P2PTransportChannelTest, TestTcpConnectionsFromActiveToPassive) { 1329 TEST_F(P2PTransportChannelTest, TestTcpConnectionsFromActiveToPassive) {
1354 AddAddress(0, kPublicAddrs[0]); 1330 AddAddress(0, kPublicAddrs[0]);
1355 AddAddress(1, kPublicAddrs[1]); 1331 AddAddress(1, kPublicAddrs[1]);
1356 1332
1357 SetAllocationStepDelay(0, kMinimumStepDelay); 1333 SetAllocationStepDelay(0, kMinimumStepDelay);
1358 SetAllocationStepDelay(1, kMinimumStepDelay); 1334 SetAllocationStepDelay(1, kMinimumStepDelay);
1359 1335
1360 int kOnlyLocalTcpPorts = PORTALLOCATOR_DISABLE_UDP | 1336 int kOnlyLocalTcpPorts = cricket::PORTALLOCATOR_DISABLE_UDP |
1361 PORTALLOCATOR_DISABLE_STUN | 1337 cricket::PORTALLOCATOR_DISABLE_STUN |
1362 PORTALLOCATOR_DISABLE_RELAY; 1338 cricket::PORTALLOCATOR_DISABLE_RELAY;
1363 // Disable all protocols except TCP. 1339 // Disable all protocols except TCP.
1364 SetAllocatorFlags(0, kOnlyLocalTcpPorts); 1340 SetAllocatorFlags(0, kOnlyLocalTcpPorts);
1365 SetAllocatorFlags(1, kOnlyLocalTcpPorts); 1341 SetAllocatorFlags(1, kOnlyLocalTcpPorts);
1366 1342
1367 SetAllowTcpListen(0, true); // actpass. 1343 SetAllowTcpListen(0, true); // actpass.
1368 SetAllowTcpListen(1, false); // active. 1344 SetAllowTcpListen(1, false); // active.
1369 1345
1370 // We want SetRemoteIceCredentials to be called as it normally would. 1346 // We want SetRemoteIceCredentials to be called as it normally would.
1371 // Otherwise we won't know what credentials to use for the expected 1347 // Otherwise we won't know what credentials to use for the expected
1372 // prflx TCP candidates. 1348 // prflx TCP candidates.
1373 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); 1349 set_remote_ice_credential_source(FROM_SETICECREDENTIALS);
1374 1350
1375 // Pause candidate so we could verify the candidate properties. 1351 // Pause candidate so we could verify the candidate properties.
1376 PauseCandidates(0); 1352 PauseCandidates(0);
1377 PauseCandidates(1); 1353 PauseCandidates(1);
1378 CreateChannels(1); 1354 CreateChannels(1);
1379 1355
1380 // Verify tcp candidates. 1356 // Verify tcp candidates.
1381 VerifySavedTcpCandidates(0, TCPTYPE_PASSIVE_STR); 1357 VerifySavedTcpCandidates(0, cricket::TCPTYPE_PASSIVE_STR);
1382 VerifySavedTcpCandidates(1, TCPTYPE_ACTIVE_STR); 1358 VerifySavedTcpCandidates(1, cricket::TCPTYPE_ACTIVE_STR);
1383 1359
1384 // Resume candidates. 1360 // Resume candidates.
1385 ResumeCandidates(0); 1361 ResumeCandidates(0);
1386 ResumeCandidates(1); 1362 ResumeCandidates(1);
1387 1363
1388 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1364 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1389 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1365 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1390 1000); 1366 1000);
1391 EXPECT_TRUE( 1367 EXPECT_TRUE(
1392 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && 1368 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() &&
1393 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 1369 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
1394 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 1370 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
1395 1371
1396 TestSendRecv(1); 1372 TestSendRecv(1);
1397 DestroyChannels(); 1373 DestroyChannels();
1398 } 1374 }
1399 1375
1400 TEST_F(P2PTransportChannelTest, TestIceRoleConflict) { 1376 TEST_F(P2PTransportChannelTest, TestIceRoleConflict) {
1401 AddAddress(0, kPublicAddrs[0]); 1377 AddAddress(0, kPublicAddrs[0]);
1402 AddAddress(1, kPublicAddrs[1]); 1378 AddAddress(1, kPublicAddrs[1]);
1403 TestSignalRoleConflict(); 1379 TestSignalRoleConflict();
1404 } 1380 }
1405 1381
1406 // Tests that the ice configs (protocol, tiebreaker and role) can be passed 1382 // Tests that the ice configs (protocol, tiebreaker and role) can be passed
1407 // down to ports. 1383 // down to ports.
1408 // Disable on Windows because it is flaky. 1384 // Disable on Windows because it is flaky.
1409 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6019 1385 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6019
1410 #if defined(WEBRTC_WIN) 1386 #if defined(WEBRTC_WIN)
1411 #define MAYBE_TestIceConfigWillPassDownToPort \ 1387 #define MAYBE_TestIceConfigWillPassDownToPort DISABLED_TestIceConfigWillPassDown ToPort
1412 DISABLED_TestIceConfigWillPassDownToPort
1413 #else 1388 #else
1414 #define MAYBE_TestIceConfigWillPassDownToPort TestIceConfigWillPassDownToPort 1389 #define MAYBE_TestIceConfigWillPassDownToPort TestIceConfigWillPassDownToPort
1415 #endif 1390 #endif
1416 TEST_F(P2PTransportChannelTest, MAYBE_TestIceConfigWillPassDownToPort) { 1391 TEST_F(P2PTransportChannelTest, MAYBE_TestIceConfigWillPassDownToPort) {
1417 AddAddress(0, kPublicAddrs[0]); 1392 AddAddress(0, kPublicAddrs[0]);
1418 AddAddress(1, kPublicAddrs[1]); 1393 AddAddress(1, kPublicAddrs[1]);
1419 1394
1420 SetIceRole(0, ICEROLE_CONTROLLING); 1395 SetIceRole(0, cricket::ICEROLE_CONTROLLING);
1421 SetIceTiebreaker(0, kTiebreaker1); 1396 SetIceTiebreaker(0, kTiebreaker1);
1422 SetIceRole(1, ICEROLE_CONTROLLING); 1397 SetIceRole(1, cricket::ICEROLE_CONTROLLING);
1423 SetIceTiebreaker(1, kTiebreaker2); 1398 SetIceTiebreaker(1, kTiebreaker2);
1424 1399
1425 CreateChannels(1); 1400 CreateChannels(1);
1426 1401
1427 EXPECT_EQ_WAIT(2u, ep1_ch1()->ports().size(), 1000); 1402 EXPECT_EQ_WAIT(2u, ep1_ch1()->ports().size(), 1000);
1428 1403
1429 const std::vector<PortInterface*> ports_before = ep1_ch1()->ports(); 1404 const std::vector<cricket::PortInterface *> ports_before = ep1_ch1()->ports();
1430 for (size_t i = 0; i < ports_before.size(); ++i) { 1405 for (size_t i = 0; i < ports_before.size(); ++i) {
1431 EXPECT_EQ(ICEROLE_CONTROLLING, ports_before[i]->GetIceRole()); 1406 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, ports_before[i]->GetIceRole());
1432 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); 1407 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker());
1433 } 1408 }
1434 1409
1435 ep1_ch1()->SetIceRole(ICEROLE_CONTROLLED); 1410 ep1_ch1()->SetIceRole(cricket::ICEROLE_CONTROLLED);
1436 ep1_ch1()->SetIceTiebreaker(kTiebreaker2); 1411 ep1_ch1()->SetIceTiebreaker(kTiebreaker2);
1437 1412
1438 const std::vector<PortInterface*> ports_after = ep1_ch1()->ports(); 1413 const std::vector<cricket::PortInterface *> ports_after = ep1_ch1()->ports();
1439 for (size_t i = 0; i < ports_after.size(); ++i) { 1414 for (size_t i = 0; i < ports_after.size(); ++i) {
1440 EXPECT_EQ(ICEROLE_CONTROLLED, ports_before[i]->GetIceRole()); 1415 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, ports_before[i]->GetIceRole());
1441 // SetIceTiebreaker after Connect() has been called will fail. So expect the 1416 // SetIceTiebreaker after Connect() has been called will fail. So expect the
1442 // original value. 1417 // original value.
1443 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker()); 1418 EXPECT_EQ(kTiebreaker1, ports_before[i]->IceTiebreaker());
1444 } 1419 }
1445 1420
1446 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && 1421 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() &&
1447 ep1_ch1()->writable() && 1422 ep1_ch1()->writable() &&
1448 ep2_ch1()->receiving() && 1423 ep2_ch1()->receiving() &&
1449 ep2_ch1()->writable(), 1424 ep2_ch1()->writable(),
1450 1000); 1425 1000);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 TEST_F(P2PTransportChannelTest, TestIPv6Connections) { 1463 TEST_F(P2PTransportChannelTest, TestIPv6Connections) {
1489 AddAddress(0, kIPv6PublicAddrs[0]); 1464 AddAddress(0, kIPv6PublicAddrs[0]);
1490 AddAddress(0, kPublicAddrs[0]); 1465 AddAddress(0, kPublicAddrs[0]);
1491 AddAddress(1, kIPv6PublicAddrs[1]); 1466 AddAddress(1, kIPv6PublicAddrs[1]);
1492 AddAddress(1, kPublicAddrs[1]); 1467 AddAddress(1, kPublicAddrs[1]);
1493 1468
1494 SetAllocationStepDelay(0, kMinimumStepDelay); 1469 SetAllocationStepDelay(0, kMinimumStepDelay);
1495 SetAllocationStepDelay(1, kMinimumStepDelay); 1470 SetAllocationStepDelay(1, kMinimumStepDelay);
1496 1471
1497 // Enable IPv6 1472 // Enable IPv6
1498 SetAllocatorFlags(0, PORTALLOCATOR_ENABLE_IPV6); 1473 SetAllocatorFlags(0, cricket::PORTALLOCATOR_ENABLE_IPV6);
1499 SetAllocatorFlags(1, PORTALLOCATOR_ENABLE_IPV6); 1474 SetAllocatorFlags(1, cricket::PORTALLOCATOR_ENABLE_IPV6);
1500 1475
1501 CreateChannels(1); 1476 CreateChannels(1);
1502 1477
1503 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1478 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1504 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1479 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1505 1000); 1480 1000);
1506 EXPECT_TRUE( 1481 EXPECT_TRUE(
1507 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && 1482 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() &&
1508 LocalCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[0]) && 1483 LocalCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[0]) &&
1509 RemoteCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[1])); 1484 RemoteCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[1]));
1510 1485
1511 TestSendRecv(1); 1486 TestSendRecv(1);
1512 DestroyChannels(); 1487 DestroyChannels();
1513 } 1488 }
1514 1489
1515 // Testing forceful TURN connections. 1490 // Testing forceful TURN connections.
1516 TEST_F(P2PTransportChannelTest, TestForceTurn) { 1491 TEST_F(P2PTransportChannelTest, TestForceTurn) {
1517 ConfigureEndpoints( 1492 ConfigureEndpoints(
1518 NAT_PORT_RESTRICTED, NAT_SYMMETRIC, 1493 NAT_PORT_RESTRICTED, NAT_SYMMETRIC,
1519 kDefaultPortAllocatorFlags | PORTALLOCATOR_ENABLE_SHARED_SOCKET, 1494 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET,
1520 kDefaultPortAllocatorFlags | PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1495 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1521 set_force_relay(true); 1496 set_force_relay(true);
1522 1497
1523 SetAllocationStepDelay(0, kMinimumStepDelay); 1498 SetAllocationStepDelay(0, kMinimumStepDelay);
1524 SetAllocationStepDelay(1, kMinimumStepDelay); 1499 SetAllocationStepDelay(1, kMinimumStepDelay);
1525 1500
1526 CreateChannels(1); 1501 CreateChannels(1);
1527 1502
1528 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1503 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1529 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1504 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1530 2000); 1505 2000);
(...skipping 11 matching lines...) Expand all
1542 } 1517 }
1543 1518
1544 // Test that if continual gathering is set to true, ICE gathering state will 1519 // Test that if continual gathering is set to true, ICE gathering state will
1545 // not change to "Complete", and vice versa. 1520 // not change to "Complete", and vice versa.
1546 TEST_F(P2PTransportChannelTest, TestContinualGathering) { 1521 TEST_F(P2PTransportChannelTest, TestContinualGathering) {
1547 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1522 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1548 kDefaultPortAllocatorFlags); 1523 kDefaultPortAllocatorFlags);
1549 SetAllocationStepDelay(0, kDefaultStepDelay); 1524 SetAllocationStepDelay(0, kDefaultStepDelay);
1550 SetAllocationStepDelay(1, kDefaultStepDelay); 1525 SetAllocationStepDelay(1, kDefaultStepDelay);
1551 CreateChannels(1); 1526 CreateChannels(1);
1552 IceConfig config = CreateIceConfig(1000, true); 1527 cricket::IceConfig config = CreateIceConfig(1000, true);
1553 ep1_ch1()->SetIceConfig(config); 1528 ep1_ch1()->SetIceConfig(config);
1554 // By default, ep2 does not gather continually. 1529 // By default, ep2 does not gather continually.
1555 1530
1556 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && 1531 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL &&
1557 ep1_ch1()->receiving() && ep1_ch1()->writable() && 1532 ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1558 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1533 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1559 1000, 1000); 1534 1000, 1000);
1560 WAIT(IceGatheringState::kIceGatheringComplete == ep1_ch1()->gathering_state(), 1535 WAIT(cricket::IceGatheringState::kIceGatheringComplete ==
1536 ep1_ch1()->gathering_state(),
1561 1000); 1537 1000);
1562 EXPECT_EQ(IceGatheringState::kIceGatheringGathering, 1538 EXPECT_EQ(cricket::IceGatheringState::kIceGatheringGathering,
1563 ep1_ch1()->gathering_state()); 1539 ep1_ch1()->gathering_state());
1564 // By now, ep2 should have completed gathering. 1540 // By now, ep2 should have completed gathering.
1565 EXPECT_EQ(IceGatheringState::kIceGatheringComplete, 1541 EXPECT_EQ(cricket::IceGatheringState::kIceGatheringComplete,
1566 ep2_ch1()->gathering_state()); 1542 ep2_ch1()->gathering_state());
1567 1543
1568 DestroyChannels(); 1544 DestroyChannels();
1569 } 1545 }
1570 1546
1571 // Test that a connection succeeds when the P2PTransportChannel uses a pooled 1547 // Test that a connection succeeds when the P2PTransportChannel uses a pooled
1572 // PortAllocatorSession that has not yet finished gathering candidates. 1548 // PortAllocatorSession that has not yet finished gathering candidates.
1573 TEST_F(P2PTransportChannelTest, TestUsingPooledSessionBeforeDoneGathering) { 1549 TEST_F(P2PTransportChannelTest, TestUsingPooledSessionBeforeDoneGathering) {
1574 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1550 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1575 kDefaultPortAllocatorFlags); 1551 kDefaultPortAllocatorFlags);
1576 // First create a pooled session for each endpoint. 1552 // First create a pooled session for each endpoint.
1577 auto& allocator_1 = GetEndpoint(0)->allocator_; 1553 auto& allocator_1 = GetEndpoint(0)->allocator_;
1578 auto& allocator_2 = GetEndpoint(1)->allocator_; 1554 auto& allocator_2 = GetEndpoint(1)->allocator_;
1579 int pool_size = 1; 1555 int pool_size = 1;
1580 allocator_1->SetConfiguration(allocator_1->stun_servers(), 1556 allocator_1->SetConfiguration(allocator_1->stun_servers(),
1581 allocator_1->turn_servers(), pool_size); 1557 allocator_1->turn_servers(), pool_size);
1582 allocator_2->SetConfiguration(allocator_2->stun_servers(), 1558 allocator_2->SetConfiguration(allocator_2->stun_servers(),
1583 allocator_2->turn_servers(), pool_size); 1559 allocator_2->turn_servers(), pool_size);
1584 const PortAllocatorSession* pooled_session_1 = 1560 const cricket::PortAllocatorSession* pooled_session_1 =
1585 allocator_1->GetPooledSession(); 1561 allocator_1->GetPooledSession();
1586 const PortAllocatorSession* pooled_session_2 = 1562 const cricket::PortAllocatorSession* pooled_session_2 =
1587 allocator_2->GetPooledSession(); 1563 allocator_2->GetPooledSession();
1588 ASSERT_NE(nullptr, pooled_session_1); 1564 ASSERT_NE(nullptr, pooled_session_1);
1589 ASSERT_NE(nullptr, pooled_session_2); 1565 ASSERT_NE(nullptr, pooled_session_2);
1590 // Sanity check that pooled sessions haven't gathered anything yet. 1566 // Sanity check that pooled sessions haven't gathered anything yet.
1591 EXPECT_TRUE(pooled_session_1->ReadyPorts().empty()); 1567 EXPECT_TRUE(pooled_session_1->ReadyPorts().empty());
1592 EXPECT_TRUE(pooled_session_1->ReadyCandidates().empty()); 1568 EXPECT_TRUE(pooled_session_1->ReadyCandidates().empty());
1593 EXPECT_TRUE(pooled_session_2->ReadyPorts().empty()); 1569 EXPECT_TRUE(pooled_session_2->ReadyPorts().empty());
1594 EXPECT_TRUE(pooled_session_2->ReadyCandidates().empty()); 1570 EXPECT_TRUE(pooled_session_2->ReadyCandidates().empty());
1595 // Now let the endpoints connect and try exchanging some data. 1571 // Now let the endpoints connect and try exchanging some data.
1596 CreateChannels(1); 1572 CreateChannels(1);
(...skipping 20 matching lines...) Expand all
1617 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1593 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1618 kDefaultPortAllocatorFlags); 1594 kDefaultPortAllocatorFlags);
1619 // First create a pooled session for each endpoint. 1595 // First create a pooled session for each endpoint.
1620 auto& allocator_1 = GetEndpoint(0)->allocator_; 1596 auto& allocator_1 = GetEndpoint(0)->allocator_;
1621 auto& allocator_2 = GetEndpoint(1)->allocator_; 1597 auto& allocator_2 = GetEndpoint(1)->allocator_;
1622 int pool_size = 1; 1598 int pool_size = 1;
1623 allocator_1->SetConfiguration(allocator_1->stun_servers(), 1599 allocator_1->SetConfiguration(allocator_1->stun_servers(),
1624 allocator_1->turn_servers(), pool_size); 1600 allocator_1->turn_servers(), pool_size);
1625 allocator_2->SetConfiguration(allocator_2->stun_servers(), 1601 allocator_2->SetConfiguration(allocator_2->stun_servers(),
1626 allocator_2->turn_servers(), pool_size); 1602 allocator_2->turn_servers(), pool_size);
1627 const PortAllocatorSession* pooled_session_1 = 1603 const cricket::PortAllocatorSession* pooled_session_1 =
1628 allocator_1->GetPooledSession(); 1604 allocator_1->GetPooledSession();
1629 const PortAllocatorSession* pooled_session_2 = 1605 const cricket::PortAllocatorSession* pooled_session_2 =
1630 allocator_2->GetPooledSession(); 1606 allocator_2->GetPooledSession();
1631 ASSERT_NE(nullptr, pooled_session_1); 1607 ASSERT_NE(nullptr, pooled_session_1);
1632 ASSERT_NE(nullptr, pooled_session_2); 1608 ASSERT_NE(nullptr, pooled_session_2);
1633 // Wait for the pooled sessions to finish gathering before the 1609 // Wait for the pooled sessions to finish gathering before the
1634 // P2PTransportChannels try to use them. 1610 // P2PTransportChannels try to use them.
1635 EXPECT_TRUE_WAIT(pooled_session_1->CandidatesAllocationDone() && 1611 EXPECT_TRUE_WAIT(pooled_session_1->CandidatesAllocationDone() &&
1636 pooled_session_2->CandidatesAllocationDone(), 1612 pooled_session_2->CandidatesAllocationDone(),
1637 kDefaultTimeout); 1613 kDefaultTimeout);
1638 // Now let the endpoints connect and try exchanging some data. 1614 // Now let the endpoints connect and try exchanging some data.
1639 CreateChannels(1); 1615 CreateChannels(1);
1640 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && 1616 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL &&
1641 ep1_ch1()->receiving() && ep1_ch1()->writable() && 1617 ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1642 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1618 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1643 1000, 1000); 1619 1000, 1000);
1644 TestSendRecv(1); 1620 TestSendRecv(1);
1645 // Make sure the P2PTransportChannels are actually using ports from the 1621 // Make sure the P2PTransportChannels are actually using ports from the
1646 // pooled sessions. 1622 // pooled sessions.
1647 auto pooled_ports_1 = pooled_session_1->ReadyPorts(); 1623 auto pooled_ports_1 = pooled_session_1->ReadyPorts();
1648 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); 1624 auto pooled_ports_2 = pooled_session_2->ReadyPorts();
1649 EXPECT_NE(pooled_ports_1.end(), 1625 EXPECT_NE(pooled_ports_1.end(),
1650 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), 1626 std::find(pooled_ports_1.begin(), pooled_ports_1.end(),
1651 ep1_ch1()->best_connection()->port())); 1627 ep1_ch1()->best_connection()->port()));
1652 EXPECT_NE(pooled_ports_2.end(), 1628 EXPECT_NE(pooled_ports_2.end(),
1653 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), 1629 std::find(pooled_ports_2.begin(), pooled_ports_2.end(),
1654 ep2_ch1()->best_connection()->port())); 1630 ep2_ch1()->best_connection()->port()));
1655 } 1631 }
1656 1632
1657 // Test that when the "presume_writable_when_fully_relayed" flag is set to
1658 // false and there's a TURN-TURN candidate pair, it's presume to be writable
1659 // as soon as it's created.
1660 TEST_F(P2PTransportChannelTest, TurnToTurnPresumedWritable) {
1661 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1662 kDefaultPortAllocatorFlags);
1663 // Only configure one channel so we can control when the remote candidate
1664 // is added.
1665 GetEndpoint(0)->cd1_.ch_.reset(
1666 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0],
1667 kIcePwd[0], kIceUfrag[1], kIcePwd[1]));
1668 IceConfig config;
1669 config.presume_writable_when_fully_relayed = true;
1670 ep1_ch1()->SetIceConfig(config);
1671 ep1_ch1()->MaybeStartGathering();
1672 EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete,
1673 ep1_ch1()->gathering_state(), kDefaultTimeout);
1674 // Add two remote candidates; a host candidate (with higher priority)
1675 // and TURN candidate.
1676 ep1_ch1()->AddRemoteCandidate(
1677 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
1678 ep1_ch1()->AddRemoteCandidate(
1679 CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 0));
1680 // Expect that the TURN-TURN candidate pair will be prioritized since it's
1681 // "probably writable".
1682 EXPECT_TRUE(ep1_ch1()->best_connection() != nullptr);
1683 EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type());
1684 EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type());
1685 // Also expect that the channel instantly indicates that it's writable since
1686 // it has a TURN-TURN pair.
1687 EXPECT_TRUE(ep1_ch1()->writable());
1688 EXPECT_TRUE(GetEndpoint(0)->ready_to_send_);
1689 }
1690
1691 // Test that a presumed-writable TURN<->TURN connection is preferred above an
1692 // unreliable connection (one that has failed to be pinged for some time).
1693 TEST_F(P2PTransportChannelTest, PresumedWritablePreferredOverUnreliable) {
1694 rtc::ScopedFakeClock fake_clock;
1695
1696 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags,
1697 kDefaultPortAllocatorFlags);
1698 IceConfig config;
1699 config.presume_writable_when_fully_relayed = true;
1700 GetEndpoint(0)->cd1_.ch_.reset(
1701 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0],
1702 kIcePwd[0], kIceUfrag[1], kIcePwd[1]));
1703 GetEndpoint(1)->cd1_.ch_.reset(
1704 CreateChannel(1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[1],
1705 kIcePwd[1], kIceUfrag[0], kIcePwd[0]));
1706 ep1_ch1()->SetIceConfig(config);
1707 ep2_ch1()->SetIceConfig(config);
1708 ep1_ch1()->MaybeStartGathering();
1709 ep2_ch1()->MaybeStartGathering();
1710 // Wait for initial connection as usual.
1711 EXPECT_TRUE_SIMULATED_WAIT(
1712 ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1713 ep1_ch1()->best_connection()->writable() && ep2_ch1()->receiving() &&
1714 ep2_ch1()->writable() && ep2_ch1()->best_connection()->writable(),
1715 1000, fake_clock);
1716 const Connection* old_best_connection = ep1_ch1()->best_connection();
1717 // Destroy the second channel and wait for the current connection on the
1718 // first channel to become "unreliable", making it no longer writable.
1719 GetEndpoint(1)->cd1_.ch_.reset();
1720 EXPECT_TRUE_SIMULATED_WAIT(!ep1_ch1()->writable(), 10000, fake_clock);
1721 EXPECT_NE(nullptr, ep1_ch1()->best_connection());
1722 // Add a remote TURN candidate. The first channel should still have a TURN
1723 // port available to make a TURN<->TURN pair that's presumed writable.
1724 ep1_ch1()->AddRemoteCandidate(
1725 CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 0));
1726 EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type());
1727 EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type());
1728 EXPECT_TRUE(ep1_ch1()->writable());
1729 EXPECT_TRUE(GetEndpoint(0)->ready_to_send_);
1730 EXPECT_NE(old_best_connection, ep1_ch1()->best_connection());
1731 // Explitly destroy channels, before fake clock is destroyed.
1732 DestroyChannels();
1733 }
1734
1735 // Test what happens when we have 2 users behind the same NAT. This can lead 1633 // Test what happens when we have 2 users behind the same NAT. This can lead
1736 // to interesting behavior because the STUN server will only give out the 1634 // to interesting behavior because the STUN server will only give out the
1737 // address of the outermost NAT. 1635 // address of the outermost NAT.
1738 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase { 1636 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase {
1739 protected: 1637 protected:
1740 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) { 1638 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) {
1741 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC); 1639 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC);
1742 rtc::NATSocketServer::Translator* outer_nat = 1640 rtc::NATSocketServer::Translator* outer_nat =
1743 nat()->AddTranslator(kPublicAddrs[0], kNatAddrs[0], 1641 nat()->AddTranslator(kPublicAddrs[0], kNatAddrs[0],
1744 static_cast<rtc::NATType>(nat_type - NAT_FULL_CONE)); 1642 static_cast<rtc::NATType>(nat_type - NAT_FULL_CONE));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1800 1698
1801 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1699 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1802 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1700 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1803 1000, 1000); 1701 1000, 1000);
1804 EXPECT_TRUE( 1702 EXPECT_TRUE(
1805 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && 1703 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() &&
1806 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 1704 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
1807 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 1705 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
1808 1706
1809 // Make the receiving timeout shorter for testing. 1707 // Make the receiving timeout shorter for testing.
1810 IceConfig config = CreateIceConfig(1000, false); 1708 cricket::IceConfig config = CreateIceConfig(1000, false);
1811 ep1_ch1()->SetIceConfig(config); 1709 ep1_ch1()->SetIceConfig(config);
1812 ep2_ch1()->SetIceConfig(config); 1710 ep2_ch1()->SetIceConfig(config);
1813 1711
1814 // Blackhole any traffic to or from the public addrs. 1712 // Blackhole any traffic to or from the public addrs.
1815 LOG(LS_INFO) << "Failing over..."; 1713 LOG(LS_INFO) << "Failing over...";
1816 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]); 1714 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[1]);
1817 // The best connections will switch, so keep references to them. 1715 // The best connections will switch, so keep references to them.
1818 const Connection* best_connection1 = ep1_ch1()->best_connection(); 1716 const cricket::Connection* best_connection1 = ep1_ch1()->best_connection();
1819 const Connection* best_connection2 = ep2_ch1()->best_connection(); 1717 const cricket::Connection* best_connection2 = ep2_ch1()->best_connection();
1820 // We should detect loss of receiving within 1 second or so. 1718 // We should detect loss of receiving within 1 second or so.
1821 EXPECT_TRUE_WAIT( 1719 EXPECT_TRUE_WAIT(
1822 !best_connection1->receiving() && !best_connection2->receiving(), 3000); 1720 !best_connection1->receiving() && !best_connection2->receiving(), 3000);
1823 1721
1824 // We should switch over to use the alternate addr immediately on both sides 1722 // We should switch over to use the alternate addr immediately on both sides
1825 // when we are not receiving. 1723 // when we are not receiving.
1826 EXPECT_TRUE_WAIT( 1724 EXPECT_TRUE_WAIT(
1827 ep1_ch1()->best_connection()->receiving() && 1725 ep1_ch1()->best_connection()->receiving() &&
1828 ep2_ch1()->best_connection()->receiving(), 1000); 1726 ep2_ch1()->best_connection()->receiving(), 1000);
1829 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0])); 1727 EXPECT_TRUE(LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]));
(...skipping 22 matching lines...) Expand all
1852 CreateChannels(1); 1750 CreateChannels(1);
1853 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1751 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1854 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1752 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1855 1000, 1000); 1753 1000, 1000);
1856 EXPECT_TRUE( 1754 EXPECT_TRUE(
1857 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && 1755 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() &&
1858 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && 1756 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) &&
1859 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); 1757 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1]));
1860 1758
1861 // Make the receiving timeout shorter for testing. 1759 // Make the receiving timeout shorter for testing.
1862 IceConfig config = CreateIceConfig(1000, false); 1760 cricket::IceConfig config = CreateIceConfig(1000, false);
1863 ep1_ch1()->SetIceConfig(config); 1761 ep1_ch1()->SetIceConfig(config);
1864 ep2_ch1()->SetIceConfig(config); 1762 ep2_ch1()->SetIceConfig(config);
1865 1763
1866 // Blackhole any traffic to or from the public addrs. 1764 // Blackhole any traffic to or from the public addrs.
1867 LOG(LS_INFO) << "Failing over..."; 1765 LOG(LS_INFO) << "Failing over...";
1868 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]); 1766 fw()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, kPublicAddrs[0]);
1869 // The best connections will switch, so keep references to them. 1767 // The best connections will switch, so keep references to them.
1870 const Connection* best_connection1 = ep1_ch1()->best_connection(); 1768 const cricket::Connection* best_connection1 = ep1_ch1()->best_connection();
1871 const Connection* best_connection2 = ep2_ch1()->best_connection(); 1769 const cricket::Connection* best_connection2 = ep2_ch1()->best_connection();
1872 // We should detect loss of receiving within 1 second or so. 1770 // We should detect loss of receiving within 1 second or so.
1873 EXPECT_TRUE_WAIT( 1771 EXPECT_TRUE_WAIT(
1874 !best_connection1->receiving() && !best_connection2->receiving(), 3000); 1772 !best_connection1->receiving() && !best_connection2->receiving(), 3000);
1875 1773
1876 // We should switch over to use the alternate addr immediately on both sides 1774 // We should switch over to use the alternate addr immediately on both sides
1877 // when we are not receiving. 1775 // when we are not receiving.
1878 EXPECT_TRUE_WAIT( 1776 EXPECT_TRUE_WAIT(
1879 ep1_ch1()->best_connection()->receiving() && 1777 ep1_ch1()->best_connection()->receiving() &&
1880 ep2_ch1()->best_connection()->receiving(), 1000); 1778 ep2_ch1()->best_connection()->receiving(), 1000);
1881 EXPECT_TRUE( 1779 EXPECT_TRUE(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1964 1862
1965 // Create channels and let them go writable, as usual. 1863 // Create channels and let them go writable, as usual.
1966 CreateChannels(1); 1864 CreateChannels(1);
1967 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1865 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1968 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1866 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1969 1000, 1000); 1867 1000, 1000);
1970 int backup_ping_interval = 2000; 1868 int backup_ping_interval = 2000;
1971 ep2_ch1()->SetIceConfig(CreateIceConfig(2000, false, backup_ping_interval)); 1869 ep2_ch1()->SetIceConfig(CreateIceConfig(2000, false, backup_ping_interval));
1972 // After the state becomes COMPLETED, the backup connection will be pinged 1870 // After the state becomes COMPLETED, the backup connection will be pinged
1973 // once every |backup_ping_interval| milliseconds. 1871 // once every |backup_ping_interval| milliseconds.
1974 ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == STATE_COMPLETED, 1000); 1872 ASSERT_TRUE_WAIT(ep2_ch1()->GetState() == cricket::STATE_COMPLETED, 1000);
1975 const std::vector<Connection*>& connections = ep2_ch1()->connections(); 1873 const std::vector<cricket::Connection*>& connections =
1874 ep2_ch1()->connections();
1976 ASSERT_EQ(2U, connections.size()); 1875 ASSERT_EQ(2U, connections.size());
1977 Connection* backup_conn = connections[1]; 1876 cricket::Connection* backup_conn = connections[1];
1978 EXPECT_TRUE_WAIT(backup_conn->writable(), 3000); 1877 EXPECT_TRUE_WAIT(backup_conn->writable(), 3000);
1979 int64_t last_ping_response_ms = backup_conn->last_ping_response_received(); 1878 int64_t last_ping_response_ms = backup_conn->last_ping_response_received();
1980 EXPECT_TRUE_WAIT( 1879 EXPECT_TRUE_WAIT(
1981 last_ping_response_ms < backup_conn->last_ping_response_received(), 5000); 1880 last_ping_response_ms < backup_conn->last_ping_response_received(), 5000);
1982 int time_elapsed = 1881 int time_elapsed =
1983 backup_conn->last_ping_response_received() - last_ping_response_ms; 1882 backup_conn->last_ping_response_received() - last_ping_response_ms;
1984 LOG(LS_INFO) << "Time elapsed: " << time_elapsed; 1883 LOG(LS_INFO) << "Time elapsed: " << time_elapsed;
1985 EXPECT_GE(time_elapsed, backup_ping_interval); 1884 EXPECT_GE(time_elapsed, backup_ping_interval);
1986 } 1885 }
1987 1886
1988 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) { 1887 TEST_F(P2PTransportChannelMultihomedTest, TestGetState) {
1989 AddAddress(0, kAlternateAddrs[0]); 1888 AddAddress(0, kAlternateAddrs[0]);
1990 AddAddress(0, kPublicAddrs[0]); 1889 AddAddress(0, kPublicAddrs[0]);
1991 AddAddress(1, kPublicAddrs[1]); 1890 AddAddress(1, kPublicAddrs[1]);
1992 // Create channels and let them go writable, as usual. 1891 // Create channels and let them go writable, as usual.
1993 CreateChannels(1); 1892 CreateChannels(1);
1994 1893
1995 // Both transport channels will reach STATE_COMPLETED quickly. 1894 // Both transport channels will reach STATE_COMPLETED quickly.
1996 EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep1_ch1()->GetState(), 1895 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED,
1997 1000); 1896 ep1_ch1()->GetState(), 1000);
1998 EXPECT_EQ_WAIT(TransportChannelState::STATE_COMPLETED, ep2_ch1()->GetState(), 1897 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED,
1999 1000); 1898 ep2_ch1()->GetState(), 1000);
2000 } 1899 }
2001 1900
2002 // Tests that when a network interface becomes inactive, if and only if 1901 // Tests that when a network interface becomes inactive, if and only if
2003 // Continual Gathering is enabled, the ports associated with that network 1902 // Continual Gathering is enabled, the ports associated with that network
2004 // will be removed from the port list of the channel, and the respective 1903 // will be removed from the port list of the channel, and the respective
2005 // remote candidates on the other participant will be removed eventually. 1904 // remote candidates on the other participant will be removed eventually.
2006 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { 1905 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) {
2007 AddAddress(0, kPublicAddrs[0]); 1906 AddAddress(0, kPublicAddrs[0]);
2008 AddAddress(1, kPublicAddrs[1]); 1907 AddAddress(1, kPublicAddrs[1]);
2009 // Create channels and let them go writable, as usual. 1908 // Create channels and let them go writable, as usual.
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2088 // pings. 1987 // pings.
2089 class P2PTransportChannelPingTest : public testing::Test, 1988 class P2PTransportChannelPingTest : public testing::Test,
2090 public sigslot::has_slots<> { 1989 public sigslot::has_slots<> {
2091 public: 1990 public:
2092 P2PTransportChannelPingTest() 1991 P2PTransportChannelPingTest()
2093 : pss_(new rtc::PhysicalSocketServer), 1992 : pss_(new rtc::PhysicalSocketServer),
2094 vss_(new rtc::VirtualSocketServer(pss_.get())), 1993 vss_(new rtc::VirtualSocketServer(pss_.get())),
2095 ss_scope_(vss_.get()) {} 1994 ss_scope_(vss_.get()) {}
2096 1995
2097 protected: 1996 protected:
2098 void PrepareChannel(P2PTransportChannel* ch) { 1997 void PrepareChannel(cricket::P2PTransportChannel* ch) {
2099 ch->SetIceRole(ICEROLE_CONTROLLING); 1998 ch->SetIceRole(cricket::ICEROLE_CONTROLLING);
2100 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); 1999 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]);
2101 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 2000 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]);
2102 ch->SignalSelectedCandidatePairChanged.connect( 2001 ch->SignalSelectedCandidatePairChanged.connect(
2103 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged); 2002 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged);
2104 ch->SignalReadyToSend.connect(this, 2003 ch->SignalReadyToSend.connect(this,
2105 &P2PTransportChannelPingTest::OnReadyToSend); 2004 &P2PTransportChannelPingTest::OnReadyToSend);
2106 ch->SignalStateChanged.connect( 2005 ch->SignalStateChanged.connect(
2107 this, &P2PTransportChannelPingTest::OnChannelStateChanged); 2006 this, &P2PTransportChannelPingTest::OnChannelStateChanged);
2108 } 2007 }
2109 2008
2110 Connection* WaitForConnectionTo(P2PTransportChannel* ch, 2009 cricket::Candidate CreateHostCandidate(const std::string& ip,
2111 const std::string& ip, 2010 int port,
2112 int port_num) { 2011 int priority,
2012 const std::string& ufrag = "") {
2013 cricket::Candidate c;
2014 c.set_address(rtc::SocketAddress(ip, port));
2015 c.set_component(1);
2016 c.set_protocol(cricket::UDP_PROTOCOL_NAME);
2017 c.set_priority(priority);
2018 c.set_username(ufrag);
2019 c.set_type(cricket::LOCAL_PORT_TYPE);
2020 return c;
2021 }
2022
2023 cricket::Connection* WaitForConnectionTo(cricket::P2PTransportChannel* ch,
2024 const std::string& ip,
2025 int port_num) {
2113 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000); 2026 EXPECT_TRUE_WAIT(GetConnectionTo(ch, ip, port_num) != nullptr, 3000);
2114 return GetConnectionTo(ch, ip, port_num); 2027 return GetConnectionTo(ch, ip, port_num);
2115 } 2028 }
2116 2029
2117 Port* GetPort(P2PTransportChannel* ch) { 2030 cricket::Port* GetPort(cricket::P2PTransportChannel* ch) {
2118 if (ch->ports().empty()) { 2031 if (ch->ports().empty()) {
2119 return nullptr; 2032 return nullptr;
2120 } 2033 }
2121 return static_cast<Port*>(ch->ports()[0]); 2034 return static_cast<cricket::Port*>(ch->ports()[0]);
2122 } 2035 }
2123 2036
2124 Connection* GetConnectionTo(P2PTransportChannel* ch, 2037 cricket::Connection* GetConnectionTo(cricket::P2PTransportChannel* ch,
2125 const std::string& ip, 2038 const std::string& ip,
2126 int port_num) { 2039 int port_num) {
2127 Port* port = GetPort(ch); 2040 cricket::Port* port = GetPort(ch);
2128 if (!port) { 2041 if (!port) {
2129 return nullptr; 2042 return nullptr;
2130 } 2043 }
2131 return port->GetConnection(rtc::SocketAddress(ip, port_num)); 2044 return port->GetConnection(rtc::SocketAddress(ip, port_num));
2132 } 2045 }
2133 2046
2134 Connection* FindNextPingableConnectionAndPingIt(P2PTransportChannel* ch) { 2047 cricket::Connection* FindNextPingableConnectionAndPingIt(
2135 Connection* conn = ch->FindNextPingableConnection(); 2048 cricket::P2PTransportChannel* ch) {
2049 cricket::Connection* conn = ch->FindNextPingableConnection();
2136 if (conn) { 2050 if (conn) {
2137 ch->MarkConnectionPinged(conn); 2051 ch->MarkConnectionPinged(conn);
2138 } 2052 }
2139 return conn; 2053 return conn;
2140 } 2054 }
2141 2055
2142 int SendData(TransportChannel& channel, 2056 int SendData(cricket::TransportChannel& channel,
2143 const char* data, 2057 const char* data,
2144 size_t len, 2058 size_t len,
2145 int packet_id) { 2059 int packet_id) {
2146 rtc::PacketOptions options; 2060 rtc::PacketOptions options;
2147 options.packet_id = packet_id; 2061 options.packet_id = packet_id;
2148 return channel.SendPacket(data, len, options, 0); 2062 return channel.SendPacket(data, len, options, 0);
2149 } 2063 }
2150 2064
2151 void OnSelectedCandidatePairChanged( 2065 void OnSelectedCandidatePairChanged(
2152 TransportChannel* transport_channel, 2066 cricket::TransportChannel* transport_channel,
2153 CandidatePairInterface* selected_candidate_pair, 2067 cricket::CandidatePairInterface* selected_candidate_pair,
2154 int last_sent_packet_id) { 2068 int last_sent_packet_id) {
2155 last_selected_candidate_pair_ = selected_candidate_pair; 2069 last_selected_candidate_pair_ = selected_candidate_pair;
2156 last_sent_packet_id_ = last_sent_packet_id; 2070 last_sent_packet_id_ = last_sent_packet_id;
2157 } 2071 }
2158 2072
2159 void ReceivePingOnConnection(Connection* conn, 2073 void ReceivePingOnConnection(cricket::Connection* conn,
2160 const std::string& remote_ufrag, 2074 const std::string& remote_ufrag,
2161 int priority) { 2075 int priority) {
2162 IceMessage msg; 2076 cricket::IceMessage msg;
2163 msg.SetType(STUN_BINDING_REQUEST); 2077 msg.SetType(cricket::STUN_BINDING_REQUEST);
2164 msg.AddAttribute(new StunByteStringAttribute( 2078 msg.AddAttribute(new cricket::StunByteStringAttribute(
2165 STUN_ATTR_USERNAME, 2079 cricket::STUN_ATTR_USERNAME,
2166 conn->local_candidate().username() + ":" + remote_ufrag)); 2080 conn->local_candidate().username() + ":" + remote_ufrag));
2167 msg.AddAttribute(new StunUInt32Attribute(STUN_ATTR_PRIORITY, priority)); 2081 msg.AddAttribute(new cricket::StunUInt32Attribute(
2168 msg.SetTransactionID(rtc::CreateRandomString(kStunTransactionIdLength)); 2082 cricket::STUN_ATTR_PRIORITY, priority));
2083 msg.SetTransactionID(
2084 rtc::CreateRandomString(cricket::kStunTransactionIdLength));
2169 msg.AddMessageIntegrity(conn->local_candidate().password()); 2085 msg.AddMessageIntegrity(conn->local_candidate().password());
2170 msg.AddFingerprint(); 2086 msg.AddFingerprint();
2171 rtc::ByteBufferWriter buf; 2087 rtc::ByteBufferWriter buf;
2172 msg.Write(&buf); 2088 msg.Write(&buf);
2173 conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0)); 2089 conn->OnReadPacket(buf.Data(), buf.Length(), rtc::CreatePacketTime(0));
2174 } 2090 }
2175 2091
2176 void OnReadyToSend(TransportChannel* channel) { 2092 void OnReadyToSend(cricket::TransportChannel* channel) {
2177 channel_ready_to_send_ = true; 2093 channel_ready_to_send_ = true;
2178 } 2094 }
2179 void OnChannelStateChanged(TransportChannelImpl* channel) { 2095 void OnChannelStateChanged(cricket::TransportChannelImpl* channel) {
2180 channel_state_ = channel->GetState(); 2096 channel_state_ = channel->GetState();
2181 } 2097 }
2182 2098
2183 CandidatePairInterface* last_selected_candidate_pair() { 2099 cricket::CandidatePairInterface* last_selected_candidate_pair() {
2184 return last_selected_candidate_pair_; 2100 return last_selected_candidate_pair_;
2185 } 2101 }
2186 int last_sent_packet_id() { return last_sent_packet_id_; } 2102 int last_sent_packet_id() { return last_sent_packet_id_; }
2187 bool channel_ready_to_send() { return channel_ready_to_send_; } 2103 bool channel_ready_to_send() { return channel_ready_to_send_; }
2188 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; } 2104 void reset_channel_ready_to_send() { channel_ready_to_send_ = false; }
2189 TransportChannelState channel_state() { return channel_state_; } 2105 cricket::TransportChannelState channel_state() { return channel_state_; }
2190 2106
2191 private: 2107 private:
2192 std::unique_ptr<rtc::PhysicalSocketServer> pss_; 2108 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
2193 std::unique_ptr<rtc::VirtualSocketServer> vss_; 2109 std::unique_ptr<rtc::VirtualSocketServer> vss_;
2194 rtc::SocketServerScope ss_scope_; 2110 rtc::SocketServerScope ss_scope_;
2195 CandidatePairInterface* last_selected_candidate_pair_ = nullptr; 2111 cricket::CandidatePairInterface* last_selected_candidate_pair_ = nullptr;
2196 int last_sent_packet_id_ = -1; 2112 int last_sent_packet_id_ = -1;
2197 bool channel_ready_to_send_ = false; 2113 bool channel_ready_to_send_ = false;
2198 TransportChannelState channel_state_ = STATE_INIT; 2114 cricket::TransportChannelState channel_state_ = cricket::STATE_INIT;
2199 }; 2115 };
2200 2116
2201 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { 2117 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) {
2202 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2118 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2203 P2PTransportChannel ch("trigger checks", 1, &pa); 2119 cricket::P2PTransportChannel ch("trigger checks", 1, &pa);
2204 PrepareChannel(&ch); 2120 PrepareChannel(&ch);
2205 ch.Connect(); 2121 ch.Connect();
2206 ch.MaybeStartGathering(); 2122 ch.MaybeStartGathering();
2207 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2123 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2208 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 2124 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
2209 2125
2210 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2126 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2211 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2127 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2212 ASSERT_TRUE(conn1 != nullptr); 2128 ASSERT_TRUE(conn1 != nullptr);
2213 ASSERT_TRUE(conn2 != nullptr); 2129 ASSERT_TRUE(conn2 != nullptr);
2214 2130
2215 // Before a triggered check, the first connection to ping is the 2131 // Before a triggered check, the first connection to ping is the
2216 // highest priority one. 2132 // highest priority one.
2217 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 2133 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
2218 2134
2219 // Receiving a ping causes a triggered check which should make conn1 2135 // Receiving a ping causes a triggered check which should make conn1
2220 // be pinged first instead of conn2, even though conn2 has a higher 2136 // be pinged first instead of conn2, even though conn2 has a higher
2221 // priority. 2137 // priority.
2222 conn1->ReceivedPing(); 2138 conn1->ReceivedPing();
2223 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); 2139 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch));
2224 } 2140 }
2225 2141
2226 TEST_F(P2PTransportChannelPingTest, TestAllConnectionsPingedSufficiently) { 2142 TEST_F(P2PTransportChannelPingTest, TestAllConnectionsPingedSufficiently) {
2227 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2143 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2228 P2PTransportChannel ch("ping sufficiently", 1, &pa); 2144 cricket::P2PTransportChannel ch("ping sufficiently", 1, &pa);
2229 PrepareChannel(&ch); 2145 PrepareChannel(&ch);
2230 ch.Connect(); 2146 ch.Connect();
2231 ch.MaybeStartGathering(); 2147 ch.MaybeStartGathering();
2232 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2148 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2233 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 2149 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
2234 2150
2235 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2151 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2236 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2152 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2237 ASSERT_TRUE(conn1 != nullptr); 2153 ASSERT_TRUE(conn1 != nullptr);
2238 ASSERT_TRUE(conn2 != nullptr); 2154 ASSERT_TRUE(conn2 != nullptr);
2239 2155
2240 // Low-priority connection becomes writable so that the other connection 2156 // Low-priority connection becomes writable so that the other connection
2241 // is not pruned. 2157 // is not pruned.
2242 conn1->ReceivedPingResponse(LOW_RTT); 2158 conn1->ReceivedPingResponse(LOW_RTT);
2243 EXPECT_TRUE_WAIT( 2159 EXPECT_TRUE_WAIT(
2244 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL && 2160 conn1->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL &&
2245 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, 2161 conn2->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL,
2246 kDefaultTimeout); 2162 kDefaultTimeout);
2247 } 2163 }
2248 2164
2249 // Verify that the connections are pinged at the right time. 2165 // Verify that the connections are pinged at the right time.
2250 TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) { 2166 TEST_F(P2PTransportChannelPingTest, TestStunPingIntervals) {
2251 rtc::ScopedFakeClock clock; 2167 rtc::ScopedFakeClock clock;
2252 int RTT_RATIO = 4; 2168 int RTT_RATIO = 4;
2253 int SCHEDULING_RANGE = 200; 2169 int SCHEDULING_RANGE = 200;
2254 int RTT_RANGE = 10; 2170 int RTT_RANGE = 10;
2255 2171
2256 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2172 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2257 P2PTransportChannel ch("TestChannel", 1, &pa); 2173 cricket::P2PTransportChannel ch("TestChannel", 1, &pa);
2258 PrepareChannel(&ch); 2174 PrepareChannel(&ch);
2259 ch.Connect(); 2175 ch.Connect();
2260 ch.MaybeStartGathering(); 2176 ch.MaybeStartGathering();
2261 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2177 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2262 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2178 cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2263 2179
2264 ASSERT_TRUE(conn != nullptr); 2180 ASSERT_TRUE(conn != nullptr);
2265 SIMULATED_WAIT(conn->num_pings_sent() == 1, kDefaultTimeout, clock); 2181 SIMULATED_WAIT(conn->num_pings_sent() == 1, kDefaultTimeout, clock);
2266 2182
2267 // Initializing. 2183 // Initializing.
2268 2184
2269 int64_t start = clock.TimeNanos(); 2185 int64_t start = clock.TimeNanos();
2270 SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL, 2186 SIMULATED_WAIT(conn->num_pings_sent() >= MIN_PINGS_AT_WEAK_PING_INTERVAL,
2271 kDefaultTimeout, clock); 2187 kDefaultTimeout, clock);
2272 int64_t ping_interval_ms = (clock.TimeNanos() - start) / 2188 int64_t ping_interval_ms = (clock.TimeNanos() - start) /
2273 rtc::kNumNanosecsPerMillisec / 2189 rtc::kNumNanosecsPerMillisec /
2274 (MIN_PINGS_AT_WEAK_PING_INTERVAL - 1); 2190 (MIN_PINGS_AT_WEAK_PING_INTERVAL - 1);
2275 EXPECT_EQ(ping_interval_ms, WEAK_PING_INTERVAL); 2191 EXPECT_EQ(ping_interval_ms, cricket::WEAK_PING_INTERVAL);
2276 2192
2277 // Stabilizing. 2193 // Stabilizing.
2278 2194
2279 conn->ReceivedPingResponse(LOW_RTT); 2195 conn->ReceivedPingResponse(LOW_RTT);
2280 int ping_sent_before = conn->num_pings_sent(); 2196 int ping_sent_before = conn->num_pings_sent();
2281 start = clock.TimeNanos(); 2197 start = clock.TimeNanos();
2282 // The connection becomes strong but not stable because we haven't been able 2198 // The connection becomes strong but not stable because we haven't been able
2283 // to converge the RTT. 2199 // to converge the RTT.
2284 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); 2200 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
2285 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 2201 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
2286 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); 2202 EXPECT_GE(ping_interval_ms,
2203 cricket::STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
2287 EXPECT_LE(ping_interval_ms, 2204 EXPECT_LE(ping_interval_ms,
2288 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); 2205 cricket::STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL +
2206 SCHEDULING_RANGE);
2289 2207
2290 // Stabilized. 2208 // Stabilized.
2291 2209
2292 // The connection becomes stable after receiving more than RTT_RATIO rtt 2210 // The connection becomes stable after receiving more than RTT_RATIO rtt
2293 // samples. 2211 // samples.
2294 for (int i = 0; i < RTT_RATIO; i++) { 2212 for (int i = 0; i < RTT_RATIO; i++) {
2295 conn->ReceivedPingResponse(LOW_RTT); 2213 conn->ReceivedPingResponse(LOW_RTT);
2296 } 2214 }
2297 ping_sent_before = conn->num_pings_sent(); 2215 ping_sent_before = conn->num_pings_sent();
2298 start = clock.TimeNanos(); 2216 start = clock.TimeNanos();
2299 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); 2217 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
2300 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 2218 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
2301 EXPECT_GE(ping_interval_ms, STABLE_WRITABLE_CONNECTION_PING_INTERVAL); 2219 EXPECT_GE(ping_interval_ms,
2302 EXPECT_LE(ping_interval_ms, 2220 cricket::STABLE_WRITABLE_CONNECTION_PING_INTERVAL);
2303 STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); 2221 EXPECT_LE(
2222 ping_interval_ms,
2223 cricket::STABLE_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
2304 2224
2305 // Destabilized. 2225 // Destabilized.
2306 2226
2307 conn->ReceivedPingResponse(LOW_RTT); 2227 conn->ReceivedPingResponse(LOW_RTT);
2308 // Create a in-flight ping. 2228 // Create a in-flight ping.
2309 conn->Ping(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec); 2229 conn->Ping(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec);
2310 start = clock.TimeNanos(); 2230 start = clock.TimeNanos();
2311 // In-flight ping timeout and the connection will be unstable. 2231 // In-flight ping timeout and the connection will be unstable.
2312 SIMULATED_WAIT( 2232 SIMULATED_WAIT(
2313 !conn->stable(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec), 3000, 2233 !conn->stable(clock.TimeNanos() / rtc::kNumNanosecsPerMillisec), 3000,
2314 clock); 2234 clock);
2315 int64_t duration_ms = 2235 int64_t duration_ms =
2316 (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 2236 (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
2317 EXPECT_GE(duration_ms, 2 * conn->rtt() - RTT_RANGE); 2237 EXPECT_GE(duration_ms, 2 * conn->rtt() - RTT_RANGE);
2318 EXPECT_LE(duration_ms, 2 * conn->rtt() + RTT_RANGE); 2238 EXPECT_LE(duration_ms, 2 * conn->rtt() + RTT_RANGE);
2319 // The connection become unstable due to not receiving ping responses. 2239 // The connection become unstable due to not receiving ping responses.
2320 ping_sent_before = conn->num_pings_sent(); 2240 ping_sent_before = conn->num_pings_sent();
2321 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); 2241 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
2322 // The interval is expected to be 2242 // The interval is expected to be
2323 // STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL. 2243 // STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL.
2324 start = clock.TimeNanos(); 2244 start = clock.TimeNanos();
2325 ping_sent_before = conn->num_pings_sent(); 2245 ping_sent_before = conn->num_pings_sent();
2326 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); 2246 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
2327 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 2247 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
2328 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); 2248 EXPECT_GE(ping_interval_ms,
2249 cricket::STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
2329 EXPECT_LE(ping_interval_ms, 2250 EXPECT_LE(ping_interval_ms,
2330 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); 2251 cricket::STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL +
2252 SCHEDULING_RANGE);
2331 } 2253 }
2332 2254
2333 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { 2255 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
2334 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2256 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2335 P2PTransportChannel ch("trigger checks", 1, &pa); 2257 cricket::P2PTransportChannel ch("trigger checks", 1, &pa);
2336 PrepareChannel(&ch); 2258 PrepareChannel(&ch);
2337 ch.Connect(); 2259 ch.Connect();
2338 ch.MaybeStartGathering(); 2260 ch.MaybeStartGathering();
2339 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2261 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2340 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 2262 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
2341 2263
2342 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2264 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2343 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2265 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2344 ASSERT_TRUE(conn1 != nullptr); 2266 ASSERT_TRUE(conn1 != nullptr);
2345 ASSERT_TRUE(conn2 != nullptr); 2267 ASSERT_TRUE(conn2 != nullptr);
2346 2268
2347 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 2269 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
2348 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); 2270 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch));
2349 conn1->ReceivedPingResponse(LOW_RTT); 2271 conn1->ReceivedPingResponse(LOW_RTT);
2350 ASSERT_TRUE(conn1->writable()); 2272 ASSERT_TRUE(conn1->writable());
2351 conn1->ReceivedPing(); 2273 conn1->ReceivedPing();
2352 2274
2353 // Ping received, but the connection is already writable, so no 2275 // Ping received, but the connection is already writable, so no
2354 // "triggered check" and conn2 is pinged before conn1 because it has 2276 // "triggered check" and conn2 is pinged before conn1 because it has
2355 // a higher priority. 2277 // a higher priority.
2356 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 2278 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
2357 } 2279 }
2358 2280
2359 TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) { 2281 TEST_F(P2PTransportChannelPingTest, TestSignalStateChanged) {
2360 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2282 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2361 P2PTransportChannel ch("state change", 1, &pa); 2283 cricket::P2PTransportChannel ch("state change", 1, &pa);
2362 PrepareChannel(&ch); 2284 PrepareChannel(&ch);
2363 ch.Connect(); 2285 ch.Connect();
2364 ch.MaybeStartGathering(); 2286 ch.MaybeStartGathering();
2365 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2287 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2366 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2288 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2367 ASSERT_TRUE(conn1 != nullptr); 2289 ASSERT_TRUE(conn1 != nullptr);
2368 // Pruning the connection reduces the set of active connections and changes 2290 // Pruning the connection reduces the set of active connections and changes
2369 // the channel state. 2291 // the channel state.
2370 conn1->Prune(); 2292 conn1->Prune();
2371 EXPECT_EQ_WAIT(STATE_FAILED, channel_state(), kDefaultTimeout); 2293 EXPECT_EQ_WAIT(cricket::STATE_FAILED, channel_state(), kDefaultTimeout);
2372 } 2294 }
2373 2295
2374 // Test adding remote candidates with different ufrags. If a remote candidate 2296 // Test adding remote candidates with different ufrags. If a remote candidate
2375 // is added with an old ufrag, it will be discarded. If it is added with a 2297 // is added with an old ufrag, it will be discarded. If it is added with a
2376 // ufrag that was not seen before, it will be used to create connections 2298 // ufrag that was not seen before, it will be used to create connections
2377 // although the ICE pwd in the remote candidate will be set when the ICE 2299 // although the ICE pwd in the remote candidate will be set when the ICE
2378 // credentials arrive. If a remote candidate is added with the current ICE 2300 // credentials arrive. If a remote candidate is added with the current ICE
2379 // ufrag, its pwd and generation will be set properly. 2301 // ufrag, its pwd and generation will be set properly.
2380 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { 2302 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) {
2381 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2303 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2382 P2PTransportChannel ch("add candidate", 1, &pa); 2304 cricket::P2PTransportChannel ch("add candidate", 1, &pa);
2383 PrepareChannel(&ch); 2305 PrepareChannel(&ch);
2384 ch.Connect(); 2306 ch.Connect();
2385 ch.MaybeStartGathering(); 2307 ch.MaybeStartGathering();
2386 // Add a candidate with a future ufrag. 2308 // Add a candidate with a future ufrag.
2387 ch.AddRemoteCandidate( 2309 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1, kIceUfrag[2]));
2388 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1, kIceUfrag[2])); 2310 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2389 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2390 ASSERT_TRUE(conn1 != nullptr); 2311 ASSERT_TRUE(conn1 != nullptr);
2391 const Candidate& candidate = conn1->remote_candidate(); 2312 const cricket::Candidate& candidate = conn1->remote_candidate();
2392 EXPECT_EQ(kIceUfrag[2], candidate.username()); 2313 EXPECT_EQ(kIceUfrag[2], candidate.username());
2393 EXPECT_TRUE(candidate.password().empty()); 2314 EXPECT_TRUE(candidate.password().empty());
2394 EXPECT_TRUE(FindNextPingableConnectionAndPingIt(&ch) == nullptr); 2315 EXPECT_TRUE(FindNextPingableConnectionAndPingIt(&ch) == nullptr);
2395 2316
2396 // Set the remote credentials with the "future" ufrag. 2317 // Set the remote credentials with the "future" ufrag.
2397 // This should set the ICE pwd in the remote candidate of |conn1|, making 2318 // This should set the ICE pwd in the remote candidate of |conn1|, making
2398 // it pingable. 2319 // it pingable.
2399 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); 2320 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]);
2400 EXPECT_EQ(kIceUfrag[2], candidate.username()); 2321 EXPECT_EQ(kIceUfrag[2], candidate.username());
2401 EXPECT_EQ(kIcePwd[2], candidate.password()); 2322 EXPECT_EQ(kIcePwd[2], candidate.password());
2402 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); 2323 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch));
2403 2324
2404 // Add a candidate with an old ufrag. No connection will be created. 2325 // Add a candidate with an old ufrag. No connection will be created.
2405 ch.AddRemoteCandidate( 2326 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2, kIceUfrag[1]));
2406 CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2, kIceUfrag[1]));
2407 rtc::Thread::Current()->ProcessMessages(500); 2327 rtc::Thread::Current()->ProcessMessages(500);
2408 EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr); 2328 EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr);
2409 2329
2410 // Add a candidate with the current ufrag, its pwd and generation will be 2330 // Add a candidate with the current ufrag, its pwd and generation will be
2411 // assigned, even if the generation is not set. 2331 // assigned, even if the generation is not set.
2412 ch.AddRemoteCandidate( 2332 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 0, kIceUfrag[2]));
2413 CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 0, kIceUfrag[2])); 2333 cricket::Connection* conn3 = nullptr;
2414 Connection* conn3 = nullptr;
2415 ASSERT_TRUE_WAIT((conn3 = GetConnectionTo(&ch, "3.3.3.3", 3)) != nullptr, 2334 ASSERT_TRUE_WAIT((conn3 = GetConnectionTo(&ch, "3.3.3.3", 3)) != nullptr,
2416 3000); 2335 3000);
2417 const Candidate& new_candidate = conn3->remote_candidate(); 2336 const cricket::Candidate& new_candidate = conn3->remote_candidate();
2418 EXPECT_EQ(kIcePwd[2], new_candidate.password()); 2337 EXPECT_EQ(kIcePwd[2], new_candidate.password());
2419 EXPECT_EQ(1U, new_candidate.generation()); 2338 EXPECT_EQ(1U, new_candidate.generation());
2420 2339
2421 // Check that the pwd of all remote candidates are properly assigned. 2340 // Check that the pwd of all remote candidates are properly assigned.
2422 for (const RemoteCandidate& candidate : ch.remote_candidates()) { 2341 for (const cricket::RemoteCandidate& candidate : ch.remote_candidates()) {
2423 EXPECT_TRUE(candidate.username() == kIceUfrag[1] || 2342 EXPECT_TRUE(candidate.username() == kIceUfrag[1] ||
2424 candidate.username() == kIceUfrag[2]); 2343 candidate.username() == kIceUfrag[2]);
2425 if (candidate.username() == kIceUfrag[1]) { 2344 if (candidate.username() == kIceUfrag[1]) {
2426 EXPECT_EQ(kIcePwd[1], candidate.password()); 2345 EXPECT_EQ(kIcePwd[1], candidate.password());
2427 } else if (candidate.username() == kIceUfrag[2]) { 2346 } else if (candidate.username() == kIceUfrag[2]) {
2428 EXPECT_EQ(kIcePwd[2], candidate.password()); 2347 EXPECT_EQ(kIcePwd[2], candidate.password());
2429 } 2348 }
2430 } 2349 }
2431 } 2350 }
2432 2351
2433 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { 2352 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) {
2434 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2353 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2435 P2PTransportChannel ch("connection resurrection", 1, &pa); 2354 cricket::P2PTransportChannel ch("connection resurrection", 1, &pa);
2436 PrepareChannel(&ch); 2355 PrepareChannel(&ch);
2437 ch.Connect(); 2356 ch.Connect();
2438 ch.MaybeStartGathering(); 2357 ch.MaybeStartGathering();
2439 2358
2440 // Create conn1 and keep track of original candidate priority. 2359 // Create conn1 and keep track of original candidate priority.
2441 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2360 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2442 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2361 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2443 ASSERT_TRUE(conn1 != nullptr); 2362 ASSERT_TRUE(conn1 != nullptr);
2444 uint32_t remote_priority = conn1->remote_candidate().priority(); 2363 uint32_t remote_priority = conn1->remote_candidate().priority();
2445 2364
2446 // Create a higher priority candidate and make the connection 2365 // Create a higher priority candidate and make the connection
2447 // receiving/writable. This will prune conn1. 2366 // receiving/writable. This will prune conn1.
2448 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 2367 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
2449 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2368 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2450 ASSERT_TRUE(conn2 != nullptr); 2369 ASSERT_TRUE(conn2 != nullptr);
2451 conn2->ReceivedPing(); 2370 conn2->ReceivedPing();
2452 conn2->ReceivedPingResponse(LOW_RTT); 2371 conn2->ReceivedPingResponse(LOW_RTT);
2453 2372
2454 // Wait for conn1 to be pruned. 2373 // Wait for conn1 to be pruned.
2455 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); 2374 EXPECT_TRUE_WAIT(conn1->pruned(), 3000);
2456 // Destroy the connection to test SignalUnknownAddress. 2375 // Destroy the connection to test SignalUnknownAddress.
2457 conn1->Destroy(); 2376 conn1->Destroy();
2458 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000); 2377 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 1000);
2459 2378
2460 // Create a minimal STUN message with prflx priority. 2379 // Create a minimal STUN message with prflx priority.
2461 IceMessage request; 2380 cricket::IceMessage request;
2462 request.SetType(STUN_BINDING_REQUEST); 2381 request.SetType(cricket::STUN_BINDING_REQUEST);
2463 request.AddAttribute( 2382 request.AddAttribute(new cricket::StunByteStringAttribute(
2464 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 2383 cricket::STUN_ATTR_USERNAME, kIceUfrag[1]));
2465 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 2384 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24;
2466 request.AddAttribute( 2385 request.AddAttribute(new cricket::StunUInt32Attribute(
2467 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 2386 cricket::STUN_ATTR_PRIORITY, prflx_priority));
2468 EXPECT_NE(prflx_priority, remote_priority); 2387 EXPECT_NE(prflx_priority, remote_priority);
2469 2388
2470 Port* port = GetPort(&ch); 2389 cricket::Port* port = GetPort(&ch);
2471 // conn1 should be resurrected with original priority. 2390 // conn1 should be resurrected with original priority.
2472 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 2391 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1),
2473 &request, kIceUfrag[1], false); 2392 cricket::PROTO_UDP, &request, kIceUfrag[1], false);
2474 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2393 conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2475 ASSERT_TRUE(conn1 != nullptr); 2394 ASSERT_TRUE(conn1 != nullptr);
2476 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority); 2395 EXPECT_EQ(conn1->remote_candidate().priority(), remote_priority);
2477 2396
2478 // conn3, a real prflx connection, should have prflx priority. 2397 // conn3, a real prflx connection, should have prflx priority.
2479 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1), PROTO_UDP, 2398 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 1),
2480 &request, kIceUfrag[1], false); 2399 cricket::PROTO_UDP, &request, kIceUfrag[1], false);
2481 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1); 2400 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 1);
2482 ASSERT_TRUE(conn3 != nullptr); 2401 ASSERT_TRUE(conn3 != nullptr);
2483 EXPECT_EQ(conn3->remote_candidate().priority(), prflx_priority); 2402 EXPECT_EQ(conn3->remote_candidate().priority(), prflx_priority);
2484 } 2403 }
2485 2404
2486 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) { 2405 TEST_F(P2PTransportChannelPingTest, TestReceivingStateChange) {
2487 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2406 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2488 P2PTransportChannel ch("receiving state change", 1, &pa); 2407 cricket::P2PTransportChannel ch("receiving state change", 1, &pa);
2489 PrepareChannel(&ch); 2408 PrepareChannel(&ch);
2490 // Default receiving timeout and checking receiving interval should not be too 2409 // Default receiving timeout and checking receiving interval should not be too
2491 // small. 2410 // small.
2492 EXPECT_LE(1000, ch.receiving_timeout()); 2411 EXPECT_LE(1000, ch.receiving_timeout());
2493 EXPECT_LE(200, ch.check_receiving_interval()); 2412 EXPECT_LE(200, ch.check_receiving_interval());
2494 ch.SetIceConfig(CreateIceConfig(500, false)); 2413 ch.SetIceConfig(CreateIceConfig(500, false));
2495 EXPECT_EQ(500, ch.receiving_timeout()); 2414 EXPECT_EQ(500, ch.receiving_timeout());
2496 EXPECT_EQ(50, ch.check_receiving_interval()); 2415 EXPECT_EQ(50, ch.check_receiving_interval());
2497 ch.Connect(); 2416 ch.Connect();
2498 ch.MaybeStartGathering(); 2417 ch.MaybeStartGathering();
2499 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2418 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2500 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2419 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2501 ASSERT_TRUE(conn1 != nullptr); 2420 ASSERT_TRUE(conn1 != nullptr);
2502 2421
2503 conn1->ReceivedPing(); 2422 conn1->ReceivedPing();
2504 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); 2423 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0));
2505 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000); 2424 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000);
2506 EXPECT_TRUE_WAIT(ch.receiving(), 1000); 2425 EXPECT_TRUE_WAIT(ch.receiving(), 1000);
2507 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); 2426 EXPECT_TRUE_WAIT(!ch.receiving(), 1000);
2508 } 2427 }
2509 2428
2510 // The controlled side will select a connection as the "best connection" based 2429 // The controlled side will select a connection as the "best connection" based
2511 // on priority until the controlling side nominates a connection, at which 2430 // on priority until the controlling side nominates a connection, at which
2512 // point the controlled side will select that connection as the 2431 // point the controlled side will select that connection as the
2513 // "best connection". Plus, SignalSelectedCandidatePair will be fired if the 2432 // "best connection". Plus, SignalSelectedCandidatePair will be fired if the
2514 // best connection changes and SignalReadyToSend will be fired if the new best 2433 // best connection changes and SignalReadyToSend will be fired if the new best
2515 // connection is writable. 2434 // connection is writable.
2516 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { 2435 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) {
2517 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2436 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2518 P2PTransportChannel ch("receiving state change", 1, &pa); 2437 cricket::P2PTransportChannel ch("receiving state change", 1, &pa);
2519 PrepareChannel(&ch); 2438 PrepareChannel(&ch);
2520 ch.SetIceRole(ICEROLE_CONTROLLED); 2439 ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
2521 ch.Connect(); 2440 ch.Connect();
2522 ch.MaybeStartGathering(); 2441 ch.MaybeStartGathering();
2523 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2442 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2524 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2443 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2525 ASSERT_TRUE(conn1 != nullptr); 2444 ASSERT_TRUE(conn1 != nullptr);
2526 EXPECT_EQ(conn1, ch.best_connection()); 2445 EXPECT_EQ(conn1, ch.best_connection());
2527 EXPECT_EQ(conn1, last_selected_candidate_pair()); 2446 EXPECT_EQ(conn1, last_selected_candidate_pair());
2528 EXPECT_EQ(-1, last_sent_packet_id()); 2447 EXPECT_EQ(-1, last_sent_packet_id());
2529 // Channel is not ready to send because it is not writable. 2448 // Channel is not ready to send because it is not writable.
2530 EXPECT_FALSE(channel_ready_to_send()); 2449 EXPECT_FALSE(channel_ready_to_send());
2531 2450
2532 int last_packet_id = 0; 2451 int last_packet_id = 0;
2533 const char* data = "ABCDEFGH"; 2452 const char* data = "ABCDEFGH";
2534 int len = static_cast<int>(strlen(data)); 2453 int len = static_cast<int>(strlen(data));
2535 SendData(ch, data, len, ++last_packet_id); 2454 SendData(ch, data, len, ++last_packet_id);
2536 // When a higher priority candidate comes in, the new connection is chosen 2455 // When a higher priority candidate comes in, the new connection is chosen
2537 // as the best connection. 2456 // as the best connection.
2538 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); 2457 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10));
2539 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2458 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2540 ASSERT_TRUE(conn2 != nullptr); 2459 ASSERT_TRUE(conn2 != nullptr);
2541 EXPECT_EQ(conn2, ch.best_connection()); 2460 EXPECT_EQ(conn2, ch.best_connection());
2542 EXPECT_EQ(conn2, last_selected_candidate_pair()); 2461 EXPECT_EQ(conn2, last_selected_candidate_pair());
2543 EXPECT_EQ(last_packet_id, last_sent_packet_id()); 2462 EXPECT_EQ(last_packet_id, last_sent_packet_id());
2544 EXPECT_FALSE(channel_ready_to_send()); 2463 EXPECT_FALSE(channel_ready_to_send());
2545 2464
2546 // If a stun request with use-candidate attribute arrives, the receiving 2465 // If a stun request with use-candidate attribute arrives, the receiving
2547 // connection will be set as the best connection, even though 2466 // connection will be set as the best connection, even though
2548 // its priority is lower. 2467 // its priority is lower.
2549 SendData(ch, data, len, ++last_packet_id); 2468 SendData(ch, data, len, ++last_packet_id);
2550 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); 2469 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1));
2551 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 2470 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
2552 ASSERT_TRUE(conn3 != nullptr); 2471 ASSERT_TRUE(conn3 != nullptr);
2553 // Because it has a lower priority, the best connection is still conn2. 2472 // Because it has a lower priority, the best connection is still conn2.
2554 EXPECT_EQ(conn2, ch.best_connection()); 2473 EXPECT_EQ(conn2, ch.best_connection());
2555 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. 2474 conn3->ReceivedPingResponse(LOW_RTT); // Become writable.
2556 // But if it is nominated via use_candidate, it is chosen as the best 2475 // But if it is nominated via use_candidate, it is chosen as the best
2557 // connection. 2476 // connection.
2558 conn3->set_nominated(true); 2477 conn3->set_nominated(true);
2559 conn3->SignalNominated(conn3); 2478 conn3->SignalNominated(conn3);
2560 EXPECT_EQ(conn3, ch.best_connection()); 2479 EXPECT_EQ(conn3, ch.best_connection());
2561 EXPECT_EQ(conn3, last_selected_candidate_pair()); 2480 EXPECT_EQ(conn3, last_selected_candidate_pair());
2562 EXPECT_EQ(last_packet_id, last_sent_packet_id()); 2481 EXPECT_EQ(last_packet_id, last_sent_packet_id());
2563 EXPECT_TRUE(channel_ready_to_send()); 2482 EXPECT_TRUE(channel_ready_to_send());
2564 2483
2565 // Even if another higher priority candidate arrives, 2484 // Even if another higher priority candidate arrives,
2566 // it will not be set as the best connection because the best connection 2485 // it will not be set as the best connection because the best connection
2567 // is nominated by the controlling side. 2486 // is nominated by the controlling side.
2568 SendData(ch, data, len, ++last_packet_id); 2487 SendData(ch, data, len, ++last_packet_id);
2569 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "4.4.4.4", 4, 100)); 2488 ch.AddRemoteCandidate(CreateHostCandidate("4.4.4.4", 4, 100));
2570 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); 2489 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
2571 ASSERT_TRUE(conn4 != nullptr); 2490 ASSERT_TRUE(conn4 != nullptr);
2572 EXPECT_EQ(conn3, ch.best_connection()); 2491 EXPECT_EQ(conn3, ch.best_connection());
2573 // But if it is nominated via use_candidate and writable, it will be set as 2492 // But if it is nominated via use_candidate and writable, it will be set as
2574 // the best connection. 2493 // the best connection.
2575 conn4->set_nominated(true); 2494 conn4->set_nominated(true);
2576 conn4->SignalNominated(conn4); 2495 conn4->SignalNominated(conn4);
2577 // Not switched yet because conn4 is not writable. 2496 // Not switched yet because conn4 is not writable.
2578 EXPECT_EQ(conn3, ch.best_connection()); 2497 EXPECT_EQ(conn3, ch.best_connection());
2579 reset_channel_ready_to_send(); 2498 reset_channel_ready_to_send();
2580 // The best connection switches after conn4 becomes writable. 2499 // The best connection switches after conn4 becomes writable.
2581 conn4->ReceivedPingResponse(LOW_RTT); 2500 conn4->ReceivedPingResponse(LOW_RTT);
2582 EXPECT_EQ(conn4, ch.best_connection()); 2501 EXPECT_EQ(conn4, ch.best_connection());
2583 EXPECT_EQ(conn4, last_selected_candidate_pair()); 2502 EXPECT_EQ(conn4, last_selected_candidate_pair());
2584 EXPECT_EQ(last_packet_id, last_sent_packet_id()); 2503 EXPECT_EQ(last_packet_id, last_sent_packet_id());
2585 // SignalReadyToSend is fired again because conn4 is writable. 2504 // SignalReadyToSend is fired again because conn4 is writable.
2586 EXPECT_TRUE(channel_ready_to_send()); 2505 EXPECT_TRUE(channel_ready_to_send());
2587 } 2506 }
2588 2507
2589 // The controlled side will select a connection as the "best connection" based 2508 // The controlled side will select a connection as the "best connection" based
2590 // on requests from an unknown address before the controlling side nominates 2509 // on requests from an unknown address before the controlling side nominates
2591 // a connection, and will nominate a connection from an unknown address if the 2510 // a connection, and will nominate a connection from an unknown address if the
2592 // request contains the use_candidate attribute. Plus, it will also sends back 2511 // request contains the use_candidate attribute. Plus, it will also sends back
2593 // a ping response and set the ICE pwd in the remote candidate appropriately. 2512 // a ping response and set the ICE pwd in the remote candidate appropriately.
2594 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { 2513 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) {
2595 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2514 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2596 P2PTransportChannel ch("receiving state change", 1, &pa); 2515 cricket::P2PTransportChannel ch("receiving state change", 1, &pa);
2597 PrepareChannel(&ch); 2516 PrepareChannel(&ch);
2598 ch.SetIceRole(ICEROLE_CONTROLLED); 2517 ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
2599 ch.Connect(); 2518 ch.Connect();
2600 ch.MaybeStartGathering(); 2519 ch.MaybeStartGathering();
2601 // A minimal STUN message with prflx priority. 2520 // A minimal STUN message with prflx priority.
2602 IceMessage request; 2521 cricket::IceMessage request;
2603 request.SetType(STUN_BINDING_REQUEST); 2522 request.SetType(cricket::STUN_BINDING_REQUEST);
2604 request.AddAttribute( 2523 request.AddAttribute(new cricket::StunByteStringAttribute(
2605 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 2524 cricket::STUN_ATTR_USERNAME, kIceUfrag[1]));
2606 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 2525 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24;
2607 request.AddAttribute( 2526 request.AddAttribute(new cricket::StunUInt32Attribute(
2608 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 2527 cricket::STUN_ATTR_PRIORITY, prflx_priority));
2609 TestUDPPort* port = static_cast<TestUDPPort*>(GetPort(&ch)); 2528 cricket::TestUDPPort* port = static_cast<cricket::TestUDPPort*>(GetPort(&ch));
2610 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 2529 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1),
2611 &request, kIceUfrag[1], false); 2530 cricket::PROTO_UDP, &request, kIceUfrag[1], false);
2612 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2531 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2613 ASSERT_TRUE(conn1 != nullptr); 2532 ASSERT_TRUE(conn1 != nullptr);
2614 EXPECT_TRUE(port->sent_binding_response()); 2533 EXPECT_TRUE(port->sent_binding_response());
2615 EXPECT_EQ(conn1, ch.best_connection()); 2534 EXPECT_EQ(conn1, ch.best_connection());
2616 conn1->ReceivedPingResponse(LOW_RTT); 2535 conn1->ReceivedPingResponse(LOW_RTT);
2617 EXPECT_EQ(conn1, ch.best_connection()); 2536 EXPECT_EQ(conn1, ch.best_connection());
2618 port->set_sent_binding_response(false); 2537 port->set_sent_binding_response(false);
2619 2538
2620 // Another connection is nominated via use_candidate. 2539 // Another connection is nominated via use_candidate.
2621 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 2540 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1));
2622 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2541 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2623 ASSERT_TRUE(conn2 != nullptr); 2542 ASSERT_TRUE(conn2 != nullptr);
2624 // Because it has a lower priority, the best connection is still conn1. 2543 // Because it has a lower priority, the best connection is still conn1.
2625 EXPECT_EQ(conn1, ch.best_connection()); 2544 EXPECT_EQ(conn1, ch.best_connection());
2626 // When it is nominated via use_candidate and writable, it is chosen as the 2545 // When it is nominated via use_candidate and writable, it is chosen as the
2627 // best connection. 2546 // best connection.
2628 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. 2547 conn2->ReceivedPingResponse(LOW_RTT); // Become writable.
2629 conn2->set_nominated(true); 2548 conn2->set_nominated(true);
2630 conn2->SignalNominated(conn2); 2549 conn2->SignalNominated(conn2);
2631 EXPECT_EQ(conn2, ch.best_connection()); 2550 EXPECT_EQ(conn2, ch.best_connection());
2632 2551
2633 // Another request with unknown address, it will not be set as the best 2552 // Another request with unknown address, it will not be set as the best
2634 // connection because the best connection was nominated by the controlling 2553 // connection because the best connection was nominated by the controlling
2635 // side. 2554 // side.
2636 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP, 2555 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3),
2637 &request, kIceUfrag[1], false); 2556 cricket::PROTO_UDP, &request, kIceUfrag[1], false);
2638 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 2557 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
2639 ASSERT_TRUE(conn3 != nullptr); 2558 ASSERT_TRUE(conn3 != nullptr);
2640 EXPECT_TRUE(port->sent_binding_response()); 2559 EXPECT_TRUE(port->sent_binding_response());
2641 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. 2560 conn3->ReceivedPingResponse(LOW_RTT); // Become writable.
2642 EXPECT_EQ(conn2, ch.best_connection()); 2561 EXPECT_EQ(conn2, ch.best_connection());
2643 port->set_sent_binding_response(false); 2562 port->set_sent_binding_response(false);
2644 2563
2645 // However if the request contains use_candidate attribute, it will be 2564 // However if the request contains use_candidate attribute, it will be
2646 // selected as the best connection. 2565 // selected as the best connection.
2647 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); 2566 request.AddAttribute(
2648 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4), PROTO_UDP, 2567 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE));
2649 &request, kIceUfrag[1], false); 2568 port->SignalUnknownAddress(port, rtc::SocketAddress("4.4.4.4", 4),
2650 Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); 2569 cricket::PROTO_UDP, &request, kIceUfrag[1], false);
2570 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4);
2651 ASSERT_TRUE(conn4 != nullptr); 2571 ASSERT_TRUE(conn4 != nullptr);
2652 EXPECT_TRUE(port->sent_binding_response()); 2572 EXPECT_TRUE(port->sent_binding_response());
2653 // conn4 is not the best connection yet because it is not writable. 2573 // conn4 is not the best connection yet because it is not writable.
2654 EXPECT_EQ(conn2, ch.best_connection()); 2574 EXPECT_EQ(conn2, ch.best_connection());
2655 conn4->ReceivedPingResponse(LOW_RTT); // Become writable. 2575 conn4->ReceivedPingResponse(LOW_RTT); // Become writable.
2656 EXPECT_EQ(conn4, ch.best_connection()); 2576 EXPECT_EQ(conn4, ch.best_connection());
2657 2577
2658 // Test that the request from an unknown address contains a ufrag from an old 2578 // Test that the request from an unknown address contains a ufrag from an old
2659 // generation. 2579 // generation.
2660 port->set_sent_binding_response(false); 2580 port->set_sent_binding_response(false);
2661 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); 2581 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]);
2662 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 2582 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]);
2663 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP, 2583 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5),
2664 &request, kIceUfrag[2], false); 2584 cricket::PROTO_UDP, &request, kIceUfrag[2], false);
2665 Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); 2585 cricket::Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5);
2666 ASSERT_TRUE(conn5 != nullptr); 2586 ASSERT_TRUE(conn5 != nullptr);
2667 EXPECT_TRUE(port->sent_binding_response()); 2587 EXPECT_TRUE(port->sent_binding_response());
2668 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password()); 2588 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password());
2669 } 2589 }
2670 2590
2671 // The controlled side will select a connection as the "best connection" 2591 // The controlled side will select a connection as the "best connection"
2672 // based on media received until the controlling side nominates a connection, 2592 // based on media received until the controlling side nominates a connection,
2673 // at which point the controlled side will select that connection as 2593 // at which point the controlled side will select that connection as
2674 // the "best connection". 2594 // the "best connection".
2675 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { 2595 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) {
2676 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2596 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2677 P2PTransportChannel ch("receiving state change", 1, &pa); 2597 cricket::P2PTransportChannel ch("receiving state change", 1, &pa);
2678 PrepareChannel(&ch); 2598 PrepareChannel(&ch);
2679 ch.SetIceRole(ICEROLE_CONTROLLED); 2599 ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
2680 ch.Connect(); 2600 ch.Connect();
2681 ch.MaybeStartGathering(); 2601 ch.MaybeStartGathering();
2682 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 10)); 2602 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 10));
2683 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2603 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2684 ASSERT_TRUE(conn1 != nullptr); 2604 ASSERT_TRUE(conn1 != nullptr);
2685 EXPECT_EQ(conn1, ch.best_connection()); 2605 EXPECT_EQ(conn1, ch.best_connection());
2686 2606
2687 // If a data packet is received on conn2, the best connection should 2607 // If a data packet is received on conn2, the best connection should
2688 // switch to conn2 because the controlled side must mirror the media path 2608 // switch to conn2 because the controlled side must mirror the media path
2689 // chosen by the controlling side. 2609 // chosen by the controlling side.
2690 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 2610 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1));
2691 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2611 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2692 ASSERT_TRUE(conn2 != nullptr); 2612 ASSERT_TRUE(conn2 != nullptr);
2693 conn2->ReceivedPing(); // Start receiving. 2613 conn2->ReceivedPing(); // Start receiving.
2694 // Do not switch because it is not writable. 2614 // Do not switch because it is not writable.
2695 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); 2615 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0));
2696 EXPECT_EQ(conn1, ch.best_connection()); 2616 EXPECT_EQ(conn1, ch.best_connection());
2697 2617
2698 conn2->ReceivedPingResponse(LOW_RTT); // Become writable. 2618 conn2->ReceivedPingResponse(LOW_RTT); // Become writable.
2699 // Switch because it is writable. 2619 // Switch because it is writable.
2700 conn2->OnReadPacket("DEF", 3, rtc::CreatePacketTime(0)); 2620 conn2->OnReadPacket("DEF", 3, rtc::CreatePacketTime(0));
2701 EXPECT_EQ(conn2, ch.best_connection()); 2621 EXPECT_EQ(conn2, ch.best_connection());
2702 2622
2703 // Now another STUN message with an unknown address and use_candidate will 2623 // Now another STUN message with an unknown address and use_candidate will
2704 // nominate the best connection. 2624 // nominate the best connection.
2705 IceMessage request; 2625 cricket::IceMessage request;
2706 request.SetType(STUN_BINDING_REQUEST); 2626 request.SetType(cricket::STUN_BINDING_REQUEST);
2627 request.AddAttribute(new cricket::StunByteStringAttribute(
2628 cricket::STUN_ATTR_USERNAME, kIceUfrag[1]));
2629 uint32_t prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24;
2630 request.AddAttribute(new cricket::StunUInt32Attribute(
2631 cricket::STUN_ATTR_PRIORITY, prflx_priority));
2707 request.AddAttribute( 2632 request.AddAttribute(
2708 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 2633 new cricket::StunByteStringAttribute(cricket::STUN_ATTR_USE_CANDIDATE));
2709 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 2634 cricket::Port* port = GetPort(&ch);
2710 request.AddAttribute( 2635 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3),
2711 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 2636 cricket::PROTO_UDP, &request, kIceUfrag[1], false);
2712 request.AddAttribute(new StunByteStringAttribute(STUN_ATTR_USE_CANDIDATE)); 2637 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
2713 Port* port = GetPort(&ch);
2714 port->SignalUnknownAddress(port, rtc::SocketAddress("3.3.3.3", 3), PROTO_UDP,
2715 &request, kIceUfrag[1], false);
2716 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
2717 ASSERT_TRUE(conn3 != nullptr); 2638 ASSERT_TRUE(conn3 != nullptr);
2718 EXPECT_EQ(conn2, ch.best_connection()); // Not writable yet. 2639 EXPECT_EQ(conn2, ch.best_connection()); // Not writable yet.
2719 conn3->ReceivedPingResponse(LOW_RTT); // Become writable. 2640 conn3->ReceivedPingResponse(LOW_RTT); // Become writable.
2720 EXPECT_EQ(conn3, ch.best_connection()); 2641 EXPECT_EQ(conn3, ch.best_connection());
2721 2642
2722 // Now another data packet will not switch the best connection because the 2643 // Now another data packet will not switch the best connection because the
2723 // best connection was nominated by the controlling side. 2644 // best connection was nominated by the controlling side.
2724 conn2->ReceivedPing(); 2645 conn2->ReceivedPing();
2725 conn2->ReceivedPingResponse(LOW_RTT); 2646 conn2->ReceivedPingResponse(LOW_RTT);
2726 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); 2647 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0));
2727 EXPECT_EQ(conn3, ch.best_connection()); 2648 EXPECT_EQ(conn3, ch.best_connection());
2728 } 2649 }
2729 2650
2730 // Test that if a new remote candidate has the same address and port with 2651 // Test that if a new remote candidate has the same address and port with
2731 // an old one, it will be used to create a new connection. 2652 // an old one, it will be used to create a new connection.
2732 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) { 2653 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithAddressReuse) {
2733 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2654 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2734 P2PTransportChannel ch("candidate reuse", 1, &pa); 2655 cricket::P2PTransportChannel ch("candidate reuse", 1, &pa);
2735 PrepareChannel(&ch); 2656 PrepareChannel(&ch);
2736 ch.Connect(); 2657 ch.Connect();
2737 ch.MaybeStartGathering(); 2658 ch.MaybeStartGathering();
2738 const std::string host_address = "1.1.1.1"; 2659 const std::string host_address = "1.1.1.1";
2739 const int port_num = 1; 2660 const int port_num = 1;
2740 2661
2741 // kIceUfrag[1] is the current generation ufrag. 2662 // kIceUfrag[1] is the current generation ufrag.
2742 Candidate candidate = CreateUdpCandidate(LOCAL_PORT_TYPE, host_address, 2663 cricket::Candidate candidate =
2743 port_num, 1, kIceUfrag[1]); 2664 CreateHostCandidate(host_address, port_num, 1, kIceUfrag[1]);
2744 ch.AddRemoteCandidate(candidate); 2665 ch.AddRemoteCandidate(candidate);
2745 Connection* conn1 = WaitForConnectionTo(&ch, host_address, port_num); 2666 cricket::Connection* conn1 = WaitForConnectionTo(&ch, host_address, port_num);
2746 ASSERT_TRUE(conn1 != nullptr); 2667 ASSERT_TRUE(conn1 != nullptr);
2747 EXPECT_EQ(0u, conn1->remote_candidate().generation()); 2668 EXPECT_EQ(0u, conn1->remote_candidate().generation());
2748 2669
2749 // Simply adding the same candidate again won't create a new connection. 2670 // Simply adding the same candidate again won't create a new connection.
2750 ch.AddRemoteCandidate(candidate); 2671 ch.AddRemoteCandidate(candidate);
2751 Connection* conn2 = GetConnectionTo(&ch, host_address, port_num); 2672 cricket::Connection* conn2 = GetConnectionTo(&ch, host_address, port_num);
2752 EXPECT_EQ(conn1, conn2); 2673 EXPECT_EQ(conn1, conn2);
2753 2674
2754 // Update the ufrag of the candidate and add it again. 2675 // Update the ufrag of the candidate and add it again.
2755 candidate.set_username(kIceUfrag[2]); 2676 candidate.set_username(kIceUfrag[2]);
2756 ch.AddRemoteCandidate(candidate); 2677 ch.AddRemoteCandidate(candidate);
2757 conn2 = GetConnectionTo(&ch, host_address, port_num); 2678 conn2 = GetConnectionTo(&ch, host_address, port_num);
2758 EXPECT_NE(conn1, conn2); 2679 EXPECT_NE(conn1, conn2);
2759 EXPECT_EQ(kIceUfrag[2], conn2->remote_candidate().username()); 2680 EXPECT_EQ(kIceUfrag[2], conn2->remote_candidate().username());
2760 EXPECT_EQ(1u, conn2->remote_candidate().generation()); 2681 EXPECT_EQ(1u, conn2->remote_candidate().generation());
2761 2682
2762 // Verify that a ping with the new ufrag can be received on the new 2683 // Verify that a ping with the new ufrag can be received on the new
2763 // connection. 2684 // connection.
2764 EXPECT_EQ(0, conn2->last_ping_received()); 2685 EXPECT_EQ(0, conn2->last_ping_received());
2765 ReceivePingOnConnection(conn2, kIceUfrag[2], 1 /* priority */); 2686 ReceivePingOnConnection(conn2, kIceUfrag[2], 1 /* priority */);
2766 EXPECT_TRUE(conn2->last_ping_received() > 0); 2687 EXPECT_TRUE(conn2->last_ping_received() > 0);
2767 } 2688 }
2768 2689
2769 // When the current best connection is strong, lower-priority connections will 2690 // When the current best connection is strong, lower-priority connections will
2770 // be pruned. Otherwise, lower-priority connections are kept. 2691 // be pruned. Otherwise, lower-priority connections are kept.
2771 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) { 2692 TEST_F(P2PTransportChannelPingTest, TestDontPruneWhenWeak) {
2772 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2693 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2773 P2PTransportChannel ch("test channel", 1, &pa); 2694 cricket::P2PTransportChannel ch("test channel", 1, &pa);
2774 PrepareChannel(&ch); 2695 PrepareChannel(&ch);
2775 ch.SetIceRole(ICEROLE_CONTROLLED); 2696 ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
2776 ch.Connect(); 2697 ch.Connect();
2777 ch.MaybeStartGathering(); 2698 ch.MaybeStartGathering();
2778 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2699 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2779 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2700 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2780 ASSERT_TRUE(conn1 != nullptr); 2701 ASSERT_TRUE(conn1 != nullptr);
2781 EXPECT_EQ(conn1, ch.best_connection()); 2702 EXPECT_EQ(conn1, ch.best_connection());
2782 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 2703 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
2783 2704
2784 // When a higher-priority, nominated candidate comes in, the connections with 2705 // When a higher-priority, nominated candidate comes in, the connections with
2785 // lower-priority are pruned. 2706 // lower-priority are pruned.
2786 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 10)); 2707 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 10));
2787 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2708 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2788 ASSERT_TRUE(conn2 != nullptr); 2709 ASSERT_TRUE(conn2 != nullptr);
2789 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 2710 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
2790 conn2->set_nominated(true); 2711 conn2->set_nominated(true);
2791 conn2->SignalNominated(conn2); 2712 conn2->SignalNominated(conn2);
2792 EXPECT_TRUE_WAIT(conn1->pruned(), 3000); 2713 EXPECT_TRUE_WAIT(conn1->pruned(), 3000);
2793 2714
2794 ch.SetIceConfig(CreateIceConfig(500, false)); 2715 ch.SetIceConfig(CreateIceConfig(500, false));
2795 // Wait until conn2 becomes not receiving. 2716 // Wait until conn2 becomes not receiving.
2796 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000); 2717 EXPECT_TRUE_WAIT(!conn2->receiving(), 3000);
2797 2718
2798 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 1)); 2719 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 1));
2799 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 2720 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
2800 ASSERT_TRUE(conn3 != nullptr); 2721 ASSERT_TRUE(conn3 != nullptr);
2801 // The best connection should still be conn2. Even through conn3 has lower 2722 // The best connection should still be conn2. Even through conn3 has lower
2802 // priority and is not receiving/writable, it is not pruned because the best 2723 // priority and is not receiving/writable, it is not pruned because the best
2803 // connection is not receiving. 2724 // connection is not receiving.
2804 WAIT(conn3->pruned(), 1000); 2725 WAIT(conn3->pruned(), 1000);
2805 EXPECT_FALSE(conn3->pruned()); 2726 EXPECT_FALSE(conn3->pruned());
2806 } 2727 }
2807 2728
2808 // Test that GetState returns the state correctly. 2729 // Test that GetState returns the state correctly.
2809 TEST_F(P2PTransportChannelPingTest, TestGetState) { 2730 TEST_F(P2PTransportChannelPingTest, TestGetState) {
2810 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2731 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2811 P2PTransportChannel ch("test channel", 1, &pa); 2732 cricket::P2PTransportChannel ch("test channel", 1, &pa);
2812 PrepareChannel(&ch); 2733 PrepareChannel(&ch);
2813 ch.Connect(); 2734 ch.Connect();
2814 ch.MaybeStartGathering(); 2735 ch.MaybeStartGathering();
2815 EXPECT_EQ(TransportChannelState::STATE_INIT, ch.GetState()); 2736 EXPECT_EQ(cricket::TransportChannelState::STATE_INIT, ch.GetState());
2816 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 2737 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100));
2817 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 2738 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1));
2818 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2739 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2819 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2740 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2820 ASSERT_TRUE(conn1 != nullptr); 2741 ASSERT_TRUE(conn1 != nullptr);
2821 ASSERT_TRUE(conn2 != nullptr); 2742 ASSERT_TRUE(conn2 != nullptr);
2822 // Now there are two connections, so the transport channel is connecting. 2743 // Now there are two connections, so the transport channel is connecting.
2823 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); 2744 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState());
2824 // |conn1| becomes writable and receiving; it then should prune |conn2|. 2745 // |conn1| becomes writable and receiving; it then should prune |conn2|.
2825 conn1->ReceivedPingResponse(LOW_RTT); 2746 conn1->ReceivedPingResponse(LOW_RTT);
2826 EXPECT_TRUE_WAIT(conn2->pruned(), 1000); 2747 EXPECT_TRUE_WAIT(conn2->pruned(), 1000);
2827 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 2748 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState());
2828 conn1->Prune(); // All connections are pruned. 2749 conn1->Prune(); // All connections are pruned.
2829 // Need to wait until the channel state is updated. 2750 // Need to wait until the channel state is updated.
2830 EXPECT_EQ_WAIT(TransportChannelState::STATE_FAILED, ch.GetState(), 1000); 2751 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_FAILED, ch.GetState(),
2752 1000);
2831 } 2753 }
2832 2754
2833 // Test that when a low-priority connection is pruned, it is not deleted 2755 // Test that when a low-priority connection is pruned, it is not deleted
2834 // right away, and it can become active and be pruned again. 2756 // right away, and it can become active and be pruned again.
2835 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) { 2757 TEST_F(P2PTransportChannelPingTest, TestConnectionPrunedAgain) {
2836 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2758 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2837 P2PTransportChannel ch("test channel", 1, &pa); 2759 cricket::P2PTransportChannel ch("test channel", 1, &pa);
2838 PrepareChannel(&ch); 2760 PrepareChannel(&ch);
2839 ch.SetIceConfig(CreateIceConfig(1000, false)); 2761 ch.SetIceConfig(CreateIceConfig(1000, false));
2840 ch.Connect(); 2762 ch.Connect();
2841 ch.MaybeStartGathering(); 2763 ch.MaybeStartGathering();
2842 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 2764 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100));
2843 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2765 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2844 ASSERT_TRUE(conn1 != nullptr); 2766 ASSERT_TRUE(conn1 != nullptr);
2845 EXPECT_EQ(conn1, ch.best_connection()); 2767 EXPECT_EQ(conn1, ch.best_connection());
2846 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 2768 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
2847 2769
2848 // Add a low-priority connection |conn2|, which will be pruned, but it will 2770 // Add a low-priority connection |conn2|, which will be pruned, but it will
2849 // not be deleted right away. Once the current best connection becomes not 2771 // not be deleted right away. Once the current best connection becomes not
2850 // receiving, |conn2| will start to ping and upon receiving the ping response, 2772 // receiving, |conn2| will start to ping and upon receiving the ping response,
2851 // it will become the best connection. 2773 // it will become the best connection.
2852 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 2774 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1));
2853 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2775 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2854 ASSERT_TRUE(conn2 != nullptr); 2776 ASSERT_TRUE(conn2 != nullptr);
2855 EXPECT_TRUE_WAIT(!conn2->active(), 1000); 2777 EXPECT_TRUE_WAIT(!conn2->active(), 1000);
2856 // |conn2| should not send a ping yet. 2778 // |conn2| should not send a ping yet.
2857 EXPECT_EQ(Connection::STATE_WAITING, conn2->state()); 2779 EXPECT_EQ(cricket::Connection::STATE_WAITING, conn2->state());
2858 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 2780 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState());
2859 // Wait for |conn1| becoming not receiving. 2781 // Wait for |conn1| becoming not receiving.
2860 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000); 2782 EXPECT_TRUE_WAIT(!conn1->receiving(), 3000);
2861 // Make sure conn2 is not deleted. 2783 // Make sure conn2 is not deleted.
2862 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2784 conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2863 ASSERT_TRUE(conn2 != nullptr); 2785 ASSERT_TRUE(conn2 != nullptr);
2864 EXPECT_EQ_WAIT(Connection::STATE_INPROGRESS, conn2->state(), 1000); 2786 EXPECT_EQ_WAIT(cricket::Connection::STATE_INPROGRESS, conn2->state(), 1000);
2865 conn2->ReceivedPingResponse(LOW_RTT); 2787 conn2->ReceivedPingResponse(LOW_RTT);
2866 EXPECT_EQ_WAIT(conn2, ch.best_connection(), 1000); 2788 EXPECT_EQ_WAIT(conn2, ch.best_connection(), 1000);
2867 EXPECT_EQ(TransportChannelState::STATE_CONNECTING, ch.GetState()); 2789 EXPECT_EQ(cricket::TransportChannelState::STATE_CONNECTING, ch.GetState());
2868 2790
2869 // When |conn1| comes back again, |conn2| will be pruned again. 2791 // When |conn1| comes back again, |conn2| will be pruned again.
2870 conn1->ReceivedPingResponse(LOW_RTT); 2792 conn1->ReceivedPingResponse(LOW_RTT);
2871 EXPECT_EQ_WAIT(conn1, ch.best_connection(), 1000); 2793 EXPECT_EQ_WAIT(conn1, ch.best_connection(), 1000);
2872 EXPECT_TRUE_WAIT(!conn2->active(), 1000); 2794 EXPECT_TRUE_WAIT(!conn2->active(), 1000);
2873 EXPECT_EQ(TransportChannelState::STATE_COMPLETED, ch.GetState()); 2795 EXPECT_EQ(cricket::TransportChannelState::STATE_COMPLETED, ch.GetState());
2874 } 2796 }
2875 2797
2876 // Test that if all connections in a channel has timed out on writing, they 2798 // Test that if all connections in a channel has timed out on writing, they
2877 // will all be deleted. We use Prune to simulate write_time_out. 2799 // will all be deleted. We use Prune to simulate write_time_out.
2878 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) { 2800 TEST_F(P2PTransportChannelPingTest, TestDeleteConnectionsIfAllWriteTimedout) {
2879 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2801 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2880 P2PTransportChannel ch("test channel", 1, &pa); 2802 cricket::P2PTransportChannel ch("test channel", 1, &pa);
2881 PrepareChannel(&ch); 2803 PrepareChannel(&ch);
2882 ch.Connect(); 2804 ch.Connect();
2883 ch.MaybeStartGathering(); 2805 ch.MaybeStartGathering();
2884 // Have one connection only but later becomes write-time-out. 2806 // Have one connection only but later becomes write-time-out.
2885 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 2807 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100));
2886 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2808 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2887 ASSERT_TRUE(conn1 != nullptr); 2809 ASSERT_TRUE(conn1 != nullptr);
2888 conn1->ReceivedPing(); // Becomes receiving 2810 conn1->ReceivedPing(); // Becomes receiving
2889 conn1->Prune(); 2811 conn1->Prune();
2890 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); 2812 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000);
2891 2813
2892 // Have two connections but both become write-time-out later. 2814 // Have two connections but both become write-time-out later.
2893 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 1)); 2815 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 1));
2894 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2816 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2895 ASSERT_TRUE(conn2 != nullptr); 2817 ASSERT_TRUE(conn2 != nullptr);
2896 conn2->ReceivedPing(); // Becomes receiving 2818 conn2->ReceivedPing(); // Becomes receiving
2897 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "3.3.3.3", 3, 2)); 2819 ch.AddRemoteCandidate(CreateHostCandidate("3.3.3.3", 3, 2));
2898 Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); 2820 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3);
2899 ASSERT_TRUE(conn3 != nullptr); 2821 ASSERT_TRUE(conn3 != nullptr);
2900 conn3->ReceivedPing(); // Becomes receiving 2822 conn3->ReceivedPing(); // Becomes receiving
2901 // Now prune both conn2 and conn3; they will be deleted soon. 2823 // Now prune both conn2 and conn3; they will be deleted soon.
2902 conn2->Prune(); 2824 conn2->Prune();
2903 conn3->Prune(); 2825 conn3->Prune();
2904 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000); 2826 EXPECT_TRUE_WAIT(ch.connections().empty(), 1000);
2905 } 2827 }
2906 2828
2907 // Tests that after a port allocator session is started, it will be stopped 2829 // Tests that after a port allocator session is started, it will be stopped
2908 // when a new connection becomes writable and receiving. Also tests that if a 2830 // when a new connection becomes writable and receiving. Also tests that if a
2909 // connection belonging to an old session becomes writable, it won't stop 2831 // connection belonging to an old session becomes writable, it won't stop
2910 // the current port allocator session. 2832 // the current port allocator session.
2911 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) { 2833 TEST_F(P2PTransportChannelPingTest, TestStopPortAllocatorSessions) {
2912 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2834 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2913 P2PTransportChannel ch("test channel", 1, &pa); 2835 cricket::P2PTransportChannel ch("test channel", 1, &pa);
2914 PrepareChannel(&ch); 2836 PrepareChannel(&ch);
2915 ch.SetIceConfig(CreateIceConfig(2000, false)); 2837 ch.SetIceConfig(CreateIceConfig(2000, false));
2916 ch.Connect(); 2838 ch.Connect();
2917 ch.MaybeStartGathering(); 2839 ch.MaybeStartGathering();
2918 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 2840 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 100));
2919 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2841 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2920 ASSERT_TRUE(conn1 != nullptr); 2842 ASSERT_TRUE(conn1 != nullptr);
2921 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 2843 conn1->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
2922 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); 2844 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
2923 2845
2924 // Start a new session. Even though conn1, which belongs to an older 2846 // Start a new session. Even though conn1, which belongs to an older
2925 // session, becomes unwritable and writable again, it should not stop the 2847 // session, becomes unwritable and writable again, it should not stop the
2926 // current session. 2848 // current session.
2927 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); 2849 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]);
2928 ch.MaybeStartGathering(); 2850 ch.MaybeStartGathering();
2929 conn1->Prune(); 2851 conn1->Prune();
2930 conn1->ReceivedPingResponse(LOW_RTT); 2852 conn1->ReceivedPingResponse(LOW_RTT);
2931 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); 2853 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts());
2932 2854
2933 // But if a new connection created from the new session becomes writable, 2855 // But if a new connection created from the new session becomes writable,
2934 // it will stop the current session. 2856 // it will stop the current session.
2935 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100)); 2857 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 100));
2936 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 2858 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
2937 ASSERT_TRUE(conn2 != nullptr); 2859 ASSERT_TRUE(conn2 != nullptr);
2938 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving 2860 conn2->ReceivedPingResponse(LOW_RTT); // Becomes writable and receiving
2939 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); 2861 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
2940 } 2862 }
2941 2863
2942 // Test that the ICE role is updated even on ports with inactive networks when 2864 // Test that the ICE role is updated even on ports with inactive networks when
2943 // doing continual gathering. These ports may still have connections that need 2865 // doing continual gathering. These ports may still have connections that need
2944 // a correct role, in case the network becomes active before the connection is 2866 // a correct role, in case the network becomes active before the connection is
2945 // destroyed. 2867 // destroyed.
2946 TEST_F(P2PTransportChannelPingTest, 2868 TEST_F(P2PTransportChannelPingTest,
2947 TestIceRoleUpdatedOnPortAfterSignalNetworkInactive) { 2869 TestIceRoleUpdatedOnPortAfterSignalNetworkInactive) {
2948 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2870 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2949 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); 2871 cricket::P2PTransportChannel ch(
2872 "test channel", cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
2950 // Starts with ICEROLE_CONTROLLING. 2873 // Starts with ICEROLE_CONTROLLING.
2951 PrepareChannel(&ch); 2874 PrepareChannel(&ch);
2952 IceConfig config = CreateIceConfig(1000, true); 2875 cricket::IceConfig config = CreateIceConfig(1000, true);
2953 ch.SetIceConfig(config); 2876 ch.SetIceConfig(config);
2954 ch.Connect(); 2877 ch.Connect();
2955 ch.MaybeStartGathering(); 2878 ch.MaybeStartGathering();
2956 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2879 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2957 2880
2958 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2881 cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2959 ASSERT_TRUE(conn != nullptr); 2882 ASSERT_TRUE(conn != nullptr);
2960 2883
2961 // Make the fake port signal that its network is inactive, then change the 2884 // Make the fake port signal that its network is inactive, then change the
2962 // ICE role and expect it to be updated. 2885 // ICE role and expect it to be updated.
2963 conn->port()->SignalNetworkInactive(conn->port()); 2886 conn->port()->SignalNetworkInactive(conn->port());
2964 ch.SetIceRole(ICEROLE_CONTROLLED); 2887 ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
2965 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); 2888 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, conn->port()->GetIceRole());
2966 } 2889 }
2967 2890
2968 // Test that the ICE role is updated even on ports with inactive networks. 2891 // Test that the ICE role is updated even on ports with inactive networks.
2969 // These ports may still have connections that need a correct role, for the 2892 // These ports may still have connections that need a correct role, for the
2970 // pings sent by those connections until they're replaced by newer-generation 2893 // pings sent by those connections until they're replaced by newer-generation
2971 // connections. 2894 // connections.
2972 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) { 2895 TEST_F(P2PTransportChannelPingTest, TestIceRoleUpdatedOnPortAfterIceRestart) {
2973 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2896 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2974 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); 2897 cricket::P2PTransportChannel ch(
2898 "test channel", cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
2975 // Starts with ICEROLE_CONTROLLING. 2899 // Starts with ICEROLE_CONTROLLING.
2976 PrepareChannel(&ch); 2900 PrepareChannel(&ch);
2977 ch.Connect(); 2901 ch.Connect();
2978 ch.MaybeStartGathering(); 2902 ch.MaybeStartGathering();
2979 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2903 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
2980 2904
2981 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2905 cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2982 ASSERT_TRUE(conn != nullptr); 2906 ASSERT_TRUE(conn != nullptr);
2983 2907
2984 // Do an ICE restart, change the role, and expect the old port to have its 2908 // Do an ICE restart, change the role, and expect the old port to have its
2985 // role updated. 2909 // role updated.
2986 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); 2910 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]);
2987 ch.MaybeStartGathering(); 2911 ch.MaybeStartGathering();
2988 ch.SetIceRole(ICEROLE_CONTROLLED); 2912 ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
2989 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); 2913 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, conn->port()->GetIceRole());
2990 } 2914 }
2991 2915
2992 // Test that after some amount of time without receiving data, the connection 2916 // Test that after some amount of time without receiving data, the connection
2993 // and port are destroyed. 2917 // and port are destroyed.
2994 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeout) { 2918 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeout) {
2995 rtc::ScopedFakeClock fake_clock; 2919 rtc::ScopedFakeClock fake_clock;
2996 2920
2997 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2921 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2998 P2PTransportChannel ch("test channel", ICE_CANDIDATE_COMPONENT_DEFAULT, &pa); 2922 cricket::P2PTransportChannel ch(
2923 "test channel", cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, &pa);
2999 PrepareChannel(&ch); 2924 PrepareChannel(&ch);
3000 // Only a controlled channel should expect its ports to be destroyed. 2925 // Only a controlled channel should expect its ports to be destroyed.
3001 ch.SetIceRole(ICEROLE_CONTROLLED); 2926 ch.SetIceRole(cricket::ICEROLE_CONTROLLED);
3002 ch.Connect(); 2927 ch.Connect();
3003 ch.MaybeStartGathering(); 2928 ch.MaybeStartGathering();
3004 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2929 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
3005 2930
3006 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2931 cricket::Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3007 ASSERT_TRUE(conn != nullptr); 2932 ASSERT_TRUE(conn != nullptr);
3008 2933
3009 // Simulate 2 minutes going by. This should be enough time for the port to 2934 // Simulate 2 minutes going by. This should be enough time for the port to
3010 // time out. 2935 // time out.
3011 for (int second = 0; second < 120; ++second) { 2936 for (int second = 0; second < 120; ++second) {
3012 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); 2937 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
3013 } 2938 }
3014 EXPECT_EQ(nullptr, GetConnectionTo(&ch, "1.1.1.1", 1)); 2939 EXPECT_EQ(nullptr, GetConnectionTo(&ch, "1.1.1.1", 1));
3015 EXPECT_EQ(nullptr, GetPort(&ch)); 2940 EXPECT_EQ(nullptr, GetPort(&ch));
3016 } 2941 }
3017 2942
3018 class P2PTransportChannelMostLikelyToWorkFirstTest 2943 class P2PTransportChannelMostLikelyToWorkFirstTest
3019 : public P2PTransportChannelPingTest { 2944 : public P2PTransportChannelPingTest {
3020 public: 2945 public:
3021 P2PTransportChannelMostLikelyToWorkFirstTest() 2946 P2PTransportChannelMostLikelyToWorkFirstTest()
3022 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) { 2947 : turn_server_(rtc::Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr) {
3023 network_manager_.AddInterface(kPublicAddrs[0]); 2948 network_manager_.AddInterface(kPublicAddrs[0]);
3024 allocator_.reset(new BasicPortAllocator( 2949 allocator_.reset(new cricket::BasicPortAllocator(
3025 &network_manager_, ServerAddresses(), rtc::SocketAddress(), 2950 &network_manager_, ServerAddresses(), rtc::SocketAddress(),
3026 rtc::SocketAddress(), rtc::SocketAddress())); 2951 rtc::SocketAddress(), rtc::SocketAddress()));
3027 allocator_->set_flags(allocator_->flags() | PORTALLOCATOR_DISABLE_STUN | 2952 allocator_->set_flags(allocator_->flags() |
3028 PORTALLOCATOR_DISABLE_TCP); 2953 cricket::PORTALLOCATOR_DISABLE_STUN |
3029 RelayServerConfig config(RELAY_TURN); 2954 cricket::PORTALLOCATOR_DISABLE_TCP);
2955 cricket::RelayServerConfig config(cricket::RELAY_TURN);
3030 config.credentials = kRelayCredentials; 2956 config.credentials = kRelayCredentials;
3031 config.ports.push_back(ProtocolAddress(kTurnUdpIntAddr, PROTO_UDP, false)); 2957 config.ports.push_back(
2958 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
3032 allocator_->AddTurnServer(config); 2959 allocator_->AddTurnServer(config);
3033 allocator_->set_step_delay(kMinimumStepDelay); 2960 allocator_->set_step_delay(kMinimumStepDelay);
3034 } 2961 }
3035 2962
3036 P2PTransportChannel& StartTransportChannel( 2963 cricket::P2PTransportChannel& StartTransportChannel(
3037 bool prioritize_most_likely_to_work, 2964 bool prioritize_most_likely_to_work,
3038 int stable_writable_connection_ping_interval) { 2965 int stable_writable_connection_ping_interval) {
3039 channel_.reset(new P2PTransportChannel("checks", 1, nullptr, allocator())); 2966 channel_.reset(
3040 IceConfig config = channel_->config(); 2967 new cricket::P2PTransportChannel("checks", 1, nullptr, allocator()));
2968 cricket::IceConfig config = channel_->config();
3041 config.prioritize_most_likely_candidate_pairs = 2969 config.prioritize_most_likely_candidate_pairs =
3042 prioritize_most_likely_to_work; 2970 prioritize_most_likely_to_work;
3043 config.stable_writable_connection_ping_interval = 2971 config.stable_writable_connection_ping_interval =
3044 stable_writable_connection_ping_interval; 2972 stable_writable_connection_ping_interval;
3045 channel_->SetIceConfig(config); 2973 channel_->SetIceConfig(config);
3046 PrepareChannel(channel_.get()); 2974 PrepareChannel(channel_.get());
3047 channel_->Connect(); 2975 channel_->Connect();
3048 channel_->MaybeStartGathering(); 2976 channel_->MaybeStartGathering();
3049 return *channel_.get(); 2977 return *channel_.get();
3050 } 2978 }
3051 2979
3052 BasicPortAllocator* allocator() { return allocator_.get(); } 2980 cricket::BasicPortAllocator* allocator() { return allocator_.get(); }
3053 TestTurnServer* turn_server() { return &turn_server_; } 2981 cricket::TestTurnServer* turn_server() { return &turn_server_; }
3054 2982
3055 // This verifies the next pingable connection has the expected candidates' 2983 // This verifies the next pingable connection has the expected candidates'
3056 // types and, for relay local candidate, the expected relay protocol and ping 2984 // types and, for relay local candidate, the expected relay protocol and ping
3057 // it. 2985 // it.
3058 void VerifyNextPingableConnection( 2986 void VerifyNextPingableConnection(
3059 const std::string& local_candidate_type, 2987 const std::string& local_candidate_type,
3060 const std::string& remote_candidate_type, 2988 const std::string& remote_candidate_type,
3061 const std::string& relay_protocol_type = UDP_PROTOCOL_NAME) { 2989 const std::string& relay_protocol_type = cricket::UDP_PROTOCOL_NAME) {
3062 Connection* conn = FindNextPingableConnectionAndPingIt(channel_.get()); 2990 cricket::Connection* conn =
2991 FindNextPingableConnectionAndPingIt(channel_.get());
3063 EXPECT_EQ(conn->local_candidate().type(), local_candidate_type); 2992 EXPECT_EQ(conn->local_candidate().type(), local_candidate_type);
3064 if (conn->local_candidate().type() == RELAY_PORT_TYPE) { 2993 if (conn->local_candidate().type() == cricket::RELAY_PORT_TYPE) {
3065 EXPECT_EQ(conn->local_candidate().relay_protocol(), relay_protocol_type); 2994 EXPECT_EQ(conn->local_candidate().relay_protocol(), relay_protocol_type);
3066 } 2995 }
3067 EXPECT_EQ(conn->remote_candidate().type(), remote_candidate_type); 2996 EXPECT_EQ(conn->remote_candidate().type(), remote_candidate_type);
3068 } 2997 }
3069 2998
2999 cricket::Candidate CreateRelayCandidate(const std::string& ip,
3000 int port,
3001 int priority,
3002 const std::string& ufrag = "") {
3003 cricket::Candidate c = CreateHostCandidate(ip, port, priority, ufrag);
3004 c.set_type(cricket::RELAY_PORT_TYPE);
3005 return c;
3006 }
3007
3070 private: 3008 private:
3071 std::unique_ptr<BasicPortAllocator> allocator_; 3009 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
3072 rtc::FakeNetworkManager network_manager_; 3010 rtc::FakeNetworkManager network_manager_;
3073 TestTurnServer turn_server_; 3011 cricket::TestTurnServer turn_server_;
3074 std::unique_ptr<P2PTransportChannel> channel_; 3012 std::unique_ptr<cricket::P2PTransportChannel> channel_;
3075 }; 3013 };
3076 3014
3077 // Test that Relay/Relay connections will be pinged first when no other 3015 // Test that Relay/Relay connections will be pinged first when no other
3078 // connections have been pinged yet, unless we need to ping a trigger check or 3016 // connections have been pinged yet, unless we need to ping a trigger check or
3079 // we have a best connection. 3017 // we have a best connection.
3080 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, 3018 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
3081 TestRelayRelayFirstWhenNothingPingedYet) { 3019 TestRelayRelayFirstWhenNothingPingedYet) {
3082 const int max_strong_interval = 100; 3020 const int max_strong_interval = 100;
3083 P2PTransportChannel& ch = StartTransportChannel(true, max_strong_interval); 3021 cricket::P2PTransportChannel& ch =
3022 StartTransportChannel(true, max_strong_interval);
3084 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); 3023 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000);
3085 EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE); 3024 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
3086 EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE); 3025 EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE);
3087 3026
3088 ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1)); 3027 ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1));
3089 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 3028 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
3090 3029
3091 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); 3030 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000);
3092 3031
3093 // Relay/Relay should be the first pingable connection. 3032 // Relay/Relay should be the first pingable connection.
3094 Connection* conn = FindNextPingableConnectionAndPingIt(&ch); 3033 cricket::Connection* conn = FindNextPingableConnectionAndPingIt(&ch);
3095 EXPECT_EQ(conn->local_candidate().type(), RELAY_PORT_TYPE); 3034 EXPECT_EQ(conn->local_candidate().type(), cricket::RELAY_PORT_TYPE);
3096 EXPECT_EQ(conn->remote_candidate().type(), RELAY_PORT_TYPE); 3035 EXPECT_EQ(conn->remote_candidate().type(), cricket::RELAY_PORT_TYPE);
3097 3036
3098 // Unless that we have a trigger check waiting to be pinged. 3037 // Unless that we have a trigger check waiting to be pinged.
3099 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3038 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3100 EXPECT_EQ(conn2->local_candidate().type(), LOCAL_PORT_TYPE); 3039 EXPECT_EQ(conn2->local_candidate().type(), cricket::LOCAL_PORT_TYPE);
3101 EXPECT_EQ(conn2->remote_candidate().type(), LOCAL_PORT_TYPE); 3040 EXPECT_EQ(conn2->remote_candidate().type(), cricket::LOCAL_PORT_TYPE);
3102 conn2->ReceivedPing(); 3041 conn2->ReceivedPing();
3103 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch)); 3042 EXPECT_EQ(conn2, FindNextPingableConnectionAndPingIt(&ch));
3104 3043
3105 // Make conn3 the best connection. 3044 // Make conn3 the best connection.
3106 Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3045 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3107 EXPECT_EQ(conn3->local_candidate().type(), LOCAL_PORT_TYPE); 3046 EXPECT_EQ(conn3->local_candidate().type(), cricket::LOCAL_PORT_TYPE);
3108 EXPECT_EQ(conn3->remote_candidate().type(), RELAY_PORT_TYPE); 3047 EXPECT_EQ(conn3->remote_candidate().type(), cricket::RELAY_PORT_TYPE);
3109 conn3->ReceivedPingResponse(LOW_RTT); 3048 conn3->ReceivedPingResponse(LOW_RTT);
3110 ASSERT_TRUE(conn3->writable()); 3049 ASSERT_TRUE(conn3->writable());
3111 conn3->ReceivedPing(); 3050 conn3->ReceivedPing();
3112 3051
3113 /* 3052 /*
3114 3053
3115 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix 3054 TODO(honghaiz): Re-enable this once we use fake clock for this test to fix
3116 the flakiness. The following test becomes flaky because we now ping the 3055 the flakiness. The following test becomes flaky because we now ping the
3117 connections with fast rates until every connection is pinged at least three 3056 connections with fast rates until every connection is pinged at least three
3118 times. The best connection may have been pinged before |max_strong_interval|, 3057 times. The best connection may have been pinged before |max_strong_interval|,
3119 so it may not be the next connection to be pinged as expected in the test. 3058 so it may not be the next connection to be pinged as expected in the test.
3120 3059
3121 // Verify that conn3 will be the "best connection" since it is readable and 3060 // Verify that conn3 will be the "best connection" since it is readable and
3122 // writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next 3061 // writable. After |MAX_CURRENT_STRONG_INTERVAL|, it should be the next
3123 // pingable connection. 3062 // pingable connection.
3124 EXPECT_TRUE_WAIT(conn3 == ch.best_connection(), 5000); 3063 EXPECT_TRUE_WAIT(conn3 == ch.best_connection(), 5000);
3125 WAIT(false, max_strong_interval + 100); 3064 WAIT(false, max_strong_interval + 100);
3126 conn3->ReceivedPingResponse(LOW_RTT); 3065 conn3->ReceivedPingResponse(LOW_RTT);
3127 ASSERT_TRUE(conn3->writable()); 3066 ASSERT_TRUE(conn3->writable());
3128 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch)); 3067 EXPECT_EQ(conn3, FindNextPingableConnectionAndPingIt(&ch));
3129 3068
3130 */ 3069 */
3131 } 3070 }
3132 3071
3133 // Test that Relay/Relay connections will be pinged first when everything has 3072 // Test that Relay/Relay connections will be pinged first when everything has
3134 // been pinged even if the Relay/Relay connection wasn't the first to be pinged 3073 // been pinged even if the Relay/Relay connection wasn't the first to be pinged
3135 // in the first round. 3074 // in the first round.
3136 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, 3075 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
3137 TestRelayRelayFirstWhenEverythingPinged) { 3076 TestRelayRelayFirstWhenEverythingPinged) {
3138 P2PTransportChannel& ch = StartTransportChannel(true, 100); 3077 cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100);
3139 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); 3078 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000);
3140 EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE); 3079 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
3141 EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE); 3080 EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE);
3142 3081
3143 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3082 ch.AddRemoteCandidate(CreateHostCandidate("1.1.1.1", 1, 1));
3144 EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000); 3083 EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000);
3145 3084
3146 // Initially, only have Local/Local and Local/Relay. 3085 // Initially, only have Local/Local and Local/Relay.
3147 VerifyNextPingableConnection(LOCAL_PORT_TYPE, LOCAL_PORT_TYPE); 3086 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
3148 VerifyNextPingableConnection(RELAY_PORT_TYPE, LOCAL_PORT_TYPE); 3087 cricket::LOCAL_PORT_TYPE);
3088 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
3089 cricket::LOCAL_PORT_TYPE);
3149 3090
3150 // Remote Relay candidate arrives. 3091 // Remote Relay candidate arrives.
3151 ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "2.2.2.2", 2, 2)); 3092 ch.AddRemoteCandidate(CreateRelayCandidate("2.2.2.2", 2, 2));
3152 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); 3093 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000);
3153 3094
3154 // Relay/Relay should be the first since it hasn't been pinged before. 3095 // Relay/Relay should be the first since it hasn't been pinged before.
3155 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE); 3096 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
3097 cricket::RELAY_PORT_TYPE);
3156 3098
3157 // Local/Relay is the final one. 3099 // Local/Relay is the final one.
3158 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 3100 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
3101 cricket::RELAY_PORT_TYPE);
3159 3102
3160 // Now, every connection has been pinged once. The next one should be 3103 // Now, every connection has been pinged once. The next one should be
3161 // Relay/Relay. 3104 // Relay/Relay.
3162 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE); 3105 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
3106 cricket::RELAY_PORT_TYPE);
3163 } 3107 }
3164 3108
3165 // Test that when we receive a new remote candidate, they will be tried first 3109 // Test that when we receive a new remote candidate, they will be tried first
3166 // before we re-ping Relay/Relay connections again. 3110 // before we re-ping Relay/Relay connections again.
3167 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, 3111 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest,
3168 TestNoStarvationOnNonRelayConnection) { 3112 TestNoStarvationOnNonRelayConnection) {
3169 P2PTransportChannel& ch = StartTransportChannel(true, 100); 3113 cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100);
3170 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000); 3114 EXPECT_TRUE_WAIT(ch.ports().size() == 2, 5000);
3171 EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE); 3115 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
3172 EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE); 3116 EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE);
3173 3117
3174 ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1)); 3118 ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1));
3175 EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000); 3119 EXPECT_TRUE_WAIT(ch.connections().size() == 2, 5000);
3176 3120
3177 // Initially, only have Relay/Relay and Local/Relay. Ping Relay/Relay first. 3121 // Initially, only have Relay/Relay and Local/Relay. Ping Relay/Relay first.
3178 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE); 3122 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
3123 cricket::RELAY_PORT_TYPE);
3179 3124
3180 // Next, ping Local/Relay. 3125 // Next, ping Local/Relay.
3181 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 3126 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
3127 cricket::RELAY_PORT_TYPE);
3182 3128
3183 // Remote Local candidate arrives. 3129 // Remote Local candidate arrives.
3184 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 3130 ch.AddRemoteCandidate(CreateHostCandidate("2.2.2.2", 2, 2));
3185 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000); 3131 EXPECT_TRUE_WAIT(ch.connections().size() == 4, 5000);
3186 3132
3187 // Local/Local should be the first since it hasn't been pinged before. 3133 // Local/Local should be the first since it hasn't been pinged before.
3188 VerifyNextPingableConnection(LOCAL_PORT_TYPE, LOCAL_PORT_TYPE); 3134 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
3135 cricket::LOCAL_PORT_TYPE);
3189 3136
3190 // Relay/Local is the final one. 3137 // Relay/Local is the final one.
3191 VerifyNextPingableConnection(RELAY_PORT_TYPE, LOCAL_PORT_TYPE); 3138 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
3139 cricket::LOCAL_PORT_TYPE);
3192 3140
3193 // Now, every connection has been pinged once. The next one should be 3141 // Now, every connection has been pinged once. The next one should be
3194 // Relay/Relay. 3142 // Relay/Relay.
3195 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE); 3143 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
3144 cricket::RELAY_PORT_TYPE);
3196 } 3145 }
3197 3146
3198 // Test the ping sequence is UDP Relay/Relay followed by TCP Relay/Relay, 3147 // Test the ping sequence is UDP Relay/Relay followed by TCP Relay/Relay,
3199 // followed by the rest. 3148 // followed by the rest.
3200 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestTcpTurn) { 3149 TEST_F(P2PTransportChannelMostLikelyToWorkFirstTest, TestTcpTurn) {
3201 // Add a Tcp Turn server. 3150 // Add a Tcp Turn server.
3202 turn_server()->AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); 3151 turn_server()->AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
3203 RelayServerConfig config(RELAY_TURN); 3152 cricket::RelayServerConfig config(cricket::RELAY_TURN);
3204 config.credentials = kRelayCredentials; 3153 config.credentials = kRelayCredentials;
3205 config.ports.push_back(ProtocolAddress(kTurnTcpIntAddr, PROTO_TCP, false)); 3154 config.ports.push_back(
3155 cricket::ProtocolAddress(kTurnTcpIntAddr, cricket::PROTO_TCP, false));
3206 allocator()->AddTurnServer(config); 3156 allocator()->AddTurnServer(config);
3207 3157
3208 P2PTransportChannel& ch = StartTransportChannel(true, 100); 3158 cricket::P2PTransportChannel& ch = StartTransportChannel(true, 100);
3209 EXPECT_TRUE_WAIT(ch.ports().size() == 3, 5000); 3159 EXPECT_TRUE_WAIT(ch.ports().size() == 3, 5000);
3210 EXPECT_EQ(ch.ports()[0]->Type(), LOCAL_PORT_TYPE); 3160 EXPECT_EQ(ch.ports()[0]->Type(), cricket::LOCAL_PORT_TYPE);
3211 EXPECT_EQ(ch.ports()[1]->Type(), RELAY_PORT_TYPE); 3161 EXPECT_EQ(ch.ports()[1]->Type(), cricket::RELAY_PORT_TYPE);
3212 EXPECT_EQ(ch.ports()[2]->Type(), RELAY_PORT_TYPE); 3162 EXPECT_EQ(ch.ports()[2]->Type(), cricket::RELAY_PORT_TYPE);
3213 3163
3214 // Remote Relay candidate arrives. 3164 // Remote Relay candidate arrives.
3215 ch.AddRemoteCandidate(CreateUdpCandidate(RELAY_PORT_TYPE, "1.1.1.1", 1, 1)); 3165 ch.AddRemoteCandidate(CreateRelayCandidate("1.1.1.1", 1, 1));
3216 EXPECT_TRUE_WAIT(ch.connections().size() == 3, 5000); 3166 EXPECT_TRUE_WAIT(ch.connections().size() == 3, 5000);
3217 3167
3218 // UDP Relay/Relay should be pinged first. 3168 // UDP Relay/Relay should be pinged first.
3219 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE); 3169 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
3170 cricket::RELAY_PORT_TYPE);
3220 3171
3221 // TCP Relay/Relay is the next. 3172 // TCP Relay/Relay is the next.
3222 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 3173 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
3223 TCP_PROTOCOL_NAME); 3174 cricket::RELAY_PORT_TYPE,
3175 cricket::TCP_PROTOCOL_NAME);
3224 3176
3225 // Finally, Local/Relay will be pinged. 3177 // Finally, Local/Relay will be pinged.
3226 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 3178 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
3179 cricket::RELAY_PORT_TYPE);
3227 } 3180 }
3228
3229 } // namespace cricket {
OLDNEW
« no previous file with comments | « webrtc/p2p/base/p2ptransportchannel.cc ('k') | webrtc/p2p/base/port.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698