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_CANDIDATE, MSG_CANDIDATE_REMOVALS }; |
pthatcher1
2016/03/09 18:00:53
Can you call these MSG_ADD_CANDIDATES and MSG_REMO
honghaiz3
2016/03/10 02:34:16
Done.
| |
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::OnCandidate); |
pthatcher1
2016/03/09 18:00:53
Can you rename this OnCandidateGathered?
honghaiz3
2016/03/10 02:34:16
Done.
| |
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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 OnCandidate(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_CANDIDATE, 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_CANDIDATE_REMOVALS, 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 cricket::Candidate& candidate = data->candidates[0]; |
pthatcher1
2016/03/09 18:00:53
Why not just make this a for loop?
honghaiz3
2016/03/10 02:34:16
Done.
| |
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) { |
682 EXPECT_NE(candidate.address().port(), cricket::DISCARD_PORT); | |
673 } else { | 683 } else { |
674 FAIL() << "Unknown tcptype: " << data->candidate.tcptype(); | 684 FAIL() << "Unknown tcptype: " << candidate.tcptype(); |
675 } | 685 } |
676 } | 686 } |
677 } | 687 } |
678 | 688 |
679 void ResumeCandidates(int endpoint) { | 689 void ResumeCandidates(int endpoint) { |
680 Endpoint* ed = GetEndpoint(endpoint); | 690 Endpoint* ed = GetEndpoint(endpoint); |
681 std::vector<CandidateData*>::iterator it = ed->saved_candidates_.begin(); | 691 std::vector<CandidatesData*>::iterator it = ed->saved_candidates_.begin(); |
682 for (; it != ed->saved_candidates_.end(); ++it) { | 692 for (; it != ed->saved_candidates_.end(); ++it) { |
683 main_->Post(this, MSG_CANDIDATE, *it); | 693 main_->Post(this, MSG_CANDIDATE, *it); |
684 } | 694 } |
685 ed->saved_candidates_.clear(); | 695 ed->saved_candidates_.clear(); |
686 ed->save_candidates_ = false; | 696 ed->save_candidates_ = false; |
687 } | 697 } |
688 | 698 |
689 void OnMessage(rtc::Message* msg) { | 699 void OnMessage(rtc::Message* msg) { |
690 switch (msg->message_id) { | 700 switch (msg->message_id) { |
691 case MSG_CANDIDATE: { | 701 case MSG_CANDIDATE: { |
692 rtc::scoped_ptr<CandidateData> data( | 702 rtc::scoped_ptr<CandidatesData> data( |
693 static_cast<CandidateData*>(msg->pdata)); | 703 static_cast<CandidatesData*>(msg->pdata)); |
694 cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel); | 704 cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel); |
695 cricket::Candidate c = data->candidate; | 705 // Candidates are currently added one at a time. |
706 cricket::Candidate c = data->candidates[0]; | |
pthatcher1
2016/03/09 18:00:53
Why not make this a for loop?
honghaiz3
2016/03/10 02:34:16
Done.
| |
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(""); |
699 } | 710 } |
700 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->" | 711 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->" |
701 << rch->component() << "): " << c.ToString(); | 712 << rch->component() << "): " << c.ToString(); |
702 rch->AddRemoteCandidate(c); | 713 rch->AddRemoteCandidate(c); |
703 break; | 714 break; |
704 } | 715 } |
716 case MSG_CANDIDATE_REMOVALS: { | |
717 rtc::scoped_ptr<CandidatesData> data( | |
718 static_cast<CandidatesData*>(msg->pdata)); | |
719 cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel); | |
720 for (cricket::Candidate& c : data->candidates) { | |
721 LOG(LS_INFO) << "Removed remote candidate " << c.ToString(); | |
722 rch->RemoveRemoteCandidate(c); | |
723 } | |
724 break; | |
725 } | |
705 } | 726 } |
706 } | 727 } |
707 void OnReadPacket(cricket::TransportChannel* channel, const char* data, | 728 void OnReadPacket(cricket::TransportChannel* channel, const char* data, |
708 size_t len, const rtc::PacketTime& packet_time, | 729 size_t len, const rtc::PacketTime& packet_time, |
709 int flags) { | 730 int flags) { |
710 std::list<std::string>& packets = GetPacketList(channel); | 731 std::list<std::string>& packets = GetPacketList(channel); |
711 packets.push_front(std::string(data, len)); | 732 packets.push_front(std::string(data, len)); |
712 } | 733 } |
713 void OnRoleConflict(cricket::TransportChannelImpl* channel) { | 734 void OnRoleConflict(cricket::TransportChannelImpl* channel) { |
714 GetEndpoint(channel)->OnRoleConflict(true); | 735 GetEndpoint(channel)->OnRoleConflict(true); |
(...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1765 // Create channels and let them go writable, as usual. | 1786 // Create channels and let them go writable, as usual. |
1766 CreateChannels(1); | 1787 CreateChannels(1); |
1767 | 1788 |
1768 // Both transport channels will reach STATE_COMPLETED quickly. | 1789 // Both transport channels will reach STATE_COMPLETED quickly. |
1769 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED, | 1790 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED, |
1770 ep1_ch1()->GetState(), 1000); | 1791 ep1_ch1()->GetState(), 1000); |
1771 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED, | 1792 EXPECT_EQ_WAIT(cricket::TransportChannelState::STATE_COMPLETED, |
1772 ep2_ch1()->GetState(), 1000); | 1793 ep2_ch1()->GetState(), 1000); |
1773 } | 1794 } |
1774 | 1795 |
1775 // Tests that when a network interface becomes inactive, the ports associated | 1796 // 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 | 1797 // Continual Gathering is enabled, the ports associated with that network |
1777 // and only if Continual Gathering is enabled. | 1798 // will be removed from the port list of the channel, and the respective |
1799 // remote candidates on the other participant will be removed eventually. | |
1778 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { | 1800 TEST_F(P2PTransportChannelMultihomedTest, TestNetworkBecomesInactive) { |
1779 AddAddress(0, kPublicAddrs[0]); | 1801 AddAddress(0, kPublicAddrs[0]); |
1780 AddAddress(1, kPublicAddrs[1]); | 1802 AddAddress(1, kPublicAddrs[1]); |
1781 // Create channels and let them go writable, as usual. | 1803 // Create channels and let them go writable, as usual. |
1782 CreateChannels(1); | 1804 CreateChannels(1); |
1783 ep1_ch1()->SetIceConfig(CreateIceConfig(2000, true)); | 1805 ep1_ch1()->SetIceConfig(CreateIceConfig(2000, true)); |
1784 ep2_ch1()->SetIceConfig(CreateIceConfig(2000, false)); | 1806 ep2_ch1()->SetIceConfig(CreateIceConfig(2000, false)); |
1785 | 1807 |
1786 SetAllocatorFlags(0, kOnlyLocalPorts); | 1808 SetAllocatorFlags(0, kOnlyLocalPorts); |
1787 SetAllocatorFlags(1, kOnlyLocalPorts); | 1809 SetAllocatorFlags(1, kOnlyLocalPorts); |
1788 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1810 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
1789 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1811 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
1790 1000, 1000); | 1812 1000, 1000); |
1791 // More than one port has been created. | 1813 // More than one port has been created. |
1792 EXPECT_LE(1U, ep1_ch1()->ports().size()); | 1814 EXPECT_LE(1U, ep1_ch1()->ports().size()); |
1793 // Endpoint 1 enabled continual gathering; the port will be removed | 1815 // Endpoint 1 enabled continual gathering; the port will be removed |
1794 // when the interface is removed. | 1816 // when the interface is removed. |
1795 RemoveAddress(0, kPublicAddrs[0]); | 1817 RemoveAddress(0, kPublicAddrs[0]); |
1796 EXPECT_EQ(0U, ep1_ch1()->ports().size()); | 1818 EXPECT_TRUE(ep1_ch1()->ports().empty()); |
1819 // The remote candidates will be removed eventually. | |
1820 EXPECT_TRUE_WAIT(ep2_ch1()->remote_candidates().empty(), 1000); | |
1797 | 1821 |
1798 size_t num_ports = ep2_ch1()->ports().size(); | 1822 size_t num_ports = ep2_ch1()->ports().size(); |
1799 EXPECT_LE(1U, num_ports); | 1823 EXPECT_LE(1U, num_ports); |
1824 size_t num_remote_candidates = ep1_ch1()->remote_candidates().size(); | |
1800 // Endpoint 2 did not enable continual gathering; the port will not be removed | 1825 // Endpoint 2 did not enable continual gathering; the port will not be removed |
1801 // when the interface is removed. | 1826 // when the interface is removed and neither the remote candidates on the |
1827 // other participant. | |
1802 RemoveAddress(1, kPublicAddrs[1]); | 1828 RemoveAddress(1, kPublicAddrs[1]); |
1829 rtc::Thread::Current()->ProcessMessages(500); | |
1803 EXPECT_EQ(num_ports, ep2_ch1()->ports().size()); | 1830 EXPECT_EQ(num_ports, ep2_ch1()->ports().size()); |
1831 EXPECT_EQ(num_remote_candidates, ep1_ch1()->remote_candidates().size()); | |
1804 } | 1832 } |
1805 | 1833 |
1806 /* | 1834 /* |
1807 | 1835 |
1808 TODO(pthatcher): Once have a way to handle network interfaces changes | 1836 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 | 1837 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 | 1838 mean time, this test only worked for GICE. With ICE, it's currently |
1811 not possible without an ICE restart. | 1839 not possible without an ICE restart. |
1812 | 1840 |
1813 // Test that we can switch links in a coordinated fashion. | 1841 // Test that we can switch links in a coordinated fashion. |
(...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2690 | 2718 |
2691 // TCP Relay/Relay is the next. | 2719 // TCP Relay/Relay is the next. |
2692 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, | 2720 VerifyNextPingableConnection(cricket::RELAY_PORT_TYPE, |
2693 cricket::RELAY_PORT_TYPE, | 2721 cricket::RELAY_PORT_TYPE, |
2694 cricket::TCP_PROTOCOL_NAME); | 2722 cricket::TCP_PROTOCOL_NAME); |
2695 | 2723 |
2696 // Finally, Local/Relay will be pinged. | 2724 // Finally, Local/Relay will be pinged. |
2697 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, | 2725 VerifyNextPingableConnection(cricket::LOCAL_PORT_TYPE, |
2698 cricket::RELAY_PORT_TYPE); | 2726 cricket::RELAY_PORT_TYPE); |
2699 } | 2727 } |
OLD | NEW |