| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 |
| 311 IceParameters IceParamsWithRenomination(const IceParameters& ice, |
| 312 bool renomination) { |
| 313 IceParameters new_ice = ice; |
| 314 new_ice.renomination = renomination; |
| 315 return new_ice; |
| 316 } |
| 317 |
| 308 void CreateChannels(int num, | 318 void CreateChannels(int num, |
| 309 const IceConfig& ep1_config, | 319 const IceConfig& ep1_config, |
| 310 const IceConfig& ep2_config) { | 320 const IceConfig& ep2_config, |
| 311 std::string ice_ufrag_ep1_cd1_ch = kIceUfrag[0]; | 321 bool renomination = false) { |
| 312 std::string ice_pwd_ep1_cd1_ch = kIcePwd[0]; | 322 IceParameters ice_ep1_cd1_ch = |
| 313 std::string ice_ufrag_ep2_cd1_ch = kIceUfrag[1]; | 323 IceParamsWithRenomination(kIceParams[0], renomination); |
| 314 std::string ice_pwd_ep2_cd1_ch = kIcePwd[1]; | 324 IceParameters ice_ep2_cd1_ch = |
| 315 ep1_.cd1_.ch_.reset(CreateChannel( | 325 IceParamsWithRenomination(kIceParams[1], renomination); |
| 316 0, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep1_cd1_ch, | 326 ep1_.cd1_.ch_.reset(CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, |
| 317 ice_pwd_ep1_cd1_ch, ice_ufrag_ep2_cd1_ch, ice_pwd_ep2_cd1_ch)); | 327 ice_ep1_cd1_ch, ice_ep2_cd1_ch)); |
| 318 ep2_.cd1_.ch_.reset(CreateChannel( | 328 ep2_.cd1_.ch_.reset(CreateChannel(1, ICE_CANDIDATE_COMPONENT_DEFAULT, |
| 319 1, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep2_cd1_ch, | 329 ice_ep2_cd1_ch, ice_ep1_cd1_ch)); |
| 320 ice_pwd_ep2_cd1_ch, ice_ufrag_ep1_cd1_ch, ice_pwd_ep1_cd1_ch)); | |
| 321 ep1_.cd1_.ch_->SetIceConfig(ep1_config); | 330 ep1_.cd1_.ch_->SetIceConfig(ep1_config); |
| 322 ep2_.cd1_.ch_->SetIceConfig(ep2_config); | 331 ep2_.cd1_.ch_->SetIceConfig(ep2_config); |
| 323 ep1_.cd1_.ch_->MaybeStartGathering(); | 332 ep1_.cd1_.ch_->MaybeStartGathering(); |
| 324 ep2_.cd1_.ch_->MaybeStartGathering(); | 333 ep2_.cd1_.ch_->MaybeStartGathering(); |
| 325 if (num == 2) { | 334 if (num == 2) { |
| 326 std::string ice_ufrag_ep1_cd2_ch = kIceUfrag[2]; | 335 IceParameters ice_ep1_cd2_ch = |
| 327 std::string ice_pwd_ep1_cd2_ch = kIcePwd[2]; | 336 IceParamsWithRenomination(kIceParams[2], renomination); |
| 328 std::string ice_ufrag_ep2_cd2_ch = kIceUfrag[3]; | 337 IceParameters ice_ep2_cd2_ch = |
| 329 std::string ice_pwd_ep2_cd2_ch = kIcePwd[3]; | 338 IceParamsWithRenomination(kIceParams[3], renomination); |
| 330 ep1_.cd2_.ch_.reset(CreateChannel( | 339 ep1_.cd2_.ch_.reset(CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, |
| 331 0, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep1_cd2_ch, | 340 ice_ep1_cd2_ch, ice_ep2_cd2_ch)); |
| 332 ice_pwd_ep1_cd2_ch, ice_ufrag_ep2_cd2_ch, ice_pwd_ep2_cd2_ch)); | 341 ep2_.cd2_.ch_.reset(CreateChannel(1, ICE_CANDIDATE_COMPONENT_DEFAULT, |
| 333 ep2_.cd2_.ch_.reset(CreateChannel( | 342 ice_ep2_cd2_ch, ice_ep1_cd2_ch)); |
| 334 1, ICE_CANDIDATE_COMPONENT_DEFAULT, ice_ufrag_ep2_cd2_ch, | |
| 335 ice_pwd_ep2_cd2_ch, ice_ufrag_ep1_cd2_ch, ice_pwd_ep1_cd2_ch)); | |
| 336 ep1_.cd2_.ch_->SetIceConfig(ep1_config); | 343 ep1_.cd2_.ch_->SetIceConfig(ep1_config); |
| 337 ep2_.cd2_.ch_->SetIceConfig(ep2_config); | 344 ep2_.cd2_.ch_->SetIceConfig(ep2_config); |
| 338 ep1_.cd2_.ch_->MaybeStartGathering(); | 345 ep1_.cd2_.ch_->MaybeStartGathering(); |
| 339 ep2_.cd2_.ch_->MaybeStartGathering(); | 346 ep2_.cd2_.ch_->MaybeStartGathering(); |
| 340 } | 347 } |
| 341 } | 348 } |
| 342 | 349 |
| 343 void CreateChannels(int num) { | 350 void CreateChannels(int num) { |
| 344 IceConfig default_config; | 351 IceConfig default_config; |
| 345 CreateChannels(num, default_config, default_config); | 352 CreateChannels(num, default_config, default_config, false); |
| 346 } | 353 } |
| 347 | 354 |
| 348 P2PTransportChannel* CreateChannel(int endpoint, | 355 P2PTransportChannel* CreateChannel(int endpoint, |
| 349 int component, | 356 int component, |
| 350 const std::string& local_ice_ufrag, | 357 const IceParameters& local_ice, |
| 351 const std::string& local_ice_pwd, | 358 const IceParameters& remote_ice) { |
| 352 const std::string& remote_ice_ufrag, | |
| 353 const std::string& remote_ice_pwd) { | |
| 354 P2PTransportChannel* channel = new P2PTransportChannel( | 359 P2PTransportChannel* channel = new P2PTransportChannel( |
| 355 "test content name", component, GetAllocator(endpoint)); | 360 "test content name", component, GetAllocator(endpoint)); |
| 356 channel->SignalReadyToSend.connect( | 361 channel->SignalReadyToSend.connect( |
| 357 this, &P2PTransportChannelTestBase::OnReadyToSend); | 362 this, &P2PTransportChannelTestBase::OnReadyToSend); |
| 358 channel->SignalCandidateGathered.connect( | 363 channel->SignalCandidateGathered.connect( |
| 359 this, &P2PTransportChannelTestBase::OnCandidateGathered); | 364 this, &P2PTransportChannelTestBase::OnCandidateGathered); |
| 360 channel->SignalCandidatesRemoved.connect( | 365 channel->SignalCandidatesRemoved.connect( |
| 361 this, &P2PTransportChannelTestBase::OnCandidatesRemoved); | 366 this, &P2PTransportChannelTestBase::OnCandidatesRemoved); |
| 362 channel->SignalReadPacket.connect( | 367 channel->SignalReadPacket.connect( |
| 363 this, &P2PTransportChannelTestBase::OnReadPacket); | 368 this, &P2PTransportChannelTestBase::OnReadPacket); |
| 364 channel->SignalRoleConflict.connect( | 369 channel->SignalRoleConflict.connect( |
| 365 this, &P2PTransportChannelTestBase::OnRoleConflict); | 370 this, &P2PTransportChannelTestBase::OnRoleConflict); |
| 366 channel->SignalSelectedCandidatePairChanged.connect( | 371 channel->SignalSelectedCandidatePairChanged.connect( |
| 367 this, &P2PTransportChannelTestBase::OnSelectedCandidatePairChanged); | 372 this, &P2PTransportChannelTestBase::OnSelectedCandidatePairChanged); |
| 368 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); | 373 channel->SetIceParameters(local_ice); |
| 369 if (remote_ice_credential_source_ == FROM_SETICECREDENTIALS) { | 374 if (remote_ice_parameter_source_ == FROM_SETICEPARAMETERS) { |
| 370 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd); | 375 channel->SetRemoteIceParameters(remote_ice); |
| 371 } | 376 } |
| 372 channel->SetIceRole(GetEndpoint(endpoint)->ice_role()); | 377 channel->SetIceRole(GetEndpoint(endpoint)->ice_role()); |
| 373 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker()); | 378 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker()); |
| 374 return channel; | 379 return channel; |
| 375 } | 380 } |
| 376 void DestroyChannels() { | 381 void DestroyChannels() { |
| 377 ep1_.cd1_.ch_.reset(); | 382 ep1_.cd1_.ch_.reset(); |
| 378 ep2_.cd1_.ch_.reset(); | 383 ep2_.cd1_.ch_.reset(); |
| 379 ep1_.cd2_.ch_.reset(); | 384 ep1_.cd2_.ch_.reset(); |
| 380 ep2_.cd2_.ch_.reset(); | 385 ep2_.cd2_.ch_.reset(); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 // local_channel2 <==> remote_channel2 | 596 // local_channel2 <==> remote_channel2 |
| 592 EXPECT_EQ_WAIT(len, SendData(ep1_ch2(), data, len), 1000); | 597 EXPECT_EQ_WAIT(len, SendData(ep1_ch2(), data, len), 1000); |
| 593 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch2(), data, len), 1000); | 598 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch2(), data, len), 1000); |
| 594 EXPECT_EQ_WAIT(len, SendData(ep2_ch2(), data, len), 1000); | 599 EXPECT_EQ_WAIT(len, SendData(ep2_ch2(), data, len), 1000); |
| 595 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep1_ch2(), data, len), 1000); | 600 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep1_ch2(), data, len), 1000); |
| 596 } | 601 } |
| 597 } | 602 } |
| 598 } | 603 } |
| 599 | 604 |
| 600 // This test waits for the transport to become receiving and writable on both | 605 // This test waits for the transport to become receiving and writable on both |
| 601 // end points. Once they are, the end points set new local ice credentials and | 606 // end points. Once they are, the end points set new local ice parameters and |
| 602 // restart the ice gathering. Finally it waits for the transport to select a | 607 // restart the ice gathering. Finally it waits for the transport to select a |
| 603 // new connection using the newly generated ice candidates. | 608 // new connection using the newly generated ice candidates. |
| 604 // Before calling this function the end points must be configured. | 609 // Before calling this function the end points must be configured. |
| 605 void TestHandleIceUfragPasswordChanged() { | 610 void TestHandleIceUfragPasswordChanged() { |
| 606 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 611 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]); |
| 607 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); | 612 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]); |
| 608 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 613 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 609 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 614 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 610 1000, 1000); | 615 1000, 1000); |
| 611 | 616 |
| 612 const Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1()); | 617 const Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1()); |
| 613 const Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1()); | 618 const Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1()); |
| 614 const Candidate* old_remote_candidate1 = RemoteCandidate(ep1_ch1()); | 619 const Candidate* old_remote_candidate1 = RemoteCandidate(ep1_ch1()); |
| 615 const Candidate* old_remote_candidate2 = RemoteCandidate(ep2_ch1()); | 620 const Candidate* old_remote_candidate2 = RemoteCandidate(ep2_ch1()); |
| 616 | 621 |
| 617 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); | 622 ep1_ch1()->SetIceParameters(kIceParams[2]); |
| 618 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 623 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]); |
| 619 ep1_ch1()->MaybeStartGathering(); | 624 ep1_ch1()->MaybeStartGathering(); |
| 620 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]); | 625 ep2_ch1()->SetIceParameters(kIceParams[3]); |
| 621 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); | 626 |
| 627 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]); |
| 622 ep2_ch1()->MaybeStartGathering(); | 628 ep2_ch1()->MaybeStartGathering(); |
| 623 | 629 |
| 624 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() != | 630 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() != |
| 625 old_local_candidate1->generation(), | 631 old_local_candidate1->generation(), |
| 626 1000, 1000); | 632 1000, 1000); |
| 627 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep2_ch1())->generation() != | 633 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep2_ch1())->generation() != |
| 628 old_local_candidate2->generation(), | 634 old_local_candidate2->generation(), |
| 629 1000, 1000); | 635 1000, 1000); |
| 630 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep1_ch1())->generation() != | 636 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep1_ch1())->generation() != |
| 631 old_remote_candidate1->generation(), | 637 old_remote_candidate1->generation(), |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 void OnMessage(rtc::Message* msg) { | 744 void OnMessage(rtc::Message* msg) { |
| 739 switch (msg->message_id) { | 745 switch (msg->message_id) { |
| 740 case MSG_ADD_CANDIDATES: { | 746 case MSG_ADD_CANDIDATES: { |
| 741 std::unique_ptr<CandidatesData> data( | 747 std::unique_ptr<CandidatesData> data( |
| 742 static_cast<CandidatesData*>(msg->pdata)); | 748 static_cast<CandidatesData*>(msg->pdata)); |
| 743 P2PTransportChannel* rch = GetRemoteChannel(data->channel); | 749 P2PTransportChannel* rch = GetRemoteChannel(data->channel); |
| 744 if (!rch) { | 750 if (!rch) { |
| 745 return; | 751 return; |
| 746 } | 752 } |
| 747 for (auto& c : data->candidates) { | 753 for (auto& c : data->candidates) { |
| 748 if (remote_ice_credential_source_ != FROM_CANDIDATE) { | 754 if (remote_ice_parameter_source_ != FROM_CANDIDATE) { |
| 749 c.set_username(""); | 755 c.set_username(""); |
| 750 c.set_password(""); | 756 c.set_password(""); |
| 751 } | 757 } |
| 752 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->" | 758 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->" |
| 753 << rch->component() << "): " << c.ToString(); | 759 << rch->component() << "): " << c.ToString(); |
| 754 rch->AddRemoteCandidate(c); | 760 rch->AddRemoteCandidate(c); |
| 755 } | 761 } |
| 756 break; | 762 break; |
| 757 } | 763 } |
| 758 case MSG_REMOVE_CANDIDATES: { | 764 case MSG_REMOVE_CANDIDATES: { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 return ep1_ch1(); | 829 return ep1_ch1(); |
| 824 else if (ch == ep2_ch2()) | 830 else if (ch == ep2_ch2()) |
| 825 return ep1_ch2(); | 831 return ep1_ch2(); |
| 826 else | 832 else |
| 827 return NULL; | 833 return NULL; |
| 828 } | 834 } |
| 829 std::list<std::string>& GetPacketList(TransportChannel* ch) { | 835 std::list<std::string>& GetPacketList(TransportChannel* ch) { |
| 830 return GetChannelData(ch)->ch_packets_; | 836 return GetChannelData(ch)->ch_packets_; |
| 831 } | 837 } |
| 832 | 838 |
| 833 enum RemoteIceCredentialSource { FROM_CANDIDATE, FROM_SETICECREDENTIALS }; | 839 enum RemoteIceParameterSource { FROM_CANDIDATE, FROM_SETICEPARAMETERS }; |
| 834 | 840 |
| 835 // How does the test pass ICE credentials to the P2PTransportChannel? | 841 // How does the test pass ICE parameters to the P2PTransportChannel? |
| 836 // On the candidate itself, or through SetIceCredentials? | 842 // On the candidate itself, or through SetRemoteIceParameters? |
| 837 // Goes through the candidate itself by default. | 843 // Goes through the candidate itself by default. |
| 838 void set_remote_ice_credential_source(RemoteIceCredentialSource source) { | 844 void set_remote_ice_parameter_source(RemoteIceParameterSource source) { |
| 839 remote_ice_credential_source_ = source; | 845 remote_ice_parameter_source_ = source; |
| 840 } | 846 } |
| 841 | 847 |
| 842 void set_force_relay(bool relay) { | 848 void set_force_relay(bool relay) { |
| 843 force_relay_ = relay; | 849 force_relay_ = relay; |
| 844 } | 850 } |
| 845 | 851 |
| 846 void ConnectSignalNominated(Connection* conn) { | 852 void ConnectSignalNominated(Connection* conn) { |
| 847 conn->SignalNominated.connect(this, | 853 conn->SignalNominated.connect(this, |
| 848 &P2PTransportChannelTestBase::OnNominated); | 854 &P2PTransportChannelTestBase::OnNominated); |
| 849 } | 855 } |
| 850 | 856 |
| 851 void OnNominated(Connection* conn) { nominated_ = true; } | 857 void OnNominated(Connection* conn) { nominated_ = true; } |
| 852 bool nominated() { return nominated_; } | 858 bool nominated() { return nominated_; } |
| 853 | 859 |
| 854 private: | 860 private: |
| 855 rtc::Thread* main_; | 861 rtc::Thread* main_; |
| 856 std::unique_ptr<rtc::PhysicalSocketServer> pss_; | 862 std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
| 857 std::unique_ptr<rtc::VirtualSocketServer> vss_; | 863 std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 858 std::unique_ptr<rtc::NATSocketServer> nss_; | 864 std::unique_ptr<rtc::NATSocketServer> nss_; |
| 859 std::unique_ptr<rtc::FirewallSocketServer> ss_; | 865 std::unique_ptr<rtc::FirewallSocketServer> ss_; |
| 860 rtc::SocketServerScope ss_scope_; | 866 rtc::SocketServerScope ss_scope_; |
| 861 std::unique_ptr<TestStunServer> stun_server_; | 867 std::unique_ptr<TestStunServer> stun_server_; |
| 862 TestTurnServer turn_server_; | 868 TestTurnServer turn_server_; |
| 863 TestRelayServer relay_server_; | 869 TestRelayServer relay_server_; |
| 864 rtc::SocksProxyServer socks_server1_; | 870 rtc::SocksProxyServer socks_server1_; |
| 865 rtc::SocksProxyServer socks_server2_; | 871 rtc::SocksProxyServer socks_server2_; |
| 866 Endpoint ep1_; | 872 Endpoint ep1_; |
| 867 Endpoint ep2_; | 873 Endpoint ep2_; |
| 868 RemoteIceCredentialSource remote_ice_credential_source_ = FROM_CANDIDATE; | 874 RemoteIceParameterSource remote_ice_parameter_source_ = FROM_CANDIDATE; |
| 869 bool force_relay_; | 875 bool force_relay_; |
| 870 int selected_candidate_pair_switches_ = 0; | 876 int selected_candidate_pair_switches_ = 0; |
| 871 | 877 |
| 872 bool nominated_ = false; | 878 bool nominated_ = false; |
| 873 }; | 879 }; |
| 874 | 880 |
| 875 // The tests have only a few outcomes, which we predefine. | 881 // The tests have only a few outcomes, which we predefine. |
| 876 const P2PTransportChannelTestBase::Result | 882 const P2PTransportChannelTestBase::Result |
| 877 P2PTransportChannelTestBase::kLocalUdpToLocalUdp("local", | 883 P2PTransportChannelTestBase::kLocalUdpToLocalUdp("local", |
| 878 "udp", | 884 "udp", |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 GetEndpoint(1)->allocator_->AddTurnServer(turn_server); | 990 GetEndpoint(1)->allocator_->AddTurnServer(turn_server); |
| 985 | 991 |
| 986 int delay = kMinimumStepDelay; | 992 int delay = kMinimumStepDelay; |
| 987 ConfigureEndpoint(0, config1); | 993 ConfigureEndpoint(0, config1); |
| 988 SetAllocatorFlags(0, allocator_flags1); | 994 SetAllocatorFlags(0, allocator_flags1); |
| 989 SetAllocationStepDelay(0, delay); | 995 SetAllocationStepDelay(0, delay); |
| 990 ConfigureEndpoint(1, config2); | 996 ConfigureEndpoint(1, config2); |
| 991 SetAllocatorFlags(1, allocator_flags2); | 997 SetAllocatorFlags(1, allocator_flags2); |
| 992 SetAllocationStepDelay(1, delay); | 998 SetAllocationStepDelay(1, delay); |
| 993 | 999 |
| 994 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); | 1000 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS); |
| 995 } | 1001 } |
| 996 void ConfigureEndpoint(int endpoint, Config config) { | 1002 void ConfigureEndpoint(int endpoint, Config config) { |
| 997 switch (config) { | 1003 switch (config) { |
| 998 case OPEN: | 1004 case OPEN: |
| 999 AddAddress(endpoint, kPublicAddrs[endpoint]); | 1005 AddAddress(endpoint, kPublicAddrs[endpoint]); |
| 1000 break; | 1006 break; |
| 1001 case NAT_FULL_CONE: | 1007 case NAT_FULL_CONE: |
| 1002 case NAT_ADDR_RESTRICTED: | 1008 case NAT_ADDR_RESTRICTED: |
| 1003 case NAT_PORT_RESTRICTED: | 1009 case NAT_PORT_RESTRICTED: |
| 1004 case NAT_SYMMETRIC: | 1010 case NAT_SYMMETRIC: |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1195 EXPECT_EQ(10 * 36U, best_conn_info->recv_total_bytes); | 1201 EXPECT_EQ(10 * 36U, best_conn_info->recv_total_bytes); |
| 1196 EXPECT_GT(best_conn_info->rtt, 0U); | 1202 EXPECT_GT(best_conn_info->rtt, 0U); |
| 1197 DestroyChannels(); | 1203 DestroyChannels(); |
| 1198 } | 1204 } |
| 1199 | 1205 |
| 1200 // Test that we properly create a connection on a STUN ping from unknown address | 1206 // Test that we properly create a connection on a STUN ping from unknown address |
| 1201 // when the signaling is slow. | 1207 // when the signaling is slow. |
| 1202 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) { | 1208 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) { |
| 1203 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1209 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
| 1204 kDefaultPortAllocatorFlags); | 1210 kDefaultPortAllocatorFlags); |
| 1205 // Emulate no remote credentials coming in. | 1211 // Emulate no remote parameters coming in. |
| 1206 set_remote_ice_credential_source(FROM_CANDIDATE); | 1212 set_remote_ice_parameter_source(FROM_CANDIDATE); |
| 1207 CreateChannels(1); | 1213 CreateChannels(1); |
| 1208 // Only have remote credentials come in for ep2, not ep1. | 1214 // Only have remote parameters come in for ep2, not ep1. |
| 1209 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); | 1215 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]); |
| 1210 | 1216 |
| 1211 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive | 1217 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive |
| 1212 // candidate. | 1218 // candidate. |
| 1213 PauseCandidates(1); | 1219 PauseCandidates(1); |
| 1214 | 1220 |
| 1215 // Wait until the callee becomes writable to make sure that a ping request is | 1221 // Wait until the callee becomes writable to make sure that a ping request is |
| 1216 // received by the caller before his remote ICE credentials are set. | 1222 // received by the caller before his remote ICE credentials are set. |
| 1217 ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, 3000); | 1223 ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, 3000); |
| 1218 // Add two sets of remote ICE credentials, so that the ones used by the | 1224 // Add two sets of remote ICE credentials, so that the ones used by the |
| 1219 // candidate will be generation 1 instead of 0. | 1225 // candidate will be generation 1 instead of 0. |
| 1220 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 1226 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]); |
| 1221 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 1227 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]); |
| 1222 // The caller should have the selected connection connected to the peer | 1228 // The caller should have the selected connection connected to the peer |
| 1223 // reflexive candidate. | 1229 // reflexive candidate. |
| 1224 const Connection* selected_connection = nullptr; | 1230 const Connection* selected_connection = nullptr; |
| 1225 ASSERT_TRUE_WAIT( | 1231 ASSERT_TRUE_WAIT( |
| 1226 (selected_connection = ep1_ch1()->selected_connection()) != nullptr, | 1232 (selected_connection = ep1_ch1()->selected_connection()) != nullptr, |
| 1227 2000); | 1233 2000); |
| 1228 EXPECT_EQ("prflx", selected_connection->remote_candidate().type()); | 1234 EXPECT_EQ("prflx", selected_connection->remote_candidate().type()); |
| 1229 EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username()); | 1235 EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username()); |
| 1230 EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password()); | 1236 EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password()); |
| 1231 EXPECT_EQ(1u, selected_connection->remote_candidate().generation()); | 1237 EXPECT_EQ(1u, selected_connection->remote_candidate().generation()); |
| 1232 | 1238 |
| 1233 ResumeCandidates(1); | 1239 ResumeCandidates(1); |
| 1234 // Verify ep1's selected connection is updated to use the 'local' candidate. | 1240 // Verify ep1's selected connection is updated to use the 'local' candidate. |
| 1235 EXPECT_EQ_WAIT("local", | 1241 EXPECT_EQ_WAIT("local", |
| 1236 ep1_ch1()->selected_connection()->remote_candidate().type(), | 1242 ep1_ch1()->selected_connection()->remote_candidate().type(), |
| 1237 2000); | 1243 2000); |
| 1238 EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection()); | 1244 EXPECT_EQ(selected_connection, ep1_ch1()->selected_connection()); |
| 1239 DestroyChannels(); | 1245 DestroyChannels(); |
| 1240 } | 1246 } |
| 1241 | 1247 |
| 1242 // Test that we properly create a connection on a STUN ping from unknown address | 1248 // Test that we properly create a connection on a STUN ping from unknown address |
| 1243 // when the signaling is slow and the end points are behind NAT. | 1249 // when the signaling is slow and the end points are behind NAT. |
| 1244 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { | 1250 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { |
| 1245 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, | 1251 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, |
| 1246 kDefaultPortAllocatorFlags); | 1252 kDefaultPortAllocatorFlags); |
| 1247 // Emulate no remote credentials coming in. | 1253 // Emulate no remote parameters coming in. |
| 1248 set_remote_ice_credential_source(FROM_CANDIDATE); | 1254 set_remote_ice_parameter_source(FROM_CANDIDATE); |
| 1249 CreateChannels(1); | 1255 CreateChannels(1); |
| 1250 // Only have remote credentials come in for ep2, not ep1. | 1256 // Only have remote parameters come in for ep2, not ep1. |
| 1251 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); | 1257 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]); |
| 1252 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive | 1258 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive |
| 1253 // candidate. | 1259 // candidate. |
| 1254 PauseCandidates(1); | 1260 PauseCandidates(1); |
| 1255 | 1261 |
| 1256 // Wait until the callee becomes writable to make sure that a ping request is | 1262 // Wait until the callee becomes writable to make sure that a ping request is |
| 1257 // received by the caller before his remote ICE credentials are set. | 1263 // received by the caller before his remote ICE credentials are set. |
| 1258 ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, 3000); | 1264 ASSERT_TRUE_WAIT(ep2_ch1()->selected_connection() != nullptr, 3000); |
| 1259 // Add two sets of remote ICE credentials, so that the ones used by the | 1265 // Add two sets of remote ICE credentials, so that the ones used by the |
| 1260 // candidate will be generation 1 instead of 0. | 1266 // candidate will be generation 1 instead of 0. |
| 1261 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 1267 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]); |
| 1262 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 1268 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]); |
| 1263 | 1269 |
| 1264 // The caller's selected connection should be connected to the peer reflexive | 1270 // The caller's selected connection should be connected to the peer reflexive |
| 1265 // candidate. | 1271 // candidate. |
| 1266 const Connection* selected_connection = nullptr; | 1272 const Connection* selected_connection = nullptr; |
| 1267 ASSERT_TRUE_WAIT( | 1273 ASSERT_TRUE_WAIT( |
| 1268 (selected_connection = ep1_ch1()->selected_connection()) != nullptr, | 1274 (selected_connection = ep1_ch1()->selected_connection()) != nullptr, |
| 1269 2000); | 1275 2000); |
| 1270 EXPECT_EQ("prflx", selected_connection->remote_candidate().type()); | 1276 EXPECT_EQ("prflx", selected_connection->remote_candidate().type()); |
| 1271 EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username()); | 1277 EXPECT_EQ(kIceUfrag[1], selected_connection->remote_candidate().username()); |
| 1272 EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password()); | 1278 EXPECT_EQ(kIcePwd[1], selected_connection->remote_candidate().password()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1291 // generations. This resulted in the old-generation prflx candidate being | 1297 // generations. This resulted in the old-generation prflx candidate being |
| 1292 // prioritized above new-generation candidate pairs. | 1298 // prioritized above new-generation candidate pairs. |
| 1293 TEST_F(P2PTransportChannelTest, | 1299 TEST_F(P2PTransportChannelTest, |
| 1294 PeerReflexiveCandidateBeforeSignalingWithIceRestart) { | 1300 PeerReflexiveCandidateBeforeSignalingWithIceRestart) { |
| 1295 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1301 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
| 1296 kDefaultPortAllocatorFlags); | 1302 kDefaultPortAllocatorFlags); |
| 1297 // Only gather relay candidates, so that when the prflx candidate arrives | 1303 // Only gather relay candidates, so that when the prflx candidate arrives |
| 1298 // it's prioritized above the current candidate pair. | 1304 // it's prioritized above the current candidate pair. |
| 1299 GetEndpoint(0)->allocator_->set_candidate_filter(CF_RELAY); | 1305 GetEndpoint(0)->allocator_->set_candidate_filter(CF_RELAY); |
| 1300 GetEndpoint(1)->allocator_->set_candidate_filter(CF_RELAY); | 1306 GetEndpoint(1)->allocator_->set_candidate_filter(CF_RELAY); |
| 1301 // Setting this allows us to control when SetRemoteIceCredentials is called. | 1307 // Setting this allows us to control when SetRemoteIceParameters is called. |
| 1302 set_remote_ice_credential_source(FROM_CANDIDATE); | 1308 set_remote_ice_parameter_source(FROM_CANDIDATE); |
| 1303 CreateChannels(1); | 1309 CreateChannels(1); |
| 1304 // Wait for the initial connection to be made. | 1310 // Wait for the initial connection to be made. |
| 1305 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 1311 ep1_ch1()->SetRemoteIceParameters(kIceParams[1]); |
| 1306 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); | 1312 ep2_ch1()->SetRemoteIceParameters(kIceParams[0]); |
| 1307 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1313 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1308 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1314 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1309 kDefaultTimeout); | 1315 kDefaultTimeout); |
| 1310 | 1316 |
| 1311 // Simulate an ICE restart on ep2, but don't signal the candidate or new | 1317 // Simulate an ICE restart on ep2, but don't signal the candidate or new |
| 1312 // ICE credentials until after a prflx connection has been made. | 1318 // ICE parameters until after a prflx connection has been made. |
| 1313 PauseCandidates(1); | 1319 PauseCandidates(1); |
| 1314 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]); | 1320 ep2_ch1()->SetIceParameters(kIceParams[3]); |
| 1315 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 1321 |
| 1322 ep1_ch1()->SetRemoteIceParameters(kIceParams[3]); |
| 1316 ep2_ch1()->MaybeStartGathering(); | 1323 ep2_ch1()->MaybeStartGathering(); |
| 1317 | 1324 |
| 1318 // The caller should have the selected connection connected to the peer | 1325 // The caller should have the selected connection connected to the peer |
| 1319 // reflexive candidate. | 1326 // reflexive candidate. |
| 1320 EXPECT_EQ_WAIT("prflx", | 1327 EXPECT_EQ_WAIT("prflx", |
| 1321 ep1_ch1()->selected_connection()->remote_candidate().type(), | 1328 ep1_ch1()->selected_connection()->remote_candidate().type(), |
| 1322 kDefaultTimeout); | 1329 kDefaultTimeout); |
| 1323 const Connection* prflx_selected_connection = | 1330 const Connection* prflx_selected_connection = |
| 1324 ep1_ch1()->selected_connection(); | 1331 ep1_ch1()->selected_connection(); |
| 1325 | 1332 |
| 1326 // Now simulate the ICE restart on ep1. | 1333 // Now simulate the ICE restart on ep1. |
| 1327 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); | 1334 ep1_ch1()->SetIceParameters(kIceParams[2]); |
| 1328 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); | 1335 |
| 1336 ep2_ch1()->SetRemoteIceParameters(kIceParams[2]); |
| 1329 ep1_ch1()->MaybeStartGathering(); | 1337 ep1_ch1()->MaybeStartGathering(); |
| 1330 | 1338 |
| 1331 // Finally send the candidates from ep2's ICE restart and verify that ep1 uses | 1339 // Finally send the candidates from ep2's ICE restart and verify that ep1 uses |
| 1332 // their information to update the peer reflexive candidate. | 1340 // their information to update the peer reflexive candidate. |
| 1333 ResumeCandidates(1); | 1341 ResumeCandidates(1); |
| 1334 | 1342 |
| 1335 EXPECT_EQ_WAIT("relay", | 1343 EXPECT_EQ_WAIT("relay", |
| 1336 ep1_ch1()->selected_connection()->remote_candidate().type(), | 1344 ep1_ch1()->selected_connection()->remote_candidate().type(), |
| 1337 kDefaultTimeout); | 1345 kDefaultTimeout); |
| 1338 EXPECT_EQ(prflx_selected_connection, ep1_ch1()->selected_connection()); | 1346 EXPECT_EQ(prflx_selected_connection, ep1_ch1()->selected_connection()); |
| 1339 DestroyChannels(); | 1347 DestroyChannels(); |
| 1340 } | 1348 } |
| 1341 | 1349 |
| 1342 // Test that if remote candidates don't have ufrag and pwd, we still work. | 1350 // Test that if remote candidates don't have ufrag and pwd, we still work. |
| 1343 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) { | 1351 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) { |
| 1344 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); | 1352 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS); |
| 1345 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1353 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
| 1346 kDefaultPortAllocatorFlags); | 1354 kDefaultPortAllocatorFlags); |
| 1347 CreateChannels(1); | 1355 CreateChannels(1); |
| 1348 const Connection* selected_connection = NULL; | 1356 const Connection* selected_connection = NULL; |
| 1349 // Wait until the callee's connections are created. | 1357 // Wait until the callee's connections are created. |
| 1350 WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 1000); | 1358 WAIT((selected_connection = ep2_ch1()->selected_connection()) != NULL, 1000); |
| 1351 // Wait to see if they get culled; they shouldn't. | 1359 // Wait to see if they get culled; they shouldn't. |
| 1352 WAIT(ep2_ch1()->selected_connection() != selected_connection, 1000); | 1360 WAIT(ep2_ch1()->selected_connection() != selected_connection, 1000); |
| 1353 EXPECT_TRUE(ep2_ch1()->selected_connection() == selected_connection); | 1361 EXPECT_TRUE(ep2_ch1()->selected_connection() == selected_connection); |
| 1354 DestroyChannels(); | 1362 DestroyChannels(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1403 int kOnlyLocalTcpPorts = PORTALLOCATOR_DISABLE_UDP | | 1411 int kOnlyLocalTcpPorts = PORTALLOCATOR_DISABLE_UDP | |
| 1404 PORTALLOCATOR_DISABLE_STUN | | 1412 PORTALLOCATOR_DISABLE_STUN | |
| 1405 PORTALLOCATOR_DISABLE_RELAY; | 1413 PORTALLOCATOR_DISABLE_RELAY; |
| 1406 // Disable all protocols except TCP. | 1414 // Disable all protocols except TCP. |
| 1407 SetAllocatorFlags(0, kOnlyLocalTcpPorts); | 1415 SetAllocatorFlags(0, kOnlyLocalTcpPorts); |
| 1408 SetAllocatorFlags(1, kOnlyLocalTcpPorts); | 1416 SetAllocatorFlags(1, kOnlyLocalTcpPorts); |
| 1409 | 1417 |
| 1410 SetAllowTcpListen(0, true); // actpass. | 1418 SetAllowTcpListen(0, true); // actpass. |
| 1411 SetAllowTcpListen(1, false); // active. | 1419 SetAllowTcpListen(1, false); // active. |
| 1412 | 1420 |
| 1413 // We want SetRemoteIceCredentials to be called as it normally would. | 1421 // We want SetRemoteIceParameters to be called as it normally would. |
| 1414 // Otherwise we won't know what credentials to use for the expected | 1422 // Otherwise we won't know what parameters to use for the expected |
| 1415 // prflx TCP candidates. | 1423 // prflx TCP candidates. |
| 1416 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); | 1424 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS); |
| 1417 | 1425 |
| 1418 // Pause candidate so we could verify the candidate properties. | 1426 // Pause candidate so we could verify the candidate properties. |
| 1419 PauseCandidates(0); | 1427 PauseCandidates(0); |
| 1420 PauseCandidates(1); | 1428 PauseCandidates(1); |
| 1421 CreateChannels(1); | 1429 CreateChannels(1); |
| 1422 | 1430 |
| 1423 // Verify tcp candidates. | 1431 // Verify tcp candidates. |
| 1424 VerifySavedTcpCandidates(0, TCPTYPE_PASSIVE_STR); | 1432 VerifySavedTcpCandidates(0, TCPTYPE_PASSIVE_STR); |
| 1425 VerifySavedTcpCandidates(1, TCPTYPE_ACTIVE_STR); | 1433 VerifySavedTcpCandidates(1, TCPTYPE_ACTIVE_STR); |
| 1426 | 1434 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1693 } | 1701 } |
| 1694 | 1702 |
| 1695 // Test that when the "presume_writable_when_fully_relayed" flag is set to | 1703 // Test that when the "presume_writable_when_fully_relayed" flag is set to |
| 1696 // true and there's a TURN-TURN candidate pair, it's presumed to be writable | 1704 // true and there's a TURN-TURN candidate pair, it's presumed to be writable |
| 1697 // as soon as it's created. | 1705 // as soon as it's created. |
| 1698 TEST_F(P2PTransportChannelTest, TurnToTurnPresumedWritable) { | 1706 TEST_F(P2PTransportChannelTest, TurnToTurnPresumedWritable) { |
| 1699 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, | 1707 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
| 1700 kDefaultPortAllocatorFlags); | 1708 kDefaultPortAllocatorFlags); |
| 1701 // Only configure one channel so we can control when the remote candidate | 1709 // Only configure one channel so we can control when the remote candidate |
| 1702 // is added. | 1710 // is added. |
| 1703 GetEndpoint(0)->cd1_.ch_.reset( | 1711 GetEndpoint(0)->cd1_.ch_.reset(CreateChannel( |
| 1704 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0], | 1712 0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[0], kIceParams[1])); |
| 1705 kIcePwd[0], kIceUfrag[1], kIcePwd[1])); | |
| 1706 IceConfig config; | 1713 IceConfig config; |
| 1707 config.presume_writable_when_fully_relayed = true; | 1714 config.presume_writable_when_fully_relayed = true; |
| 1708 ep1_ch1()->SetIceConfig(config); | 1715 ep1_ch1()->SetIceConfig(config); |
| 1709 ep1_ch1()->MaybeStartGathering(); | 1716 ep1_ch1()->MaybeStartGathering(); |
| 1710 EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, | 1717 EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, |
| 1711 ep1_ch1()->gathering_state(), kDefaultTimeout); | 1718 ep1_ch1()->gathering_state(), kDefaultTimeout); |
| 1712 // Add two remote candidates; a host candidate (with higher priority) | 1719 // Add two remote candidates; a host candidate (with higher priority) |
| 1713 // and TURN candidate. | 1720 // and TURN candidate. |
| 1714 ep1_ch1()->AddRemoteCandidate( | 1721 ep1_ch1()->AddRemoteCandidate( |
| 1715 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); | 1722 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1741 virtual_socket_server()->UpdateDelayDistribution(); | 1748 virtual_socket_server()->UpdateDelayDistribution(); |
| 1742 | 1749 |
| 1743 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, | 1750 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, |
| 1744 kDefaultPortAllocatorFlags); | 1751 kDefaultPortAllocatorFlags); |
| 1745 // We want the remote TURN candidate to show up as prflx. To do this we need | 1752 // We want the remote TURN candidate to show up as prflx. To do this we need |
| 1746 // to configure the server to accept packets from an address we haven't | 1753 // to configure the server to accept packets from an address we haven't |
| 1747 // explicitly installed permission for. | 1754 // explicitly installed permission for. |
| 1748 test_turn_server()->set_enable_permission_checks(false); | 1755 test_turn_server()->set_enable_permission_checks(false); |
| 1749 IceConfig config; | 1756 IceConfig config; |
| 1750 config.presume_writable_when_fully_relayed = true; | 1757 config.presume_writable_when_fully_relayed = true; |
| 1751 GetEndpoint(0)->cd1_.ch_.reset( | 1758 GetEndpoint(0)->cd1_.ch_.reset(CreateChannel( |
| 1752 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0], | 1759 0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[0], kIceParams[1])); |
| 1753 kIcePwd[0], kIceUfrag[1], kIcePwd[1])); | 1760 GetEndpoint(1)->cd1_.ch_.reset(CreateChannel( |
| 1754 GetEndpoint(1)->cd1_.ch_.reset( | 1761 1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[1], kIceParams[0])); |
| 1755 CreateChannel(1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[1], | |
| 1756 kIcePwd[1], kIceUfrag[0], kIcePwd[0])); | |
| 1757 ep1_ch1()->SetIceConfig(config); | 1762 ep1_ch1()->SetIceConfig(config); |
| 1758 ep2_ch1()->SetIceConfig(config); | 1763 ep2_ch1()->SetIceConfig(config); |
| 1759 // Don't signal candidates from channel 2, so that channel 1 sees the TURN | 1764 // Don't signal candidates from channel 2, so that channel 1 sees the TURN |
| 1760 // candidate as peer reflexive. | 1765 // candidate as peer reflexive. |
| 1761 PauseCandidates(1); | 1766 PauseCandidates(1); |
| 1762 ep1_ch1()->MaybeStartGathering(); | 1767 ep1_ch1()->MaybeStartGathering(); |
| 1763 ep2_ch1()->MaybeStartGathering(); | 1768 ep2_ch1()->MaybeStartGathering(); |
| 1764 | 1769 |
| 1765 // Wait for the TURN<->prflx connection. | 1770 // Wait for the TURN<->prflx connection. |
| 1766 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable(), | 1771 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable(), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1782 | 1787 |
| 1783 // Test that a presumed-writable TURN<->TURN connection is preferred above an | 1788 // Test that a presumed-writable TURN<->TURN connection is preferred above an |
| 1784 // unreliable connection (one that has failed to be pinged for some time). | 1789 // unreliable connection (one that has failed to be pinged for some time). |
| 1785 TEST_F(P2PTransportChannelTest, PresumedWritablePreferredOverUnreliable) { | 1790 TEST_F(P2PTransportChannelTest, PresumedWritablePreferredOverUnreliable) { |
| 1786 rtc::ScopedFakeClock fake_clock; | 1791 rtc::ScopedFakeClock fake_clock; |
| 1787 | 1792 |
| 1788 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, | 1793 ConfigureEndpoints(NAT_SYMMETRIC, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, |
| 1789 kDefaultPortAllocatorFlags); | 1794 kDefaultPortAllocatorFlags); |
| 1790 IceConfig config; | 1795 IceConfig config; |
| 1791 config.presume_writable_when_fully_relayed = true; | 1796 config.presume_writable_when_fully_relayed = true; |
| 1792 GetEndpoint(0)->cd1_.ch_.reset( | 1797 GetEndpoint(0)->cd1_.ch_.reset(CreateChannel( |
| 1793 CreateChannel(0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[0], | 1798 0, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[0], kIceParams[1])); |
| 1794 kIcePwd[0], kIceUfrag[1], kIcePwd[1])); | 1799 GetEndpoint(1)->cd1_.ch_.reset(CreateChannel( |
| 1795 GetEndpoint(1)->cd1_.ch_.reset( | 1800 1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceParams[1], kIceParams[0])); |
| 1796 CreateChannel(1, ICE_CANDIDATE_COMPONENT_DEFAULT, kIceUfrag[1], | |
| 1797 kIcePwd[1], kIceUfrag[0], kIcePwd[0])); | |
| 1798 ep1_ch1()->SetIceConfig(config); | 1801 ep1_ch1()->SetIceConfig(config); |
| 1799 ep2_ch1()->SetIceConfig(config); | 1802 ep2_ch1()->SetIceConfig(config); |
| 1800 ep1_ch1()->MaybeStartGathering(); | 1803 ep1_ch1()->MaybeStartGathering(); |
| 1801 ep2_ch1()->MaybeStartGathering(); | 1804 ep2_ch1()->MaybeStartGathering(); |
| 1802 // Wait for initial connection as usual. | 1805 // Wait for initial connection as usual. |
| 1803 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1806 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1804 ep1_ch1()->selected_connection()->writable() && | 1807 ep1_ch1()->selected_connection()->writable() && |
| 1805 ep2_ch1()->receiving() && | 1808 ep2_ch1()->receiving() && |
| 1806 ep2_ch1()->writable() && | 1809 ep2_ch1()->writable() && |
| 1807 ep2_ch1()->selected_connection()->writable(), | 1810 ep2_ch1()->selected_connection()->writable(), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1830 // address of the outermost NAT. | 1833 // address of the outermost NAT. |
| 1831 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase { | 1834 class P2PTransportChannelSameNatTest : public P2PTransportChannelTestBase { |
| 1832 protected: | 1835 protected: |
| 1833 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) { | 1836 void ConfigureEndpoints(Config nat_type, Config config1, Config config2) { |
| 1834 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC); | 1837 ASSERT(nat_type >= NAT_FULL_CONE && nat_type <= NAT_SYMMETRIC); |
| 1835 rtc::NATSocketServer::Translator* outer_nat = | 1838 rtc::NATSocketServer::Translator* outer_nat = |
| 1836 nat()->AddTranslator(kPublicAddrs[0], kNatAddrs[0], | 1839 nat()->AddTranslator(kPublicAddrs[0], kNatAddrs[0], |
| 1837 static_cast<rtc::NATType>(nat_type - NAT_FULL_CONE)); | 1840 static_cast<rtc::NATType>(nat_type - NAT_FULL_CONE)); |
| 1838 ConfigureEndpoint(outer_nat, 0, config1); | 1841 ConfigureEndpoint(outer_nat, 0, config1); |
| 1839 ConfigureEndpoint(outer_nat, 1, config2); | 1842 ConfigureEndpoint(outer_nat, 1, config2); |
| 1840 set_remote_ice_credential_source(FROM_SETICECREDENTIALS); | 1843 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS); |
| 1841 } | 1844 } |
| 1842 void ConfigureEndpoint(rtc::NATSocketServer::Translator* nat, | 1845 void ConfigureEndpoint(rtc::NATSocketServer::Translator* nat, |
| 1843 int endpoint, Config config) { | 1846 int endpoint, Config config) { |
| 1844 ASSERT(config <= NAT_SYMMETRIC); | 1847 ASSERT(config <= NAT_SYMMETRIC); |
| 1845 if (config == OPEN) { | 1848 if (config == OPEN) { |
| 1846 AddAddress(endpoint, kPrivateAddrs[endpoint]); | 1849 AddAddress(endpoint, kPrivateAddrs[endpoint]); |
| 1847 nat->AddClient(kPrivateAddrs[endpoint]); | 1850 nat->AddClient(kPrivateAddrs[endpoint]); |
| 1848 } else { | 1851 } else { |
| 1849 AddAddress(endpoint, kCascadedPrivateAddrs[endpoint]); | 1852 AddAddress(endpoint, kCascadedPrivateAddrs[endpoint]); |
| 1850 nat->AddTranslator(kPrivateAddrs[endpoint], kCascadedNatAddrs[endpoint], | 1853 nat->AddTranslator(kPrivateAddrs[endpoint], kCascadedNatAddrs[endpoint], |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2020 // Adding alternate address will make sure |kPublicAddrs| has the higher | 2023 // Adding alternate address will make sure |kPublicAddrs| has the higher |
| 2021 // priority than others. This is due to FakeNetwork::AddInterface method. | 2024 // priority than others. This is due to FakeNetwork::AddInterface method. |
| 2022 AddAddress(0, kAlternateAddrs[0]); | 2025 AddAddress(0, kAlternateAddrs[0]); |
| 2023 AddAddress(0, kPublicAddrs[0]); | 2026 AddAddress(0, kPublicAddrs[0]); |
| 2024 AddAddress(1, kPublicAddrs[1]); | 2027 AddAddress(1, kPublicAddrs[1]); |
| 2025 | 2028 |
| 2026 // Use only local ports for simplicity. | 2029 // Use only local ports for simplicity. |
| 2027 SetAllocatorFlags(0, kOnlyLocalPorts); | 2030 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 2028 SetAllocatorFlags(1, kOnlyLocalPorts); | 2031 SetAllocatorFlags(1, kOnlyLocalPorts); |
| 2029 | 2032 |
| 2033 // We want it to set the remote ICE parameters when creating channels. |
| 2034 set_remote_ice_parameter_source(FROM_SETICEPARAMETERS); |
| 2030 // Make the receiving timeout shorter for testing. | 2035 // Make the receiving timeout shorter for testing. |
| 2031 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); | 2036 IceConfig config = CreateIceConfig(1000, GATHER_ONCE); |
| 2032 // Create channels and let them go writable, as usual. | 2037 // Create channels with ICE renomination and let them go writable as usual. |
| 2033 CreateChannels(1, config, config); | 2038 CreateChannels(1, config, config, true); |
| 2034 ep1_ch1()->set_remote_supports_renomination(true); | |
| 2035 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 2039 EXPECT_TRUE_SIMULATED_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 2036 ep2_ch1()->receiving() && | 2040 ep2_ch1()->receiving() && |
| 2037 ep2_ch1()->writable(), | 2041 ep2_ch1()->writable(), |
| 2038 3000, clock); | 2042 3000, clock); |
| 2039 EXPECT_TRUE_SIMULATED_WAIT( | 2043 EXPECT_TRUE_SIMULATED_WAIT( |
| 2040 ep2_ch1()->selected_connection()->remote_nomination() > 0 && | 2044 ep2_ch1()->selected_connection()->remote_nomination() > 0 && |
| 2041 ep1_ch1()->selected_connection()->acked_nomination() > 0, | 2045 ep1_ch1()->selected_connection()->acked_nomination() > 0, |
| 2042 kDefaultTimeout, clock); | 2046 kDefaultTimeout, clock); |
| 2043 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); | 2047 const Connection* selected_connection1 = ep1_ch1()->selected_connection(); |
| 2044 Connection* selected_connection2 = | 2048 Connection* selected_connection2 = |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2594 public sigslot::has_slots<> { | 2598 public sigslot::has_slots<> { |
| 2595 public: | 2599 public: |
| 2596 P2PTransportChannelPingTest() | 2600 P2PTransportChannelPingTest() |
| 2597 : pss_(new rtc::PhysicalSocketServer), | 2601 : pss_(new rtc::PhysicalSocketServer), |
| 2598 vss_(new rtc::VirtualSocketServer(pss_.get())), | 2602 vss_(new rtc::VirtualSocketServer(pss_.get())), |
| 2599 ss_scope_(vss_.get()) {} | 2603 ss_scope_(vss_.get()) {} |
| 2600 | 2604 |
| 2601 protected: | 2605 protected: |
| 2602 void PrepareChannel(P2PTransportChannel* ch) { | 2606 void PrepareChannel(P2PTransportChannel* ch) { |
| 2603 ch->SetIceRole(ICEROLE_CONTROLLING); | 2607 ch->SetIceRole(ICEROLE_CONTROLLING); |
| 2604 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); | 2608 ch->SetIceParameters(kIceParams[0]); |
| 2605 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 2609 ch->SetRemoteIceParameters(kIceParams[1]); |
| 2606 ch->SignalSelectedCandidatePairChanged.connect( | 2610 ch->SignalSelectedCandidatePairChanged.connect( |
| 2607 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged); | 2611 this, &P2PTransportChannelPingTest::OnSelectedCandidatePairChanged); |
| 2608 ch->SignalReadyToSend.connect(this, | 2612 ch->SignalReadyToSend.connect(this, |
| 2609 &P2PTransportChannelPingTest::OnReadyToSend); | 2613 &P2PTransportChannelPingTest::OnReadyToSend); |
| 2610 ch->SignalStateChanged.connect( | 2614 ch->SignalStateChanged.connect( |
| 2611 this, &P2PTransportChannelPingTest::OnChannelStateChanged); | 2615 this, &P2PTransportChannelPingTest::OnChannelStateChanged); |
| 2612 } | 2616 } |
| 2613 | 2617 |
| 2614 Connection* WaitForConnectionTo(P2PTransportChannel* ch, | 2618 Connection* WaitForConnectionTo(P2PTransportChannel* ch, |
| 2615 const std::string& ip, | 2619 const std::string& ip, |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2874 start = clock.TimeNanos(); | 2878 start = clock.TimeNanos(); |
| 2875 ping_sent_before = conn->num_pings_sent(); | 2879 ping_sent_before = conn->num_pings_sent(); |
| 2876 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); | 2880 SIMULATED_WAIT(conn->num_pings_sent() == ping_sent_before + 1, 3000, clock); |
| 2877 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; | 2881 ping_interval_ms = (clock.TimeNanos() - start) / rtc::kNumNanosecsPerMillisec; |
| 2878 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); | 2882 EXPECT_GE(ping_interval_ms, STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL); |
| 2879 EXPECT_LE(ping_interval_ms, | 2883 EXPECT_LE(ping_interval_ms, |
| 2880 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); | 2884 STABILIZING_WRITABLE_CONNECTION_PING_INTERVAL + SCHEDULING_RANGE); |
| 2881 } | 2885 } |
| 2882 | 2886 |
| 2883 // Test that we start pinging as soon as we have a connection and remote ICE | 2887 // Test that we start pinging as soon as we have a connection and remote ICE |
| 2884 // credentials. | 2888 // parameters. |
| 2885 TEST_F(P2PTransportChannelPingTest, PingingStartedAsSoonAsPossible) { | 2889 TEST_F(P2PTransportChannelPingTest, PingingStartedAsSoonAsPossible) { |
| 2886 rtc::ScopedFakeClock clock; | 2890 rtc::ScopedFakeClock clock; |
| 2887 | 2891 |
| 2888 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2892 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2889 P2PTransportChannel ch("TestChannel", 1, &pa); | 2893 P2PTransportChannel ch("TestChannel", 1, &pa); |
| 2890 ch.SetIceRole(ICEROLE_CONTROLLING); | 2894 ch.SetIceRole(ICEROLE_CONTROLLING); |
| 2891 ch.SetIceCredentials(kIceUfrag[0], kIcePwd[0]); | 2895 ch.SetIceParameters(kIceParams[0]); |
| 2892 ch.MaybeStartGathering(); | 2896 ch.MaybeStartGathering(); |
| 2893 EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, ch.gathering_state(), | 2897 EXPECT_EQ_WAIT(IceGatheringState::kIceGatheringComplete, ch.gathering_state(), |
| 2894 kDefaultTimeout); | 2898 kDefaultTimeout); |
| 2895 | 2899 |
| 2896 // Simulate a binding request being received, creating a peer reflexive | 2900 // Simulate a binding request being received, creating a peer reflexive |
| 2897 // candidate pair while we still don't have remote ICE credentials. | 2901 // candidate pair while we still don't have remote ICE parameters. |
| 2898 IceMessage request; | 2902 IceMessage request; |
| 2899 request.SetType(STUN_BINDING_REQUEST); | 2903 request.SetType(STUN_BINDING_REQUEST); |
| 2900 request.AddAttribute( | 2904 request.AddAttribute( |
| 2901 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); | 2905 new StunByteStringAttribute(STUN_ATTR_USERNAME, kIceUfrag[1])); |
| 2902 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; | 2906 uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24; |
| 2903 request.AddAttribute( | 2907 request.AddAttribute( |
| 2904 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); | 2908 new StunUInt32Attribute(STUN_ATTR_PRIORITY, prflx_priority)); |
| 2905 Port* port = GetPort(&ch); | 2909 Port* port = GetPort(&ch); |
| 2906 ASSERT_NE(nullptr, port); | 2910 ASSERT_NE(nullptr, port); |
| 2907 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, | 2911 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), PROTO_UDP, |
| 2908 &request, kIceUfrag[1], false); | 2912 &request, kIceUfrag[1], false); |
| 2909 Connection* conn = GetConnectionTo(&ch, "1.1.1.1", 1); | 2913 Connection* conn = GetConnectionTo(&ch, "1.1.1.1", 1); |
| 2910 ASSERT_NE(nullptr, conn); | 2914 ASSERT_NE(nullptr, conn); |
| 2911 | 2915 |
| 2912 // Simulate waiting for a second (and change) and verify that no pings were | 2916 // Simulate waiting for a second (and change) and verify that no pings were |
| 2913 // sent, since we don't yet have remote ICE credentials. | 2917 // sent, since we don't yet have remote ICE parameters. |
| 2914 SIMULATED_WAIT(conn->num_pings_sent() > 0, 1025, clock); | 2918 SIMULATED_WAIT(conn->num_pings_sent() > 0, 1025, clock); |
| 2915 EXPECT_EQ(0, conn->num_pings_sent()); | 2919 EXPECT_EQ(0, conn->num_pings_sent()); |
| 2916 | 2920 |
| 2917 // Set remote ICE credentials. Now we should be able to ping. Ensure that | 2921 // Set remote ICE parameters. Now we should be able to ping. Ensure that |
| 2918 // the first ping is sent as soon as possible, within one simulated clock | 2922 // the first ping is sent as soon as possible, within one simulated clock |
| 2919 // tick. | 2923 // tick. |
| 2920 ch.SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 2924 ch.SetRemoteIceParameters(kIceParams[1]); |
| 2921 EXPECT_TRUE_SIMULATED_WAIT(conn->num_pings_sent() > 0, 1, clock); | 2925 EXPECT_TRUE_SIMULATED_WAIT(conn->num_pings_sent() > 0, 1, clock); |
| 2922 } | 2926 } |
| 2923 | 2927 |
| 2924 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { | 2928 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { |
| 2925 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2929 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2926 P2PTransportChannel ch("trigger checks", 1, &pa); | 2930 P2PTransportChannel ch("trigger checks", 1, &pa); |
| 2927 PrepareChannel(&ch); | 2931 PrepareChannel(&ch); |
| 2928 ch.MaybeStartGathering(); | 2932 ch.MaybeStartGathering(); |
| 2929 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); | 2933 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
| 2930 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); | 2934 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2974 // Pruning the connection reduces the set of active connections and changes | 2978 // Pruning the connection reduces the set of active connections and changes |
| 2975 // the channel state. | 2979 // the channel state. |
| 2976 conn1->Prune(); | 2980 conn1->Prune(); |
| 2977 EXPECT_EQ_WAIT(STATE_FAILED, channel_state(), kDefaultTimeout); | 2981 EXPECT_EQ_WAIT(STATE_FAILED, channel_state(), kDefaultTimeout); |
| 2978 } | 2982 } |
| 2979 | 2983 |
| 2980 // Test adding remote candidates with different ufrags. If a remote candidate | 2984 // Test adding remote candidates with different ufrags. If a remote candidate |
| 2981 // is added with an old ufrag, it will be discarded. If it is added with a | 2985 // is added with an old ufrag, it will be discarded. If it is added with a |
| 2982 // ufrag that was not seen before, it will be used to create connections | 2986 // ufrag that was not seen before, it will be used to create connections |
| 2983 // although the ICE pwd in the remote candidate will be set when the ICE | 2987 // although the ICE pwd in the remote candidate will be set when the ICE |
| 2984 // credentials arrive. If a remote candidate is added with the current ICE | 2988 // parameters arrive. If a remote candidate is added with the current ICE |
| 2985 // ufrag, its pwd and generation will be set properly. | 2989 // ufrag, its pwd and generation will be set properly. |
| 2986 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { | 2990 TEST_F(P2PTransportChannelPingTest, TestAddRemoteCandidateWithVariousUfrags) { |
| 2987 FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 2991 FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 2988 P2PTransportChannel ch("add candidate", 1, &pa); | 2992 P2PTransportChannel ch("add candidate", 1, &pa); |
| 2989 PrepareChannel(&ch); | 2993 PrepareChannel(&ch); |
| 2990 ch.MaybeStartGathering(); | 2994 ch.MaybeStartGathering(); |
| 2991 // Add a candidate with a future ufrag. | 2995 // Add a candidate with a future ufrag. |
| 2992 ch.AddRemoteCandidate( | 2996 ch.AddRemoteCandidate( |
| 2993 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1, kIceUfrag[2])); | 2997 CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1, kIceUfrag[2])); |
| 2994 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 2998 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 2995 ASSERT_TRUE(conn1 != nullptr); | 2999 ASSERT_TRUE(conn1 != nullptr); |
| 2996 const Candidate& candidate = conn1->remote_candidate(); | 3000 const Candidate& candidate = conn1->remote_candidate(); |
| 2997 EXPECT_EQ(kIceUfrag[2], candidate.username()); | 3001 EXPECT_EQ(kIceUfrag[2], candidate.username()); |
| 2998 EXPECT_TRUE(candidate.password().empty()); | 3002 EXPECT_TRUE(candidate.password().empty()); |
| 2999 EXPECT_TRUE(FindNextPingableConnectionAndPingIt(&ch) == nullptr); | 3003 EXPECT_TRUE(FindNextPingableConnectionAndPingIt(&ch) == nullptr); |
| 3000 | 3004 |
| 3001 // Set the remote credentials with the "future" ufrag. | 3005 // Set the remote ICE parameters with the "future" ufrag. |
| 3002 // This should set the ICE pwd in the remote candidate of |conn1|, making | 3006 // This should set the ICE pwd in the remote candidate of |conn1|, making |
| 3003 // it pingable. | 3007 // it pingable. |
| 3004 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); | 3008 ch.SetRemoteIceParameters(kIceParams[2]); |
| 3005 EXPECT_EQ(kIceUfrag[2], candidate.username()); | 3009 EXPECT_EQ(kIceUfrag[2], candidate.username()); |
| 3006 EXPECT_EQ(kIcePwd[2], candidate.password()); | 3010 EXPECT_EQ(kIcePwd[2], candidate.password()); |
| 3007 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); | 3011 EXPECT_EQ(conn1, FindNextPingableConnectionAndPingIt(&ch)); |
| 3008 | 3012 |
| 3009 // Add a candidate with an old ufrag. No connection will be created. | 3013 // Add a candidate with an old ufrag. No connection will be created. |
| 3010 ch.AddRemoteCandidate( | 3014 ch.AddRemoteCandidate( |
| 3011 CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2, kIceUfrag[1])); | 3015 CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 2, kIceUfrag[1])); |
| 3012 rtc::Thread::Current()->ProcessMessages(500); | 3016 rtc::Thread::Current()->ProcessMessages(500); |
| 3013 EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr); | 3017 EXPECT_TRUE(GetConnectionTo(&ch, "2.2.2.2", 2) == nullptr); |
| 3014 | 3018 |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3254 ASSERT_TRUE(conn4 != nullptr); | 3258 ASSERT_TRUE(conn4 != nullptr); |
| 3255 EXPECT_TRUE(port->sent_binding_response()); | 3259 EXPECT_TRUE(port->sent_binding_response()); |
| 3256 // conn4 is not the selected connection yet because it is not writable. | 3260 // conn4 is not the selected connection yet because it is not writable. |
| 3257 EXPECT_EQ(conn2, ch.selected_connection()); | 3261 EXPECT_EQ(conn2, ch.selected_connection()); |
| 3258 conn4->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. | 3262 conn4->ReceivedPingResponse(LOW_RTT, "id"); // Become writable. |
| 3259 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); | 3263 EXPECT_EQ_WAIT(conn4, ch.selected_connection(), kDefaultTimeout); |
| 3260 | 3264 |
| 3261 // Test that the request from an unknown address contains a ufrag from an old | 3265 // Test that the request from an unknown address contains a ufrag from an old |
| 3262 // generation. | 3266 // generation. |
| 3263 port->set_sent_binding_response(false); | 3267 port->set_sent_binding_response(false); |
| 3264 ch.SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); | 3268 ch.SetRemoteIceParameters(kIceParams[2]); |
| 3265 ch.SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 3269 ch.SetRemoteIceParameters(kIceParams[3]); |
| 3266 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP, | 3270 port->SignalUnknownAddress(port, rtc::SocketAddress("5.5.5.5", 5), PROTO_UDP, |
| 3267 &request, kIceUfrag[2], false); | 3271 &request, kIceUfrag[2], false); |
| 3268 Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); | 3272 Connection* conn5 = WaitForConnectionTo(&ch, "5.5.5.5", 5); |
| 3269 ASSERT_TRUE(conn5 != nullptr); | 3273 ASSERT_TRUE(conn5 != nullptr); |
| 3270 EXPECT_TRUE(port->sent_binding_response()); | 3274 EXPECT_TRUE(port->sent_binding_response()); |
| 3271 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password()); | 3275 EXPECT_EQ(kIcePwd[2], conn5->remote_candidate().password()); |
| 3272 } | 3276 } |
| 3273 | 3277 |
| 3274 // The controlled side will select a connection as the "selected connection" | 3278 // The controlled side will select a connection as the "selected connection" |
| 3275 // based on media received until the controlling side nominates a connection, | 3279 // based on media received until the controlling side nominates a connection, |
| (...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3725 ch.MaybeStartGathering(); | 3729 ch.MaybeStartGathering(); |
| 3726 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); | 3730 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 100)); |
| 3727 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3731 Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 3728 ASSERT_TRUE(conn1 != nullptr); | 3732 ASSERT_TRUE(conn1 != nullptr); |
| 3729 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving | 3733 conn1->ReceivedPingResponse(LOW_RTT, "id"); // Becomes writable and receiving |
| 3730 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); | 3734 EXPECT_TRUE(!ch.allocator_session()->IsGettingPorts()); |
| 3731 | 3735 |
| 3732 // Start a new session. Even though conn1, which belongs to an older | 3736 // Start a new session. Even though conn1, which belongs to an older |
| 3733 // session, becomes unwritable and writable again, it should not stop the | 3737 // session, becomes unwritable and writable again, it should not stop the |
| 3734 // current session. | 3738 // current session. |
| 3735 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); | 3739 ch.SetIceParameters(kIceParams[1]); |
| 3736 ch.MaybeStartGathering(); | 3740 ch.MaybeStartGathering(); |
| 3737 conn1->Prune(); | 3741 conn1->Prune(); |
| 3738 conn1->ReceivedPingResponse(LOW_RTT, "id"); | 3742 conn1->ReceivedPingResponse(LOW_RTT, "id"); |
| 3739 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); | 3743 EXPECT_TRUE(ch.allocator_session()->IsGettingPorts()); |
| 3740 | 3744 |
| 3741 // But if a new connection created from the new session becomes writable, | 3745 // But if a new connection created from the new session becomes writable, |
| 3742 // it will stop the current session. | 3746 // it will stop the current session. |
| 3743 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100)); | 3747 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "2.2.2.2", 2, 100)); |
| 3744 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 3748 Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 3745 ASSERT_TRUE(conn2 != nullptr); | 3749 ASSERT_TRUE(conn2 != nullptr); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3781 // Starts with ICEROLE_CONTROLLING. | 3785 // Starts with ICEROLE_CONTROLLING. |
| 3782 PrepareChannel(&ch); | 3786 PrepareChannel(&ch); |
| 3783 ch.MaybeStartGathering(); | 3787 ch.MaybeStartGathering(); |
| 3784 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); | 3788 ch.AddRemoteCandidate(CreateUdpCandidate(LOCAL_PORT_TYPE, "1.1.1.1", 1, 1)); |
| 3785 | 3789 |
| 3786 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 3790 Connection* conn = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 3787 ASSERT_TRUE(conn != nullptr); | 3791 ASSERT_TRUE(conn != nullptr); |
| 3788 | 3792 |
| 3789 // Do an ICE restart, change the role, and expect the old port to have its | 3793 // Do an ICE restart, change the role, and expect the old port to have its |
| 3790 // role updated. | 3794 // role updated. |
| 3791 ch.SetIceCredentials(kIceUfrag[1], kIcePwd[1]); | 3795 ch.SetIceParameters(kIceParams[1]); |
| 3792 ch.MaybeStartGathering(); | 3796 ch.MaybeStartGathering(); |
| 3793 ch.SetIceRole(ICEROLE_CONTROLLED); | 3797 ch.SetIceRole(ICEROLE_CONTROLLED); |
| 3794 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); | 3798 EXPECT_EQ(ICEROLE_CONTROLLED, conn->port()->GetIceRole()); |
| 3795 } | 3799 } |
| 3796 | 3800 |
| 3797 // Test that after some amount of time without receiving data, the connection | 3801 // Test that after some amount of time without receiving data, the connection |
| 3798 // will be destroyed. The port will only be destroyed after it is marked as | 3802 // will be destroyed. The port will only be destroyed after it is marked as |
| 3799 // "pruned." | 3803 // "pruned." |
| 3800 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeoutAndPruned) { | 3804 TEST_F(P2PTransportChannelPingTest, TestPortDestroyedAfterTimeoutAndPruned) { |
| 3801 rtc::ScopedFakeClock fake_clock; | 3805 rtc::ScopedFakeClock fake_clock; |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4031 | 4035 |
| 4032 // TCP Relay/Relay is the next. | 4036 // TCP Relay/Relay is the next. |
| 4033 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, | 4037 VerifyNextPingableConnection(RELAY_PORT_TYPE, RELAY_PORT_TYPE, |
| 4034 TCP_PROTOCOL_NAME); | 4038 TCP_PROTOCOL_NAME); |
| 4035 | 4039 |
| 4036 // Finally, Local/Relay will be pinged. | 4040 // Finally, Local/Relay will be pinged. |
| 4037 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); | 4041 VerifyNextPingableConnection(LOCAL_PORT_TYPE, RELAY_PORT_TYPE); |
| 4038 } | 4042 } |
| 4039 | 4043 |
| 4040 } // namespace cricket { | 4044 } // namespace cricket { |
| OLD | NEW |