diff --git a/webrtc/api/peerconnectioninterface_unittest.cc b/webrtc/api/peerconnectioninterface_unittest.cc index 445f0257c1..d2f0ad1c56 100644 --- a/webrtc/api/peerconnectioninterface_unittest.cc +++ b/webrtc/api/peerconnectioninterface_unittest.cc @@ -1058,7 +1058,6 @@ TEST_F(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) { EXPECT_EQ(1UL, session->stun_servers().size()); EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6); EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP); - EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); } TEST_F(PeerConnectionInterfaceTest, AddStreams) { @@ -1973,14 +1972,13 @@ TEST_F(PeerConnectionInterfaceTest, server.uri = kStunAddressOnly; config.servers.push_back(server); config.type = PeerConnectionInterface::kRelay; - CreatePeerConnection(config, nullptr); + EXPECT_TRUE(pc_->SetConfiguration(config)); const cricket::FakePortAllocatorSession* session = static_cast( port_allocator_->GetPooledSession()); ASSERT_NE(nullptr, session); EXPECT_EQ(1UL, session->stun_servers().size()); - EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); } // Test that PeerConnection::Close changes the states to closed and all remote diff --git a/webrtc/p2p/base/fakeportallocator.h b/webrtc/p2p/base/fakeportallocator.h index 6730d1ebb8..0da50d3d22 100644 --- a/webrtc/p2p/base/fakeportallocator.h +++ b/webrtc/p2p/base/fakeportallocator.h @@ -103,11 +103,14 @@ class FakePortAllocatorSession : public PortAllocatorSession { running_(false), port_config_count_(0), stun_servers_(allocator->stun_servers()), - turn_servers_(allocator->turn_servers()), - candidate_filter_(allocator->candidate_filter()) { + turn_servers_(allocator->turn_servers()) { network_.AddIP(rtc::IPAddress(INADDR_LOOPBACK)); } + void SetCandidateFilter(uint32_t filter) override { + candidate_filter_ = filter; + } + void StartGettingPorts() override { if (!port_) { port_.reset(TestUDPPort::Create(worker_thread_, factory_, &network_, @@ -181,7 +184,7 @@ class FakePortAllocatorSession : public PortAllocatorSession { bool allocation_done_ = false; ServerAddresses stun_servers_; std::vector turn_servers_; - uint32_t candidate_filter_; + uint32_t candidate_filter_ = CF_ALL; int transport_info_update_count_ = 0; }; diff --git a/webrtc/p2p/base/port.cc b/webrtc/p2p/base/port.cc index bd7368bf3a..15da8f95ae 100644 --- a/webrtc/p2p/base/port.cc +++ b/webrtc/p2p/base/port.cc @@ -150,8 +150,7 @@ Port::Port(rtc::Thread* thread, enable_port_packets_(false), ice_role_(ICEROLE_UNKNOWN), tiebreaker_(0), - shared_socket_(true), - candidate_filter_(CF_ALL) { + shared_socket_(true) { Construct(); } @@ -180,8 +179,7 @@ Port::Port(rtc::Thread* thread, enable_port_packets_(false), ice_role_(ICEROLE_UNKNOWN), tiebreaker_(0), - shared_socket_(false), - candidate_filter_(CF_ALL) { + shared_socket_(false) { ASSERT(factory_ != NULL); Construct(); } diff --git a/webrtc/p2p/base/port.h b/webrtc/p2p/base/port.h index e72e9dcc31..c850d31edc 100644 --- a/webrtc/p2p/base/port.h +++ b/webrtc/p2p/base/port.h @@ -293,9 +293,6 @@ class Port : public PortInterface, public rtc::MessageHandler, // Returns the index of the new local candidate. size_t AddPrflxCandidate(const Candidate& local); - void set_candidate_filter(uint32_t candidate_filter) { - candidate_filter_ = candidate_filter; - } int16_t network_cost() const { return network_cost_; } protected: @@ -349,8 +346,6 @@ class Port : public PortInterface, public rtc::MessageHandler, return rtc::DSCP_NO_CHANGE; } - uint32_t candidate_filter() { return candidate_filter_; } - private: void Construct(); // Called when one of our connections deletes itself. @@ -398,12 +393,6 @@ class Port : public PortInterface, public rtc::MessageHandler, std::string user_agent_; rtc::ProxyInfo proxy_; - // Candidate filter is pushed down to Port such that each Port could - // make its own decision on how to create candidates. For example, - // when IceTransportsType is set to relay, both RelayPort and - // TurnPort will hide raddr to avoid local address leakage. - uint32_t candidate_filter_; - // A virtual cost perceived by the user, usually based on the network type // (WiFi. vs. Cellular). It takes precedence over the priority when // comparing two connections. diff --git a/webrtc/p2p/base/portallocator.cc b/webrtc/p2p/base/portallocator.cc index fdf213b311..f9f87b007f 100644 --- a/webrtc/p2p/base/portallocator.cc +++ b/webrtc/p2p/base/portallocator.cc @@ -71,8 +71,10 @@ std::unique_ptr PortAllocator::CreateSession( int component, const std::string& ice_ufrag, const std::string& ice_pwd) { - return std::unique_ptr( + auto session = std::unique_ptr( CreateSessionInternal(content_name, component, ice_ufrag, ice_pwd)); + session->SetCandidateFilter(candidate_filter()); + return session; } std::unique_ptr PortAllocator::TakePooledSession( @@ -88,6 +90,9 @@ std::unique_ptr PortAllocator::TakePooledSession( std::unique_ptr ret = std::move(pooled_sessions_.front()); ret->SetIceParameters(content_name, component, ice_ufrag, ice_pwd); + // According to JSEP, a pooled session should filter candidates only after + // it's taken out of the pool. + ret->SetCandidateFilter(candidate_filter()); pooled_sessions_.pop_front(); return ret; } diff --git a/webrtc/p2p/base/portallocator.h b/webrtc/p2p/base/portallocator.h index 89a0e0aae8..75354bcad3 100644 --- a/webrtc/p2p/base/portallocator.h +++ b/webrtc/p2p/base/portallocator.h @@ -141,6 +141,13 @@ class PortAllocatorSession : public sigslot::has_slots<> { const std::string& ice_pwd() const { return ice_pwd_; } bool pooled() const { return ice_ufrag_.empty(); } + // Setting this filter should affect not only candidates gathered in the + // future, but candidates already gathered and ports already "ready", + // which would be returned by ReadyCandidates() and ReadyPorts(). + // + // Default filter should be CF_ALL. + virtual void SetCandidateFilter(uint32_t filter) = 0; + // Starts gathering STUN and Relay configurations. virtual void StartGettingPorts() = 0; virtual void StopGettingPorts() = 0; @@ -300,7 +307,6 @@ class PortAllocator : public sigslot::has_slots<> { uint32_t candidate_filter() { return candidate_filter_; } void set_candidate_filter(uint32_t filter) { - // TODO(mallinath) - Do transition check? candidate_filter_ = filter; } diff --git a/webrtc/p2p/base/portallocator_unittest.cc b/webrtc/p2p/base/portallocator_unittest.cc index 2e16725de4..dd845236c4 100644 --- a/webrtc/p2p/base/portallocator_unittest.cc +++ b/webrtc/p2p/base/portallocator_unittest.cc @@ -15,6 +15,7 @@ #include "webrtc/p2p/base/fakeportallocator.h" #include "webrtc/p2p/base/portallocator.h" +static const char kSessionId[] = "session id"; static const char kContentName[] = "test content"; // Based on ICE_UFRAG_LENGTH static const char kIceUfrag[] = "TESTICEUFRAG0000"; @@ -37,6 +38,20 @@ class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> { candidate_pool_size); } + std::unique_ptr CreateSession( + const std::string& sid, + const std::string& content_name, + int component, + const std::string& ice_ufrag, + const std::string& ice_pwd) { + return std::unique_ptr( + static_cast( + allocator_ + ->CreateSession(sid, content_name, component, ice_ufrag, + ice_pwd) + .release())); + } + const cricket::FakePortAllocatorSession* GetPooledSession() const { return static_cast( allocator_->GetPooledSession()); @@ -76,6 +91,19 @@ TEST_F(PortAllocatorTest, TestDefaults) { EXPECT_EQ(0, GetAllPooledSessionsReturnCount()); } +// Call CreateSession and verify that the parameters passed in and the +// candidate filter are applied as expected. +TEST_F(PortAllocatorTest, CreateSession) { + allocator_->set_candidate_filter(cricket::CF_RELAY); + auto session = CreateSession(kSessionId, kContentName, 1, kIceUfrag, kIcePwd); + ASSERT_NE(nullptr, session); + EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); + EXPECT_EQ(kContentName, session->content_name()); + EXPECT_EQ(1, session->component()); + EXPECT_EQ(kIceUfrag, session->ice_ufrag()); + EXPECT_EQ(kIcePwd, session->ice_pwd()); +} + TEST_F(PortAllocatorTest, SetConfigurationUpdatesIceServers) { cricket::ServerAddresses stun_servers_1 = {stun_server_1}; std::vector turn_servers_1 = {turn_server_1}; @@ -203,3 +231,17 @@ TEST_F(PortAllocatorTest, TakePooledSessionUpdatesIceParameters) { EXPECT_EQ(kIceUfrag, session->ice_ufrag()); EXPECT_EQ(kIcePwd, session->ice_pwd()); } + +// According to JSEP, candidate filtering should be done when the pooled +// candidates are surfaced to the application. This means when a pooled +// session is taken. So a pooled session should gather candidates +// unfiltered until it's returned by TakePooledSession. +TEST_F(PortAllocatorTest, TakePooledSessionUpdatesCandidateFilter) { + allocator_->set_candidate_filter(cricket::CF_RELAY); + SetConfigurationWithPoolSize(1); + auto peeked_session = GetPooledSession(); + ASSERT_NE(nullptr, peeked_session); + EXPECT_EQ(cricket::CF_ALL, peeked_session->candidate_filter()); + auto session = TakePooledSession(); + EXPECT_EQ(cricket::CF_RELAY, session->candidate_filter()); +} diff --git a/webrtc/p2p/base/stunport.cc b/webrtc/p2p/base/stunport.cc index 15c00957ef..9fc499ddc7 100644 --- a/webrtc/p2p/base/stunport.cc +++ b/webrtc/p2p/base/stunport.cc @@ -448,10 +448,7 @@ void UDPPort::OnStunBindingRequestSucceeded( rtc::SocketAddress related_address = socket_->GetLocalAddress(); // If we can't stamp the related address correctly, empty it to avoid leak. - if (!MaybeSetDefaultLocalAddress(&related_address) || - !(candidate_filter() & CF_HOST)) { - // If candidate filter doesn't have CF_HOST specified, empty raddr to - // avoid local address leakage. + if (!MaybeSetDefaultLocalAddress(&related_address)) { related_address = rtc::EmptySocketAddressWithFamily( related_address.family()); } diff --git a/webrtc/p2p/base/turnport.cc b/webrtc/p2p/base/turnport.cc index 0255395012..31c15fb3df 100644 --- a/webrtc/p2p/base/turnport.cc +++ b/webrtc/p2p/base/turnport.cc @@ -720,11 +720,6 @@ void TurnPort::OnAllocateSuccess(const rtc::SocketAddress& address, state_ = STATE_READY; rtc::SocketAddress related_address = stun_address; - if (!(candidate_filter() & CF_REFLEXIVE)) { - // If candidate filter only allows relay type of address, empty raddr to - // avoid local address leakage. - related_address = rtc::EmptySocketAddressWithFamily(stun_address.family()); - } // For relayed candidate, Base is the candidate itself. AddAddress(address, // Candidate address. diff --git a/webrtc/p2p/client/basicportallocator.cc b/webrtc/p2p/client/basicportallocator.cc index bf61bc88fc..14f7b13212 100644 --- a/webrtc/p2p/client/basicportallocator.cc +++ b/webrtc/p2p/client/basicportallocator.cc @@ -167,6 +167,29 @@ BasicPortAllocatorSession::~BasicPortAllocatorSession() { delete sequences_[i]; } +void BasicPortAllocatorSession::SetCandidateFilter(uint32_t filter) { + if (filter == candidate_filter_) { + return; + } + // We assume the filter will only change from "ALL" to something else. + RTC_DCHECK(candidate_filter_ == CF_ALL); + candidate_filter_ = filter; + for (PortData& port : ports_) { + if (!port.has_pairable_candidate()) { + continue; + } + const auto& candidates = port.port()->Candidates(); + // Setting a filter may cause a ready port to become non-ready + // if it no longer has any pairable candidates. + if (!std::any_of(candidates.begin(), candidates.end(), + [this, &port](const Candidate& candidate) { + return CandidatePairable(candidate, port.port()); + })) { + port.set_has_pairable_candidate(false); + } + } +} + void BasicPortAllocatorSession::StartGettingPorts() { network_thread_ = rtc::Thread::Current(); if (!socket_factory_) { @@ -195,7 +218,7 @@ void BasicPortAllocatorSession::ClearGettingPorts() { std::vector BasicPortAllocatorSession::ReadyPorts() const { std::vector ret; for (const PortData& port : ports_) { - if (port.ready() || port.complete()) { + if (port.has_pairable_candidate() && !port.error()) { ret.push_back(port.port()); } } @@ -214,12 +237,32 @@ std::vector BasicPortAllocatorSession::ReadyCandidates() const { !data.sequence()->ProtocolEnabled(pvalue)) { continue; } - candidates.push_back(candidate); + candidates.push_back(SanitizeRelatedAddress(candidate)); } } return candidates; } +Candidate BasicPortAllocatorSession::SanitizeRelatedAddress( + const Candidate& c) const { + Candidate copy = c; + // If adapter enumeration is disabled or host candidates are disabled, + // clear the raddr of STUN candidates to avoid local address leakage. + bool filter_stun_related_address = + ((flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) && + (flags() & PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE)) || + !(candidate_filter_ & CF_HOST); + // If the candidate filter doesn't allow reflexive addresses, empty TURN raddr + // to avoid reflexive address leakage. + bool filter_turn_related_address = !(candidate_filter_ & CF_REFLEXIVE); + if ((c.type() == STUN_PORT_TYPE && filter_stun_related_address) || + (c.type() == RELAY_PORT_TYPE && filter_turn_related_address)) { + copy.set_related_address( + rtc::EmptySocketAddressWithFamily(copy.address().family())); + } + return copy; +} + bool BasicPortAllocatorSession::CandidatesAllocationDone() const { // Done only if all required AllocationSequence objects // are created. @@ -483,17 +526,6 @@ void BasicPortAllocatorSession::AddAllocatedPort(Port* port, port->set_send_retransmit_count_attribute( (flags() & PORTALLOCATOR_ENABLE_STUN_RETRANSMIT_ATTRIBUTE) != 0); - // Push down the candidate_filter to individual port. - uint32_t candidate_filter = allocator_->candidate_filter(); - - // When adapter enumeration is disabled, disable CF_HOST at port level so - // local address is not leaked by stunport in the candidate's related address. - if ((flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) && - (flags() & PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE)) { - candidate_filter &= ~CF_HOST; - } - port->set_candidate_filter(candidate_filter); - PortData data(port, seq); ports_.push_back(data); @@ -529,44 +561,29 @@ void BasicPortAllocatorSession::OnCandidateReady( } ProtocolType pvalue; - bool candidate_signalable = CheckCandidateFilter(c); - - // When device enumeration is disabled (to prevent non-default IP addresses - // from leaking), we ping from some local candidates even though we don't - // signal them. However, if host candidates are also disabled (for example, to - // prevent even default IP addresses from leaking), we still don't want to - // ping from them, even if device enumeration is disabled. Thus, we check for - // both device enumeration and host candidates being disabled. - bool network_enumeration_disabled = c.address().IsAnyIP(); - bool can_ping_from_candidate = - (port->SharedSocket() || c.protocol() == TCP_PROTOCOL_NAME); - bool host_canidates_disabled = !(allocator_->candidate_filter() & CF_HOST); - - bool candidate_pairable = - candidate_signalable || - (network_enumeration_disabled && can_ping_from_candidate && - !host_canidates_disabled); bool candidate_protocol_enabled = StringToProto(c.protocol().c_str(), &pvalue) && data->sequence()->ProtocolEnabled(pvalue); - if (candidate_signalable && candidate_protocol_enabled) { + if (CheckCandidateFilter(c) && candidate_protocol_enabled) { std::vector candidates; - candidates.push_back(c); + candidates.push_back(SanitizeRelatedAddress(c)); SignalCandidatesReady(this, candidates); } - // Port has been made ready. Nothing to do here. - if (data->ready()) { + // Port has already been marked as having a pairable candidate. + // Nothing to do here. + if (data->has_pairable_candidate()) { return; } - // Move the port to the READY state, either because we have a usable candidate - // from the port, or simply because the port is bound to the any address and - // therefore has no host candidate. This will trigger the port to start - // creating candidate pairs (connections) and issue connectivity checks. - if (candidate_pairable) { - data->set_ready(); + // Mark that the port has a pairable candidate, either because we have a + // usable candidate from the port, or simply because the port is bound to the + // any address and therefore has no host candidate. This will trigger the port + // to start creating candidate pairs (connections) and issue connectivity + // checks. + if (CandidatePairable(c, port)) { + data->set_has_pairable_candidate(true); SignalPortReady(this, port); } } @@ -613,8 +630,9 @@ void BasicPortAllocatorSession::OnProtocolEnabled(AllocationSequence* seq, const std::vector& potentials = it->port()->Candidates(); for (size_t i = 0; i < potentials.size(); ++i) { - if (!CheckCandidateFilter(potentials[i])) + if (!CheckCandidateFilter(potentials[i])) { continue; + } ProtocolType pvalue; bool candidate_protocol_enabled = StringToProto(potentials[i].protocol().c_str(), &pvalue) && @@ -631,7 +649,7 @@ void BasicPortAllocatorSession::OnProtocolEnabled(AllocationSequence* seq, } bool BasicPortAllocatorSession::CheckCandidateFilter(const Candidate& c) const { - uint32_t filter = allocator_->candidate_filter(); + uint32_t filter = candidate_filter_; // When binding to any address, before sending packets out, the getsockname // returns all 0s, but after sending packets, it'll be the NIC used to @@ -661,6 +679,26 @@ bool BasicPortAllocatorSession::CheckCandidateFilter(const Candidate& c) const { return false; } +bool BasicPortAllocatorSession::CandidatePairable(const Candidate& c, + const Port* port) const { + bool candidate_signalable = CheckCandidateFilter(c); + + // When device enumeration is disabled (to prevent non-default IP addresses + // from leaking), we ping from some local candidates even though we don't + // signal them. However, if host candidates are also disabled (for example, to + // prevent even default IP addresses from leaking), we still don't want to + // ping from them, even if device enumeration is disabled. Thus, we check for + // both device enumeration and host candidates being disabled. + bool network_enumeration_disabled = c.address().IsAnyIP(); + bool can_ping_from_candidate = + (port->SharedSocket() || c.protocol() == TCP_PROTOCOL_NAME); + bool host_candidates_disabled = !(candidate_filter_ & CF_HOST); + + return candidate_signalable || + (network_enumeration_disabled && can_ping_from_candidate && + !host_candidates_disabled); +} + void BasicPortAllocatorSession::OnPortAllocationComplete( AllocationSequence* seq) { // Send candidate allocation complete signal if all ports are done. diff --git a/webrtc/p2p/client/basicportallocator.h b/webrtc/p2p/client/basicportallocator.h index 6a719c73bd..8ea66c431e 100644 --- a/webrtc/p2p/client/basicportallocator.h +++ b/webrtc/p2p/client/basicportallocator.h @@ -88,6 +88,7 @@ class BasicPortAllocatorSession : public PortAllocatorSession, rtc::Thread* network_thread() { return network_thread_; } rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } + void SetCandidateFilter(uint32_t filter) override; void StartGettingPorts() override; void StopGettingPorts() override; void ClearGettingPorts() override; @@ -113,36 +114,40 @@ class BasicPortAllocatorSession : public PortAllocatorSession, private: class PortData { public: - PortData() : port_(NULL), sequence_(NULL), state_(STATE_INIT) {} + PortData() {} PortData(Port* port, AllocationSequence* seq) - : port_(port), sequence_(seq), state_(STATE_INIT) { - } + : port_(port), sequence_(seq) {} Port* port() const { return port_; } AllocationSequence* sequence() const { return sequence_; } - bool ready() const { return state_ == STATE_READY; } + bool has_pairable_candidate() const { return has_pairable_candidate_; } bool complete() const { return state_ == STATE_COMPLETE; } bool error() const { return state_ == STATE_ERROR; } - void set_ready() { ASSERT(state_ == STATE_INIT); state_ = STATE_READY; } + void set_has_pairable_candidate(bool has_pairable_candidate) { + if (has_pairable_candidate) { + ASSERT(state_ == STATE_INPROGRESS); + } + has_pairable_candidate_ = has_pairable_candidate; + } void set_complete() { state_ = STATE_COMPLETE; } void set_error() { - ASSERT(state_ == STATE_INIT || state_ == STATE_READY); + ASSERT(state_ == STATE_INPROGRESS); state_ = STATE_ERROR; } private: enum State { - STATE_INIT, // No candidates allocated yet. - STATE_READY, // At least one candidate is ready for process. - STATE_COMPLETE, // All candidates allocated and ready for process. - STATE_ERROR // Error in gathering candidates. + STATE_INPROGRESS, // Still gathering candidates. + STATE_COMPLETE, // All candidates allocated and ready for process. + STATE_ERROR // Error in gathering candidates. }; - Port* port_; - AllocationSequence* sequence_; - State state_; + Port* port_ = nullptr; + AllocationSequence* sequence_ = nullptr; + State state_ = STATE_INPROGRESS; + bool has_pairable_candidate_ = false; }; void OnConfigReady(PortConfiguration* config); @@ -168,6 +173,10 @@ class BasicPortAllocatorSession : public PortAllocatorSession, void GetNetworks(std::vector* networks); bool CheckCandidateFilter(const Candidate& c) const; + bool CandidatePairable(const Candidate& c, const Port* port) const; + // Clear the related address according to the flags and candidate filter + // in order to avoid leaking any information. + Candidate SanitizeRelatedAddress(const Candidate& c) const; BasicPortAllocator* allocator_; rtc::Thread* network_thread_; @@ -180,6 +189,7 @@ class BasicPortAllocatorSession : public PortAllocatorSession, std::vector configs_; std::vector sequences_; std::vector ports_; + uint32_t candidate_filter_ = CF_ALL; friend class AllocationSequence; }; diff --git a/webrtc/p2p/client/basicportallocator_unittest.cc b/webrtc/p2p/client/basicportallocator_unittest.cc index fba7f9932c..024f46fffc 100644 --- a/webrtc/p2p/client/basicportallocator_unittest.cc +++ b/webrtc/p2p/client/basicportallocator_unittest.cc @@ -34,7 +34,6 @@ #include "webrtc/base/thread.h" #include "webrtc/base/virtualsocketserver.h" -using cricket::ServerAddresses; using rtc::IPAddress; using rtc::SocketAddress; using rtc::Thread; @@ -84,13 +83,11 @@ static const int kStunTimeoutMs = 15000; namespace cricket { // Helper for dumping candidates -std::ostream& operator<<(std::ostream& os, const cricket::Candidate& c) { +std::ostream& operator<<(std::ostream& os, const Candidate& c) { os << c.ToString(); return os; } -} // namespace cricket - class BasicPortAllocatorTest : public testing::Test, public sigslot::has_slots<> { public: @@ -101,8 +98,7 @@ class BasicPortAllocatorTest : public testing::Test, ss_scope_(fss_.get()), nat_factory_(vss_.get(), kNatUdpAddr, kNatTcpAddr), nat_socket_factory_(new rtc::BasicPacketSocketFactory(&nat_factory_)), - stun_server_( - cricket::TestStunServer::Create(Thread::Current(), kStunAddr)), + stun_server_(TestStunServer::Create(Thread::Current(), kStunAddr)), relay_server_(Thread::Current(), kRelayUdpIntAddr, kRelayUdpExtAddr, @@ -112,14 +108,14 @@ class BasicPortAllocatorTest : public testing::Test, kRelaySslTcpExtAddr), turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr), candidate_allocation_done_(false) { - cricket::ServerAddresses stun_servers; + ServerAddresses stun_servers; stun_servers.insert(kStunAddr); // Passing the addresses of GTURN servers will enable GTURN in // Basicportallocator. - allocator_.reset(new cricket::BasicPortAllocator( - &network_manager_, stun_servers, kRelayUdpIntAddr, kRelayTcpIntAddr, - kRelaySslTcpIntAddr)); - allocator_->set_step_delay(cricket::kMinimumStepDelay); + allocator_.reset(new BasicPortAllocator(&network_manager_, stun_servers, + kRelayUdpIntAddr, kRelayTcpIntAddr, + kRelaySslTcpIntAddr)); + allocator_->set_step_delay(kMinimumStepDelay); } void AddInterface(const SocketAddress& addr) { @@ -153,8 +149,8 @@ class BasicPortAllocatorTest : public testing::Test, } // Endpoint is on the public network. No STUN or TURN. void ResetWithNoServersOrNat() { - allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); - allocator_->set_step_delay(cricket::kMinimumStepDelay); + allocator_.reset(new BasicPortAllocator(&network_manager_)); + allocator_->set_step_delay(kMinimumStepDelay); } // Endpoint is behind a NAT, with STUN specified. void ResetWithStunServerAndNat(const rtc::SocketAddress& stun_server) { @@ -173,17 +169,17 @@ class BasicPortAllocatorTest : public testing::Test, void AddTurnServers(const rtc::SocketAddress& udp_turn, const rtc::SocketAddress& tcp_turn) { - cricket::RelayServerConfig turn_server(cricket::RELAY_TURN); - cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); + RelayServerConfig turn_server(RELAY_TURN); + RelayCredentials credentials(kTurnUsername, kTurnPassword); turn_server.credentials = credentials; if (!udp_turn.IsNil()) { turn_server.ports.push_back( - cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false)); + ProtocolAddress(kTurnUdpIntAddr, PROTO_UDP, false)); } if (!tcp_turn.IsNil()) { turn_server.ports.push_back( - cricket::ProtocolAddress(kTurnTcpIntAddr, cricket::PROTO_TCP, false)); + ProtocolAddress(kTurnTcpIntAddr, PROTO_TCP, false)); } allocator_->AddTurnServer(turn_server); } @@ -204,28 +200,26 @@ class BasicPortAllocatorTest : public testing::Test, return true; } - std::unique_ptr CreateSession( - const std::string& sid, - int component) { + std::unique_ptr CreateSession(const std::string& sid, + int component) { return CreateSession(sid, kContentName, component); } - std::unique_ptr CreateSession( + std::unique_ptr CreateSession( const std::string& sid, const std::string& content_name, int component) { return CreateSession(sid, content_name, component, kIceUfrag0, kIcePwd0); } - std::unique_ptr CreateSession( + std::unique_ptr CreateSession( const std::string& sid, const std::string& content_name, int component, const std::string& ice_ufrag, const std::string& ice_pwd) { - std::unique_ptr session = - allocator_->CreateSession(sid, content_name, component, ice_ufrag, - ice_pwd); + std::unique_ptr session = allocator_->CreateSession( + sid, content_name, component, ice_ufrag, ice_pwd); session->SignalPortReady.connect(this, &BasicPortAllocatorTest::OnPortReady); session->SignalCandidatesReady.connect( @@ -235,7 +229,7 @@ class BasicPortAllocatorTest : public testing::Test, return session; } - static bool CheckCandidate(const cricket::Candidate& c, + static bool CheckCandidate(const Candidate& c, int component, const std::string& type, const std::string& proto, @@ -251,7 +245,7 @@ class BasicPortAllocatorTest : public testing::Test, return (addr.port() >= min_port && addr.port() <= max_port); } - void OnCandidatesAllocationDone(cricket::PortAllocatorSession* session) { + void OnCandidatesAllocationDone(PortAllocatorSession* session) { // We should only get this callback once, except in the mux test where // we have multiple port allocation sessions. if (session == session_.get()) { @@ -264,7 +258,7 @@ class BasicPortAllocatorTest : public testing::Test, // Check if all ports allocated have send-buffer size |expected|. If // |expected| == -1, check if GetOptions returns SOCKET_ERROR. void CheckSendBufferSizesOfAllPorts(int expected) { - std::vector::iterator it; + std::vector::iterator it; for (it = ports_.begin(); it < ports_.end(); ++it) { int send_buffer_size; if (expected == -1) { @@ -292,11 +286,11 @@ class BasicPortAllocatorTest : public testing::Test, network_manager_.set_default_local_addresses(kPrivateAddr.ipaddr(), rtc::IPAddress()); if (!session_) { - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); } session_->set_flags(session_->flags() | - cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | - cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); + PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | + PORTALLOCATOR_ENABLE_SHARED_SOCKET); allocator().set_allow_tcp_listen(false); session_->StartGettingPorts(); EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); @@ -304,13 +298,13 @@ class BasicPortAllocatorTest : public testing::Test, uint32_t total_candidates = 0; if (!host_candidate_addr.IsNil()) { EXPECT_PRED5(CheckCandidate, candidates_[total_candidates], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", + ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", rtc::SocketAddress(kPrivateAddr.ipaddr(), 0)); ++total_candidates; } if (!stun_candidate_addr.IsNil()) { EXPECT_PRED5(CheckCandidate, candidates_[total_candidates], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", + ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", rtc::SocketAddress(stun_candidate_addr, 0)); rtc::IPAddress related_address = host_candidate_addr; if (host_candidate_addr.IsNil()) { @@ -323,7 +317,7 @@ class BasicPortAllocatorTest : public testing::Test, } if (!relay_candidate_udp_transport_addr.IsNil()) { EXPECT_PRED5(CheckCandidate, candidates_[total_candidates], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", + ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", rtc::SocketAddress(relay_candidate_udp_transport_addr, 0)); EXPECT_EQ(stun_candidate_addr, candidates_[total_candidates].related_address().ipaddr()); @@ -331,7 +325,7 @@ class BasicPortAllocatorTest : public testing::Test, } if (!relay_candidate_tcp_transport_addr.IsNil()) { EXPECT_PRED5(CheckCandidate, candidates_[total_candidates], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", + ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", rtc::SocketAddress(relay_candidate_tcp_transport_addr, 0)); EXPECT_EQ(stun_candidate_addr, candidates_[total_candidates].related_address().ipaddr()); @@ -343,10 +337,9 @@ class BasicPortAllocatorTest : public testing::Test, } protected: - cricket::BasicPortAllocator& allocator() { return *allocator_; } + BasicPortAllocator& allocator() { return *allocator_; } - void OnPortReady(cricket::PortAllocatorSession* ses, - cricket::PortInterface* port) { + void OnPortReady(PortAllocatorSession* ses, PortInterface* port) { LOG(LS_INFO) << "OnPortReady: " << port->ToString(); ports_.push_back(port); // Make sure the new port is added to ReadyPorts. @@ -354,25 +347,25 @@ class BasicPortAllocatorTest : public testing::Test, EXPECT_NE(ready_ports.end(), std::find(ready_ports.begin(), ready_ports.end(), port)); } - void OnCandidatesReady(cricket::PortAllocatorSession* ses, - const std::vector& candidates) { + void OnCandidatesReady(PortAllocatorSession* ses, + const std::vector& candidates) { for (size_t i = 0; i < candidates.size(); ++i) { LOG(LS_INFO) << "OnCandidatesReady: " << candidates[i].ToString(); candidates_.push_back(candidates[i]); } // Make sure the new candidates are added to Candidates. auto ses_candidates = ses->ReadyCandidates(); - for (const cricket::Candidate& candidate : candidates) { + for (const Candidate& candidate : candidates) { EXPECT_NE( ses_candidates.end(), std::find(ses_candidates.begin(), ses_candidates.end(), candidate)); } } - bool HasRelayAddress(const cricket::ProtocolAddress& proto_addr) { + bool HasRelayAddress(const ProtocolAddress& proto_addr) { for (size_t i = 0; i < allocator_->turn_servers().size(); ++i) { - cricket::RelayServerConfig server_config = allocator_->turn_servers()[i]; - cricket::PortList::const_iterator relay_port; + RelayServerConfig server_config = allocator_->turn_servers()[i]; + PortList::const_iterator relay_port; for (relay_port = server_config.ports.begin(); relay_port != server_config.ports.end(); ++relay_port) { if (proto_addr.address == relay_port->address && @@ -397,9 +390,9 @@ class BasicPortAllocatorTest : public testing::Test, if (!stun_server.IsNil()) { stun_servers.insert(stun_server); } - allocator_.reset(new cricket::BasicPortAllocator( + allocator_.reset(new BasicPortAllocator( &network_manager_, nat_socket_factory_.get(), stun_servers)); - allocator().set_step_delay(cricket::kMinimumStepDelay); + allocator().set_step_delay(kMinimumStepDelay); } std::unique_ptr pss_; @@ -409,14 +402,14 @@ class BasicPortAllocatorTest : public testing::Test, std::unique_ptr nat_server_; rtc::NATSocketFactory nat_factory_; std::unique_ptr nat_socket_factory_; - std::unique_ptr stun_server_; - cricket::TestRelayServer relay_server_; - cricket::TestTurnServer turn_server_; + std::unique_ptr stun_server_; + TestRelayServer relay_server_; + TestTurnServer turn_server_; rtc::FakeNetworkManager network_manager_; - std::unique_ptr allocator_; - std::unique_ptr session_; - std::vector ports_; - std::vector candidates_; + std::unique_ptr allocator_; + std::unique_ptr session_; + std::vector ports_; + std::vector candidates_; bool candidate_allocation_done_; }; @@ -425,17 +418,15 @@ TEST_F(BasicPortAllocatorTest, TestBasic) { EXPECT_EQ(&network_manager_, allocator().network_manager()); EXPECT_EQ(kStunAddr, *allocator().stun_servers().begin()); ASSERT_EQ(1u, allocator().turn_servers().size()); - EXPECT_EQ(cricket::RELAY_GTURN, allocator().turn_servers()[0].type); + EXPECT_EQ(RELAY_GTURN, allocator().turn_servers()[0].type); // Empty relay credentials are used for GTURN. EXPECT_TRUE(allocator().turn_servers()[0].credentials.username.empty()); EXPECT_TRUE(allocator().turn_servers()[0].credentials.password.empty()); - EXPECT_TRUE(HasRelayAddress( - cricket::ProtocolAddress(kRelayUdpIntAddr, cricket::PROTO_UDP))); - EXPECT_TRUE(HasRelayAddress( - cricket::ProtocolAddress(kRelayTcpIntAddr, cricket::PROTO_TCP))); - EXPECT_TRUE(HasRelayAddress( - cricket::ProtocolAddress(kRelaySslTcpIntAddr, cricket::PROTO_SSLTCP))); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(HasRelayAddress(ProtocolAddress(kRelayUdpIntAddr, PROTO_UDP))); + EXPECT_TRUE(HasRelayAddress(ProtocolAddress(kRelayTcpIntAddr, PROTO_TCP))); + EXPECT_TRUE( + HasRelayAddress(ProtocolAddress(kRelaySslTcpIntAddr, PROTO_SSLTCP))); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); EXPECT_FALSE(session_->CandidatesAllocationDone()); } @@ -451,14 +442,13 @@ TEST_F(BasicPortAllocatorTest, TestIgnoreOnlyLoopbackNetworkByDefault) { rtc::ADAPTER_TYPE_VPN); AddInterface(SocketAddress(IPAddress(0x12345604U), 0), "test_lo", rtc::ADAPTER_TYPE_LOOPBACK); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); - session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | - cricket::PORTALLOCATOR_DISABLE_RELAY | - cricket::PORTALLOCATOR_DISABLE_TCP); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); + session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | + PORTALLOCATOR_DISABLE_TCP); session_->StartGettingPorts(); EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); EXPECT_EQ(4U, candidates_.size()); - for (cricket::Candidate candidate : candidates_) { + for (Candidate candidate : candidates_) { EXPECT_LT(candidate.address().ip(), 0x12345604U); } } @@ -473,10 +463,9 @@ TEST_F(BasicPortAllocatorTest, TestIgnoreNetworksAccordingToIgnoreMask) { allocator_->SetNetworkIgnoreMask(rtc::ADAPTER_TYPE_ETHERNET | rtc::ADAPTER_TYPE_LOOPBACK | rtc::ADAPTER_TYPE_WIFI); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); - session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | - cricket::PORTALLOCATOR_DISABLE_RELAY | - cricket::PORTALLOCATOR_DISABLE_TCP); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); + session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | + PORTALLOCATOR_DISABLE_TCP); session_->StartGettingPorts(); EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); EXPECT_EQ(1U, candidates_.size()); @@ -485,7 +474,7 @@ TEST_F(BasicPortAllocatorTest, TestIgnoreNetworksAccordingToIgnoreMask) { // Tests that we allocator session not trying to allocate ports for every 250ms. TEST_F(BasicPortAllocatorTest, TestNoNetworkInterface) { - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); // Waiting for one second to make sure BasicPortAllocatorSession has not // called OnAllocate multiple times. In old behavior it's called every 250ms. @@ -500,10 +489,9 @@ TEST_F(BasicPortAllocatorTest, TestNoNetworkInterface) { TEST_F(BasicPortAllocatorTest, TestLoopbackNetworkInterface) { AddInterface(kLoopbackAddr, "test_loopback", rtc::ADAPTER_TYPE_LOOPBACK); allocator_->SetNetworkIgnoreMask(0); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); - session_->set_flags(cricket::PORTALLOCATOR_DISABLE_STUN | - cricket::PORTALLOCATOR_DISABLE_RELAY | - cricket::PORTALLOCATOR_DISABLE_TCP); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); + session_->set_flags(PORTALLOCATOR_DISABLE_STUN | PORTALLOCATOR_DISABLE_RELAY | + PORTALLOCATOR_DISABLE_TCP); session_->StartGettingPorts(); EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); EXPECT_EQ(1U, candidates_.size()); @@ -512,31 +500,24 @@ TEST_F(BasicPortAllocatorTest, TestLoopbackNetworkInterface) { // Tests that we can get all the desired addresses successfully. TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithMinimumStepDelay) { AddInterface(kClientAddr); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); EXPECT_EQ(4U, ports_.size()); - EXPECT_PRED5(CheckCandidate, candidates_[0], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", - kClientAddr); - EXPECT_PRED5(CheckCandidate, candidates_[1], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", - kClientAddr); - EXPECT_PRED5(CheckCandidate, candidates_[2], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", - kRelayUdpIntAddr); - EXPECT_PRED5(CheckCandidate, candidates_[3], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", - kRelayUdpExtAddr); - EXPECT_PRED5(CheckCandidate, candidates_[4], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", - kRelayTcpIntAddr); - EXPECT_PRED5(CheckCandidate, candidates_[5], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", - kClientAddr); - EXPECT_PRED5(CheckCandidate, candidates_[6], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "ssltcp", - kRelaySslTcpIntAddr); + EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, + "local", "udp", kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, + "stun", "udp", kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "udp", kRelayUdpIntAddr); + EXPECT_PRED5(CheckCandidate, candidates_[3], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "udp", kRelayUdpExtAddr); + EXPECT_PRED5(CheckCandidate, candidates_[4], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "tcp", kRelayTcpIntAddr); + EXPECT_PRED5(CheckCandidate, candidates_[5], ICE_CANDIDATE_COMPONENT_RTP, + "local", "tcp", kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[6], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "ssltcp", kRelaySslTcpIntAddr); EXPECT_TRUE(candidate_allocation_done_); } @@ -546,7 +527,7 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithMinimumStepDelay) { TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) { std::string if_name("test_net0"); AddInterface(kClientAddr, if_name); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); EXPECT_EQ(4U, ports_.size()); @@ -574,7 +555,7 @@ TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) { TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionStopped) { std::string if_name("test_net0"); AddInterface(kClientAddr, if_name); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); EXPECT_EQ(4U, ports_.size()); @@ -598,31 +579,26 @@ TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionStopped) { // Verify candidates with default step delay of 1sec. TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { AddInterface(kClientAddr); - allocator_->set_step_delay(cricket::kDefaultStepDelay); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + allocator_->set_step_delay(kDefaultStepDelay); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); EXPECT_EQ(2U, ports_.size()); ASSERT_EQ_WAIT(4U, candidates_.size(), 2000); EXPECT_EQ(3U, ports_.size()); - EXPECT_PRED5(CheckCandidate, candidates_[2], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", - kRelayUdpIntAddr); - EXPECT_PRED5(CheckCandidate, candidates_[3], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", - kRelayUdpExtAddr); + EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "udp", kRelayUdpIntAddr); + EXPECT_PRED5(CheckCandidate, candidates_[3], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "udp", kRelayUdpExtAddr); ASSERT_EQ_WAIT(6U, candidates_.size(), 1500); - EXPECT_PRED5(CheckCandidate, candidates_[4], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", - kRelayTcpIntAddr); - EXPECT_PRED5(CheckCandidate, candidates_[5], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", - kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[4], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "tcp", kRelayTcpIntAddr); + EXPECT_PRED5(CheckCandidate, candidates_[5], ICE_CANDIDATE_COMPONENT_RTP, + "local", "tcp", kClientAddr); EXPECT_EQ(4U, ports_.size()); ASSERT_EQ_WAIT(7U, candidates_.size(), 2000); - EXPECT_PRED5(CheckCandidate, candidates_[6], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "ssltcp", - kRelaySslTcpIntAddr); + EXPECT_PRED5(CheckCandidate, candidates_[6], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "ssltcp", kRelaySslTcpIntAddr); EXPECT_EQ(4U, ports_.size()); EXPECT_TRUE(candidate_allocation_done_); // If we Stop gathering now, we shouldn't get a second "done" callback. @@ -631,8 +607,7 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { TEST_F(BasicPortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) { AddInterface(kClientAddr); - EXPECT_TRUE( - CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP, cricket::CN_VIDEO)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP, CN_VIDEO)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); EXPECT_TRUE(candidate_allocation_done_); @@ -646,7 +621,7 @@ TEST_F(BasicPortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) { // Tests that we can get callback after StopGetAllPorts. TEST_F(BasicPortAllocatorTest, TestStopGetAllPorts) { AddInterface(kClientAddr); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); EXPECT_EQ(2U, ports_.size()); @@ -665,7 +640,7 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsPortRange) { EXPECT_TRUE(SetPortRange(0, 0)); // Check that a valid port range succeeds. EXPECT_TRUE(SetPortRange(kMinPort, kMaxPort)); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); EXPECT_EQ(4U, ports_.size()); @@ -683,7 +658,7 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsPortRange) { // Test that we don't crash or malfunction if we have no network adapters. TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoAdapters) { - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); rtc::Thread::Current()->ProcessMessages(100); // Without network adapter, we should not get any candidate. @@ -696,7 +671,7 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoAdapters) { TEST_F(BasicPortAllocatorTest, TestDisableAdapterEnumerationWithoutNatRelayTransportOnly) { ResetWithStunServerNoNat(kStunAddr); - allocator().set_candidate_filter(cricket::CF_RELAY); + allocator().set_candidate_filter(CF_RELAY); // Expect to see no ports and no candidates. CheckDisableAdapterEnumeration(0U, rtc::IPAddress(), rtc::IPAddress(), rtc::IPAddress(), rtc::IPAddress()); @@ -715,8 +690,8 @@ TEST_F(BasicPortAllocatorTest, // Enable IPv6 here. Since the network_manager doesn't have IPv6 default // address set and we have no IPv6 STUN server, there should be no IPv6 // candidates. - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); - session_->set_flags(cricket::PORTALLOCATOR_ENABLE_IPV6); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); + session_->set_flags(PORTALLOCATOR_ENABLE_IPV6); // Expect to see 3 ports for IPv4: HOST/STUN, TURN/UDP and TCP ports, 2 ports // for IPv6: HOST, and TCP. Only IPv4 candidates: a default private, STUN and @@ -729,7 +704,7 @@ TEST_F(BasicPortAllocatorTest, // Test that we should get a default private, STUN, TURN/UDP and TURN/TCP // candidates when both TURN/UDP and TURN/TCP servers are specified. TEST_F(BasicPortAllocatorTest, TestDisableAdapterEnumerationBehindNatWithTcp) { - turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); + turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); AddInterface(kPrivateAddr); ResetWithStunServerAndNat(kStunAddr); AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); @@ -756,8 +731,8 @@ TEST_F(BasicPortAllocatorTest, TEST_F(BasicPortAllocatorTest, TestDisableAdapterEnumerationWithoutNatLocalhostCandidateDisabled) { ResetWithStunServerNoNat(kStunAddr); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); - session_->set_flags(cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); + session_->set_flags(PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); // Expect to see 2 ports: STUN and TCP ports, localhost candidate and STUN // candidate. CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), rtc::IPAddress(), @@ -774,8 +749,8 @@ TEST_F( TestDisableAdapterEnumerationWithoutNatLocalhostCandidateDisabledWithDifferentDefaultRoute) { ResetWithStunServerNoNat(kStunAddr); AddInterfaceAsDefaultRoute(kClientAddr); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); - session_->set_flags(cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); + session_->set_flags(PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); // Expect to see 2 ports: STUN and TCP ports, localhost candidate and STUN // candidate. CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), kClientAddr.ipaddr(), @@ -788,8 +763,8 @@ TEST_F( TEST_F(BasicPortAllocatorTest, TestDisableAdapterEnumerationWithNatLocalhostCandidateDisabled) { ResetWithStunServerAndNat(kStunAddr); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); - session_->set_flags(cricket::PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); + session_->set_flags(PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE); // Expect to see 2 ports: STUN and TCP ports, and single STUN candidate. CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), kNatUdpAddr.ipaddr(), rtc::IPAddress(), rtc::IPAddress()); @@ -798,15 +773,14 @@ TEST_F(BasicPortAllocatorTest, // Test that we disable relay over UDP, and only TCP is used when connecting to // the relay server. TEST_F(BasicPortAllocatorTest, TestDisableUdpTurn) { - turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); + turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); AddInterface(kClientAddr); ResetWithStunServerAndNat(kStunAddr); AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); - session_->set_flags(cricket::PORTALLOCATOR_DISABLE_UDP_RELAY | - cricket::PORTALLOCATOR_DISABLE_UDP | - cricket::PORTALLOCATOR_DISABLE_STUN | - cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); + session_->set_flags(PORTALLOCATOR_DISABLE_UDP_RELAY | + PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN | + PORTALLOCATOR_ENABLE_SHARED_SOCKET); session_->StartGettingPorts(); EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); @@ -815,14 +789,12 @@ TEST_F(BasicPortAllocatorTest, TestDisableUdpTurn) { // TURN/TCP candidates. EXPECT_EQ(2U, ports_.size()); EXPECT_EQ(2U, candidates_.size()); - EXPECT_PRED5(CheckCandidate, candidates_[0], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", - kTurnUdpExtAddr); + EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "udp", kTurnUdpExtAddr); // The TURN candidate should use TCP to contact the TURN server. - EXPECT_EQ(cricket::TCP_PROTOCOL_NAME, candidates_[0].relay_protocol()); - EXPECT_PRED5(CheckCandidate, candidates_[1], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", - kClientAddr); + EXPECT_EQ(TCP_PROTOCOL_NAME, candidates_[0].relay_protocol()); + EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, + "local", "tcp", kClientAddr); } // Disable for asan, see @@ -833,11 +805,9 @@ TEST_F(BasicPortAllocatorTest, TestDisableUdpTurn) { // are disabled. TEST_F(BasicPortAllocatorTest, TestDisableAllPorts) { AddInterface(kClientAddr); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); - session_->set_flags(cricket::PORTALLOCATOR_DISABLE_UDP | - cricket::PORTALLOCATOR_DISABLE_STUN | - cricket::PORTALLOCATOR_DISABLE_RELAY | - cricket::PORTALLOCATOR_DISABLE_TCP); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); + session_->set_flags(PORTALLOCATOR_DISABLE_UDP | PORTALLOCATOR_DISABLE_STUN | + PORTALLOCATOR_DISABLE_RELAY | PORTALLOCATOR_DISABLE_TCP); session_->StartGettingPorts(); rtc::Thread::Current()->ProcessMessages(100); EXPECT_EQ(0U, candidates_.size()); @@ -852,21 +822,16 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSockets) { session_->StartGettingPorts(); ASSERT_EQ_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout); EXPECT_EQ(2U, ports_.size()); - EXPECT_PRED5(CheckCandidate, candidates_[0], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", - kRelayUdpIntAddr); - EXPECT_PRED5(CheckCandidate, candidates_[1], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", - kRelayUdpExtAddr); - EXPECT_PRED5(CheckCandidate, candidates_[2], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", - kRelayTcpIntAddr); - EXPECT_PRED5(CheckCandidate, candidates_[3], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", - kClientAddr); - EXPECT_PRED5(CheckCandidate, candidates_[4], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "ssltcp", - kRelaySslTcpIntAddr); + EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "udp", kRelayUdpIntAddr); + EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "udp", kRelayUdpExtAddr); + EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "tcp", kRelayTcpIntAddr); + EXPECT_PRED5(CheckCandidate, candidates_[3], ICE_CANDIDATE_COMPONENT_RTP, + "local", "tcp", kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[4], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "ssltcp", kRelaySslTcpIntAddr); EXPECT_TRUE(candidate_allocation_done_); } @@ -901,7 +866,7 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoSockets) { AddInterface(kClientAddr); fss_->set_tcp_sockets_enabled(false); fss_->set_udp_sockets_enabled(false); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); WAIT(candidates_.size() > 0, 2000); // TODO(deadbeef): Check candidate_allocation_done signal. @@ -913,32 +878,26 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoSockets) { TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpAllowed) { fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); AddInterface(kClientAddr); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); EXPECT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); EXPECT_EQ(2U, ports_.size()); - EXPECT_PRED5(CheckCandidate, candidates_[0], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", - kClientAddr); - EXPECT_PRED5(CheckCandidate, candidates_[1], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", - kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, + "local", "udp", kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, + "local", "tcp", kClientAddr); // RelayPort connection timeout is 3sec. TCP connection with RelayServer // will be tried after 3 seconds. EXPECT_EQ_WAIT(6U, candidates_.size(), 4000); EXPECT_EQ(3U, ports_.size()); - EXPECT_PRED5(CheckCandidate, candidates_[2], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", - kRelayUdpIntAddr); - EXPECT_PRED5(CheckCandidate, candidates_[3], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "tcp", - kRelayTcpIntAddr); - EXPECT_PRED5(CheckCandidate, candidates_[4], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "ssltcp", - kRelaySslTcpIntAddr); - EXPECT_PRED5(CheckCandidate, candidates_[5], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", - kRelayUdpExtAddr); + EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "udp", kRelayUdpIntAddr); + EXPECT_PRED5(CheckCandidate, candidates_[3], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "tcp", kRelayTcpIntAddr); + EXPECT_PRED5(CheckCandidate, candidates_[4], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "ssltcp", kRelaySslTcpIntAddr); + EXPECT_PRED5(CheckCandidate, candidates_[5], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "udp", kRelayUdpExtAddr); // Stun Timeout is 9sec. EXPECT_TRUE_WAIT(candidate_allocation_done_, 9000); } @@ -948,10 +907,9 @@ TEST_F(BasicPortAllocatorTest, TestCandidatePriorityOfMultipleInterfaces) { AddInterface(kClientAddr2); // Allocating only host UDP ports. This is done purely for testing // convenience. - allocator().set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | - cricket::PORTALLOCATOR_DISABLE_STUN | - cricket::PORTALLOCATOR_DISABLE_RELAY); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + allocator().set_flags(PORTALLOCATOR_DISABLE_TCP | PORTALLOCATOR_DISABLE_STUN | + PORTALLOCATOR_DISABLE_RELAY); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); ASSERT_EQ(2U, candidates_.size()); @@ -963,7 +921,7 @@ TEST_F(BasicPortAllocatorTest, TestCandidatePriorityOfMultipleInterfaces) { // Test to verify ICE restart process. TEST_F(BasicPortAllocatorTest, TestGetAllPortsRestarts) { AddInterface(kClientAddr); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); EXPECT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); EXPECT_EQ(4U, ports_.size()); @@ -971,6 +929,23 @@ TEST_F(BasicPortAllocatorTest, TestGetAllPortsRestarts) { // TODO(deadbeef): Extend this to verify ICE restart. } +// Test that the allocator session uses the candidate filter it's created with, +// rather than the filter of its parent allocator. +// The filter of the allocator should only affect the next gathering phase, +// according to JSEP, which means the *next* allocator session returned. +TEST_F(BasicPortAllocatorTest, TestSessionUsesOwnCandidateFilter) { + AddInterface(kClientAddr); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); + // Set candidate filter *after* creating the session. Should have no effect. + allocator().set_candidate_filter(CF_RELAY); + session_->StartGettingPorts(); + // 7 candidates and 4 ports is what we would normally get (see the + // TestGetAllPorts* tests). + EXPECT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); + EXPECT_EQ(4U, ports_.size()); + EXPECT_TRUE(candidate_allocation_done_); +} + // Test ICE candidate filter mechanism with options Relay/Host/Reflexive. // This test also verifies that when the allocator is only allowed to use // relay (i.e. IceTransportsType is relay), the raddr is an empty @@ -980,18 +955,17 @@ TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithRelayOnly) { AddInterface(kClientAddr); // GTURN is not configured here. ResetWithTurnServersNoNat(kTurnUdpIntAddr, rtc::SocketAddress()); - allocator().set_candidate_filter(cricket::CF_RELAY); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + allocator().set_candidate_filter(CF_RELAY); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); - EXPECT_PRED5(CheckCandidate, candidates_[0], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", - rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); + EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); EXPECT_EQ(1U, candidates_.size()); EXPECT_EQ(1U, ports_.size()); // Only Relay port will be in ready state. for (size_t i = 0; i < candidates_.size(); ++i) { - EXPECT_EQ(std::string(cricket::RELAY_PORT_TYPE), candidates_[i].type()); + EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidates_[i].type()); EXPECT_EQ( candidates_[0].related_address(), rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); @@ -1000,15 +974,15 @@ TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithRelayOnly) { TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithHostOnly) { AddInterface(kClientAddr); - allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); - allocator().set_candidate_filter(cricket::CF_HOST); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); + allocator().set_candidate_filter(CF_HOST); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); EXPECT_EQ(2U, candidates_.size()); // Host UDP/TCP candidates only. EXPECT_EQ(2U, ports_.size()); // UDP/TCP ports only. for (size_t i = 0; i < candidates_.size(); ++i) { - EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); + EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidates_[i].type()); } } @@ -1017,9 +991,9 @@ TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { AddInterface(kPrivateAddr); ResetWithStunServerAndNat(kStunAddr); - allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); - allocator().set_candidate_filter(cricket::CF_REFLEXIVE); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); + allocator().set_candidate_filter(CF_REFLEXIVE); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); // Host is behind NAT, no private address will be exposed. Hence only UDP @@ -1027,7 +1001,7 @@ TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { EXPECT_EQ(1U, candidates_.size()); // Only STUN candidate. EXPECT_EQ(1U, ports_.size()); // Only UDP port will be in ready state. for (size_t i = 0; i < candidates_.size(); ++i) { - EXPECT_EQ(std::string(cricket::STUN_PORT_TYPE), candidates_[i].type()); + EXPECT_EQ(std::string(STUN_PORT_TYPE), candidates_[i].type()); EXPECT_EQ( candidates_[0].related_address(), rtc::EmptySocketAddressWithFamily(candidates_[0].address().family())); @@ -1037,34 +1011,31 @@ TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnly) { // Host is not behind the NAT. TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithReflexiveOnlyAndNoNAT) { AddInterface(kClientAddr); - allocator().set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); - allocator().set_candidate_filter(cricket::CF_REFLEXIVE); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + allocator().set_flags(PORTALLOCATOR_ENABLE_SHARED_SOCKET); + allocator().set_candidate_filter(CF_REFLEXIVE); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); // Host has a public address, both UDP and TCP candidates will be exposed. EXPECT_EQ(2U, candidates_.size()); // Local UDP + TCP candidate. EXPECT_EQ(2U, ports_.size()); // UDP and TCP ports will be in ready state. for (size_t i = 0; i < candidates_.size(); ++i) { - EXPECT_EQ(std::string(cricket::LOCAL_PORT_TYPE), candidates_[i].type()); + EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidates_[i].type()); } } // Test that we get the same ufrag and pwd for all candidates. TEST_F(BasicPortAllocatorTest, TestEnableSharedUfrag) { AddInterface(kClientAddr); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout); - EXPECT_PRED5(CheckCandidate, candidates_[0], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", - kClientAddr); - EXPECT_PRED5(CheckCandidate, candidates_[1], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", - kClientAddr); - EXPECT_PRED5(CheckCandidate, candidates_[5], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", - kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, + "local", "udp", kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, + "stun", "udp", kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[5], ICE_CANDIDATE_COMPONENT_RTP, + "local", "tcp", kClientAddr); EXPECT_EQ(4U, ports_.size()); EXPECT_EQ(kIceUfrag0, candidates_[0].username()); EXPECT_EQ(kIceUfrag0, candidates_[1].username()); @@ -1081,14 +1052,13 @@ TEST_F(BasicPortAllocatorTest, TestEnableSharedUfrag) { TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNat) { AddInterface(kClientAddr); allocator_->set_flags(allocator().flags() | - cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + PORTALLOCATOR_ENABLE_SHARED_SOCKET); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(6U, candidates_.size(), kDefaultAllocationTimeout); EXPECT_EQ(3U, ports_.size()); - EXPECT_PRED5(CheckCandidate, candidates_[0], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", - kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, + "local", "udp", kClientAddr); EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); } @@ -1100,48 +1070,43 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNat) { ResetWithStunServerAndNat(kStunAddr); allocator_->set_flags(allocator().flags() | - cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + PORTALLOCATOR_ENABLE_SHARED_SOCKET); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); ASSERT_EQ(2U, ports_.size()); - EXPECT_PRED5(CheckCandidate, candidates_[0], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", - kClientAddr); - EXPECT_PRED5(CheckCandidate, candidates_[1], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", - rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); + EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, + "local", "udp", kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, + "stun", "udp", rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); EXPECT_EQ(3U, candidates_.size()); } // Test TURN port in shared socket mode with UDP and TCP TURN server addresses. TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { - turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); + turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); AddInterface(kClientAddr); - allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); + allocator_.reset(new BasicPortAllocator(&network_manager_)); AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); - allocator_->set_step_delay(cricket::kMinimumStepDelay); + allocator_->set_step_delay(kMinimumStepDelay); allocator_->set_flags(allocator().flags() | - cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | - cricket::PORTALLOCATOR_DISABLE_TCP); + PORTALLOCATOR_ENABLE_SHARED_SOCKET | + PORTALLOCATOR_DISABLE_TCP); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); ASSERT_EQ(3U, ports_.size()); - EXPECT_PRED5(CheckCandidate, candidates_[0], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", - kClientAddr); - EXPECT_PRED5(CheckCandidate, candidates_[1], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", - rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); - EXPECT_PRED5(CheckCandidate, candidates_[2], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", - rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); + EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, + "local", "udp", kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); + EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); EXPECT_EQ(3U, candidates_.size()); } @@ -1150,22 +1115,22 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNatUsingTurn) { // handling the unresolved address signal from TurnPort. TEST_F(BasicPortAllocatorTest, TestSharedSocketWithServerAddressResolve) { turn_server_.AddInternalSocket(rtc::SocketAddress("127.0.0.1", 3478), - cricket::PROTO_UDP); + PROTO_UDP); AddInterface(kClientAddr); - allocator_.reset(new cricket::BasicPortAllocator(&network_manager_)); - cricket::RelayServerConfig turn_server(cricket::RELAY_TURN); - cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); + allocator_.reset(new BasicPortAllocator(&network_manager_)); + RelayServerConfig turn_server(RELAY_TURN); + RelayCredentials credentials(kTurnUsername, kTurnPassword); turn_server.credentials = credentials; - turn_server.ports.push_back(cricket::ProtocolAddress( - rtc::SocketAddress("localhost", 3478), cricket::PROTO_UDP, false)); + turn_server.ports.push_back( + ProtocolAddress(rtc::SocketAddress("localhost", 3478), PROTO_UDP, false)); allocator_->AddTurnServer(turn_server); - allocator_->set_step_delay(cricket::kMinimumStepDelay); + allocator_->set_step_delay(kMinimumStepDelay); allocator_->set_flags(allocator().flags() | - cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | - cricket::PORTALLOCATOR_DISABLE_TCP); + PORTALLOCATOR_ENABLE_SHARED_SOCKET | + PORTALLOCATOR_DISABLE_TCP); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); EXPECT_EQ_WAIT(2U, ports_.size(), kDefaultAllocationTimeout); @@ -1181,23 +1146,20 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurn) { AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); allocator_->set_flags(allocator().flags() | - cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | - cricket::PORTALLOCATOR_DISABLE_TCP); + PORTALLOCATOR_ENABLE_SHARED_SOCKET | + PORTALLOCATOR_DISABLE_TCP); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); ASSERT_EQ(2U, ports_.size()); - EXPECT_PRED5(CheckCandidate, candidates_[0], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", - kClientAddr); - EXPECT_PRED5(CheckCandidate, candidates_[1], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", - rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); - EXPECT_PRED5(CheckCandidate, candidates_[2], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", - rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); + EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, + "local", "udp", kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, + "stun", "udp", rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); + EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); EXPECT_EQ(3U, candidates_.size()); // Local port will be created first and then TURN port. @@ -1220,22 +1182,19 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) { // webrtc issue 3537. allocator_->set_step_delay(0); allocator_->set_flags(allocator().flags() | - cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | - cricket::PORTALLOCATOR_DISABLE_TCP); + PORTALLOCATOR_ENABLE_SHARED_SOCKET | + PORTALLOCATOR_DISABLE_TCP); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); - EXPECT_PRED5(CheckCandidate, candidates_[0], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", - kClientAddr); - EXPECT_PRED5(CheckCandidate, candidates_[1], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", - rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); - EXPECT_PRED5(CheckCandidate, candidates_[2], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", - rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); + EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, + "local", "udp", kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, + "stun", "udp", rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); + EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); @@ -1249,26 +1208,24 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) { // a UDP STUN server, as this could leak our IP address. Thus we should only // expect two ports, a UDPPort and TurnPort. TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { - turn_server_.AddInternalSocket(kTurnTcpIntAddr, cricket::PROTO_TCP); + turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); AddInterface(kClientAddr); ResetWithStunServerAndNat(rtc::SocketAddress()); AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr); allocator_->set_flags(allocator().flags() | - cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | - cricket::PORTALLOCATOR_DISABLE_TCP); + PORTALLOCATOR_ENABLE_SHARED_SOCKET | + PORTALLOCATOR_DISABLE_TCP); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); ASSERT_EQ(2U, ports_.size()); - EXPECT_PRED5(CheckCandidate, candidates_[0], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", - kClientAddr); - EXPECT_PRED5(CheckCandidate, candidates_[1], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", - rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); + EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, + "local", "udp", kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); EXPECT_EQ(2U, candidates_.size()); EXPECT_EQ(1U, ports_[0]->Candidates().size()); @@ -1286,23 +1243,19 @@ TEST_F(BasicPortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { ResetWithStunServerAndNat(SocketAddress()); AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); - allocator_->set_flags(allocator().flags() | - cricket::PORTALLOCATOR_DISABLE_TCP); + allocator_->set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_TCP); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); ASSERT_EQ(3U, ports_.size()); - EXPECT_PRED5(CheckCandidate, candidates_[0], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", - kClientAddr); - EXPECT_PRED5(CheckCandidate, candidates_[1], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", - rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); - EXPECT_PRED5(CheckCandidate, candidates_[2], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", - rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); + EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, + "local", "udp", kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, + "stun", "udp", rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); + EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); // Not using shared socket, so the STUN request's server reflexive address // should be different than the TURN request's server reflexive address. EXPECT_NE(candidates_[2].related_address(), candidates_[1].address()); @@ -1325,22 +1278,19 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); allocator_->set_flags(allocator().flags() | - cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET | - cricket::PORTALLOCATOR_DISABLE_TCP); + PORTALLOCATOR_ENABLE_SHARED_SOCKET | + PORTALLOCATOR_DISABLE_TCP); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout); - EXPECT_PRED5(CheckCandidate, candidates_[0], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", - kClientAddr); - EXPECT_PRED5(CheckCandidate, candidates_[1], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", - rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); - EXPECT_PRED5(CheckCandidate, candidates_[2], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", - rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); + EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, + "local", "udp", kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, + "stun", "udp", rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); + EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, + "relay", "udp", rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); EXPECT_EQ(candidates_[2].related_address(), candidates_[1].address()); // Don't bother waiting for STUN timeout, since we already verified @@ -1351,19 +1301,17 @@ TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { // and fail to generate STUN candidate, local UDP candidate is generated // properly. TEST_F(BasicPortAllocatorTest, TestSharedSocketNoUdpAllowed) { - allocator().set_flags(allocator().flags() | - cricket::PORTALLOCATOR_DISABLE_RELAY | - cricket::PORTALLOCATOR_DISABLE_TCP | - cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); + allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | + PORTALLOCATOR_DISABLE_TCP | + PORTALLOCATOR_ENABLE_SHARED_SOCKET); fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); AddInterface(kClientAddr); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); EXPECT_EQ(1U, candidates_.size()); - EXPECT_PRED5(CheckCandidate, candidates_[0], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", - kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, + "local", "udp", kClientAddr); // STUN timeout is 9.5sec. We need to wait to get candidate done signal. EXPECT_TRUE_WAIT(candidate_allocation_done_, kStunTimeoutMs); EXPECT_EQ(1U, candidates_.size()); @@ -1377,58 +1325,49 @@ TEST_F(BasicPortAllocatorTest, TestNetworkPermissionBlocked) { rtc::IPAddress()); network_manager_.set_enumeration_permission( rtc::NetworkManager::ENUMERATION_BLOCKED); - allocator().set_flags(allocator().flags() | - cricket::PORTALLOCATOR_DISABLE_RELAY | - cricket::PORTALLOCATOR_DISABLE_TCP | - cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); - EXPECT_EQ(0U, allocator_->flags() & - cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); - EXPECT_EQ(0U, session_->flags() & - cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); + allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | + PORTALLOCATOR_DISABLE_TCP | + PORTALLOCATOR_ENABLE_SHARED_SOCKET); + EXPECT_EQ(0U, + allocator_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); + EXPECT_EQ(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); session_->StartGettingPorts(); EXPECT_EQ_WAIT(1U, ports_.size(), kDefaultAllocationTimeout); EXPECT_EQ(1U, candidates_.size()); - EXPECT_PRED5(CheckCandidate, candidates_[0], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", - kPrivateAddr); - EXPECT_NE(0U, session_->flags() & - cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); + EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, + "local", "udp", kPrivateAddr); + EXPECT_NE(0U, session_->flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION); } // This test verifies allocator can use IPv6 addresses along with IPv4. TEST_F(BasicPortAllocatorTest, TestEnableIPv6Addresses) { - allocator().set_flags(allocator().flags() | - cricket::PORTALLOCATOR_DISABLE_RELAY | - cricket::PORTALLOCATOR_ENABLE_IPV6 | - cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); + allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | + PORTALLOCATOR_ENABLE_IPV6 | + PORTALLOCATOR_ENABLE_SHARED_SOCKET); AddInterface(kClientIPv6Addr); AddInterface(kClientAddr); - allocator_->set_step_delay(cricket::kMinimumStepDelay); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + allocator_->set_step_delay(kMinimumStepDelay); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(4U, ports_.size(), kDefaultAllocationTimeout); EXPECT_EQ(4U, candidates_.size()); EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); - EXPECT_PRED5(CheckCandidate, candidates_[0], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", - kClientIPv6Addr); - EXPECT_PRED5(CheckCandidate, candidates_[1], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", - kClientAddr); - EXPECT_PRED5(CheckCandidate, candidates_[2], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", - kClientIPv6Addr); - EXPECT_PRED5(CheckCandidate, candidates_[3], - cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "tcp", - kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[0], ICE_CANDIDATE_COMPONENT_RTP, + "local", "udp", kClientIPv6Addr); + EXPECT_PRED5(CheckCandidate, candidates_[1], ICE_CANDIDATE_COMPONENT_RTP, + "local", "udp", kClientAddr); + EXPECT_PRED5(CheckCandidate, candidates_[2], ICE_CANDIDATE_COMPONENT_RTP, + "local", "tcp", kClientIPv6Addr); + EXPECT_PRED5(CheckCandidate, candidates_[3], ICE_CANDIDATE_COMPONENT_RTP, + "local", "tcp", kClientAddr); EXPECT_EQ(4U, candidates_.size()); } TEST_F(BasicPortAllocatorTest, TestStopGettingPorts) { AddInterface(kClientAddr); - allocator_->set_step_delay(cricket::kDefaultStepDelay); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + allocator_->set_step_delay(kDefaultStepDelay); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); EXPECT_EQ(2U, ports_.size()); @@ -1448,8 +1387,8 @@ TEST_F(BasicPortAllocatorTest, TestStopGettingPorts) { TEST_F(BasicPortAllocatorTest, TestClearGettingPorts) { AddInterface(kClientAddr); - allocator_->set_step_delay(cricket::kDefaultStepDelay); - EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); + allocator_->set_step_delay(kDefaultStepDelay); + EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); session_->StartGettingPorts(); ASSERT_EQ_WAIT(2U, candidates_.size(), 1000); EXPECT_EQ(2U, ports_.size()); @@ -1474,8 +1413,7 @@ TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) { int pool_size = 1; allocator_->SetConfiguration(allocator_->stun_servers(), allocator_->turn_servers(), pool_size); - const cricket::PortAllocatorSession* peeked_session = - allocator_->GetPooledSession(); + const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); ASSERT_NE(nullptr, peeked_session); EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), kDefaultAllocationTimeout); @@ -1490,17 +1428,55 @@ TEST_F(BasicPortAllocatorTest, TestTransportInformationUpdated) { auto candidates = session_->ReadyCandidates(); EXPECT_FALSE(ready_ports.empty()); EXPECT_FALSE(candidates.empty()); - for (const cricket::PortInterface* port_interface : ready_ports) { - const cricket::Port* port = - static_cast(port_interface); + for (const PortInterface* port_interface : ready_ports) { + const Port* port = static_cast(port_interface); EXPECT_EQ(kContentName, port->content_name()); EXPECT_EQ(1, port->component()); EXPECT_EQ(kIceUfrag0, port->username_fragment()); EXPECT_EQ(kIcePwd0, port->password()); } - for (const cricket::Candidate& candidate : candidates) { + for (const Candidate& candidate : candidates) { EXPECT_EQ(1, candidate.component()); EXPECT_EQ(kIceUfrag0, candidate.username()); EXPECT_EQ(kIcePwd0, candidate.password()); } } + +// Test that a new candidate filter takes effect even on already-gathered +// candidates. +TEST_F(BasicPortAllocatorTest, TestSetCandidateFilterAfterCandidatesGathered) { + AddInterface(kClientAddr); + int pool_size = 1; + allocator_->SetConfiguration(allocator_->stun_servers(), + allocator_->turn_servers(), pool_size); + const PortAllocatorSession* peeked_session = allocator_->GetPooledSession(); + ASSERT_NE(nullptr, peeked_session); + EXPECT_EQ_WAIT(true, peeked_session->CandidatesAllocationDone(), + kDefaultAllocationTimeout); + size_t initial_candidates_size = peeked_session->ReadyCandidates().size(); + size_t initial_ports_size = peeked_session->ReadyPorts().size(); + allocator_->set_candidate_filter(CF_RELAY); + // Assume that when TakePooledSession is called, the candidate filter will be + // applied to the pooled session. This is tested by PortAllocatorTest. + session_ = + allocator_->TakePooledSession(kContentName, 1, kIceUfrag0, kIcePwd0); + ASSERT_NE(nullptr, session_.get()); + auto candidates = session_->ReadyCandidates(); + auto ports = session_->ReadyPorts(); + // Sanity check that the number of candidates and ports decreased. + EXPECT_GT(initial_candidates_size, candidates.size()); + EXPECT_GT(initial_ports_size, ports.size()); + for (const PortInterface* port : ports) { + // Expect only relay ports. + EXPECT_EQ(RELAY_PORT_TYPE, port->Type()); + } + for (const Candidate& candidate : candidates) { + // Expect only relay candidates now that the filter is applied. + EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); + // Expect that the raddr is emptied due to the CF_RELAY filter. + EXPECT_EQ(candidate.related_address(), + rtc::EmptySocketAddressWithFamily(candidate.address().family())); + } +} + +} // namespace cricket