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

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

Issue 1956453003: Relanding: Implement RTCConfiguration.iceCandidatePoolSize. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing uninitialized variable (noticed by msan) Created 4 years, 7 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
11 #include <algorithm>
11 #include <memory> 12 #include <memory>
12 13
14 #include "webrtc/p2p/base/fakeportallocator.h"
13 #include "webrtc/p2p/base/p2ptransportchannel.h" 15 #include "webrtc/p2p/base/p2ptransportchannel.h"
14 #include "webrtc/p2p/base/testrelayserver.h" 16 #include "webrtc/p2p/base/testrelayserver.h"
15 #include "webrtc/p2p/base/teststunserver.h" 17 #include "webrtc/p2p/base/teststunserver.h"
16 #include "webrtc/p2p/base/testturnserver.h" 18 #include "webrtc/p2p/base/testturnserver.h"
17 #include "webrtc/p2p/client/basicportallocator.h" 19 #include "webrtc/p2p/client/basicportallocator.h"
18 #include "webrtc/p2p/client/fakeportallocator.h"
19 #include "webrtc/base/dscp.h" 20 #include "webrtc/base/dscp.h"
20 #include "webrtc/base/fakenetwork.h" 21 #include "webrtc/base/fakenetwork.h"
21 #include "webrtc/base/firewallsocketserver.h" 22 #include "webrtc/base/firewallsocketserver.h"
22 #include "webrtc/base/gunit.h" 23 #include "webrtc/base/gunit.h"
23 #include "webrtc/base/helpers.h" 24 #include "webrtc/base/helpers.h"
24 #include "webrtc/base/logging.h" 25 #include "webrtc/base/logging.h"
25 #include "webrtc/base/natserver.h" 26 #include "webrtc/base/natserver.h"
26 #include "webrtc/base/natsocketfactory.h" 27 #include "webrtc/base/natsocketfactory.h"
27 #include "webrtc/base/physicalsocketserver.h" 28 #include "webrtc/base/physicalsocketserver.h"
28 #include "webrtc/base/proxyserver.h" 29 #include "webrtc/base/proxyserver.h"
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 std::string ice_ufrag_ep2_cd1_ch = kIceUfrag[1]; 281 std::string ice_ufrag_ep2_cd1_ch = kIceUfrag[1];
281 std::string ice_pwd_ep2_cd1_ch = kIcePwd[1]; 282 std::string ice_pwd_ep2_cd1_ch = kIcePwd[1];
282 ep1_.cd1_.ch_.reset(CreateChannel( 283 ep1_.cd1_.ch_.reset(CreateChannel(
283 0, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, 284 0, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT,
284 ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch, 285 ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch,
285 ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch)); 286 ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch));
286 ep2_.cd1_.ch_.reset(CreateChannel( 287 ep2_.cd1_.ch_.reset(CreateChannel(
287 1, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, 288 1, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT,
288 ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch, 289 ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch,
289 ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch)); 290 ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch));
291 ep1_.cd1_.ch_->MaybeStartGathering();
292 ep2_.cd1_.ch_->MaybeStartGathering();
290 if (num == 2) { 293 if (num == 2) {
291 std::string ice_ufrag_ep1_cd2_ch = kIceUfrag[2]; 294 std::string ice_ufrag_ep1_cd2_ch = kIceUfrag[2];
292 std::string ice_pwd_ep1_cd2_ch = kIcePwd[2]; 295 std::string ice_pwd_ep1_cd2_ch = kIcePwd[2];
293 std::string ice_ufrag_ep2_cd2_ch = kIceUfrag[3]; 296 std::string ice_ufrag_ep2_cd2_ch = kIceUfrag[3];
294 std::string ice_pwd_ep2_cd2_ch = kIcePwd[3]; 297 std::string ice_pwd_ep2_cd2_ch = kIcePwd[3];
295 ep1_.cd2_.ch_.reset(CreateChannel( 298 ep1_.cd2_.ch_.reset(CreateChannel(
296 0, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, 299 0, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT,
297 ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch, 300 ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch,
298 ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch)); 301 ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch));
299 ep2_.cd2_.ch_.reset(CreateChannel( 302 ep2_.cd2_.ch_.reset(CreateChannel(
300 1, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT, 303 1, cricket::ICE_CANDIDATE_COMPONENT_DEFAULT,
301 ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch, 304 ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch,
302 ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch)); 305 ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch));
306 ep1_.cd2_.ch_->MaybeStartGathering();
307 ep2_.cd2_.ch_->MaybeStartGathering();
303 } 308 }
304 } 309 }
305 cricket::P2PTransportChannel* CreateChannel( 310 cricket::P2PTransportChannel* CreateChannel(
306 int endpoint, 311 int endpoint,
307 int component, 312 int component,
308 const std::string& local_ice_ufrag, 313 const std::string& local_ice_ufrag,
309 const std::string& local_ice_pwd, 314 const std::string& local_ice_pwd,
310 const std::string& remote_ice_ufrag, 315 const std::string& remote_ice_ufrag,
311 const std::string& remote_ice_pwd) { 316 const std::string& remote_ice_pwd) {
312 cricket::P2PTransportChannel* channel = new cricket::P2PTransportChannel( 317 cricket::P2PTransportChannel* channel = new cricket::P2PTransportChannel(
313 "test content name", component, GetAllocator(endpoint)); 318 "test content name", component, GetAllocator(endpoint));
314 channel->SignalCandidateGathered.connect( 319 channel->SignalCandidateGathered.connect(
315 this, &P2PTransportChannelTestBase::OnCandidateGathered); 320 this, &P2PTransportChannelTestBase::OnCandidateGathered);
316 channel->SignalCandidatesRemoved.connect( 321 channel->SignalCandidatesRemoved.connect(
317 this, &P2PTransportChannelTestBase::OnCandidatesRemoved); 322 this, &P2PTransportChannelTestBase::OnCandidatesRemoved);
318 channel->SignalReadPacket.connect( 323 channel->SignalReadPacket.connect(
319 this, &P2PTransportChannelTestBase::OnReadPacket); 324 this, &P2PTransportChannelTestBase::OnReadPacket);
320 channel->SignalRoleConflict.connect( 325 channel->SignalRoleConflict.connect(
321 this, &P2PTransportChannelTestBase::OnRoleConflict); 326 this, &P2PTransportChannelTestBase::OnRoleConflict);
322 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); 327 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd);
323 if (clear_remote_candidates_ufrag_pwd_) { 328 if (clear_remote_candidates_ufrag_pwd_) {
324 // This only needs to be set if we're clearing them from the 329 // This only needs to be set if we're clearing them from the
325 // candidates. Some unit tests rely on this not being set. 330 // candidates. Some unit tests rely on this not being set.
326 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd); 331 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd);
327 } 332 }
328 channel->SetIceRole(GetEndpoint(endpoint)->ice_role()); 333 channel->SetIceRole(GetEndpoint(endpoint)->ice_role());
329 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker()); 334 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker());
330 channel->Connect(); 335 channel->Connect();
331 channel->MaybeStartGathering();
332 return channel; 336 return channel;
333 } 337 }
334 void DestroyChannels() { 338 void DestroyChannels() {
335 ep1_.cd1_.ch_.reset(); 339 ep1_.cd1_.ch_.reset();
336 ep2_.cd1_.ch_.reset(); 340 ep2_.cd1_.ch_.reset();
337 ep1_.cd2_.ch_.reset(); 341 ep1_.cd2_.ch_.reset();
338 ep2_.cd2_.ch_.reset(); 342 ep2_.cd2_.ch_.reset();
339 } 343 }
340 cricket::P2PTransportChannel* ep1_ch1() { return ep1_.cd1_.ch_.get(); } 344 cricket::P2PTransportChannel* ep1_ch1() { return ep1_.cd1_.ch_.get(); }
341 cricket::P2PTransportChannel* ep1_ch2() { return ep1_.cd2_.ch_.get(); } 345 cricket::P2PTransportChannel* ep1_ch2() { return ep1_.cd2_.ch_.get(); }
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 1000); 1544 1000);
1541 EXPECT_EQ(cricket::IceGatheringState::kIceGatheringGathering, 1545 EXPECT_EQ(cricket::IceGatheringState::kIceGatheringGathering,
1542 ep1_ch1()->gathering_state()); 1546 ep1_ch1()->gathering_state());
1543 // By now, ep2 should have completed gathering. 1547 // By now, ep2 should have completed gathering.
1544 EXPECT_EQ(cricket::IceGatheringState::kIceGatheringComplete, 1548 EXPECT_EQ(cricket::IceGatheringState::kIceGatheringComplete,
1545 ep2_ch1()->gathering_state()); 1549 ep2_ch1()->gathering_state());
1546 1550
1547 DestroyChannels(); 1551 DestroyChannels();
1548 } 1552 }
1549 1553
1554 // Test that a connection succeeds when the P2PTransportChannel uses a pooled
1555 // PortAllocatorSession that has not yet finished gathering candidates.
1556 TEST_F(P2PTransportChannelTest, TestUsingPooledSessionBeforeDoneGathering) {
1557 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1558 kDefaultPortAllocatorFlags);
1559 // First create a pooled session for each endpoint.
1560 auto& allocator_1 = GetEndpoint(0)->allocator_;
1561 auto& allocator_2 = GetEndpoint(1)->allocator_;
1562 int pool_size = 1;
1563 allocator_1->SetConfiguration(allocator_1->stun_servers(),
1564 allocator_1->turn_servers(), pool_size);
1565 allocator_2->SetConfiguration(allocator_2->stun_servers(),
1566 allocator_2->turn_servers(), pool_size);
1567 const cricket::PortAllocatorSession* pooled_session_1 =
1568 allocator_1->GetPooledSession();
1569 const cricket::PortAllocatorSession* pooled_session_2 =
1570 allocator_2->GetPooledSession();
1571 ASSERT_NE(nullptr, pooled_session_1);
1572 ASSERT_NE(nullptr, pooled_session_2);
1573 // Sanity check that pooled sessions haven't gathered anything yet.
1574 EXPECT_TRUE(pooled_session_1->ReadyPorts().empty());
1575 EXPECT_TRUE(pooled_session_1->ReadyCandidates().empty());
1576 EXPECT_TRUE(pooled_session_2->ReadyPorts().empty());
1577 EXPECT_TRUE(pooled_session_2->ReadyCandidates().empty());
1578 // Now let the endpoints connect and try exchanging some data.
1579 CreateChannels(1);
1580 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL &&
1581 ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1582 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1583 1000, 1000);
1584 TestSendRecv(1);
1585 // Make sure the P2PTransportChannels are actually using ports from the
1586 // pooled sessions.
1587 auto pooled_ports_1 = pooled_session_1->ReadyPorts();
1588 auto pooled_ports_2 = pooled_session_2->ReadyPorts();
1589 EXPECT_NE(pooled_ports_1.end(),
1590 std::find(pooled_ports_1.begin(), pooled_ports_1.end(),
1591 ep1_ch1()->best_connection()->port()));
1592 EXPECT_NE(pooled_ports_2.end(),
1593 std::find(pooled_ports_2.begin(), pooled_ports_2.end(),
1594 ep2_ch1()->best_connection()->port()));
1595 }
1596
1597 // Test that a connection succeeds when the P2PTransportChannel uses a pooled
1598 // PortAllocatorSession that already finished gathering candidates.
1599 TEST_F(P2PTransportChannelTest, TestUsingPooledSessionAfterDoneGathering) {
1600 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1601 kDefaultPortAllocatorFlags);
1602 // First create a pooled session for each endpoint.
1603 auto& allocator_1 = GetEndpoint(0)->allocator_;
1604 auto& allocator_2 = GetEndpoint(1)->allocator_;
1605 int pool_size = 1;
1606 allocator_1->SetConfiguration(allocator_1->stun_servers(),
1607 allocator_1->turn_servers(), pool_size);
1608 allocator_2->SetConfiguration(allocator_2->stun_servers(),
1609 allocator_2->turn_servers(), pool_size);
1610 const cricket::PortAllocatorSession* pooled_session_1 =
1611 allocator_1->GetPooledSession();
1612 const cricket::PortAllocatorSession* pooled_session_2 =
1613 allocator_2->GetPooledSession();
1614 ASSERT_NE(nullptr, pooled_session_1);
1615 ASSERT_NE(nullptr, pooled_session_2);
1616 // Wait for the pooled sessions to finish gathering before the
1617 // P2PTransportChannels try to use them.
1618 EXPECT_TRUE_WAIT(pooled_session_1->CandidatesAllocationDone() &&
1619 pooled_session_2->CandidatesAllocationDone(),
1620 kDefaultTimeout);
1621 // Now let the endpoints connect and try exchanging some data.
1622 CreateChannels(1);
1623 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL &&
1624 ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1625 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1626 1000, 1000);
1627 TestSendRecv(1);
1628 // Make sure the P2PTransportChannels are actually using ports from the
1629 // pooled sessions.
1630 auto pooled_ports_1 = pooled_session_1->ReadyPorts();
1631 auto pooled_ports_2 = pooled_session_2->ReadyPorts();
1632 EXPECT_NE(pooled_ports_1.end(),
1633 std::find(pooled_ports_1.begin(), pooled_ports_1.end(),
1634 ep1_ch1()->best_connection()->port()));
1635 EXPECT_NE(pooled_ports_2.end(),
1636 std::find(pooled_ports_2.begin(), pooled_ports_2.end(),
1637 ep2_ch1()->best_connection()->port()));
1638 }
1639
1550 // Test what happens when we have 2 users behind the same NAT. This can lead 1640 // Test what happens when we have 2 users behind the same NAT. This can lead
1551 // to interesting behavior because the STUN server will only give out the 1641 // to interesting behavior because the STUN server will only give out the
1552 // address of the outermost NAT. 1642 // address of the outermost NAT.
1553 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase { 1643 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase {
1554 protected: 1644 protected:
1555 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) { 1645 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) {
1556 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC); 1646 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC);
1557 rtc::NATSocketServer::Translator* outer_nat = 1647 rtc::NATSocketServer::Translator* outer_nat =
1558 nat()->AddTranslator(kPublicAddrs[0], kNatAddrs[0], 1648 nat()->AddTranslator(kPublicAddrs[0], kNatAddrs[0],
1559 static_cast<rtc::NATType>(nat_type - NAT_FULL_CONE)); 1649 static_cast<rtc::NATType>(nat_type - NAT_FULL_CONE));
(...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after
2804 2894
2805 // TCP Relay/Relay is the next. 2895 // TCP Relay/Relay is the next.
2806 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, 2896 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE,
2807 cricket::RELAY_PORT_TYPE, 2897 cricket::RELAY_PORT_TYPE,
2808 cricket::TCP_PROTOCOL_NAME); 2898 cricket::TCP_PROTOCOL_NAME);
2809 2899
2810 // Finally, Local/Relay will be pinged. 2900 // Finally, Local/Relay will be pinged.
2811 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, 2901 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE,
2812 cricket::RELAY_PORT_TYPE); 2902 cricket::RELAY_PORT_TYPE);
2813 } 2903 }
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