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

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

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

Powered by Google App Engine
This is Rietveld 408576698