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

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

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

Powered by Google App Engine
This is Rietveld 408576698