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

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: Merge with head 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 bool ready_to_send_ = false; 301 bool ready_to_send_ = false;
299 }; 302 };
300 303
301 ChannelData* GetChannelData(TransportChannel* channel) { 304 ChannelData* GetChannelData(TransportChannel* channel) {
302 if (ep1_.HasChannel(channel)) 305 if (ep1_.HasChannel(channel))
303 return ep1_.GetChannelData(channel); 306 return ep1_.GetChannelData(channel);
304 else 307 else
305 return ep2_.GetChannelData(channel); 308 return ep2_.GetChannelData(channel);
306 } 309 }
307 310
308 void CreateChannels(int num) { 311 IceParameters GetIceParams(const IceParameters& ice, bool renomination) {
Taylor Brandstetter 2016/08/17 01:08:17 nit: "CreateIceParamsWithRenomination" or somethin
pthatcher1 2016/08/17 17:25:46 +1
honghaiz3 2016/08/17 20:21:48 Done.
309 std::string ice_ufrag_ep1_cd1_ch = kIceUfrag[0]; 312 IceParameters new_ice = ice;
310 std::string ice_pwd_ep1_cd1_ch = kIcePwd[0]; 313 new_ice.renomination = renomination;
311 std::string ice_ufrag_ep2_cd1_ch = kIceUfrag[1]; 314 return new_ice;
312 std::string ice_pwd_ep2_cd1_ch = kIcePwd[1]; 315 }
313 ep1_.cd1_.ch_.reset(CreateChannel( 316
314 0, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep1_cd1_ch, 317 void CreateChannels(int num, bool renomination = false) {
315 ice_pwd_ep1_cd1_ch, ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch)); 318 IceParameters ice_ep1_cd1_ch = GetIceParams(kIceParams[0], renomination);
316 ep2_.cd1_.ch_.reset(CreateChannel( 319 IceParameters ice_ep2_cd1_ch = GetIceParams(kIceParams[1], renomination);
317 1, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep2_cd1_ch, 320 ep1_.cd1_.ch_.reset(CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT,
318 ice_pwd_ep2_cd1_ch, ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch)); 321 ice_ep1_cd1_ch, ice_ep2_cd1_ch));
322 ep2_.cd1_.ch_.reset(CreateChannel(1, ICE_CANDIDATE_COMPONENT_DEFAULT,
323 ice_ep2_cd1_ch, ice_ep1_cd1_ch));
319 ep1_.cd1_.ch_->MaybeStartGathering(); 324 ep1_.cd1_.ch_->MaybeStartGathering();
320 ep2_.cd1_.ch_->MaybeStartGathering(); 325 ep2_.cd1_.ch_->MaybeStartGathering();
321 if (num == 2) { 326 if (num == 2) {
322 std::string ice_ufrag_ep1_cd2_ch = kIceUfrag[2]; 327 IceParameters ice_ep1_cd2_ch = GetIceParams(kIceParams[2], renomination);
323 std::string ice_pwd_ep1_cd2_ch = kIcePwd[2]; 328 IceParameters ice_ep2_cd2_ch = GetIceParams(kIceParams[3], renomination);
324 std::string ice_ufrag_ep2_cd2_ch = kIceUfrag[3]; 329 ep1_.cd2_.ch_.reset(CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT,
325 std::string ice_pwd_ep2_cd2_ch = kIcePwd[3]; 330 ice_ep1_cd2_ch, ice_ep2_cd2_ch));
326 ep1_.cd2_.ch_.reset(CreateChannel( 331 ep2_.cd2_.ch_.reset(CreateChannel(1, ICE_CANDIDATE_COMPONENT_DEFAULT,
327 0, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep1_cd2_ch, 332 ice_ep2_cd2_ch, ice_ep1_cd2_ch));
328 ice_pwd_ep1_cd2_ch, ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch));
329 ep2_.cd2_.ch_.reset(CreateChannel(
330 1, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep2_cd2_ch,
331 ice_pwd_ep2_cd2_ch, ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch));
332 ep1_.cd2_.ch_->MaybeStartGathering(); 333 ep1_.cd2_.ch_->MaybeStartGathering();
333 ep2_.cd2_.ch_->MaybeStartGathering(); 334 ep2_.cd2_.ch_->MaybeStartGathering();
334 } 335 }
335 } 336 }
336 P2PTransportChannel* CreateChannel(int endpoint, 337 P2PTransportChannel* CreateChannel(int endpoint,
337 int component, 338 int component,
338 const std::string& local_ice_ufrag, 339 const IceParameters& local_ice,
339 const std::string& local_ice_pwd, 340 const IceParameters& remote_ice) {
340 const std::string& remote_ice_ufrag,
341 const std::string& remote_ice_pwd) {
342 P2PTransportChannel* channel = new P2PTransportChannel( 341 P2PTransportChannel* channel = new P2PTransportChannel(
343 "test content name", component, GetAllocator(endpoint)); 342 "test content name", component, GetAllocator(endpoint));
344 channel->SignalReadyToSend.connect( 343 channel->SignalReadyToSend.connect(
345 this, &P2PTransportChannelTestBase::OnReadyToSend); 344 this, &P2PTransportChannelTestBase::OnReadyToSend);
346 channel->SignalCandidateGathered.connect( 345 channel->SignalCandidateGathered.connect(
347 this, &P2PTransportChannelTestBase::OnCandidateGathered); 346 this, &P2PTransportChannelTestBase::OnCandidateGathered);
348 channel->SignalCandidatesRemoved.connect( 347 channel->SignalCandidatesRemoved.connect(
349 this, &P2PTransportChannelTestBase::OnCandidatesRemoved); 348 this, &P2PTransportChannelTestBase::OnCandidatesRemoved);
350 channel->SignalReadPacket.connect( 349 channel->SignalReadPacket.connect(
351 this, &P2PTransportChannelTestBase::OnReadPacket); 350 this, &P2PTransportChannelTestBase::OnReadPacket);
352 channel->SignalRoleConflict.connect( 351 channel->SignalRoleConflict.connect(
353 this, &P2PTransportChannelTestBase::OnRoleConflict); 352 this, &P2PTransportChannelTestBase::OnRoleConflict);
354 channel->SignalSelectedCandidatePairChanged.connect( 353 channel->SignalSelectedCandidatePairChanged.connect(
355 this, &P2PTransportChannelTestBase::OnSelectedCandidatePairChanged); 354 this, &P2PTransportChannelTestBase::OnSelectedCandidatePairChanged);
356 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); 355 channel->SetIceParameters(local_ice);
357 if (remote_ice_credential_source_ == FROM_SETICECREDENTIALS) { 356 if (remote_ice_parameter_source_ == FROM_SETICEPARAMETERS) {
358 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd); 357 channel->SetRemoteIceParameters(remote_ice);
359 } 358 }
360 channel->SetIceRole(GetEndpoint(endpoint)->ice_role()); 359 channel->SetIceRole(GetEndpoint(endpoint)->ice_role());
361 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker()); 360 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker());
362 return channel; 361 return channel;
363 } 362 }
364 void DestroyChannels() { 363 void DestroyChannels() {
365 ep1_.cd1_.ch_.reset(); 364 ep1_.cd1_.ch_.reset();
366 ep2_.cd1_.ch_.reset(); 365 ep2_.cd1_.ch_.reset();
367 ep1_.cd2_.ch_.reset(); 366 ep1_.cd2_.ch_.reset();
368 ep2_.cd2_.ch_.reset(); 367 ep2_.cd2_.ch_.reset();
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 // local_channel2 <==> remote_channel2 578 // local_channel2 <==> remote_channel2
580 EXPECT_EQ_WAIT(len, SendData(ep1_ch2(), data, len), 1000); 579 EXPECT_EQ_WAIT(len, SendData(ep1_ch2(), data, len), 1000);
581 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch2(), data, len), 1000); 580 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch2(), data, len), 1000);
582 EXPECT_EQ_WAIT(len, SendData(ep2_ch2(), data, len), 1000); 581 EXPECT_EQ_WAIT(len, SendData(ep2_ch2(), data, len), 1000);
583 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep1_ch2(), data, len), 1000); 582 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep1_ch2(), data, len), 1000);
584 } 583 }
585 } 584 }
586 } 585 }
587 586
588 // This test waits for the transport to become receiving and writable on both 587 // This test waits for the transport to become receiving and writable on both
589 // end points. Once they are, the end points set new local ice credentials and 588 // end points. Once they are, the end points set new local ice parameters and
590 // restart the ice gathering. Finally it waits for the transport to select a 589 // restart the ice gathering. Finally it waits for the transport to select a
591 // new connection using the newly generated ice candidates. 590 // new connection using the newly generated ice candidates.
592 // Before calling this function the end points must be configured. 591 // Before calling this function the end points must be configured.
593 void TestHandleIceUfragPasswordChanged() { 592 void TestHandleIceUfragPasswordChanged() {
594 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 593 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]);
595 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); 594 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]);
596 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && 595 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
597 ep2_ch1()->receiving() && ep2_ch1()->writable(), 596 ep2_ch1()->receiving() && ep2_ch1()->writable(),
598 1000, 1000); 597 1000, 1000);
599 598
600 const Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1()); 599 const Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1());
601 const Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1()); 600 const Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1());
602 const Candidate* old_remote_candidate1 = RemoteCandidate(ep1_ch1()); 601 const Candidate* old_remote_candidate1 = RemoteCandidate(ep1_ch1());
603 const Candidate* old_remote_candidate2 = RemoteCandidate(ep2_ch1()); 602 const Candidate* old_remote_candidate2 = RemoteCandidate(ep2_ch1());
604 603
605 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); 604 ep1_ch1()->SetIceParameters(kIceParams[2]);
606 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 605 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
607 ep1_ch1()->MaybeStartGathering(); 606 ep1_ch1()->MaybeStartGathering();
608 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]); 607 ep2_ch1()->SetIceParameters(kIceParams[3]);
609 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); 608
609 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]);
610 ep2_ch1()->MaybeStartGathering(); 610 ep2_ch1()->MaybeStartGathering();
611 611
612 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() != 612 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() !=
613 old_local_candidate1->generation(), 613 old_local_candidate1->generation(),
614 1000, 1000); 614 1000, 1000);
615 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep2_ch1())->generation() != 615 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep2_ch1())->generation() !=
616 old_local_candidate2->generation(), 616 old_local_candidate2->generation(),
617 1000, 1000); 617 1000, 1000);
618 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep1_ch1())->generation() != 618 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep1_ch1())->generation() !=
619 old_remote_candidate1->generation(), 619 old_remote_candidate1->generation(),
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 void OnMessage(rtc::Message* msg) { 722 void OnMessage(rtc::Message* msg) {
723 switch (msg->message_id) { 723 switch (msg->message_id) {
724 case MSG_ADD_CANDIDATES: { 724 case MSG_ADD_CANDIDATES: {
725 std::unique_ptr<CandidatesData> data( 725 std::unique_ptr<CandidatesData> data(
726 static_cast<CandidatesData*>(msg->pdata)); 726 static_cast<CandidatesData*>(msg->pdata));
727 P2PTransportChannel* rch = GetRemoteChannel(data->channel); 727 P2PTransportChannel* rch = GetRemoteChannel(data->channel);
728 if (!rch) { 728 if (!rch) {
729 return; 729 return;
730 } 730 }
731 for (auto& c : data->candidates) { 731 for (auto& c : data->candidates) {
732 if (remote_ice_credential_source_ != FROM_CANDIDATE) { 732 if (remote_ice_parameter_source_ != FROM_CANDIDATE) {
733 c.set_username(""); 733 c.set_username("");
734 c.set_password(""); 734 c.set_password("");
735 } 735 }
736 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->" 736 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->"
737 << rch->component() << "): " << c.ToString(); 737 << rch->component() << "): " << c.ToString();
738 rch->AddRemoteCandidate(c); 738 rch->AddRemoteCandidate(c);
739 } 739 }
740 break; 740 break;
741 } 741 }
742 case MSG_REMOVE_CANDIDATES: { 742 case MSG_REMOVE_CANDIDATES: {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 return ep1_ch1(); 807 return ep1_ch1();
808 else if (ch == ep2_ch2()) 808 else if (ch == ep2_ch2())
809 return ep1_ch2(); 809 return ep1_ch2();
810 else 810 else
811 return NULL; 811 return NULL;
812 } 812 }
813 std::list<std::string>& GetPacketList(TransportChannel* ch) { 813 std::list<std::string>& GetPacketList(TransportChannel* ch) {
814 return GetChannelData(ch)->ch_packets_; 814 return GetChannelData(ch)->ch_packets_;
815 } 815 }
816 816
817 enum RemoteIceCredentialSource { FROM_CANDIDATE, FROM_SETICECREDENTIALS }; 817 enum RemoteIceParameterSource { FROM_CANDIDATE, FROM_SETICEPARAMETERS };
818 818
819 // How does the test pass ICE credentials to the P2PTransportChannel? 819 // How does the test pass ICE parameters to the P2PTransportChannel?
820 // On the candidate itself, or through SetIceCredentials? 820 // On the candidate itself, or through SetRemoteIceParameters?
821 // Goes through the candidate itself by default. 821 // Goes through the candidate itself by default.
822 void set_remote_ice_credential_source(RemoteIceCredentialSource source) { 822 void set_remote_ice_parameter_source(RemoteIceParameterSource source) {
823 remote_ice_credential_source_ = source; 823 remote_ice_parameter_source_ = source;
824 } 824 }
825 825
826 void set_force_relay(bool relay) { 826 void set_force_relay(bool relay) {
827 force_relay_ = relay; 827 force_relay_ = relay;
828 } 828 }
829 829
830 void ConnectSignalNominated(Connection* conn) { 830 void ConnectSignalNominated(Connection* conn) {
831 conn->SignalNominated.connect(this, 831 conn->SignalNominated.connect(this,
832 &P2PTransportChannelTestBase::OnNominated); 832 &P2PTransportChannelTestBase::OnNominated);
833 } 833 }
834 834
835 void OnNominated(Connection* conn) { nominated_ = true; } 835 void OnNominated(Connection* conn) { nominated_ = true; }
836 bool nominated() { return nominated_; } 836 bool nominated() { return nominated_; }
837 837
838 private: 838 private:
839 rtc::Thread* main_; 839 rtc::Thread* main_;
840 std::unique_ptr<rtc::PhysicalSocketServer> pss_; 840 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
841 std::unique_ptr<rtc::VirtualSocketServer> vss_; 841 std::unique_ptr<rtc::VirtualSocketServer> vss_;
842 std::unique_ptr<rtc::NATSocketServer> nss_; 842 std::unique_ptr<rtc::NATSocketServer> nss_;
843 std::unique_ptr<rtc::FirewallSocketServer> ss_; 843 std::unique_ptr<rtc::FirewallSocketServer> ss_;
844 rtc::SocketServerScope ss_scope_; 844 rtc::SocketServerScope ss_scope_;
845 std::unique_ptr<TestStunServer> stun_server_; 845 std::unique_ptr<TestStunServer> stun_server_;
846 TestTurnServer turn_server_; 846 TestTurnServer turn_server_;
847 TestRelayServer relay_server_; 847 TestRelayServer relay_server_;
848 rtc::SocksProxyServer socks_server1_; 848 rtc::SocksProxyServer socks_server1_;
849 rtc::SocksProxyServer socks_server2_; 849 rtc::SocksProxyServer socks_server2_;
850 Endpoint ep1_; 850 Endpoint ep1_;
851 Endpoint ep2_; 851 Endpoint ep2_;
852 RemoteIceCredentialSource remote_ice_credential_source_ = FROM_CANDIDATE; 852 RemoteIceParameterSource remote_ice_parameter_source_ = FROM_CANDIDATE;
853 bool force_relay_; 853 bool force_relay_;
854 int selected_candidate_pair_switches_ = 0; 854 int selected_candidate_pair_switches_ = 0;
855 855
856 bool nominated_ = false; 856 bool nominated_ = false;
857 }; 857 };
858 858
859 // The tests have only a few outcomes, which we predefine. 859 // The tests have only a few outcomes, which we predefine.
860 const P2PTransportChannelTestBase::Result 860 const P2PTransportChannelTestBase::Result
861 P2PTransportChannelTestBase::kLocalUdpToLocalUdp("local", 861 P2PTransportChannelTestBase::kLocalUdpToLocalUdp("local",
862 "udp", 862 "udp",
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 GetEndpoint(1)->allocator_->AddTurnServer(turn_server); 968 GetEndpoint(1)->allocator_->AddTurnServer(turn_server);
969 969
970 int delay = kMinimumStepDelay; 970 int delay = kMinimumStepDelay;
971 ConfigureEndpoint(0, config1); 971 ConfigureEndpoint(0, config1);
972 SetAllocatorFlags(0, allocator_flags1); 972 SetAllocatorFlags(0, allocator_flags1);
973 SetAllocationStepDelay(0, delay); 973 SetAllocationStepDelay(0, delay);
974 ConfigureEndpoint(1, config2); 974 ConfigureEndpoint(1, config2);
975 SetAllocatorFlags(1, allocator_flags2); 975 SetAllocatorFlags(1, allocator_flags2);
976 SetAllocationStepDelay(1, delay); 976 SetAllocationStepDelay(1, delay);
977 977
978 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); 978 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS);
979 } 979 }
980 void ConfigureEndpoint(int endpoint, Config config) { 980 void ConfigureEndpoint(int endpoint, Config config) {
981 switch (config) { 981 switch (config) {
982 case OPEN: 982 case OPEN:
983 AddAddress(endpoint, kPublicAddrs[endpoint]); 983 AddAddress(endpoint, kPublicAddrs[endpoint]);
984 break; 984 break;
985 case NAT_FULL_CONE: 985 case NAT_FULL_CONE:
986 case NAT_ADDR_RESTRICTED: 986 case NAT_ADDR_RESTRICTED:
987 case NAT_PORT_RESTRICTED: 987 case NAT_PORT_RESTRICTED:
988 case NAT_SYMMETRIC: 988 case NAT_SYMMETRIC:
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 EXPECT_EQ(10 * 36U, best_conn_info->recv_total_bytes); 1179 EXPECT_EQ(10 * 36U, best_conn_info->recv_total_bytes);
1180 EXPECT_GT(best_conn_info->rtt, 0U); 1180 EXPECT_GT(best_conn_info->rtt, 0U);
1181 DestroyChannels(); 1181 DestroyChannels();
1182 } 1182 }
1183 1183
1184 // Test that we properly create a connection on a STUN ping from unknown address 1184 // Test that we properly create a connection on a STUN ping from unknown address
1185 // when the signaling is slow. 1185 // when the signaling is slow.
1186 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) { 1186 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) {
1187 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1187 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1188 kDefaultPortAllocatorFlags); 1188 kDefaultPortAllocatorFlags);
1189 // Emulate no remote credentials coming in. 1189 // Emulate no remote parameters coming in.
1190 set_remote_ice_credential_source(FROM_CANDIDATE); 1190 set_remote_ice_parameter_source(FROM_CANDIDATE);
1191 CreateChannels(1); 1191 CreateChannels(1);
1192 // Only have remote credentials come in for ep2, not ep1. 1192 // Only have remote parameters come in for ep2, not ep1.
1193 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); 1193 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]);
1194 1194
1195 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive 1195 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive
1196 // candidate. 1196 // candidate.
1197 PauseCandidates(1); 1197 PauseCandidates(1);
1198 1198
1199 // The caller should have the selected connection connected to the peer 1199 // The caller should have the selected connection connected to the peer
1200 // reflexive candidate. 1200 // reflexive candidate.
1201 const Connection* selected_connection = NULL; 1201 const Connection* selected_connection = NULL;
1202 WAIT((selected_connection = ep1_ch1()->selected_connection()) != NULL, 2000); 1202 WAIT((selected_connection = ep1_ch1()->selected_connection()) != NULL, 2000);
1203 EXPECT_EQ("prflx", 1203 EXPECT_EQ("prflx",
1204 ep1_ch1()->selected_connection()->remote_candidate().type()); 1204 ep1_ch1()->selected_connection()->remote_candidate().type());
1205 1205
1206 // Because we don't have a remote pwd, we don't ping yet. 1206 // Because we don't have a remote pwd, we don't ping yet.
1207 EXPECT_EQ(kIceUfrag[1], 1207 EXPECT_EQ(kIceUfrag[1],
1208 ep1_ch1()->selected_connection()->remote_candidate().username()); 1208 ep1_ch1()->selected_connection()->remote_candidate().username());
1209 EXPECT_EQ("", 1209 EXPECT_EQ("",
1210 ep1_ch1()->selected_connection()->remote_candidate().password()); 1210 ep1_ch1()->selected_connection()->remote_candidate().password());
1211 // Because we don't have ICE credentials yet, we don't know the generation. 1211 // Because we don't have ICE parameters yet, we don't know the generation.
1212 EXPECT_EQ(0u, 1212 EXPECT_EQ(0u,
1213 ep1_ch1()->selected_connection()->remote_candidate().generation()); 1213 ep1_ch1()->selected_connection()->remote_candidate().generation());
1214 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); 1214 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection());
1215 1215
1216 // Add two sets of remote ICE credentials, so that the ones used by the 1216 // Add two sets of remote ICE parameters, so that the ones used by the
1217 // candidate will be generation 1 instead of 0. 1217 // candidate will be generation 1 instead of 0.
1218 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 1218 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
1219 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 1219 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]);
1220 // After setting the remote ICE credentials, the password and generation 1220
1221 // After setting the remote ICE parameters, the password and generation
1221 // of the peer reflexive candidate should be updated. 1222 // of the peer reflexive candidate should be updated.
1222 EXPECT_EQ(kIcePwd[1], 1223 EXPECT_EQ(kIcePwd[1],
1223 ep1_ch1()->selected_connection()->remote_candidate().password()); 1224 ep1_ch1()->selected_connection()->remote_candidate().password());
1224 EXPECT_EQ(1u, 1225 EXPECT_EQ(1u,
1225 ep1_ch1()->selected_connection()->remote_candidate().generation()); 1226 ep1_ch1()->selected_connection()->remote_candidate().generation());
1226 EXPECT_TRUE(nullptr != ep1_ch1()->FindNextPingableConnection()); 1227 EXPECT_TRUE(nullptr != ep1_ch1()->FindNextPingableConnection());
1227 1228
1228 ResumeCandidates(1); 1229 ResumeCandidates(1);
1229 1230
1230 WAIT(ep2_ch1()->selected_connection() != NULL, 2000); 1231 WAIT(ep2_ch1()->selected_connection() != NULL, 2000);
1231 // Verify ep1's selected connection is updated to use the 'local' candidate. 1232 // Verify ep1's selected connection is updated to use the 'local' candidate.
1232 EXPECT_EQ_WAIT("local", 1233 EXPECT_EQ_WAIT("local",
1233 ep1_ch1()->selected_connection()->remote_candidate().type(), 1234 ep1_ch1()->selected_connection()->remote_candidate().type(),
1234 2000); 1235 2000);
1235 EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection()); 1236 EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection());
1236 DestroyChannels(); 1237 DestroyChannels();
1237 } 1238 }
1238 1239
1239 // Test that we properly create a connection on a STUN ping from unknown address 1240 // Test that we properly create a connection on a STUN ping from unknown address
1240 // when the signaling is slow and the end points are behind NAT. 1241 // when the signaling is slow and the end points are behind NAT.
1241 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { 1242 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) {
1242 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, 1243 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags,
1243 kDefaultPortAllocatorFlags); 1244 kDefaultPortAllocatorFlags);
1244 // Emulate no remote credentials coming in. 1245 // Emulate no remote parameters coming in.
1245 set_remote_ice_credential_source(FROM_CANDIDATE); 1246 set_remote_ice_parameter_source(FROM_CANDIDATE);
1246 CreateChannels(1); 1247 CreateChannels(1);
1247 // Only have remote credentials come in for ep2, not ep1. 1248 // Only have remote parameters come in for ep2, not ep1.
1248 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); 1249 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]);
1249 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive 1250 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive
1250 // candidate. 1251 // candidate.
1251 PauseCandidates(1); 1252 PauseCandidates(1);
1252 1253
1253 // The caller should have the selected connection connected to the peer 1254 // The caller should have the selected connection connected to the peer
1254 // reflexive candidate. 1255 // reflexive candidate.
1255 WAIT(ep1_ch1()->selected_connection() != NULL, 2000); 1256 WAIT(ep1_ch1()->selected_connection() != NULL, 2000);
1256 EXPECT_EQ("prflx", 1257 EXPECT_EQ("prflx",
1257 ep1_ch1()->selected_connection()->remote_candidate().type()); 1258 ep1_ch1()->selected_connection()->remote_candidate().type());
1258 1259
1259 // Because we don't have a remote pwd, we don't ping yet. 1260 // Because we don't have a remote pwd, we don't ping yet.
1260 EXPECT_EQ(kIceUfrag[1], 1261 EXPECT_EQ(kIceUfrag[1],
1261 ep1_ch1()->selected_connection()->remote_candidate().username()); 1262 ep1_ch1()->selected_connection()->remote_candidate().username());
1262 EXPECT_EQ("", 1263 EXPECT_EQ("",
1263 ep1_ch1()->selected_connection()->remote_candidate().password()); 1264 ep1_ch1()->selected_connection()->remote_candidate().password());
1264 // Because we don't have ICE credentials yet, we don't know the generation. 1265 // Because we don't have ICE parameters yet, we don't know the generation.
1265 EXPECT_EQ(0u, 1266 EXPECT_EQ(0u,
1266 ep1_ch1()->selected_connection()->remote_candidate().generation()); 1267 ep1_ch1()->selected_connection()->remote_candidate().generation());
1267 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection()); 1268 EXPECT_TRUE(nullptr == ep1_ch1()->FindNextPingableConnection());
1268 1269
1269 // Add two sets of remote ICE credentials, so that the ones used by the 1270 // Add two sets of remote ICE parameters, so that the ones used by the
1270 // candidate will be generation 1 instead of 0. 1271 // candidate will be generation 1 instead of 0.
1271 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 1272 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
1272 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 1273 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]);
1273 // After setting the remote ICE credentials, the password and generation 1274 // After setting the remote ICE parameters, the password and generation
1274 // of the peer reflexive candidate should be updated. 1275 // of the peer reflexive candidate should be updated.
1275 EXPECT_EQ(kIcePwd[1], 1276 EXPECT_EQ(kIcePwd[1],
1276 ep1_ch1()->selected_connection()->remote_candidate().password()); 1277 ep1_ch1()->selected_connection()->remote_candidate().password());
1277 EXPECT_EQ(1u, 1278 EXPECT_EQ(1u,
1278 ep1_ch1()->selected_connection()->remote_candidate().generation()); 1279 ep1_ch1()->selected_connection()->remote_candidate().generation());
1279 1280
1280 ResumeCandidates(1); 1281 ResumeCandidates(1);
1281 1282
1282 const Connection* selected_connection = NULL; 1283 const Connection* selected_connection = NULL;
1283 WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 2000); 1284 WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 2000);
(...skipping 16 matching lines...) Expand all
1300 // generations. This resulted in the old-generation prflx candidate being 1301 // generations. This resulted in the old-generation prflx candidate being
1301 // prioritized above new-generation candidate pairs. 1302 // prioritized above new-generation candidate pairs.
1302 TEST_F(P2PTransportChannelTest, 1303 TEST_F(P2PTransportChannelTest,
1303 PeerReflexiveCandidateBeforeSignalingWithIceRestart) { 1304 PeerReflexiveCandidateBeforeSignalingWithIceRestart) {
1304 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1305 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1305 kDefaultPortAllocatorFlags); 1306 kDefaultPortAllocatorFlags);
1306 // Only gather relay candidates, so that when the prflx candidate arrives 1307 // Only gather relay candidates, so that when the prflx candidate arrives
1307 // it's prioritized above the current candidate pair. 1308 // it's prioritized above the current candidate pair.
1308 GetEndpoint(0)->allocator_->set_candidate_filter(CF_RELAY); 1309 GetEndpoint(0)->allocator_->set_candidate_filter(CF_RELAY);
1309 GetEndpoint(1)->allocator_->set_candidate_filter(CF_RELAY); 1310 GetEndpoint(1)->allocator_->set_candidate_filter(CF_RELAY);
1310 // Setting this allows us to control when SetRemoteIceCredentials is called. 1311 // Setting this allows us to control when SetRemoteIceParameters is called.
1311 set_remote_ice_credential_source(FROM_CANDIDATE); 1312 set_remote_ice_parameter_source(FROM_CANDIDATE);
1312 CreateChannels(1); 1313 CreateChannels(1);
1313 // Wait for the initial connection to be made. 1314 // Wait for the initial connection to be made.
1314 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 1315 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]);
1315 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); 1316 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]);
1316 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1317 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1317 ep2_ch1()->receiving() && ep2_ch1()->writable(), 1318 ep2_ch1()->receiving() && ep2_ch1()->writable(),
1318 kDefaultTimeout); 1319 kDefaultTimeout);
1319 1320
1320 // Simulate an ICE restart on ep2, but don't signal the candidate or new 1321 // Simulate an ICE restart on ep2, but don't signal the candidate or new
1321 // ICE credentials until after a prflx connection has been made. 1322 // ICE parameters until after a prflx connection has been made.
1322 PauseCandidates(1); 1323 PauseCandidates(1);
1323 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]); 1324 ep2_ch1()->SetIceParameters(kIceParams[3]);
1324 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 1325
1326 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]);
1325 ep2_ch1()->MaybeStartGathering(); 1327 ep2_ch1()->MaybeStartGathering();
1326 1328
1327 // The caller should have the selected connection connected to the peer 1329 // The caller should have the selected connection connected to the peer
1328 // reflexive candidate. 1330 // reflexive candidate.
1329 EXPECT_EQ_WAIT("prflx", 1331 EXPECT_EQ_WAIT("prflx",
1330 ep1_ch1()->selected_connection()->remote_candidate().type(), 1332 ep1_ch1()->selected_connection()->remote_candidate().type(),
1331 kDefaultTimeout); 1333 kDefaultTimeout);
1332 const Connection* prflx_selected_connection = 1334 const Connection* prflx_selected_connection =
1333 ep1_ch1()->selected_connection(); 1335 ep1_ch1()->selected_connection();
1334 1336
1335 // Now simulate the ICE restart on ep1. 1337 // Now simulate the ICE restart on ep1.
1336 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); 1338 ep1_ch1()->SetIceParameters(kIceParams[2]);
1337 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); 1339
1340 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]);
1338 ep1_ch1()->MaybeStartGathering(); 1341 ep1_ch1()->MaybeStartGathering();
1339 1342
1340 // Finally send the candidates from ep2's ICE restart and verify that ep1 uses 1343 // Finally send the candidates from ep2's ICE restart and verify that ep1 uses
1341 // their information to update the peer reflexive candidate. 1344 // their information to update the peer reflexive candidate.
1342 ResumeCandidates(1); 1345 ResumeCandidates(1);
1343 1346
1344 EXPECT_EQ_WAIT("relay", 1347 EXPECT_EQ_WAIT("relay",
1345 ep1_ch1()->selected_connection()->remote_candidate().type(), 1348 ep1_ch1()->selected_connection()->remote_candidate().type(),
1346 kDefaultTimeout); 1349 kDefaultTimeout);
1347 EXPECT_EQ(prflx_selected_connection, ep1_ch1()->selected_connection()); 1350 EXPECT_EQ(prflx_selected_connection, ep1_ch1()->selected_connection());
1348 DestroyChannels(); 1351 DestroyChannels();
1349 } 1352 }
1350 1353
1351 // Test that if remote candidates don't have ufrag and pwd, we still work. 1354 // Test that if remote candidates don't have ufrag and pwd, we still work.
1352 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) { 1355 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) {
1353 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); 1356 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS);
1354 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1357 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1355 kDefaultPortAllocatorFlags); 1358 kDefaultPortAllocatorFlags);
1356 CreateChannels(1); 1359 CreateChannels(1);
1357 const Connection* selected_connection = NULL; 1360 const Connection* selected_connection = NULL;
1358 // Wait until the callee's connections are created. 1361 // Wait until the callee's connections are created.
1359 WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 1000); 1362 WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 1000);
1360 // Wait to see if they get culled; they shouldn't. 1363 // Wait to see if they get culled; they shouldn't.
1361 WAIT(ep2_ch1()->selected_connection() != selected_connection, 1000); 1364 WAIT(ep2_ch1()->selected_connection() != selected_connection, 1000);
1362 EXPECT_TRUE(ep2_ch1()->selected_connection() == selected_connection); 1365 EXPECT_TRUE(ep2_ch1()->selected_connection() == selected_connection);
1363 DestroyChannels(); 1366 DestroyChannels();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 int kOnlyLocalTcpPorts = PORTALLOCATOR_DISABLE_UDP | 1415 int kOnlyLocalTcpPorts = PORTALLOCATOR_DISABLE_UDP |
1413 PORTALLOCATOR_DISABLE_STUN | 1416 PORTALLOCATOR_DISABLE_STUN |
1414 PORTALLOCATOR_DISABLE_RELAY; 1417 PORTALLOCATOR_DISABLE_RELAY;
1415 // Disable all protocols except TCP. 1418 // Disable all protocols except TCP.
1416 SetAllocatorFlags(0, kOnlyLocalTcpPorts); 1419 SetAllocatorFlags(0, kOnlyLocalTcpPorts);
1417 SetAllocatorFlags(1, kOnlyLocalTcpPorts); 1420 SetAllocatorFlags(1, kOnlyLocalTcpPorts);
1418 1421
1419 SetAllowTcpListen(0, true); // actpass. 1422 SetAllowTcpListen(0, true); // actpass.
1420 SetAllowTcpListen(1, false); // active. 1423 SetAllowTcpListen(1, false); // active.
1421 1424
1422 // We want SetRemoteIceCredentials to be called as it normally would. 1425 // We want SetRemoteIceParameters to be called as it normally would.
1423 // Otherwise we won't know what credentials to use for the expected 1426 // Otherwise we won't know what parameters to use for the expected
1424 // prflx TCP candidates. 1427 // prflx TCP candidates.
1425 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); 1428 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS);
1426 1429
1427 // Pause candidate so we could verify the candidate properties. 1430 // Pause candidate so we could verify the candidate properties.
1428 PauseCandidates(0); 1431 PauseCandidates(0);
1429 PauseCandidates(1); 1432 PauseCandidates(1);
1430 CreateChannels(1); 1433 CreateChannels(1);
1431 1434
1432 // Verify tcp candidates. 1435 // Verify tcp candidates.
1433 VerifySavedTcpCandidates(0, TCPTYPE_PASSIVE_STR); 1436 VerifySavedTcpCandidates(0, TCPTYPE_PASSIVE_STR);
1434 VerifySavedTcpCandidates(1, TCPTYPE_ACTIVE_STR); 1437 VerifySavedTcpCandidates(1, TCPTYPE_ACTIVE_STR);
1435 1438
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 } 1704 }
1702 1705
1703 // Test that when the "presume_writable_when_fully_relayed" flag is set to 1706 // Test that when the "presume_writable_when_fully_relayed" flag is set to
1704 // true and there's a TURN-TURN candidate pair, it's presumed to be writable 1707 // true and there's a TURN-TURN candidate pair, it's presumed to be writable
1705 // as soon as it's created. 1708 // as soon as it's created.
1706 TEST_F(P2PTransportChannelTest, TurnToTurnPresumedWritable) { 1709 TEST_F(P2PTransportChannelTest, TurnToTurnPresumedWritable) {
1707 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, 1710 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags,
1708 kDefaultPortAllocatorFlags); 1711 kDefaultPortAllocatorFlags);
1709 // Only configure one channel so we can control when the remote candidate 1712 // Only configure one channel so we can control when the remote candidate
1710 // is added. 1713 // is added.
1711 GetEndpoint(0)->cd1_.ch_.reset( 1714 GetEndpoint(0)->cd1_.ch_.reset(CreateChannel(
1712 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0], 1715 0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[0], kIceParams[1]));
1713 kIcePwd[0], kIceUfrag[1], kIcePwd[1]));
1714 IceConfig config; 1716 IceConfig config;
1715 config.presume_writable_when_fully_relayed = true; 1717 config.presume_writable_when_fully_relayed = true;
1716 ep1_ch1()->SetIceConfig(config); 1718 ep1_ch1()->SetIceConfig(config);
1717 ep1_ch1()->MaybeStartGathering(); 1719 ep1_ch1()->MaybeStartGathering();
1718 EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, 1720 EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete,
1719 ep1_ch1()->gathering_state(), kDefaultTimeout); 1721 ep1_ch1()->gathering_state(), kDefaultTimeout);
1720 // Add two remote candidates; a host candidate (with higher priority) 1722 // Add two remote candidates; a host candidate (with higher priority)
1721 // and TURN candidate. 1723 // and TURN candidate.
1722 ep1_ch1()->AddRemoteCandidate( 1724 ep1_ch1()->AddRemoteCandidate(
1723 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 1725 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
(...skipping 25 matching lines...) Expand all
1749 virtual_socket_server()->UpdateDelayDistribution(); 1751 virtual_socket_server()->UpdateDelayDistribution();
1750 1752
1751 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, 1753 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags,
1752 kDefaultPortAllocatorFlags); 1754 kDefaultPortAllocatorFlags);
1753 // We want the remote TURN candidate to show up as prflx. To do this we need 1755 // We want the remote TURN candidate to show up as prflx. To do this we need
1754 // to configure the server to accept packets from an address we haven't 1756 // to configure the server to accept packets from an address we haven't
1755 // explicitly installed permission for. 1757 // explicitly installed permission for.
1756 test_turn_server()->set_enable_permission_checks(false); 1758 test_turn_server()->set_enable_permission_checks(false);
1757 IceConfig config; 1759 IceConfig config;
1758 config.presume_writable_when_fully_relayed = true; 1760 config.presume_writable_when_fully_relayed = true;
1759 GetEndpoint(0)->cd1_.ch_.reset( 1761 GetEndpoint(0)->cd1_.ch_.reset(CreateChannel(
1760 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0], 1762 0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[0], kIceParams[1]));
1761 kIcePwd[0], kIceUfrag[1], kIcePwd[1])); 1763 GetEndpoint(1)->cd1_.ch_.reset(CreateChannel(
1762 GetEndpoint(1)->cd1_.ch_.reset( 1764 1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[1], kIceParams[0]));
1763 CreateChannel(1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[1],
1764 kIcePwd[1], kIceUfrag[0], kIcePwd[0]));
1765 ep1_ch1()->SetIceConfig(config); 1765 ep1_ch1()->SetIceConfig(config);
1766 ep2_ch1()->SetIceConfig(config); 1766 ep2_ch1()->SetIceConfig(config);
1767 // Don't signal candidates from channel 2, so that channel 1 sees the TURN 1767 // Don't signal candidates from channel 2, so that channel 1 sees the TURN
1768 // candidate as peer reflexive. 1768 // candidate as peer reflexive.
1769 PauseCandidates(1); 1769 PauseCandidates(1);
1770 ep1_ch1()->MaybeStartGathering(); 1770 ep1_ch1()->MaybeStartGathering();
1771 ep2_ch1()->MaybeStartGathering(); 1771 ep2_ch1()->MaybeStartGathering();
1772 1772
1773 // Wait for the TURN<->prflx connection. 1773 // Wait for the TURN<->prflx connection.
1774 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable(), 1774 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable(),
(...skipping 15 matching lines...) Expand all
1790 1790
1791 // Test that a presumed-writable TURN<->TURN connection is preferred above an 1791 // Test that a presumed-writable TURN<->TURN connection is preferred above an
1792 // unreliable connection (one that has failed to be pinged for some time). 1792 // unreliable connection (one that has failed to be pinged for some time).
1793 TEST_F(P2PTransportChannelTest, PresumedWritablePreferredOverUnreliable) { 1793 TEST_F(P2PTransportChannelTest, PresumedWritablePreferredOverUnreliable) {
1794 rtc::ScopedFakeClock fake_clock; 1794 rtc::ScopedFakeClock fake_clock;
1795 1795
1796 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, 1796 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags,
1797 kDefaultPortAllocatorFlags); 1797 kDefaultPortAllocatorFlags);
1798 IceConfig config; 1798 IceConfig config;
1799 config.presume_writable_when_fully_relayed = true; 1799 config.presume_writable_when_fully_relayed = true;
1800 GetEndpoint(0)->cd1_.ch_.reset( 1800 GetEndpoint(0)->cd1_.ch_.reset(CreateChannel(
1801 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0], 1801 0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[0], kIceParams[1]));
1802 kIcePwd[0], kIceUfrag[1], kIcePwd[1])); 1802 GetEndpoint(1)->cd1_.ch_.reset(CreateChannel(
1803 GetEndpoint(1)->cd1_.ch_.reset( 1803 1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[1], kIceParams[0]));
1804 CreateChannel(1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[1],
1805 kIcePwd[1], kIceUfrag[0], kIcePwd[0]));
1806 ep1_ch1()->SetIceConfig(config); 1804 ep1_ch1()->SetIceConfig(config);
1807 ep2_ch1()->SetIceConfig(config); 1805 ep2_ch1()->SetIceConfig(config);
1808 ep1_ch1()->MaybeStartGathering(); 1806 ep1_ch1()->MaybeStartGathering();
1809 ep2_ch1()->MaybeStartGathering(); 1807 ep2_ch1()->MaybeStartGathering();
1810 // Wait for initial connection as usual. 1808 // Wait for initial connection as usual.
1811 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 1809 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
1812 ep1_ch1()->selected_connection()->writable() && 1810 ep1_ch1()->selected_connection()->writable() &&
1813 ep2_ch1()->receiving() && 1811 ep2_ch1()->receiving() &&
1814 ep2_ch1()->writable() && 1812 ep2_ch1()->writable() &&
1815 ep2_ch1()->selected_connection()->writable(), 1813 ep2_ch1()->selected_connection()->writable(),
(...skipping 22 matching lines...) Expand all
1838 // address of the outermost NAT. 1836 // address of the outermost NAT.
1839 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase { 1837 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase {
1840 protected: 1838 protected:
1841 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) { 1839 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) {
1842 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC); 1840 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC);
1843 rtc::NATSocketServer::Translator* outer_nat = 1841 rtc::NATSocketServer::Translator* outer_nat =
1844 nat()->AddTranslator(kPublicAddrs[0], kNatAddrs[0], 1842 nat()->AddTranslator(kPublicAddrs[0], kNatAddrs[0],
1845 static_cast<rtc::NATType>(nat_type - NAT_FULL_CONE)); 1843 static_cast<rtc::NATType>(nat_type - NAT_FULL_CONE));
1846 ConfigureEndpoint(outer_nat, 0, config1); 1844 ConfigureEndpoint(outer_nat, 0, config1);
1847 ConfigureEndpoint(outer_nat, 1, config2); 1845 ConfigureEndpoint(outer_nat, 1, config2);
1848 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); 1846 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS);
1849 } 1847 }
1850 void ConfigureEndpoint(rtc::NATSocketServer::Translator* nat, 1848 void ConfigureEndpoint(rtc::NATSocketServer::Translator* nat,
1851 int endpoint, Config config) { 1849 int endpoint, Config config) {
1852 ASSERT(config <= NAT_SYMMETRIC); 1850 ASSERT(config <= NAT_SYMMETRIC);
1853 if (config == OPEN) { 1851 if (config == OPEN) {
1854 AddAddress(endpoint, kPrivateAddrs[endpoint]); 1852 AddAddress(endpoint, kPrivateAddrs[endpoint]);
1855 nat->AddClient(kPrivateAddrs[endpoint]); 1853 nat->AddClient(kPrivateAddrs[endpoint]);
1856 } else { 1854 } else {
1857 AddAddress(endpoint, kCascadedPrivateAddrs[endpoint]); 1855 AddAddress(endpoint, kCascadedPrivateAddrs[endpoint]);
1858 nat->AddTranslator(kPrivateAddrs[endpoint], kCascadedNatAddrs[endpoint], 1856 nat->AddTranslator(kPrivateAddrs[endpoint], kCascadedNatAddrs[endpoint],
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
2034 // Adding alternate address will make sure |kPublicAddrs| has the higher 2032 // Adding alternate address will make sure |kPublicAddrs| has the higher
2035 // priority than others. This is due to FakeNetwork::AddInterface method. 2033 // priority than others. This is due to FakeNetwork::AddInterface method.
2036 AddAddress(0, kAlternateAddrs[0]); 2034 AddAddress(0, kAlternateAddrs[0]);
2037 AddAddress(0, kPublicAddrs[0]); 2035 AddAddress(0, kPublicAddrs[0]);
2038 AddAddress(1, kPublicAddrs[1]); 2036 AddAddress(1, kPublicAddrs[1]);
2039 2037
2040 // Use only local ports for simplicity. 2038 // Use only local ports for simplicity.
2041 SetAllocatorFlags(0, kOnlyLocalPorts); 2039 SetAllocatorFlags(0, kOnlyLocalPorts);
2042 SetAllocatorFlags(1, kOnlyLocalPorts); 2040 SetAllocatorFlags(1, kOnlyLocalPorts);
2043 2041
2044 // Create channels and let them go writable, as usual. 2042 // We want it to set the remote ICE parameters when creating channels.
2045 CreateChannels(1); 2043 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS);
2046 ep1_ch1()->set_remote_supports_renomination(true); 2044 // Create channels with renomination enabled.
2045 CreateChannels(1, true);
2047 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && 2046 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() &&
2048 ep2_ch1()->receiving() && 2047 ep2_ch1()->receiving() &&
2049 ep2_ch1()->writable(), 2048 ep2_ch1()->writable(),
2050 3000, clock); 2049 3000, clock);
2051 EXPECT_TRUE_SIMULATED_WAIT( 2050 EXPECT_TRUE_SIMULATED_WAIT(
2052 ep2_ch1()->selected_connection()->remote_nomination() > 0 && 2051 ep2_ch1()->selected_connection()->remote_nomination() > 0 &&
2053 ep1_ch1()->selected_connection()->acked_nomination() > 0, 2052 ep1_ch1()->selected_connection()->acked_nomination() > 0,
2054 kDefaultTimeout, clock); 2053 kDefaultTimeout, clock);
2055 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); 2054 const Connection* selected_connection1 = ep1_ch1()->selected_connection();
2056 Connection* selected_connection2 = 2055 Connection* selected_connection2 =
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
2562 public sigslot::has_slots<> { 2561 public sigslot::has_slots<> {
2563 public: 2562 public:
2564 P2PTransportChannelPingTest() 2563 P2PTransportChannelPingTest()
2565 : pss_(new rtc::PhysicalSocketServer), 2564 : pss_(new rtc::PhysicalSocketServer),
2566 vss_(new rtc::VirtualSocketServer(pss_.get())), 2565 vss_(new rtc::VirtualSocketServer(pss_.get())),
2567 ss_scope_(vss_.get()) {} 2566 ss_scope_(vss_.get()) {}
2568 2567
2569 protected: 2568 protected:
2570 void PrepareChannel(P2PTransportChannel* ch) { 2569 void PrepareChannel(P2PTransportChannel* ch) {
2571 ch->SetIceRole(ICEROLE_CONTROLLING); 2570 ch->SetIceRole(ICEROLE_CONTROLLING);
2572 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); 2571 ch->SetIceParameters(kIceParams[0]);
2573 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 2572 ch->SetRemoteIceParameters(kIceParams[1]);
2574 ch->SignalSelectedCandidatePairChanged.connect( 2573 ch->SignalSelectedCandidatePairChanged.connect(
2575 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged); 2574 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged);
2576 ch->SignalReadyToSend.connect(this, 2575 ch->SignalReadyToSend.connect(this,
2577 &P2PTransportChannelPingTest::OnReadyToSend); 2576 &P2PTransportChannelPingTest::OnReadyToSend);
2578 ch->SignalStateChanged.connect( 2577 ch->SignalStateChanged.connect(
2579 this, &P2PTransportChannelPingTest::OnChannelStateChanged); 2578 this, &P2PTransportChannelPingTest::OnChannelStateChanged);
2580 } 2579 }
2581 2580
2582 Connection* WaitForConnectionTo(P2PTransportChannel* ch, 2581 Connection* WaitForConnectionTo(P2PTransportChannel* ch,
2583 const std::string& ip, 2582 const std::string& ip,
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2836 start = clock.TimeNanos(); 2835 start = clock.TimeNanos();
2837 ping_sent_before = conn->num_pings_sent(); 2836 ping_sent_before = conn->num_pings_sent();
2838 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); 2837 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock);
2839 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; 2838 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec;
2840 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); 2839 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL);
2841 EXPECT_LE(ping_interval_ms, 2840 EXPECT_LE(ping_interval_ms,
2842 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); 2841 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE);
2843 } 2842 }
2844 2843
2845 // Test that we start pinging as soon as we have a connection and remote ICE 2844 // Test that we start pinging as soon as we have a connection and remote ICE
2846 // credentials. 2845 // parameters.
2847 TEST_F(P2PTransportChannelPingTest, PingingStartedAsSoonAsPossible) { 2846 TEST_F(P2PTransportChannelPingTest, PingingStartedAsSoonAsPossible) {
2848 rtc::ScopedFakeClock clock; 2847 rtc::ScopedFakeClock clock;
2849 2848
2850 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2849 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2851 P2PTransportChannel ch("TestChannel", 1, &pa); 2850 P2PTransportChannel ch("TestChannel", 1, &pa);
2852 ch.SetIceRole(ICEROLE_CONTROLLING); 2851 ch.SetIceRole(ICEROLE_CONTROLLING);
2853 ch.SetIceCredentials(kIceUfrag[0], kIcePwd[0]); 2852 ch.SetIceParameters(kIceParams[0]);
2854 ch.MaybeStartGathering(); 2853 ch.MaybeStartGathering();
2855 EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, ch.gathering_state(), 2854 EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, ch.gathering_state(),
2856 kDefaultTimeout); 2855 kDefaultTimeout);
2857 2856
2858 // Simulate a binding request being received, creating a peer reflexive 2857 // Simulate a binding request being received, creating a peer reflexive
2859 // candidate pair while we still don't have remote ICE credentials. 2858 // candidate pair while we still don't have remote ICE parameters.
2860 IceMessage request; 2859 IceMessage request;
2861 request.SetType(STUN_BINDING_REQUEST); 2860 request.SetType(STUN_BINDING_REQUEST);
2862 request.AddAttribute( 2861 request.AddAttribute(
2863 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); 2862 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1]));
2864 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; 2863 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
2865 request.AddAttribute( 2864 request.AddAttribute(
2866 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); 2865 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority));
2867 Port* port = GetPort(&ch); 2866 Port* port = GetPort(&ch);
2868 ASSERT_NE(nullptr, port); 2867 ASSERT_NE(nullptr, port);
2869 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, 2868 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP,
2870 &request, kIceUfrag[1], false); 2869 &request, kIceUfrag[1], false);
2871 Connection* conn = GetConnectionTo(&ch, "1.1.1.1", 1); 2870 Connection* conn = GetConnectionTo(&ch, "1.1.1.1", 1);
2872 ASSERT_NE(nullptr, conn); 2871 ASSERT_NE(nullptr, conn);
2873 2872
2874 // Simulate waiting for a second (and change) and verify that no pings were 2873 // Simulate waiting for a second (and change) and verify that no pings were
2875 // sent, since we don't yet have remote ICE credentials. 2874 // sent, since we don't yet have remote ICE parameters.
2876 SIMULATED_WAIT(conn->num_pings_sent() > 0, 1025, clock); 2875 SIMULATED_WAIT(conn->num_pings_sent() > 0, 1025, clock);
2877 EXPECT_EQ(0, conn->num_pings_sent()); 2876 EXPECT_EQ(0, conn->num_pings_sent());
2878 2877
2879 // Set remote ICE credentials. Now we should be able to ping. Ensure that 2878 // Set remote ICE parameters. Now we should be able to ping. Ensure that
2880 // the first ping is sent as soon as possible, within one simulated clock 2879 // the first ping is sent as soon as possible, within one simulated clock
2881 // tick. 2880 // tick.
2882 ch.SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); 2881 ch.SetRemoteIceParameters(kIceParams[1]);
2883 EXPECT_TRUE_SIMULATED_WAIT(conn->num_pings_sent() > 0, 1, clock); 2882 EXPECT_TRUE_SIMULATED_WAIT(conn->num_pings_sent() > 0, 1, clock);
2884 } 2883 }
2885 2884
2886 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { 2885 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) {
2887 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2886 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2888 P2PTransportChannel ch("trigger checks", 1, &pa); 2887 P2PTransportChannel ch("trigger checks", 1, &pa);
2889 PrepareChannel(&ch); 2888 PrepareChannel(&ch);
2890 ch.MaybeStartGathering(); 2889 ch.MaybeStartGathering();
2891 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 2890 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
2892 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); 2891 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2));
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2936 // Pruning the connection reduces the set of active connections and changes 2935 // Pruning the connection reduces the set of active connections and changes
2937 // the channel state. 2936 // the channel state.
2938 conn1->Prune(); 2937 conn1->Prune();
2939 EXPECT_EQ_WAIT(STATE_FAILED, channel_state(), kDefaultTimeout); 2938 EXPECT_EQ_WAIT(STATE_FAILED, channel_state(), kDefaultTimeout);
2940 } 2939 }
2941 2940
2942 // Test adding remote candidates with different ufrags. If a remote candidate 2941 // Test adding remote candidates with different ufrags. If a remote candidate
2943 // is added with an old ufrag, it will be discarded. If it is added with a 2942 // is added with an old ufrag, it will be discarded. If it is added with a
2944 // ufrag that was not seen before, it will be used to create connections 2943 // ufrag that was not seen before, it will be used to create connections
2945 // although the ICE pwd in the remote candidate will be set when the ICE 2944 // although the ICE pwd in the remote candidate will be set when the ICE
2946 // credentials arrive. If a remote candidate is added with the current ICE 2945 // parameters arrive. If a remote candidate is added with the current ICE
2947 // ufrag, its pwd and generation will be set properly. 2946 // ufrag, its pwd and generation will be set properly.
2948 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { 2947 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) {
2949 FakePortAllocator pa(rtc::Thread::Current(), nullptr); 2948 FakePortAllocator pa(rtc::Thread::Current(), nullptr);
2950 P2PTransportChannel ch("add candidate", 1, &pa); 2949 P2PTransportChannel ch("add candidate", 1, &pa);
2951 PrepareChannel(&ch); 2950 PrepareChannel(&ch);
2952 ch.MaybeStartGathering(); 2951 ch.MaybeStartGathering();
2953 // Add a candidate with a future ufrag. 2952 // Add a candidate with a future ufrag.
2954 ch.AddRemoteCandidate( 2953 ch.AddRemoteCandidate(
2955 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1, kIceUfrag[2])); 2954 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1, kIceUfrag[2]));
2956 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 2955 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
2957 ASSERT_TRUE(conn1 != nullptr); 2956 ASSERT_TRUE(conn1 != nullptr);
2958 const Candidate& candidate = conn1->remote_candidate(); 2957 const Candidate& candidate = conn1->remote_candidate();
2959 EXPECT_EQ(kIceUfrag[2], candidate.username()); 2958 EXPECT_EQ(kIceUfrag[2], candidate.username());
2960 EXPECT_TRUE(candidate.password().empty()); 2959 EXPECT_TRUE(candidate.password().empty());
2961 EXPECT_TRUE(FindNextPingableConnectionAndPingIt(&ch) == nullptr); 2960 EXPECT_TRUE(FindNextPingableConnectionAndPingIt(&ch) == nullptr);
2962 2961
2963 // Set the remote credentials with the "future" ufrag. 2962 // Set the remote ICE parameters with the "future" ufrag.
2964 // This should set the ICE pwd in the remote candidate of |conn1|, making 2963 // This should set the ICE pwd in the remote candidate of |conn1|, making
2965 // it pingable. 2964 // it pingable.
2966 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); 2965 ch.SetRemoteIceParameters(kIceParams[2]);
2967 EXPECT_EQ(kIceUfrag[2], candidate.username()); 2966 EXPECT_EQ(kIceUfrag[2], candidate.username());
2968 EXPECT_EQ(kIcePwd[2], candidate.password()); 2967 EXPECT_EQ(kIcePwd[2], candidate.password());
2969 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); 2968 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch));
2970 2969
2971 // Add a candidate with an old ufrag. No connection will be created. 2970 // Add a candidate with an old ufrag. No connection will be created.
2972 ch.AddRemoteCandidate( 2971 ch.AddRemoteCandidate(
2973 CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2, kIceUfrag[1])); 2972 CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2, kIceUfrag[1]));
2974 rtc::Thread::Current()->ProcessMessages(500); 2973 rtc::Thread::Current()->ProcessMessages(500);
2975 EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr); 2974 EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr);
2976 2975
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
3212 ASSERT_TRUE(conn4 != nullptr); 3211 ASSERT_TRUE(conn4 != nullptr);
3213 EXPECT_TRUE(port->sent_binding_response()); 3212 EXPECT_TRUE(port->sent_binding_response());
3214 // conn4 is not the selected connection yet because it is not writable. 3213 // conn4 is not the selected connection yet because it is not writable.
3215 EXPECT_EQ(conn2, ch.selected_connection()); 3214 EXPECT_EQ(conn2, ch.selected_connection());
3216 conn4->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. 3215 conn4->ReceivedPingResponse(LOW_RTT, "id"); // Become writable.
3217 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); 3216 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout);
3218 3217
3219 // Test that the request from an unknown address contains a ufrag from an old 3218 // Test that the request from an unknown address contains a ufrag from an old
3220 // generation. 3219 // generation.
3221 port->set_sent_binding_response(false); 3220 port->set_sent_binding_response(false);
3222 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); 3221 ch.SetRemoteIceParameters(kIceParams[2]);
3223 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); 3222 ch.SetRemoteIceParameters(kIceParams[3]);
3224 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP, 3223 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP,
3225 &request, kIceUfrag[2], false); 3224 &request, kIceUfrag[2], false);
3226 Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); 3225 Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5);
3227 ASSERT_TRUE(conn5 != nullptr); 3226 ASSERT_TRUE(conn5 != nullptr);
3228 EXPECT_TRUE(port->sent_binding_response()); 3227 EXPECT_TRUE(port->sent_binding_response());
3229 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password()); 3228 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password());
3230 } 3229 }
3231 3230
3232 // The controlled side will select a connection as the "selected connection" 3231 // The controlled side will select a connection as the "selected connection"
3233 // based on media received until the controlling side nominates a connection, 3232 // based on media received until the controlling side nominates a connection,
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
3672 ch.MaybeStartGathering(); 3671 ch.MaybeStartGathering();
3673 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); 3672 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100));
3674 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3673 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3675 ASSERT_TRUE(conn1 != nullptr); 3674 ASSERT_TRUE(conn1 != nullptr);
3676 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving 3675 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving
3677 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); 3676 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts());
3678 3677
3679 // Start a new session. Even though conn1, which belongs to an older 3678 // Start a new session. Even though conn1, which belongs to an older
3680 // session, becomes unwritable and writable again, it should not stop the 3679 // session, becomes unwritable and writable again, it should not stop the
3681 // current session. 3680 // current session.
3682 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); 3681 ch.SetIceParameters(kIceParams[1]);
3683 ch.MaybeStartGathering(); 3682 ch.MaybeStartGathering();
3684 conn1->Prune(); 3683 conn1->Prune();
3685 conn1->ReceivedPingResponse(LOW_RTT, "id"); 3684 conn1->ReceivedPingResponse(LOW_RTT, "id");
3686 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); 3685 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts());
3687 3686
3688 // But if a new connection created from the new session becomes writable, 3687 // But if a new connection created from the new session becomes writable,
3689 // it will stop the current session. 3688 // it will stop the current session.
3690 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100)); 3689 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100));
3691 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); 3690 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2);
3692 ASSERT_TRUE(conn2 != nullptr); 3691 ASSERT_TRUE(conn2 != nullptr);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3728 // Starts with ICEROLE_CONTROLLING. 3727 // Starts with ICEROLE_CONTROLLING.
3729 PrepareChannel(&ch); 3728 PrepareChannel(&ch);
3730 ch.MaybeStartGathering(); 3729 ch.MaybeStartGathering();
3731 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); 3730 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1));
3732 3731
3733 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); 3732 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1);
3734 ASSERT_TRUE(conn != nullptr); 3733 ASSERT_TRUE(conn != nullptr);
3735 3734
3736 // Do an ICE restart, change the role, and expect the old port to have its 3735 // Do an ICE restart, change the role, and expect the old port to have its
3737 // role updated. 3736 // role updated.
3738 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); 3737 ch.SetIceParameters(kIceParams[1]);
3739 ch.MaybeStartGathering(); 3738 ch.MaybeStartGathering();
3740 ch.SetIceRole(ICEROLE_CONTROLLED); 3739 ch.SetIceRole(ICEROLE_CONTROLLED);
3741 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); 3740 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole());
3742 } 3741 }
3743 3742
3744 // Test that after some amount of time without receiving data, the connection 3743 // Test that after some amount of time without receiving data, the connection
3745 // will be destroyed. The port will only be destroyed after it is marked as 3744 // will be destroyed. The port will only be destroyed after it is marked as
3746 // "pruned." 3745 // "pruned."
3747 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeoutAndPruned) { 3746 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeoutAndPruned) {
3748 rtc::ScopedFakeClock fake_clock; 3747 rtc::ScopedFakeClock fake_clock;
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
3978 3977
3979 // TCP Relay/Relay is the next. 3978 // TCP Relay/Relay is the next.
3980 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, 3979 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE,
3981 TCP_PROTOCOL_NAME); 3980 TCP_PROTOCOL_NAME);
3982 3981
3983 // Finally, Local/Relay will be pinged. 3982 // Finally, Local/Relay will be pinged.
3984 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); 3983 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE);
3985 } 3984 }
3986 3985
3987 } // namespace cricket { 3986 } // namespace cricket {
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698