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

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

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

Powered by Google App Engine
This is Rietveld 408576698