OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
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 Loading... | |
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(); | |
Taylor Brandstetter
2016/05/05 19:56:23
This needed to be moved because when using a poole
pthatcher1
2016/05/05 21:51:25
Should we change that by having MaybeStartGatherin
Taylor Brandstetter
2016/05/06 03:53:34
No; the TransportController already posts candidat
| |
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 Loading... | |
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 allocator_1->SetConfiguration(allocator_1->stun_servers(), | |
1563 allocator_1->turn_servers(), 1); | |
1564 allocator_2->SetConfiguration(allocator_2->stun_servers(), | |
1565 allocator_2->turn_servers(), 1); | |
1566 const cricket::PortAllocatorSession* pooled_session_1 = | |
1567 allocator_1->PeekPooledSession(); | |
1568 const cricket::PortAllocatorSession* pooled_session_2 = | |
1569 allocator_2->PeekPooledSession(); | |
1570 ASSERT_NE(nullptr, pooled_session_1); | |
1571 ASSERT_NE(nullptr, pooled_session_2); | |
1572 // Sanity check that pooled sessions haven't gathered anything yet. | |
1573 EXPECT_TRUE(pooled_session_1->ReadyPorts().empty()); | |
1574 EXPECT_TRUE(pooled_session_1->ReadyCandidates().empty()); | |
1575 EXPECT_TRUE(pooled_session_2->ReadyPorts().empty()); | |
1576 EXPECT_TRUE(pooled_session_2->ReadyCandidates().empty()); | |
1577 // Now let the endpoints connect and try exchanging some data. | |
1578 CreateChannels(1); | |
1579 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && | |
1580 ep1_ch1()->receiving() && ep1_ch1()->writable() && | |
1581 ep2_ch1()->receiving() && ep2_ch1()->writable(), | |
1582 1000, 1000); | |
1583 TestSendRecv(1); | |
1584 // Make sure the P2PTransportChannels are actually using ports from the | |
1585 // pooled sessions. | |
1586 auto pooled_ports_1 = pooled_session_1->ReadyPorts(); | |
1587 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); | |
1588 EXPECT_NE(pooled_ports_1.end(), | |
1589 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), | |
1590 ep1_ch1()->best_connection()->port())); | |
1591 EXPECT_NE(pooled_ports_2.end(), | |
1592 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), | |
1593 ep2_ch1()->best_connection()->port())); | |
1594 } | |
1595 | |
1596 // Test that a connection succeeds when the P2PTransportChannel uses a pooled | |
1597 // PortAllocatorSession that already finished gathering candidates. | |
1598 TEST_F(P2PTransportChannelTest, TestUsingPooledSessionAfterDoneGathering) { | |
1599 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | |
1600 kDefaultPortAllocatorFlags); | |
1601 // First create a pooled session for each endpoint. | |
1602 auto& allocator_1 = GetEndpoint(0)->allocator_; | |
1603 auto& allocator_2 = GetEndpoint(1)->allocator_; | |
1604 allocator_1->SetConfiguration(allocator_1->stun_servers(), | |
1605 allocator_1->turn_servers(), 1); | |
1606 allocator_2->SetConfiguration(allocator_2->stun_servers(), | |
1607 allocator_2->turn_servers(), 1); | |
pthatcher1
2016/05/05 21:51:25
Can you give this value of 1 a name to make it mor
Taylor Brandstetter
2016/05/06 03:53:34
Done.
| |
1608 const cricket::PortAllocatorSession* pooled_session_1 = | |
1609 allocator_1->PeekPooledSession(); | |
1610 const cricket::PortAllocatorSession* pooled_session_2 = | |
1611 allocator_2->PeekPooledSession(); | |
1612 ASSERT_NE(nullptr, pooled_session_1); | |
1613 ASSERT_NE(nullptr, pooled_session_2); | |
1614 // Wait for the pooled sessions to finish gathering before the | |
1615 // P2PTransportChannels try to use them. | |
1616 EXPECT_TRUE_WAIT(pooled_session_1->CandidatesAllocationDone() && | |
1617 pooled_session_2->CandidatesAllocationDone(), | |
1618 kDefaultTimeout); | |
1619 // Now let the endpoints connect and try exchanging some data. | |
1620 CreateChannels(1); | |
1621 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && | |
1622 ep1_ch1()->receiving() && ep1_ch1()->writable() && | |
1623 ep2_ch1()->receiving() && ep2_ch1()->writable(), | |
1624 1000, 1000); | |
1625 TestSendRecv(1); | |
1626 // Make sure the P2PTransportChannels are actually using ports from the | |
1627 // pooled sessions. | |
1628 auto pooled_ports_1 = pooled_session_1->ReadyPorts(); | |
1629 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); | |
1630 EXPECT_NE(pooled_ports_1.end(), | |
1631 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), | |
1632 ep1_ch1()->best_connection()->port())); | |
1633 EXPECT_NE(pooled_ports_2.end(), | |
1634 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), | |
1635 ep2_ch1()->best_connection()->port())); | |
1636 } | |
1637 | |
1550 // Test what happens when we have 2 users behind the same NAT. This can lead | 1638 // 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 | 1639 // to interesting behavior because the STUN server will only give out the |
1552 // address of the outermost NAT. | 1640 // address of the outermost NAT. |
1553 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase { | 1641 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase { |
1554 protected: | 1642 protected: |
1555 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) { | 1643 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) { |
1556 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC); | 1644 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC); |
1557 rtc::NATSocketServer::Translator* outer_nat = | 1645 rtc::NATSocketServer::Translator* outer_nat = |
1558 nat()->AddTranslator(kPublicAddrs[0], kNatAddrs[0], | 1646 nat()->AddTranslator(kPublicAddrs[0], kNatAddrs[0], |
1559 static_cast<rtc::NATType>(nat_type - NAT_FULL_CONE)); | 1647 static_cast<rtc::NATType>(nat_type - NAT_FULL_CONE)); |
(...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2797 | 2885 |
2798 // TCP Relay/Relay is the next. | 2886 // TCP Relay/Relay is the next. |
2799 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 2887 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
2800 cricket::RELAY_PORT_TYPE, | 2888 cricket::RELAY_PORT_TYPE, |
2801 cricket::TCP_PROTOCOL_NAME); | 2889 cricket::TCP_PROTOCOL_NAME); |
2802 | 2890 |
2803 // Finally, Local/Relay will be pinged. | 2891 // Finally, Local/Relay will be pinged. |
2804 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, | 2892 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, |
2805 cricket::RELAY_PORT_TYPE); | 2893 cricket::RELAY_PORT_TYPE); |
2806 } | 2894 } |
OLD | NEW |