OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 Loading... | |
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 | |
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. | |
960 TEST_F(PortAllocatorTest, TestNonSharedSocketWithoutNatUsingTurnTcp) { | |
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_DISABLE_TCP); | |
971 | |
972 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | |
973 session_->StartGettingPorts(); | |
974 | |
975 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); | |
976 ASSERT_EQ(2U, ports_.size()); | |
977 EXPECT_PRED5(CheckCandidate, candidates_[0], | |
978 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | |
979 EXPECT_PRED5(CheckCandidate, candidates_[1], | |
980 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | |
981 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | |
982 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | |
983 EXPECT_EQ(2U, candidates_.size()); | |
984 EXPECT_EQ(1U, ports_[0]->Candidates().size()); | |
985 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | |
986 } | |
987 | |
988 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the | |
989 // TURN server is used as the STUN server and we get 'local', 'stun', and | |
990 // 'relay' candidates. | |
991 TEST_F(PortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { | |
992 AddInterface(kClientAddr); | |
993 // Use an empty SocketAddress to add a NAT without STUN server. | |
994 ResetWithNatServer(SocketAddress()); | |
995 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | |
996 | |
997 allocator_->set_step_delay(0); | |
998 allocator_->set_flags(allocator().flags() | | |
999 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | |
1000 cricket::PORTALLOCATOR_DISABLE_TCP); | |
1001 | |
1002 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | |
1003 session_->StartGettingPorts(); | |
1004 | |
1005 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | |
1006 ASSERT_EQ(3U, ports_.size()); | |
1007 EXPECT_PRED5(CheckCandidate, candidates_[0], | |
1008 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | |
1009 EXPECT_PRED5(CheckCandidate, candidates_[1], | |
1010 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", | |
1011 rtc::SocketAddress(kNatAddr.ipaddr(), 0)); | |
1012 EXPECT_PRED5(CheckCandidate, candidates_[2], | |
1013 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | |
1014 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | |
1015 // Not using shared socket, so the STUN request's server reflexive address | |
1016 // should be different than the TURN request's server reflexive address. | |
1017 EXPECT_NE(candidates_[2].related_address(), candidates_[1].address()); | |
juberti1
2015/06/29 18:54:49
But candidates_[2] is not server reflexive, so thi
Taylor Brandstetter
2015/06/29 20:18:35
candidates_[2] isn't server reflexive, but its rel
| |
1018 | |
1019 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | |
1020 EXPECT_EQ(3U, candidates_.size()); | |
1021 EXPECT_EQ(1U, ports_[0]->Candidates().size()); | |
1022 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | |
1023 EXPECT_EQ(1U, ports_[2]->Candidates().size()); | |
1024 } | |
1025 | |
919 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled | 1026 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled |
920 // and fail to generate STUN candidate, local UDP candidate is generated | 1027 // and fail to generate STUN candidate, local UDP candidate is generated |
921 // properly. | 1028 // properly. |
922 TEST_F(PortAllocatorTest, TestSharedSocketNoUdpAllowed) { | 1029 TEST_F(PortAllocatorTest, TestSharedSocketNoUdpAllowed) { |
923 allocator().set_flags(allocator().flags() | | 1030 allocator().set_flags(allocator().flags() | |
924 cricket::PORTALLOCATOR_DISABLE_RELAY | | 1031 cricket::PORTALLOCATOR_DISABLE_RELAY | |
925 cricket::PORTALLOCATOR_DISABLE_TCP | | 1032 cricket::PORTALLOCATOR_DISABLE_TCP | |
926 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | 1033 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | |
927 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1034 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
928 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); | 1035 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1045 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1152 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1046 session_->StartGettingPorts(); | 1153 session_->StartGettingPorts(); |
1047 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 1154 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
1048 EXPECT_EQ(4U, ports_.size()); | 1155 EXPECT_EQ(4U, ports_.size()); |
1049 | 1156 |
1050 auto it = ports_.begin(); | 1157 auto it = ports_.begin(); |
1051 for (; it != ports_.end(); ++it) { | 1158 for (; it != ports_.end(); ++it) { |
1052 (reinterpret_cast<cricket::Port*>(*it))->Destroy(); | 1159 (reinterpret_cast<cricket::Port*>(*it))->Destroy(); |
1053 } | 1160 } |
1054 } | 1161 } |
OLD | NEW |