| 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 } | 290 } |
| 291 cricket::P2PTransportChannel* CreateChannel( | 291 cricket::P2PTransportChannel* CreateChannel( |
| 292 int endpoint, | 292 int endpoint, |
| 293 int component, | 293 int component, |
| 294 const std::string& local_ice_ufrag, | 294 const std::string& local_ice_ufrag, |
| 295 const std::string& local_ice_pwd, | 295 const std::string& local_ice_pwd, |
| 296 const std::string& remote_ice_ufrag, | 296 const std::string& remote_ice_ufrag, |
| 297 const std::string& remote_ice_pwd) { | 297 const std::string& remote_ice_pwd) { |
| 298 cricket::P2PTransportChannel* channel = new cricket::P2PTransportChannel( | 298 cricket::P2PTransportChannel* channel = new cricket::P2PTransportChannel( |
| 299 "test content name", component, NULL, GetAllocator(endpoint)); | 299 "test content name", component, NULL, GetAllocator(endpoint)); |
| 300 channel->SignalRequestSignaling.connect( | 300 channel->SignalCandidateGathered.connect( |
| 301 this, &P2PTransportChannelTestBase::OnChannelRequestSignaling); | 301 this, &P2PTransportChannelTestBase::OnCandidate); |
| 302 channel->SignalCandidateReady.connect(this, | |
| 303 &P2PTransportChannelTestBase::OnCandidate); | |
| 304 channel->SignalReadPacket.connect( | 302 channel->SignalReadPacket.connect( |
| 305 this, &P2PTransportChannelTestBase::OnReadPacket); | 303 this, &P2PTransportChannelTestBase::OnReadPacket); |
| 306 channel->SignalRoleConflict.connect( | 304 channel->SignalRoleConflict.connect( |
| 307 this, &P2PTransportChannelTestBase::OnRoleConflict); | 305 this, &P2PTransportChannelTestBase::OnRoleConflict); |
| 308 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); | 306 channel->SetIceCredentials(local_ice_ufrag, local_ice_pwd); |
| 309 if (clear_remote_candidates_ufrag_pwd_) { | 307 if (clear_remote_candidates_ufrag_pwd_) { |
| 310 // This only needs to be set if we're clearing them from the | 308 // This only needs to be set if we're clearing them from the |
| 311 // candidates. Some unit tests rely on this not being set. | 309 // candidates. Some unit tests rely on this not being set. |
| 312 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd); | 310 channel->SetRemoteIceCredentials(remote_ice_ufrag, remote_ice_pwd); |
| 313 } | 311 } |
| 314 channel->SetIceRole(GetEndpoint(endpoint)->ice_role()); | 312 channel->SetIceRole(GetEndpoint(endpoint)->ice_role()); |
| 315 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker()); | 313 channel->SetIceTiebreaker(GetEndpoint(endpoint)->GetIceTiebreaker()); |
| 316 channel->Connect(); | 314 channel->Connect(); |
| 315 channel->MaybeStartGathering(); |
| 317 return channel; | 316 return channel; |
| 318 } | 317 } |
| 319 void DestroyChannels() { | 318 void DestroyChannels() { |
| 320 ep1_.cd1_.ch_.reset(); | 319 ep1_.cd1_.ch_.reset(); |
| 321 ep2_.cd1_.ch_.reset(); | 320 ep2_.cd1_.ch_.reset(); |
| 322 ep1_.cd2_.ch_.reset(); | 321 ep1_.cd2_.ch_.reset(); |
| 323 ep2_.cd2_.ch_.reset(); | 322 ep2_.cd2_.ch_.reset(); |
| 324 } | 323 } |
| 325 cricket::P2PTransportChannel* ep1_ch1() { return ep1_.cd1_.ch_.get(); } | 324 cricket::P2PTransportChannel* ep1_ch1() { return ep1_.cd1_.ch_.get(); } |
| 326 cricket::P2PTransportChannel* ep1_ch2() { return ep1_.cd2_.ch_.get(); } | 325 cricket::P2PTransportChannel* ep1_ch2() { return ep1_.cd2_.ch_.get(); } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 return GetEndpoint(endpoint)->role_conflict(); | 381 return GetEndpoint(endpoint)->role_conflict(); |
| 383 } | 382 } |
| 384 void SetAllocationStepDelay(int endpoint, uint32 delay) { | 383 void SetAllocationStepDelay(int endpoint, uint32 delay) { |
| 385 return GetEndpoint(endpoint)->SetAllocationStepDelay(delay); | 384 return GetEndpoint(endpoint)->SetAllocationStepDelay(delay); |
| 386 } | 385 } |
| 387 void SetAllowTcpListen(int endpoint, bool allow_tcp_listen) { | 386 void SetAllowTcpListen(int endpoint, bool allow_tcp_listen) { |
| 388 return GetEndpoint(endpoint)->SetAllowTcpListen(allow_tcp_listen); | 387 return GetEndpoint(endpoint)->SetAllowTcpListen(allow_tcp_listen); |
| 389 } | 388 } |
| 390 | 389 |
| 391 bool IsLocalToPrflxOrTheReverse(const Result& expected) { | 390 bool IsLocalToPrflxOrTheReverse(const Result& expected) { |
| 392 return ((expected.local_type == "local" && | 391 return ( |
| 393 expected.remote_type == "prflx") || | 392 (expected.local_type == "local" && expected.remote_type == "prflx") || |
| 394 (expected.local_type == "prflx" && | 393 (expected.local_type == "prflx" && expected.remote_type == "local")); |
| 395 expected.remote_type == "local")); | |
| 396 } | 394 } |
| 397 | 395 |
| 398 // Return true if the approprite parts of the expected Result, based | 396 // Return true if the approprite parts of the expected Result, based |
| 399 // on the local and remote candidate of ep1_ch1, match. This can be | 397 // on the local and remote candidate of ep1_ch1, match. This can be |
| 400 // used in an EXPECT_TRUE_WAIT. | 398 // used in an EXPECT_TRUE_WAIT. |
| 401 bool CheckCandidate1(const Result& expected) { | 399 bool CheckCandidate1(const Result& expected) { |
| 402 const std::string& local_type = LocalCandidate(ep1_ch1())->type(); | 400 const std::string& local_type = LocalCandidate(ep1_ch1())->type(); |
| 403 const std::string& local_proto = LocalCandidate(ep1_ch1())->protocol(); | 401 const std::string& local_proto = LocalCandidate(ep1_ch1())->protocol(); |
| 404 const std::string& remote_type = RemoteCandidate(ep1_ch1())->type(); | 402 const std::string& remote_type = RemoteCandidate(ep1_ch1())->type(); |
| 405 const std::string& remote_proto = RemoteCandidate(ep1_ch1())->protocol(); | 403 const std::string& remote_proto = RemoteCandidate(ep1_ch1())->protocol(); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 LOG(LS_INFO) << "Connect time: " << "TIMEOUT (" | 503 LOG(LS_INFO) << "Connect time: " << "TIMEOUT (" |
| 506 << expected.connect_wait << " ms)"; | 504 << expected.connect_wait << " ms)"; |
| 507 } | 505 } |
| 508 | 506 |
| 509 // Allow a few turns of the crank for the best connections to emerge. | 507 // Allow a few turns of the crank for the best connections to emerge. |
| 510 // This may take up to 2 seconds. | 508 // This may take up to 2 seconds. |
| 511 if (ep1_ch1()->best_connection() && | 509 if (ep1_ch1()->best_connection() && |
| 512 ep2_ch1()->best_connection()) { | 510 ep2_ch1()->best_connection()) { |
| 513 int32 converge_start = rtc::Time(), converge_time; | 511 int32 converge_start = rtc::Time(), converge_time; |
| 514 int converge_wait = 2000; | 512 int converge_wait = 2000; |
| 515 EXPECT_TRUE_WAIT_MARGIN(CheckCandidate1(expected), | 513 EXPECT_TRUE_WAIT_MARGIN(CheckCandidate1(expected), converge_wait, |
| 516 converge_wait, converge_wait); | 514 converge_wait); |
| 517 // Also do EXPECT_EQ on each part so that failures are more verbose. | 515 // Also do EXPECT_EQ on each part so that failures are more verbose. |
| 518 ExpectCandidate1(expected); | 516 ExpectCandidate1(expected); |
| 519 | 517 |
| 520 // Verifying remote channel best connection information. This is done | 518 // Verifying remote channel best connection information. This is done |
| 521 // only for the RFC 5245 as controlled agent will use USE-CANDIDATE | 519 // only for the RFC 5245 as controlled agent will use USE-CANDIDATE |
| 522 // from controlling (ep1) agent. We can easily predict from EP1 result | 520 // from controlling (ep1) agent. We can easily predict from EP1 result |
| 523 // matrix. | 521 // matrix. |
| 524 | 522 |
| 525 // Checking for best connection candidates information at remote. | 523 // Checking for best connection candidates information at remote. |
| 526 EXPECT_TRUE_WAIT(CheckCandidate2(expected), kDefaultTimeout); | 524 EXPECT_TRUE_WAIT(CheckCandidate2(expected), kDefaultTimeout); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 555 // local_channel2 <==> remote_channel2 | 553 // local_channel2 <==> remote_channel2 |
| 556 EXPECT_EQ_WAIT(len, SendData(ep1_ch2(), data, len), 1000); | 554 EXPECT_EQ_WAIT(len, SendData(ep1_ch2(), data, len), 1000); |
| 557 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch2(), data, len), 1000); | 555 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep2_ch2(), data, len), 1000); |
| 558 EXPECT_EQ_WAIT(len, SendData(ep2_ch2(), data, len), 1000); | 556 EXPECT_EQ_WAIT(len, SendData(ep2_ch2(), data, len), 1000); |
| 559 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep1_ch2(), data, len), 1000); | 557 EXPECT_TRUE_WAIT(CheckDataOnChannel(ep1_ch2(), data, len), 1000); |
| 560 } | 558 } |
| 561 } | 559 } |
| 562 } | 560 } |
| 563 | 561 |
| 564 // This test waits for the transport to become receiving and writable on both | 562 // This test waits for the transport to become receiving and writable on both |
| 565 // end points. Once they are, the end points set new local ice credentials to | 563 // end points. Once they are, the end points set new local ice credentials and |
| 566 // restart the ice gathering. Finally it waits for the transport to select a | 564 // restart the ice gathering. Finally it waits for the transport to select a |
| 567 // new connection using the newly generated ice candidates. | 565 // new connection using the newly generated ice candidates. |
| 568 // Before calling this function the end points must be configured. | 566 // Before calling this function the end points must be configured. |
| 569 void TestHandleIceUfragPasswordChanged() { | 567 void TestHandleIceUfragPasswordChanged() { |
| 570 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 568 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
| 571 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); | 569 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[0], kIcePwd[0]); |
| 572 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 570 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 573 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 571 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 574 1000, 1000); | 572 1000, 1000); |
| 575 | 573 |
| 576 const cricket::Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1()); | 574 const cricket::Candidate* old_local_candidate1 = LocalCandidate(ep1_ch1()); |
| 577 const cricket::Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1()); | 575 const cricket::Candidate* old_local_candidate2 = LocalCandidate(ep2_ch1()); |
| 578 const cricket::Candidate* old_remote_candidate1 = | 576 const cricket::Candidate* old_remote_candidate1 = |
| 579 RemoteCandidate(ep1_ch1()); | 577 RemoteCandidate(ep1_ch1()); |
| 580 const cricket::Candidate* old_remote_candidate2 = | 578 const cricket::Candidate* old_remote_candidate2 = |
| 581 RemoteCandidate(ep2_ch1()); | 579 RemoteCandidate(ep2_ch1()); |
| 582 | 580 |
| 583 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); | 581 ep1_ch1()->SetIceCredentials(kIceUfrag[2], kIcePwd[2]); |
| 584 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 582 ep1_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
| 583 ep1_ch1()->MaybeStartGathering(); |
| 585 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]); | 584 ep2_ch1()->SetIceCredentials(kIceUfrag[3], kIcePwd[3]); |
| 586 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); | 585 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[2], kIcePwd[2]); |
| 586 ep2_ch1()->MaybeStartGathering(); |
| 587 | 587 |
| 588 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() != | 588 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep1_ch1())->generation() != |
| 589 old_local_candidate1->generation(), | 589 old_local_candidate1->generation(), |
| 590 1000, 1000); | 590 1000, 1000); |
| 591 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep2_ch1())->generation() != | 591 EXPECT_TRUE_WAIT_MARGIN(LocalCandidate(ep2_ch1())->generation() != |
| 592 old_local_candidate2->generation(), | 592 old_local_candidate2->generation(), |
| 593 1000, 1000); | 593 1000, 1000); |
| 594 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep1_ch1())->generation() != | 594 EXPECT_TRUE_WAIT_MARGIN(RemoteCandidate(ep1_ch1())->generation() != |
| 595 old_remote_candidate1->generation(), | 595 old_remote_candidate1->generation(), |
| 596 1000, 1000); | 596 1000, 1000); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 619 ep2_ch1()->receiving() && | 619 ep2_ch1()->receiving() && |
| 620 ep2_ch1()->writable(), | 620 ep2_ch1()->writable(), |
| 621 1000); | 621 1000); |
| 622 | 622 |
| 623 EXPECT_TRUE(ep1_ch1()->best_connection() && | 623 EXPECT_TRUE(ep1_ch1()->best_connection() && |
| 624 ep2_ch1()->best_connection()); | 624 ep2_ch1()->best_connection()); |
| 625 | 625 |
| 626 TestSendRecv(1); | 626 TestSendRecv(1); |
| 627 } | 627 } |
| 628 | 628 |
| 629 void OnChannelRequestSignaling(cricket::TransportChannelImpl* channel) { | |
| 630 channel->OnSignalingReady(); | |
| 631 } | |
| 632 // We pass the candidates directly to the other side. | 629 // We pass the candidates directly to the other side. |
| 633 void OnCandidate(cricket::TransportChannelImpl* ch, | 630 void OnCandidate(cricket::TransportChannelImpl* ch, |
| 634 const cricket::Candidate& c) { | 631 const cricket::Candidate& c) { |
| 635 if (force_relay_ && c.type() != cricket::RELAY_PORT_TYPE) | 632 if (force_relay_ && c.type() != cricket::RELAY_PORT_TYPE) |
| 636 return; | 633 return; |
| 637 | 634 |
| 638 if (GetEndpoint(ch)->save_candidates_) { | 635 if (GetEndpoint(ch)->save_candidates_) { |
| 639 GetEndpoint(ch)->saved_candidates_.push_back(new CandidateData(ch, c)); | 636 GetEndpoint(ch)->saved_candidates_.push_back(new CandidateData(ch, c)); |
| 640 } else { | 637 } else { |
| 641 main_->Post(this, MSG_CANDIDATE, new CandidateData(ch, c)); | 638 main_->Post(this, MSG_CANDIDATE, new CandidateData(ch, c)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 662 rtc::scoped_ptr<CandidateData> data( | 659 rtc::scoped_ptr<CandidateData> data( |
| 663 static_cast<CandidateData*>(msg->pdata)); | 660 static_cast<CandidateData*>(msg->pdata)); |
| 664 cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel); | 661 cricket::P2PTransportChannel* rch = GetRemoteChannel(data->channel); |
| 665 cricket::Candidate c = data->candidate; | 662 cricket::Candidate c = data->candidate; |
| 666 if (clear_remote_candidates_ufrag_pwd_) { | 663 if (clear_remote_candidates_ufrag_pwd_) { |
| 667 c.set_username(""); | 664 c.set_username(""); |
| 668 c.set_password(""); | 665 c.set_password(""); |
| 669 } | 666 } |
| 670 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->" | 667 LOG(LS_INFO) << "Candidate(" << data->channel->component() << "->" |
| 671 << rch->component() << "): " << c.ToString(); | 668 << rch->component() << "): " << c.ToString(); |
| 672 rch->OnCandidate(c); | 669 rch->AddRemoteCandidate(c); |
| 673 break; | 670 break; |
| 674 } | 671 } |
| 675 } | 672 } |
| 676 } | 673 } |
| 677 void OnReadPacket(cricket::TransportChannel* channel, const char* data, | 674 void OnReadPacket(cricket::TransportChannel* channel, const char* data, |
| 678 size_t len, const rtc::PacketTime& packet_time, | 675 size_t len, const rtc::PacketTime& packet_time, |
| 679 int flags) { | 676 int flags) { |
| 680 std::list<std::string>& packets = GetPacketList(channel); | 677 std::list<std::string>& packets = GetPacketList(channel); |
| 681 packets.push_front(std::string(data, len)); | 678 packets.push_front(std::string(data, len)); |
| 682 } | 679 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 "local", "tcp", "prflx", "tcp", 3000); | 794 "local", "tcp", "prflx", "tcp", 3000); |
| 798 | 795 |
| 799 // Test the matrix of all the connectivity types we expect to see in the wild. | 796 // Test the matrix of all the connectivity types we expect to see in the wild. |
| 800 // Just test every combination of the configs in the Config enum. | 797 // Just test every combination of the configs in the Config enum. |
| 801 class P2PTransportChannelTest : public P2PTransportChannelTestBase { | 798 class P2PTransportChannelTest : public P2PTransportChannelTestBase { |
| 802 protected: | 799 protected: |
| 803 static const Result* kMatrix[NUM_CONFIGS][NUM_CONFIGS]; | 800 static const Result* kMatrix[NUM_CONFIGS][NUM_CONFIGS]; |
| 804 static const Result* kMatrixSharedUfrag[NUM_CONFIGS][NUM_CONFIGS]; | 801 static const Result* kMatrixSharedUfrag[NUM_CONFIGS][NUM_CONFIGS]; |
| 805 static const Result* kMatrixSharedSocketAsGice[NUM_CONFIGS][NUM_CONFIGS]; | 802 static const Result* kMatrixSharedSocketAsGice[NUM_CONFIGS][NUM_CONFIGS]; |
| 806 static const Result* kMatrixSharedSocketAsIce[NUM_CONFIGS][NUM_CONFIGS]; | 803 static const Result* kMatrixSharedSocketAsIce[NUM_CONFIGS][NUM_CONFIGS]; |
| 807 void ConfigureEndpoints(Config config1, Config config2, | 804 void ConfigureEndpoints(Config config1, |
| 808 int allocator_flags1, int allocator_flags2) { | 805 Config config2, |
| 806 int allocator_flags1, |
| 807 int allocator_flags2) { |
| 809 ServerAddresses stun_servers; | 808 ServerAddresses stun_servers; |
| 810 stun_servers.insert(kStunAddr); | 809 stun_servers.insert(kStunAddr); |
| 811 GetEndpoint(0)->allocator_.reset( | 810 GetEndpoint(0)->allocator_.reset( |
| 812 new cricket::BasicPortAllocator(&(GetEndpoint(0)->network_manager_), | 811 new cricket::BasicPortAllocator(&(GetEndpoint(0)->network_manager_), |
| 813 stun_servers, | 812 stun_servers, |
| 814 rtc::SocketAddress(), rtc::SocketAddress(), | 813 rtc::SocketAddress(), rtc::SocketAddress(), |
| 815 rtc::SocketAddress())); | 814 rtc::SocketAddress())); |
| 816 GetEndpoint(1)->allocator_.reset( | 815 GetEndpoint(1)->allocator_.reset( |
| 817 new cricket::BasicPortAllocator(&(GetEndpoint(1)->network_manager_), | 816 new cricket::BasicPortAllocator(&(GetEndpoint(1)->network_manager_), |
| 818 stun_servers, | 817 stun_servers, |
| 819 rtc::SocketAddress(), rtc::SocketAddress(), | 818 rtc::SocketAddress(), rtc::SocketAddress(), |
| 820 rtc::SocketAddress())); | 819 rtc::SocketAddress())); |
| 821 | 820 |
| 822 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); | 821 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); |
| 823 relay_server.credentials = kRelayCredentials; | 822 relay_server.credentials = kRelayCredentials; |
| 824 relay_server.ports.push_back(cricket::ProtocolAddress( | 823 relay_server.ports.push_back( |
| 825 kTurnUdpIntAddr, cricket::PROTO_UDP, false)); | 824 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); |
| 826 GetEndpoint(0)->allocator_->AddRelay(relay_server); | 825 GetEndpoint(0)->allocator_->AddRelay(relay_server); |
| 827 GetEndpoint(1)->allocator_->AddRelay(relay_server); | 826 GetEndpoint(1)->allocator_->AddRelay(relay_server); |
| 828 | 827 |
| 829 int delay = kMinimumStepDelay; | 828 int delay = kMinimumStepDelay; |
| 830 ConfigureEndpoint(0, config1); | 829 ConfigureEndpoint(0, config1); |
| 831 SetAllocatorFlags(0, allocator_flags1); | 830 SetAllocatorFlags(0, allocator_flags1); |
| 832 SetAllocationStepDelay(0, delay); | 831 SetAllocationStepDelay(0, delay); |
| 833 ConfigureEndpoint(1, config2); | 832 ConfigureEndpoint(1, config2); |
| 834 SetAllocatorFlags(1, allocator_flags2); | 833 SetAllocatorFlags(1, allocator_flags2); |
| 835 SetAllocationStepDelay(1, delay); | 834 SetAllocationStepDelay(1, delay); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 /*SC*/ {PULU, PUSU, PUSU, PURU, PURU, PUSU, PURU, NULL, NULL, LSRS, NULL, LTRT}, | 1018 /*SC*/ {PULU, PUSU, PUSU, PURU, PURU, PUSU, PURU, NULL, NULL, LSRS, NULL, LTRT}, |
| 1020 /*!U*/ {PTLT, NULL, NULL, NULL, NULL, NULL, NULL, PTLT, LTPT, LSRS, NULL, LTRT}, | 1019 /*!U*/ {PTLT, NULL, NULL, NULL, NULL, NULL, NULL, PTLT, LTPT, LSRS, NULL, LTRT}, |
| 1021 /*!T*/ {LTRT, NULL, NULL, NULL, NULL, NULL, NULL, PTLT, LTRT, LSRS, NULL, LTRT}, | 1020 /*!T*/ {LTRT, NULL, NULL, NULL, NULL, NULL, NULL, PTLT, LTRT, LSRS, NULL, LTRT}, |
| 1022 /*HT*/ {LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, NULL, LSRS}, | 1021 /*HT*/ {LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, LSRS, NULL, LSRS}, |
| 1023 /*PR*/ {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, | 1022 /*PR*/ {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, |
| 1024 /*PR*/ {LTRT, LTRT, LTRT, LTRT, LTRT, LTRT, LTRT, LTRT, LTRT, LSRS, NULL, LTRT}, | 1023 /*PR*/ {LTRT, LTRT, LTRT, LTRT, LTRT, LTRT, LTRT, LTRT, LTRT, LSRS, NULL, LTRT}, |
| 1025 }; | 1024 }; |
| 1026 | 1025 |
| 1027 // The actual tests that exercise all the various configurations. | 1026 // The actual tests that exercise all the various configurations. |
| 1028 // Test names are of the form P2PTransportChannelTest_TestOPENToNAT_FULL_CONE | 1027 // Test names are of the form P2PTransportChannelTest_TestOPENToNAT_FULL_CONE |
| 1029 #define P2P_TEST_DECLARATION(x, y, z) \ | 1028 #define P2P_TEST_DECLARATION(x, y, z) \ |
| 1030 TEST_F(P2PTransportChannelTest, z##Test##x##To##y) { \ | 1029 TEST_F(P2PTransportChannelTest, z##Test##x##To##y) { \ |
| 1031 ConfigureEndpoints(x, y, \ | 1030 ConfigureEndpoints(x, y, PORTALLOCATOR_ENABLE_SHARED_SOCKET, \ |
| 1032 PORTALLOCATOR_ENABLE_SHARED_SOCKET, \ | 1031 PORTALLOCATOR_ENABLE_SHARED_SOCKET); \ |
| 1033 PORTALLOCATOR_ENABLE_SHARED_SOCKET); \ | 1032 if (kMatrixSharedSocketAsIce[x][y] != NULL) \ |
| 1034 if (kMatrixSharedSocketAsIce[x][y] != NULL) \ | 1033 Test(*kMatrixSharedSocketAsIce[x][y]); \ |
| 1035 Test(*kMatrixSharedSocketAsIce[x][y]); \ | 1034 else \ |
| 1036 else \ | 1035 LOG(LS_WARNING) << "Not yet implemented"; \ |
| 1037 LOG(LS_WARNING) << "Not yet implemented"; \ | |
| 1038 } | 1036 } |
| 1039 | 1037 |
| 1040 #define P2P_TEST(x, y) \ | 1038 #define P2P_TEST(x, y) \ |
| 1041 P2P_TEST_DECLARATION(x, y,) | 1039 P2P_TEST_DECLARATION(x, y,) |
| 1042 | 1040 |
| 1043 #define FLAKY_P2P_TEST(x, y) \ | 1041 #define FLAKY_P2P_TEST(x, y) \ |
| 1044 P2P_TEST_DECLARATION(x, y, DISABLED_) | 1042 P2P_TEST_DECLARATION(x, y, DISABLED_) |
| 1045 | 1043 |
| 1046 // TODO(holmer): Disabled due to randomly failing on webrtc buildbots. | 1044 // TODO(holmer): Disabled due to randomly failing on webrtc buildbots. |
| 1047 // Issue: webrtc/2383 | 1045 // Issue: webrtc/2383 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1082 P2P_TEST_SET(NAT_SYMMETRIC_THEN_CONE) | 1080 P2P_TEST_SET(NAT_SYMMETRIC_THEN_CONE) |
| 1083 P2P_TEST_SET(BLOCK_UDP) | 1081 P2P_TEST_SET(BLOCK_UDP) |
| 1084 P2P_TEST_SET(BLOCK_UDP_AND_INCOMING_TCP) | 1082 P2P_TEST_SET(BLOCK_UDP_AND_INCOMING_TCP) |
| 1085 P2P_TEST_SET(BLOCK_ALL_BUT_OUTGOING_HTTP) | 1083 P2P_TEST_SET(BLOCK_ALL_BUT_OUTGOING_HTTP) |
| 1086 P2P_TEST_SET(PROXY_HTTPS) | 1084 P2P_TEST_SET(PROXY_HTTPS) |
| 1087 P2P_TEST_SET(PROXY_SOCKS) | 1085 P2P_TEST_SET(PROXY_SOCKS) |
| 1088 | 1086 |
| 1089 // Test that we restart candidate allocation when local ufrag&pwd changed. | 1087 // Test that we restart candidate allocation when local ufrag&pwd changed. |
| 1090 // Standard Ice protocol is used. | 1088 // Standard Ice protocol is used. |
| 1091 TEST_F(P2PTransportChannelTest, HandleUfragPwdChange) { | 1089 TEST_F(P2PTransportChannelTest, HandleUfragPwdChange) { |
| 1092 ConfigureEndpoints(OPEN, OPEN, | 1090 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
| 1093 kDefaultPortAllocatorFlags, | |
| 1094 kDefaultPortAllocatorFlags); | 1091 kDefaultPortAllocatorFlags); |
| 1095 CreateChannels(1); | 1092 CreateChannels(1); |
| 1096 TestHandleIceUfragPasswordChanged(); | 1093 TestHandleIceUfragPasswordChanged(); |
| 1097 DestroyChannels(); | 1094 DestroyChannels(); |
| 1098 } | 1095 } |
| 1099 | 1096 |
| 1100 // Test the operation of GetStats. | 1097 // Test the operation of GetStats. |
| 1101 TEST_F(P2PTransportChannelTest, GetStats) { | 1098 TEST_F(P2PTransportChannelTest, GetStats) { |
| 1102 ConfigureEndpoints(OPEN, OPEN, | 1099 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
| 1103 kDefaultPortAllocatorFlags, | |
| 1104 kDefaultPortAllocatorFlags); | 1100 kDefaultPortAllocatorFlags); |
| 1105 CreateChannels(1); | 1101 CreateChannels(1); |
| 1106 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1102 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1107 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1103 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1108 1000, 1000); | 1104 1000, 1000); |
| 1109 TestSendRecv(1); | 1105 TestSendRecv(1); |
| 1110 cricket::ConnectionInfos infos; | 1106 cricket::ConnectionInfos infos; |
| 1111 ASSERT_TRUE(ep1_ch1()->GetStats(&infos)); | 1107 ASSERT_TRUE(ep1_ch1()->GetStats(&infos)); |
| 1112 ASSERT_EQ(1U, infos.size()); | 1108 ASSERT_EQ(1U, infos.size()); |
| 1113 EXPECT_TRUE(infos[0].new_connection); | 1109 EXPECT_TRUE(infos[0].new_connection); |
| 1114 EXPECT_TRUE(infos[0].best_connection); | 1110 EXPECT_TRUE(infos[0].best_connection); |
| 1115 EXPECT_TRUE(infos[0].receiving); | 1111 EXPECT_TRUE(infos[0].receiving); |
| 1116 EXPECT_TRUE(infos[0].writable); | 1112 EXPECT_TRUE(infos[0].writable); |
| 1117 EXPECT_FALSE(infos[0].timeout); | 1113 EXPECT_FALSE(infos[0].timeout); |
| 1118 EXPECT_EQ(10U, infos[0].sent_total_packets); | 1114 EXPECT_EQ(10U, infos[0].sent_total_packets); |
| 1119 EXPECT_EQ(0U, infos[0].sent_discarded_packets); | 1115 EXPECT_EQ(0U, infos[0].sent_discarded_packets); |
| 1120 EXPECT_EQ(10 * 36U, infos[0].sent_total_bytes); | 1116 EXPECT_EQ(10 * 36U, infos[0].sent_total_bytes); |
| 1121 EXPECT_EQ(10 * 36U, infos[0].recv_total_bytes); | 1117 EXPECT_EQ(10 * 36U, infos[0].recv_total_bytes); |
| 1122 EXPECT_GT(infos[0].rtt, 0U); | 1118 EXPECT_GT(infos[0].rtt, 0U); |
| 1123 DestroyChannels(); | 1119 DestroyChannels(); |
| 1124 } | 1120 } |
| 1125 | 1121 |
| 1126 // Test that we properly create a connection on a STUN ping from unknown address | 1122 // Test that we properly create a connection on a STUN ping from unknown address |
| 1127 // when the signaling is slow. | 1123 // when the signaling is slow. |
| 1128 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) { | 1124 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignaling) { |
| 1129 ConfigureEndpoints(OPEN, OPEN, | 1125 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
| 1130 kDefaultPortAllocatorFlags, | |
| 1131 kDefaultPortAllocatorFlags); | 1126 kDefaultPortAllocatorFlags); |
| 1132 // Emulate no remote credentials coming in. | 1127 // Emulate no remote credentials coming in. |
| 1133 set_clear_remote_candidates_ufrag_pwd(false); | 1128 set_clear_remote_candidates_ufrag_pwd(false); |
| 1134 CreateChannels(1); | 1129 CreateChannels(1); |
| 1135 // Only have remote credentials come in for ep2, not ep1. | 1130 // Only have remote credentials come in for ep2, not ep1. |
| 1136 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 1131 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
| 1137 | 1132 |
| 1138 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive | 1133 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive |
| 1139 // candidate. | 1134 // candidate. |
| 1140 PauseCandidates(1); | 1135 PauseCandidates(1); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1164 "local", | 1159 "local", |
| 1165 ep1_ch1()->best_connection()->remote_candidate().type(), | 1160 ep1_ch1()->best_connection()->remote_candidate().type(), |
| 1166 2000); | 1161 2000); |
| 1167 EXPECT_EQ(best_connection, ep1_ch1()->best_connection()); | 1162 EXPECT_EQ(best_connection, ep1_ch1()->best_connection()); |
| 1168 DestroyChannels(); | 1163 DestroyChannels(); |
| 1169 } | 1164 } |
| 1170 | 1165 |
| 1171 // Test that we properly create a connection on a STUN ping from unknown address | 1166 // Test that we properly create a connection on a STUN ping from unknown address |
| 1172 // when the signaling is slow and the end points are behind NAT. | 1167 // when the signaling is slow and the end points are behind NAT. |
| 1173 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { | 1168 TEST_F(P2PTransportChannelTest, PeerReflexiveCandidateBeforeSignalingWithNAT) { |
| 1174 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, | 1169 ConfigureEndpoints(OPEN, NAT_SYMMETRIC, kDefaultPortAllocatorFlags, |
| 1175 kDefaultPortAllocatorFlags, | |
| 1176 kDefaultPortAllocatorFlags); | 1170 kDefaultPortAllocatorFlags); |
| 1177 // Emulate no remote credentials coming in. | 1171 // Emulate no remote credentials coming in. |
| 1178 set_clear_remote_candidates_ufrag_pwd(false); | 1172 set_clear_remote_candidates_ufrag_pwd(false); |
| 1179 CreateChannels(1); | 1173 CreateChannels(1); |
| 1180 // Only have remote credentials come in for ep2, not ep1. | 1174 // Only have remote credentials come in for ep2, not ep1. |
| 1181 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); | 1175 ep2_ch1()->SetRemoteIceCredentials(kIceUfrag[3], kIcePwd[3]); |
| 1182 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive | 1176 // Pause sending ep2's candidates to ep1 until ep1 receives the peer reflexive |
| 1183 // candidate. | 1177 // candidate. |
| 1184 PauseCandidates(1); | 1178 PauseCandidates(1); |
| 1185 | 1179 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1207 // Wait to verify the connection is not culled. | 1201 // Wait to verify the connection is not culled. |
| 1208 WAIT(ep1_ch1()->writable(), 2000); | 1202 WAIT(ep1_ch1()->writable(), 2000); |
| 1209 EXPECT_EQ(ep2_ch1()->best_connection(), best_connection); | 1203 EXPECT_EQ(ep2_ch1()->best_connection(), best_connection); |
| 1210 EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type()); | 1204 EXPECT_EQ("prflx", ep1_ch1()->best_connection()->remote_candidate().type()); |
| 1211 DestroyChannels(); | 1205 DestroyChannels(); |
| 1212 } | 1206 } |
| 1213 | 1207 |
| 1214 // Test that if remote candidates don't have ufrag and pwd, we still work. | 1208 // Test that if remote candidates don't have ufrag and pwd, we still work. |
| 1215 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) { | 1209 TEST_F(P2PTransportChannelTest, RemoteCandidatesWithoutUfragPwd) { |
| 1216 set_clear_remote_candidates_ufrag_pwd(true); | 1210 set_clear_remote_candidates_ufrag_pwd(true); |
| 1217 ConfigureEndpoints(OPEN, OPEN, | 1211 ConfigureEndpoints(OPEN, OPEN, kDefaultPortAllocatorFlags, |
| 1218 kDefaultPortAllocatorFlags, | |
| 1219 kDefaultPortAllocatorFlags); | 1212 kDefaultPortAllocatorFlags); |
| 1220 CreateChannels(1); | 1213 CreateChannels(1); |
| 1221 const cricket::Connection* best_connection = NULL; | 1214 const cricket::Connection* best_connection = NULL; |
| 1222 // Wait until the callee's connections are created. | 1215 // Wait until the callee's connections are created. |
| 1223 WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 1000); | 1216 WAIT((best_connection = ep2_ch1()->best_connection()) != NULL, 1000); |
| 1224 // Wait to see if they get culled; they shouldn't. | 1217 // Wait to see if they get culled; they shouldn't. |
| 1225 WAIT(ep2_ch1()->best_connection() != best_connection, 1000); | 1218 WAIT(ep2_ch1()->best_connection() != best_connection, 1000); |
| 1226 EXPECT_TRUE(ep2_ch1()->best_connection() == best_connection); | 1219 EXPECT_TRUE(ep2_ch1()->best_connection() == best_connection); |
| 1227 DestroyChannels(); | 1220 DestroyChannels(); |
| 1228 } | 1221 } |
| 1229 | 1222 |
| 1230 // Test that a host behind NAT cannot be reached when incoming_only | 1223 // Test that a host behind NAT cannot be reached when incoming_only |
| 1231 // is set to true. | 1224 // is set to true. |
| 1232 TEST_F(P2PTransportChannelTest, IncomingOnlyBlocked) { | 1225 TEST_F(P2PTransportChannelTest, IncomingOnlyBlocked) { |
| 1233 ConfigureEndpoints(NAT_FULL_CONE, OPEN, | 1226 ConfigureEndpoints(NAT_FULL_CONE, OPEN, kDefaultPortAllocatorFlags, |
| 1234 kDefaultPortAllocatorFlags, | |
| 1235 kDefaultPortAllocatorFlags); | 1227 kDefaultPortAllocatorFlags); |
| 1236 | 1228 |
| 1237 SetAllocatorFlags(0, kOnlyLocalPorts); | 1229 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 1238 CreateChannels(1); | 1230 CreateChannels(1); |
| 1239 ep1_ch1()->set_incoming_only(true); | 1231 ep1_ch1()->set_incoming_only(true); |
| 1240 | 1232 |
| 1241 // Pump for 1 second and verify that the channels are not connected. | 1233 // Pump for 1 second and verify that the channels are not connected. |
| 1242 rtc::Thread::Current()->ProcessMessages(1000); | 1234 rtc::Thread::Current()->ProcessMessages(1000); |
| 1243 | 1235 |
| 1244 EXPECT_FALSE(ep1_ch1()->receiving()); | 1236 EXPECT_FALSE(ep1_ch1()->receiving()); |
| 1245 EXPECT_FALSE(ep1_ch1()->writable()); | 1237 EXPECT_FALSE(ep1_ch1()->writable()); |
| 1246 EXPECT_FALSE(ep2_ch1()->receiving()); | 1238 EXPECT_FALSE(ep2_ch1()->receiving()); |
| 1247 EXPECT_FALSE(ep2_ch1()->writable()); | 1239 EXPECT_FALSE(ep2_ch1()->writable()); |
| 1248 | 1240 |
| 1249 DestroyChannels(); | 1241 DestroyChannels(); |
| 1250 } | 1242 } |
| 1251 | 1243 |
| 1252 // Test that a peer behind NAT can connect to a peer that has | 1244 // Test that a peer behind NAT can connect to a peer that has |
| 1253 // incoming_only flag set. | 1245 // incoming_only flag set. |
| 1254 TEST_F(P2PTransportChannelTest, IncomingOnlyOpen) { | 1246 TEST_F(P2PTransportChannelTest, IncomingOnlyOpen) { |
| 1255 ConfigureEndpoints(OPEN, NAT_FULL_CONE, | 1247 ConfigureEndpoints(OPEN, NAT_FULL_CONE, kDefaultPortAllocatorFlags, |
| 1256 kDefaultPortAllocatorFlags, | |
| 1257 kDefaultPortAllocatorFlags); | 1248 kDefaultPortAllocatorFlags); |
| 1258 | 1249 |
| 1259 SetAllocatorFlags(0, kOnlyLocalPorts); | 1250 SetAllocatorFlags(0, kOnlyLocalPorts); |
| 1260 CreateChannels(1); | 1251 CreateChannels(1); |
| 1261 ep1_ch1()->set_incoming_only(true); | 1252 ep1_ch1()->set_incoming_only(true); |
| 1262 | 1253 |
| 1263 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && | 1254 EXPECT_TRUE_WAIT_MARGIN(ep1_ch1() != NULL && ep2_ch1() != NULL && |
| 1264 ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1255 ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1265 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1256 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1266 1000, 1000); | 1257 1000, 1000); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1407 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1398 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
| 1408 LocalCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[0]) && | 1399 LocalCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[0]) && |
| 1409 RemoteCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[1])); | 1400 RemoteCandidate(ep1_ch1())->address().EqualIPs(kIPv6PublicAddrs[1])); |
| 1410 | 1401 |
| 1411 TestSendRecv(1); | 1402 TestSendRecv(1); |
| 1412 DestroyChannels(); | 1403 DestroyChannels(); |
| 1413 } | 1404 } |
| 1414 | 1405 |
| 1415 // Testing forceful TURN connections. | 1406 // Testing forceful TURN connections. |
| 1416 TEST_F(P2PTransportChannelTest, TestForceTurn) { | 1407 TEST_F(P2PTransportChannelTest, TestForceTurn) { |
| 1417 ConfigureEndpoints(NAT_PORT_RESTRICTED, NAT_SYMMETRIC, | 1408 ConfigureEndpoints( |
| 1418 kDefaultPortAllocatorFlags | | 1409 NAT_PORT_RESTRICTED, NAT_SYMMETRIC, |
| 1419 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET, | 1410 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET, |
| 1420 kDefaultPortAllocatorFlags | | 1411 kDefaultPortAllocatorFlags | cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
| 1421 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | |
| 1422 set_force_relay(true); | 1412 set_force_relay(true); |
| 1423 | 1413 |
| 1424 SetAllocationStepDelay(0, kMinimumStepDelay); | 1414 SetAllocationStepDelay(0, kMinimumStepDelay); |
| 1425 SetAllocationStepDelay(1, kMinimumStepDelay); | 1415 SetAllocationStepDelay(1, kMinimumStepDelay); |
| 1426 | 1416 |
| 1427 CreateChannels(1); | 1417 CreateChannels(1); |
| 1428 | 1418 |
| 1429 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1419 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1430 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1420 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1431 2000); | 1421 2000); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1466 nat->AddTranslator(kPrivateAddrs[endpoint], kCascadedNatAddrs[endpoint], | 1456 nat->AddTranslator(kPrivateAddrs[endpoint], kCascadedNatAddrs[endpoint], |
| 1467 static_cast<rtc::NATType>(config - NAT_FULL_CONE))->AddClient( | 1457 static_cast<rtc::NATType>(config - NAT_FULL_CONE))->AddClient( |
| 1468 kCascadedPrivateAddrs[endpoint]); | 1458 kCascadedPrivateAddrs[endpoint]); |
| 1469 } | 1459 } |
| 1470 } | 1460 } |
| 1471 }; | 1461 }; |
| 1472 | 1462 |
| 1473 TEST_F(P2PTransportChannelSameNatTest, TestConesBehindSameCone) { | 1463 TEST_F(P2PTransportChannelSameNatTest, TestConesBehindSameCone) { |
| 1474 ConfigureEndpoints(NAT_FULL_CONE, NAT_FULL_CONE, NAT_FULL_CONE); | 1464 ConfigureEndpoints(NAT_FULL_CONE, NAT_FULL_CONE, NAT_FULL_CONE); |
| 1475 Test(P2PTransportChannelTestBase::Result( | 1465 Test(P2PTransportChannelTestBase::Result( |
| 1476 "prflx", "udp", "stun", "udp", | 1466 "prflx", "udp", "stun", "udp", "stun", "udp", "prflx", "udp", 1000)); |
| 1477 "stun", "udp", "prflx", "udp", 1000)); | |
| 1478 } | 1467 } |
| 1479 | 1468 |
| 1480 // Test what happens when we have multiple available pathways. | 1469 // Test what happens when we have multiple available pathways. |
| 1481 // In the future we will try different RTTs and configs for the different | 1470 // In the future we will try different RTTs and configs for the different |
| 1482 // interfaces, so that we can simulate a user with Ethernet and VPN networks. | 1471 // interfaces, so that we can simulate a user with Ethernet and VPN networks. |
| 1483 class P2PTransportChannelMultihomedTest : public P2PTransportChannelTestBase { | 1472 class P2PTransportChannelMultihomedTest : public P2PTransportChannelTestBase { |
| 1484 }; | 1473 }; |
| 1485 | 1474 |
| 1486 // Test that we can establish connectivity when both peers are multihomed. | 1475 // Test that we can establish connectivity when both peers are multihomed. |
| 1487 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) { | 1476 TEST_F(P2PTransportChannelMultihomedTest, DISABLED_TestBasic) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1553 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && | 1542 EXPECT_TRUE_WAIT(ep1_ch1()->receiving() && ep1_ch1()->writable() && |
| 1554 ep2_ch1()->receiving() && ep2_ch1()->writable(), | 1543 ep2_ch1()->receiving() && ep2_ch1()->writable(), |
| 1555 1000); | 1544 1000); |
| 1556 EXPECT_TRUE( | 1545 EXPECT_TRUE( |
| 1557 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1546 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
| 1558 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1547 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 1559 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); | 1548 RemoteCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[1])); |
| 1560 | 1549 |
| 1561 | 1550 |
| 1562 // Remove the public interface, add the alternate interface, and allocate | 1551 // Remove the public interface, add the alternate interface, and allocate |
| 1563 // a new generation of candidates for the new interface (via Connect()). | 1552 // a new generation of candidates for the new interface (via |
| 1553 // MaybeStartGathering()). |
| 1564 LOG(LS_INFO) << "Draining..."; | 1554 LOG(LS_INFO) << "Draining..."; |
| 1565 AddAddress(1, kAlternateAddrs[1]); | 1555 AddAddress(1, kAlternateAddrs[1]); |
| 1566 RemoveAddress(1, kPublicAddrs[1]); | 1556 RemoveAddress(1, kPublicAddrs[1]); |
| 1567 ep2_ch1()->Connect(); | 1557 ep2_ch1()->MaybeStartGathering(); |
| 1568 | 1558 |
| 1569 // We should switch over to use the alternate address after | 1559 // We should switch over to use the alternate address after |
| 1570 // an exchange of pings. | 1560 // an exchange of pings. |
| 1571 EXPECT_TRUE_WAIT( | 1561 EXPECT_TRUE_WAIT( |
| 1572 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && | 1562 ep1_ch1()->best_connection() && ep2_ch1()->best_connection() && |
| 1573 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && | 1563 LocalCandidate(ep1_ch1())->address().EqualIPs(kPublicAddrs[0]) && |
| 1574 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), | 1564 RemoteCandidate(ep1_ch1())->address().EqualIPs(kAlternateAddrs[1]), |
| 1575 3000); | 1565 3000); |
| 1576 | 1566 |
| 1577 DestroyChannels(); | 1567 DestroyChannels(); |
| 1578 } | 1568 } |
| 1579 | 1569 |
| 1580 */ | 1570 */ |
| 1581 | 1571 |
| 1582 // A collection of tests which tests a single P2PTransportChannel by sending | 1572 // A collection of tests which tests a single P2PTransportChannel by sending |
| 1583 // pings. | 1573 // pings. |
| 1584 class P2PTransportChannelPingTest : public testing::Test, | 1574 class P2PTransportChannelPingTest : public testing::Test, |
| 1585 public sigslot::has_slots<> { | 1575 public sigslot::has_slots<> { |
| 1586 public: | 1576 public: |
| 1587 P2PTransportChannelPingTest() | 1577 P2PTransportChannelPingTest() |
| 1588 : pss_(new rtc::PhysicalSocketServer), | 1578 : pss_(new rtc::PhysicalSocketServer), |
| 1589 vss_(new rtc::VirtualSocketServer(pss_.get())), | 1579 vss_(new rtc::VirtualSocketServer(pss_.get())), |
| 1590 ss_scope_(vss_.get()) {} | 1580 ss_scope_(vss_.get()) {} |
| 1591 | 1581 |
| 1592 protected: | 1582 protected: |
| 1593 void PrepareChannel(cricket::P2PTransportChannel* ch) { | 1583 void PrepareChannel(cricket::P2PTransportChannel* ch) { |
| 1594 ch->SignalRequestSignaling.connect( | |
| 1595 this, &P2PTransportChannelPingTest::OnChannelRequestSignaling); | |
| 1596 ch->SetIceRole(cricket::ICEROLE_CONTROLLING); | 1584 ch->SetIceRole(cricket::ICEROLE_CONTROLLING); |
| 1597 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); | 1585 ch->SetIceCredentials(kIceUfrag[0], kIcePwd[0]); |
| 1598 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); | 1586 ch->SetRemoteIceCredentials(kIceUfrag[1], kIcePwd[1]); |
| 1599 } | 1587 } |
| 1600 | 1588 |
| 1601 void OnChannelRequestSignaling(cricket::TransportChannelImpl* channel) { | |
| 1602 channel->OnSignalingReady(); | |
| 1603 } | |
| 1604 | |
| 1605 cricket::Candidate CreateCandidate(const std::string& ip, | 1589 cricket::Candidate CreateCandidate(const std::string& ip, |
| 1606 int port, | 1590 int port, |
| 1607 int priority) { | 1591 int priority) { |
| 1608 cricket::Candidate c; | 1592 cricket::Candidate c; |
| 1609 c.set_address(rtc::SocketAddress(ip, port)); | 1593 c.set_address(rtc::SocketAddress(ip, port)); |
| 1610 c.set_component(1); | 1594 c.set_component(1); |
| 1611 c.set_protocol(cricket::UDP_PROTOCOL_NAME); | 1595 c.set_protocol(cricket::UDP_PROTOCOL_NAME); |
| 1612 c.set_priority(priority); | 1596 c.set_priority(priority); |
| 1613 return c; | 1597 return c; |
| 1614 } | 1598 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1641 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; | 1625 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
| 1642 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; | 1626 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_; |
| 1643 rtc::SocketServerScope ss_scope_; | 1627 rtc::SocketServerScope ss_scope_; |
| 1644 }; | 1628 }; |
| 1645 | 1629 |
| 1646 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { | 1630 TEST_F(P2PTransportChannelPingTest, TestTriggeredChecks) { |
| 1647 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1631 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 1648 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); | 1632 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); |
| 1649 PrepareChannel(&ch); | 1633 PrepareChannel(&ch); |
| 1650 ch.Connect(); | 1634 ch.Connect(); |
| 1651 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1635 ch.MaybeStartGathering(); |
| 1652 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 1636 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
| 1637 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); |
| 1653 | 1638 |
| 1654 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1639 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 1655 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1640 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 1656 ASSERT_TRUE(conn1 != nullptr); | 1641 ASSERT_TRUE(conn1 != nullptr); |
| 1657 ASSERT_TRUE(conn2 != nullptr); | 1642 ASSERT_TRUE(conn2 != nullptr); |
| 1658 | 1643 |
| 1659 // Before a triggered check, the first connection to ping is the | 1644 // Before a triggered check, the first connection to ping is the |
| 1660 // highest priority one. | 1645 // highest priority one. |
| 1661 EXPECT_EQ(conn2, ch.FindNextPingableConnection()); | 1646 EXPECT_EQ(conn2, ch.FindNextPingableConnection()); |
| 1662 | 1647 |
| 1663 // Receiving a ping causes a triggered check which should make conn1 | 1648 // Receiving a ping causes a triggered check which should make conn1 |
| 1664 // be pinged first instead of conn2, even though conn2 has a higher | 1649 // be pinged first instead of conn2, even though conn2 has a higher |
| 1665 // priority. | 1650 // priority. |
| 1666 conn1->ReceivedPing(); | 1651 conn1->ReceivedPing(); |
| 1667 EXPECT_EQ(conn1, ch.FindNextPingableConnection()); | 1652 EXPECT_EQ(conn1, ch.FindNextPingableConnection()); |
| 1668 } | 1653 } |
| 1669 | 1654 |
| 1670 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { | 1655 TEST_F(P2PTransportChannelPingTest, TestNoTriggeredChecksWhenWritable) { |
| 1671 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1656 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 1672 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); | 1657 cricket::P2PTransportChannel ch("trigger checks", 1, nullptr, &pa); |
| 1673 PrepareChannel(&ch); | 1658 PrepareChannel(&ch); |
| 1674 ch.Connect(); | 1659 ch.Connect(); |
| 1675 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1660 ch.MaybeStartGathering(); |
| 1676 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 1661 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
| 1662 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); |
| 1677 | 1663 |
| 1678 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1664 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 1679 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1665 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 1680 ASSERT_TRUE(conn1 != nullptr); | 1666 ASSERT_TRUE(conn1 != nullptr); |
| 1681 ASSERT_TRUE(conn2 != nullptr); | 1667 ASSERT_TRUE(conn2 != nullptr); |
| 1682 | 1668 |
| 1683 EXPECT_EQ(conn2, ch.FindNextPingableConnection()); | 1669 EXPECT_EQ(conn2, ch.FindNextPingableConnection()); |
| 1684 conn1->ReceivedPingResponse(); | 1670 conn1->ReceivedPingResponse(); |
| 1685 ASSERT_TRUE(conn1->writable()); | 1671 ASSERT_TRUE(conn1->writable()); |
| 1686 conn1->ReceivedPing(); | 1672 conn1->ReceivedPing(); |
| 1687 | 1673 |
| 1688 // Ping received, but the connection is already writable, so no | 1674 // Ping received, but the connection is already writable, so no |
| 1689 // "triggered check" and conn2 is pinged before conn1 because it has | 1675 // "triggered check" and conn2 is pinged before conn1 because it has |
| 1690 // a higher priority. | 1676 // a higher priority. |
| 1691 EXPECT_EQ(conn2, ch.FindNextPingableConnection()); | 1677 EXPECT_EQ(conn2, ch.FindNextPingableConnection()); |
| 1692 } | 1678 } |
| 1693 | 1679 |
| 1694 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { | 1680 TEST_F(P2PTransportChannelPingTest, ConnectionResurrection) { |
| 1695 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1681 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 1696 cricket::P2PTransportChannel ch("connection resurrection", 1, nullptr, &pa); | 1682 cricket::P2PTransportChannel ch("connection resurrection", 1, nullptr, &pa); |
| 1697 PrepareChannel(&ch); | 1683 PrepareChannel(&ch); |
| 1698 ch.Connect(); | 1684 ch.Connect(); |
| 1685 ch.MaybeStartGathering(); |
| 1699 | 1686 |
| 1700 // Create conn1 and keep track of original candidate priority. | 1687 // Create conn1 and keep track of original candidate priority. |
| 1701 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1688 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
| 1702 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1689 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 1703 ASSERT_TRUE(conn1 != nullptr); | 1690 ASSERT_TRUE(conn1 != nullptr); |
| 1704 uint32 remote_priority = conn1->remote_candidate().priority(); | 1691 uint32 remote_priority = conn1->remote_candidate().priority(); |
| 1705 | 1692 |
| 1706 // Create a higher priority candidate and make the connection | 1693 // Create a higher priority candidate and make the connection |
| 1707 // receiving/writable. This will prune conn1. | 1694 // receiving/writable. This will prune conn1. |
| 1708 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 2)); | 1695 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 2)); |
| 1709 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1696 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 1710 ASSERT_TRUE(conn2 != nullptr); | 1697 ASSERT_TRUE(conn2 != nullptr); |
| 1711 conn2->ReceivedPing(); | 1698 conn2->ReceivedPing(); |
| 1712 conn2->ReceivedPingResponse(); | 1699 conn2->ReceivedPingResponse(); |
| 1713 | 1700 |
| 1714 // Wait for conn1 to be destroyed. | 1701 // Wait for conn1 to be destroyed. |
| 1715 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 3000); | 1702 EXPECT_TRUE_WAIT(GetConnectionTo(&ch, "1.1.1.1", 1) == nullptr, 3000); |
| 1716 cricket::Port* port = GetPort(&ch); | 1703 cricket::Port* port = GetPort(&ch); |
| 1717 | 1704 |
| 1718 // Create a minimal STUN message with prflx priority. | 1705 // Create a minimal STUN message with prflx priority. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1745 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); | 1732 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); |
| 1746 PrepareChannel(&ch); | 1733 PrepareChannel(&ch); |
| 1747 // Default receiving timeout and checking receiving delay should not be too | 1734 // Default receiving timeout and checking receiving delay should not be too |
| 1748 // small. | 1735 // small. |
| 1749 EXPECT_LE(1000, ch.receiving_timeout()); | 1736 EXPECT_LE(1000, ch.receiving_timeout()); |
| 1750 EXPECT_LE(200, ch.check_receiving_delay()); | 1737 EXPECT_LE(200, ch.check_receiving_delay()); |
| 1751 ch.SetReceivingTimeout(500); | 1738 ch.SetReceivingTimeout(500); |
| 1752 EXPECT_EQ(500, ch.receiving_timeout()); | 1739 EXPECT_EQ(500, ch.receiving_timeout()); |
| 1753 EXPECT_EQ(50, ch.check_receiving_delay()); | 1740 EXPECT_EQ(50, ch.check_receiving_delay()); |
| 1754 ch.Connect(); | 1741 ch.Connect(); |
| 1755 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1742 ch.MaybeStartGathering(); |
| 1743 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
| 1756 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1744 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 1757 ASSERT_TRUE(conn1 != nullptr); | 1745 ASSERT_TRUE(conn1 != nullptr); |
| 1758 | 1746 |
| 1759 conn1->ReceivedPing(); | 1747 conn1->ReceivedPing(); |
| 1760 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 1748 conn1->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
| 1761 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000) | 1749 EXPECT_TRUE_WAIT(ch.best_connection() != nullptr, 1000) |
| 1762 EXPECT_TRUE_WAIT(ch.receiving(), 1000); | 1750 EXPECT_TRUE_WAIT(ch.receiving(), 1000); |
| 1763 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); | 1751 EXPECT_TRUE_WAIT(!ch.receiving(), 1000); |
| 1764 } | 1752 } |
| 1765 | 1753 |
| 1766 // The controlled side will select a connection as the "best connection" based | 1754 // The controlled side will select a connection as the "best connection" based |
| 1767 // on priority until the controlling side nominates a connection, at which | 1755 // on priority until the controlling side nominates a connection, at which |
| 1768 // point the controlled side will select that connection as the | 1756 // point the controlled side will select that connection as the |
| 1769 // "best connection". | 1757 // "best connection". |
| 1770 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { | 1758 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBeforeNomination) { |
| 1771 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1759 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 1772 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); | 1760 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); |
| 1773 PrepareChannel(&ch); | 1761 PrepareChannel(&ch); |
| 1774 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 1762 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 1775 ch.Connect(); | 1763 ch.Connect(); |
| 1776 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 1)); | 1764 ch.MaybeStartGathering(); |
| 1765 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 1)); |
| 1777 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1766 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 1778 ASSERT_TRUE(conn1 != nullptr); | 1767 ASSERT_TRUE(conn1 != nullptr); |
| 1779 EXPECT_EQ(conn1, ch.best_connection()); | 1768 EXPECT_EQ(conn1, ch.best_connection()); |
| 1780 | 1769 |
| 1781 // When a higher priority candidate comes in, the new connection is chosen | 1770 // When a higher priority candidate comes in, the new connection is chosen |
| 1782 // as the best connection. | 1771 // as the best connection. |
| 1783 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 10)); | 1772 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 10)); |
| 1784 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1773 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 1785 ASSERT_TRUE(conn1 != nullptr); | 1774 ASSERT_TRUE(conn1 != nullptr); |
| 1786 EXPECT_EQ(conn2, ch.best_connection()); | 1775 EXPECT_EQ(conn2, ch.best_connection()); |
| 1787 | 1776 |
| 1788 // If a stun request with use-candidate attribute arrives, the receiving | 1777 // If a stun request with use-candidate attribute arrives, the receiving |
| 1789 // connection will be set as the best connection, even though | 1778 // connection will be set as the best connection, even though |
| 1790 // its priority is lower. | 1779 // its priority is lower. |
| 1791 ch.OnCandidate(CreateCandidate("3.3.3.3", 3, 1)); | 1780 ch.AddRemoteCandidate(CreateCandidate("3.3.3.3", 3, 1)); |
| 1792 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); | 1781 cricket::Connection* conn3 = WaitForConnectionTo(&ch, "3.3.3.3", 3); |
| 1793 ASSERT_TRUE(conn3 != nullptr); | 1782 ASSERT_TRUE(conn3 != nullptr); |
| 1794 // Because it has a lower priority, the best connection is still conn2. | 1783 // Because it has a lower priority, the best connection is still conn2. |
| 1795 EXPECT_EQ(conn2, ch.best_connection()); | 1784 EXPECT_EQ(conn2, ch.best_connection()); |
| 1796 conn3->ReceivedPingResponse(); // Become writable. | 1785 conn3->ReceivedPingResponse(); // Become writable. |
| 1797 // But if it is nominated via use_candidate, it is chosen as the best | 1786 // But if it is nominated via use_candidate, it is chosen as the best |
| 1798 // connection. | 1787 // connection. |
| 1799 conn3->set_nominated(true); | 1788 conn3->set_nominated(true); |
| 1800 conn3->SignalNominated(conn3); | 1789 conn3->SignalNominated(conn3); |
| 1801 EXPECT_EQ(conn3, ch.best_connection()); | 1790 EXPECT_EQ(conn3, ch.best_connection()); |
| 1802 | 1791 |
| 1803 // Even if another higher priority candidate arrives, | 1792 // Even if another higher priority candidate arrives, |
| 1804 // it will not be set as the best connection because the best connection | 1793 // it will not be set as the best connection because the best connection |
| 1805 // is nominated by the controlling side. | 1794 // is nominated by the controlling side. |
| 1806 ch.OnCandidate(CreateCandidate("4.4.4.4", 4, 100)); | 1795 ch.AddRemoteCandidate(CreateCandidate("4.4.4.4", 4, 100)); |
| 1807 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); | 1796 cricket::Connection* conn4 = WaitForConnectionTo(&ch, "4.4.4.4", 4); |
| 1808 ASSERT_TRUE(conn4 != nullptr); | 1797 ASSERT_TRUE(conn4 != nullptr); |
| 1809 EXPECT_EQ(conn3, ch.best_connection()); | 1798 EXPECT_EQ(conn3, ch.best_connection()); |
| 1810 // But if it is nominated via use_candidate and writable, it will be set as | 1799 // But if it is nominated via use_candidate and writable, it will be set as |
| 1811 // the best connection. | 1800 // the best connection. |
| 1812 conn4->set_nominated(true); | 1801 conn4->set_nominated(true); |
| 1813 conn4->SignalNominated(conn4); | 1802 conn4->SignalNominated(conn4); |
| 1814 // Not switched yet because conn4 is not writable. | 1803 // Not switched yet because conn4 is not writable. |
| 1815 EXPECT_EQ(conn3, ch.best_connection()); | 1804 EXPECT_EQ(conn3, ch.best_connection()); |
| 1816 // The best connection switches after conn4 becomes writable. | 1805 // The best connection switches after conn4 becomes writable. |
| 1817 conn4->ReceivedPingResponse(); | 1806 conn4->ReceivedPingResponse(); |
| 1818 EXPECT_EQ(conn4, ch.best_connection()); | 1807 EXPECT_EQ(conn4, ch.best_connection()); |
| 1819 } | 1808 } |
| 1820 | 1809 |
| 1821 // The controlled side will select a connection as the "best connection" based | 1810 // The controlled side will select a connection as the "best connection" based |
| 1822 // on requests from an unknown address before the controlling side nominates | 1811 // on requests from an unknown address before the controlling side nominates |
| 1823 // a connection, and will nominate a connection from an unknown address if the | 1812 // a connection, and will nominate a connection from an unknown address if the |
| 1824 // request contains the use_candidate attribute. | 1813 // request contains the use_candidate attribute. |
| 1825 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { | 1814 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionFromUnknownAddress) { |
| 1826 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1815 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 1827 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); | 1816 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); |
| 1828 PrepareChannel(&ch); | 1817 PrepareChannel(&ch); |
| 1829 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 1818 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 1830 ch.Connect(); | 1819 ch.Connect(); |
| 1820 ch.MaybeStartGathering(); |
| 1831 // A minimal STUN message with prflx priority. | 1821 // A minimal STUN message with prflx priority. |
| 1832 cricket::IceMessage request; | 1822 cricket::IceMessage request; |
| 1833 request.SetType(cricket::STUN_BINDING_REQUEST); | 1823 request.SetType(cricket::STUN_BINDING_REQUEST); |
| 1834 request.AddAttribute(new cricket::StunByteStringAttribute( | 1824 request.AddAttribute(new cricket::StunByteStringAttribute( |
| 1835 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); | 1825 cricket::STUN_ATTR_USERNAME, kIceUfrag[1])); |
| 1836 uint32 prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; | 1826 uint32 prflx_priority = cricket::ICE_TYPE_PREFERENCE_PRFLX << 24; |
| 1837 request.AddAttribute(new cricket::StunUInt32Attribute( | 1827 request.AddAttribute(new cricket::StunUInt32Attribute( |
| 1838 cricket::STUN_ATTR_PRIORITY, prflx_priority)); | 1828 cricket::STUN_ATTR_PRIORITY, prflx_priority)); |
| 1839 cricket::Port* port = GetPort(&ch); | 1829 cricket::Port* port = GetPort(&ch); |
| 1840 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), | 1830 port->SignalUnknownAddress(port, rtc::SocketAddress("1.1.1.1", 1), |
| 1841 cricket::PROTO_UDP, &request, kIceUfrag[1], false); | 1831 cricket::PROTO_UDP, &request, kIceUfrag[1], false); |
| 1842 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1832 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 1843 ASSERT_TRUE(conn1 != nullptr); | 1833 ASSERT_TRUE(conn1 != nullptr); |
| 1844 EXPECT_EQ(conn1, ch.best_connection()); | 1834 EXPECT_EQ(conn1, ch.best_connection()); |
| 1845 conn1->ReceivedPingResponse(); | 1835 conn1->ReceivedPingResponse(); |
| 1846 EXPECT_EQ(conn1, ch.best_connection()); | 1836 EXPECT_EQ(conn1, ch.best_connection()); |
| 1847 | 1837 |
| 1848 // Another connection is nominated via use_candidate. | 1838 // Another connection is nominated via use_candidate. |
| 1849 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 1)); | 1839 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); |
| 1850 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1840 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 1851 ASSERT_TRUE(conn2 != nullptr); | 1841 ASSERT_TRUE(conn2 != nullptr); |
| 1852 // Because it has a lower priority, the best connection is still conn1. | 1842 // Because it has a lower priority, the best connection is still conn1. |
| 1853 EXPECT_EQ(conn1, ch.best_connection()); | 1843 EXPECT_EQ(conn1, ch.best_connection()); |
| 1854 // When it is nominated via use_candidate and writable, it is chosen as the | 1844 // When it is nominated via use_candidate and writable, it is chosen as the |
| 1855 // best connection. | 1845 // best connection. |
| 1856 conn2->ReceivedPingResponse(); // Become writable. | 1846 conn2->ReceivedPingResponse(); // Become writable. |
| 1857 conn2->set_nominated(true); | 1847 conn2->set_nominated(true); |
| 1858 conn2->SignalNominated(conn2); | 1848 conn2->SignalNominated(conn2); |
| 1859 EXPECT_EQ(conn2, ch.best_connection()); | 1849 EXPECT_EQ(conn2, ch.best_connection()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1885 // The controlled side will select a connection as the "best connection" | 1875 // The controlled side will select a connection as the "best connection" |
| 1886 // based on media received until the controlling side nominates a connection, | 1876 // based on media received until the controlling side nominates a connection, |
| 1887 // at which point the controlled side will select that connection as | 1877 // at which point the controlled side will select that connection as |
| 1888 // the "best connection". | 1878 // the "best connection". |
| 1889 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { | 1879 TEST_F(P2PTransportChannelPingTest, TestSelectConnectionBasedOnMediaReceived) { |
| 1890 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); | 1880 cricket::FakePortAllocator pa(rtc::Thread::Current(), nullptr); |
| 1891 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); | 1881 cricket::P2PTransportChannel ch("receiving state change", 1, nullptr, &pa); |
| 1892 PrepareChannel(&ch); | 1882 PrepareChannel(&ch); |
| 1893 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); | 1883 ch.SetIceRole(cricket::ICEROLE_CONTROLLED); |
| 1894 ch.Connect(); | 1884 ch.Connect(); |
| 1895 ch.OnCandidate(CreateCandidate("1.1.1.1", 1, 10)); | 1885 ch.MaybeStartGathering(); |
| 1886 ch.AddRemoteCandidate(CreateCandidate("1.1.1.1", 1, 10)); |
| 1896 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); | 1887 cricket::Connection* conn1 = WaitForConnectionTo(&ch, "1.1.1.1", 1); |
| 1897 ASSERT_TRUE(conn1 != nullptr); | 1888 ASSERT_TRUE(conn1 != nullptr); |
| 1898 EXPECT_EQ(conn1, ch.best_connection()); | 1889 EXPECT_EQ(conn1, ch.best_connection()); |
| 1899 | 1890 |
| 1900 // If a data packet is received on conn2, the best connection should | 1891 // If a data packet is received on conn2, the best connection should |
| 1901 // switch to conn2 because the controlled side must mirror the media path | 1892 // switch to conn2 because the controlled side must mirror the media path |
| 1902 // chosen by the controlling side. | 1893 // chosen by the controlling side. |
| 1903 ch.OnCandidate(CreateCandidate("2.2.2.2", 2, 1)); | 1894 ch.AddRemoteCandidate(CreateCandidate("2.2.2.2", 2, 1)); |
| 1904 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); | 1895 cricket::Connection* conn2 = WaitForConnectionTo(&ch, "2.2.2.2", 2); |
| 1905 ASSERT_TRUE(conn2 != nullptr); | 1896 ASSERT_TRUE(conn2 != nullptr); |
| 1906 conn2->ReceivedPing(); // Start receiving. | 1897 conn2->ReceivedPing(); // Start receiving. |
| 1907 // Do not switch because it is not writable. | 1898 // Do not switch because it is not writable. |
| 1908 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); | 1899 conn2->OnReadPacket("ABC", 3, rtc::CreatePacketTime(0)); |
| 1909 EXPECT_EQ(conn1, ch.best_connection()); | 1900 EXPECT_EQ(conn1, ch.best_connection()); |
| 1910 | 1901 |
| 1911 conn2->ReceivedPingResponse(); // Become writable. | 1902 conn2->ReceivedPingResponse(); // Become writable. |
| 1912 // Switch because it is writable. | 1903 // Switch because it is writable. |
| 1913 conn2->OnReadPacket("DEF", 3, rtc::CreatePacketTime(0)); | 1904 conn2->OnReadPacket("DEF", 3, rtc::CreatePacketTime(0)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1933 conn3->ReceivedPingResponse(); // Become writable. | 1924 conn3->ReceivedPingResponse(); // Become writable. |
| 1934 EXPECT_EQ(conn3, ch.best_connection()); | 1925 EXPECT_EQ(conn3, ch.best_connection()); |
| 1935 | 1926 |
| 1936 // Now another data packet will not switch the best connection because the | 1927 // Now another data packet will not switch the best connection because the |
| 1937 // best connection was nominated by the controlling side. | 1928 // best connection was nominated by the controlling side. |
| 1938 conn2->ReceivedPing(); | 1929 conn2->ReceivedPing(); |
| 1939 conn2->ReceivedPingResponse(); | 1930 conn2->ReceivedPingResponse(); |
| 1940 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); | 1931 conn2->OnReadPacket("XYZ", 3, rtc::CreatePacketTime(0)); |
| 1941 EXPECT_EQ(conn3, ch.best_connection()); | 1932 EXPECT_EQ(conn3, ch.best_connection()); |
| 1942 } | 1933 } |
| OLD | NEW |