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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 "TESTICEUFRAG0002", "TESTICEUFRAG0003"}; | 91 "TESTICEUFRAG0002", "TESTICEUFRAG0003"}; |
92 // Based on ICE_PWD_LENGTH | 92 // Based on ICE_PWD_LENGTH |
93 static const char* kIcePwd[4] = {"TESTICEPWD00000000000000", | 93 static const char* kIcePwd[4] = {"TESTICEPWD00000000000000", |
94 "TESTICEPWD00000000000001", | 94 "TESTICEPWD00000000000001", |
95 "TESTICEPWD00000000000002", | 95 "TESTICEPWD00000000000002", |
96 "TESTICEPWD00000000000003"}; | 96 "TESTICEPWD00000000000003"}; |
97 | 97 |
98 static const uint64_t kTiebreaker1 = 11111; | 98 static const uint64_t kTiebreaker1 = 11111; |
99 static const uint64_t kTiebreaker2 = 22222; | 99 static const uint64_t kTiebreaker2 = 22222; |
100 | 100 |
101 enum { | 101 enum { MSG_ADD_CANDIDATES, MSG_REMOVE_CANDIDATES }; |
102 MSG_CANDIDATE | |
103 }; | |
104 | 102 |
105 static cricket::IceConfig CreateIceConfig(int receiving_timeout, | 103 static cricket::IceConfig CreateIceConfig(int receiving_timeout, |
106 bool gather_continually, | 104 bool gather_continually, |
107 int backup_ping_interval = -1) { | 105 int backup_ping_interval = -1) { |
108 cricket::IceConfig config; | 106 cricket::IceConfig config; |
109 config.receiving_timeout = receiving_timeout; | 107 config.receiving_timeout = receiving_timeout; |
110 config.gather_continually = gather_continually; | 108 config.gather_continually = gather_continually; |
111 config.backup_connection_ping_interval = backup_ping_interval; | 109 config.backup_connection_ping_interval = backup_ping_interval; |
112 return config; | 110 return config; |
113 } | 111 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 ch_packets_.pop_front(); | 207 ch_packets_.pop_front(); |
210 } | 208 } |
211 return ret; | 209 return ret; |
212 } | 210 } |
213 | 211 |
214 std::string name_; // TODO - Currently not used. | 212 std::string name_; // TODO - Currently not used. |
215 std::list<std::string> ch_packets_; | 213 std::list<std::string> ch_packets_; |
216 rtc::scoped_ptr<cricket::P2PTransportChannel> ch_; | 214 rtc::scoped_ptr<cricket::P2PTransportChannel> ch_; |
217 }; | 215 }; |
218 | 216 |
219 struct CandidateData : public rtc::MessageData { | 217 struct CandidatesData : public rtc::MessageData { |
220 CandidateData(cricket::TransportChannel* ch, const cricket::Candidate& c) | 218 CandidatesData(cricket::TransportChannel* ch, const cricket::Candidate& c) |
221 : channel(ch), candidate(c) { | 219 : channel(ch), candidates(1, c) {} |
222 } | 220 CandidatesData(cricket::TransportChannel* ch, |
| 221 const std::vector<cricket::Candidate>& cc) |
| 222 : channel(ch), candidates(cc) {} |
223 cricket::TransportChannel* channel; | 223 cricket::TransportChannel* channel; |
224 cricket::Candidate candidate; | 224 cricket::Candidates candidates; |
225 }; | 225 }; |
226 | 226 |
227 struct Endpoint { | 227 struct Endpoint { |
228 Endpoint() | 228 Endpoint() |
229 : role_(cricket::ICEROLE_UNKNOWN), | 229 : role_(cricket::ICEROLE_UNKNOWN), |
230 tiebreaker_(0), | 230 tiebreaker_(0), |
231 role_conflict_(false), | 231 role_conflict_(false), |
232 save_candidates_(false) {} | 232 save_candidates_(false) {} |
233 bool HasChannel(cricket::TransportChannel* ch) { | 233 bool HasChannel(cricket::TransportChannel* ch) { |
234 return (ch == cd1_.ch_.get() || ch == cd2_.ch_.get()); | 234 return (ch == cd1_.ch_.get() || ch == cd2_.ch_.get()); |
(...skipping 20 matching lines...) Expand all Loading... |
255 } | 255 } |
256 | 256 |
257 rtc::FakeNetworkManager network_manager_; | 257 rtc::FakeNetworkManager network_manager_; |
258 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_; | 258 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_; |
259 ChannelData cd1_; | 259 ChannelData cd1_; |
260 ChannelData cd2_; | 260 ChannelData cd2_; |
261 cricket::IceRole role_; | 261 cricket::IceRole role_; |
262 uint64_t tiebreaker_; | 262 uint64_t tiebreaker_; |
263 bool role_conflict_; | 263 bool role_conflict_; |
264 bool save_candidates_; | 264 bool save_candidates_; |
265 std::vector<CandidateData*> saved_candidates_; | 265 std::vector<CandidatesData*> saved_candidates_; |
266 }; | 266 }; |
267 | 267 |
268 ChannelData* GetChannelData(cricket::TransportChannel* channel) { | 268 ChannelData* GetChannelData(cricket::TransportChannel* channel) { |
269 if (ep1_.HasChannel(channel)) | 269 if (ep1_.HasChannel(channel)) |
270 return ep1_.GetChannelData(channel); | 270 return ep1_.GetChannelData(channel); |
271 else | 271 else |
272 return ep2_.GetChannelData(channel); | 272 return ep2_.GetChannelData(channel); |
273 } | 273 } |
274 | 274 |
275 void CreateChannels(int num) { | 275 void CreateChannels(int num) { |
(...skipping 27 matching lines...) Expand all Loading... |
303 cricket::P2PTransportChannel* CreateChannel( | 303 cricket::P2PTransportChannel* CreateChannel( |
304 int endpoint, | 304 int endpoint, |
305 int component, | 305 int component, |
306 const std::string& local_ice_ufrag, | 306 const std::string& local_ice_ufrag, |
307 const std::string& local_ice_pwd, | 307 const std::string& local_ice_pwd, |
308 const std::string& remote_ice_ufrag, | 308 const std::string& remote_ice_ufrag, |
309 const std::string& remote_ice_pwd) { | 309 const std::string& remote_ice_pwd) { |
310 cricket::P2PTransportChannel* channel = new cricket::P2PTransportChannel( | 310 cricket::P2PTransportChannel* channel = new cricket::P2PTransportChannel( |
311 "test content name", component, GetAllocator(endpoint)); | 311 "test content name", component, GetAllocator(endpoint)); |
312 channel->SignalCandidateGathered.connect( | 312 channel->SignalCandidateGathered.connect( |
313 this, &P2PTransportChannelTestBase::OnCandidate); | 313 this, &P2PTransportChannelTestBase::OnCandidateGathered); |
| 314 channel->SignalCandidatesRemoved.connect( |
| 315 this, &P2PTransportChannelTestBase::OnCandidatesRemoved); |
314 channel->SignalReadPacket.connect( | 316 channel->SignalReadPacket.connect( |
315 this, &P2PTransportChannelTestBase::OnReadPacket); | 317 this, &P2PTransportChannelTestBase::OnReadPacket); |
316 channel->SignalRoleConflict.connect( | 318 channel->SignalRoleConflict.connect( |
317 this, &P2PTransportChannelTestBase::OnRoleConflict); | 319 this, &P2PTransportChannelTestBase::OnRoleConflict); |
318 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); | 320 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); |
319 if (clear_remote_candidates_ufrag_pwd_) { | 321 if (clear_remote_candidates_ufrag_pwd_) { |
320 // This only needs to be set if we're clearing them from the | 322 // This only needs to be set if we're clearing them from the |
321 // candidates. Some unit tests rely on this not being set. | 323 // candidates. Some unit tests rely on this not being set. |
322 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd); | 324 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd); |
323 } | 325 } |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 ep2_ch1()->writable(), | 640 ep2_ch1()->writable(), |
639 1000); | 641 1000); |
640 | 642 |
641 EXPECT_TRUE(ep1_ch1()->best_connection() && | 643 EXPECT_TRUE(ep1_ch1()->best_connection() && |
642 ep2_ch1()->best_connection()); | 644 ep2_ch1()->best_connection()); |
643 | 645 |
644 TestSendRecv(1); | 646 TestSendRecv(1); |
645 } | 647 } |
646 | 648 |
647 // We pass the candidates directly to the other side. | 649 // We pass the candidates directly to the other side. |
648 void OnCandidate(cricket::TransportChannelImpl* ch, | 650 void OnCandidateGathered(cricket::TransportChannelImpl* ch, |
649 const cricket::Candidate& c) { | 651 const cricket::Candidate& c) { |
650 if (force_relay_ && c.type() != cricket::RELAY_PORT_TYPE) | 652 if (force_relay_ && c.type() != cricket::RELAY_PORT_TYPE) |
651 return; | 653 return; |
652 | 654 |
653 if (GetEndpoint(ch)->save_candidates_) { | 655 if (GetEndpoint(ch)->save_candidates_) { |
654 GetEndpoint(ch)->saved_candidates_.push_back(new CandidateData(ch, c)); | 656 GetEndpoint(ch)->saved_candidates_.push_back(new CandidatesData(ch, c)); |
655 } else { | 657 } else { |
656 main_->Post(this, MSG_CANDIDATE, new CandidateData(ch, c)); | 658 main_->Post(this, MSG_ADD_CANDIDATES, new CandidatesData(ch, c)); |
657 } | 659 } |
658 } | 660 } |
659 | 661 |
660 void PauseCandidates(int endpoint) { | 662 void PauseCandidates(int endpoint) { |
661 GetEndpoint(endpoint)->save_candidates_ = true; | 663 GetEndpoint(endpoint)->save_candidates_ = true; |
662 } | 664 } |
663 | 665 |
| 666 void OnCandidatesRemoved(cricket::TransportChannelImpl* ch, |
| 667 const std::vector<cricket::Candidate>& candidates) { |
| 668 // Candidate removals are not paused. |
| 669 CandidatesData* candidates_data = new CandidatesData(ch, candidates); |
| 670 main_->Post(this, MSG_REMOVE_CANDIDATES, candidates_data); |
| 671 } |
| 672 |
664 // Tcp candidate verification has to be done when they are generated. | 673 // Tcp candidate verification has to be done when they are generated. |
665 void VerifySavedTcpCandidates(int endpoint, const std::string& tcptype) { | 674 void VerifySavedTcpCandidates(int endpoint, const std::string& tcptype) { |
666 for (auto& data : GetEndpoint(endpoint)->saved_candidates_) { | 675 for (auto& data : GetEndpoint(endpoint)->saved_candidates_) { |
667 EXPECT_EQ(data->candidate.protocol(), cricket::TCP_PROTOCOL_NAME); | 676 for (auto& candidate : data->candidates) { |
668 EXPECT_EQ(data->candidate.tcptype(), tcptype); | 677 EXPECT_EQ(candidate.protocol(), cricket::TCP_PROTOCOL_NAME); |
669 if (data->candidate.tcptype() == cricket::TCPTYPE_ACTIVE_STR) { | 678 EXPECT_EQ(candidate.tcptype(), tcptype); |
670 EXPECT_EQ(data->candidate.address().port(), cricket::DISCARD_PORT); | 679 if (candidate.tcptype() == cricket::TCPTYPE_ACTIVE_STR) { |
671 } else if (data->candidate.tcptype() == cricket::TCPTYPE_PASSIVE_STR) { | 680 EXPECT_EQ(candidate.address().port(), cricket::DISCARD_PORT); |
672 EXPECT_NE(data->candidate.address().port(), cricket::DISCARD_PORT); | 681 } else if (candidate.tcptype() == cricket::TCPTYPE_PASSIVE_STR) { |
673 } else { | 682 EXPECT_NE(candidate.address().port(), cricket::DISCARD_PORT); |
674 FAIL() << "Unknown tcptype: " << data->candidate.tcptype(); | 683 } else { |
| 684 FAIL() << "Unknown tcptype: " << candidate.tcptype(); |
| 685 } |
675 } | 686 } |
676 } | 687 } |
677 } | 688 } |
678 | 689 |
679 void ResumeCandidates(int endpoint) { | 690 void ResumeCandidates(int endpoint) { |
680 Endpoint* ed = GetEndpoint(endpoint); | 691 Endpoint* ed = GetEndpoint(endpoint); |
681 std::vector<CandidateData*>::iterator it = ed->saved_candidates_.begin(); | 692 std::vector<CandidatesData*>::iterator it = ed->saved_candidates_.begin(); |
682 for (; it != ed->saved_candidates_.end(); ++it) { | 693 for (; it != ed->saved_candidates_.end(); ++it) { |
683 main_->Post(this, MSG_CANDIDATE, *it); | 694 main_->Post(this, MSG_ADD_CANDIDATES, *it); |
684 } | 695 } |
685 ed->saved_candidates_.clear(); | 696 ed->saved_candidates_.clear(); |
686 ed->save_candidates_ = false; | 697 ed->save_candidates_ = false; |
687 } | 698 } |
688 | 699 |
689 void OnMessage(rtc::Message* msg) { | 700 void OnMessage(rtc::Message* msg) { |
690 switch (msg->message_id) { | 701 switch (msg->message_id) { |
691 case MSG_CANDIDATE: { | 702 case MSG_ADD_CANDIDATES: { |
692 rtc::scoped_ptr<CandidateData> data( | 703 rtc::scoped_ptr<CandidatesData> data( |
693 static_cast<CandidateData*>(msg->pdata)); | 704 static_cast<CandidatesData*>(msg->pdata)); |
694 cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel); | 705 cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel); |
695 cricket::Candidate c = data->candidate; | 706 for (auto& c : data->candidates) { |
696 if (clear_remote_candidates_ufrag_pwd_) { | 707 if (clear_remote_candidates_ufrag_pwd_) { |
697 c.set_username(""); | 708 c.set_username(""); |
698 c.set_password(""); | 709 c.set_password(""); |
| 710 } |
| 711 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->" |
| 712 << rch->component() << "): " << c.ToString(); |
| 713 rch->AddRemoteCandidate(c); |
699 } | 714 } |
700 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->" | 715 break; |
701 << rch->component() << "): " << c.ToString(); | 716 } |
702 rch->AddRemoteCandidate(c); | 717 case MSG_REMOVE_CANDIDATES: { |
| 718 rtc::scoped_ptr<CandidatesData> data( |
| 719 static_cast<CandidatesData*>(msg->pdata)); |
| 720 cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel); |
| 721 for (cricket::Candidate& c : data->candidates) { |
| 722 LOG(LS_INFO) << "Removed remote candidate " << c.ToString(); |
| 723 rch->RemoveRemoteCandidate(c); |
| 724 } |
703 break; | 725 break; |
704 } | 726 } |
705 } | 727 } |
706 } | 728 } |
707 void OnReadPacket(cricket::TransportChannel* channel, const char* data, | 729 void OnReadPacket(cricket::TransportChannel* channel, const char* data, |
708 size_t len, const rtc::PacketTime& packet_time, | 730 size_t len, const rtc::PacketTime& packet_time, |
709 int flags) { | 731 int flags) { |
710 std::list<std::string>& packets = GetPacketList(channel); | 732 std::list<std::string>& packets = GetPacketList(channel); |
711 packets.push_front(std::string(data, len)); | 733 packets.push_front(std::string(data, len)); |
712 } | 734 } |
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1765 // Create channels and let them go writable, as usual. | 1787 // Create channels and let them go writable, as usual. |
1766 CreateChannels(1); | 1788 CreateChannels(1); |
1767 | 1789 |
1768 // Both transport channels will reach STATE_COMPLETED quickly. | 1790 // Both transport channels will reach STATE_COMPLETED quickly. |
1769 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED, | 1791 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED, |
1770 ep1_ch1()->GetState(), 1000); | 1792 ep1_ch1()->GetState(), 1000); |
1771 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED, | 1793 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED, |
1772 ep2_ch1()->GetState(), 1000); | 1794 ep2_ch1()->GetState(), 1000); |
1773 } | 1795 } |
1774 | 1796 |
1775 // Tests that when a network interface becomes inactive, the ports associated | 1797 // Tests that when a network interface becomes inactive, if and only if |
1776 // with that network will be removed from the port list of the channel if | 1798 // Continual Gathering is enabled, the ports associated with that network |
1777 // and only if Continual Gathering is enabled. | 1799 // will be removed from the port list of the channel, and the respective |
| 1800 // remote candidates on the other participant will be removed eventually. |
1778 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { | 1801 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { |
1779 AddAddress(0, kPublicAddrs[0]); | 1802 AddAddress(0, kPublicAddrs[0]); |
1780 AddAddress(1, kPublicAddrs[1]); | 1803 AddAddress(1, kPublicAddrs[1]); |
1781 // Create channels and let them go writable, as usual. | 1804 // Create channels and let them go writable, as usual. |
1782 CreateChannels(1); | 1805 CreateChannels(1); |
1783 ep1_ch1()->SetIceConfig(CreateIceConfig(2000, true)); | 1806 ep1_ch1()->SetIceConfig(CreateIceConfig(2000, true)); |
1784 ep2_ch1()->SetIceConfig(CreateIceConfig(2000, false)); | 1807 ep2_ch1()->SetIceConfig(CreateIceConfig(2000, false)); |
1785 | 1808 |
1786 SetAllocatorFlags(0, kOnlyLocalPorts); | 1809 SetAllocatorFlags(0, kOnlyLocalPorts); |
1787 SetAllocatorFlags(1, kOnlyLocalPorts); | 1810 SetAllocatorFlags(1, kOnlyLocalPorts); |
1788 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1811 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1789 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1812 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1790 1000, 1000); | 1813 1000, 1000); |
1791 // More than one port has been created. | 1814 // More than one port has been created. |
1792 EXPECT_LE(1U, ep1_ch1()->ports().size()); | 1815 EXPECT_LE(1U, ep1_ch1()->ports().size()); |
1793 // Endpoint 1 enabled continual gathering; the port will be removed | 1816 // Endpoint 1 enabled continual gathering; the port will be removed |
1794 // when the interface is removed. | 1817 // when the interface is removed. |
1795 RemoveAddress(0, kPublicAddrs[0]); | 1818 RemoveAddress(0, kPublicAddrs[0]); |
1796 EXPECT_EQ(0U, ep1_ch1()->ports().size()); | 1819 EXPECT_TRUE(ep1_ch1()->ports().empty()); |
| 1820 // The remote candidates will be removed eventually. |
| 1821 EXPECT_TRUE_WAIT(ep2_ch1()->remote_candidates().empty(), 1000); |
1797 | 1822 |
1798 size_t num_ports = ep2_ch1()->ports().size(); | 1823 size_t num_ports = ep2_ch1()->ports().size(); |
1799 EXPECT_LE(1U, num_ports); | 1824 EXPECT_LE(1U, num_ports); |
| 1825 size_t num_remote_candidates = ep1_ch1()->remote_candidates().size(); |
1800 // Endpoint 2 did not enable continual gathering; the port will not be removed | 1826 // Endpoint 2 did not enable continual gathering; the port will not be removed |
1801 // when the interface is removed. | 1827 // when the interface is removed and neither the remote candidates on the |
| 1828 // other participant. |
1802 RemoveAddress(1, kPublicAddrs[1]); | 1829 RemoveAddress(1, kPublicAddrs[1]); |
| 1830 rtc::Thread::Current()->ProcessMessages(500); |
1803 EXPECT_EQ(num_ports, ep2_ch1()->ports().size()); | 1831 EXPECT_EQ(num_ports, ep2_ch1()->ports().size()); |
| 1832 EXPECT_EQ(num_remote_candidates, ep1_ch1()->remote_candidates().size()); |
1804 } | 1833 } |
1805 | 1834 |
1806 /* | 1835 /* |
1807 | 1836 |
1808 TODO(pthatcher): Once have a way to handle network interfaces changes | 1837 TODO(pthatcher): Once have a way to handle network interfaces changes |
1809 without signalling an ICE restart, put a test like this back. In the | 1838 without signalling an ICE restart, put a test like this back. In the |
1810 mean time, this test only worked for GICE. With ICE, it's currently | 1839 mean time, this test only worked for GICE. With ICE, it's currently |
1811 not possible without an ICE restart. | 1840 not possible without an ICE restart. |
1812 | 1841 |
1813 // Test that we can switch links in a coordinated fashion. | 1842 // Test that we can switch links in a coordinated fashion. |
(...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2690 | 2719 |
2691 // TCP Relay/Relay is the next. | 2720 // TCP Relay/Relay is the next. |
2692 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 2721 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
2693 cricket::RELAY_PORT_TYPE, | 2722 cricket::RELAY_PORT_TYPE, |
2694 cricket::TCP_PROTOCOL_NAME); | 2723 cricket::TCP_PROTOCOL_NAME); |
2695 | 2724 |
2696 // Finally, Local/Relay will be pinged. | 2725 // Finally, Local/Relay will be pinged. |
2697 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, | 2726 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, |
2698 cricket::RELAY_PORT_TYPE); | 2727 cricket::RELAY_PORT_TYPE); |
2699 } | 2728 } |
OLD | NEW |