OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 } | 285 } |
286 | 286 |
287 rtc::FakeNetworkManager network_manager_; | 287 rtc::FakeNetworkManager network_manager_; |
288 std::unique_ptr<BasicPortAllocator> allocator_; | 288 std::unique_ptr<BasicPortAllocator> allocator_; |
289 ChannelData cd1_; | 289 ChannelData cd1_; |
290 ChannelData cd2_; | 290 ChannelData cd2_; |
291 IceRole role_; | 291 IceRole role_; |
292 uint64_t tiebreaker_; | 292 uint64_t tiebreaker_; |
293 bool role_conflict_; | 293 bool role_conflict_; |
294 bool save_candidates_; | 294 bool save_candidates_; |
295 std::vector<CandidatesData*> saved_candidates_; | 295 std::vector<std::unique_ptr<CandidatesData>> saved_candidates_; |
296 bool ready_to_send_ = false; | 296 bool ready_to_send_ = false; |
297 }; | 297 }; |
298 | 298 |
299 ChannelData* GetChannelData(TransportChannel* channel) { | 299 ChannelData* GetChannelData(TransportChannel* channel) { |
300 if (ep1_.HasChannel(channel)) | 300 if (ep1_.HasChannel(channel)) |
301 return ep1_.GetChannelData(channel); | 301 return ep1_.GetChannelData(channel); |
302 else | 302 else |
303 return ep2_.GetChannelData(channel); | 303 return ep2_.GetChannelData(channel); |
304 } | 304 } |
305 | 305 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 ep1_.cd1_.ch_.reset(); | 362 ep1_.cd1_.ch_.reset(); |
363 ep2_.cd1_.ch_.reset(); | 363 ep2_.cd1_.ch_.reset(); |
364 ep1_.cd2_.ch_.reset(); | 364 ep1_.cd2_.ch_.reset(); |
365 ep2_.cd2_.ch_.reset(); | 365 ep2_.cd2_.ch_.reset(); |
366 } | 366 } |
367 P2PTransportChannel* ep1_ch1() { return ep1_.cd1_.ch_.get(); } | 367 P2PTransportChannel* ep1_ch1() { return ep1_.cd1_.ch_.get(); } |
368 P2PTransportChannel* ep1_ch2() { return ep1_.cd2_.ch_.get(); } | 368 P2PTransportChannel* ep1_ch2() { return ep1_.cd2_.ch_.get(); } |
369 P2PTransportChannel* ep2_ch1() { return ep2_.cd1_.ch_.get(); } | 369 P2PTransportChannel* ep2_ch1() { return ep2_.cd1_.ch_.get(); } |
370 P2PTransportChannel* ep2_ch2() { return ep2_.cd2_.ch_.get(); } | 370 P2PTransportChannel* ep2_ch2() { return ep2_.cd2_.ch_.get(); } |
371 | 371 |
| 372 TestTurnServer* test_turn_server() { return &turn_server_; } |
| 373 |
372 // Common results. | 374 // Common results. |
373 static const Result kLocalUdpToLocalUdp; | 375 static const Result kLocalUdpToLocalUdp; |
374 static const Result kLocalUdpToStunUdp; | 376 static const Result kLocalUdpToStunUdp; |
375 static const Result kLocalUdpToPrflxUdp; | 377 static const Result kLocalUdpToPrflxUdp; |
376 static const Result kPrflxUdpToLocalUdp; | 378 static const Result kPrflxUdpToLocalUdp; |
377 static const Result kStunUdpToLocalUdp; | 379 static const Result kStunUdpToLocalUdp; |
378 static const Result kStunUdpToStunUdp; | 380 static const Result kStunUdpToStunUdp; |
379 static const Result kPrflxUdpToStunUdp; | 381 static const Result kPrflxUdpToStunUdp; |
380 static const Result kLocalUdpToRelayUdp; | 382 static const Result kLocalUdpToRelayUdp; |
381 static const Result kPrflxUdpToRelayUdp; | 383 static const Result kPrflxUdpToRelayUdp; |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 void OnReadyToSend(TransportChannel* ch) { | 670 void OnReadyToSend(TransportChannel* ch) { |
669 GetEndpoint(ch)->ready_to_send_ = true; | 671 GetEndpoint(ch)->ready_to_send_ = true; |
670 } | 672 } |
671 | 673 |
672 // We pass the candidates directly to the other side. | 674 // We pass the candidates directly to the other side. |
673 void OnCandidateGathered(TransportChannelImpl* ch, const Candidate& c) { | 675 void OnCandidateGathered(TransportChannelImpl* ch, const Candidate& c) { |
674 if (force_relay_ && c.type() != RELAY_PORT_TYPE) | 676 if (force_relay_ && c.type() != RELAY_PORT_TYPE) |
675 return; | 677 return; |
676 | 678 |
677 if (GetEndpoint(ch)->save_candidates_) { | 679 if (GetEndpoint(ch)->save_candidates_) { |
678 GetEndpoint(ch)->saved_candidates_.push_back(new CandidatesData(ch, c)); | 680 GetEndpoint(ch)->saved_candidates_.push_back( |
| 681 std::unique_ptr<CandidatesData>(new CandidatesData(ch, c))); |
679 } else { | 682 } else { |
680 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, | 683 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, |
681 new CandidatesData(ch, c)); | 684 new CandidatesData(ch, c)); |
682 } | 685 } |
683 } | 686 } |
684 | 687 |
685 void PauseCandidates(int endpoint) { | 688 void PauseCandidates(int endpoint) { |
686 GetEndpoint(endpoint)->save_candidates_ = true; | 689 GetEndpoint(endpoint)->save_candidates_ = true; |
687 } | 690 } |
688 | 691 |
(...skipping 16 matching lines...) Expand all Loading... |
705 EXPECT_NE(candidate.address().port(), DISCARD_PORT); | 708 EXPECT_NE(candidate.address().port(), DISCARD_PORT); |
706 } else { | 709 } else { |
707 FAIL() << "Unknown tcptype: " << candidate.tcptype(); | 710 FAIL() << "Unknown tcptype: " << candidate.tcptype(); |
708 } | 711 } |
709 } | 712 } |
710 } | 713 } |
711 } | 714 } |
712 | 715 |
713 void ResumeCandidates(int endpoint) { | 716 void ResumeCandidates(int endpoint) { |
714 Endpoint* ed = GetEndpoint(endpoint); | 717 Endpoint* ed = GetEndpoint(endpoint); |
715 std::vector<CandidatesData*>::iterator it = ed->saved_candidates_.begin(); | 718 for (auto& candidate : ed->saved_candidates_) { |
716 for (; it != ed->saved_candidates_.end(); ++it) { | 719 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, candidate.release()); |
717 main_->Post(RTC_FROM_HERE, this, MSG_ADD_CANDIDATES, *it); | |
718 } | 720 } |
719 ed->saved_candidates_.clear(); | 721 ed->saved_candidates_.clear(); |
720 ed->save_candidates_ = false; | 722 ed->save_candidates_ = false; |
721 } | 723 } |
722 | 724 |
723 void OnMessage(rtc::Message* msg) { | 725 void OnMessage(rtc::Message* msg) { |
724 switch (msg->message_id) { | 726 switch (msg->message_id) { |
725 case MSG_ADD_CANDIDATES: { | 727 case MSG_ADD_CANDIDATES: { |
726 std::unique_ptr<CandidatesData> data( | 728 std::unique_ptr<CandidatesData> data( |
727 static_cast<CandidatesData*>(msg->pdata)); | 729 static_cast<CandidatesData*>(msg->pdata)); |
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1658 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); | 1660 auto pooled_ports_2 = pooled_session_2->ReadyPorts(); |
1659 EXPECT_NE(pooled_ports_1.end(), | 1661 EXPECT_NE(pooled_ports_1.end(), |
1660 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), | 1662 std::find(pooled_ports_1.begin(), pooled_ports_1.end(), |
1661 ep1_ch1()->selected_connection()->port())); | 1663 ep1_ch1()->selected_connection()->port())); |
1662 EXPECT_NE(pooled_ports_2.end(), | 1664 EXPECT_NE(pooled_ports_2.end(), |
1663 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), | 1665 std::find(pooled_ports_2.begin(), pooled_ports_2.end(), |
1664 ep2_ch1()->selected_connection()->port())); | 1666 ep2_ch1()->selected_connection()->port())); |
1665 } | 1667 } |
1666 | 1668 |
1667 // Test that when the "presume_writable_when_fully_relayed" flag is set to | 1669 // Test that when the "presume_writable_when_fully_relayed" flag is set to |
1668 // false and there's a TURN-TURN candidate pair, it's presume to be writable | 1670 // true and there's a TURN-TURN candidate pair, it's presumed to be writable |
1669 // as soon as it's created. | 1671 // as soon as it's created. |
1670 TEST_F(P2PTransportChannelTest, TurnToTurnPresumedWritable) { | 1672 TEST_F(P2PTransportChannelTest, TurnToTurnPresumedWritable) { |
1671 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1673 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
1672 kDefaultPortAllocatorFlags); | 1674 kDefaultPortAllocatorFlags); |
1673 // Only configure one channel so we can control when the remote candidate | 1675 // Only configure one channel so we can control when the remote candidate |
1674 // is added. | 1676 // is added. |
1675 GetEndpoint(0)->cd1_.ch_.reset( | 1677 GetEndpoint(0)->cd1_.ch_.reset( |
1676 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0], | 1678 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0], |
1677 kIcePwd[0], kIceUfrag[1], kIcePwd[1])); | 1679 kIcePwd[0], kIceUfrag[1], kIcePwd[1])); |
1678 IceConfig config; | 1680 IceConfig config; |
(...skipping 12 matching lines...) Expand all Loading... |
1691 // "probably writable". | 1693 // "probably writable". |
1692 EXPECT_TRUE(ep1_ch1()->selected_connection() != nullptr); | 1694 EXPECT_TRUE(ep1_ch1()->selected_connection() != nullptr); |
1693 EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type()); | 1695 EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type()); |
1694 EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type()); | 1696 EXPECT_EQ(RELAY_PORT_TYPE, RemoteCandidate(ep1_ch1())->type()); |
1695 // Also expect that the channel instantly indicates that it's writable since | 1697 // Also expect that the channel instantly indicates that it's writable since |
1696 // it has a TURN-TURN pair. | 1698 // it has a TURN-TURN pair. |
1697 EXPECT_TRUE(ep1_ch1()->writable()); | 1699 EXPECT_TRUE(ep1_ch1()->writable()); |
1698 EXPECT_TRUE(GetEndpoint(0)->ready_to_send_); | 1700 EXPECT_TRUE(GetEndpoint(0)->ready_to_send_); |
1699 } | 1701 } |
1700 | 1702 |
| 1703 // Test that a TURN/peer reflexive candidate pair is also presumed writable. |
| 1704 TEST_F(P2PTransportChannelTest, TurnToPrflxPresumedWritable) { |
| 1705 rtc::ScopedFakeClock fake_clock; |
| 1706 |
| 1707 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, |
| 1708 kDefaultPortAllocatorFlags); |
| 1709 // We want the remote TURN candidate to show up as prflx. To do this we need |
| 1710 // to configure the server to accept packets from an address we haven't |
| 1711 // explicitly installed permission for. |
| 1712 test_turn_server()->set_enable_permission_checks(false); |
| 1713 IceConfig config; |
| 1714 config.presume_writable_when_fully_relayed = true; |
| 1715 GetEndpoint(0)->cd1_.ch_.reset( |
| 1716 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0], |
| 1717 kIcePwd[0], kIceUfrag[1], kIcePwd[1])); |
| 1718 GetEndpoint(1)->cd1_.ch_.reset( |
| 1719 CreateChannel(1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[1], |
| 1720 kIcePwd[1], kIceUfrag[0], kIcePwd[0])); |
| 1721 ep1_ch1()->SetIceConfig(config); |
| 1722 ep2_ch1()->SetIceConfig(config); |
| 1723 // Don't signal candidates from channel 2, so that channel 1 sees the TURN |
| 1724 // candidate as peer reflexive. |
| 1725 PauseCandidates(1); |
| 1726 ep1_ch1()->MaybeStartGathering(); |
| 1727 ep2_ch1()->MaybeStartGathering(); |
| 1728 |
| 1729 // Wait for the TURN<->prflx connection. |
| 1730 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable(), |
| 1731 1000, fake_clock); |
| 1732 ASSERT_NE(nullptr, ep1_ch1()->selected_connection()); |
| 1733 EXPECT_EQ(RELAY_PORT_TYPE, LocalCandidate(ep1_ch1())->type()); |
| 1734 EXPECT_EQ(PRFLX_PORT_TYPE, RemoteCandidate(ep1_ch1())->type()); |
| 1735 // Make sure that at this point the connection is only presumed writable, |
| 1736 // not fully writable. |
| 1737 EXPECT_FALSE(ep1_ch1()->selected_connection()->writable()); |
| 1738 |
| 1739 // Now wait for it to actually become writable. |
| 1740 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->selected_connection()->writable(), 1000, |
| 1741 fake_clock); |
| 1742 |
| 1743 // Explitly destroy channels, before fake clock is destroyed. |
| 1744 DestroyChannels(); |
| 1745 } |
| 1746 |
1701 // Test that a presumed-writable TURN<->TURN connection is preferred above an | 1747 // Test that a presumed-writable TURN<->TURN connection is preferred above an |
1702 // unreliable connection (one that has failed to be pinged for some time). | 1748 // unreliable connection (one that has failed to be pinged for some time). |
1703 TEST_F(P2PTransportChannelTest, PresumedWritablePreferredOverUnreliable) { | 1749 TEST_F(P2PTransportChannelTest, PresumedWritablePreferredOverUnreliable) { |
1704 rtc::ScopedFakeClock fake_clock; | 1750 rtc::ScopedFakeClock fake_clock; |
1705 | 1751 |
1706 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, | 1752 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, |
1707 kDefaultPortAllocatorFlags); | 1753 kDefaultPortAllocatorFlags); |
1708 IceConfig config; | 1754 IceConfig config; |
1709 config.presume_writable_when_fully_relayed = true; | 1755 config.presume_writable_when_fully_relayed = true; |
1710 GetEndpoint(0)->cd1_.ch_.reset( | 1756 GetEndpoint(0)->cd1_.ch_.reset( |
(...skipping 1717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3428 | 3474 |
3429 // TCP Relay/Relay is the next. | 3475 // TCP Relay/Relay is the next. |
3430 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, | 3476 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, |
3431 TCP_PROTOCOL_NAME); | 3477 TCP_PROTOCOL_NAME); |
3432 | 3478 |
3433 // Finally, Local/Relay will be pinged. | 3479 // Finally, Local/Relay will be pinged. |
3434 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); | 3480 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
3435 } | 3481 } |
3436 | 3482 |
3437 } // namespace cricket { | 3483 } // namespace cricket { |
OLD | NEW |