diff --git a/p2p/base/portallocator.cc b/p2p/base/portallocator.cc index 109472b136..6ec6417ffc 100644 --- a/p2p/base/portallocator.cc +++ b/p2p/base/portallocator.cc @@ -13,6 +13,43 @@ namespace cricket { +RelayServerConfig::RelayServerConfig(RelayType type) : type(type) {} + +RelayServerConfig::RelayServerConfig(const rtc::SocketAddress& address, + const std::string& username, + const std::string& password, + ProtocolType proto) + : type(RELAY_TURN), credentials(username, password) { + ports.push_back(ProtocolAddress(address, proto)); +} + +RelayServerConfig::RelayServerConfig(const std::string& address, + int port, + const std::string& username, + const std::string& password, + ProtocolType proto) + : RelayServerConfig(rtc::SocketAddress(address, port), + username, + password, + proto) {} + +// Legacy constructor where "secure" and PROTO_TCP implies PROTO_TLS. +RelayServerConfig::RelayServerConfig(const std::string& address, + int port, + const std::string& username, + const std::string& password, + ProtocolType proto, + bool secure) + : RelayServerConfig(address, + port, + username, + password, + (proto == PROTO_TCP && secure ? PROTO_TLS : proto)) {} + +RelayServerConfig::RelayServerConfig(const RelayServerConfig&) = default; + +RelayServerConfig::~RelayServerConfig() = default; + PortAllocatorSession::PortAllocatorSession(const std::string& content_name, int component, const std::string& ice_ufrag, @@ -29,6 +66,35 @@ PortAllocatorSession::PortAllocatorSession(const std::string& content_name, RTC_DCHECK(ice_ufrag.empty() == ice_pwd.empty()); } +PortAllocatorSession::~PortAllocatorSession() = default; + +bool PortAllocatorSession::IsCleared() const { + return false; +} + +bool PortAllocatorSession::IsStopped() const { + return false; +} + +uint32_t PortAllocatorSession::generation() { + return generation_; +} + +void PortAllocatorSession::set_generation(uint32_t generation) { + generation_ = generation; +} + +PortAllocator::PortAllocator() + : flags_(kDefaultPortAllocatorFlags), + min_port_(0), + max_port_(0), + max_ipv6_networks_(kDefaultMaxIPv6Networks), + step_delay_(kDefaultStepDelay), + allow_tcp_listen_(true), + candidate_filter_(CF_ALL) {} + +PortAllocator::~PortAllocator() = default; + bool PortAllocator::SetConfiguration( const ServerAddresses& stun_servers, const std::vector& turn_servers, diff --git a/p2p/base/portallocator.h b/p2p/base/portallocator.h index 5c0d303502..1092910a49 100644 --- a/p2p/base/portallocator.h +++ b/p2p/base/portallocator.h @@ -148,38 +148,25 @@ struct RelayCredentials { typedef std::vector PortList; // TODO(deadbeef): Rename to TurnServerConfig. struct RelayServerConfig { - RelayServerConfig(RelayType type) : type(type) {} - + RelayServerConfig(RelayType type); RelayServerConfig(const rtc::SocketAddress& address, const std::string& username, const std::string& password, - ProtocolType proto) - : type(RELAY_TURN), credentials(username, password) { - ports.push_back(ProtocolAddress(address, proto)); - } - + ProtocolType proto); RelayServerConfig(const std::string& address, int port, const std::string& username, const std::string& password, - ProtocolType proto) - : RelayServerConfig(rtc::SocketAddress(address, port), - username, - password, - proto) {} - + ProtocolType proto); // Legacy constructor where "secure" and PROTO_TCP implies PROTO_TLS. RelayServerConfig(const std::string& address, int port, const std::string& username, const std::string& password, ProtocolType proto, - bool secure) - : RelayServerConfig(address, - port, - username, - password, - (proto == PROTO_TCP && secure ? PROTO_TLS : proto)) {} + bool secure); + RelayServerConfig(const RelayServerConfig&); + ~RelayServerConfig(); bool operator==(const RelayServerConfig& o) const { return type == o.type && ports == o.ports && credentials == o.credentials && @@ -206,7 +193,7 @@ class PortAllocatorSession : public sigslot::has_slots<> { uint32_t flags); // Subclasses should clean up any ports created. - virtual ~PortAllocatorSession() {} + ~PortAllocatorSession() override; uint32_t flags() const { return flags_; } void set_flags(uint32_t flags) { flags_ = flags; } @@ -242,9 +229,9 @@ class PortAllocatorSession : public sigslot::has_slots<> { 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). - virtual bool IsCleared() const { return false; } + virtual bool IsCleared() const; // Whether the session has completely stopped. - virtual bool IsStopped() const { return false; } + virtual bool IsStopped() const; // 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 @@ -283,8 +270,8 @@ class PortAllocatorSession : public sigslot::has_slots<> { sigslot::signal2 SignalIceRegathering; - virtual uint32_t generation() { return generation_; } - virtual void set_generation(uint32_t generation) { generation_ = generation; } + virtual uint32_t generation(); + virtual void set_generation(uint32_t generation); sigslot::signal1 SignalDestroyed; protected: @@ -333,16 +320,8 @@ class PortAllocatorSession : public sigslot::has_slots<> { // passing it into an object that uses it on a different thread. class PortAllocator : public sigslot::has_slots<> { public: - PortAllocator() - : flags_(kDefaultPortAllocatorFlags), - min_port_(0), - max_port_(0), - max_ipv6_networks_(kDefaultMaxIPv6Networks), - step_delay_(kDefaultStepDelay), - allow_tcp_listen_(true), - candidate_filter_(CF_ALL) {} - - virtual ~PortAllocator() {} + PortAllocator(); + ~PortAllocator() override; // This should be called on the PortAllocator's thread before the // PortAllocator is used. Subclasses may override this if necessary. diff --git a/p2p/client/basicportallocator.cc b/p2p/client/basicportallocator.cc index 471748400d..c68c4fa47d 100644 --- a/p2p/client/basicportallocator.cc +++ b/p2p/client/basicportallocator.cc @@ -179,6 +179,13 @@ BasicPortAllocator::~BasicPortAllocator() { DiscardCandidatePool(); } +void BasicPortAllocator::SetNetworkIgnoreMask(int network_ignore_mask) { + // TODO(phoglund): implement support for other types than loopback. + // See https://code.google.com/p/webrtc/issues/detail?id=4288. + // Then remove set_network_ignore_list from NetworkManager. + network_ignore_mask_ = network_ignore_mask; +} + PortAllocatorSession* BasicPortAllocator::CreateSessionInternal( const std::string& content_name, int component, const std::string& ice_ufrag, const std::string& ice_pwd) { @@ -242,6 +249,10 @@ BasicPortAllocatorSession::~BasicPortAllocatorSession() { delete sequences_[i]; } +BasicPortAllocator* BasicPortAllocatorSession::allocator() { + return allocator_; +} + void BasicPortAllocatorSession::SetCandidateFilter(uint32_t filter) { if (filter == candidate_filter_) { return; @@ -298,6 +309,18 @@ void BasicPortAllocatorSession::ClearGettingPorts() { state_ = SessionState::CLEARED; } +bool BasicPortAllocatorSession::IsGettingPorts() { + return state_ == SessionState::GATHERING; +} + +bool BasicPortAllocatorSession::IsCleared() const { + return state_ == SessionState::CLEARED; +} + +bool BasicPortAllocatorSession::IsStopped() const { + return state_ == SessionState::STOPPED; +} + std::vector BasicPortAllocatorSession::GetFailedNetworks() { std::vector networks = GetNetworks(); @@ -1484,6 +1507,8 @@ PortConfiguration::PortConfiguration(const ServerAddresses& stun_servers, stun_address = *(stun_servers.begin()); } +PortConfiguration::~PortConfiguration() = default; + ServerAddresses PortConfiguration::StunServers() { if (!stun_address.IsNil() && stun_servers.find(stun_address) == stun_servers.end()) { diff --git a/p2p/client/basicportallocator.h b/p2p/client/basicportallocator.h index 5ec721b8fd..f5cc1d16a6 100644 --- a/p2p/client/basicportallocator.h +++ b/p2p/client/basicportallocator.h @@ -38,16 +38,10 @@ class BasicPortAllocator : public PortAllocator { const rtc::SocketAddress& relay_server_udp, const rtc::SocketAddress& relay_server_tcp, const rtc::SocketAddress& relay_server_ssl); - virtual ~BasicPortAllocator(); + ~BasicPortAllocator() override; // Set to kDefaultNetworkIgnoreMask by default. - void SetNetworkIgnoreMask(int network_ignore_mask) override { - // TODO(phoglund): implement support for other types than loopback. - // See https://code.google.com/p/webrtc/issues/detail?id=4288. - // Then remove set_network_ignore_list from NetworkManager. - network_ignore_mask_ = network_ignore_mask; - } - + void SetNetworkIgnoreMask(int network_ignore_mask) override; int network_ignore_mask() const { return network_ignore_mask_; } rtc::NetworkManager* network_manager() const { return network_manager_; } @@ -96,9 +90,9 @@ class BasicPortAllocatorSession : public PortAllocatorSession, int component, const std::string& ice_ufrag, const std::string& ice_pwd); - ~BasicPortAllocatorSession(); + ~BasicPortAllocatorSession() override; - virtual BasicPortAllocator* allocator() { return allocator_; } + virtual BasicPortAllocator* allocator(); rtc::Thread* network_thread() { return network_thread_; } rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } @@ -106,9 +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; } + bool IsGettingPorts() override; + bool IsCleared() const override; + bool IsStopped() const override; // These will all be cricket::Ports. std::vector ReadyPorts() const override; std::vector ReadyCandidates() const override; @@ -269,6 +263,8 @@ struct PortConfiguration : public rtc::MessageData { const std::string& username, const std::string& password); + ~PortConfiguration() override; + // Returns addresses of both the explicitly configured STUN servers, // and TURN servers that should be used as STUN servers. ServerAddresses StunServers(); @@ -306,7 +302,7 @@ class AllocationSequence : public rtc::MessageHandler, rtc::Network* network, PortConfiguration* config, uint32_t flags); - ~AllocationSequence(); + ~AllocationSequence() override; void Init(); void Clear(); void OnNetworkFailed(); @@ -329,7 +325,7 @@ class AllocationSequence : public rtc::MessageHandler, void Stop(); // MessageHandler - void OnMessage(rtc::Message* msg); + void OnMessage(rtc::Message* msg) override; // Signal from AllocationSequence, when it's done with allocating ports. // This signal is useful, when port allocation fails which doesn't result