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

Side by Side Diff: webrtc/p2p/client/portallocator_unittest.cc

Issue 1288843003: Revert "Generate localhost candidate when no STUN/TURN and portallocator has the right flag spefied… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Created 5 years, 4 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/client/fakeportallocator.h ('k') | no next file » | 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 } 236 }
237 } 237 }
238 238
239 // This function starts the port/address gathering and check the existence of 239 // This function starts the port/address gathering and check the existence of
240 // candidates as specified. When |expect_stun_candidate| is true, 240 // candidates as specified. When |expect_stun_candidate| is true,
241 // |stun_candidate_addr| carries the expected reflective address, which is 241 // |stun_candidate_addr| carries the expected reflective address, which is
242 // also the related address for TURN candidate if it is expected. Otherwise, 242 // also the related address for TURN candidate if it is expected. Otherwise,
243 // it should be ignore. 243 // it should be ignore.
244 void CheckDisableAdapterEnumeration( 244 void CheckDisableAdapterEnumeration(
245 uint32 total_ports, 245 uint32 total_ports,
246 const rtc::IPAddress& host_candidate_addr,
247 const rtc::IPAddress& stun_candidate_addr, 246 const rtc::IPAddress& stun_candidate_addr,
248 const rtc::IPAddress& relay_candidate_udp_transport_addr, 247 const rtc::IPAddress& relay_candidate_udp_transport_addr,
249 const rtc::IPAddress& relay_candidate_tcp_transport_addr) { 248 const rtc::IPAddress& relay_candidate_tcp_transport_addr) {
250 if (!session_) { 249 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
251 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 250 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION |
252 }
253 session_->set_flags(session_->flags() |
254 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION |
255 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 251 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
256 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 252 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
257 allocator().set_allow_tcp_listen(false); 253 allocator().set_allow_tcp_listen(false);
258 session_->StartGettingPorts(); 254 session_->StartGettingPorts();
259 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 255 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
260 256
261 uint32 total_candidates = 0; 257 uint32 total_candidates = 0;
262 if (!host_candidate_addr.IsNil()) { 258 if (!stun_candidate_addr.IsNil()) {
263 EXPECT_PRED5(CheckCandidate, candidates_[total_candidates],
264 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp",
265 rtc::SocketAddress(host_candidate_addr, 0));
266 ++total_candidates; 259 ++total_candidates;
267 } 260 EXPECT_PRED5(CheckCandidate, candidates_[0],
268 if (!stun_candidate_addr.IsNil()) {
269 EXPECT_PRED5(CheckCandidate, candidates_[total_candidates],
270 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", 261 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
271 rtc::SocketAddress(stun_candidate_addr, 0)); 262 rtc::SocketAddress(stun_candidate_addr, 0));
272 EXPECT_EQ(rtc::EmptySocketAddressWithFamily( 263 EXPECT_EQ(
273 candidates_[total_candidates].address().family()), 264 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()),
274 candidates_[total_candidates].related_address()); 265 candidates_[0].related_address());
275 ++total_candidates;
276 } 266 }
277 if (!relay_candidate_udp_transport_addr.IsNil()) { 267 if (!relay_candidate_udp_transport_addr.IsNil()) {
278 EXPECT_PRED5(CheckCandidate, candidates_[total_candidates], 268 ++total_candidates;
269 EXPECT_PRED5(CheckCandidate, candidates_[1],
279 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", 270 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
280 rtc::SocketAddress(relay_candidate_udp_transport_addr, 0)); 271 rtc::SocketAddress(relay_candidate_udp_transport_addr, 0));
281 EXPECT_EQ(stun_candidate_addr, 272 EXPECT_EQ(stun_candidate_addr, candidates_[1].related_address().ipaddr());
282 candidates_[total_candidates].related_address().ipaddr());
283 ++total_candidates;
284 } 273 }
285 if (!relay_candidate_tcp_transport_addr.IsNil()) { 274 if (!relay_candidate_tcp_transport_addr.IsNil()) {
286 EXPECT_PRED5(CheckCandidate, candidates_[total_candidates], 275 ++total_candidates;
276 EXPECT_PRED5(CheckCandidate, candidates_[2],
287 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", 277 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
288 rtc::SocketAddress(relay_candidate_tcp_transport_addr, 0)); 278 rtc::SocketAddress(relay_candidate_tcp_transport_addr, 0));
289 EXPECT_EQ(stun_candidate_addr, 279 EXPECT_EQ(stun_candidate_addr, candidates_[2].related_address().ipaddr());
290 candidates_[total_candidates].related_address().ipaddr());
291 ++total_candidates;
292 } 280 }
293 281
294 EXPECT_EQ(total_candidates, candidates_.size()); 282 EXPECT_EQ(total_candidates, candidates_.size());
295 EXPECT_EQ(total_ports, ports_.size()); 283 EXPECT_EQ(total_ports, ports_.size());
296 } 284 }
297 285
298 protected: 286 protected:
299 cricket::BasicPortAllocator& allocator() { 287 cricket::BasicPortAllocator& allocator() {
300 return *allocator_; 288 return *allocator_;
301 } 289 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 502
515 // Test that we should only get STUN and TURN candidates when adapter 503 // Test that we should only get STUN and TURN candidates when adapter
516 // enumeration is disabled. 504 // enumeration is disabled.
517 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationBehindNat) { 505 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationBehindNat) {
518 AddInterface(kClientAddr); 506 AddInterface(kClientAddr);
519 // GTURN is not configured here. 507 // GTURN is not configured here.
520 ResetWithStunServerAndNat(kStunAddr); 508 ResetWithStunServerAndNat(kStunAddr);
521 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 509 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
522 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, and both STUN and 510 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, and both STUN and
523 // TURN/UDP candidates. 511 // TURN/UDP candidates.
524 CheckDisableAdapterEnumeration(3U, rtc::IPAddress(), kNatUdpAddr.ipaddr(), 512 CheckDisableAdapterEnumeration(3U, kNatUdpAddr.ipaddr(),
525 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress()); 513 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress());
526 } 514 }
527 515
528 // Test that even with multiple interfaces, the result should still be one STUN 516 // Test that even with multiple interfaces, the result should still be one STUN
529 // and one TURN candidate since we bind to any address (i.e. all 0s). 517 // and one TURN candidate since we bind to any address (i.e. all 0s).
530 TEST_F(PortAllocatorTest, 518 TEST_F(PortAllocatorTest,
531 TestDisableAdapterEnumerationBehindNatMultipleInterfaces) { 519 TestDisableAdapterEnumerationBehindNatMultipleInterfaces) {
532 AddInterface(kPrivateAddr); 520 AddInterface(kPrivateAddr);
533 AddInterface(kPrivateAddr2); 521 AddInterface(kPrivateAddr2);
534 ResetWithStunServerAndNat(kStunAddr); 522 ResetWithStunServerAndNat(kStunAddr);
535 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 523 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
536 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, and both STUN and 524 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, and both STUN and
537 // TURN/UDP candidates. 525 // TURN/UDP candidates.
538 CheckDisableAdapterEnumeration(3U, rtc::IPAddress(), kNatUdpAddr.ipaddr(), 526 CheckDisableAdapterEnumeration(3U, kNatUdpAddr.ipaddr(),
539 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress()); 527 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress());
540 } 528 }
541 529
542 // Test that we should get STUN, TURN/UDP and TURN/TCP candidates when a 530 // Test that we should get STUN, TURN/UDP and TURN/TCP candidates when a
543 // TURN/TCP server is specified. 531 // TURN/TCP server is specified.
544 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationBehindNatWithTcp) { 532 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationBehindNatWithTcp) {
545 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); 533 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
546 AddInterface(kClientAddr); 534 AddInterface(kClientAddr);
547 // GTURN is not configured here. 535 // GTURN is not configured here.
548 ResetWithStunServerAndNat(kStunAddr); 536 ResetWithStunServerAndNat(kStunAddr);
549 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); 537 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
550 // Expect to see 4 ports - STUN, TURN/UDP, TURN/TCP and TCP port. STUN, 538 // Expect to see 4 ports - STUN, TURN/UDP, TURN/TCP and TCP port. STUN,
551 // TURN/UDP, and TURN/TCP candidates. 539 // TURN/UDP, and TURN/TCP candidates.
552 CheckDisableAdapterEnumeration(4U, rtc::IPAddress(), kNatUdpAddr.ipaddr(), 540 CheckDisableAdapterEnumeration(4U, kNatUdpAddr.ipaddr(),
553 kTurnUdpExtAddr.ipaddr(), 541 kTurnUdpExtAddr.ipaddr(),
554 kTurnUdpExtAddr.ipaddr()); 542 kTurnUdpExtAddr.ipaddr());
555 } 543 }
556 544
557 // Test that we should only get STUN and TURN candidates when adapter 545 // Test that we should only get STUN and TURN candidates when adapter
558 // enumeration is disabled. Since the endpoint is not behind NAT, the srflx 546 // enumeration is disabled. Since the endpoint is not behind NAT, the srflx
559 // address should be the public client interface. 547 // address should be the public client interface.
560 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNat) { 548 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNat) {
561 AddInterfaceAsDefaultRoute(kClientAddr); 549 AddInterfaceAsDefaultRoute(kClientAddr);
562 ResetWithStunServerNoNat(kStunAddr); 550 ResetWithStunServerNoNat(kStunAddr);
563 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 551 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
564 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, but only both STUN and 552 // Expect to see 3 ports: STUN, TURN/UDP and TCP ports, but only both STUN and
565 // TURN candidates. The STUN candidate should have kClientAddr as srflx 553 // TURN candidates. The STUN candidate should have kClientAddr as srflx
566 // address, and TURN candidate with kClientAddr as the related address. 554 // address, and TURN candidate with kClientAddr as the related address.
567 CheckDisableAdapterEnumeration(3U, rtc::IPAddress(), kClientAddr.ipaddr(), 555 CheckDisableAdapterEnumeration(3U, kClientAddr.ipaddr(),
568 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress()); 556 kTurnUdpExtAddr.ipaddr(), rtc::IPAddress());
569 } 557 }
570 558
571 // Test that when adapter enumeration is disabled, for endpoints without 559 // Test that when adapter enumeration is disabled, for endpoints without
572 // STUN/TURN specified, no candidate is generated. 560 // STUN/TURN specified, no candidate is generated.
573 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNatOrServers) { 561 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNatOrServers) {
574 AddInterfaceAsDefaultRoute(kClientAddr); 562 AddInterfaceAsDefaultRoute(kClientAddr);
575 ResetWithNoServersOrNat(); 563 ResetWithNoServersOrNat();
576 // Expect to see 2 ports: STUN and TCP ports, but no candidate. 564 // Expect to see 2 ports: STUN and TCP ports, but no candidate.
577 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), rtc::IPAddress(), 565 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), rtc::IPAddress(),
578 rtc::IPAddress(), rtc::IPAddress());
579 }
580
581 // Test that when adapter enumeration is disabled, with
582 // PORTALLOCATOR_ENABLE_LOCALHOST_CANDIDATE specified, for endpoints not behind
583 // a NAT, there are a localhost candidate in addition to a STUN candidate.
584 TEST_F(PortAllocatorTest,
585 TestDisableAdapterEnumerationWithoutNatLocalhostCandidateRequested) {
586 AddInterfaceAsDefaultRoute(kClientAddr);
587 ResetWithStunServerNoNat(kStunAddr);
588 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
589 session_->set_flags(cricket::PORTALLOCATOR_ENABLE_LOCALHOST_CANDIDATE);
590 // Expect to see 2 ports: STUN and TCP ports, localhost candidate and STUN
591 // candidate.
592 CheckDisableAdapterEnumeration(2U, rtc::GetLoopbackIP(AF_INET),
593 kClientAddr.ipaddr(), rtc::IPAddress(),
594 rtc::IPAddress()); 566 rtc::IPAddress());
595 } 567 }
596 568
597 // Disable for asan, see 569 // Disable for asan, see
598 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details. 570 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details.
599 #if !defined(ADDRESS_SANITIZER) 571 #if !defined(ADDRESS_SANITIZER)
600 572
601 // Test that we can get OnCandidatesAllocationDone callback when all the ports 573 // Test that we can get OnCandidatesAllocationDone callback when all the ports
602 // are disabled. 574 // are disabled.
603 TEST_F(PortAllocatorTest, TestDisableAllPorts) { 575 TEST_F(PortAllocatorTest, TestDisableAllPorts) {
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 session_->StartGettingPorts(); 1130 session_->StartGettingPorts();
1159 ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); 1131 ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout);
1160 EXPECT_EQ(1U, candidates_.size()); 1132 EXPECT_EQ(1U, candidates_.size());
1161 EXPECT_PRED5(CheckCandidate, candidates_[0], 1133 EXPECT_PRED5(CheckCandidate, candidates_[0],
1162 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 1134 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
1163 // STUN timeout is 9sec. We need to wait to get candidate done signal. 1135 // STUN timeout is 9sec. We need to wait to get candidate done signal.
1164 EXPECT_TRUE_WAIT(candidate_allocation_done_, 10000); 1136 EXPECT_TRUE_WAIT(candidate_allocation_done_, 10000);
1165 EXPECT_EQ(1U, candidates_.size()); 1137 EXPECT_EQ(1U, candidates_.size());
1166 } 1138 }
1167 1139
1168 // Test that when the NetworkManager doesn't have permission to enumerate
1169 // adapters, the PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified
1170 // automatically.
1171 TEST_F(PortAllocatorTest, TestNetworkPermissionBlocked) {
1172 AddInterface(kClientAddr);
1173 network_manager_.set_enumeration_permission(
1174 rtc::NetworkManager::kEnumerationDisallowed);
1175 allocator().set_flags(allocator().flags() |
1176 cricket::PORTALLOCATOR_DISABLE_RELAY |
1177 cricket::PORTALLOCATOR_DISABLE_TCP |
1178 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1179 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1180 EXPECT_EQ(
1181 allocator_->flags() & cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION,
1182 0U);
1183 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1184 EXPECT_EQ(
1185 session_->flags() & cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION,
1186 0U);
1187 session_->StartGettingPorts();
1188 EXPECT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout);
1189 EXPECT_EQ(0U, candidates_.size());
1190 EXPECT_TRUE((session_->flags() &
1191 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) != 0);
1192 }
1193
1194 // This test verifies allocator can use IPv6 addresses along with IPv4. 1140 // This test verifies allocator can use IPv6 addresses along with IPv4.
1195 TEST_F(PortAllocatorTest, TestEnableIPv6Addresses) { 1141 TEST_F(PortAllocatorTest, TestEnableIPv6Addresses) {
1196 allocator().set_flags(allocator().flags() | 1142 allocator().set_flags(allocator().flags() |
1197 cricket::PORTALLOCATOR_DISABLE_RELAY | 1143 cricket::PORTALLOCATOR_DISABLE_RELAY |
1198 cricket::PORTALLOCATOR_ENABLE_IPV6 | 1144 cricket::PORTALLOCATOR_ENABLE_IPV6 |
1199 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 1145 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1200 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1146 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1201 AddInterface(kClientIPv6Addr); 1147 AddInterface(kClientIPv6Addr);
1202 AddInterface(kClientAddr); 1148 AddInterface(kClientAddr);
1203 allocator_->set_step_delay(cricket::kMinimumStepDelay); 1149 allocator_->set_step_delay(cricket::kMinimumStepDelay);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1329 AllocationSequenceForTest alloc_sequence( 1275 AllocationSequenceForTest alloc_sequence(
1330 static_cast<cricket::BasicPortAllocatorSession*>(session_.get()), 1276 static_cast<cricket::BasicPortAllocatorSession*>(session_.get()),
1331 &network1, &config, flag); 1277 &network1, &config, flag);
1332 // This simply tests it will not crash if udp_socket_ in the 1278 // This simply tests it will not crash if udp_socket_ in the
1333 // AllocationSequence is null, which is chosen in the constructor. 1279 // AllocationSequence is null, which is chosen in the constructor.
1334 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); 1280 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1335 relay_server.ports.push_back( 1281 relay_server.ports.push_back(
1336 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); 1282 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1337 alloc_sequence.CreateTurnPort(relay_server); 1283 alloc_sequence.CreateTurnPort(relay_server);
1338 } 1284 }
OLDNEW
« no previous file with comments | « webrtc/p2p/client/fakeportallocator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698