Chromium Code Reviews| 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 */ |
|
Taylor Brandstetter
2016/05/05 19:56:23
Aside from OnPortReady, OnCandidatesReady, OnCandi
| |
| 10 | 10 |
| 11 #include <algorithm> | |
| 11 #include <memory> | 12 #include <memory> |
| 12 | 13 |
| 13 #include "webrtc/p2p/base/basicpacketsocketfactory.h" | 14 #include "webrtc/p2p/base/basicpacketsocketfactory.h" |
| 14 #include "webrtc/p2p/base/p2pconstants.h" | 15 #include "webrtc/p2p/base/p2pconstants.h" |
| 15 #include "webrtc/p2p/base/p2ptransportchannel.h" | 16 #include "webrtc/p2p/base/p2ptransportchannel.h" |
| 16 #include "webrtc/p2p/base/testrelayserver.h" | 17 #include "webrtc/p2p/base/testrelayserver.h" |
| 17 #include "webrtc/p2p/base/teststunserver.h" | 18 #include "webrtc/p2p/base/teststunserver.h" |
| 18 #include "webrtc/p2p/base/testturnserver.h" | 19 #include "webrtc/p2p/base/testturnserver.h" |
| 19 #include "webrtc/p2p/client/basicportallocator.h" | 20 #include "webrtc/p2p/client/basicportallocator.h" |
| 20 #include "webrtc/p2p/client/httpportallocator.h" | 21 #include "webrtc/p2p/client/httpportallocator.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 35 | 36 |
| 36 using cricket::ServerAddresses; | 37 using cricket::ServerAddresses; |
| 37 using rtc::IPAddress; | 38 using rtc::IPAddress; |
| 38 using rtc::SocketAddress; | 39 using rtc::SocketAddress; |
| 39 using rtc::Thread; | 40 using rtc::Thread; |
| 40 | 41 |
| 41 static const SocketAddress kClientAddr("11.11.11.11", 0); | 42 static const SocketAddress kClientAddr("11.11.11.11", 0); |
| 42 static const SocketAddress kLoopbackAddr("127.0.0.1", 0); | 43 static const SocketAddress kLoopbackAddr("127.0.0.1", 0); |
| 43 static const SocketAddress kPrivateAddr("192.168.1.11", 0); | 44 static const SocketAddress kPrivateAddr("192.168.1.11", 0); |
| 44 static const SocketAddress kPrivateAddr2("192.168.1.12", 0); | 45 static const SocketAddress kPrivateAddr2("192.168.1.12", 0); |
| 45 static const SocketAddress kClientIPv6Addr( | 46 static const SocketAddress kClientIPv6Addr("2401:fa00:4:1000:be30:5bff:fee5:c3", |
| 46 "2401:fa00:4:1000:be30:5bff:fee5:c3", 0); | 47 0); |
| 47 static const SocketAddress kClientAddr2("22.22.22.22", 0); | 48 static const SocketAddress kClientAddr2("22.22.22.22", 0); |
| 48 static const SocketAddress kNatUdpAddr("77.77.77.77", rtc::NAT_SERVER_UDP_PORT); | 49 static const SocketAddress kNatUdpAddr("77.77.77.77", rtc::NAT_SERVER_UDP_PORT); |
| 49 static const SocketAddress kNatTcpAddr("77.77.77.77", rtc::NAT_SERVER_TCP_PORT); | 50 static const SocketAddress kNatTcpAddr("77.77.77.77", rtc::NAT_SERVER_TCP_PORT); |
| 50 static const SocketAddress kRemoteClientAddr("22.22.22.22", 0); | 51 static const SocketAddress kRemoteClientAddr("22.22.22.22", 0); |
| 51 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT); | 52 static const SocketAddress kStunAddr("99.99.99.1", cricket::STUN_SERVER_PORT); |
| 52 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); | 53 static const SocketAddress kRelayUdpIntAddr("99.99.99.2", 5000); |
| 53 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); | 54 static const SocketAddress kRelayUdpExtAddr("99.99.99.3", 5001); |
| 54 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); | 55 static const SocketAddress kRelayTcpIntAddr("99.99.99.2", 5002); |
| 55 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); | 56 static const SocketAddress kRelayTcpExtAddr("99.99.99.3", 5003); |
| 56 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); | 57 static const SocketAddress kRelaySslTcpIntAddr("99.99.99.2", 5004); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 77 namespace cricket { | 78 namespace cricket { |
| 78 | 79 |
| 79 // Helper for dumping candidates | 80 // Helper for dumping candidates |
| 80 std::ostream& operator<<(std::ostream& os, const cricket::Candidate& c) { | 81 std::ostream& operator<<(std::ostream& os, const cricket::Candidate& c) { |
| 81 os << c.ToString(); | 82 os << c.ToString(); |
| 82 return os; | 83 return os; |
| 83 } | 84 } |
| 84 | 85 |
| 85 } // namespace cricket | 86 } // namespace cricket |
| 86 | 87 |
| 87 class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> { | 88 class BasicPortAllocatorTest : public testing::Test, |
| 89 public sigslot::has_slots<> { | |
| 88 public: | 90 public: |
| 89 PortAllocatorTest() | 91 BasicPortAllocatorTest() |
| 90 : pss_(new rtc::PhysicalSocketServer), | 92 : pss_(new rtc::PhysicalSocketServer), |
| 91 vss_(new rtc::VirtualSocketServer(pss_.get())), | 93 vss_(new rtc::VirtualSocketServer(pss_.get())), |
| 92 fss_(new rtc::FirewallSocketServer(vss_.get())), | 94 fss_(new rtc::FirewallSocketServer(vss_.get())), |
| 93 ss_scope_(fss_.get()), | 95 ss_scope_(fss_.get()), |
| 94 nat_factory_(vss_.get(), kNatUdpAddr, kNatTcpAddr), | 96 nat_factory_(vss_.get(), kNatUdpAddr, kNatTcpAddr), |
| 95 nat_socket_factory_(new rtc::BasicPacketSocketFactory(&nat_factory_)), | 97 nat_socket_factory_(new rtc::BasicPacketSocketFactory(&nat_factory_)), |
| 96 stun_server_(cricket::TestStunServer::Create(Thread::Current(), | 98 stun_server_( |
| 97 kStunAddr)), | 99 cricket::TestStunServer::Create(Thread::Current(), kStunAddr)), |
| 98 relay_server_(Thread::Current(), kRelayUdpIntAddr, kRelayUdpExtAddr, | 100 relay_server_(Thread::Current(), |
| 99 kRelayTcpIntAddr, kRelayTcpExtAddr, | 101 kRelayUdpIntAddr, |
| 100 kRelaySslTcpIntAddr, kRelaySslTcpExtAddr), | 102 kRelayUdpExtAddr, |
| 103 kRelayTcpIntAddr, | |
| 104 kRelayTcpExtAddr, | |
| 105 kRelaySslTcpIntAddr, | |
| 106 kRelaySslTcpExtAddr), | |
| 101 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr), | 107 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr), |
| 102 candidate_allocation_done_(false) { | 108 candidate_allocation_done_(false) { |
| 103 cricket::ServerAddresses stun_servers; | 109 cricket::ServerAddresses stun_servers; |
| 104 stun_servers.insert(kStunAddr); | 110 stun_servers.insert(kStunAddr); |
| 105 // Passing the addresses of GTURN servers will enable GTURN in | 111 // Passing the addresses of GTURN servers will enable GTURN in |
| 106 // Basicportallocator. | 112 // Basicportallocator. |
| 107 allocator_.reset(new cricket::BasicPortAllocator( | 113 allocator_.reset(new cricket::BasicPortAllocator( |
| 108 &network_manager_, | 114 &network_manager_, stun_servers, kRelayUdpIntAddr, kRelayTcpIntAddr, |
| 109 stun_servers, | 115 kRelaySslTcpIntAddr)); |
| 110 kRelayUdpIntAddr, kRelayTcpIntAddr, kRelaySslTcpIntAddr)); | |
| 111 allocator_->set_step_delay(cricket::kMinimumStepDelay); | 116 allocator_->set_step_delay(cricket::kMinimumStepDelay); |
| 112 } | 117 } |
| 113 | 118 |
| 114 void AddInterface(const SocketAddress& addr) { | 119 void AddInterface(const SocketAddress& addr) { |
| 115 network_manager_.AddInterface(addr); | 120 network_manager_.AddInterface(addr); |
| 116 } | 121 } |
| 117 void AddInterface(const SocketAddress& addr, const std::string& if_name) { | 122 void AddInterface(const SocketAddress& addr, const std::string& if_name) { |
| 118 network_manager_.AddInterface(addr, if_name); | 123 network_manager_.AddInterface(addr, if_name); |
| 119 } | 124 } |
| 120 void AddInterface(const SocketAddress& addr, | 125 void AddInterface(const SocketAddress& addr, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 return true; | 189 return true; |
| 185 } | 190 } |
| 186 | 191 |
| 187 bool CreateSession(int component, const std::string& content_name) { | 192 bool CreateSession(int component, const std::string& content_name) { |
| 188 session_.reset(CreateSession("session", content_name, component)); | 193 session_.reset(CreateSession("session", content_name, component)); |
| 189 if (!session_) | 194 if (!session_) |
| 190 return false; | 195 return false; |
| 191 return true; | 196 return true; |
| 192 } | 197 } |
| 193 | 198 |
| 194 cricket::PortAllocatorSession* CreateSession( | 199 cricket::PortAllocatorSession* CreateSession(const std::string& sid, |
| 195 const std::string& sid, int component) { | 200 int component) { |
| 196 return CreateSession(sid, kContentName, component); | 201 return CreateSession(sid, kContentName, component); |
| 197 } | 202 } |
| 198 | 203 |
| 199 cricket::PortAllocatorSession* CreateSession( | 204 cricket::PortAllocatorSession* CreateSession(const std::string& sid, |
| 200 const std::string& sid, const std::string& content_name, int component) { | 205 const std::string& content_name, |
| 206 int component) { | |
| 201 return CreateSession(sid, content_name, component, kIceUfrag0, kIcePwd0); | 207 return CreateSession(sid, content_name, component, kIceUfrag0, kIcePwd0); |
| 202 } | 208 } |
| 203 | 209 |
| 204 cricket::PortAllocatorSession* CreateSession( | 210 cricket::PortAllocatorSession* CreateSession(const std::string& sid, |
| 205 const std::string& sid, const std::string& content_name, int component, | 211 const std::string& content_name, |
| 206 const std::string& ice_ufrag, const std::string& ice_pwd) { | 212 int component, |
| 207 cricket::PortAllocatorSession* session = | 213 const std::string& ice_ufrag, |
| 208 allocator_->CreateSession( | 214 const std::string& ice_pwd) { |
| 209 sid, content_name, component, ice_ufrag, ice_pwd); | 215 cricket::PortAllocatorSession* session = allocator_->CreateSession( |
| 216 sid, content_name, component, ice_ufrag, ice_pwd); | |
| 210 session->SignalPortReady.connect(this, | 217 session->SignalPortReady.connect(this, |
| 211 &PortAllocatorTest::OnPortReady); | 218 &BasicPortAllocatorTest::OnPortReady); |
| 212 session->SignalCandidatesReady.connect(this, | 219 session->SignalCandidatesReady.connect( |
| 213 &PortAllocatorTest::OnCandidatesReady); | 220 this, &BasicPortAllocatorTest::OnCandidatesReady); |
| 214 session->SignalCandidatesAllocationDone.connect(this, | 221 session->SignalCandidatesAllocationDone.connect( |
| 215 &PortAllocatorTest::OnCandidatesAllocationDone); | 222 this, &BasicPortAllocatorTest::OnCandidatesAllocationDone); |
| 216 return session; | 223 return session; |
| 217 } | 224 } |
| 218 | 225 |
| 219 static bool CheckCandidate(const cricket::Candidate& c, | 226 static bool CheckCandidate(const cricket::Candidate& c, |
| 220 int component, const std::string& type, | 227 int component, |
| 228 const std::string& type, | |
| 221 const std::string& proto, | 229 const std::string& proto, |
| 222 const SocketAddress& addr) { | 230 const SocketAddress& addr) { |
| 223 return (c.component() == component && c.type() == type && | 231 return (c.component() == component && c.type() == type && |
| 224 c.protocol() == proto && c.address().ipaddr() == addr.ipaddr() && | 232 c.protocol() == proto && c.address().ipaddr() == addr.ipaddr() && |
| 225 ((addr.port() == 0 && (c.address().port() != 0)) || | 233 ((addr.port() == 0 && (c.address().port() != 0)) || |
| 226 (c.address().port() == addr.port()))); | 234 (c.address().port() == addr.port()))); |
| 227 } | 235 } |
| 228 static bool CheckPort(const rtc::SocketAddress& addr, | 236 static bool CheckPort(const rtc::SocketAddress& addr, |
| 229 int min_port, int max_port) { | 237 int min_port, |
| 238 int max_port) { | |
| 230 return (addr.port() >= min_port && addr.port() <= max_port); | 239 return (addr.port() >= min_port && addr.port() <= max_port); |
| 231 } | 240 } |
| 232 | 241 |
| 233 void OnCandidatesAllocationDone(cricket::PortAllocatorSession* session) { | 242 void OnCandidatesAllocationDone(cricket::PortAllocatorSession* session) { |
| 234 // We should only get this callback once, except in the mux test where | 243 // We should only get this callback once, except in the mux test where |
| 235 // we have multiple port allocation sessions. | 244 // we have multiple port allocation sessions. |
| 236 if (session == session_.get()) { | 245 if (session == session_.get()) { |
| 237 ASSERT_FALSE(candidate_allocation_done_); | 246 ASSERT_FALSE(candidate_allocation_done_); |
| 238 candidate_allocation_done_ = true; | 247 candidate_allocation_done_ = true; |
| 239 } | 248 } |
| 249 EXPECT_TRUE(session->CandidatesAllocationDone()); | |
| 240 } | 250 } |
| 241 | 251 |
| 242 // Check if all ports allocated have send-buffer size |expected|. If | 252 // Check if all ports allocated have send-buffer size |expected|. If |
| 243 // |expected| == -1, check if GetOptions returns SOCKET_ERROR. | 253 // |expected| == -1, check if GetOptions returns SOCKET_ERROR. |
| 244 void CheckSendBufferSizesOfAllPorts(int expected) { | 254 void CheckSendBufferSizesOfAllPorts(int expected) { |
| 245 std::vector<cricket::PortInterface*>::iterator it; | 255 std::vector<cricket::PortInterface*>::iterator it; |
| 246 for (it = ports_.begin(); it < ports_.end(); ++it) { | 256 for (it = ports_.begin(); it < ports_.end(); ++it) { |
| 247 int send_buffer_size; | 257 int send_buffer_size; |
| 248 if (expected == -1) { | 258 if (expected == -1) { |
| 249 EXPECT_EQ(SOCKET_ERROR, | 259 EXPECT_EQ(SOCKET_ERROR, |
| 250 (*it)->GetOption(rtc::Socket::OPT_SNDBUF, | 260 (*it)->GetOption(rtc::Socket::OPT_SNDBUF, &send_buffer_size)); |
| 251 &send_buffer_size)); | |
| 252 } else { | 261 } else { |
| 253 EXPECT_EQ(0, (*it)->GetOption(rtc::Socket::OPT_SNDBUF, | 262 EXPECT_EQ(0, |
| 254 &send_buffer_size)); | 263 (*it)->GetOption(rtc::Socket::OPT_SNDBUF, &send_buffer_size)); |
| 255 ASSERT_EQ(expected, send_buffer_size); | 264 ASSERT_EQ(expected, send_buffer_size); |
| 256 } | 265 } |
| 257 } | 266 } |
| 258 } | 267 } |
| 259 | 268 |
| 260 // This function starts the port/address gathering and check the existence of | 269 // This function starts the port/address gathering and check the existence of |
| 261 // candidates as specified. When |expect_stun_candidate| is true, | 270 // candidates as specified. When |expect_stun_candidate| is true, |
| 262 // |stun_candidate_addr| carries the expected reflective address, which is | 271 // |stun_candidate_addr| carries the expected reflective address, which is |
| 263 // also the related address for TURN candidate if it is expected. Otherwise, | 272 // also the related address for TURN candidate if it is expected. Otherwise, |
| 264 // it should be ignore. | 273 // it should be ignore. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 EXPECT_EQ(stun_candidate_addr, | 324 EXPECT_EQ(stun_candidate_addr, |
| 316 candidates_[total_candidates].related_address().ipaddr()); | 325 candidates_[total_candidates].related_address().ipaddr()); |
| 317 ++total_candidates; | 326 ++total_candidates; |
| 318 } | 327 } |
| 319 | 328 |
| 320 EXPECT_EQ(total_candidates, candidates_.size()); | 329 EXPECT_EQ(total_candidates, candidates_.size()); |
| 321 EXPECT_EQ(total_ports, ports_.size()); | 330 EXPECT_EQ(total_ports, ports_.size()); |
| 322 } | 331 } |
| 323 | 332 |
| 324 protected: | 333 protected: |
| 325 cricket::BasicPortAllocator& allocator() { | 334 cricket::BasicPortAllocator& allocator() { return *allocator_; } |
| 326 return *allocator_; | |
| 327 } | |
| 328 | 335 |
| 329 void OnPortReady(cricket::PortAllocatorSession* ses, | 336 void OnPortReady(cricket::PortAllocatorSession* ses, |
| 330 cricket::PortInterface* port) { | 337 cricket::PortInterface* port) { |
| 331 LOG(LS_INFO) << "OnPortReady: " << port->ToString(); | 338 LOG(LS_INFO) << "OnPortReady: " << port->ToString(); |
| 332 ports_.push_back(port); | 339 ports_.push_back(port); |
| 340 // Make sure the new port is added to ReadyPorts. | |
| 341 auto ready_ports = ses->ReadyPorts(); | |
| 342 EXPECT_NE(ready_ports.end(), | |
| 343 std::find(ready_ports.begin(), ready_ports.end(), port)); | |
| 333 } | 344 } |
| 334 void OnCandidatesReady(cricket::PortAllocatorSession* ses, | 345 void OnCandidatesReady(cricket::PortAllocatorSession* ses, |
| 335 const std::vector<cricket::Candidate>& candidates) { | 346 const std::vector<cricket::Candidate>& candidates) { |
| 336 for (size_t i = 0; i < candidates.size(); ++i) { | 347 for (size_t i = 0; i < candidates.size(); ++i) { |
| 337 LOG(LS_INFO) << "OnCandidatesReady: " << candidates[i].ToString(); | 348 LOG(LS_INFO) << "OnCandidatesReady: " << candidates[i].ToString(); |
| 338 candidates_.push_back(candidates[i]); | 349 candidates_.push_back(candidates[i]); |
| 339 } | 350 } |
| 351 // Make sure the new candidates are added to Candidates. | |
| 352 auto ses_candidates = ses->ReadyCandidates(); | |
| 353 for (const cricket::Candidate& candidate : candidates) { | |
| 354 EXPECT_NE( | |
| 355 ses_candidates.end(), | |
| 356 std::find(ses_candidates.begin(), ses_candidates.end(), candidate)); | |
| 357 } | |
| 340 } | 358 } |
| 341 | 359 |
| 342 bool HasRelayAddress(const cricket::ProtocolAddress& proto_addr) { | 360 bool HasRelayAddress(const cricket::ProtocolAddress& proto_addr) { |
| 343 for (size_t i = 0; i < allocator_->turn_servers().size(); ++i) { | 361 for (size_t i = 0; i < allocator_->turn_servers().size(); ++i) { |
| 344 cricket::RelayServerConfig server_config = allocator_->turn_servers()[i]; | 362 cricket::RelayServerConfig server_config = allocator_->turn_servers()[i]; |
| 345 cricket::PortList::const_iterator relay_port; | 363 cricket::PortList::const_iterator relay_port; |
| 346 for (relay_port = server_config.ports.begin(); | 364 for (relay_port = server_config.ports.begin(); |
| 347 relay_port != server_config.ports.end(); ++relay_port) { | 365 relay_port != server_config.ports.end(); ++relay_port) { |
| 348 if (proto_addr.address == relay_port->address && | 366 if (proto_addr.address == relay_port->address && |
| 349 proto_addr.proto == relay_port->proto) | 367 proto_addr.proto == relay_port->proto) |
| 350 return true; | 368 return true; |
| 351 } | 369 } |
| 352 } | 370 } |
| 353 return false; | 371 return false; |
| 354 } | 372 } |
| 355 | 373 |
| 356 void ResetWithStunServer(const rtc::SocketAddress& stun_server, | 374 void ResetWithStunServer(const rtc::SocketAddress& stun_server, |
| 357 bool with_nat) { | 375 bool with_nat) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 384 cricket::TestTurnServer turn_server_; | 402 cricket::TestTurnServer turn_server_; |
| 385 rtc::FakeNetworkManager network_manager_; | 403 rtc::FakeNetworkManager network_manager_; |
| 386 std::unique_ptr<cricket::BasicPortAllocator> allocator_; | 404 std::unique_ptr<cricket::BasicPortAllocator> allocator_; |
| 387 std::unique_ptr<cricket::PortAllocatorSession> session_; | 405 std::unique_ptr<cricket::PortAllocatorSession> session_; |
| 388 std::vector<cricket::PortInterface*> ports_; | 406 std::vector<cricket::PortInterface*> ports_; |
| 389 std::vector<cricket::Candidate> candidates_; | 407 std::vector<cricket::Candidate> candidates_; |
| 390 bool candidate_allocation_done_; | 408 bool candidate_allocation_done_; |
| 391 }; | 409 }; |
| 392 | 410 |
| 393 // Tests that we can init the port allocator and create a session. | 411 // Tests that we can init the port allocator and create a session. |
| 394 TEST_F(PortAllocatorTest, TestBasic) { | 412 TEST_F(BasicPortAllocatorTest, TestBasic) { |
| 395 EXPECT_EQ(&network_manager_, allocator().network_manager()); | 413 EXPECT_EQ(&network_manager_, allocator().network_manager()); |
| 396 EXPECT_EQ(kStunAddr, *allocator().stun_servers().begin()); | 414 EXPECT_EQ(kStunAddr, *allocator().stun_servers().begin()); |
| 397 ASSERT_EQ(1u, allocator().turn_servers().size()); | 415 ASSERT_EQ(1u, allocator().turn_servers().size()); |
| 398 EXPECT_EQ(cricket::RELAY_GTURN, allocator().turn_servers()[0].type); | 416 EXPECT_EQ(cricket::RELAY_GTURN, allocator().turn_servers()[0].type); |
| 399 // Empty relay credentials are used for GTURN. | 417 // Empty relay credentials are used for GTURN. |
| 400 EXPECT_TRUE(allocator().turn_servers()[0].credentials.username.empty()); | 418 EXPECT_TRUE(allocator().turn_servers()[0].credentials.username.empty()); |
| 401 EXPECT_TRUE(allocator().turn_servers()[0].credentials.password.empty()); | 419 EXPECT_TRUE(allocator().turn_servers()[0].credentials.password.empty()); |
| 402 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress( | 420 EXPECT_TRUE(HasRelayAddress( |
| 403 kRelayUdpIntAddr, cricket::PROTO_UDP))); | 421 cricket::ProtocolAddress(kRelayUdpIntAddr, cricket::PROTO_UDP))); |
| 404 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress( | 422 EXPECT_TRUE(HasRelayAddress( |
| 405 kRelayTcpIntAddr, cricket::PROTO_TCP))); | 423 cricket::ProtocolAddress(kRelayTcpIntAddr, cricket::PROTO_TCP))); |
| 406 EXPECT_TRUE(HasRelayAddress(cricket::ProtocolAddress( | 424 EXPECT_TRUE(HasRelayAddress( |
| 407 kRelaySslTcpIntAddr, cricket::PROTO_SSLTCP))); | 425 cricket::ProtocolAddress(kRelaySslTcpIntAddr, cricket::PROTO_SSLTCP))); |
| 408 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 426 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 427 EXPECT_FALSE(session_->CandidatesAllocationDone()); | |
| 409 } | 428 } |
| 410 | 429 |
| 411 // Tests that our network filtering works properly. | 430 // Tests that our network filtering works properly. |
| 412 TEST_F(PortAllocatorTest, TestIgnoreOnlyLoopbackNetworkByDefault) { | 431 TEST_F(BasicPortAllocatorTest, TestIgnoreOnlyLoopbackNetworkByDefault) { |
| 413 AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0", | 432 AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0", |
| 414 rtc::ADAPTER_TYPE_ETHERNET); | 433 rtc::ADAPTER_TYPE_ETHERNET); |
| 415 AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0", | 434 AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0", |
| 416 rtc::ADAPTER_TYPE_WIFI); | 435 rtc::ADAPTER_TYPE_WIFI); |
| 417 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", | 436 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", |
| 418 rtc::ADAPTER_TYPE_CELLULAR); | 437 rtc::ADAPTER_TYPE_CELLULAR); |
| 419 AddInterface(SocketAddress(IPAddress(0x12345603U), 0), "test_vpn0", | 438 AddInterface(SocketAddress(IPAddress(0x12345603U), 0), "test_vpn0", |
| 420 rtc::ADAPTER_TYPE_VPN); | 439 rtc::ADAPTER_TYPE_VPN); |
| 421 AddInterface(SocketAddress(IPAddress(0x12345604U), 0), "test_lo", | 440 AddInterface(SocketAddress(IPAddress(0x12345604U), 0), "test_lo", |
| 422 rtc::ADAPTER_TYPE_LOOPBACK); | 441 rtc::ADAPTER_TYPE_LOOPBACK); |
| 423 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 442 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 424 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | | 443 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | |
| 425 cricket::PORTALLOCATOR_DISABLE_RELAY | | 444 cricket::PORTALLOCATOR_DISABLE_RELAY | |
| 426 cricket::PORTALLOCATOR_DISABLE_TCP); | 445 cricket::PORTALLOCATOR_DISABLE_TCP); |
| 427 session_->StartGettingPorts(); | 446 session_->StartGettingPorts(); |
| 428 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 447 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 429 EXPECT_EQ(4U, candidates_.size()); | 448 EXPECT_EQ(4U, candidates_.size()); |
| 430 for (cricket::Candidate candidate : candidates_) { | 449 for (cricket::Candidate candidate : candidates_) { |
| 431 EXPECT_LT(candidate.address().ip(), 0x12345604U); | 450 EXPECT_LT(candidate.address().ip(), 0x12345604U); |
| 432 } | 451 } |
| 433 } | 452 } |
| 434 | 453 |
| 435 TEST_F(PortAllocatorTest, TestIgnoreNetworksAccordingToIgnoreMask) { | 454 TEST_F(BasicPortAllocatorTest, TestIgnoreNetworksAccordingToIgnoreMask) { |
| 436 AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0", | 455 AddInterface(SocketAddress(IPAddress(0x12345600U), 0), "test_eth0", |
| 437 rtc::ADAPTER_TYPE_ETHERNET); | 456 rtc::ADAPTER_TYPE_ETHERNET); |
| 438 AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0", | 457 AddInterface(SocketAddress(IPAddress(0x12345601U), 0), "test_wlan0", |
| 439 rtc::ADAPTER_TYPE_WIFI); | 458 rtc::ADAPTER_TYPE_WIFI); |
| 440 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", | 459 AddInterface(SocketAddress(IPAddress(0x12345602U), 0), "test_cell0", |
| 441 rtc::ADAPTER_TYPE_CELLULAR); | 460 rtc::ADAPTER_TYPE_CELLULAR); |
| 442 allocator_->SetNetworkIgnoreMask(rtc::ADAPTER_TYPE_ETHERNET | | 461 allocator_->SetNetworkIgnoreMask(rtc::ADAPTER_TYPE_ETHERNET | |
| 443 rtc::ADAPTER_TYPE_LOOPBACK | | 462 rtc::ADAPTER_TYPE_LOOPBACK | |
| 444 rtc::ADAPTER_TYPE_WIFI); | 463 rtc::ADAPTER_TYPE_WIFI); |
| 445 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 464 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 446 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | | 465 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | |
| 447 cricket::PORTALLOCATOR_DISABLE_RELAY | | 466 cricket::PORTALLOCATOR_DISABLE_RELAY | |
| 448 cricket::PORTALLOCATOR_DISABLE_TCP); | 467 cricket::PORTALLOCATOR_DISABLE_TCP); |
| 449 session_->StartGettingPorts(); | 468 session_->StartGettingPorts(); |
| 450 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 469 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 451 EXPECT_EQ(1U, candidates_.size()); | 470 EXPECT_EQ(1U, candidates_.size()); |
| 452 EXPECT_EQ(0x12345602U, candidates_[0].address().ip()); | 471 EXPECT_EQ(0x12345602U, candidates_[0].address().ip()); |
| 453 } | 472 } |
| 454 | 473 |
| 455 // Tests that we allocator session not trying to allocate ports for every 250ms. | 474 // Tests that we allocator session not trying to allocate ports for every 250ms. |
| 456 TEST_F(PortAllocatorTest, TestNoNetworkInterface) { | 475 TEST_F(BasicPortAllocatorTest, TestNoNetworkInterface) { |
| 457 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 476 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 458 session_->StartGettingPorts(); | 477 session_->StartGettingPorts(); |
| 459 // Waiting for one second to make sure BasicPortAllocatorSession has not | 478 // Waiting for one second to make sure BasicPortAllocatorSession has not |
| 460 // called OnAllocate multiple times. In old behavior it's called every 250ms. | 479 // called OnAllocate multiple times. In old behavior it's called every 250ms. |
| 461 // When there are no network interfaces, each execution of OnAllocate will | 480 // When there are no network interfaces, each execution of OnAllocate will |
| 462 // result in SignalCandidatesAllocationDone signal. | 481 // result in SignalCandidatesAllocationDone signal. |
| 463 rtc::Thread::Current()->ProcessMessages(1000); | 482 rtc::Thread::Current()->ProcessMessages(1000); |
| 464 EXPECT_TRUE(candidate_allocation_done_); | 483 EXPECT_TRUE(candidate_allocation_done_); |
| 465 EXPECT_EQ(0U, candidates_.size()); | 484 EXPECT_EQ(0U, candidates_.size()); |
| 466 } | 485 } |
| 467 | 486 |
| 468 // Test that we could use loopback interface as host candidate. | 487 // Test that we could use loopback interface as host candidate. |
| 469 TEST_F(PortAllocatorTest, TestLoopbackNetworkInterface) { | 488 TEST_F(BasicPortAllocatorTest, TestLoopbackNetworkInterface) { |
| 470 AddInterface(kLoopbackAddr, "test_loopback", rtc::ADAPTER_TYPE_LOOPBACK); | 489 AddInterface(kLoopbackAddr, "test_loopback", rtc::ADAPTER_TYPE_LOOPBACK); |
| 471 allocator_->SetNetworkIgnoreMask(0); | 490 allocator_->SetNetworkIgnoreMask(0); |
| 472 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 491 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 473 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | | 492 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | |
| 474 cricket::PORTALLOCATOR_DISABLE_RELAY | | 493 cricket::PORTALLOCATOR_DISABLE_RELAY | |
| 475 cricket::PORTALLOCATOR_DISABLE_TCP); | 494 cricket::PORTALLOCATOR_DISABLE_TCP); |
| 476 session_->StartGettingPorts(); | 495 session_->StartGettingPorts(); |
| 477 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 496 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 478 EXPECT_EQ(1U, candidates_.size()); | 497 EXPECT_EQ(1U, candidates_.size()); |
| 479 } | 498 } |
| 480 | 499 |
| 481 // Tests that we can get all the desired addresses successfully. | 500 // Tests that we can get all the desired addresses successfully. |
| 482 TEST_F(PortAllocatorTest, TestGetAllPortsWithMinimumStepDelay) { | 501 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithMinimumStepDelay) { |
| 483 AddInterface(kClientAddr); | 502 AddInterface(kClientAddr); |
| 484 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 503 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 485 session_->StartGettingPorts(); | 504 session_->StartGettingPorts(); |
| 486 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 505 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
| 487 EXPECT_EQ(4U, ports_.size()); | 506 EXPECT_EQ(4U, ports_.size()); |
| 488 EXPECT_PRED5(CheckCandidate, candidates_[0], | 507 EXPECT_PRED5(CheckCandidate, candidates_[0], |
| 489 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | 508 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
| 509 kClientAddr); | |
| 490 EXPECT_PRED5(CheckCandidate, candidates_[1], | 510 EXPECT_PRED5(CheckCandidate, candidates_[1], |
| 491 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", kClientAddr); | 511 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", |
| 512 kClientAddr); | |
| 492 EXPECT_PRED5(CheckCandidate, candidates_[2], | 513 EXPECT_PRED5(CheckCandidate, candidates_[2], |
| 493 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", kRelayUdpIntAddr); | 514 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
| 515 kRelayUdpIntAddr); | |
| 494 EXPECT_PRED5(CheckCandidate, candidates_[3], | 516 EXPECT_PRED5(CheckCandidate, candidates_[3], |
| 495 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", kRelayUdpExtAddr); | 517 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
| 518 kRelayUdpExtAddr); | |
| 496 EXPECT_PRED5(CheckCandidate, candidates_[4], | 519 EXPECT_PRED5(CheckCandidate, candidates_[4], |
| 497 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", kRelayTcpIntAddr); | 520 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", |
| 521 kRelayTcpIntAddr); | |
| 498 EXPECT_PRED5(CheckCandidate, candidates_[5], | 522 EXPECT_PRED5(CheckCandidate, candidates_[5], |
| 499 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr); | 523 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", |
| 524 kClientAddr); | |
| 500 EXPECT_PRED5(CheckCandidate, candidates_[6], | 525 EXPECT_PRED5(CheckCandidate, candidates_[6], |
| 501 cricket::ICE_CANDIDATE_COMPONENT_RTP, | 526 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "ssltcp", |
| 502 "relay", "ssltcp", kRelaySslTcpIntAddr); | 527 kRelaySslTcpIntAddr); |
| 503 EXPECT_TRUE(candidate_allocation_done_); | 528 EXPECT_TRUE(candidate_allocation_done_); |
| 504 } | 529 } |
| 505 | 530 |
| 506 // Test that when the same network interface is brought down and up, the | 531 // Test that when the same network interface is brought down and up, the |
| 507 // port allocator session will restart a new allocation sequence if | 532 // port allocator session will restart a new allocation sequence if |
| 508 // it is not stopped. | 533 // it is not stopped. |
| 509 TEST_F(PortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) { | 534 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) { |
| 510 std::string if_name("test_net0"); | 535 std::string if_name("test_net0"); |
| 511 AddInterface(kClientAddr, if_name); | 536 AddInterface(kClientAddr, if_name); |
| 512 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 537 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 513 session_->StartGettingPorts(); | 538 session_->StartGettingPorts(); |
| 514 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 539 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
| 515 EXPECT_EQ(4U, ports_.size()); | 540 EXPECT_EQ(4U, ports_.size()); |
| 516 EXPECT_TRUE(candidate_allocation_done_); | 541 EXPECT_TRUE(candidate_allocation_done_); |
| 517 candidate_allocation_done_ = false; | 542 candidate_allocation_done_ = false; |
| 518 candidates_.clear(); | 543 candidates_.clear(); |
| 519 ports_.clear(); | 544 ports_.clear(); |
| 520 | 545 |
| 521 RemoveInterface(kClientAddr); | 546 RemoveInterface(kClientAddr); |
| 522 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); | 547 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); |
| 523 EXPECT_EQ(0U, ports_.size()); | 548 EXPECT_EQ(0U, ports_.size()); |
| 524 EXPECT_FALSE(candidate_allocation_done_); | 549 EXPECT_FALSE(candidate_allocation_done_); |
| 525 | 550 |
| 526 // When the same interfaces are added again, new candidates/ports should be | 551 // When the same interfaces are added again, new candidates/ports should be |
| 527 // generated. | 552 // generated. |
| 528 AddInterface(kClientAddr, if_name); | 553 AddInterface(kClientAddr, if_name); |
| 529 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 554 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
| 530 EXPECT_EQ(4U, ports_.size()); | 555 EXPECT_EQ(4U, ports_.size()); |
| 531 EXPECT_TRUE(candidate_allocation_done_); | 556 EXPECT_TRUE(candidate_allocation_done_); |
| 532 } | 557 } |
| 533 | 558 |
| 534 // Test that when the same network interface is brought down and up, the | 559 // Test that when the same network interface is brought down and up, the |
| 535 // port allocator session will not restart a new allocation sequence if | 560 // port allocator session will not restart a new allocation sequence if |
| 536 // it is stopped. | 561 // it is stopped. |
| 537 TEST_F(PortAllocatorTest, TestSameNetworkDownAndUpWhenSessionStopped) { | 562 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionStopped) { |
| 538 std::string if_name("test_net0"); | 563 std::string if_name("test_net0"); |
| 539 AddInterface(kClientAddr, if_name); | 564 AddInterface(kClientAddr, if_name); |
| 540 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 565 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 541 session_->StartGettingPorts(); | 566 session_->StartGettingPorts(); |
| 542 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 567 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
| 543 EXPECT_EQ(4U, ports_.size()); | 568 EXPECT_EQ(4U, ports_.size()); |
| 544 EXPECT_TRUE(candidate_allocation_done_); | 569 EXPECT_TRUE(candidate_allocation_done_); |
| 545 session_->StopGettingPorts(); | 570 session_->StopGettingPorts(); |
| 546 candidates_.clear(); | 571 candidates_.clear(); |
| 547 ports_.clear(); | 572 ports_.clear(); |
| 548 | 573 |
| 549 RemoveInterface(kClientAddr); | 574 RemoveInterface(kClientAddr); |
| 550 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); | 575 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); |
| 551 EXPECT_EQ(0U, ports_.size()); | 576 EXPECT_EQ(0U, ports_.size()); |
| 552 | 577 |
| 553 // When the same interfaces are added again, new candidates/ports should not | 578 // When the same interfaces are added again, new candidates/ports should not |
| 554 // be generated because the session has stopped. | 579 // be generated because the session has stopped. |
| 555 AddInterface(kClientAddr, if_name); | 580 AddInterface(kClientAddr, if_name); |
| 556 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); | 581 ASSERT_EQ_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout); |
| 557 EXPECT_EQ(0U, ports_.size()); | 582 EXPECT_EQ(0U, ports_.size()); |
| 558 EXPECT_TRUE(candidate_allocation_done_); | 583 EXPECT_TRUE(candidate_allocation_done_); |
| 559 } | 584 } |
| 560 | 585 |
| 561 // Verify candidates with default step delay of 1sec. | 586 // Verify candidates with default step delay of 1sec. |
| 562 TEST_F(PortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { | 587 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { |
| 563 AddInterface(kClientAddr); | 588 AddInterface(kClientAddr); |
| 564 allocator_->set_step_delay(cricket::kDefaultStepDelay); | 589 allocator_->set_step_delay(cricket::kDefaultStepDelay); |
| 565 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 590 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 566 session_->StartGettingPorts(); | 591 session_->StartGettingPorts(); |
| 567 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 592 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); |
| 568 EXPECT_EQ(2U, ports_.size()); | 593 EXPECT_EQ(2U, ports_.size()); |
| 569 ASSERT_EQ_WAIT(4U, candidates_.size(), 2000); | 594 ASSERT_EQ_WAIT(4U, candidates_.size(), 2000); |
| 570 EXPECT_EQ(3U, ports_.size()); | 595 EXPECT_EQ(3U, ports_.size()); |
| 571 EXPECT_PRED5(CheckCandidate, candidates_[2], | 596 EXPECT_PRED5(CheckCandidate, candidates_[2], |
| 572 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", kRelayUdpIntAddr); | 597 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
| 598 kRelayUdpIntAddr); | |
| 573 EXPECT_PRED5(CheckCandidate, candidates_[3], | 599 EXPECT_PRED5(CheckCandidate, candidates_[3], |
| 574 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", kRelayUdpExtAddr); | 600 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
| 601 kRelayUdpExtAddr); | |
| 575 ASSERT_EQ_WAIT(6U, candidates_.size(), 1500); | 602 ASSERT_EQ_WAIT(6U, candidates_.size(), 1500); |
| 576 EXPECT_PRED5(CheckCandidate, candidates_[4], | 603 EXPECT_PRED5(CheckCandidate, candidates_[4], |
| 577 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", kRelayTcpIntAddr); | 604 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", |
| 605 kRelayTcpIntAddr); | |
| 578 EXPECT_PRED5(CheckCandidate, candidates_[5], | 606 EXPECT_PRED5(CheckCandidate, candidates_[5], |
| 579 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr); | 607 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", |
| 608 kClientAddr); | |
| 580 EXPECT_EQ(4U, ports_.size()); | 609 EXPECT_EQ(4U, ports_.size()); |
| 581 ASSERT_EQ_WAIT(7U, candidates_.size(), 2000); | 610 ASSERT_EQ_WAIT(7U, candidates_.size(), 2000); |
| 582 EXPECT_PRED5(CheckCandidate, candidates_[6], | 611 EXPECT_PRED5(CheckCandidate, candidates_[6], |
| 583 cricket::ICE_CANDIDATE_COMPONENT_RTP, | 612 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "ssltcp", |
| 584 "relay", "ssltcp", kRelaySslTcpIntAddr); | 613 kRelaySslTcpIntAddr); |
| 585 EXPECT_EQ(4U, ports_.size()); | 614 EXPECT_EQ(4U, ports_.size()); |
| 586 EXPECT_TRUE(candidate_allocation_done_); | 615 EXPECT_TRUE(candidate_allocation_done_); |
| 587 // If we Stop gathering now, we shouldn't get a second "done" callback. | 616 // If we Stop gathering now, we shouldn't get a second "done" callback. |
| 588 session_->StopGettingPorts(); | 617 session_->StopGettingPorts(); |
| 589 } | 618 } |
| 590 | 619 |
| 591 TEST_F(PortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) { | 620 TEST_F(BasicPortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) { |
| 592 AddInterface(kClientAddr); | 621 AddInterface(kClientAddr); |
| 593 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP, | 622 EXPECT_TRUE( |
| 594 cricket::CN_VIDEO)); | 623 CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP, cricket::CN_VIDEO)); |
| 595 session_->StartGettingPorts(); | 624 session_->StartGettingPorts(); |
| 596 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 625 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
| 597 EXPECT_TRUE(candidate_allocation_done_); | 626 EXPECT_TRUE(candidate_allocation_done_); |
| 598 // If we Stop gathering now, we shouldn't get a second "done" callback. | 627 // If we Stop gathering now, we shouldn't get a second "done" callback. |
| 599 session_->StopGettingPorts(); | 628 session_->StopGettingPorts(); |
| 600 | 629 |
| 601 // All ports should have unset send-buffer sizes. | 630 // All ports should have unset send-buffer sizes. |
| 602 CheckSendBufferSizesOfAllPorts(-1); | 631 CheckSendBufferSizesOfAllPorts(-1); |
| 603 } | 632 } |
| 604 | 633 |
| 605 // Tests that we can get callback after StopGetAllPorts. | 634 // Tests that we can get callback after StopGetAllPorts. |
| 606 TEST_F(PortAllocatorTest, TestStopGetAllPorts) { | 635 TEST_F(BasicPortAllocatorTest, TestStopGetAllPorts) { |
| 607 AddInterface(kClientAddr); | 636 AddInterface(kClientAddr); |
| 608 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 637 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 609 session_->StartGettingPorts(); | 638 session_->StartGettingPorts(); |
| 610 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); | 639 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); |
| 611 EXPECT_EQ(2U, ports_.size()); | 640 EXPECT_EQ(2U, ports_.size()); |
| 612 session_->StopGettingPorts(); | 641 session_->StopGettingPorts(); |
| 613 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 642 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 614 } | 643 } |
| 615 | 644 |
| 616 // Test that we restrict client ports appropriately when a port range is set. | 645 // Test that we restrict client ports appropriately when a port range is set. |
| 617 // We check the candidates for udp/stun/tcp ports, and the from address | 646 // We check the candidates for udp/stun/tcp ports, and the from address |
| 618 // for relay ports. | 647 // for relay ports. |
| 619 TEST_F(PortAllocatorTest, TestGetAllPortsPortRange) { | 648 TEST_F(BasicPortAllocatorTest, TestGetAllPortsPortRange) { |
| 620 AddInterface(kClientAddr); | 649 AddInterface(kClientAddr); |
| 621 // Check that an invalid port range fails. | 650 // Check that an invalid port range fails. |
| 622 EXPECT_FALSE(SetPortRange(kMaxPort, kMinPort)); | 651 EXPECT_FALSE(SetPortRange(kMaxPort, kMinPort)); |
| 623 // Check that a null port range succeeds. | 652 // Check that a null port range succeeds. |
| 624 EXPECT_TRUE(SetPortRange(0, 0)); | 653 EXPECT_TRUE(SetPortRange(0, 0)); |
| 625 // Check that a valid port range succeeds. | 654 // Check that a valid port range succeeds. |
| 626 EXPECT_TRUE(SetPortRange(kMinPort, kMaxPort)); | 655 EXPECT_TRUE(SetPortRange(kMinPort, kMaxPort)); |
| 627 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 656 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 628 session_->StartGettingPorts(); | 657 session_->StartGettingPorts(); |
| 629 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 658 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
| 630 EXPECT_EQ(4U, ports_.size()); | 659 EXPECT_EQ(4U, ports_.size()); |
| 631 // Check the port number for the UDP port object. | 660 // Check the port number for the UDP port object. |
| 632 EXPECT_PRED3(CheckPort, candidates_[0].address(), kMinPort, kMaxPort); | 661 EXPECT_PRED3(CheckPort, candidates_[0].address(), kMinPort, kMaxPort); |
| 633 // Check the port number for the STUN port object. | 662 // Check the port number for the STUN port object. |
| 634 EXPECT_PRED3(CheckPort, candidates_[1].address(), kMinPort, kMaxPort); | 663 EXPECT_PRED3(CheckPort, candidates_[1].address(), kMinPort, kMaxPort); |
| 635 // Check the port number used to connect to the relay server. | 664 // Check the port number used to connect to the relay server. |
| 636 EXPECT_PRED3(CheckPort, relay_server_.GetConnection(0).source(), | 665 EXPECT_PRED3(CheckPort, relay_server_.GetConnection(0).source(), kMinPort, |
| 637 kMinPort, kMaxPort); | 666 kMaxPort); |
| 638 // Check the port number for the TCP port object. | 667 // Check the port number for the TCP port object. |
| 639 EXPECT_PRED3(CheckPort, candidates_[5].address(), kMinPort, kMaxPort); | 668 EXPECT_PRED3(CheckPort, candidates_[5].address(), kMinPort, kMaxPort); |
| 640 EXPECT_TRUE(candidate_allocation_done_); | 669 EXPECT_TRUE(candidate_allocation_done_); |
| 641 } | 670 } |
| 642 | 671 |
| 643 // Test that we don't crash or malfunction if we have no network adapters. | 672 // Test that we don't crash or malfunction if we have no network adapters. |
| 644 TEST_F(PortAllocatorTest, TestGetAllPortsNoAdapters) { | 673 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoAdapters) { |
| 645 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 674 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 646 session_->StartGettingPorts(); | 675 session_->StartGettingPorts(); |
| 647 rtc::Thread::Current()->ProcessMessages(100); | 676 rtc::Thread::Current()->ProcessMessages(100); |
| 648 // Without network adapter, we should not get any candidate. | 677 // Without network adapter, we should not get any candidate. |
| 649 EXPECT_EQ(0U, candidates_.size()); | 678 EXPECT_EQ(0U, candidates_.size()); |
| 650 EXPECT_TRUE(candidate_allocation_done_); | 679 EXPECT_TRUE(candidate_allocation_done_); |
| 651 } | 680 } |
| 652 | 681 |
| 653 // Test that when enumeration is disabled, we should not have any ports when | 682 // Test that when enumeration is disabled, we should not have any ports when |
| 654 // candidate_filter() is set to CF_RELAY and no relay is specified. | 683 // candidate_filter() is set to CF_RELAY and no relay is specified. |
| 655 TEST_F(PortAllocatorTest, | 684 TEST_F(BasicPortAllocatorTest, |
| 656 TestDisableAdapterEnumerationWithoutNatRelayTransportOnly) { | 685 TestDisableAdapterEnumerationWithoutNatRelayTransportOnly) { |
| 657 ResetWithStunServerNoNat(kStunAddr); | 686 ResetWithStunServerNoNat(kStunAddr); |
| 658 allocator().set_candidate_filter(cricket::CF_RELAY); | 687 allocator().set_candidate_filter(cricket::CF_RELAY); |
| 659 // Expect to see no ports and no candidates. | 688 // Expect to see no ports and no candidates. |
| 660 CheckDisableAdapterEnumeration(0U, rtc::IPAddress(), rtc::IPAddress(), | 689 CheckDisableAdapterEnumeration(0U, rtc::IPAddress(), rtc::IPAddress(), |
| 661 rtc::IPAddress(), rtc::IPAddress()); | 690 rtc::IPAddress(), rtc::IPAddress()); |
| 662 } | 691 } |
| 663 | 692 |
| 664 // Test that even with multiple interfaces, the result should still be a single | 693 // Test that even with multiple interfaces, the result should still be a single |
| 665 // default private, one STUN and one TURN candidate since we bind to any address | 694 // default private, one STUN and one TURN candidate since we bind to any address |
| 666 // (i.e. all 0s). | 695 // (i.e. all 0s). |
| 667 TEST_F(PortAllocatorTest, | 696 TEST_F(BasicPortAllocatorTest, |
| 668 TestDisableAdapterEnumerationBehindNatMultipleInterfaces) { | 697 TestDisableAdapterEnumerationBehindNatMultipleInterfaces) { |
| 669 AddInterface(kPrivateAddr); | 698 AddInterface(kPrivateAddr); |
| 670 AddInterface(kPrivateAddr2); | 699 AddInterface(kPrivateAddr2); |
| 671 ResetWithStunServerAndNat(kStunAddr); | 700 ResetWithStunServerAndNat(kStunAddr); |
| 672 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 701 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
| 673 | 702 |
| 674 // Enable IPv6 here. Since the network_manager doesn't have IPv6 default | 703 // Enable IPv6 here. Since the network_manager doesn't have IPv6 default |
| 675 // address set and we have no IPv6 STUN server, there should be no IPv6 | 704 // address set and we have no IPv6 STUN server, there should be no IPv6 |
| 676 // candidates. | 705 // candidates. |
| 677 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 706 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 678 session_->set_flags(cricket::PORTALLOCATOR_ENABLE_IPV6); | 707 session_->set_flags(cricket::PORTALLOCATOR_ENABLE_IPV6); |
| 679 | 708 |
| 680 // Expect to see 3 ports for IPv4: HOST/STUN, TURN/UDP and TCP ports, 2 ports | 709 // Expect to see 3 ports for IPv4: HOST/STUN, TURN/UDP and TCP ports, 2 ports |
| 681 // for IPv6: HOST, and TCP. Only IPv4 candidates: a default private, STUN and | 710 // for IPv6: HOST, and TCP. Only IPv4 candidates: a default private, STUN and |
| 682 // TURN/UDP candidates. | 711 // TURN/UDP candidates. |
| 683 CheckDisableAdapterEnumeration(5U, kPrivateAddr.ipaddr(), | 712 CheckDisableAdapterEnumeration(5U, kPrivateAddr.ipaddr(), |
| 684 kNatUdpAddr.ipaddr(), kTurnUdpExtAddr.ipaddr(), | 713 kNatUdpAddr.ipaddr(), kTurnUdpExtAddr.ipaddr(), |
| 685 rtc::IPAddress()); | 714 rtc::IPAddress()); |
| 686 } | 715 } |
| 687 | 716 |
| 688 // Test that we should get a default private, STUN, TURN/UDP and TURN/TCP | 717 // Test that we should get a default private, STUN, TURN/UDP and TURN/TCP |
| 689 // candidates when both TURN/UDP and TURN/TCP servers are specified. | 718 // candidates when both TURN/UDP and TURN/TCP servers are specified. |
| 690 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationBehindNatWithTcp) { | 719 TEST_F(BasicPortAllocatorTest, TestDisableAdapterEnumerationBehindNatWithTcp) { |
| 691 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); | 720 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); |
| 692 AddInterface(kPrivateAddr); | 721 AddInterface(kPrivateAddr); |
| 693 ResetWithStunServerAndNat(kStunAddr); | 722 ResetWithStunServerAndNat(kStunAddr); |
| 694 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | 723 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
| 695 // Expect to see 4 ports - STUN, TURN/UDP, TURN/TCP and TCP port. A default | 724 // Expect to see 4 ports - STUN, TURN/UDP, TURN/TCP and TCP port. A default |
| 696 // private, STUN, TURN/UDP, and TURN/TCP candidates. | 725 // private, STUN, TURN/UDP, and TURN/TCP candidates. |
| 697 CheckDisableAdapterEnumeration(4U, kPrivateAddr.ipaddr(), | 726 CheckDisableAdapterEnumeration(4U, kPrivateAddr.ipaddr(), |
| 698 kNatUdpAddr.ipaddr(), kTurnUdpExtAddr.ipaddr(), | 727 kNatUdpAddr.ipaddr(), kTurnUdpExtAddr.ipaddr(), |
| 699 kTurnUdpExtAddr.ipaddr()); | 728 kTurnUdpExtAddr.ipaddr()); |
| 700 } | 729 } |
| 701 | 730 |
| 702 // Test that when adapter enumeration is disabled, for endpoints without | 731 // Test that when adapter enumeration is disabled, for endpoints without |
| 703 // STUN/TURN specified, a default private candidate is still generated. | 732 // STUN/TURN specified, a default private candidate is still generated. |
| 704 TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNatOrServers) { | 733 TEST_F(BasicPortAllocatorTest, |
| 734 TestDisableAdapterEnumerationWithoutNatOrServers) { | |
| 705 ResetWithNoServersOrNat(); | 735 ResetWithNoServersOrNat(); |
| 706 // Expect to see 2 ports: STUN and TCP ports, one default private candidate. | 736 // Expect to see 2 ports: STUN and TCP ports, one default private candidate. |
| 707 CheckDisableAdapterEnumeration(2U, kPrivateAddr.ipaddr(), rtc::IPAddress(), | 737 CheckDisableAdapterEnumeration(2U, kPrivateAddr.ipaddr(), rtc::IPAddress(), |
| 708 rtc::IPAddress(), rtc::IPAddress()); | 738 rtc::IPAddress(), rtc::IPAddress()); |
| 709 } | 739 } |
| 710 | 740 |
| 711 // Test that when adapter enumeration is disabled, with | 741 // Test that when adapter enumeration is disabled, with |
| 712 // PORTALLOCATOR_DISABLE_LOCALHOST_CANDIDATE specified, for endpoints not behind | 742 // PORTALLOCATOR_DISABLE_LOCALHOST_CANDIDATE specified, for endpoints not behind |
| 713 // a NAT, there is no local candidate. | 743 // a NAT, there is no local candidate. |
| 714 TEST_F(PortAllocatorTest, | 744 TEST_F(BasicPortAllocatorTest, |
| 715 TestDisableAdapterEnumerationWithoutNatLocalhostCandidateDisabled) { | 745 TestDisableAdapterEnumerationWithoutNatLocalhostCandidateDisabled) { |
| 716 ResetWithStunServerNoNat(kStunAddr); | 746 ResetWithStunServerNoNat(kStunAddr); |
| 717 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 747 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 718 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); | 748 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); |
| 719 // Expect to see 2 ports: STUN and TCP ports, localhost candidate and STUN | 749 // Expect to see 2 ports: STUN and TCP ports, localhost candidate and STUN |
| 720 // candidate. | 750 // candidate. |
| 721 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), rtc::IPAddress(), | 751 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), rtc::IPAddress(), |
| 722 rtc::IPAddress(), rtc::IPAddress()); | 752 rtc::IPAddress(), rtc::IPAddress()); |
| 723 } | 753 } |
| 724 | 754 |
| 725 // Test that when adapter enumeration is disabled, with | 755 // Test that when adapter enumeration is disabled, with |
| 726 // PORTALLOCATOR_DISABLE_LOCALHOST_CANDIDATE specified, for endpoints not behind | 756 // PORTALLOCATOR_DISABLE_LOCALHOST_CANDIDATE specified, for endpoints not behind |
| 727 // a NAT, there is no local candidate. However, this specified default route | 757 // a NAT, there is no local candidate. However, this specified default route |
| 728 // (kClientAddr) which was discovered when sending STUN requests, will become | 758 // (kClientAddr) which was discovered when sending STUN requests, will become |
| 729 // the srflx addresses. | 759 // the srflx addresses. |
| 730 TEST_F( | 760 TEST_F( |
| 731 PortAllocatorTest, | 761 BasicPortAllocatorTest, |
| 732 TestDisableAdapterEnumerationWithoutNatLocalhostCandidateDisabledWithDiffere ntDefaultRoute) { | 762 TestDisableAdapterEnumerationWithoutNatLocalhostCandidateDisabledWithDiffere ntDefaultRoute) { |
| 733 ResetWithStunServerNoNat(kStunAddr); | 763 ResetWithStunServerNoNat(kStunAddr); |
| 734 AddInterfaceAsDefaultRoute(kClientAddr); | 764 AddInterfaceAsDefaultRoute(kClientAddr); |
| 735 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 765 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 736 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); | 766 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); |
| 737 // Expect to see 2 ports: STUN and TCP ports, localhost candidate and STUN | 767 // Expect to see 2 ports: STUN and TCP ports, localhost candidate and STUN |
| 738 // candidate. | 768 // candidate. |
| 739 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), kClientAddr.ipaddr(), | 769 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), kClientAddr.ipaddr(), |
| 740 rtc::IPAddress(), rtc::IPAddress()); | 770 rtc::IPAddress(), rtc::IPAddress()); |
| 741 } | 771 } |
| 742 | 772 |
| 743 // Test that when adapter enumeration is disabled, with | 773 // Test that when adapter enumeration is disabled, with |
| 744 // PORTALLOCATOR_DISABLE_LOCALHOST_CANDIDATE specified, for endpoints behind a | 774 // PORTALLOCATOR_DISABLE_LOCALHOST_CANDIDATE specified, for endpoints behind a |
| 745 // NAT, there is only one STUN candidate. | 775 // NAT, there is only one STUN candidate. |
| 746 TEST_F(PortAllocatorTest, | 776 TEST_F(BasicPortAllocatorTest, |
| 747 TestDisableAdapterEnumerationWithNatLocalhostCandidateDisabled) { | 777 TestDisableAdapterEnumerationWithNatLocalhostCandidateDisabled) { |
| 748 ResetWithStunServerAndNat(kStunAddr); | 778 ResetWithStunServerAndNat(kStunAddr); |
| 749 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 779 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 750 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); | 780 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); |
| 751 // Expect to see 2 ports: STUN and TCP ports, and single STUN candidate. | 781 // Expect to see 2 ports: STUN and TCP ports, and single STUN candidate. |
| 752 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), kNatUdpAddr.ipaddr(), | 782 CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), kNatUdpAddr.ipaddr(), |
| 753 rtc::IPAddress(), rtc::IPAddress()); | 783 rtc::IPAddress(), rtc::IPAddress()); |
| 754 } | 784 } |
| 755 | 785 |
| 756 // Test that we disable relay over UDP, and only TCP is used when connecting to | 786 // Test that we disable relay over UDP, and only TCP is used when connecting to |
| 757 // the relay server. | 787 // the relay server. |
| 758 TEST_F(PortAllocatorTest, TestDisableUdpTurn) { | 788 TEST_F(BasicPortAllocatorTest, TestDisableUdpTurn) { |
| 759 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); | 789 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); |
| 760 AddInterface(kClientAddr); | 790 AddInterface(kClientAddr); |
| 761 ResetWithStunServerAndNat(kStunAddr); | 791 ResetWithStunServerAndNat(kStunAddr); |
| 762 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | 792 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
| 763 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 793 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 764 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_UDP_RELAY | | 794 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_UDP_RELAY | |
| 765 cricket::PORTALLOCATOR_DISABLE_UDP | | 795 cricket::PORTALLOCATOR_DISABLE_UDP | |
| 766 cricket::PORTALLOCATOR_DISABLE_STUN | | 796 cricket::PORTALLOCATOR_DISABLE_STUN | |
| 767 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 797 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
| 768 | 798 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 782 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", | 812 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", |
| 783 kClientAddr); | 813 kClientAddr); |
| 784 } | 814 } |
| 785 | 815 |
| 786 // Disable for asan, see | 816 // Disable for asan, see |
| 787 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details. | 817 // https://code.google.com/p/webrtc/issues/detail?id=4743 for details. |
| 788 #if !defined(ADDRESS_SANITIZER) | 818 #if !defined(ADDRESS_SANITIZER) |
| 789 | 819 |
| 790 // Test that we can get OnCandidatesAllocationDone callback when all the ports | 820 // Test that we can get OnCandidatesAllocationDone callback when all the ports |
| 791 // are disabled. | 821 // are disabled. |
| 792 TEST_F(PortAllocatorTest, TestDisableAllPorts) { | 822 TEST_F(BasicPortAllocatorTest, TestDisableAllPorts) { |
| 793 AddInterface(kClientAddr); | 823 AddInterface(kClientAddr); |
| 794 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 824 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 795 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_UDP | | 825 session_->set_flags(cricket::PORTALLOCATOR_DISABLE_UDP | |
| 796 cricket::PORTALLOCATOR_DISABLE_STUN | | 826 cricket::PORTALLOCATOR_DISABLE_STUN | |
| 797 cricket::PORTALLOCATOR_DISABLE_RELAY | | 827 cricket::PORTALLOCATOR_DISABLE_RELAY | |
| 798 cricket::PORTALLOCATOR_DISABLE_TCP); | 828 cricket::PORTALLOCATOR_DISABLE_TCP); |
| 799 session_->StartGettingPorts(); | 829 session_->StartGettingPorts(); |
| 800 rtc::Thread::Current()->ProcessMessages(100); | 830 rtc::Thread::Current()->ProcessMessages(100); |
| 801 EXPECT_EQ(0U, candidates_.size()); | 831 EXPECT_EQ(0U, candidates_.size()); |
| 802 EXPECT_TRUE(candidate_allocation_done_); | 832 EXPECT_TRUE(candidate_allocation_done_); |
| 803 } | 833 } |
| 804 | 834 |
| 805 // Test that we don't crash or malfunction if we can't create UDP sockets. | 835 // Test that we don't crash or malfunction if we can't create UDP sockets. |
| 806 TEST_F(PortAllocatorTest, TestGetAllPortsNoUdpSockets) { | 836 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSockets) { |
| 807 AddInterface(kClientAddr); | 837 AddInterface(kClientAddr); |
| 808 fss_->set_udp_sockets_enabled(false); | 838 fss_->set_udp_sockets_enabled(false); |
| 809 EXPECT_TRUE(CreateSession(1)); | 839 EXPECT_TRUE(CreateSession(1)); |
| 810 session_->StartGettingPorts(); | 840 session_->StartGettingPorts(); |
| 811 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout); | 841 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout); |
| 812 EXPECT_EQ(2U, ports_.size()); | 842 EXPECT_EQ(2U, ports_.size()); |
| 813 EXPECT_PRED5(CheckCandidate, candidates_[0], | 843 EXPECT_PRED5(CheckCandidate, candidates_[0], |
| 814 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", kRelayUdpIntAddr); | 844 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
| 845 kRelayUdpIntAddr); | |
| 815 EXPECT_PRED5(CheckCandidate, candidates_[1], | 846 EXPECT_PRED5(CheckCandidate, candidates_[1], |
| 816 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", kRelayUdpExtAddr); | 847 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
| 848 kRelayUdpExtAddr); | |
| 817 EXPECT_PRED5(CheckCandidate, candidates_[2], | 849 EXPECT_PRED5(CheckCandidate, candidates_[2], |
| 818 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", kRelayTcpIntAddr); | 850 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", |
| 851 kRelayTcpIntAddr); | |
| 819 EXPECT_PRED5(CheckCandidate, candidates_[3], | 852 EXPECT_PRED5(CheckCandidate, candidates_[3], |
| 820 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr); | 853 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", |
| 854 kClientAddr); | |
| 821 EXPECT_PRED5(CheckCandidate, candidates_[4], | 855 EXPECT_PRED5(CheckCandidate, candidates_[4], |
| 822 cricket::ICE_CANDIDATE_COMPONENT_RTP, | 856 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "ssltcp", |
| 823 "relay", "ssltcp", kRelaySslTcpIntAddr); | 857 kRelaySslTcpIntAddr); |
| 824 EXPECT_TRUE(candidate_allocation_done_); | 858 EXPECT_TRUE(candidate_allocation_done_); |
| 825 } | 859 } |
| 826 | 860 |
| 827 #endif // if !defined(ADDRESS_SANITIZER) | 861 #endif // if !defined(ADDRESS_SANITIZER) |
| 828 | 862 |
| 829 // Test that we don't crash or malfunction if we can't create UDP sockets or | 863 // Test that we don't crash or malfunction if we can't create UDP sockets or |
| 830 // listen on TCP sockets. We still give out a local TCP address, since | 864 // listen on TCP sockets. We still give out a local TCP address, since |
| 831 // apparently this is needed for the remote side to accept our connection. | 865 // apparently this is needed for the remote side to accept our connection. |
| 832 TEST_F(PortAllocatorTest, TestGetAllPortsNoUdpSocketsNoTcpListen) { | 866 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSocketsNoTcpListen) { |
| 833 AddInterface(kClientAddr); | 867 AddInterface(kClientAddr); |
| 834 fss_->set_udp_sockets_enabled(false); | 868 fss_->set_udp_sockets_enabled(false); |
| 835 fss_->set_tcp_listen_enabled(false); | 869 fss_->set_tcp_listen_enabled(false); |
| 836 EXPECT_TRUE(CreateSession(1)); | 870 EXPECT_TRUE(CreateSession(1)); |
| 837 session_->StartGettingPorts(); | 871 session_->StartGettingPorts(); |
| 838 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout); | 872 ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout); |
| 839 EXPECT_EQ(2U, ports_.size()); | 873 EXPECT_EQ(2U, ports_.size()); |
| 840 EXPECT_PRED5(CheckCandidate, candidates_[0], | 874 EXPECT_PRED5(CheckCandidate, candidates_[0], 1, "relay", "udp", |
| 841 1, "relay", "udp", kRelayUdpIntAddr); | 875 kRelayUdpIntAddr); |
| 842 EXPECT_PRED5(CheckCandidate, candidates_[1], | 876 EXPECT_PRED5(CheckCandidate, candidates_[1], 1, "relay", "udp", |
| 843 1, "relay", "udp", kRelayUdpExtAddr); | 877 kRelayUdpExtAddr); |
| 844 EXPECT_PRED5(CheckCandidate, candidates_[2], | 878 EXPECT_PRED5(CheckCandidate, candidates_[2], 1, "relay", "tcp", |
| 845 1, "relay", "tcp", kRelayTcpIntAddr); | 879 kRelayTcpIntAddr); |
| 846 EXPECT_PRED5(CheckCandidate, candidates_[3], | 880 EXPECT_PRED5(CheckCandidate, candidates_[3], 1, "local", "tcp", kClientAddr); |
| 847 1, "local", "tcp", kClientAddr); | 881 EXPECT_PRED5(CheckCandidate, candidates_[4], 1, "relay", "ssltcp", |
| 848 EXPECT_PRED5(CheckCandidate, candidates_[4], | 882 kRelaySslTcpIntAddr); |
| 849 1, "relay", "ssltcp", kRelaySslTcpIntAddr); | |
| 850 EXPECT_TRUE(candidate_allocation_done_); | 883 EXPECT_TRUE(candidate_allocation_done_); |
| 851 } | 884 } |
| 852 | 885 |
| 853 // Test that we don't crash or malfunction if we can't create any sockets. | 886 // Test that we don't crash or malfunction if we can't create any sockets. |
| 854 // TODO: Find a way to exit early here. | 887 // TODO(deadbeef): Find a way to exit early here. |
| 855 TEST_F(PortAllocatorTest, TestGetAllPortsNoSockets) { | 888 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoSockets) { |
| 856 AddInterface(kClientAddr); | 889 AddInterface(kClientAddr); |
| 857 fss_->set_tcp_sockets_enabled(false); | 890 fss_->set_tcp_sockets_enabled(false); |
| 858 fss_->set_udp_sockets_enabled(false); | 891 fss_->set_udp_sockets_enabled(false); |
| 859 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 892 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 860 session_->StartGettingPorts(); | 893 session_->StartGettingPorts(); |
| 861 WAIT(candidates_.size() > 0, 2000); | 894 WAIT(candidates_.size() > 0, 2000); |
| 862 // TODO - Check candidate_allocation_done signal. | 895 // TODO(deadbeef): Check candidate_allocation_done signal. |
| 863 // In case of Relay, ports creation will succeed but sockets will fail. | 896 // In case of Relay, ports creation will succeed but sockets will fail. |
| 864 // There is no error reporting from RelayEntry to handle this failure. | 897 // There is no error reporting from RelayEntry to handle this failure. |
| 865 } | 898 } |
| 866 | 899 |
| 867 // Testing STUN timeout. | 900 // Testing STUN timeout. |
| 868 TEST_F(PortAllocatorTest, TestGetAllPortsNoUdpAllowed) { | 901 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpAllowed) { |
| 869 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); | 902 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); |
| 870 AddInterface(kClientAddr); | 903 AddInterface(kClientAddr); |
| 871 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 904 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 872 session_->StartGettingPorts(); | 905 session_->StartGettingPorts(); |
| 873 EXPECT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); | 906 EXPECT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); |
| 874 EXPECT_EQ(2U, ports_.size()); | 907 EXPECT_EQ(2U, ports_.size()); |
| 875 EXPECT_PRED5(CheckCandidate, candidates_[0], | 908 EXPECT_PRED5(CheckCandidate, candidates_[0], |
| 876 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | 909 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
| 910 kClientAddr); | |
| 877 EXPECT_PRED5(CheckCandidate, candidates_[1], | 911 EXPECT_PRED5(CheckCandidate, candidates_[1], |
| 878 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr); | 912 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", |
| 913 kClientAddr); | |
| 879 // RelayPort connection timeout is 3sec. TCP connection with RelayServer | 914 // RelayPort connection timeout is 3sec. TCP connection with RelayServer |
| 880 // will be tried after 3 seconds. | 915 // will be tried after 3 seconds. |
| 881 EXPECT_EQ_WAIT(6U, candidates_.size(), 4000); | 916 EXPECT_EQ_WAIT(6U, candidates_.size(), 4000); |
| 882 EXPECT_EQ(3U, ports_.size()); | 917 EXPECT_EQ(3U, ports_.size()); |
| 883 EXPECT_PRED5(CheckCandidate, candidates_[2], | 918 EXPECT_PRED5(CheckCandidate, candidates_[2], |
| 884 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", kRelayUdpIntAddr); | 919 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
| 920 kRelayUdpIntAddr); | |
| 885 EXPECT_PRED5(CheckCandidate, candidates_[3], | 921 EXPECT_PRED5(CheckCandidate, candidates_[3], |
| 886 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", kRelayTcpIntAddr); | 922 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", |
| 923 kRelayTcpIntAddr); | |
| 887 EXPECT_PRED5(CheckCandidate, candidates_[4], | 924 EXPECT_PRED5(CheckCandidate, candidates_[4], |
| 888 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "ssltcp", | 925 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "ssltcp", |
| 889 kRelaySslTcpIntAddr); | 926 kRelaySslTcpIntAddr); |
| 890 EXPECT_PRED5(CheckCandidate, candidates_[5], | 927 EXPECT_PRED5(CheckCandidate, candidates_[5], |
| 891 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", kRelayUdpExtAddr); | 928 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
| 929 kRelayUdpExtAddr); | |
| 892 // Stun Timeout is 9sec. | 930 // Stun Timeout is 9sec. |
| 893 EXPECT_TRUE_WAIT(candidate_allocation_done_, 9000); | 931 EXPECT_TRUE_WAIT(candidate_allocation_done_, 9000); |
| 894 } | 932 } |
| 895 | 933 |
| 896 TEST_F(PortAllocatorTest, TestCandidatePriorityOfMultipleInterfaces) { | 934 TEST_F(BasicPortAllocatorTest, TestCandidatePriorityOfMultipleInterfaces) { |
| 897 AddInterface(kClientAddr); | 935 AddInterface(kClientAddr); |
| 898 AddInterface(kClientAddr2); | 936 AddInterface(kClientAddr2); |
| 899 // Allocating only host UDP ports. This is done purely for testing | 937 // Allocating only host UDP ports. This is done purely for testing |
| 900 // convenience. | 938 // convenience. |
| 901 allocator().set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | | 939 allocator().set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
| 902 cricket::PORTALLOCATOR_DISABLE_STUN | | 940 cricket::PORTALLOCATOR_DISABLE_STUN | |
| 903 cricket::PORTALLOCATOR_DISABLE_RELAY); | 941 cricket::PORTALLOCATOR_DISABLE_RELAY); |
| 904 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 942 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 905 session_->StartGettingPorts(); | 943 session_->StartGettingPorts(); |
| 906 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 944 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 907 ASSERT_EQ(2U, candidates_.size()); | 945 ASSERT_EQ(2U, candidates_.size()); |
| 908 EXPECT_EQ(2U, ports_.size()); | 946 EXPECT_EQ(2U, ports_.size()); |
| 909 // Candidates priorities should be different. | 947 // Candidates priorities should be different. |
| 910 EXPECT_NE(candidates_[0].priority(), candidates_[1].priority()); | 948 EXPECT_NE(candidates_[0].priority(), candidates_[1].priority()); |
| 911 } | 949 } |
| 912 | 950 |
| 913 // Test to verify ICE restart process. | 951 // Test to verify ICE restart process. |
| 914 TEST_F(PortAllocatorTest, TestGetAllPortsRestarts) { | 952 TEST_F(BasicPortAllocatorTest, TestGetAllPortsRestarts) { |
| 915 AddInterface(kClientAddr); | 953 AddInterface(kClientAddr); |
| 916 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 954 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 917 session_->StartGettingPorts(); | 955 session_->StartGettingPorts(); |
| 918 EXPECT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 956 EXPECT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
| 919 EXPECT_EQ(4U, ports_.size()); | 957 EXPECT_EQ(4U, ports_.size()); |
| 920 EXPECT_TRUE(candidate_allocation_done_); | 958 EXPECT_TRUE(candidate_allocation_done_); |
| 921 // TODO - Extend this to verify ICE restart. | 959 // TODO(deadbeef): Extend this to verify ICE restart. |
| 922 } | 960 } |
| 923 | 961 |
| 924 // Test ICE candidate filter mechanism with options Relay/Host/Reflexive. | 962 // Test ICE candidate filter mechanism with options Relay/Host/Reflexive. |
| 925 // This test also verifies that when the allocator is only allowed to use | 963 // This test also verifies that when the allocator is only allowed to use |
| 926 // relay (i.e. IceTransportsType is relay), the raddr is an empty | 964 // relay (i.e. IceTransportsType is relay), the raddr is an empty |
| 927 // address with the correct family. This is to prevent any local | 965 // address with the correct family. This is to prevent any local |
| 928 // reflective address leakage in the sdp line. | 966 // reflective address leakage in the sdp line. |
| 929 TEST_F(PortAllocatorTest, TestCandidateFilterWithRelayOnly) { | 967 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithRelayOnly) { |
| 930 AddInterface(kClientAddr); | 968 AddInterface(kClientAddr); |
| 931 // GTURN is not configured here. | 969 // GTURN is not configured here. |
| 932 ResetWithTurnServersNoNat(kTurnUdpIntAddr, rtc::SocketAddress()); | 970 ResetWithTurnServersNoNat(kTurnUdpIntAddr, rtc::SocketAddress()); |
| 933 allocator().set_candidate_filter(cricket::CF_RELAY); | 971 allocator().set_candidate_filter(cricket::CF_RELAY); |
| 934 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 972 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 935 session_->StartGettingPorts(); | 973 session_->StartGettingPorts(); |
| 936 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 974 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 937 EXPECT_PRED5(CheckCandidate, | 975 EXPECT_PRED5(CheckCandidate, candidates_[0], |
| 938 candidates_[0], | 976 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
| 939 cricket::ICE_CANDIDATE_COMPONENT_RTP, | |
| 940 "relay", | |
| 941 "udp", | |
| 942 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 977 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
| 943 | 978 |
| 944 EXPECT_EQ(1U, candidates_.size()); | 979 EXPECT_EQ(1U, candidates_.size()); |
| 945 EXPECT_EQ(1U, ports_.size()); // Only Relay port will be in ready state. | 980 EXPECT_EQ(1U, ports_.size()); // Only Relay port will be in ready state. |
| 946 for (size_t i = 0; i < candidates_.size(); ++i) { | 981 for (size_t i = 0; i < candidates_.size(); ++i) { |
| 947 EXPECT_EQ(std::string(cricket::RELAY_PORT_TYPE), candidates_[i].type()); | 982 EXPECT_EQ(std::string(cricket::RELAY_PORT_TYPE), candidates_[i].type()); |
| 948 EXPECT_EQ( | 983 EXPECT_EQ( |
| 949 candidates_[0].related_address(), | 984 candidates_[0].related_address(), |
| 950 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); | 985 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); |
| 951 } | 986 } |
| 952 } | 987 } |
| 953 | 988 |
| 954 TEST_F(PortAllocatorTest, TestCandidateFilterWithHostOnly) { | 989 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithHostOnly) { |
| 955 AddInterface(kClientAddr); | 990 AddInterface(kClientAddr); |
| 956 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 991 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
| 957 allocator().set_candidate_filter(cricket::CF_HOST); | 992 allocator().set_candidate_filter(cricket::CF_HOST); |
| 958 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 993 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 959 session_->StartGettingPorts(); | 994 session_->StartGettingPorts(); |
| 960 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 995 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 961 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. | 996 EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. |
| 962 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. | 997 EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. |
| 963 for (size_t i = 0; i < candidates_.size(); ++i) { | 998 for (size_t i = 0; i < candidates_.size(); ++i) { |
| 964 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); | 999 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); |
| 965 } | 1000 } |
| 966 } | 1001 } |
| 967 | 1002 |
| 968 // Host is behind the NAT. | 1003 // Host is behind the NAT. |
| 969 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { | 1004 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { |
| 970 AddInterface(kPrivateAddr); | 1005 AddInterface(kPrivateAddr); |
| 971 ResetWithStunServerAndNat(kStunAddr); | 1006 ResetWithStunServerAndNat(kStunAddr); |
| 972 | 1007 |
| 973 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1008 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
| 974 allocator().set_candidate_filter(cricket::CF_REFLEXIVE); | 1009 allocator().set_candidate_filter(cricket::CF_REFLEXIVE); |
| 975 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1010 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 976 session_->StartGettingPorts(); | 1011 session_->StartGettingPorts(); |
| 977 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1012 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 978 // Host is behind NAT, no private address will be exposed. Hence only UDP | 1013 // Host is behind NAT, no private address will be exposed. Hence only UDP |
| 979 // port with STUN candidate will be sent outside. | 1014 // port with STUN candidate will be sent outside. |
| 980 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. | 1015 EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. |
| 981 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state. | 1016 EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state. |
| 982 for (size_t i = 0; i < candidates_.size(); ++i) { | 1017 for (size_t i = 0; i < candidates_.size(); ++i) { |
| 983 EXPECT_EQ(std::string(cricket::STUN_PORT_TYPE), candidates_[i].type()); | 1018 EXPECT_EQ(std::string(cricket::STUN_PORT_TYPE), candidates_[i].type()); |
| 984 EXPECT_EQ( | 1019 EXPECT_EQ( |
| 985 candidates_[0].related_address(), | 1020 candidates_[0].related_address(), |
| 986 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); | 1021 rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); |
| 987 } | 1022 } |
| 988 } | 1023 } |
| 989 | 1024 |
| 990 // Host is not behind the NAT. | 1025 // Host is not behind the NAT. |
| 991 TEST_F(PortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) { | 1026 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) { |
| 992 AddInterface(kClientAddr); | 1027 AddInterface(kClientAddr); |
| 993 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1028 allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
| 994 allocator().set_candidate_filter(cricket::CF_REFLEXIVE); | 1029 allocator().set_candidate_filter(cricket::CF_REFLEXIVE); |
| 995 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1030 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 996 session_->StartGettingPorts(); | 1031 session_->StartGettingPorts(); |
| 997 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1032 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 998 // Host has a public address, both UDP and TCP candidates will be exposed. | 1033 // Host has a public address, both UDP and TCP candidates will be exposed. |
| 999 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate. | 1034 EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate. |
| 1000 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state. | 1035 EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state. |
| 1001 for (size_t i = 0; i < candidates_.size(); ++i) { | 1036 for (size_t i = 0; i < candidates_.size(); ++i) { |
| 1002 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); | 1037 EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); |
| 1003 } | 1038 } |
| 1004 } | 1039 } |
| 1005 | 1040 |
| 1006 // Test that we get the same ufrag and pwd for all candidates. | 1041 // Test that we get the same ufrag and pwd for all candidates. |
| 1007 TEST_F(PortAllocatorTest, TestEnableSharedUfrag) { | 1042 TEST_F(BasicPortAllocatorTest, TestEnableSharedUfrag) { |
| 1008 AddInterface(kClientAddr); | 1043 AddInterface(kClientAddr); |
| 1009 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1044 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 1010 session_->StartGettingPorts(); | 1045 session_->StartGettingPorts(); |
| 1011 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); | 1046 ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); |
| 1012 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1047 EXPECT_PRED5(CheckCandidate, candidates_[0], |
| 1013 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | 1048 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
| 1049 kClientAddr); | |
| 1014 EXPECT_PRED5(CheckCandidate, candidates_[1], | 1050 EXPECT_PRED5(CheckCandidate, candidates_[1], |
| 1015 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", kClientAddr); | 1051 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", |
| 1052 kClientAddr); | |
| 1016 EXPECT_PRED5(CheckCandidate, candidates_[5], | 1053 EXPECT_PRED5(CheckCandidate, candidates_[5], |
| 1017 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", kClientAddr); | 1054 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", |
| 1055 kClientAddr); | |
| 1018 EXPECT_EQ(4U, ports_.size()); | 1056 EXPECT_EQ(4U, ports_.size()); |
| 1019 EXPECT_EQ(kIceUfrag0, candidates_[0].username()); | 1057 EXPECT_EQ(kIceUfrag0, candidates_[0].username()); |
| 1020 EXPECT_EQ(kIceUfrag0, candidates_[1].username()); | 1058 EXPECT_EQ(kIceUfrag0, candidates_[1].username()); |
| 1021 EXPECT_EQ(kIceUfrag0, candidates_[2].username()); | 1059 EXPECT_EQ(kIceUfrag0, candidates_[2].username()); |
| 1022 EXPECT_EQ(kIcePwd0, candidates_[0].password()); | 1060 EXPECT_EQ(kIcePwd0, candidates_[0].password()); |
| 1023 EXPECT_EQ(kIcePwd0, candidates_[1].password()); | 1061 EXPECT_EQ(kIcePwd0, candidates_[1].password()); |
| 1024 EXPECT_TRUE(candidate_allocation_done_); | 1062 EXPECT_TRUE(candidate_allocation_done_); |
| 1025 } | 1063 } |
| 1026 | 1064 |
| 1027 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port | 1065 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port |
| 1028 // is allocated for udp and stun. Also verify there is only one candidate | 1066 // is allocated for udp and stun. Also verify there is only one candidate |
| 1029 // (local) if stun candidate is same as local candidate, which will be the case | 1067 // (local) if stun candidate is same as local candidate, which will be the case |
| 1030 // in a public network like the below test. | 1068 // in a public network like the below test. |
| 1031 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNat) { | 1069 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNat) { |
| 1032 AddInterface(kClientAddr); | 1070 AddInterface(kClientAddr); |
| 1033 allocator_->set_flags(allocator().flags() | | 1071 allocator_->set_flags(allocator().flags() | |
| 1034 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1072 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
| 1035 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1073 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 1036 session_->StartGettingPorts(); | 1074 session_->StartGettingPorts(); |
| 1037 ASSERT_EQ_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout); | 1075 ASSERT_EQ_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout); |
| 1038 EXPECT_EQ(3U, ports_.size()); | 1076 EXPECT_EQ(3U, ports_.size()); |
| 1039 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1077 EXPECT_PRED5(CheckCandidate, candidates_[0], |
| 1040 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | 1078 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
| 1079 kClientAddr); | |
| 1041 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1080 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 1042 } | 1081 } |
| 1043 | 1082 |
| 1044 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port | 1083 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port |
| 1045 // is allocated for udp and stun. In this test we should expect both stun and | 1084 // is allocated for udp and stun. In this test we should expect both stun and |
| 1046 // local candidates as client behind a nat. | 1085 // local candidates as client behind a nat. |
| 1047 TEST_F(PortAllocatorTest, TestSharedSocketWithNat) { | 1086 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNat) { |
| 1048 AddInterface(kClientAddr); | 1087 AddInterface(kClientAddr); |
| 1049 ResetWithStunServerAndNat(kStunAddr); | 1088 ResetWithStunServerAndNat(kStunAddr); |
| 1050 | 1089 |
| 1051 allocator_->set_flags(allocator().flags() | | 1090 allocator_->set_flags(allocator().flags() | |
| 1052 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1091 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
| 1053 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1092 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 1054 session_->StartGettingPorts(); | 1093 session_->StartGettingPorts(); |
| 1055 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1094 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); |
| 1056 ASSERT_EQ(2U, ports_.size()); | 1095 ASSERT_EQ(2U, ports_.size()); |
| 1057 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1096 EXPECT_PRED5(CheckCandidate, candidates_[0], |
| 1058 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | 1097 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
| 1098 kClientAddr); | |
| 1059 EXPECT_PRED5(CheckCandidate, candidates_[1], | 1099 EXPECT_PRED5(CheckCandidate, candidates_[1], |
| 1060 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", | 1100 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", |
| 1061 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); | 1101 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); |
| 1062 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1102 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 1063 EXPECT_EQ(3U, candidates_.size()); | 1103 EXPECT_EQ(3U, candidates_.size()); |
| 1064 } | 1104 } |
| 1065 | 1105 |
| 1066 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses. | 1106 // Test TURN port in shared socket mode with UDP and TCP TURN server addresses. |
| 1067 TEST_F(PortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { | 1107 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { |
| 1068 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); | 1108 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); |
| 1069 AddInterface(kClientAddr); | 1109 AddInterface(kClientAddr); |
| 1070 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); | 1110 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); |
| 1071 | 1111 |
| 1072 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); | 1112 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
| 1073 | 1113 |
| 1074 allocator_->set_step_delay(cricket::kMinimumStepDelay); | 1114 allocator_->set_step_delay(cricket::kMinimumStepDelay); |
| 1075 allocator_->set_flags(allocator().flags() | | 1115 allocator_->set_flags(allocator().flags() | |
| 1076 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1116 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
| 1077 cricket::PORTALLOCATOR_DISABLE_TCP); | 1117 cricket::PORTALLOCATOR_DISABLE_TCP); |
| 1078 | 1118 |
| 1079 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1119 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 1080 session_->StartGettingPorts(); | 1120 session_->StartGettingPorts(); |
| 1081 | 1121 |
| 1082 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1122 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); |
| 1083 ASSERT_EQ(3U, ports_.size()); | 1123 ASSERT_EQ(3U, ports_.size()); |
| 1084 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1124 EXPECT_PRED5(CheckCandidate, candidates_[0], |
| 1085 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | 1125 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
| 1126 kClientAddr); | |
| 1086 EXPECT_PRED5(CheckCandidate, candidates_[1], | 1127 EXPECT_PRED5(CheckCandidate, candidates_[1], |
| 1087 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 1128 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
| 1088 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1129 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
| 1089 EXPECT_PRED5(CheckCandidate, candidates_[2], | 1130 EXPECT_PRED5(CheckCandidate, candidates_[2], |
| 1090 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 1131 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
| 1091 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1132 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
| 1092 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1133 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 1093 EXPECT_EQ(3U, candidates_.size()); | 1134 EXPECT_EQ(3U, candidates_.size()); |
| 1094 } | 1135 } |
| 1095 | 1136 |
| 1096 // Testing DNS resolve for the TURN server, this will test AllocationSequence | 1137 // Testing DNS resolve for the TURN server, this will test AllocationSequence |
| 1097 // handling the unresolved address signal from TurnPort. | 1138 // handling the unresolved address signal from TurnPort. |
| 1098 TEST_F(PortAllocatorTest, TestSharedSocketWithServerAddressResolve) { | 1139 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithServerAddressResolve) { |
| 1099 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), | 1140 turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), |
| 1100 cricket::PROTO_UDP); | 1141 cricket::PROTO_UDP); |
| 1101 AddInterface(kClientAddr); | 1142 AddInterface(kClientAddr); |
| 1102 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); | 1143 allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); |
| 1103 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN); | 1144 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN); |
| 1104 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); | 1145 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); |
| 1105 turn_server.credentials = credentials; | 1146 turn_server.credentials = credentials; |
| 1106 turn_server.ports.push_back(cricket::ProtocolAddress( | 1147 turn_server.ports.push_back(cricket::ProtocolAddress( |
| 1107 rtc::SocketAddress("localhost", 3478), cricket::PROTO_UDP, false)); | 1148 rtc::SocketAddress("localhost", 3478), cricket::PROTO_UDP, false)); |
| 1108 allocator_->AddTurnServer(turn_server); | 1149 allocator_->AddTurnServer(turn_server); |
| 1109 | 1150 |
| 1110 allocator_->set_step_delay(cricket::kMinimumStepDelay); | 1151 allocator_->set_step_delay(cricket::kMinimumStepDelay); |
| 1111 allocator_->set_flags(allocator().flags() | | 1152 allocator_->set_flags(allocator().flags() | |
| 1112 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1153 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
| 1113 cricket::PORTALLOCATOR_DISABLE_TCP); | 1154 cricket::PORTALLOCATOR_DISABLE_TCP); |
| 1114 | 1155 |
| 1115 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1156 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 1116 session_->StartGettingPorts(); | 1157 session_->StartGettingPorts(); |
| 1117 | 1158 |
| 1118 EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout); | 1159 EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout); |
| 1119 } | 1160 } |
| 1120 | 1161 |
| 1121 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port | 1162 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port |
| 1122 // is allocated for udp/stun/turn. In this test we should expect all local, | 1163 // is allocated for udp/stun/turn. In this test we should expect all local, |
| 1123 // stun and turn candidates. | 1164 // stun and turn candidates. |
| 1124 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurn) { | 1165 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurn) { |
| 1125 AddInterface(kClientAddr); | 1166 AddInterface(kClientAddr); |
| 1126 ResetWithStunServerAndNat(kStunAddr); | 1167 ResetWithStunServerAndNat(kStunAddr); |
| 1127 | 1168 |
| 1128 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1169 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
| 1129 | 1170 |
| 1130 allocator_->set_flags(allocator().flags() | | 1171 allocator_->set_flags(allocator().flags() | |
| 1131 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1172 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
| 1132 cricket::PORTALLOCATOR_DISABLE_TCP); | 1173 cricket::PORTALLOCATOR_DISABLE_TCP); |
| 1133 | 1174 |
| 1134 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1175 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 1135 session_->StartGettingPorts(); | 1176 session_->StartGettingPorts(); |
| 1136 | 1177 |
| 1137 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1178 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); |
| 1138 ASSERT_EQ(2U, ports_.size()); | 1179 ASSERT_EQ(2U, ports_.size()); |
| 1139 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1180 EXPECT_PRED5(CheckCandidate, candidates_[0], |
| 1140 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | 1181 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
| 1182 kClientAddr); | |
| 1141 EXPECT_PRED5(CheckCandidate, candidates_[1], | 1183 EXPECT_PRED5(CheckCandidate, candidates_[1], |
| 1142 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", | 1184 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", |
| 1143 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); | 1185 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); |
| 1144 EXPECT_PRED5(CheckCandidate, candidates_[2], | 1186 EXPECT_PRED5(CheckCandidate, candidates_[2], |
| 1145 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 1187 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
| 1146 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1188 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
| 1147 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1189 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 1148 EXPECT_EQ(3U, candidates_.size()); | 1190 EXPECT_EQ(3U, candidates_.size()); |
| 1149 // Local port will be created first and then TURN port. | 1191 // Local port will be created first and then TURN port. |
| 1150 EXPECT_EQ(2U, ports_[0]->Candidates().size()); | 1192 EXPECT_EQ(2U, ports_[0]->Candidates().size()); |
| 1151 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | 1193 EXPECT_EQ(1U, ports_[1]->Candidates().size()); |
| 1152 } | 1194 } |
| 1153 | 1195 |
| 1154 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled and the TURN | 1196 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled and the TURN |
| 1155 // server is also used as the STUN server, we should get 'local', 'stun', and | 1197 // server is also used as the STUN server, we should get 'local', 'stun', and |
| 1156 // 'relay' candidates. | 1198 // 'relay' candidates. |
| 1157 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) { | 1199 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) { |
| 1158 AddInterface(kClientAddr); | 1200 AddInterface(kClientAddr); |
| 1159 // Use an empty SocketAddress to add a NAT without STUN server. | 1201 // Use an empty SocketAddress to add a NAT without STUN server. |
| 1160 ResetWithStunServerAndNat(SocketAddress()); | 1202 ResetWithStunServerAndNat(SocketAddress()); |
| 1161 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1203 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
| 1162 | 1204 |
| 1163 // Must set the step delay to 0 to make sure the relay allocation phase is | 1205 // Must set the step delay to 0 to make sure the relay allocation phase is |
| 1164 // started before the STUN candidates are obtained, so that the STUN binding | 1206 // started before the STUN candidates are obtained, so that the STUN binding |
| 1165 // response is processed when both StunPort and TurnPort exist to reproduce | 1207 // response is processed when both StunPort and TurnPort exist to reproduce |
| 1166 // webrtc issue 3537. | 1208 // webrtc issue 3537. |
| 1167 allocator_->set_step_delay(0); | 1209 allocator_->set_step_delay(0); |
| 1168 allocator_->set_flags(allocator().flags() | | 1210 allocator_->set_flags(allocator().flags() | |
| 1169 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1211 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
| 1170 cricket::PORTALLOCATOR_DISABLE_TCP); | 1212 cricket::PORTALLOCATOR_DISABLE_TCP); |
| 1171 | 1213 |
| 1172 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1214 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 1173 session_->StartGettingPorts(); | 1215 session_->StartGettingPorts(); |
| 1174 | 1216 |
| 1175 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); | 1217 ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); |
| 1176 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1218 EXPECT_PRED5(CheckCandidate, candidates_[0], |
| 1177 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | 1219 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
| 1220 kClientAddr); | |
| 1178 EXPECT_PRED5(CheckCandidate, candidates_[1], | 1221 EXPECT_PRED5(CheckCandidate, candidates_[1], |
| 1179 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", | 1222 cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", |
| 1180 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); | 1223 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); |
| 1181 EXPECT_PRED5(CheckCandidate, candidates_[2], | 1224 EXPECT_PRED5(CheckCandidate, candidates_[2], |
| 1182 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", | 1225 cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
| 1183 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1226 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
| 1184 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); | 1227 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); |
| 1185 | 1228 |
| 1186 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1229 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 1187 EXPECT_EQ(3U, candidates_.size()); | 1230 EXPECT_EQ(3U, candidates_.size()); |
| 1188 // Local port will be created first and then TURN port. | 1231 // Local port will be created first and then TURN port. |
| 1189 EXPECT_EQ(2U, ports_[0]->Candidates().size()); | 1232 EXPECT_EQ(2U, ports_[0]->Candidates().size()); |
| 1190 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | 1233 EXPECT_EQ(1U, ports_[1]->Candidates().size()); |
| 1191 } | 1234 } |
| 1192 | 1235 |
| 1193 // Test that when only a TCP TURN server is available, we do NOT use it as | 1236 // Test that when only a TCP TURN server is available, we do NOT use it as |
| 1194 // a UDP STUN server, as this could leak our IP address. Thus we should only | 1237 // a UDP STUN server, as this could leak our IP address. Thus we should only |
| 1195 // expect two ports, a UDPPort and TurnPort. | 1238 // expect two ports, a UDPPort and TurnPort. |
| 1196 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { | 1239 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { |
| 1197 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); | 1240 turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); |
| 1198 AddInterface(kClientAddr); | 1241 AddInterface(kClientAddr); |
| 1199 ResetWithStunServerAndNat(rtc::SocketAddress()); | 1242 ResetWithStunServerAndNat(rtc::SocketAddress()); |
| 1200 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr); | 1243 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr); |
| 1201 | 1244 |
| 1202 allocator_->set_flags(allocator().flags() | | 1245 allocator_->set_flags(allocator().flags() | |
| 1203 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1246 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
| 1204 cricket::PORTALLOCATOR_DISABLE_TCP); | 1247 cricket::PORTALLOCATOR_DISABLE_TCP); |
| 1205 | 1248 |
| 1206 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1249 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1218 EXPECT_EQ(2U, candidates_.size()); | 1261 EXPECT_EQ(2U, candidates_.size()); |
| 1219 EXPECT_EQ(1U, ports_[0]->Candidates().size()); | 1262 EXPECT_EQ(1U, ports_[0]->Candidates().size()); |
| 1220 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | 1263 EXPECT_EQ(1U, ports_[1]->Candidates().size()); |
| 1221 } | 1264 } |
| 1222 | 1265 |
| 1223 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the | 1266 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the |
| 1224 // TURN server is used as the STUN server and we get 'local', 'stun', and | 1267 // TURN server is used as the STUN server and we get 'local', 'stun', and |
| 1225 // 'relay' candidates. | 1268 // 'relay' candidates. |
| 1226 // TODO(deadbeef): Remove this test when support for non-shared socket mode | 1269 // TODO(deadbeef): Remove this test when support for non-shared socket mode |
| 1227 // is removed. | 1270 // is removed. |
| 1228 TEST_F(PortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { | 1271 TEST_F(BasicPortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { |
| 1229 AddInterface(kClientAddr); | 1272 AddInterface(kClientAddr); |
| 1230 // Use an empty SocketAddress to add a NAT without STUN server. | 1273 // Use an empty SocketAddress to add a NAT without STUN server. |
| 1231 ResetWithStunServerAndNat(SocketAddress()); | 1274 ResetWithStunServerAndNat(SocketAddress()); |
| 1232 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1275 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
| 1233 | 1276 |
| 1234 allocator_->set_flags(allocator().flags() | | 1277 allocator_->set_flags(allocator().flags() | |
| 1235 cricket::PORTALLOCATOR_DISABLE_TCP); | 1278 cricket::PORTALLOCATOR_DISABLE_TCP); |
| 1236 | 1279 |
| 1237 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1280 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 1238 session_->StartGettingPorts(); | 1281 session_->StartGettingPorts(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1254 | 1297 |
| 1255 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1298 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 1256 EXPECT_EQ(3U, candidates_.size()); | 1299 EXPECT_EQ(3U, candidates_.size()); |
| 1257 EXPECT_EQ(1U, ports_[0]->Candidates().size()); | 1300 EXPECT_EQ(1U, ports_[0]->Candidates().size()); |
| 1258 EXPECT_EQ(1U, ports_[1]->Candidates().size()); | 1301 EXPECT_EQ(1U, ports_[1]->Candidates().size()); |
| 1259 EXPECT_EQ(1U, ports_[2]->Candidates().size()); | 1302 EXPECT_EQ(1U, ports_[2]->Candidates().size()); |
| 1260 } | 1303 } |
| 1261 | 1304 |
| 1262 // Test that even when both a STUN and TURN server are configured, the TURN | 1305 // Test that even when both a STUN and TURN server are configured, the TURN |
| 1263 // server is used as a STUN server and we get a 'stun' candidate. | 1306 // server is used as a STUN server and we get a 'stun' candidate. |
| 1264 TEST_F(PortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { | 1307 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { |
| 1265 AddInterface(kClientAddr); | 1308 AddInterface(kClientAddr); |
| 1266 // Configure with STUN server but destroy it, so we can ensure that it's | 1309 // Configure with STUN server but destroy it, so we can ensure that it's |
| 1267 // the TURN server actually being used as a STUN server. | 1310 // the TURN server actually being used as a STUN server. |
| 1268 ResetWithStunServerAndNat(kStunAddr); | 1311 ResetWithStunServerAndNat(kStunAddr); |
| 1269 stun_server_.reset(); | 1312 stun_server_.reset(); |
| 1270 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); | 1313 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
| 1271 | 1314 |
| 1272 allocator_->set_flags(allocator().flags() | | 1315 allocator_->set_flags(allocator().flags() | |
| 1273 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | | 1316 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | |
| 1274 cricket::PORTALLOCATOR_DISABLE_TCP); | 1317 cricket::PORTALLOCATOR_DISABLE_TCP); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1288 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); | 1331 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); |
| 1289 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); | 1332 EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); |
| 1290 | 1333 |
| 1291 // Don't bother waiting for STUN timeout, since we already verified | 1334 // Don't bother waiting for STUN timeout, since we already verified |
| 1292 // that we got a STUN candidate from the TURN server. | 1335 // that we got a STUN candidate from the TURN server. |
| 1293 } | 1336 } |
| 1294 | 1337 |
| 1295 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled | 1338 // This test verifies when PORTALLOCATOR_ENABLE_SHARED_SOCKET flag is enabled |
| 1296 // and fail to generate STUN candidate, local UDP candidate is generated | 1339 // and fail to generate STUN candidate, local UDP candidate is generated |
| 1297 // properly. | 1340 // properly. |
| 1298 TEST_F(PortAllocatorTest, TestSharedSocketNoUdpAllowed) { | 1341 TEST_F(BasicPortAllocatorTest, TestSharedSocketNoUdpAllowed) { |
| 1299 allocator().set_flags(allocator().flags() | | 1342 allocator().set_flags(allocator().flags() | |
| 1300 cricket::PORTALLOCATOR_DISABLE_RELAY | | 1343 cricket::PORTALLOCATOR_DISABLE_RELAY | |
| 1301 cricket::PORTALLOCATOR_DISABLE_TCP | | 1344 cricket::PORTALLOCATOR_DISABLE_TCP | |
| 1302 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1345 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
| 1303 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); | 1346 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); |
| 1304 AddInterface(kClientAddr); | 1347 AddInterface(kClientAddr); |
| 1305 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1348 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 1306 session_->StartGettingPorts(); | 1349 session_->StartGettingPorts(); |
| 1307 ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); | 1350 ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); |
| 1308 EXPECT_EQ(1U, candidates_.size()); | 1351 EXPECT_EQ(1U, candidates_.size()); |
| 1309 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1352 EXPECT_PRED5(CheckCandidate, candidates_[0], |
| 1310 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", kClientAddr); | 1353 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
| 1354 kClientAddr); | |
| 1311 // STUN timeout is 9sec. We need to wait to get candidate done signal. | 1355 // STUN timeout is 9sec. We need to wait to get candidate done signal. |
| 1312 EXPECT_TRUE_WAIT(candidate_allocation_done_, 10000); | 1356 EXPECT_TRUE_WAIT(candidate_allocation_done_, 10000); |
| 1313 EXPECT_EQ(1U, candidates_.size()); | 1357 EXPECT_EQ(1U, candidates_.size()); |
| 1314 } | 1358 } |
| 1315 | 1359 |
| 1316 // Test that when the NetworkManager doesn't have permission to enumerate | 1360 // Test that when the NetworkManager doesn't have permission to enumerate |
| 1317 // adapters, the PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified | 1361 // adapters, the PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified |
| 1318 // automatically. | 1362 // automatically. |
| 1319 TEST_F(PortAllocatorTest, TestNetworkPermissionBlocked) { | 1363 TEST_F(BasicPortAllocatorTest, TestNetworkPermissionBlocked) { |
| 1320 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(), | 1364 network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(), |
| 1321 rtc::IPAddress()); | 1365 rtc::IPAddress()); |
| 1322 network_manager_.set_enumeration_permission( | 1366 network_manager_.set_enumeration_permission( |
| 1323 rtc::NetworkManager::ENUMERATION_BLOCKED); | 1367 rtc::NetworkManager::ENUMERATION_BLOCKED); |
| 1324 allocator().set_flags(allocator().flags() | | 1368 allocator().set_flags(allocator().flags() | |
| 1325 cricket::PORTALLOCATOR_DISABLE_RELAY | | 1369 cricket::PORTALLOCATOR_DISABLE_RELAY | |
| 1326 cricket::PORTALLOCATOR_DISABLE_TCP | | 1370 cricket::PORTALLOCATOR_DISABLE_TCP | |
| 1327 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1371 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
| 1328 EXPECT_EQ(0U, allocator_->flags() & | 1372 EXPECT_EQ(0U, allocator_->flags() & |
| 1329 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); | 1373 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); |
| 1330 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1374 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 1331 EXPECT_EQ(0U, session_->flags() & | 1375 EXPECT_EQ(0U, session_->flags() & |
| 1332 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); | 1376 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); |
| 1333 session_->StartGettingPorts(); | 1377 session_->StartGettingPorts(); |
| 1334 EXPECT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); | 1378 EXPECT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); |
| 1335 EXPECT_EQ(1U, candidates_.size()); | 1379 EXPECT_EQ(1U, candidates_.size()); |
| 1336 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1380 EXPECT_PRED5(CheckCandidate, candidates_[0], |
| 1337 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 1381 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
| 1338 kPrivateAddr); | 1382 kPrivateAddr); |
| 1339 EXPECT_TRUE((session_->flags() & | 1383 EXPECT_NE(0U, session_->flags() & |
| 1340 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) != 0); | 1384 cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); |
| 1341 } | 1385 } |
| 1342 | 1386 |
| 1343 // This test verifies allocator can use IPv6 addresses along with IPv4. | 1387 // This test verifies allocator can use IPv6 addresses along with IPv4. |
| 1344 TEST_F(PortAllocatorTest, TestEnableIPv6Addresses) { | 1388 TEST_F(BasicPortAllocatorTest, TestEnableIPv6Addresses) { |
| 1345 allocator().set_flags(allocator().flags() | | 1389 allocator().set_flags(allocator().flags() | |
| 1346 cricket::PORTALLOCATOR_DISABLE_RELAY | | 1390 cricket::PORTALLOCATOR_DISABLE_RELAY | |
| 1347 cricket::PORTALLOCATOR_ENABLE_IPV6 | | 1391 cricket::PORTALLOCATOR_ENABLE_IPV6 | |
| 1348 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); | 1392 cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
| 1349 AddInterface(kClientIPv6Addr); | 1393 AddInterface(kClientIPv6Addr); |
| 1350 AddInterface(kClientAddr); | 1394 AddInterface(kClientAddr); |
| 1351 allocator_->set_step_delay(cricket::kMinimumStepDelay); | 1395 allocator_->set_step_delay(cricket::kMinimumStepDelay); |
| 1352 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1396 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 1353 session_->StartGettingPorts(); | 1397 session_->StartGettingPorts(); |
| 1354 ASSERT_EQ_WAIT(4U, ports_.size(), kDefaultAllocationTimeout); | 1398 ASSERT_EQ_WAIT(4U, ports_.size(), kDefaultAllocationTimeout); |
| 1355 EXPECT_EQ(4U, candidates_.size()); | 1399 EXPECT_EQ(4U, candidates_.size()); |
| 1356 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); | 1400 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
| 1357 EXPECT_PRED5(CheckCandidate, candidates_[0], | 1401 EXPECT_PRED5(CheckCandidate, candidates_[0], |
| 1358 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 1402 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
| 1359 kClientIPv6Addr); | 1403 kClientIPv6Addr); |
| 1360 EXPECT_PRED5(CheckCandidate, candidates_[1], | 1404 EXPECT_PRED5(CheckCandidate, candidates_[1], |
| 1361 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", | 1405 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
| 1362 kClientAddr); | 1406 kClientAddr); |
| 1363 EXPECT_PRED5(CheckCandidate, candidates_[2], | 1407 EXPECT_PRED5(CheckCandidate, candidates_[2], |
| 1364 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", | 1408 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", |
| 1365 kClientIPv6Addr); | 1409 kClientIPv6Addr); |
| 1366 EXPECT_PRED5(CheckCandidate, candidates_[3], | 1410 EXPECT_PRED5(CheckCandidate, candidates_[3], |
| 1367 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", | 1411 cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", |
| 1368 kClientAddr); | 1412 kClientAddr); |
| 1369 EXPECT_EQ(4U, candidates_.size()); | 1413 EXPECT_EQ(4U, candidates_.size()); |
| 1370 } | 1414 } |
| 1371 | 1415 |
| 1372 TEST_F(PortAllocatorTest, TestStopGettingPorts) { | 1416 TEST_F(BasicPortAllocatorTest, TestStopGettingPorts) { |
| 1373 AddInterface(kClientAddr); | 1417 AddInterface(kClientAddr); |
| 1374 allocator_->set_step_delay(cricket::kDefaultStepDelay); | 1418 allocator_->set_step_delay(cricket::kDefaultStepDelay); |
| 1375 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1419 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 1376 session_->StartGettingPorts(); | 1420 session_->StartGettingPorts(); |
| 1377 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 1421 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); |
| 1378 EXPECT_EQ(2U, ports_.size()); | 1422 EXPECT_EQ(2U, ports_.size()); |
| 1379 session_->StopGettingPorts(); | 1423 session_->StopGettingPorts(); |
| 1380 EXPECT_TRUE_WAIT(candidate_allocation_done_, 1000); | 1424 EXPECT_TRUE_WAIT(candidate_allocation_done_, 1000); |
| 1381 | 1425 |
| 1382 // After stopping getting ports, adding a new interface will not start | 1426 // After stopping getting ports, adding a new interface will not start |
| 1383 // getting ports again. | 1427 // getting ports again. |
| 1384 candidates_.clear(); | 1428 candidates_.clear(); |
| 1385 ports_.clear(); | 1429 ports_.clear(); |
| 1386 candidate_allocation_done_ = false; | 1430 candidate_allocation_done_ = false; |
| 1387 network_manager_.AddInterface(kClientAddr2); | 1431 network_manager_.AddInterface(kClientAddr2); |
| 1388 rtc::Thread::Current()->ProcessMessages(1000); | 1432 rtc::Thread::Current()->ProcessMessages(1000); |
| 1389 EXPECT_EQ(0U, candidates_.size()); | 1433 EXPECT_EQ(0U, candidates_.size()); |
| 1390 EXPECT_EQ(0U, ports_.size()); | 1434 EXPECT_EQ(0U, ports_.size()); |
| 1391 } | 1435 } |
| 1392 | 1436 |
| 1393 TEST_F(PortAllocatorTest, TestClearGettingPorts) { | 1437 TEST_F(BasicPortAllocatorTest, TestClearGettingPorts) { |
| 1394 AddInterface(kClientAddr); | 1438 AddInterface(kClientAddr); |
| 1395 allocator_->set_step_delay(cricket::kDefaultStepDelay); | 1439 allocator_->set_step_delay(cricket::kDefaultStepDelay); |
| 1396 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); | 1440 EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 1397 session_->StartGettingPorts(); | 1441 session_->StartGettingPorts(); |
| 1398 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 1442 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); |
| 1399 EXPECT_EQ(2U, ports_.size()); | 1443 EXPECT_EQ(2U, ports_.size()); |
| 1400 session_->ClearGettingPorts(); | 1444 session_->ClearGettingPorts(); |
| 1401 WAIT(candidate_allocation_done_, 1000); | 1445 WAIT(candidate_allocation_done_, 1000); |
| 1402 EXPECT_FALSE(candidate_allocation_done_); | 1446 EXPECT_FALSE(candidate_allocation_done_); |
| 1403 | 1447 |
| 1404 // After clearing getting ports, adding a new interface will start getting | 1448 // After clearing getting ports, adding a new interface will start getting |
| 1405 // ports again. | 1449 // ports again. |
| 1406 candidates_.clear(); | 1450 candidates_.clear(); |
| 1407 ports_.clear(); | 1451 ports_.clear(); |
| 1408 candidate_allocation_done_ = false; | 1452 candidate_allocation_done_ = false; |
| 1409 network_manager_.AddInterface(kClientAddr2); | 1453 network_manager_.AddInterface(kClientAddr2); |
| 1410 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); | 1454 ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); |
| 1411 EXPECT_EQ(2U, ports_.size()); | 1455 EXPECT_EQ(2U, ports_.size()); |
| 1412 } | 1456 } |
| 1457 | |
| 1458 // Test that the ports and candidates are updated with new ufrag/pwd/etc. when | |
| 1459 // a pooled session is taken out of the pool. | |
| 1460 TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) { | |
| 1461 AddInterface(kClientAddr); | |
| 1462 // Set candidate pool size to 1. | |
|
pthatcher1
2016/05/05 21:51:25
int pool_size = 1; would be more clear.
Taylor Brandstetter
2016/05/06 03:53:35
Done.
| |
| 1463 allocator_->SetConfiguration(allocator_->stun_servers(), | |
| 1464 allocator_->turn_servers(), 1); | |
| 1465 const cricket::PortAllocatorSession* peeked_session = | |
| 1466 allocator_->PeekPooledSession(); | |
| 1467 ASSERT_NE(nullptr, peeked_session); | |
| 1468 EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), | |
| 1469 kDefaultAllocationTimeout); | |
| 1470 // Expect that when GetPooledSession is called, | |
| 1471 // UpdateTransportInformationInternal will be called and the | |
| 1472 // BasicPortAllocatorSession will update the ufrag/pwd of ports and | |
| 1473 // candidates. | |
| 1474 session_.reset( | |
| 1475 allocator_->GetPooledSession(kContentName, 1, kIceUfrag0, kIcePwd0)); | |
| 1476 ASSERT_NE(nullptr, session_.get()); | |
| 1477 auto ready_ports = session_->ReadyPorts(); | |
| 1478 auto candidates = session_->ReadyCandidates(); | |
| 1479 EXPECT_FALSE(ready_ports.empty()); | |
| 1480 EXPECT_FALSE(candidates.empty()); | |
| 1481 for (const cricket::PortInterface* port_interface : ready_ports) { | |
| 1482 const cricket::Port* port = | |
| 1483 static_cast<const cricket::Port*>(port_interface); | |
| 1484 EXPECT_EQ(kContentName, port->content_name()); | |
| 1485 EXPECT_EQ(1, port->component()); | |
| 1486 EXPECT_EQ(kIceUfrag0, port->username_fragment()); | |
| 1487 EXPECT_EQ(kIcePwd0, port->password()); | |
| 1488 } | |
| 1489 for (const cricket::Candidate& candidate : candidates) { | |
| 1490 EXPECT_EQ(1, candidate.component()); | |
| 1491 EXPECT_EQ(kIceUfrag0, candidate.username()); | |
| 1492 EXPECT_EQ(kIcePwd0, candidate.password()); | |
| 1493 } | |
| 1494 } | |
| OLD | NEW |