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

Side by Side Diff: webrtc/p2p/client/portallocator_unittest.cc

Issue 1215713003: Ensuring that UDP TURN servers are always used as STUN servers. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 6 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/client/basicportallocator.cc ('k') | no next file » | 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 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 ASSERT_EQ(2U, ports_.size()); 777 ASSERT_EQ(2U, ports_.size());
778 EXPECT_PRED5(CheckCandidate, candidates_[0], 778 EXPECT_PRED5(CheckCandidate, candidates_[0],
779 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); 779 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
780 EXPECT_PRED5(CheckCandidate, candidates_[1], 780 EXPECT_PRED5(CheckCandidate, candidates_[1],
781 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", 781 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
782 rtc::SocketAddress(kNatAddr.ipaddr(), 0)); 782 rtc::SocketAddress(kNatAddr.ipaddr(), 0));
783 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 783 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
784 EXPECT_EQ(3U, candidates_.size()); 784 EXPECT_EQ(3U, candidates_.size());
785 } 785 }
786 786
787 // Test TURN port in shared socket mode with UDP and TCP TURN server adderesses. 787 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses.
788 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { 788 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) {
789 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); 789 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
790 AddInterface(kClientAddr); 790 AddInterface(kClientAddr);
791 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); 791 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_));
792 792
793 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); 793 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
794 794
795 allocator_->set_step_delay(cricket::kMinimumStepDelay); 795 allocator_->set_step_delay(cricket::kMinimumStepDelay);
796 allocator_->set_flags(allocator().flags() | 796 allocator_->set_flags(allocator().flags() |
797 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 797 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 909 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
910 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); 910 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address());
911 911
912 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 912 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
913 EXPECT_EQ(3U, candidates_.size()); 913 EXPECT_EQ(3U, candidates_.size());
914 // Local port will be created first and then TURN port. 914 // Local port will be created first and then TURN port.
915 EXPECT_EQ(2U, ports_[0]->Candidates().size()); 915 EXPECT_EQ(2U, ports_[0]->Candidates().size());
916 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 916 EXPECT_EQ(1U, ports_[1]->Candidates().size());
917 } 917 }
918 918
919 // Test that even when both a STUN and TURN server are configured, the TURN
920 // server is used as a STUN server and we get a 'stun' candidate.
921 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) {
922 AddInterface(kClientAddr);
923 // Configure with STUN server but destroy it, so we can ensure that it's
924 // the TURN server actually being used as a STUN server.
925 ResetWithNatServer(kStunAddr);
926 stun_server_.reset();
927 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
928
929 // Must set the step delay to 0 to make sure the relay allocation phase is
930 // started before the STUN candidates are obtained, so that the STUN binding
931 // response is processed when both StunPort and TurnPort exist to reproduce
932 // webrtc issue 3537.
933 allocator_->set_step_delay(0);
934 allocator_->set_flags(allocator().flags() |
935 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
936 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
937 cricket::PORTALLOCATOR_DISABLE_TCP);
938
939 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
940 session_->StartGettingPorts();
941
942 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
943 EXPECT_PRED5(CheckCandidate, candidates_[0],
944 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
945 EXPECT_PRED5(CheckCandidate, candidates_[1],
946 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
947 rtc::SocketAddress(kNatAddr.ipaddr(), 0));
948 EXPECT_PRED5(CheckCandidate, candidates_[2],
949 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
950 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
951 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address());
952
953 // Don't bother waiting for STUN timeout, since we already verified
juberti1 2015/06/27 04:39:54 I don't understand this. Don't we want to get the
Taylor Brandstetter 2015/06/27 17:05:49 In this case the main thing I wanted to test was t
juberti1 2015/06/29 18:40:00 OK, I see what you are saying. I think the 2-level
Taylor Brandstetter 2015/06/29 20:18:34 The 3537 comment and step delay aren't really need
954 // that we got a STUN candidate from the TURN server.
955 }
956
957 // Test that when only a TCP TURN server is available, we do NOT use it as
958 // a UDP STUN server, as this could leak our IP address. Thus we should only
959 // expect two ports, a UDPPort and TurnPort.
juberti1 2015/06/27 04:39:54 You'll only have two ports anytime you use shared
Taylor Brandstetter 2015/06/27 17:05:49 That's why I had intended to use non-shared socket
960 TEST_F(PortAllocatorTest, TestNonSharedSocketWithoutNatUsingTurnTcp) {
juberti1 2015/06/27 04:39:54 The socket is shared, so this name is confusing
Taylor Brandstetter 2015/06/27 17:05:50 As mentioned above, fixed in patch set 2.
961 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP);
962 AddInterface(kClientAddr);
963 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_));
964
965 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr);
966
967 allocator_->set_step_delay(cricket::kMinimumStepDelay);
968 allocator_->set_flags(allocator().flags() |
969 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
970 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET |
971 cricket::PORTALLOCATOR_DISABLE_TCP);
972
973 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
974 session_->StartGettingPorts();
975
976 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout);
977 ASSERT_EQ(2U, ports_.size());
978 EXPECT_PRED5(CheckCandidate, candidates_[0],
979 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
980 EXPECT_PRED5(CheckCandidate, candidates_[1],
981 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
982 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
983 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
984 EXPECT_EQ(2U, candidates_.size());
985 EXPECT_EQ(1U, ports_[0]->Candidates().size());
986 EXPECT_EQ(1U, ports_[1]->Candidates().size());
987 }
988
989 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the
990 // TURN server is used as the STUN server and we get 'local', 'stun', and
991 // 'relay' candidates.
992 TEST_F(PortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) {
993 AddInterface(kClientAddr);
994 // Use an empty SocketAddress to add a NAT without STUN server.
995 ResetWithNatServer(SocketAddress());
996 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
997
998 allocator_->set_step_delay(0);
999 allocator_->set_flags(allocator().flags() |
1000 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
1001 cricket::PORTALLOCATOR_DISABLE_TCP);
1002
1003 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1004 session_->StartGettingPorts();
1005
1006 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout);
1007 ASSERT_EQ(3U, ports_.size());
1008 EXPECT_PRED5(CheckCandidate, candidates_[0],
1009 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr);
1010 EXPECT_PRED5(CheckCandidate, candidates_[1],
1011 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp",
1012 rtc::SocketAddress(kNatAddr.ipaddr(), 0));
1013 EXPECT_PRED5(CheckCandidate, candidates_[2],
1014 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp",
1015 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1016 // Not using shared socket, so the STUN request's server reflexive address
1017 // should be different than the TURN request's server reflexive address.
1018 EXPECT_NE(candidates_[2].related_address(), candidates_[1].address());
1019
1020 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout);
1021 EXPECT_EQ(3U, candidates_.size());
1022 EXPECT_EQ(1U, ports_[0]->Candidates().size());
1023 EXPECT_EQ(1U, ports_[1]->Candidates().size());
1024 EXPECT_EQ(1U, ports_[2]->Candidates().size());
1025 }
1026
919 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled 1027 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled
920 // and fail to generate STUN candidate, local UDP candidate is generated 1028 // and fail to generate STUN candidate, local UDP candidate is generated
921 // properly. 1029 // properly.
922 TEST_F(PortAllocatorTest, TestSharedSocketNoUdpAllowed) { 1030 TEST_F(PortAllocatorTest, TestSharedSocketNoUdpAllowed) {
923 allocator().set_flags(allocator().flags() | 1031 allocator().set_flags(allocator().flags() |
924 cricket::PORTALLOCATOR_DISABLE_RELAY | 1032 cricket::PORTALLOCATOR_DISABLE_RELAY |
925 cricket::PORTALLOCATOR_DISABLE_TCP | 1033 cricket::PORTALLOCATOR_DISABLE_TCP |
926 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | 1034 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
927 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1035 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET);
928 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); 1036 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); 1153 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP));
1046 session_->StartGettingPorts(); 1154 session_->StartGettingPorts();
1047 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); 1155 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout);
1048 EXPECT_EQ(4U, ports_.size()); 1156 EXPECT_EQ(4U, ports_.size());
1049 1157
1050 auto it = ports_.begin(); 1158 auto it = ports_.begin();
1051 for (; it != ports_.end(); ++it) { 1159 for (; it != ports_.end(); ++it) {
1052 (reinterpret_cast<cricket::Port*>(*it))->Destroy(); 1160 (reinterpret_cast<cricket::Port*>(*it))->Destroy();
1053 } 1161 }
1054 } 1162 }
OLDNEW
« no previous file with comments | « webrtc/p2p/client/basicportallocator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698