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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 uint32 total_ports, | 246 uint32 total_ports, |
247 const rtc::IPAddress& host_candidate_addr, | 247 const rtc::IPAddress& host_candidate_addr, |
248 const rtc::IPAddress& stun_candidate_addr, | 248 const rtc::IPAddress& stun_candidate_addr, |
249 const rtc::IPAddress& relay_candidate_udp_transport_addr, | 249 const rtc::IPAddress& relay_candidate_udp_transport_addr, |
250 const rtc::IPAddress& relay_candidate_tcp_transport_addr) { | 250 const rtc::IPAddress& relay_candidate_tcp_transport_addr) { |
251 if (!session_) { | 251 if (!session_) { |
252 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 252 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
253 } | 253 } |
254 session_->set_flags(session_->flags() | | 254 session_->set_flags(session_->flags() | |
255 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | | 255 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | |
256 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | |
257 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 256 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
258 allocator().set_allow_tcp_listen(false); | 257 allocator().set_allow_tcp_listen(false); |
259 session_->StartGettingPorts(); | 258 session_->StartGettingPorts(); |
260 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 259 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
261 | 260 |
262 uint32 total_candidates = 0; | 261 uint32 total_candidates = 0; |
263 if (!host_candidate_addr.IsNil()) { | 262 if (!host_candidate_addr.IsNil()) { |
264 EXPECT_PRED5(CheckCandidate, candidates_[total_candidates], | 263 EXPECT_PRED5(CheckCandidate, candidates_[total_candidates], |
265 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 264 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
266 rtc::SocketAddress(host_candidate_addr, 0)); | 265 rtc::SocketAddress(host_candidate_addr, 0)); |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 for (size_t i = 0; i < candidates_.size(); ++i) { | 769 for (size_t i = 0; i < candidates_.size(); ++i) { |
771 EXPECT_EQ(std::string(cricket::RELAY_PORT_TYPE), candidates_[i].type()); | 770 EXPECT_EQ(std::string(cricket::RELAY_PORT_TYPE), candidates_[i].type()); |
772 EXPECT_EQ( | 771 EXPECT_EQ( |
773 candidates_[0].related_address(), | 772 candidates_[0].related_address(), |
774 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); | 773 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); |
775 } | 774 } |
776 } | 775 } |
777 | 776 |
778 TEST_F(PortAllocatorTest, TestCandidateFilterWithHostOnly) { | 777 TEST_F(PortAllocatorTest, TestCandidateFilterWithHostOnly) { |
779 AddInterface(kClientAddr); | 778 AddInterface(kClientAddr); |
780 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | 779 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
781 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | |
782 allocator().set_candidate_filter(cricket::CF_HOST); | 780 allocator().set_candidate_filter(cricket::CF_HOST); |
783 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 781 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
784 session_->StartGettingPorts(); | 782 session_->StartGettingPorts(); |
785 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 783 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
786 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. | 784 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. |
787 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. | 785 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. |
788 for (size_t i = 0; i < candidates_.size(); ++i) { | 786 for (size_t i = 0; i < candidates_.size(); ++i) { |
789 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); | 787 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); |
790 } | 788 } |
791 } | 789 } |
792 | 790 |
793 // Host is behind the NAT. | 791 // Host is behind the NAT. |
794 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { | 792 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { |
795 AddInterface(kPrivateAddr); | 793 AddInterface(kPrivateAddr); |
796 ResetWithStunServerAndNat(kStunAddr); | 794 ResetWithStunServerAndNat(kStunAddr); |
797 | 795 |
798 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | 796 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
799 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | |
800 allocator().set_candidate_filter(cricket::CF_REFLEXIVE); | 797 allocator().set_candidate_filter(cricket::CF_REFLEXIVE); |
801 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 798 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
802 session_->StartGettingPorts(); | 799 session_->StartGettingPorts(); |
803 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 800 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
804 // Host is behind NAT, no private address will be exposed. Hence only UDP | 801 // Host is behind NAT, no private address will be exposed. Hence only UDP |
805 // port with STUN candidate will be sent outside. | 802 // port with STUN candidate will be sent outside. |
806 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. | 803 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. |
807 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state. | 804 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state. |
808 for (size_t i = 0; i < candidates_.size(); ++i) { | 805 for (size_t i = 0; i < candidates_.size(); ++i) { |
809 EXPECT_EQ(std::string(cricket::STUN_PORT_TYPE), candidates_[i].type()); | 806 EXPECT_EQ(std::string(cricket::STUN_PORT_TYPE), candidates_[i].type()); |
810 EXPECT_EQ( | 807 EXPECT_EQ( |
811 candidates_[0].related_address(), | 808 candidates_[0].related_address(), |
812 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); | 809 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); |
813 } | 810 } |
814 } | 811 } |
815 | 812 |
816 // Host is not behind the NAT. | 813 // Host is not behind the NAT. |
817 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) { | 814 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) { |
818 AddInterface(kClientAddr); | 815 AddInterface(kClientAddr); |
819 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | 816 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
820 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | |
821 allocator().set_candidate_filter(cricket::CF_REFLEXIVE); | 817 allocator().set_candidate_filter(cricket::CF_REFLEXIVE); |
822 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 818 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
823 session_->StartGettingPorts(); | 819 session_->StartGettingPorts(); |
824 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 820 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
825 // Host has a public address, both UDP and TCP candidates will be exposed. | 821 // Host has a public address, both UDP and TCP candidates will be exposed. |
826 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate. | 822 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate. |
827 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state. | 823 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state. |
828 for (size_t i = 0; i < candidates_.size(); ++i) { | 824 for (size_t i = 0; i < candidates_.size(); ++i) { |
829 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); | 825 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); |
830 } | 826 } |
831 } | 827 } |
832 | 828 |
833 // Test that when the PORTALLOCATOR_ENABLE_SHARED_UFRAG is enabled we got same | 829 // Test that we get the same ufrag and pwd for all candidates. |
834 // ufrag and pwd for the collected candidates. | |
835 TEST_F(PortAllocatorTest, TestEnableSharedUfrag) { | 830 TEST_F(PortAllocatorTest, TestEnableSharedUfrag) { |
836 allocator().set_flags(allocator().flags() | | |
837 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG); | |
838 AddInterface(kClientAddr); | 831 AddInterface(kClientAddr); |
839 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 832 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
840 session_->StartGettingPorts(); | 833 session_->StartGettingPorts(); |
841 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 834 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
842 EXPECT_PRED5(CheckCandidate, candidates_[0], | 835 EXPECT_PRED5(CheckCandidate, candidates_[0], |
843 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | 836 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); |
844 EXPECT_PRED5(CheckCandidate, candidates_[1], | 837 EXPECT_PRED5(CheckCandidate, candidates_[1], |
845 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", kClientAddr); | 838 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", kClientAddr); |
846 EXPECT_PRED5(CheckCandidate, candidates_[5], | 839 EXPECT_PRED5(CheckCandidate, candidates_[5], |
847 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr); | 840 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr); |
848 EXPECT_EQ(4U, ports_.size()); | 841 EXPECT_EQ(4U, ports_.size()); |
849 EXPECT_EQ(kIceUfrag0, candidates_[0].username()); | 842 EXPECT_EQ(kIceUfrag0, candidates_[0].username()); |
850 EXPECT_EQ(kIceUfrag0, candidates_[1].username()); | 843 EXPECT_EQ(kIceUfrag0, candidates_[1].username()); |
851 EXPECT_EQ(kIceUfrag0, candidates_[2].username()); | 844 EXPECT_EQ(kIceUfrag0, candidates_[2].username()); |
852 EXPECT_EQ(kIcePwd0, candidates_[0].password()); | 845 EXPECT_EQ(kIcePwd0, candidates_[0].password()); |
853 EXPECT_EQ(kIcePwd0, candidates_[1].password()); | 846 EXPECT_EQ(kIcePwd0, candidates_[1].password()); |
854 EXPECT_TRUE(candidate_allocation_done_); | 847 EXPECT_TRUE(candidate_allocation_done_); |
855 } | 848 } |
856 | 849 |
857 // Test that when the PORTALLOCATOR_ENABLE_SHARED_UFRAG isn't enabled we got | |
858 // different ufrag and pwd for the collected candidates. | |
859 TEST_F(PortAllocatorTest, TestDisableSharedUfrag) { | |
860 allocator().set_flags(allocator().flags() & | |
861 ~cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG); | |
862 AddInterface(kClientAddr); | |
863 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | |
864 session_->StartGettingPorts(); | |
865 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | |
866 EXPECT_PRED5(CheckCandidate, candidates_[0], | |
867 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | |
868 EXPECT_PRED5(CheckCandidate, candidates_[1], | |
869 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", kClientAddr); | |
870 EXPECT_EQ(4U, ports_.size()); | |
871 // Port should generate random ufrag and pwd. | |
872 EXPECT_NE(kIceUfrag0, candidates_[0].username()); | |
873 EXPECT_NE(kIceUfrag0, candidates_[1].username()); | |
874 EXPECT_NE(candidates_[0].username(), candidates_[1].username()); | |
875 EXPECT_NE(kIcePwd0, candidates_[0].password()); | |
876 EXPECT_NE(kIcePwd0, candidates_[1].password()); | |
877 EXPECT_NE(candidates_[0].password(), candidates_[1].password()); | |
878 EXPECT_TRUE(candidate_allocation_done_); | |
879 } | |
880 | |
881 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port | 850 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port |
882 // is allocated for udp and stun. Also verify there is only one candidate | 851 // is allocated for udp and stun. Also verify there is only one candidate |
883 // (local) if stun candidate is same as local candidate, which will be the case | 852 // (local) if stun candidate is same as local candidate, which will be the case |
884 // in a public network like the below test. | 853 // in a public network like the below test. |
885 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNat) { | 854 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNat) { |
886 AddInterface(kClientAddr); | 855 AddInterface(kClientAddr); |
887 allocator_->set_flags(allocator().flags() | | 856 allocator_->set_flags(allocator().flags() | |
888 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | |
889 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 857 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
890 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 858 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
891 session_->StartGettingPorts(); | 859 session_->StartGettingPorts(); |
892 ASSERT_EQ_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout); | 860 ASSERT_EQ_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout); |
893 EXPECT_EQ(3U, ports_.size()); | 861 EXPECT_EQ(3U, ports_.size()); |
894 EXPECT_PRED5(CheckCandidate, candidates_[0], | 862 EXPECT_PRED5(CheckCandidate, candidates_[0], |
895 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | 863 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); |
896 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 864 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
897 } | 865 } |
898 | 866 |
899 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port | 867 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port |
900 // is allocated for udp and stun. In this test we should expect both stun and | 868 // is allocated for udp and stun. In this test we should expect both stun and |
901 // local candidates as client behind a nat. | 869 // local candidates as client behind a nat. |
902 TEST_F(PortAllocatorTest, TestSharedSocketWithNat) { | 870 TEST_F(PortAllocatorTest, TestSharedSocketWithNat) { |
903 AddInterface(kClientAddr); | 871 AddInterface(kClientAddr); |
904 ResetWithStunServerAndNat(kStunAddr); | 872 ResetWithStunServerAndNat(kStunAddr); |
905 | 873 |
906 allocator_->set_flags(allocator().flags() | | 874 allocator_->set_flags(allocator().flags() | |
907 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | |
908 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 875 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
909 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 876 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
910 session_->StartGettingPorts(); | 877 session_->StartGettingPorts(); |
911 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 878 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); |
912 ASSERT_EQ(2U, ports_.size()); | 879 ASSERT_EQ(2U, ports_.size()); |
913 EXPECT_PRED5(CheckCandidate, candidates_[0], | 880 EXPECT_PRED5(CheckCandidate, candidates_[0], |
914 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | 881 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); |
915 EXPECT_PRED5(CheckCandidate, candidates_[1], | 882 EXPECT_PRED5(CheckCandidate, candidates_[1], |
916 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", | 883 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", |
917 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); | 884 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); |
918 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 885 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
919 EXPECT_EQ(3U, candidates_.size()); | 886 EXPECT_EQ(3U, candidates_.size()); |
920 } | 887 } |
921 | 888 |
922 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses. | 889 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses. |
923 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { | 890 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { |
924 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); | 891 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); |
925 AddInterface(kClientAddr); | 892 AddInterface(kClientAddr); |
926 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); | 893 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); |
927 | 894 |
928 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | 895 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
929 | 896 |
930 allocator_->set_step_delay(cricket::kMinimumStepDelay); | 897 allocator_->set_step_delay(cricket::kMinimumStepDelay); |
931 allocator_->set_flags(allocator().flags() | | 898 allocator_->set_flags(allocator().flags() | |
932 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | |
933 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 899 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
934 cricket::PORTALLOCATOR_DISABLE_TCP); | 900 cricket::PORTALLOCATOR_DISABLE_TCP); |
935 | 901 |
936 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 902 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
937 session_->StartGettingPorts(); | 903 session_->StartGettingPorts(); |
938 | 904 |
939 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 905 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); |
940 ASSERT_EQ(3U, ports_.size()); | 906 ASSERT_EQ(3U, ports_.size()); |
941 EXPECT_PRED5(CheckCandidate, candidates_[0], | 907 EXPECT_PRED5(CheckCandidate, candidates_[0], |
942 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | 908 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); |
(...skipping 17 matching lines...) Expand all Loading... |
960 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); | 926 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); |
961 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); | 927 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); |
962 relay_server.credentials = credentials; | 928 relay_server.credentials = credentials; |
963 relay_server.ports.push_back(cricket::ProtocolAddress( | 929 relay_server.ports.push_back(cricket::ProtocolAddress( |
964 rtc::SocketAddress("localhost", 3478), | 930 rtc::SocketAddress("localhost", 3478), |
965 cricket::PROTO_UDP, false)); | 931 cricket::PROTO_UDP, false)); |
966 allocator_->AddRelay(relay_server); | 932 allocator_->AddRelay(relay_server); |
967 | 933 |
968 allocator_->set_step_delay(cricket::kMinimumStepDelay); | 934 allocator_->set_step_delay(cricket::kMinimumStepDelay); |
969 allocator_->set_flags(allocator().flags() | | 935 allocator_->set_flags(allocator().flags() | |
970 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | |
971 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 936 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
972 cricket::PORTALLOCATOR_DISABLE_TCP); | 937 cricket::PORTALLOCATOR_DISABLE_TCP); |
973 | 938 |
974 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 939 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
975 session_->StartGettingPorts(); | 940 session_->StartGettingPorts(); |
976 | 941 |
977 EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout); | 942 EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout); |
978 } | 943 } |
979 | 944 |
980 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port | 945 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port |
981 // is allocated for udp/stun/turn. In this test we should expect all local, | 946 // is allocated for udp/stun/turn. In this test we should expect all local, |
982 // stun and turn candidates. | 947 // stun and turn candidates. |
983 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurn) { | 948 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurn) { |
984 AddInterface(kClientAddr); | 949 AddInterface(kClientAddr); |
985 ResetWithStunServerAndNat(kStunAddr); | 950 ResetWithStunServerAndNat(kStunAddr); |
986 | 951 |
987 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 952 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
988 | 953 |
989 allocator_->set_flags(allocator().flags() | | 954 allocator_->set_flags(allocator().flags() | |
990 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | |
991 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 955 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
992 cricket::PORTALLOCATOR_DISABLE_TCP); | 956 cricket::PORTALLOCATOR_DISABLE_TCP); |
993 | 957 |
994 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 958 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
995 session_->StartGettingPorts(); | 959 session_->StartGettingPorts(); |
996 | 960 |
997 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 961 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); |
998 ASSERT_EQ(2U, ports_.size()); | 962 ASSERT_EQ(2U, ports_.size()); |
999 EXPECT_PRED5(CheckCandidate, candidates_[0], | 963 EXPECT_PRED5(CheckCandidate, candidates_[0], |
1000 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | 964 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); |
(...skipping 18 matching lines...) Expand all Loading... |
1019 // Use an empty SocketAddress to add a NAT without STUN server. | 983 // Use an empty SocketAddress to add a NAT without STUN server. |
1020 ResetWithStunServerAndNat(SocketAddress()); | 984 ResetWithStunServerAndNat(SocketAddress()); |
1021 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 985 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
1022 | 986 |
1023 // Must set the step delay to 0 to make sure the relay allocation phase is | 987 // Must set the step delay to 0 to make sure the relay allocation phase is |
1024 // started before the STUN candidates are obtained, so that the STUN binding | 988 // started before the STUN candidates are obtained, so that the STUN binding |
1025 // response is processed when both StunPort and TurnPort exist to reproduce | 989 // response is processed when both StunPort and TurnPort exist to reproduce |
1026 // webrtc issue 3537. | 990 // webrtc issue 3537. |
1027 allocator_->set_step_delay(0); | 991 allocator_->set_step_delay(0); |
1028 allocator_->set_flags(allocator().flags() | | 992 allocator_->set_flags(allocator().flags() | |
1029 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | |
1030 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 993 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1031 cricket::PORTALLOCATOR_DISABLE_TCP); | 994 cricket::PORTALLOCATOR_DISABLE_TCP); |
1032 | 995 |
1033 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 996 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1034 session_->StartGettingPorts(); | 997 session_->StartGettingPorts(); |
1035 | 998 |
1036 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 999 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); |
1037 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1000 EXPECT_PRED5(CheckCandidate, candidates_[0], |
1038 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | 1001 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); |
1039 EXPECT_PRED5(CheckCandidate, candidates_[1], | 1002 EXPECT_PRED5(CheckCandidate, candidates_[1], |
(...skipping 14 matching lines...) Expand all Loading... |
1054 // Test that when only a TCP TURN server is available, we do NOT use it as | 1017 // Test that when only a TCP TURN server is available, we do NOT use it as |
1055 // a UDP STUN server, as this could leak our IP address. Thus we should only | 1018 // a UDP STUN server, as this could leak our IP address. Thus we should only |
1056 // expect two ports, a UDPPort and TurnPort. | 1019 // expect two ports, a UDPPort and TurnPort. |
1057 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { | 1020 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { |
1058 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); | 1021 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); |
1059 AddInterface(kClientAddr); | 1022 AddInterface(kClientAddr); |
1060 ResetWithStunServerAndNat(rtc::SocketAddress()); | 1023 ResetWithStunServerAndNat(rtc::SocketAddress()); |
1061 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr); | 1024 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr); |
1062 | 1025 |
1063 allocator_->set_flags(allocator().flags() | | 1026 allocator_->set_flags(allocator().flags() | |
1064 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | |
1065 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1027 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1066 cricket::PORTALLOCATOR_DISABLE_TCP); | 1028 cricket::PORTALLOCATOR_DISABLE_TCP); |
1067 | 1029 |
1068 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1030 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1069 session_->StartGettingPorts(); | 1031 session_->StartGettingPorts(); |
1070 | 1032 |
1071 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); | 1033 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); |
1072 ASSERT_EQ(2U, ports_.size()); | 1034 ASSERT_EQ(2U, ports_.size()); |
1073 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1035 EXPECT_PRED5(CheckCandidate, candidates_[0], |
1074 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 1036 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
(...skipping 12 matching lines...) Expand all Loading... |
1087 // 'relay' candidates. | 1049 // 'relay' candidates. |
1088 // TODO(deadbeef): Remove this test when support for non-shared socket mode | 1050 // TODO(deadbeef): Remove this test when support for non-shared socket mode |
1089 // is removed. | 1051 // is removed. |
1090 TEST_F(PortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { | 1052 TEST_F(PortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { |
1091 AddInterface(kClientAddr); | 1053 AddInterface(kClientAddr); |
1092 // Use an empty SocketAddress to add a NAT without STUN server. | 1054 // Use an empty SocketAddress to add a NAT without STUN server. |
1093 ResetWithStunServerAndNat(SocketAddress()); | 1055 ResetWithStunServerAndNat(SocketAddress()); |
1094 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1056 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
1095 | 1057 |
1096 allocator_->set_flags(allocator().flags() | | 1058 allocator_->set_flags(allocator().flags() | |
1097 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | |
1098 cricket::PORTALLOCATOR_DISABLE_TCP); | 1059 cricket::PORTALLOCATOR_DISABLE_TCP); |
1099 | 1060 |
1100 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1061 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1101 session_->StartGettingPorts(); | 1062 session_->StartGettingPorts(); |
1102 | 1063 |
1103 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1064 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); |
1104 ASSERT_EQ(3U, ports_.size()); | 1065 ASSERT_EQ(3U, ports_.size()); |
1105 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1066 EXPECT_PRED5(CheckCandidate, candidates_[0], |
1106 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 1067 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
1107 kClientAddr); | 1068 kClientAddr); |
(...skipping 18 matching lines...) Expand all Loading... |
1126 // server is used as a STUN server and we get a 'stun' candidate. | 1087 // server is used as a STUN server and we get a 'stun' candidate. |
1127 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { | 1088 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { |
1128 AddInterface(kClientAddr); | 1089 AddInterface(kClientAddr); |
1129 // Configure with STUN server but destroy it, so we can ensure that it's | 1090 // Configure with STUN server but destroy it, so we can ensure that it's |
1130 // the TURN server actually being used as a STUN server. | 1091 // the TURN server actually being used as a STUN server. |
1131 ResetWithStunServerAndNat(kStunAddr); | 1092 ResetWithStunServerAndNat(kStunAddr); |
1132 stun_server_.reset(); | 1093 stun_server_.reset(); |
1133 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1094 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
1134 | 1095 |
1135 allocator_->set_flags(allocator().flags() | | 1096 allocator_->set_flags(allocator().flags() | |
1136 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | |
1137 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1097 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
1138 cricket::PORTALLOCATOR_DISABLE_TCP); | 1098 cricket::PORTALLOCATOR_DISABLE_TCP); |
1139 | 1099 |
1140 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1100 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1141 session_->StartGettingPorts(); | 1101 session_->StartGettingPorts(); |
1142 | 1102 |
1143 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1103 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); |
1144 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1104 EXPECT_PRED5(CheckCandidate, candidates_[0], |
1145 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 1105 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
1146 kClientAddr); | 1106 kClientAddr); |
1147 EXPECT_PRED5(CheckCandidate, candidates_[1], | 1107 EXPECT_PRED5(CheckCandidate, candidates_[1], |
1148 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", | 1108 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", |
1149 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); | 1109 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); |
1150 EXPECT_PRED5(CheckCandidate, candidates_[2], | 1110 EXPECT_PRED5(CheckCandidate, candidates_[2], |
1151 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 1111 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
1152 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1112 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
1153 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); | 1113 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); |
1154 | 1114 |
1155 // Don't bother waiting for STUN timeout, since we already verified | 1115 // Don't bother waiting for STUN timeout, since we already verified |
1156 // that we got a STUN candidate from the TURN server. | 1116 // that we got a STUN candidate from the TURN server. |
1157 } | 1117 } |
1158 | 1118 |
1159 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled | 1119 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled |
1160 // and fail to generate STUN candidate, local UDP candidate is generated | 1120 // and fail to generate STUN candidate, local UDP candidate is generated |
1161 // properly. | 1121 // properly. |
1162 TEST_F(PortAllocatorTest, TestSharedSocketNoUdpAllowed) { | 1122 TEST_F(PortAllocatorTest, TestSharedSocketNoUdpAllowed) { |
1163 allocator().set_flags(allocator().flags() | | 1123 allocator().set_flags(allocator().flags() | |
1164 cricket::PORTALLOCATOR_DISABLE_RELAY | | 1124 cricket::PORTALLOCATOR_DISABLE_RELAY | |
1165 cricket::PORTALLOCATOR_DISABLE_TCP | | 1125 cricket::PORTALLOCATOR_DISABLE_TCP | |
1166 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | |
1167 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1126 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1168 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); | 1127 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); |
1169 AddInterface(kClientAddr); | 1128 AddInterface(kClientAddr); |
1170 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1129 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1171 session_->StartGettingPorts(); | 1130 session_->StartGettingPorts(); |
1172 ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); | 1131 ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); |
1173 EXPECT_EQ(1U, candidates_.size()); | 1132 EXPECT_EQ(1U, candidates_.size()); |
1174 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1133 EXPECT_PRED5(CheckCandidate, candidates_[0], |
1175 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | 1134 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); |
1176 // STUN timeout is 9sec. We need to wait to get candidate done signal. | 1135 // STUN timeout is 9sec. We need to wait to get candidate done signal. |
1177 EXPECT_TRUE_WAIT(candidate_allocation_done_, 10000); | 1136 EXPECT_TRUE_WAIT(candidate_allocation_done_, 10000); |
1178 EXPECT_EQ(1U, candidates_.size()); | 1137 EXPECT_EQ(1U, candidates_.size()); |
1179 } | 1138 } |
1180 | 1139 |
1181 // Test that when the NetworkManager doesn't have permission to enumerate | 1140 // Test that when the NetworkManager doesn't have permission to enumerate |
1182 // adapters, the PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified | 1141 // adapters, the PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified |
1183 // automatically. | 1142 // automatically. |
1184 TEST_F(PortAllocatorTest, TestNetworkPermissionBlocked) { | 1143 TEST_F(PortAllocatorTest, TestNetworkPermissionBlocked) { |
1185 AddInterface(kClientAddr); | 1144 AddInterface(kClientAddr); |
1186 network_manager_.set_enumeration_permission( | 1145 network_manager_.set_enumeration_permission( |
1187 rtc::NetworkManager::ENUMERATION_BLOCKED); | 1146 rtc::NetworkManager::ENUMERATION_BLOCKED); |
1188 allocator().set_flags(allocator().flags() | | 1147 allocator().set_flags(allocator().flags() | |
1189 cricket::PORTALLOCATOR_DISABLE_RELAY | | 1148 cricket::PORTALLOCATOR_DISABLE_RELAY | |
1190 cricket::PORTALLOCATOR_DISABLE_TCP | | 1149 cricket::PORTALLOCATOR_DISABLE_TCP | |
1191 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | |
1192 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1150 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1193 EXPECT_EQ(0U, allocator_->flags() & | 1151 EXPECT_EQ(0U, allocator_->flags() & |
1194 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); | 1152 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); |
1195 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1153 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1196 EXPECT_EQ(0U, session_->flags() & | 1154 EXPECT_EQ(0U, session_->flags() & |
1197 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); | 1155 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); |
1198 session_->StartGettingPorts(); | 1156 session_->StartGettingPorts(); |
1199 EXPECT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); | 1157 EXPECT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); |
1200 EXPECT_EQ(0U, candidates_.size()); | 1158 EXPECT_EQ(0U, candidates_.size()); |
1201 EXPECT_TRUE((session_->flags() & | 1159 EXPECT_TRUE((session_->flags() & |
1202 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) != 0); | 1160 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) != 0); |
1203 } | 1161 } |
1204 | 1162 |
1205 // This test verifies allocator can use IPv6 addresses along with IPv4. | 1163 // This test verifies allocator can use IPv6 addresses along with IPv4. |
1206 TEST_F(PortAllocatorTest, TestEnableIPv6Addresses) { | 1164 TEST_F(PortAllocatorTest, TestEnableIPv6Addresses) { |
1207 allocator().set_flags(allocator().flags() | | 1165 allocator().set_flags(allocator().flags() | |
1208 cricket::PORTALLOCATOR_DISABLE_RELAY | | 1166 cricket::PORTALLOCATOR_DISABLE_RELAY | |
1209 cricket::PORTALLOCATOR_ENABLE_IPV6 | | 1167 cricket::PORTALLOCATOR_ENABLE_IPV6 | |
1210 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | | |
1211 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1168 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
1212 AddInterface(kClientIPv6Addr); | 1169 AddInterface(kClientIPv6Addr); |
1213 AddInterface(kClientAddr); | 1170 AddInterface(kClientAddr); |
1214 allocator_->set_step_delay(cricket::kMinimumStepDelay); | 1171 allocator_->set_step_delay(cricket::kMinimumStepDelay); |
1215 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1172 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
1216 session_->StartGettingPorts(); | 1173 session_->StartGettingPorts(); |
1217 ASSERT_EQ_WAIT(4U, ports_.size(), kDefaultAllocationTimeout); | 1174 ASSERT_EQ_WAIT(4U, ports_.size(), kDefaultAllocationTimeout); |
1218 EXPECT_EQ(4U, candidates_.size()); | 1175 EXPECT_EQ(4U, candidates_.size()); |
1219 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1176 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
1220 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1177 EXPECT_PRED5(CheckCandidate, candidates_[0], |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1259 alloc.SetStunHosts(stun_servers); | 1216 alloc.SetStunHosts(stun_servers); |
1260 EXPECT_EQ(2U, alloc.relay_hosts().size()); | 1217 EXPECT_EQ(2U, alloc.relay_hosts().size()); |
1261 EXPECT_EQ(2U, alloc.stun_hosts().size()); | 1218 EXPECT_EQ(2U, alloc.stun_hosts().size()); |
1262 } | 1219 } |
1263 | 1220 |
1264 // Test that the HttpPortAllocator uses correct URL to create sessions. | 1221 // Test that the HttpPortAllocator uses correct URL to create sessions. |
1265 TEST(HttpPortAllocatorTest, TestSessionRequestUrl) { | 1222 TEST(HttpPortAllocatorTest, TestSessionRequestUrl) { |
1266 rtc::FakeNetworkManager network_manager; | 1223 rtc::FakeNetworkManager network_manager; |
1267 cricket::HttpPortAllocator alloc(&network_manager, "unit test agent"); | 1224 cricket::HttpPortAllocator alloc(&network_manager, "unit test agent"); |
1268 | 1225 |
1269 // Disable PORTALLOCATOR_ENABLE_SHARED_UFRAG. | |
1270 alloc.set_flags(alloc.flags() & ~cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG); | |
1271 rtc::scoped_ptr<cricket::HttpPortAllocatorSessionBase> session( | 1226 rtc::scoped_ptr<cricket::HttpPortAllocatorSessionBase> session( |
1272 static_cast<cricket::HttpPortAllocatorSession*>( | 1227 static_cast<cricket::HttpPortAllocatorSession*>( |
1273 alloc.CreateSessionInternal( | 1228 alloc.CreateSessionInternal( |
1274 "test content", 0, kIceUfrag0, kIcePwd0))); | 1229 "test content", 0, kIceUfrag0, kIcePwd0))); |
1275 std::string url = session->GetSessionRequestUrl(); | 1230 std::string url = session->GetSessionRequestUrl(); |
1276 LOG(LS_INFO) << "url: " << url; | 1231 LOG(LS_INFO) << "url: " << url; |
1277 EXPECT_EQ(std::string(cricket::HttpPortAllocator::kCreateSessionURL), url); | |
1278 | |
1279 // Enable PORTALLOCATOR_ENABLE_SHARED_UFRAG. | |
1280 alloc.set_flags(alloc.flags() | cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG); | |
1281 session.reset(static_cast<cricket::HttpPortAllocatorSession*>( | |
1282 alloc.CreateSessionInternal("test content", 0, kIceUfrag0, kIcePwd0))); | |
1283 url = session->GetSessionRequestUrl(); | |
1284 LOG(LS_INFO) << "url: " << url; | |
1285 std::vector<std::string> parts; | 1232 std::vector<std::string> parts; |
1286 rtc::split(url, '?', &parts); | 1233 rtc::split(url, '?', &parts); |
1287 ASSERT_EQ(2U, parts.size()); | 1234 ASSERT_EQ(2U, parts.size()); |
1288 | 1235 |
1289 std::vector<std::string> args_parts; | 1236 std::vector<std::string> args_parts; |
1290 rtc::split(parts[1], '&', &args_parts); | 1237 rtc::split(parts[1], '&', &args_parts); |
1291 | 1238 |
1292 std::map<std::string, std::string> args; | 1239 std::map<std::string, std::string> args; |
1293 for (std::vector<std::string>::iterator it = args_parts.begin(); | 1240 for (std::vector<std::string>::iterator it = args_parts.begin(); |
1294 it != args_parts.end(); ++it) { | 1241 it != args_parts.end(); ++it) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 AllocationSequenceForTest alloc_sequence( | 1287 AllocationSequenceForTest alloc_sequence( |
1341 static_cast<cricket::BasicPortAllocatorSession*>(session_.get()), | 1288 static_cast<cricket::BasicPortAllocatorSession*>(session_.get()), |
1342 &network1, &config, flag); | 1289 &network1, &config, flag); |
1343 // This simply tests it will not crash if udp_socket_ in the | 1290 // This simply tests it will not crash if udp_socket_ in the |
1344 // AllocationSequence is null, which is chosen in the constructor. | 1291 // AllocationSequence is null, which is chosen in the constructor. |
1345 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); | 1292 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN); |
1346 relay_server.ports.push_back( | 1293 relay_server.ports.push_back( |
1347 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); | 1294 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); |
1348 alloc_sequence.CreateTurnPort(relay_server); | 1295 alloc_sequence.CreateTurnPort(relay_server); |
1349 } | 1296 } |
OLD | NEW |