diff --git a/webrtc/p2p/base/fakeportallocator.h b/webrtc/p2p/base/fakeportallocator.h index 15e7937694..001308543e 100644 --- a/webrtc/p2p/base/fakeportallocator.h +++ b/webrtc/p2p/base/fakeportallocator.h @@ -123,7 +123,6 @@ class FakePortAllocatorSession : public PortAllocatorSession { } void StartGettingPorts() override { - PortAllocatorSession::StartGettingPorts(); if (!port_) { rtc::Network& network = (rtc::HasIPv6Enabled() && (flags() & PORTALLOCATOR_ENABLE_IPV6)) @@ -137,8 +136,13 @@ class FakePortAllocatorSession : public PortAllocatorSession { AddPort(port_.get()); } ++port_config_count_; + running_ = true; } + void StopGettingPorts() override { running_ = false; } + bool IsGettingPorts() override { return running_; } + void ClearGettingPorts() override {} + std::vector ReadyPorts() const override { return ready_ports_; } @@ -204,6 +208,7 @@ class FakePortAllocatorSession : public PortAllocatorSession { std::vector turn_servers_; uint32_t candidate_filter_ = CF_ALL; int transport_info_update_count_ = 0; + bool running_ = false; }; class FakePortAllocator : public cricket::PortAllocator { diff --git a/webrtc/p2p/base/portallocator.h b/webrtc/p2p/base/portallocator.h index dc1961db73..152474d4f4 100644 --- a/webrtc/p2p/base/portallocator.h +++ b/webrtc/p2p/base/portallocator.h @@ -88,14 +88,6 @@ enum { CF_ALL = 0x7, }; -enum class SessionState { - GATHERING, // Actively allocating ports and gathering candidates. - CLEARED, // Current allocation process has been stopped but may start - // new ones. - STOPPED // This session has completely stopped, no new allocation - // process will be started. -}; - // TODO(deadbeef): Rename to TurnCredentials (and username to ufrag). struct RelayCredentials { RelayCredentials() {} @@ -167,18 +159,19 @@ class PortAllocatorSession : public sigslot::has_slots<> { virtual void SetCandidateFilter(uint32_t filter) = 0; // Starts gathering STUN and Relay configurations. - virtual void StartGettingPorts() { state_ = SessionState::GATHERING; } + virtual void StartGettingPorts() = 0; // Completely stops the gathering process and will not start new ones. - virtual void StopGettingPorts() { state_ = SessionState::STOPPED; } - // Only stops the existing gathering process but may start new ones if needed. - virtual void ClearGettingPorts() { state_ = SessionState::CLEARED; } + virtual void StopGettingPorts() = 0; // Whether the session is actively getting ports. - bool IsGettingPorts() { return state_ == SessionState::GATHERING; } + virtual bool IsGettingPorts() = 0; + // ClearGettingPorts and IsCleared are used by continual gathering. + // Only stops the existing gathering process but may start new ones if needed. + virtual void ClearGettingPorts() = 0; // Whether it is in the state where the existing gathering process is stopped, // but new ones may be started (basically after calling ClearGettingPorts). - bool IsCleared() { return state_ == SessionState::CLEARED; } + virtual bool IsCleared() const { return false; } // Whether the session has completely stopped. - bool IsStopped() { return state_ == SessionState::STOPPED; } + virtual bool IsStopped() const { return false; } // Re-gathers candidates on networks that do not have any connections. More // precisely, a network interface may have more than one IP addresses (e.g., // IPv4 and IPv6 addresses). Each address subnet will be used to create a @@ -252,7 +245,6 @@ class PortAllocatorSession : public sigslot::has_slots<> { int component_; std::string ice_ufrag_; std::string ice_pwd_; - SessionState state_ = SessionState::CLEARED; // SetIceParameters is an implementation detail which only PortAllocator // should be able to call. diff --git a/webrtc/p2p/client/basicportallocator.cc b/webrtc/p2p/client/basicportallocator.cc index 7f8ad52889..fabbc429e5 100644 --- a/webrtc/p2p/client/basicportallocator.cc +++ b/webrtc/p2p/client/basicportallocator.cc @@ -238,7 +238,7 @@ void BasicPortAllocatorSession::SetCandidateFilter(uint32_t filter) { void BasicPortAllocatorSession::StartGettingPorts() { network_thread_ = rtc::Thread::Current(); - PortAllocatorSession::StartGettingPorts(); + state_ = SessionState::GATHERING; if (!socket_factory_) { owned_socket_factory_.reset( new rtc::BasicPacketSocketFactory(network_thread_)); @@ -257,7 +257,7 @@ void BasicPortAllocatorSession::StopGettingPorts() { ClearGettingPorts(); // Note: this must be called after ClearGettingPorts because both may set the // session state and we should set the state to STOPPED. - PortAllocatorSession::StopGettingPorts(); + state_ = SessionState::STOPPED; } void BasicPortAllocatorSession::ClearGettingPorts() { @@ -266,7 +266,7 @@ void BasicPortAllocatorSession::ClearGettingPorts() { for (uint32_t i = 0; i < sequences_.size(); ++i) { sequences_[i]->Stop(); } - PortAllocatorSession::ClearGettingPorts(); + state_ = SessionState::CLEARED; } std::vector BasicPortAllocatorSession::GetFailedNetworks() { diff --git a/webrtc/p2p/client/basicportallocator.h b/webrtc/p2p/client/basicportallocator.h index f133bdfc7e..d9cfc4d81a 100644 --- a/webrtc/p2p/client/basicportallocator.h +++ b/webrtc/p2p/client/basicportallocator.h @@ -74,6 +74,14 @@ class BasicPortAllocator : public PortAllocator { struct PortConfiguration; class AllocationSequence; +enum class SessionState { + GATHERING, // Actively allocating ports and gathering candidates. + CLEARED, // Current allocation process has been stopped but may start + // new ones. + STOPPED // This session has completely stopped, no new allocation + // process will be started. +}; + class BasicPortAllocatorSession : public PortAllocatorSession, public rtc::MessageHandler { public: @@ -92,6 +100,9 @@ class BasicPortAllocatorSession : public PortAllocatorSession, void StartGettingPorts() override; void StopGettingPorts() override; void ClearGettingPorts() override; + bool IsGettingPorts() override { return state_ == SessionState::GATHERING; } + bool IsCleared() const override { return state_ == SessionState::CLEARED; } + bool IsStopped() const override { return state_ == SessionState::STOPPED; } // These will all be cricket::Ports. std::vector ReadyPorts() const override; std::vector ReadyCandidates() const override; @@ -212,6 +223,7 @@ class BasicPortAllocatorSession : public PortAllocatorSession, uint32_t candidate_filter_ = CF_ALL; // Whether to prune low-priority ports, taken from the port allocator. bool prune_turn_ports_; + SessionState state_ = SessionState::CLEARED; friend class AllocationSequence; };