Make the state transition for a PortAllocatorSession in each derived class instead of in the base class.
Putting them in the base class may potentially break subclasses if they
have not called the same method in the base class.
R=deadbeef@webrtc.org, pthatcher@webrtc.org
Review URL: https://codereview.webrtc.org/2120733002 .
Cr-Commit-Position: refs/heads/master@{#13372}
diff --git a/webrtc/p2p/base/fakeportallocator.h b/webrtc/p2p/base/fakeportallocator.h
index 15e7937..0013085 100644
--- a/webrtc/p2p/base/fakeportallocator.h
+++ b/webrtc/p2p/base/fakeportallocator.h
@@ -123,7 +123,6 @@
}
void StartGettingPorts() override {
- PortAllocatorSession::StartGettingPorts();
if (!port_) {
rtc::Network& network =
(rtc::HasIPv6Enabled() && (flags() & PORTALLOCATOR_ENABLE_IPV6))
@@ -137,8 +136,13 @@
AddPort(port_.get());
}
++port_config_count_;
+ running_ = true;
}
+ void StopGettingPorts() override { running_ = false; }
+ bool IsGettingPorts() override { return running_; }
+ void ClearGettingPorts() override {}
+
std::vector<PortInterface*> ReadyPorts() const override {
return ready_ports_;
}
@@ -204,6 +208,7 @@
std::vector<RelayServerConfig> 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 dc1961d..152474d 100644
--- a/webrtc/p2p/base/portallocator.h
+++ b/webrtc/p2p/base/portallocator.h
@@ -88,14 +88,6 @@
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 @@
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 @@
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 7f8ad52..fabbc42 100644
--- a/webrtc/p2p/client/basicportallocator.cc
+++ b/webrtc/p2p/client/basicportallocator.cc
@@ -238,7 +238,7 @@
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 @@
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 @@
for (uint32_t i = 0; i < sequences_.size(); ++i) {
sequences_[i]->Stop();
}
- PortAllocatorSession::ClearGettingPorts();
+ state_ = SessionState::CLEARED;
}
std::vector<rtc::Network*> BasicPortAllocatorSession::GetFailedNetworks() {
diff --git a/webrtc/p2p/client/basicportallocator.h b/webrtc/p2p/client/basicportallocator.h
index f133bdf..d9cfc4d 100644
--- a/webrtc/p2p/client/basicportallocator.h
+++ b/webrtc/p2p/client/basicportallocator.h
@@ -74,6 +74,14 @@
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 @@
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<PortInterface*> ReadyPorts() const override;
std::vector<Candidate> ReadyCandidates() const override;
@@ -212,6 +223,7 @@
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;
};