henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef WEBRTC_P2P_BASE_PORTALLOCATOR_H_ |
| 12 | #define WEBRTC_P2P_BASE_PORTALLOCATOR_H_ |
| 13 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 14 | #include <deque> |
| 15 | #include <memory> |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 16 | #include <string> |
| 17 | #include <vector> |
| 18 | |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 19 | #include "webrtc/p2p/base/port.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 20 | #include "webrtc/p2p/base/portinterface.h" |
| 21 | #include "webrtc/base/helpers.h" |
| 22 | #include "webrtc/base/proxyinfo.h" |
| 23 | #include "webrtc/base/sigslot.h" |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 24 | #include "webrtc/base/thread.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 25 | |
| 26 | namespace cricket { |
| 27 | |
| 28 | // PortAllocator is responsible for allocating Port types for a given |
| 29 | // P2PSocket. It also handles port freeing. |
| 30 | // |
| 31 | // Clients can override this class to control port allocation, including |
| 32 | // what kinds of ports are allocated. |
| 33 | |
| 34 | enum { |
Guo-wei Shieh | 13d35f6 | 2015-08-26 15:32:56 -0700 | [diff] [blame] | 35 | // Disable local UDP ports. This doesn't impact how we connect to relay |
| 36 | // servers. |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 37 | PORTALLOCATOR_DISABLE_UDP = 0x01, |
| 38 | PORTALLOCATOR_DISABLE_STUN = 0x02, |
| 39 | PORTALLOCATOR_DISABLE_RELAY = 0x04, |
Guo-wei Shieh | 13d35f6 | 2015-08-26 15:32:56 -0700 | [diff] [blame] | 40 | // Disable local TCP ports. This doesn't impact how we connect to relay |
| 41 | // servers. |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 42 | PORTALLOCATOR_DISABLE_TCP = 0x08, |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 43 | PORTALLOCATOR_ENABLE_IPV6 = 0x40, |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 44 | // TODO(pthatcher): Remove this once it's no longer used in: |
| 45 | // remoting/client/plugin/pepper_port_allocator.cc |
| 46 | // remoting/protocol/chromium_port_allocator.cc |
| 47 | // remoting/test/fake_port_allocator.cc |
| 48 | // It's a no-op and is no longer needed. |
pthatcher | fa30180 | 2015-08-11 04:12:56 -0700 | [diff] [blame] | 49 | PORTALLOCATOR_ENABLE_SHARED_UFRAG = 0x80, |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 50 | PORTALLOCATOR_ENABLE_SHARED_SOCKET = 0x100, |
| 51 | PORTALLOCATOR_ENABLE_STUN_RETRANSMIT_ATTRIBUTE = 0x200, |
Guo-wei Shieh | 9af97f8 | 2015-11-10 14:47:39 -0800 | [diff] [blame] | 52 | // When specified, we'll only allocate the STUN candidate for the public |
| 53 | // interface as seen by regular http traffic and the HOST candidate associated |
| 54 | // with the default local interface. |
guoweis@webrtc.org | f358aea | 2015-02-18 18:44:01 +0000 | [diff] [blame] | 55 | PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION = 0x400, |
Guo-wei Shieh | 9af97f8 | 2015-11-10 14:47:39 -0800 | [diff] [blame] | 56 | // When specified along with PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION, the |
| 57 | // default local candidate mentioned above will not be allocated. Only the |
| 58 | // STUN candidate will be. |
| 59 | PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE = 0x800, |
Guo-wei Shieh | 13d35f6 | 2015-08-26 15:32:56 -0700 | [diff] [blame] | 60 | // Disallow use of UDP when connecting to a relay server. Since proxy servers |
| 61 | // usually don't handle UDP, using UDP will leak the IP address. |
| 62 | PORTALLOCATOR_DISABLE_UDP_RELAY = 0x1000, |
honghaiz | 6034705 | 2016-05-31 18:29:12 -0700 | [diff] [blame] | 63 | |
| 64 | // When multiple networks exist, do not gather candidates on the ones with |
| 65 | // high cost. So if both Wi-Fi and cellular networks exist, gather only on the |
| 66 | // Wi-Fi network. If a network type is "unknown", it has a cost lower than |
| 67 | // cellular but higher than Wi-Fi/Ethernet. So if an unknown network exists, |
| 68 | // cellular networks will not be used to gather candidates and if a Wi-Fi |
| 69 | // network is present, "unknown" networks will not be usd to gather |
| 70 | // candidates. Doing so ensures that even if a cellular network type was not |
| 71 | // detected initially, it would not be used if a Wi-Fi network is present. |
| 72 | PORTALLOCATOR_DISABLE_COSTLY_NETWORKS = 0x2000, |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 75 | const uint32_t kDefaultPortAllocatorFlags = 0; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 76 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 77 | const uint32_t kDefaultStepDelay = 1000; // 1 sec step delay. |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 78 | // As per RFC 5245 Appendix B.1, STUN transactions need to be paced at certain |
| 79 | // internal. Less than 20ms is not acceptable. We choose 50ms as our default. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 80 | const uint32_t kMinimumStepDelay = 50; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 81 | |
| 82 | // CF = CANDIDATE FILTER |
| 83 | enum { |
| 84 | CF_NONE = 0x0, |
| 85 | CF_HOST = 0x1, |
| 86 | CF_REFLEXIVE = 0x2, |
| 87 | CF_RELAY = 0x4, |
| 88 | CF_ALL = 0x7, |
| 89 | }; |
| 90 | |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 91 | // TODO(deadbeef): Rename to TurnCredentials (and username to ufrag). |
| 92 | struct RelayCredentials { |
| 93 | RelayCredentials() {} |
| 94 | RelayCredentials(const std::string& username, const std::string& password) |
| 95 | : username(username), password(password) {} |
| 96 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 97 | bool operator==(const RelayCredentials& o) const { |
| 98 | return username == o.username && password == o.password; |
| 99 | } |
| 100 | bool operator!=(const RelayCredentials& o) const { return !(*this == o); } |
| 101 | |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 102 | std::string username; |
| 103 | std::string password; |
| 104 | }; |
| 105 | |
| 106 | typedef std::vector<ProtocolAddress> PortList; |
| 107 | // TODO(deadbeef): Rename to TurnServerConfig. |
| 108 | struct RelayServerConfig { |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 109 | RelayServerConfig(RelayType type) : type(type) {} |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 110 | |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 111 | RelayServerConfig(const std::string& address, |
| 112 | int port, |
| 113 | const std::string& username, |
| 114 | const std::string& password, |
| 115 | ProtocolType proto, |
| 116 | bool secure) |
| 117 | : type(RELAY_TURN), credentials(username, password) { |
| 118 | ports.push_back( |
| 119 | ProtocolAddress(rtc::SocketAddress(address, port), proto, secure)); |
| 120 | } |
| 121 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 122 | bool operator==(const RelayServerConfig& o) const { |
| 123 | return type == o.type && ports == o.ports && credentials == o.credentials && |
| 124 | priority == o.priority; |
| 125 | } |
| 126 | bool operator!=(const RelayServerConfig& o) const { return !(*this == o); } |
| 127 | |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 128 | RelayType type; |
| 129 | PortList ports; |
| 130 | RelayCredentials credentials; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 131 | int priority = 0; |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 132 | }; |
| 133 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 134 | class PortAllocatorSession : public sigslot::has_slots<> { |
| 135 | public: |
| 136 | // Content name passed in mostly for logging and debugging. |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 137 | PortAllocatorSession(const std::string& content_name, |
| 138 | int component, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 139 | const std::string& ice_ufrag, |
| 140 | const std::string& ice_pwd, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 141 | uint32_t flags); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 142 | |
| 143 | // Subclasses should clean up any ports created. |
| 144 | virtual ~PortAllocatorSession() {} |
| 145 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 146 | uint32_t flags() const { return flags_; } |
| 147 | void set_flags(uint32_t flags) { flags_ = flags; } |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 148 | std::string content_name() const { return content_name_; } |
| 149 | int component() const { return component_; } |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 150 | const std::string& ice_ufrag() const { return ice_ufrag_; } |
| 151 | const std::string& ice_pwd() const { return ice_pwd_; } |
| 152 | bool pooled() const { return ice_ufrag_.empty(); } |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 153 | |
Taylor Brandstetter | 417eebe | 2016-05-23 16:02:19 -0700 | [diff] [blame] | 154 | // Setting this filter should affect not only candidates gathered in the |
| 155 | // future, but candidates already gathered and ports already "ready", |
| 156 | // which would be returned by ReadyCandidates() and ReadyPorts(). |
| 157 | // |
| 158 | // Default filter should be CF_ALL. |
| 159 | virtual void SetCandidateFilter(uint32_t filter) = 0; |
| 160 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 161 | // Starts gathering STUN and Relay configurations. |
| 162 | virtual void StartGettingPorts() = 0; |
| 163 | virtual void StopGettingPorts() = 0; |
honghaiz | 98db68f | 2015-09-29 07:58:17 -0700 | [diff] [blame] | 164 | // Only stop the existing gathering process but may start new ones if needed. |
| 165 | virtual void ClearGettingPorts() = 0; |
| 166 | // Whether the process of getting ports has been stopped. |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 167 | virtual bool IsGettingPorts() = 0; |
| 168 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 169 | // Another way of getting the information provided by the signals below. |
| 170 | // |
| 171 | // Ports and candidates are not guaranteed to be in the same order as the |
| 172 | // signals were emitted in. |
| 173 | virtual std::vector<PortInterface*> ReadyPorts() const = 0; |
| 174 | virtual std::vector<Candidate> ReadyCandidates() const = 0; |
| 175 | virtual bool CandidatesAllocationDone() const = 0; |
| 176 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 177 | sigslot::signal2<PortAllocatorSession*, PortInterface*> SignalPortReady; |
| 178 | sigslot::signal2<PortAllocatorSession*, |
| 179 | const std::vector<Candidate>&> SignalCandidatesReady; |
| 180 | sigslot::signal1<PortAllocatorSession*> SignalCandidatesAllocationDone; |
| 181 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 182 | virtual uint32_t generation() { return generation_; } |
| 183 | virtual void set_generation(uint32_t generation) { generation_ = generation; } |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 184 | sigslot::signal1<PortAllocatorSession*> SignalDestroyed; |
| 185 | |
deadbeef | c55fb30 | 2016-05-12 12:51:38 -0700 | [diff] [blame] | 186 | protected: |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 187 | // This method is called when a pooled session (which doesn't have these |
| 188 | // properties initially) is returned by PortAllocator::TakePooledSession, |
| 189 | // and the content name, component, and ICE ufrag/pwd are updated. |
| 190 | // |
| 191 | // A subclass may need to override this method to perform additional actions, |
| 192 | // such as applying the updated information to ports and candidates. |
| 193 | virtual void UpdateIceParametersInternal() {} |
| 194 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 195 | // TODO(deadbeef): Get rid of these when everyone switches to ice_ufrag and |
| 196 | // ice_pwd. |
| 197 | const std::string& username() const { return ice_ufrag_; } |
| 198 | const std::string& password() const { return ice_pwd_; } |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 199 | |
deadbeef | c55fb30 | 2016-05-12 12:51:38 -0700 | [diff] [blame] | 200 | private: |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 201 | void SetIceParameters(const std::string& content_name, |
| 202 | int component, |
| 203 | const std::string& ice_ufrag, |
| 204 | const std::string& ice_pwd) { |
| 205 | content_name_ = content_name; |
| 206 | component_ = component; |
| 207 | ice_ufrag_ = ice_ufrag; |
| 208 | ice_pwd_ = ice_pwd; |
| 209 | UpdateIceParametersInternal(); |
| 210 | } |
| 211 | |
deadbeef | c55fb30 | 2016-05-12 12:51:38 -0700 | [diff] [blame] | 212 | uint32_t flags_; |
| 213 | uint32_t generation_; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 214 | std::string content_name_; |
| 215 | int component_; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 216 | std::string ice_ufrag_; |
| 217 | std::string ice_pwd_; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 218 | |
| 219 | // SetIceParameters is an implementation detail which only PortAllocator |
| 220 | // should be able to call. |
| 221 | friend class PortAllocator; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 222 | }; |
| 223 | |
Taylor Brandstetter | f8e6577 | 2016-06-27 17:20:15 -0700 | [diff] [blame^] | 224 | // Every method of PortAllocator (including the destructor) must be called on |
| 225 | // the same thread, except for the constructor which may be called on any |
| 226 | // thread. |
| 227 | // |
| 228 | // This allows constructing a PortAllocator subclass on one thread and |
| 229 | // passing it into an object that uses it on a different thread. |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 230 | class PortAllocator : public sigslot::has_slots<> { |
| 231 | public: |
| 232 | PortAllocator() : |
| 233 | flags_(kDefaultPortAllocatorFlags), |
| 234 | min_port_(0), |
| 235 | max_port_(0), |
| 236 | step_delay_(kDefaultStepDelay), |
| 237 | allow_tcp_listen_(true), |
| 238 | candidate_filter_(CF_ALL) { |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 239 | } |
Peter Thatcher | 73ba7a6 | 2015-04-14 09:26:03 -0700 | [diff] [blame] | 240 | virtual ~PortAllocator() {} |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 241 | |
Taylor Brandstetter | f8e6577 | 2016-06-27 17:20:15 -0700 | [diff] [blame^] | 242 | // This should be called on the PortAllocator's thread before the |
| 243 | // PortAllocator is used. Subclasses may override this if necessary. |
| 244 | virtual void Initialize() {} |
| 245 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 246 | // Set STUN and TURN servers to be used in future sessions, and set |
| 247 | // candidate pool size, as described in JSEP. |
| 248 | // |
| 249 | // If the servers are changing and the candidate pool size is nonzero, |
| 250 | // existing pooled sessions will be destroyed and new ones created. |
| 251 | // |
| 252 | // If the servers are not changing but the candidate pool size is, |
| 253 | // pooled sessions will be either created or destroyed as necessary. |
| 254 | void SetConfiguration(const ServerAddresses& stun_servers, |
| 255 | const std::vector<RelayServerConfig>& turn_servers, |
| 256 | int candidate_pool_size); |
| 257 | |
| 258 | const ServerAddresses& stun_servers() const { return stun_servers_; } |
| 259 | |
| 260 | const std::vector<RelayServerConfig>& turn_servers() const { |
| 261 | return turn_servers_; |
| 262 | } |
| 263 | |
| 264 | int candidate_pool_size() const { return target_pooled_session_count_; } |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 265 | |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 266 | // Sets the network types to ignore. |
| 267 | // Values are defined by the AdapterType enum. |
| 268 | // For instance, calling this with |
| 269 | // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and |
| 270 | // loopback interfaces. |
| 271 | virtual void SetNetworkIgnoreMask(int network_ignore_mask) = 0; |
| 272 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 273 | std::unique_ptr<PortAllocatorSession> CreateSession( |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 274 | const std::string& sid, |
| 275 | const std::string& content_name, |
| 276 | int component, |
| 277 | const std::string& ice_ufrag, |
| 278 | const std::string& ice_pwd); |
| 279 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 280 | // Get an available pooled session and set the transport information on it. |
| 281 | // |
| 282 | // Caller takes ownership of the returned session. |
| 283 | // |
| 284 | // If no pooled sessions are available, returns null. |
| 285 | std::unique_ptr<PortAllocatorSession> TakePooledSession( |
| 286 | const std::string& content_name, |
| 287 | int component, |
| 288 | const std::string& ice_ufrag, |
| 289 | const std::string& ice_pwd); |
| 290 | |
| 291 | // Returns the next session that would be returned by TakePooledSession. |
| 292 | const PortAllocatorSession* GetPooledSession() const; |
| 293 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 294 | uint32_t flags() const { return flags_; } |
| 295 | void set_flags(uint32_t flags) { flags_ = flags; } |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 296 | |
| 297 | const std::string& user_agent() const { return agent_; } |
| 298 | const rtc::ProxyInfo& proxy() const { return proxy_; } |
| 299 | void set_proxy(const std::string& agent, const rtc::ProxyInfo& proxy) { |
| 300 | agent_ = agent; |
| 301 | proxy_ = proxy; |
| 302 | } |
| 303 | |
| 304 | // Gets/Sets the port range to use when choosing client ports. |
| 305 | int min_port() const { return min_port_; } |
| 306 | int max_port() const { return max_port_; } |
| 307 | bool SetPortRange(int min_port, int max_port) { |
| 308 | if (min_port > max_port) { |
| 309 | return false; |
| 310 | } |
| 311 | |
| 312 | min_port_ = min_port; |
| 313 | max_port_ = max_port; |
| 314 | return true; |
| 315 | } |
| 316 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 317 | uint32_t step_delay() const { return step_delay_; } |
| 318 | void set_step_delay(uint32_t delay) { step_delay_ = delay; } |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 319 | |
| 320 | bool allow_tcp_listen() const { return allow_tcp_listen_; } |
| 321 | void set_allow_tcp_listen(bool allow_tcp_listen) { |
| 322 | allow_tcp_listen_ = allow_tcp_listen; |
| 323 | } |
| 324 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 325 | uint32_t candidate_filter() { return candidate_filter_; } |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 326 | void set_candidate_filter(uint32_t filter) { |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 327 | candidate_filter_ = filter; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 328 | } |
| 329 | |
pthatcher@webrtc.org | 0ba1533 | 2015-01-10 00:47:02 +0000 | [diff] [blame] | 330 | // Gets/Sets the Origin value used for WebRTC STUN requests. |
| 331 | const std::string& origin() const { return origin_; } |
| 332 | void set_origin(const std::string& origin) { origin_ = origin; } |
| 333 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 334 | protected: |
| 335 | virtual PortAllocatorSession* CreateSessionInternal( |
| 336 | const std::string& content_name, |
| 337 | int component, |
| 338 | const std::string& ice_ufrag, |
| 339 | const std::string& ice_pwd) = 0; |
| 340 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 341 | uint32_t flags_; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 342 | std::string agent_; |
| 343 | rtc::ProxyInfo proxy_; |
| 344 | int min_port_; |
| 345 | int max_port_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 346 | uint32_t step_delay_; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 347 | bool allow_tcp_listen_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 348 | uint32_t candidate_filter_; |
pthatcher@webrtc.org | 0ba1533 | 2015-01-10 00:47:02 +0000 | [diff] [blame] | 349 | std::string origin_; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 350 | |
| 351 | private: |
| 352 | ServerAddresses stun_servers_; |
| 353 | std::vector<RelayServerConfig> turn_servers_; |
| 354 | // The last size passed into SetConfiguration. |
| 355 | int target_pooled_session_count_ = 0; |
| 356 | // This variable represents the total number of pooled sessions |
| 357 | // both owned by this class and taken by TakePooledSession. |
| 358 | int allocated_pooled_session_count_ = 0; |
| 359 | std::deque<std::unique_ptr<PortAllocatorSession>> pooled_sessions_; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 360 | }; |
| 361 | |
| 362 | } // namespace cricket |
| 363 | |
| 364 | #endif // WEBRTC_P2P_BASE_PORTALLOCATOR_H_ |