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

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

Issue 2224563004: Add signaling to support ICE renomination. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: . Created 4 years, 4 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
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005); 85 static const SocketAddress kRelaySslTcpExtAddr("99.99.99.3", 5005);
86 // The addresses for the public turn server. 86 // The addresses for the public turn server.
87 static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 87 static const SocketAddress kTurnUdpIntAddr("99.99.99.4",
88 cricket::STUN_SERVER_PORT); 88 cricket::STUN_SERVER_PORT);
89 static const SocketAddress kTurnTcpIntAddr("99.99.99.4", 89 static const SocketAddress kTurnTcpIntAddr("99.99.99.4",
90 cricket::STUN_SERVER_PORT + 1); 90 cricket::STUN_SERVER_PORT + 1);
91 static const SocketAddress kTurnUdpExtAddr("99.99.99.5", 0); 91 static const SocketAddress kTurnUdpExtAddr("99.99.99.5", 0);
92 static const cricket::RelayCredentials kRelayCredentials("test", "test"); 92 static const cricket::RelayCredentials kRelayCredentials("test", "test");
93 93
94 // Based on ICE_UFRAG_LENGTH 94 // Based on ICE_UFRAG_LENGTH
95 static const char* kIceUfrag[4] = {"UF00", "UF01", 95 const char* kIceUfrag[4] = {"UF00", "UF01", "UF02", "UF03"};
96 "UF02", "UF03"};
97 // Based on ICE_PWD_LENGTH 96 // Based on ICE_PWD_LENGTH
98 static const char* kIcePwd[4] = {"TESTICEPWD00000000000000", 97 const char* kIcePwd[4] = {
99 "TESTICEPWD00000000000001", 98 "TESTICEPWD00000000000000", "TESTICEPWD00000000000001",
100 "TESTICEPWD00000000000002", 99 "TESTICEPWD00000000000002", "TESTICEPWD00000000000003"};
101 "TESTICEPWD00000000000003"}; 100 const cricket::IceParameters kIceParams[4] = {
101 {kIceUfrag[0], kIcePwd[0], false},
102 {kIceUfrag[1], kIcePwd[1], false},
103 {kIceUfrag[2], kIcePwd[2], false},
104 {kIceUfrag[3], kIcePwd[3], false}};
102 105
103 static const uint64_t kLowTiebreaker = 11111; 106 const uint64_t kLowTiebreaker = 11111;
104 static const uint64_t kHighTiebreaker = 22222; 107 const uint64_t kHighTiebreaker = 22222;
105 108
106 enum { MSG_ADD_CANDIDATES, MSG_REMOVE_CANDIDATES }; 109 enum { MSG_ADD_CANDIDATES, MSG_REMOVE_CANDIDATES };
107 110
108 cricket::IceConfig CreateIceConfig( 111 cricket::IceConfig CreateIceConfig(
109 int receiving_timeout, 112 int receiving_timeout,
110 cricket::ContinualGatheringPolicy continual_gathering_policy, 113 cricket::ContinualGatheringPolicy continual_gathering_policy,
111 int backup_ping_interval = -1) { 114 int backup_ping_interval = -1) {
112 cricket::IceConfig config; 115 cricket::IceConfig config;
113 config.receiving_timeout = receiving_timeout; 116 config.receiving_timeout = receiving_timeout;
114 config.continual_gathering_policy = continual_gathering_policy; 117 config.continual_gathering_policy = continual_gathering_policy;
115 config.backup_connection_ping_interval = backup_ping_interval; 118 config.backup_connection_ping_interval = backup_ping_interval;
116 return config; 119 return config;
117 } 120 }
118 121
119 cricket::Candidate CreateUdpCandidate(const std::string& type, 122 cricket::Candidate CreateUdpCandidate(const std::string& type,
120 const std::string& ip, 123 const std::string& ip,
121 int port, 124 int port,
122 int priority, 125 int priority,
123 const std::string& ufrag = "") { 126 const std::string& ufrag = "") {
124 cricket::Candidate c; 127 cricket::Candidate c;
125 c.set_address(rtc::SocketAddress(ip, port)); 128 c.set_address(rtc::SocketAddress(ip, port));
126 c.set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT); 129 c.set_component(cricket::ICE_CANDIDATE_COMPONENT_DEFAULT);
127 c.set_protocol(cricket::UDP_PROTOCOL_NAME); 130 c.set_protocol(cricket::UDP_PROTOCOL_NAME);
128 c.set_priority(priority); 131 c.set_priority(priority);
129 c.set_username(ufrag); 132 c.set_username(ufrag);
130 c.set_type(type); 133 c.set_type(type);
131 return c; 134 return c;
132 } 135 }
133 136
134 } // namespace { 137 } // namespace
135 138
136 namespace cricket { 139 namespace cricket {
137 140
138 // This test simulates 2 P2P endpoints that want to establish connectivity 141 // This test simulates 2 P2P endpoints that want to establish connectivity
139 // with each other over various network topologies and conditions, which can be 142 // with each other over various network topologies and conditions, which can be
140 // specified in each individial test. 143 // specified in each individial test.
141 // A virtual network (via VirtualSocketServer) along with virtual firewalls and 144 // A virtual network (via VirtualSocketServer) along with virtual firewalls and
142 // NATs (via Firewall/NATSocketServer) are used to simulate the various network 145 // NATs (via Firewall/NATSocketServer) are used to simulate the various network
143 // conditions. We can configure the IP addresses of the endpoints, 146 // conditions. We can configure the IP addresses of the endpoints,
144 // block various types of connectivity, or add arbitrary levels of NAT. 147 // block various types of connectivity, or add arbitrary levels of NAT.
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 }; 301 };
299 302
300 ChannelData* GetChannelData(TransportChannel* channel) { 303 ChannelData* GetChannelData(TransportChannel* channel) {
301 if (ep1_.HasChannel(channel)) 304 if (ep1_.HasChannel(channel))
302 return ep1_.GetChannelData(channel); 305 return ep1_.GetChannelData(channel);
303 else 306 else
304 return ep2_.GetChannelData(channel); 307 return ep2_.GetChannelData(channel);
305 } 308 }
306 309
307 void CreateChannels(int num) { 310 void CreateChannels(int num) {
308 std::string ice_ufrag_ep1_cd1_ch = kIceUfrag[0]; 311 const IceParameters& ice_ep1_cd1_ch = kIceParams[0];
309 std::string ice_pwd_ep1_cd1_ch = kIcePwd[0]; 312 const IceParameters& ice_ep2_cd1_ch = kIceParams[1];
310 std::string ice_ufrag_ep2_cd1_ch = kIceUfrag[1]; 313 ep1_.cd1_.ch_.reset(CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT,
311 std::string ice_pwd_ep2_cd1_ch = kIcePwd[1]; 314 ice_ep1_cd1_ch, ice_ep2_cd1_ch));
312 ep1_.cd1_.ch_.reset(CreateChannel( 315 ep2_.cd1_.ch_.reset(CreateChannel(1, ICE_CANDIDATE_COMPONENT_DEFAULT,
313 0, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep1_cd1_ch, 316 ice_ep2_cd1_ch, ice_ep1_cd1_ch));
314 ice_pwd_ep1_cd1_ch, ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch));
315 ep2_.cd1_.ch_.reset(CreateChannel(
316 1, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep2_cd1_ch,
317 ice_pwd_ep2_cd1_ch, ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch));
318 ep1_.cd1_.ch_->MaybeStartGathering(); 317 ep1_.cd1_.ch_->MaybeStartGathering();
319 ep2_.cd1_.ch_->MaybeStartGathering(); 318 ep2_.cd1_.ch_->MaybeStartGathering();
320 if (num == 2) { 319 if (num == 2) {
321 std::string ice_ufrag_ep1_cd2_ch = kIceUfrag[2]; 320 const IceParameters& ice_ep1_cd2_ch = kIceParams[2];
322 std::string ice_pwd_ep1_cd2_ch = kIcePwd[2]; 321 const IceParameters& ice_ep2_cd2_ch = kIceParams[3];
323 std::string ice_ufrag_ep2_cd2_ch = kIceUfrag[3]; 322 ep1_.cd2_.ch_.reset(CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT,
324 std::string ice_pwd_ep2_cd2_ch = kIcePwd[3]; 323 ice_ep1_cd2_ch, ice_ep2_cd2_ch));
325 ep1_.cd2_.ch_.reset(CreateChannel( 324 ep2_.cd2_.ch_.reset(CreateChannel(1, ICE_CANDIDATE_COMPONENT_DEFAULT,
326 0, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep1_cd2_ch, 325 ice_ep2_cd2_ch, ice_ep1_cd2_ch));
327 ice_pwd_ep1_cd2_ch, ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch));
328 ep2_.cd2_.ch_.reset(CreateChannel(
329 1, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep2_cd2_ch,
330 ice_pwd_ep2_cd2_ch, ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch));
331 ep1_.cd2_.ch_->MaybeStartGathering(); 326 ep1_.cd2_.ch_->MaybeStartGathering();
332 ep2_.cd2_.ch_->MaybeStartGathering(); 327 ep2_.cd2_.ch_->MaybeStartGathering();
333 } 328 }
334 } 329 }
335 P2PTransportChannel* CreateChannel(int endpoint, 330 P2PTransportChannel* CreateChannel(int endpoint,
336 int component, 331 int component,
337 const std::string& local_ice_ufrag, 332 const IceParameters& local_ice,
338 const std::string& local_ice_pwd, 333 const IceParameters& remote_ice) {
339 const std::string& remote_ice_ufrag,
340 const std::string& remote_ice_pwd) {
341 P2PTransportChannel* channel = new P2PTransportChannel( 334 P2PTransportChannel* channel = new P2PTransportChannel(
342 "test content name", component, GetAllocator(endpoint)); 335 "test content name", component, GetAllocator(endpoint));
343 channel->SignalReadyToSend.connect( 336 channel->SignalReadyToSend.connect(
344 this, &P2PTransportChannelTestBase::OnReadyToSend); 337 this, &P2PTransportChannelTestBase::OnReadyToSend);
345 channel->SignalCandidateGathered.connect( 338 channel->SignalCandidateGathered.connect(
346 this, &P2PTransportChannelTestBase::OnCandidateGathered); 339 this, &P2PTransportChannelTestBase::OnCandidateGathered);
347 channel->SignalCandidatesRemoved.connect( 340 channel->SignalCandidatesRemoved.connect(
348 this, &P2PTransportChannelTestBase::OnCandidatesRemoved); 341 this, &P2PTransportChannelTestBase::OnCandidatesRemoved);
349 channel->SignalReadPacket.connect( 342 channel->SignalReadPacket.connect(
350 this, &P2PTransportChannelTestBase::OnReadPacket); 343 this, &P2PTransportChannelTestBase::OnReadPacket);
351 channel->SignalRoleConflict.connect( 344 channel->SignalRoleConflict.connect(
352 this, &P2PTransportChannelTestBase::OnRoleConflict); 345 this, &P2PTransportChannelTestBase::OnRoleConflict);
353 channel->SignalSelectedCandidatePairChanged.connect( 346 channel->SignalSelectedCandidatePairChanged.connect(
354 this, &P2PTransportChannelTestBase::OnSelectedCandidatePairChanged); 347 this, &P2PTransportChannelTestBase::OnSelectedCandidatePairChanged);
355 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); 348 channel->SetIceParameters(local_ice);
356 if (remote_ice_credential_source_ == FROM_SETICECREDENTIALS) { 349 if (remote_ice_parameter_source_ == FROM_SETICEPARAMETERS) {
357 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd); 350 channel->SetRemoteIceParameters(remote_ice);
358 } 351 }
359 channel->SetIceRole(GetEndpoint(endpoint)->ice_role()); 352 channel->SetIceRole(GetEndpoint(endpoint)->ice_role());
360 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker()); 353 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker());
361 return channel; 354 return channel;
362 } 355 }
363 void DestroyChannels() { 356 void DestroyChannels() {
364 ep1_.cd1_.ch_.reset(); 357 ep1_.cd1_.ch_.reset();
365 ep2_.cd1_.ch_.reset(); 358 ep2_.cd1_.ch_.reset();
366 ep1_.cd2_.ch_.reset(); 359 ep1_.cd2_.ch_.reset();
367 ep2_.cd2_.ch_.reset(); 360 ep2_.cd2_.ch_.reset();
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 // local_channel2 <==> remote_channel2 594 // local_channel2 <==> remote_channel2
602 EXPECT_EQ_WAIT(len, SendData(ep1_ch2(), data, len), 1000); 595 EXPECT_EQ_WAIT(len, SendData(ep1_ch2(), data, len), 1000);
603 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch2(), data, len), 1000); 596 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch2(), data, len), 1000);
604 EXPECT_EQ_WAIT(len, SendData(ep2_ch2(), data, len), 1000); 597 EXPECT_EQ_WAIT(len, SendData(ep2_ch2(), data, len), 1000);
605 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep1_ch2(), data, len), 1000); 598 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep1_ch2(), data, len), 1000);
606 } 599 }
607 } 600 }
608 } 601 }
609 602
610 // This test waits for the transport to become receiving and writable on both 603 // This test waits for the transport to become receiving and writable on both
611 // end points. Once they are, the end points set new local ice credentials and 604 // end points. Once they are, the end points set new local ice parameters and
612 // restart the ice gathering. Finally it waits for the transport to select a 605 // restart the ice gathering. Finally it waits for the transport to select a
613 // new connection using the newly generated ice candidates. 606 // new connection using the newly generated ice candidates.
614 // Before calling this function the end points must be configured. 607 // Before calling this function the end points must be configured.
615 void TestHandleIceUfragPasswordChanged() { 608 void TestHandleIceUfragPasswordChanged() {
616 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 609 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]);
617 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); 610 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]);
618 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && 611 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
619 ep2_ch1()->receiving() && ep2_ch1()->writable(), 612 ep2_ch1()->receiving() && ep2_ch1()->writable(),
620 1000, 1000); 613 1000, 1000);
621 614
622 const Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1()); 615 const Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1());
623 const Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1()); 616 const Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1());
624 const Candidate* old_remote_candidate1 = RemoteCandidate(ep1_ch1()); 617 const Candidate* old_remote_candidate1 = RemoteCandidate(ep1_ch1());
625 const Candidate* old_remote_candidate2 = RemoteCandidate(ep2_ch1()); 618 const Candidate* old_remote_candidate2 = RemoteCandidate(ep2_ch1());
626 619
627 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); 620 ep1_ch1()->SetIceParameters(kIceParams[2]);
628 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 621 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
629 ep1_ch1()->MaybeStartGathering(); 622 ep1_ch1()->MaybeStartGathering();
630 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]); 623 ep2_ch1()->SetIceParameters(kIceParams[3]);
631 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); 624
625 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]);
632 ep2_ch1()->MaybeStartGathering(); 626 ep2_ch1()->MaybeStartGathering();
633 627
634 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() != 628 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() !=
635 old_local_candidate1->generation(), 629 old_local_candidate1->generation(),
636 1000, 1000); 630 1000, 1000);
637 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep2_ch1())->generation() != 631 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep2_ch1())->generation() !=
638 old_local_candidate2->generation(), 632 old_local_candidate2->generation(),
639 1000, 1000); 633 1000, 1000);
640 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep1_ch1())->generation() != 634 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep1_ch1())->generation() !=
641 old_remote_candidate1->generation(), 635 old_remote_candidate1->generation(),
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 void OnMessage(rtc::Message* msg) { 738 void OnMessage(rtc::Message* msg) {
745 switch (msg->message_id) { 739 switch (msg->message_id) {
746 case MSG_ADD_CANDIDATES: { 740 case MSG_ADD_CANDIDATES: {
747 std::unique_ptr<CandidatesData> data( 741 std::unique_ptr<CandidatesData> data(
748 static_cast<CandidatesData*>(msg->pdata)); 742 static_cast<CandidatesData*>(msg->pdata));
749 P2PTransportChannel* rch = GetRemoteChannel(data->channel); 743 P2PTransportChannel* rch = GetRemoteChannel(data->channel);
750 if (!rch) { 744 if (!rch) {
751 return; 745 return;
752 } 746 }
753 for (auto& c : data->candidates) { 747 for (auto& c : data->candidates) {
754 if (remote_ice_credential_source_ != FROM_CANDIDATE) { 748 if (remote_ice_parameter_source_ != FROM_CANDIDATE) {
755 c.set_username(""); 749 c.set_username("");
756 c.set_password(""); 750 c.set_password("");
757 } 751 }
758 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->" 752 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->"
759 << rch->component() << "): " << c.ToString(); 753 << rch->component() << "): " << c.ToString();
760 rch->AddRemoteCandidate(c); 754 rch->AddRemoteCandidate(c);
761 } 755 }
762 break; 756 break;
763 } 757 }
764 case MSG_REMOVE_CANDIDATES: { 758 case MSG_REMOVE_CANDIDATES: {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 return ep1_ch1(); 823 return ep1_ch1();
830 else if (ch == ep2_ch2()) 824 else if (ch == ep2_ch2())
831 return ep1_ch2(); 825 return ep1_ch2();
832 else 826 else
833 return NULL; 827 return NULL;
834 } 828 }
835 std::list<std::string>& GetPacketList(TransportChannel* ch) { 829 std::list<std::string>& GetPacketList(TransportChannel* ch) {
836 return GetChannelData(ch)->ch_packets_; 830 return GetChannelData(ch)->ch_packets_;
837 } 831 }
838 832
839 enum RemoteIceCredentialSource { FROM_CANDIDATE, FROM_SETICECREDENTIALS }; 833 enum RemoteIceParameterSource { FROM_CANDIDATE, FROM_SETICEPARAMETERS };
840 834
841 // How does the test pass ICE credentials to the P2PTransportChannel? 835 // How does the test pass ICE parameters to the P2PTransportChannel?
842 // On the candidate itself, or through SetIceCredentials? 836 // On the candidate itself, or through SetRemoteIceParameters?
843 // Goes through the candidate itself by default. 837 // Goes through the candidate itself by default.
844 void set_remote_ice_credential_source(RemoteIceCredentialSource source) { 838 void set_remote_ice_parameter_source(RemoteIceParameterSource source) {
845 remote_ice_credential_source_ = source; 839 remote_ice_parameter_source_ = source;
846 } 840 }
847 841
848 void set_force_relay(bool relay) { 842 void set_force_relay(bool relay) {
849 force_relay_ = relay; 843 force_relay_ = relay;
850 } 844 }
851 845
852 void ConnectSignalNominated(Connection* conn) { 846 void ConnectSignalNominated(Connection* conn) {
853 conn->SignalNominated.connect(this, 847 conn->SignalNominated.connect(this,
854 &P2PTransportChannelTestBase::OnNominated); 848 &P2PTransportChannelTestBase::OnNominated);
855 } 849 }
856 850
857 void OnNominated(Connection* conn) { nominated_ = true; } 851 void OnNominated(Connection* conn) { nominated_ = true; }
858 bool nominated() { return nominated_; } 852 bool nominated() { return nominated_; }
859 853
860 private: 854 private:
861 rtc::Thread* main_; 855 rtc::Thread* main_;
862 std::unique_ptr<rtc::PhysicalSocketServer> pss_; 856 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
863 std::unique_ptr<rtc::VirtualSocketServer> vss_; 857 std::unique_ptr<rtc::VirtualSocketServer> vss_;
864 std::unique_ptr<rtc::NATSocketServer> nss_; 858 std::unique_ptr<rtc::NATSocketServer> nss_;
865 std::unique_ptr<rtc::FirewallSocketServer> ss_; 859 std::unique_ptr<rtc::FirewallSocketServer> ss_;
866 rtc::SocketServerScope ss_scope_; 860 rtc::SocketServerScope ss_scope_;
867 std::unique_ptr<TestStunServer> stun_server_; 861 std::unique_ptr<TestStunServer> stun_server_;
868 TestTurnServer turn_server_; 862 TestTurnServer turn_server_;
869 TestRelayServer relay_server_; 863 TestRelayServer relay_server_;
870 rtc::SocksProxyServer socks_server1_; 864 rtc::SocksProxyServer socks_server1_;
871 rtc::SocksProxyServer socks_server2_; 865 rtc::SocksProxyServer socks_server2_;
872 Endpoint ep1_; 866 Endpoint ep1_;
873 Endpoint ep2_; 867 Endpoint ep2_;
874 RemoteIceCredentialSource remote_ice_credential_source_ = FROM_CANDIDATE; 868 RemoteIceParameterSource remote_ice_parameter_source_ = FROM_CANDIDATE;
875 bool force_relay_; 869 bool force_relay_;
876 int selected_candidate_pair_switches_ = 0; 870 int selected_candidate_pair_switches_ = 0;
877 871
878 bool nominated_ = false; 872 bool nominated_ = false;
879 }; 873 };
880 874
881 // The tests have only a few outcomes, which we predefine. 875 // The tests have only a few outcomes, which we predefine.
882 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase:: 876 const P2PTransportChannelTestBase::Result P2PTransportChannelTestBase::
883 kLocalUdpToLocalUdp("local", "udp", "local", "udp", 877 kLocalUdpToLocalUdp("local", "udp", "local", "udp",
884 "local", "udp", "local", "udp", 1000); 878 "local", "udp", "local", "udp", 1000);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 GetEndpoint(1)->allocator_->AddTurnServer(turn_server); 936 GetEndpoint(1)->allocator_->AddTurnServer(turn_server);
943 937
944 int delay = kMinimumStepDelay; 938 int delay = kMinimumStepDelay;
945 ConfigureEndpoint(0, config1); 939 ConfigureEndpoint(0, config1);
946 SetAllocatorFlags(0, allocator_flags1); 940 SetAllocatorFlags(0, allocator_flags1);
947 SetAllocationStepDelay(0, delay); 941 SetAllocationStepDelay(0, delay);
948 ConfigureEndpoint(1, config2); 942 ConfigureEndpoint(1, config2);
949 SetAllocatorFlags(1, allocator_flags2); 943 SetAllocatorFlags(1, allocator_flags2);
950 SetAllocationStepDelay(1, delay); 944 SetAllocationStepDelay(1, delay);
951 945
952 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); 946 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS);
953 } 947 }
954 void ConfigureEndpoint(int endpoint, Config config) { 948 void ConfigureEndpoint(int endpoint, Config config) {
955 switch (config) { 949 switch (config) {
956 case OPEN: 950 case OPEN:
957 AddAddress(endpoint, kPublicAddrs[endpoint]); 951 AddAddress(endpoint, kPublicAddrs[endpoint]);
958 break; 952 break;
959 case NAT_FULL_CONE: 953 case NAT_FULL_CONE:
960 case NAT_ADDR_RESTRICTED: 954 case NAT_ADDR_RESTRICTED:
961 case NAT_PORT_RESTRICTED: 955 case NAT_PORT_RESTRICTED:
962 case NAT_SYMMETRIC: 956 case NAT_SYMMETRIC:
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 EXPECT_EQ(10 * 36U, best_conn_info->recv_total_bytes); 1149 EXPECT_EQ(10 * 36U, best_conn_info->recv_total_bytes);
1156 EXPECT_GT(best_conn_info->rtt, 0U); 1150 EXPECT_GT(best_conn_info->rtt, 0U);
1157 DestroyChannels(); 1151 DestroyChannels();
1158 } 1152 }
1159 1153
1160 // Test that we properly create a connection on a STUN ping from unknown address 1154 // Test that we properly create a connection on a STUN ping from unknown address
1161 // when the signaling is slow. 1155 // when the signaling is slow.
1162 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) { 1156 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) {
1163 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1157 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1164 kDefaultPortAllocatorFlags); 1158 kDefaultPortAllocatorFlags);
1165 // Emulate no remote credentials coming in. 1159 // Emulate no remote parameters coming in.
1166 set_remote_ice_credential_source(FROM_CANDIDATE); 1160 set_remote_ice_parameter_source(FROM_CANDIDATE);
1167 CreateChannels(1); 1161 CreateChannels(1);
1168 // Only have remote credentials come in for ep2, not ep1. 1162 // Only have remote parameters come in for ep2, not ep1.
1169 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); 1163 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]);
1170 1164
1171 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive 1165 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive
1172 // candidate. 1166 // candidate.
1173 PauseCandidates(1); 1167 PauseCandidates(1);
1174 1168
1175 // The caller should have the selected connection connected to the peer 1169 // The caller should have the selected connection connected to the peer
1176 // reflexive candidate. 1170 // reflexive candidate.
1177 const Connection* selected_connection = NULL; 1171 const Connection* selected_connection = NULL;
1178 WAIT((selected_connection = ep1_ch1()->selected_connection()) != NULL, 2000); 1172 WAIT((selected_connection = ep1_ch1()->selected_connection()) != NULL, 2000);
1179 EXPECT_EQ("prflx", 1173 EXPECT_EQ("prflx",
1180 ep1_ch1()->selected_connection()->remote_candidate().type()); 1174 ep1_ch1()->selected_connection()->remote_candidate().type());
1181 1175
1182 // Because we don't have a remote pwd, we don't ping yet. 1176 // Because we don't have a remote pwd, we don't ping yet.
1183 EXPECT_EQ(kIceUfrag[1], 1177 EXPECT_EQ(kIceUfrag[1],
1184 ep1_ch1()->selected_connection()->remote_candidate().username()); 1178 ep1_ch1()->selected_connection()->remote_candidate().username());
1185 EXPECT_EQ("", 1179 EXPECT_EQ("",
1186 ep1_ch1()->selected_connection()->remote_candidate().password()); 1180 ep1_ch1()->selected_connection()->remote_candidate().password());
1187 // Because we don't have ICE credentials yet, we don't know the generation. 1181 // Because we don't have ICE parameters yet, we don't know the generation.
1188 EXPECT_EQ(0u, 1182 EXPECT_EQ(0u,
1189 ep1_ch1()->selected_connection()->remote_candidate().generation()); 1183 ep1_ch1()->selected_connection()->remote_candidate().generation());
1190 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); 1184 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection());
1191 1185
1192 // Add two sets of remote ICE credentials, so that the ones used by the 1186 // Add two sets of remote ICE parameters, so that the ones used by the
1193 // candidate will be generation 1 instead of 0. 1187 // candidate will be generation 1 instead of 0.
1194 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 1188 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
1195 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 1189 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]);
1196 // After setting the remote ICE credentials, the password and generation 1190
1191 // After setting the remote ICE parameters, the password and generation
1197 // of the peer reflexive candidate should be updated. 1192 // of the peer reflexive candidate should be updated.
1198 EXPECT_EQ(kIcePwd[1], 1193 EXPECT_EQ(kIcePwd[1],
1199 ep1_ch1()->selected_connection()->remote_candidate().password()); 1194 ep1_ch1()->selected_connection()->remote_candidate().password());
1200 EXPECT_EQ(1u, 1195 EXPECT_EQ(1u,
1201 ep1_ch1()->selected_connection()->remote_candidate().generation()); 1196 ep1_ch1()->selected_connection()->remote_candidate().generation());
1202 EXPECT_TRUE(nullptr != ep1_ch1()->FindNextPingableConnection()); 1197 EXPECT_TRUE(nullptr != ep1_ch1()->FindNextPingableConnection());
1203 1198
1204 ResumeCandidates(1); 1199 ResumeCandidates(1);
1205 1200
1206 WAIT(ep2_ch1()->selected_connection() != NULL, 2000); 1201 WAIT(ep2_ch1()->selected_connection() != NULL, 2000);
1207 // Verify ep1's selected connection is updated to use the 'local' candidate. 1202 // Verify ep1's selected connection is updated to use the 'local' candidate.
1208 EXPECT_EQ_WAIT("local", 1203 EXPECT_EQ_WAIT("local",
1209 ep1_ch1()->selected_connection()->remote_candidate().type(), 1204 ep1_ch1()->selected_connection()->remote_candidate().type(),
1210 2000); 1205 2000);
1211 EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection()); 1206 EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection());
1212 DestroyChannels(); 1207 DestroyChannels();
1213 } 1208 }
1214 1209
1215 // Test that we properly create a connection on a STUN ping from unknown address 1210 // Test that we properly create a connection on a STUN ping from unknown address
1216 // when the signaling is slow and the end points are behind NAT. 1211 // when the signaling is slow and the end points are behind NAT.
1217 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { 1212 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) {
1218 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, 1213 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags,
1219 kDefaultPortAllocatorFlags); 1214 kDefaultPortAllocatorFlags);
1220 // Emulate no remote credentials coming in. 1215 // Emulate no remote parameters coming in.
1221 set_remote_ice_credential_source(FROM_CANDIDATE); 1216 set_remote_ice_parameter_source(FROM_CANDIDATE);
1222 CreateChannels(1); 1217 CreateChannels(1);
1223 // Only have remote credentials come in for ep2, not ep1. 1218 // Only have remote parameters come in for ep2, not ep1.
1224 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); 1219 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]);
1225 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive 1220 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive
1226 // candidate. 1221 // candidate.
1227 PauseCandidates(1); 1222 PauseCandidates(1);
1228 1223
1229 // The caller should have the selected connection connected to the peer 1224 // The caller should have the selected connection connected to the peer
1230 // reflexive candidate. 1225 // reflexive candidate.
1231 WAIT(ep1_ch1()->selected_connection() != NULL, 2000); 1226 WAIT(ep1_ch1()->selected_connection() != NULL, 2000);
1232 EXPECT_EQ("prflx", 1227 EXPECT_EQ("prflx",
1233 ep1_ch1()->selected_connection()->remote_candidate().type()); 1228 ep1_ch1()->selected_connection()->remote_candidate().type());
1234 1229
1235 // Because we don't have a remote pwd, we don't ping yet. 1230 // Because we don't have a remote pwd, we don't ping yet.
1236 EXPECT_EQ(kIceUfrag[1], 1231 EXPECT_EQ(kIceUfrag[1],
1237 ep1_ch1()->selected_connection()->remote_candidate().username()); 1232 ep1_ch1()->selected_connection()->remote_candidate().username());
1238 EXPECT_EQ("", 1233 EXPECT_EQ("",
1239 ep1_ch1()->selected_connection()->remote_candidate().password()); 1234 ep1_ch1()->selected_connection()->remote_candidate().password());
1240 // Because we don't have ICE credentials yet, we don't know the generation. 1235 // Because we don't have ICE parameters yet, we don't know the generation.
1241 EXPECT_EQ(0u, 1236 EXPECT_EQ(0u,
1242 ep1_ch1()->selected_connection()->remote_candidate().generation()); 1237 ep1_ch1()->selected_connection()->remote_candidate().generation());
1243 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); 1238 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection());
1244 1239
1245 // Add two sets of remote ICE credentials, so that the ones used by the 1240 // Add two sets of remote ICE parameters, so that the ones used by the
1246 // candidate will be generation 1 instead of 0. 1241 // candidate will be generation 1 instead of 0.
1247 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 1242 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
1248 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 1243 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]);
1249 // After setting the remote ICE credentials, the password and generation 1244 // After setting the remote ICE parameters, the password and generation
1250 // of the peer reflexive candidate should be updated. 1245 // of the peer reflexive candidate should be updated.
1251 EXPECT_EQ(kIcePwd[1], 1246 EXPECT_EQ(kIcePwd[1],
1252 ep1_ch1()->selected_connection()->remote_candidate().password()); 1247 ep1_ch1()->selected_connection()->remote_candidate().password());
1253 EXPECT_EQ(1u, 1248 EXPECT_EQ(1u,
1254 ep1_ch1()->selected_connection()->remote_candidate().generation()); 1249 ep1_ch1()->selected_connection()->remote_candidate().generation());
1255 1250
1256 ResumeCandidates(1); 1251 ResumeCandidates(1);
1257 1252
1258 const Connection* selected_connection = NULL; 1253 const Connection* selected_connection = NULL;
1259 WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 2000); 1254 WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 2000);
(...skipping 16 matching lines...) Expand all
1276 // generations. This resulted in the old-generation prflx candidate being 1271 // generations. This resulted in the old-generation prflx candidate being
1277 // prioritized above new-generation candidate pairs. 1272 // prioritized above new-generation candidate pairs.
1278 TEST_F(P2PTransportChannelTest, 1273 TEST_F(P2PTransportChannelTest,
1279 PeerReflexiveCandidateBeforeSignalingWithIceRestart) { 1274 PeerReflexiveCandidateBeforeSignalingWithIceRestart) {
1280 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1275 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1281 kDefaultPortAllocatorFlags); 1276 kDefaultPortAllocatorFlags);
1282 // Only gather relay candidates, so that when the prflx candidate arrives 1277 // Only gather relay candidates, so that when the prflx candidate arrives
1283 // it's prioritized above the current candidate pair. 1278 // it's prioritized above the current candidate pair.
1284 GetEndpoint(0)->allocator_->set_candidate_filter(CF_RELAY); 1279 GetEndpoint(0)->allocator_->set_candidate_filter(CF_RELAY);
1285 GetEndpoint(1)->allocator_->set_candidate_filter(CF_RELAY); 1280 GetEndpoint(1)->allocator_->set_candidate_filter(CF_RELAY);
1286 // Setting this allows us to control when SetRemoteIceCredentials is called. 1281 // Setting this allows us to control when SetRemoteIceParameters is called.
1287 set_remote_ice_credential_source(FROM_CANDIDATE); 1282 set_remote_ice_parameter_source(FROM_CANDIDATE);
1288 CreateChannels(1); 1283 CreateChannels(1);
1289 // Wait for the initial connection to be made. 1284 // Wait for the initial connection to be made.
1290 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 1285 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]);
1291 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); 1286 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]);
1292 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1287 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1293 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1288 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1294 kDefaultTimeout); 1289 kDefaultTimeout);
1295 1290
1296 // Simulate an ICE restart on ep2, but don't signal the candidate or new 1291 // Simulate an ICE restart on ep2, but don't signal the candidate or new
1297 // ICE credentials until after a prflx connection has been made. 1292 // ICE parameters until after a prflx connection has been made.
1298 PauseCandidates(1); 1293 PauseCandidates(1);
1299 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]); 1294 ep2_ch1()->SetIceParameters(kIceParams[3]);
1300 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 1295
1296 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
1301 ep2_ch1()->MaybeStartGathering(); 1297 ep2_ch1()->MaybeStartGathering();
1302 1298
1303 // The caller should have the selected connection connected to the peer 1299 // The caller should have the selected connection connected to the peer
1304 // reflexive candidate. 1300 // reflexive candidate.
1305 EXPECT_EQ_WAIT("prflx", 1301 EXPECT_EQ_WAIT("prflx",
1306 ep1_ch1()->selected_connection()->remote_candidate().type(), 1302 ep1_ch1()->selected_connection()->remote_candidate().type(),
1307 kDefaultTimeout); 1303 kDefaultTimeout);
1308 const Connection* prflx_selected_connection = 1304 const Connection* prflx_selected_connection =
1309 ep1_ch1()->selected_connection(); 1305 ep1_ch1()->selected_connection();
1310 1306
1311 // Now simulate the ICE restart on ep1. 1307 // Now simulate the ICE restart on ep1.
1312 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); 1308 ep1_ch1()->SetIceParameters(kIceParams[2]);
1313 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); 1309
1310 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]);
1314 ep1_ch1()->MaybeStartGathering(); 1311 ep1_ch1()->MaybeStartGathering();
1315 1312
1316 // Finally send the candidates from ep2's ICE restart and verify that ep1 uses 1313 // Finally send the candidates from ep2's ICE restart and verify that ep1 uses
1317 // their information to update the peer reflexive candidate. 1314 // their information to update the peer reflexive candidate.
1318 ResumeCandidates(1); 1315 ResumeCandidates(1);
1319 1316
1320 EXPECT_EQ_WAIT("relay", 1317 EXPECT_EQ_WAIT("relay",
1321 ep1_ch1()->selected_connection()->remote_candidate().type(), 1318 ep1_ch1()->selected_connection()->remote_candidate().type(),
1322 kDefaultTimeout); 1319 kDefaultTimeout);
1323 EXPECT_EQ(prflx_selected_connection, ep1_ch1()->selected_connection()); 1320 EXPECT_EQ(prflx_selected_connection, ep1_ch1()->selected_connection());
1324 DestroyChannels(); 1321 DestroyChannels();
1325 } 1322 }
1326 1323
1327 // Test that if remote candidates don't have ufrag and pwd, we still work. 1324 // Test that if remote candidates don't have ufrag and pwd, we still work.
1328 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) { 1325 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) {
1329 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); 1326 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS);
1330 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1327 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1331 kDefaultPortAllocatorFlags); 1328 kDefaultPortAllocatorFlags);
1332 CreateChannels(1); 1329 CreateChannels(1);
1333 const Connection* selected_connection = NULL; 1330 const Connection* selected_connection = NULL;
1334 // Wait until the callee's connections are created. 1331 // Wait until the callee's connections are created.
1335 WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 1000); 1332 WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 1000);
1336 // Wait to see if they get culled; they shouldn't. 1333 // Wait to see if they get culled; they shouldn't.
1337 WAIT(ep2_ch1()->selected_connection() != selected_connection, 1000); 1334 WAIT(ep2_ch1()->selected_connection() != selected_connection, 1000);
1338 EXPECT_TRUE(ep2_ch1()->selected_connection() == selected_connection); 1335 EXPECT_TRUE(ep2_ch1()->selected_connection() == selected_connection);
1339 DestroyChannels(); 1336 DestroyChannels();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 int kOnlyLocalTcpPorts = PORTALLOCATOR_DISABLE_UDP | 1385 int kOnlyLocalTcpPorts = PORTALLOCATOR_DISABLE_UDP |
1389 PORTALLOCATOR_DISABLE_STUN | 1386 PORTALLOCATOR_DISABLE_STUN |
1390 PORTALLOCATOR_DISABLE_RELAY; 1387 PORTALLOCATOR_DISABLE_RELAY;
1391 // Disable all protocols except TCP. 1388 // Disable all protocols except TCP.
1392 SetAllocatorFlags(0, kOnlyLocalTcpPorts); 1389 SetAllocatorFlags(0, kOnlyLocalTcpPorts);
1393 SetAllocatorFlags(1, kOnlyLocalTcpPorts); 1390 SetAllocatorFlags(1, kOnlyLocalTcpPorts);
1394 1391
1395 SetAllowTcpListen(0, true); // actpass. 1392 SetAllowTcpListen(0, true); // actpass.
1396 SetAllowTcpListen(1, false); // active. 1393 SetAllowTcpListen(1, false); // active.
1397 1394
1398 // We want SetRemoteIceCredentials to be called as it normally would. 1395 // We want SetRemoteIceParameters to be called as it normally would.
1399 // Otherwise we won't know what credentials to use for the expected 1396 // Otherwise we won't know what parameters to use for the expected
1400 // prflx TCP candidates. 1397 // prflx TCP candidates.
1401 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); 1398 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS);
1402 1399
1403 // Pause candidate so we could verify the candidate properties. 1400 // Pause candidate so we could verify the candidate properties.
1404 PauseCandidates(0); 1401 PauseCandidates(0);
1405 PauseCandidates(1); 1402 PauseCandidates(1);
1406 CreateChannels(1); 1403 CreateChannels(1);
1407 1404
1408 // Verify tcp candidates. 1405 // Verify tcp candidates.
1409 VerifySavedTcpCandidates(0, TCPTYPE_PASSIVE_STR); 1406 VerifySavedTcpCandidates(0, TCPTYPE_PASSIVE_STR);
1410 VerifySavedTcpCandidates(1, TCPTYPE_ACTIVE_STR); 1407 VerifySavedTcpCandidates(1, TCPTYPE_ACTIVE_STR);
1411 1408
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 } 1674 }
1678 1675
1679 // Test that when the "presume_writable_when_fully_relayed" flag is set to 1676 // Test that when the "presume_writable_when_fully_relayed" flag is set to
1680 // true and there's a TURN-TURN candidate pair, it's presumed to be writable 1677 // true and there's a TURN-TURN candidate pair, it's presumed to be writable
1681 // as soon as it's created. 1678 // as soon as it's created.
1682 TEST_F(P2PTransportChannelTest, TurnToTurnPresumedWritable) { 1679 TEST_F(P2PTransportChannelTest, TurnToTurnPresumedWritable) {
1683 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1680 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1684 kDefaultPortAllocatorFlags); 1681 kDefaultPortAllocatorFlags);
1685 // Only configure one channel so we can control when the remote candidate 1682 // Only configure one channel so we can control when the remote candidate
1686 // is added. 1683 // is added.
1687 GetEndpoint(0)->cd1_.ch_.reset( 1684 GetEndpoint(0)->cd1_.ch_.reset(CreateChannel(
1688 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0], 1685 0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[0], kIceParams[1]));
1689 kIcePwd[0], kIceUfrag[1], kIcePwd[1]));
1690 IceConfig config; 1686 IceConfig config;
1691 config.presume_writable_when_fully_relayed = true; 1687 config.presume_writable_when_fully_relayed = true;
1692 ep1_ch1()->SetIceConfig(config); 1688 ep1_ch1()->SetIceConfig(config);
1693 ep1_ch1()->MaybeStartGathering(); 1689 ep1_ch1()->MaybeStartGathering();
1694 EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, 1690 EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete,
1695 ep1_ch1()->gathering_state(), kDefaultTimeout); 1691 ep1_ch1()->gathering_state(), kDefaultTimeout);
1696 // Add two remote candidates; a host candidate (with higher priority) 1692 // Add two remote candidates; a host candidate (with higher priority)
1697 // and TURN candidate. 1693 // and TURN candidate.
1698 ep1_ch1()->AddRemoteCandidate( 1694 ep1_ch1()->AddRemoteCandidate(
1699 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 1695 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
(...skipping 25 matching lines...) Expand all
1725 virtual_socket_server()->UpdateDelayDistribution(); 1721 virtual_socket_server()->UpdateDelayDistribution();
1726 1722
1727 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, 1723 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags,
1728 kDefaultPortAllocatorFlags); 1724 kDefaultPortAllocatorFlags);
1729 // We want the remote TURN candidate to show up as prflx. To do this we need 1725 // We want the remote TURN candidate to show up as prflx. To do this we need
1730 // to configure the server to accept packets from an address we haven't 1726 // to configure the server to accept packets from an address we haven't
1731 // explicitly installed permission for. 1727 // explicitly installed permission for.
1732 test_turn_server()->set_enable_permission_checks(false); 1728 test_turn_server()->set_enable_permission_checks(false);
1733 IceConfig config; 1729 IceConfig config;
1734 config.presume_writable_when_fully_relayed = true; 1730 config.presume_writable_when_fully_relayed = true;
1735 GetEndpoint(0)->cd1_.ch_.reset( 1731 GetEndpoint(0)->cd1_.ch_.reset(CreateChannel(
1736 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0], 1732 0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[0], kIceParams[1]));
1737 kIcePwd[0], kIceUfrag[1], kIcePwd[1])); 1733 GetEndpoint(1)->cd1_.ch_.reset(CreateChannel(
1738 GetEndpoint(1)->cd1_.ch_.reset( 1734 1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[1], kIceParams[0]));
1739 CreateChannel(1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[1],
1740 kIcePwd[1], kIceUfrag[0], kIcePwd[0]));
1741 ep1_ch1()->SetIceConfig(config); 1735 ep1_ch1()->SetIceConfig(config);
1742 ep2_ch1()->SetIceConfig(config); 1736 ep2_ch1()->SetIceConfig(config);
1743 // Don't signal candidates from channel 2, so that channel 1 sees the TURN 1737 // Don't signal candidates from channel 2, so that channel 1 sees the TURN
1744 // candidate as peer reflexive. 1738 // candidate as peer reflexive.
1745 PauseCandidates(1); 1739 PauseCandidates(1);
1746 ep1_ch1()->MaybeStartGathering(); 1740 ep1_ch1()->MaybeStartGathering();
1747 ep2_ch1()->MaybeStartGathering(); 1741 ep2_ch1()->MaybeStartGathering();
1748 1742
1749 // Wait for the TURN<->prflx connection. 1743 // Wait for the TURN<->prflx connection.
1750 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable(), 1744 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable(),
(...skipping 15 matching lines...) Expand all
1766 1760
1767 // Test that a presumed-writable TURN<->TURN connection is preferred above an 1761 // Test that a presumed-writable TURN<->TURN connection is preferred above an
1768 // unreliable connection (one that has failed to be pinged for some time). 1762 // unreliable connection (one that has failed to be pinged for some time).
1769 TEST_F(P2PTransportChannelTest, PresumedWritablePreferredOverUnreliable) { 1763 TEST_F(P2PTransportChannelTest, PresumedWritablePreferredOverUnreliable) {
1770 rtc::ScopedFakeClock fake_clock; 1764 rtc::ScopedFakeClock fake_clock;
1771 1765
1772 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, 1766 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags,
1773 kDefaultPortAllocatorFlags); 1767 kDefaultPortAllocatorFlags);
1774 IceConfig config; 1768 IceConfig config;
1775 config.presume_writable_when_fully_relayed = true; 1769 config.presume_writable_when_fully_relayed = true;
1776 GetEndpoint(0)->cd1_.ch_.reset( 1770 GetEndpoint(0)->cd1_.ch_.reset(CreateChannel(
1777 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0], 1771 0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[0], kIceParams[1]));
1778 kIcePwd[0], kIceUfrag[1], kIcePwd[1])); 1772 GetEndpoint(1)->cd1_.ch_.reset(CreateChannel(
1779 GetEndpoint(1)->cd1_.ch_.reset( 1773 1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[1], kIceParams[0]));
1780 CreateChannel(1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[1],
1781 kIcePwd[1], kIceUfrag[0], kIcePwd[0]));
1782 ep1_ch1()->SetIceConfig(config); 1774 ep1_ch1()->SetIceConfig(config);
1783 ep2_ch1()->SetIceConfig(config); 1775 ep2_ch1()->SetIceConfig(config);
1784 ep1_ch1()->MaybeStartGathering(); 1776 ep1_ch1()->MaybeStartGathering();
1785 ep2_ch1()->MaybeStartGathering(); 1777 ep2_ch1()->MaybeStartGathering();
1786 // Wait for initial connection as usual. 1778 // Wait for initial connection as usual.
1787 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1779 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1788 ep1_ch1()->selected_connection()->writable() && 1780 ep1_ch1()->selected_connection()->writable() &&
1789 ep2_ch1()->receiving() && 1781 ep2_ch1()->receiving() &&
1790 ep2_ch1()->writable() && 1782 ep2_ch1()->writable() &&
1791 ep2_ch1()->selected_connection()->writable(), 1783 ep2_ch1()->selected_connection()->writable(),
(...skipping 22 matching lines...) Expand all
1814 // address of the outermost NAT. 1806 // address of the outermost NAT.
1815 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase { 1807 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase {
1816 protected: 1808 protected:
1817 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) { 1809 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) {
1818 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC); 1810 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC);
1819 rtc::NATSocketServer::Translator* outer_nat = 1811 rtc::NATSocketServer::Translator* outer_nat =
1820 nat()->AddTranslator(kPublicAddrs[0], kNatAddrs[0], 1812 nat()->AddTranslator(kPublicAddrs[0], kNatAddrs[0],
1821 static_cast<rtc::NATType>(nat_type - NAT_FULL_CONE)); 1813 static_cast<rtc::NATType>(nat_type - NAT_FULL_CONE));
1822 ConfigureEndpoint(outer_nat, 0, config1); 1814 ConfigureEndpoint(outer_nat, 0, config1);
1823 ConfigureEndpoint(outer_nat, 1, config2); 1815 ConfigureEndpoint(outer_nat, 1, config2);
1824 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); 1816 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS);
1825 } 1817 }
1826 void ConfigureEndpoint(rtc::NATSocketServer::Translator* nat, 1818 void ConfigureEndpoint(rtc::NATSocketServer::Translator* nat,
1827 int endpoint, Config config) { 1819 int endpoint, Config config) {
1828 ASSERT(config <= NAT_SYMMETRIC); 1820 ASSERT(config <= NAT_SYMMETRIC);
1829 if (config == OPEN) { 1821 if (config == OPEN) {
1830 AddAddress(endpoint, kPrivateAddrs[endpoint]); 1822 AddAddress(endpoint, kPrivateAddrs[endpoint]);
1831 nat->AddClient(kPrivateAddrs[endpoint]); 1823 nat->AddClient(kPrivateAddrs[endpoint]);
1832 } else { 1824 } else {
1833 AddAddress(endpoint, kCascadedPrivateAddrs[endpoint]); 1825 AddAddress(endpoint, kCascadedPrivateAddrs[endpoint]);
1834 nat->AddTranslator(kPrivateAddrs[endpoint], kCascadedNatAddrs[endpoint], 1826 nat->AddTranslator(kPrivateAddrs[endpoint], kCascadedNatAddrs[endpoint],
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
2010 // Adding alternate address will make sure |kPublicAddrs| has the higher 2002 // Adding alternate address will make sure |kPublicAddrs| has the higher
2011 // priority than others. This is due to FakeNetwork::AddInterface method. 2003 // priority than others. This is due to FakeNetwork::AddInterface method.
2012 AddAddress(0, kAlternateAddrs[0]); 2004 AddAddress(0, kAlternateAddrs[0]);
2013 AddAddress(0, kPublicAddrs[0]); 2005 AddAddress(0, kPublicAddrs[0]);
2014 AddAddress(1, kPublicAddrs[1]); 2006 AddAddress(1, kPublicAddrs[1]);
2015 2007
2016 // Use only local ports for simplicity. 2008 // Use only local ports for simplicity.
2017 SetAllocatorFlags(0, kOnlyLocalPorts); 2009 SetAllocatorFlags(0, kOnlyLocalPorts);
2018 SetAllocatorFlags(1, kOnlyLocalPorts); 2010 SetAllocatorFlags(1, kOnlyLocalPorts);
2019 2011
2012 // We want it to set the remote ICE parameters when creating channels.
2013 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS);
2020 // Create channels and let them go writable, as usual. 2014 // Create channels and let them go writable, as usual.
2021 CreateChannels(1); 2015 CreateChannels(1);
2022 ep1_ch1()->set_remote_supports_renomination(true); 2016 // TODO(honghaiz): Once we enable renomination for all webrtc clients, we
2017 // should set the renomination to be true by default, so we won't need this.
2018 ASSERT_TRUE(ep1_ch1()->set_remote_supports_renomination(true));
2023 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2019 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2024 ep2_ch1()->receiving() && 2020 ep2_ch1()->receiving() &&
2025 ep2_ch1()->writable(), 2021 ep2_ch1()->writable(),
2026 3000, clock); 2022 3000, clock);
2027 EXPECT_TRUE_SIMULATED_WAIT( 2023 EXPECT_TRUE_SIMULATED_WAIT(
2028 ep2_ch1()->selected_connection()->remote_nomination() > 0 && 2024 ep2_ch1()->selected_connection()->remote_nomination() > 0 &&
2029 ep1_ch1()->selected_connection()->acked_nomination() > 0, 2025 ep1_ch1()->selected_connection()->acked_nomination() > 0,
2030 kDefaultTimeout, clock); 2026 kDefaultTimeout, clock);
2031 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); 2027 const Connection* selected_connection1 = ep1_ch1()->selected_connection();
2032 Connection* selected_connection2 = 2028 Connection* selected_connection2 =
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
2538 public sigslot::has_slots<> { 2534 public sigslot::has_slots<> {
2539 public: 2535 public:
2540 P2PTransportChannelPingTest() 2536 P2PTransportChannelPingTest()
2541 : pss_(new rtc::PhysicalSocketServer), 2537 : pss_(new rtc::PhysicalSocketServer),
2542 vss_(new rtc::VirtualSocketServer(pss_.get())), 2538 vss_(new rtc::VirtualSocketServer(pss_.get())),
2543 ss_scope_(vss_.get()) {} 2539 ss_scope_(vss_.get()) {}
2544 2540
2545 protected: 2541 protected:
2546 void PrepareChannel(P2PTransportChannel* ch) { 2542 void PrepareChannel(P2PTransportChannel* ch) {
2547 ch->SetIceRole(ICEROLE_CONTROLLING); 2543 ch->SetIceRole(ICEROLE_CONTROLLING);
2548 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); 2544 ch->SetIceParameters(kIceParams[0]);
2549 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 2545 ch->SetRemoteIceParameters(kIceParams[1]);
2550 ch->SignalSelectedCandidatePairChanged.connect( 2546 ch->SignalSelectedCandidatePairChanged.connect(
2551 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged); 2547 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged);
2552 ch->SignalReadyToSend.connect(this, 2548 ch->SignalReadyToSend.connect(this,
2553 &P2PTransportChannelPingTest::OnReadyToSend); 2549 &P2PTransportChannelPingTest::OnReadyToSend);
2554 ch->SignalStateChanged.connect( 2550 ch->SignalStateChanged.connect(
2555 this, &P2PTransportChannelPingTest::OnChannelStateChanged); 2551 this, &P2PTransportChannelPingTest::OnChannelStateChanged);
2556 } 2552 }
2557 2553
2558 Connection* WaitForConnectionTo(P2PTransportChannel* ch, 2554 Connection* WaitForConnectionTo(P2PTransportChannel* ch,
2559 const std::string& ip, 2555 const std::string& ip,
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2812 start = clock.TimeNanos(); 2808 start = clock.TimeNanos();
2813 ping_sent_before = conn->num_pings_sent(); 2809 ping_sent_before = conn->num_pings_sent();
2814 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); 2810 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
2815 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 2811 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
2816 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); 2812 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
2817 EXPECT_LE(ping_interval_ms, 2813 EXPECT_LE(ping_interval_ms,
2818 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); 2814 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
2819 } 2815 }
2820 2816
2821 // Test that we start pinging as soon as we have a connection and remote ICE 2817 // Test that we start pinging as soon as we have a connection and remote ICE
2822 // credentials. 2818 // parameters.
2823 TEST_F(P2PTransportChannelPingTest, PingingStartedAsSoonAsPossible) { 2819 TEST_F(P2PTransportChannelPingTest, PingingStartedAsSoonAsPossible) {
2824 rtc::ScopedFakeClock clock; 2820 rtc::ScopedFakeClock clock;
2825 2821
2826 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2822 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2827 P2PTransportChannel ch("TestChannel", 1, &pa); 2823 P2PTransportChannel ch("TestChannel", 1, &pa);
2828 ch.SetIceRole(ICEROLE_CONTROLLING); 2824 ch.SetIceRole(ICEROLE_CONTROLLING);
2829 ch.SetIceCredentials(kIceUfrag[0], kIcePwd[0]); 2825 ch.SetIceParameters(kIceParams[0]);
2830 ch.MaybeStartGathering(); 2826 ch.MaybeStartGathering();
2831 EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, ch.gathering_state(), 2827 EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, ch.gathering_state(),
2832 kDefaultTimeout); 2828 kDefaultTimeout);
2833 2829
2834 // Simulate a binding request being received, creating a peer reflexive 2830 // Simulate a binding request being received, creating a peer reflexive
2835 // candidate pair while we still don't have remote ICE credentials. 2831 // candidate pair while we still don't have remote ICE parameters.
2836 IceMessage request; 2832 IceMessage request;
2837 request.SetType(STUN_BINDING_REQUEST); 2833 request.SetType(STUN_BINDING_REQUEST);
2838 request.AddAttribute( 2834 request.AddAttribute(
2839 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 2835 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
2840 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 2836 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
2841 request.AddAttribute( 2837 request.AddAttribute(
2842 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 2838 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
2843 Port* port = GetPort(&ch); 2839 Port* port = GetPort(&ch);
2844 ASSERT_NE(nullptr, port); 2840 ASSERT_NE(nullptr, port);
2845 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 2841 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
2846 &request, kIceUfrag[1], false); 2842 &request, kIceUfrag[1], false);
2847 Connection* conn = GetConnectionTo(&ch, "1.1.1.1", 1); 2843 Connection* conn = GetConnectionTo(&ch, "1.1.1.1", 1);
2848 ASSERT_NE(nullptr, conn); 2844 ASSERT_NE(nullptr, conn);
2849 2845
2850 // Simulate waiting for a second (and change) and verify that no pings were 2846 // Simulate waiting for a second (and change) and verify that no pings were
2851 // sent, since we don't yet have remote ICE credentials. 2847 // sent, since we don't yet have remote ICE parameters.
2852 SIMULATED_WAIT(conn->num_pings_sent() > 0, 1025, clock); 2848 SIMULATED_WAIT(conn->num_pings_sent() > 0, 1025, clock);
2853 EXPECT_EQ(0, conn->num_pings_sent()); 2849 EXPECT_EQ(0, conn->num_pings_sent());
2854 2850
2855 // Set remote ICE credentials. Now we should be able to ping. Ensure that 2851 // Set remote ICE parameters. Now we should be able to ping. Ensure that
2856 // the first ping is sent as soon as possible, within one simulated clock 2852 // the first ping is sent as soon as possible, within one simulated clock
2857 // tick. 2853 // tick.
2858 ch.SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 2854 ch.SetRemoteIceParameters(kIceParams[1]);
2859 EXPECT_TRUE_SIMULATED_WAIT(conn->num_pings_sent() > 0, 1, clock); 2855 EXPECT_TRUE_SIMULATED_WAIT(conn->num_pings_sent() > 0, 1, clock);
2860 } 2856 }
2861 2857
2862 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { 2858 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
2863 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2859 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2864 P2PTransportChannel ch("trigger checks", 1, &pa); 2860 P2PTransportChannel ch("trigger checks", 1, &pa);
2865 PrepareChannel(&ch); 2861 PrepareChannel(&ch);
2866 ch.MaybeStartGathering(); 2862 ch.MaybeStartGathering();
2867 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2863 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2868 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 2864 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2912 // Pruning the connection reduces the set of active connections and changes 2908 // Pruning the connection reduces the set of active connections and changes
2913 // the channel state. 2909 // the channel state.
2914 conn1->Prune(); 2910 conn1->Prune();
2915 EXPECT_EQ_WAIT(STATE_FAILED, channel_state(), kDefaultTimeout); 2911 EXPECT_EQ_WAIT(STATE_FAILED, channel_state(), kDefaultTimeout);
2916 } 2912 }
2917 2913
2918 // Test adding remote candidates with different ufrags. If a remote candidate 2914 // Test adding remote candidates with different ufrags. If a remote candidate
2919 // is added with an old ufrag, it will be discarded. If it is added with a 2915 // is added with an old ufrag, it will be discarded. If it is added with a
2920 // ufrag that was not seen before, it will be used to create connections 2916 // ufrag that was not seen before, it will be used to create connections
2921 // although the ICE pwd in the remote candidate will be set when the ICE 2917 // although the ICE pwd in the remote candidate will be set when the ICE
2922 // credentials arrive. If a remote candidate is added with the current ICE 2918 // parameters arrive. If a remote candidate is added with the current ICE
2923 // ufrag, its pwd and generation will be set properly. 2919 // ufrag, its pwd and generation will be set properly.
2924 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { 2920 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) {
2925 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2921 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2926 P2PTransportChannel ch("add candidate", 1, &pa); 2922 P2PTransportChannel ch("add candidate", 1, &pa);
2927 PrepareChannel(&ch); 2923 PrepareChannel(&ch);
2928 ch.MaybeStartGathering(); 2924 ch.MaybeStartGathering();
2929 // Add a candidate with a future ufrag. 2925 // Add a candidate with a future ufrag.
2930 ch.AddRemoteCandidate( 2926 ch.AddRemoteCandidate(
2931 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1, kIceUfrag[2])); 2927 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1, kIceUfrag[2]));
2932 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2928 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2933 ASSERT_TRUE(conn1 != nullptr); 2929 ASSERT_TRUE(conn1 != nullptr);
2934 const Candidate& candidate = conn1->remote_candidate(); 2930 const Candidate& candidate = conn1->remote_candidate();
2935 EXPECT_EQ(kIceUfrag[2], candidate.username()); 2931 EXPECT_EQ(kIceUfrag[2], candidate.username());
2936 EXPECT_TRUE(candidate.password().empty()); 2932 EXPECT_TRUE(candidate.password().empty());
2937 EXPECT_TRUE(FindNextPingableConnectionAndPingIt(&ch) == nullptr); 2933 EXPECT_TRUE(FindNextPingableConnectionAndPingIt(&ch) == nullptr);
2938 2934
2939 // Set the remote credentials with the "future" ufrag. 2935 // Set the remote ICE parameters with the "future" ufrag.
2940 // This should set the ICE pwd in the remote candidate of |conn1|, making 2936 // This should set the ICE pwd in the remote candidate of |conn1|, making
2941 // it pingable. 2937 // it pingable.
2942 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); 2938 ch.SetRemoteIceParameters(kIceParams[2]);
2943 EXPECT_EQ(kIceUfrag[2], candidate.username()); 2939 EXPECT_EQ(kIceUfrag[2], candidate.username());
2944 EXPECT_EQ(kIcePwd[2], candidate.password()); 2940 EXPECT_EQ(kIcePwd[2], candidate.password());
2945 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); 2941 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch));
2946 2942
2947 // Add a candidate with an old ufrag. No connection will be created. 2943 // Add a candidate with an old ufrag. No connection will be created.
2948 ch.AddRemoteCandidate( 2944 ch.AddRemoteCandidate(
2949 CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2, kIceUfrag[1])); 2945 CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2, kIceUfrag[1]));
2950 rtc::Thread::Current()->ProcessMessages(500); 2946 rtc::Thread::Current()->ProcessMessages(500);
2951 EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr); 2947 EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr);
2952 2948
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
3188 ASSERT_TRUE(conn4 != nullptr); 3184 ASSERT_TRUE(conn4 != nullptr);
3189 EXPECT_TRUE(port->sent_binding_response()); 3185 EXPECT_TRUE(port->sent_binding_response());
3190 // conn4 is not the selected connection yet because it is not writable. 3186 // conn4 is not the selected connection yet because it is not writable.
3191 EXPECT_EQ(conn2, ch.selected_connection()); 3187 EXPECT_EQ(conn2, ch.selected_connection());
3192 conn4->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. 3188 conn4->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3193 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); 3189 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout);
3194 3190
3195 // Test that the request from an unknown address contains a ufrag from an old 3191 // Test that the request from an unknown address contains a ufrag from an old
3196 // generation. 3192 // generation.
3197 port->set_sent_binding_response(false); 3193 port->set_sent_binding_response(false);
3198 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); 3194 ch.SetRemoteIceParameters(kIceParams[2]);
3199 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 3195 ch.SetRemoteIceParameters(kIceParams[3]);
3200 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP, 3196 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP,
3201 &request, kIceUfrag[2], false); 3197 &request, kIceUfrag[2], false);
3202 Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); 3198 Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5);
3203 ASSERT_TRUE(conn5 != nullptr); 3199 ASSERT_TRUE(conn5 != nullptr);
3204 EXPECT_TRUE(port->sent_binding_response()); 3200 EXPECT_TRUE(port->sent_binding_response());
3205 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password()); 3201 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password());
3206 } 3202 }
3207 3203
3208 // The controlled side will select a connection as the "selected connection" 3204 // The controlled side will select a connection as the "selected connection"
3209 // based on media received until the controlling side nominates a connection, 3205 // based on media received until the controlling side nominates a connection,
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
3648 ch.MaybeStartGathering(); 3644 ch.MaybeStartGathering();
3649 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3645 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3650 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3646 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3651 ASSERT_TRUE(conn1 != nullptr); 3647 ASSERT_TRUE(conn1 != nullptr);
3652 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving 3648 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3653 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); 3649 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
3654 3650
3655 // Start a new session. Even though conn1, which belongs to an older 3651 // Start a new session. Even though conn1, which belongs to an older
3656 // session, becomes unwritable and writable again, it should not stop the 3652 // session, becomes unwritable and writable again, it should not stop the
3657 // current session. 3653 // current session.
3658 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); 3654 ch.SetIceParameters(kIceParams[1]);
3659 ch.MaybeStartGathering(); 3655 ch.MaybeStartGathering();
3660 conn1->Prune(); 3656 conn1->Prune();
3661 conn1->ReceivedPingResponse(LOW_RTT, "id"); 3657 conn1->ReceivedPingResponse(LOW_RTT, "id");
3662 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); 3658 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts());
3663 3659
3664 // But if a new connection created from the new session becomes writable, 3660 // But if a new connection created from the new session becomes writable,
3665 // it will stop the current session. 3661 // it will stop the current session.
3666 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100)); 3662 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100));
3667 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3663 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3668 ASSERT_TRUE(conn2 != nullptr); 3664 ASSERT_TRUE(conn2 != nullptr);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3704 // Starts with ICEROLE_CONTROLLING. 3700 // Starts with ICEROLE_CONTROLLING.
3705 PrepareChannel(&ch); 3701 PrepareChannel(&ch);
3706 ch.MaybeStartGathering(); 3702 ch.MaybeStartGathering();
3707 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3703 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3708 3704
3709 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3705 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3710 ASSERT_TRUE(conn != nullptr); 3706 ASSERT_TRUE(conn != nullptr);
3711 3707
3712 // Do an ICE restart, change the role, and expect the old port to have its 3708 // Do an ICE restart, change the role, and expect the old port to have its
3713 // role updated. 3709 // role updated.
3714 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); 3710 ch.SetIceParameters(kIceParams[1]);
3715 ch.MaybeStartGathering(); 3711 ch.MaybeStartGathering();
3716 ch.SetIceRole(ICEROLE_CONTROLLED); 3712 ch.SetIceRole(ICEROLE_CONTROLLED);
3717 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); 3713 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole());
3718 } 3714 }
3719 3715
3720 // Test that after some amount of time without receiving data, the connection 3716 // Test that after some amount of time without receiving data, the connection
3721 // will be destroyed. The port will only be destroyed after it is marked as 3717 // will be destroyed. The port will only be destroyed after it is marked as
3722 // "pruned." 3718 // "pruned."
3723 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeoutAndPruned) { 3719 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeoutAndPruned) {
3724 rtc::ScopedFakeClock fake_clock; 3720 rtc::ScopedFakeClock fake_clock;
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
3954 3950
3955 // TCP Relay/Relay is the next. 3951 // TCP Relay/Relay is the next.
3956 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 3952 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
3957 TCP_PROTOCOL_NAME); 3953 TCP_PROTOCOL_NAME);
3958 3954
3959 // Finally, Local/Relay will be pinged. 3955 // Finally, Local/Relay will be pinged.
3960 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 3956 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
3961 } 3957 }
3962 3958
3963 } // namespace cricket { 3959 } // namespace cricket {
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698