blob: eec7580a1c0325af06aa44ac4617629f1e1716ec [file] [log] [blame]
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +00001/*
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 Brandstettera1c30352016-05-13 08:15:11 -070014#include <deque>
15#include <memory>
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000016#include <string>
17#include <vector>
18
deadbeef653b8e02015-11-11 12:55:10 -080019#include "webrtc/p2p/base/port.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000020#include "webrtc/p2p/base/portinterface.h"
21#include "webrtc/base/helpers.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000022#include "webrtc/base/sigslot.h"
Taylor Brandstettera1c30352016-05-13 08:15:11 -070023#include "webrtc/base/thread.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000024
Honghai Zhangd93f50c2016-10-05 11:47:22 -070025namespace webrtc {
26class MetricsObserverInterface;
27}
28
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000029namespace cricket {
30
31// PortAllocator is responsible for allocating Port types for a given
32// P2PSocket. It also handles port freeing.
33//
34// Clients can override this class to control port allocation, including
35// what kinds of ports are allocated.
36
37enum {
Guo-wei Shieh13d35f62015-08-26 15:32:56 -070038 // Disable local UDP ports. This doesn't impact how we connect to relay
39 // servers.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000040 PORTALLOCATOR_DISABLE_UDP = 0x01,
41 PORTALLOCATOR_DISABLE_STUN = 0x02,
42 PORTALLOCATOR_DISABLE_RELAY = 0x04,
Guo-wei Shieh13d35f62015-08-26 15:32:56 -070043 // Disable local TCP ports. This doesn't impact how we connect to relay
44 // servers.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000045 PORTALLOCATOR_DISABLE_TCP = 0x08,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000046 PORTALLOCATOR_ENABLE_IPV6 = 0x40,
Peter Thatcher7cbd1882015-09-17 18:54:52 -070047 // TODO(pthatcher): Remove this once it's no longer used in:
48 // remoting/client/plugin/pepper_port_allocator.cc
49 // remoting/protocol/chromium_port_allocator.cc
50 // remoting/test/fake_port_allocator.cc
51 // It's a no-op and is no longer needed.
pthatcherfa301802015-08-11 04:12:56 -070052 PORTALLOCATOR_ENABLE_SHARED_UFRAG = 0x80,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000053 PORTALLOCATOR_ENABLE_SHARED_SOCKET = 0x100,
54 PORTALLOCATOR_ENABLE_STUN_RETRANSMIT_ATTRIBUTE = 0x200,
Guo-wei Shieh9af97f82015-11-10 14:47:39 -080055 // When specified, we'll only allocate the STUN candidate for the public
56 // interface as seen by regular http traffic and the HOST candidate associated
57 // with the default local interface.
guoweis@webrtc.orgf358aea2015-02-18 18:44:01 +000058 PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION = 0x400,
Guo-wei Shieh9af97f82015-11-10 14:47:39 -080059 // When specified along with PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION, the
60 // default local candidate mentioned above will not be allocated. Only the
61 // STUN candidate will be.
62 PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE = 0x800,
Guo-wei Shieh13d35f62015-08-26 15:32:56 -070063 // Disallow use of UDP when connecting to a relay server. Since proxy servers
64 // usually don't handle UDP, using UDP will leak the IP address.
65 PORTALLOCATOR_DISABLE_UDP_RELAY = 0x1000,
honghaiz60347052016-05-31 18:29:12 -070066
67 // When multiple networks exist, do not gather candidates on the ones with
68 // high cost. So if both Wi-Fi and cellular networks exist, gather only on the
69 // Wi-Fi network. If a network type is "unknown", it has a cost lower than
70 // cellular but higher than Wi-Fi/Ethernet. So if an unknown network exists,
71 // cellular networks will not be used to gather candidates and if a Wi-Fi
72 // network is present, "unknown" networks will not be usd to gather
73 // candidates. Doing so ensures that even if a cellular network type was not
74 // detected initially, it would not be used if a Wi-Fi network is present.
75 PORTALLOCATOR_DISABLE_COSTLY_NETWORKS = 0x2000,
zhihuangb09b3f92017-03-07 14:40:51 -080076
77 // When specified, do not collect IPv6 ICE candidates on Wi-Fi.
78 PORTALLOCATOR_ENABLE_IPV6_ON_WIFI = 0x4000,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000079};
80
Honghai Zhangd93f50c2016-10-05 11:47:22 -070081// Defines various reasons that have caused ICE regathering.
82enum class IceRegatheringReason { NETWORK_CHANGE, NETWORK_FAILURE, MAX_VALUE };
83
Peter Boström0c4e06b2015-10-07 12:23:21 +020084const uint32_t kDefaultPortAllocatorFlags = 0;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000085
Peter Boström0c4e06b2015-10-07 12:23:21 +020086const uint32_t kDefaultStepDelay = 1000; // 1 sec step delay.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000087// As per RFC 5245 Appendix B.1, STUN transactions need to be paced at certain
88// internal. Less than 20ms is not acceptable. We choose 50ms as our default.
Peter Boström0c4e06b2015-10-07 12:23:21 +020089const uint32_t kMinimumStepDelay = 50;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000090
91// CF = CANDIDATE FILTER
92enum {
93 CF_NONE = 0x0,
94 CF_HOST = 0x1,
95 CF_REFLEXIVE = 0x2,
96 CF_RELAY = 0x4,
97 CF_ALL = 0x7,
98};
99
hnsl04833622017-01-09 08:35:45 -0800100// TLS certificate policy.
101enum class TlsCertPolicy {
102 // For TLS based protocols, ensure the connection is secure by not
103 // circumventing certificate validation.
104 TLS_CERT_POLICY_SECURE,
105 // For TLS based protocols, disregard security completely by skipping
106 // certificate validation. This is insecure and should never be used unless
107 // security is irrelevant in that particular context.
108 TLS_CERT_POLICY_INSECURE_NO_CHECK,
109};
110
deadbeef653b8e02015-11-11 12:55:10 -0800111// TODO(deadbeef): Rename to TurnCredentials (and username to ufrag).
112struct RelayCredentials {
113 RelayCredentials() {}
114 RelayCredentials(const std::string& username, const std::string& password)
115 : username(username), password(password) {}
116
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700117 bool operator==(const RelayCredentials& o) const {
118 return username == o.username && password == o.password;
119 }
120 bool operator!=(const RelayCredentials& o) const { return !(*this == o); }
121
deadbeef653b8e02015-11-11 12:55:10 -0800122 std::string username;
123 std::string password;
124};
125
126typedef std::vector<ProtocolAddress> PortList;
127// TODO(deadbeef): Rename to TurnServerConfig.
128struct RelayServerConfig {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700129 RelayServerConfig(RelayType type) : type(type) {}
deadbeef653b8e02015-11-11 12:55:10 -0800130
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800131 RelayServerConfig(const std::string& address,
132 int port,
133 const std::string& username,
134 const std::string& password,
hnsl277b2502016-12-13 05:17:23 -0800135 ProtocolType proto)
136 : type(RELAY_TURN), credentials(username, password) {
137 ports.push_back(ProtocolAddress(rtc::SocketAddress(address, port), proto));
138 }
139
140 // Legacy constructor where "secure" and PROTO_TCP implies PROTO_TLS.
141 RelayServerConfig(const std::string& address,
142 int port,
143 const std::string& username,
144 const std::string& password,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800145 ProtocolType proto,
146 bool secure)
hnsl277b2502016-12-13 05:17:23 -0800147 : RelayServerConfig(address,
148 port,
149 username,
150 password,
151 (proto == PROTO_TCP && secure ? PROTO_TLS : proto)) {}
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800152
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700153 bool operator==(const RelayServerConfig& o) const {
154 return type == o.type && ports == o.ports && credentials == o.credentials &&
155 priority == o.priority;
156 }
157 bool operator!=(const RelayServerConfig& o) const { return !(*this == o); }
158
deadbeef653b8e02015-11-11 12:55:10 -0800159 RelayType type;
160 PortList ports;
161 RelayCredentials credentials;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700162 int priority = 0;
hnsl04833622017-01-09 08:35:45 -0800163 TlsCertPolicy tls_cert_policy = TlsCertPolicy::TLS_CERT_POLICY_SECURE;
deadbeef653b8e02015-11-11 12:55:10 -0800164};
165
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000166class PortAllocatorSession : public sigslot::has_slots<> {
167 public:
168 // Content name passed in mostly for logging and debugging.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000169 PortAllocatorSession(const std::string& content_name,
170 int component,
deadbeefcbecd352015-09-23 11:50:27 -0700171 const std::string& ice_ufrag,
172 const std::string& ice_pwd,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200173 uint32_t flags);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000174
175 // Subclasses should clean up any ports created.
176 virtual ~PortAllocatorSession() {}
177
Peter Boström0c4e06b2015-10-07 12:23:21 +0200178 uint32_t flags() const { return flags_; }
179 void set_flags(uint32_t flags) { flags_ = flags; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000180 std::string content_name() const { return content_name_; }
181 int component() const { return component_; }
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700182 const std::string& ice_ufrag() const { return ice_ufrag_; }
183 const std::string& ice_pwd() const { return ice_pwd_; }
184 bool pooled() const { return ice_ufrag_.empty(); }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000185
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700186 // Setting this filter should affect not only candidates gathered in the
187 // future, but candidates already gathered and ports already "ready",
188 // which would be returned by ReadyCandidates() and ReadyPorts().
189 //
190 // Default filter should be CF_ALL.
191 virtual void SetCandidateFilter(uint32_t filter) = 0;
192
deadbeefb60a8192016-08-24 15:15:00 -0700193 // Starts gathering ports and ICE candidates.
Honghai Zhangd8f6fc42016-07-01 17:31:12 -0700194 virtual void StartGettingPorts() = 0;
deadbeefb60a8192016-08-24 15:15:00 -0700195 // Completely stops gathering. Will not gather again unless StartGettingPorts
196 // is called again.
Honghai Zhangd8f6fc42016-07-01 17:31:12 -0700197 virtual void StopGettingPorts() = 0;
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700198 // Whether the session is actively getting ports.
Honghai Zhangd8f6fc42016-07-01 17:31:12 -0700199 virtual bool IsGettingPorts() = 0;
deadbeefb60a8192016-08-24 15:15:00 -0700200
201 //
202 // NOTE: The group of methods below is only used for continual gathering.
203 //
204
205 // ClearGettingPorts should have the same immediate effect as
206 // StopGettingPorts, but if the implementation supports continual gathering,
207 // ClearGettingPorts allows additional ports/candidates to be gathered if the
208 // network conditions change.
Honghai Zhangd8f6fc42016-07-01 17:31:12 -0700209 virtual void ClearGettingPorts() = 0;
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700210 // Whether it is in the state where the existing gathering process is stopped,
211 // but new ones may be started (basically after calling ClearGettingPorts).
Honghai Zhangd8f6fc42016-07-01 17:31:12 -0700212 virtual bool IsCleared() const { return false; }
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700213 // Whether the session has completely stopped.
Honghai Zhangd8f6fc42016-07-01 17:31:12 -0700214 virtual bool IsStopped() const { return false; }
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700215 // Re-gathers candidates on networks that do not have any connections. More
216 // precisely, a network interface may have more than one IP addresses (e.g.,
217 // IPv4 and IPv6 addresses). Each address subnet will be used to create a
218 // network. Only if all networks of an interface have no connection, the
219 // implementation should start re-gathering on all networks of that interface.
220 virtual void RegatherOnFailedNetworks() {}
221 // Re-gathers candidates on all networks.
222 // TODO(honghaiz): Implement this in BasicPortAllocator.
223 virtual void RegatherOnAllNetworks() {}
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000224
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700225 // Another way of getting the information provided by the signals below.
226 //
227 // Ports and candidates are not guaranteed to be in the same order as the
228 // signals were emitted in.
229 virtual std::vector<PortInterface*> ReadyPorts() const = 0;
230 virtual std::vector<Candidate> ReadyCandidates() const = 0;
231 virtual bool CandidatesAllocationDone() const = 0;
Honghai Zhanga74363c2016-07-28 18:06:15 -0700232 // Marks all ports in the current session as "pruned" so that they may be
233 // destroyed if no connection is using them.
234 virtual void PruneAllPorts() {}
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700235
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000236 sigslot::signal2<PortAllocatorSession*, PortInterface*> SignalPortReady;
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700237 // Fires this signal when the network of the ports failed (either because the
238 // interface is down, or because there is no connection on the interface),
239 // or when TURN ports are pruned because a higher-priority TURN port becomes
240 // ready(pairable).
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700241 sigslot::signal2<PortAllocatorSession*, const std::vector<PortInterface*>&>
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700242 SignalPortsPruned;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000243 sigslot::signal2<PortAllocatorSession*,
244 const std::vector<Candidate>&> SignalCandidatesReady;
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700245 // Candidates should be signaled to be removed when the port that generated
246 // the candidates is removed.
247 sigslot::signal2<PortAllocatorSession*, const std::vector<Candidate>&>
248 SignalCandidatesRemoved;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000249 sigslot::signal1<PortAllocatorSession*> SignalCandidatesAllocationDone;
250
Honghai Zhangd93f50c2016-10-05 11:47:22 -0700251 sigslot::signal2<PortAllocatorSession*, IceRegatheringReason>
252 SignalIceRegathering;
253
Peter Boström0c4e06b2015-10-07 12:23:21 +0200254 virtual uint32_t generation() { return generation_; }
255 virtual void set_generation(uint32_t generation) { generation_ = generation; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000256 sigslot::signal1<PortAllocatorSession*> SignalDestroyed;
257
deadbeefc55fb302016-05-12 12:51:38 -0700258 protected:
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700259 // This method is called when a pooled session (which doesn't have these
260 // properties initially) is returned by PortAllocator::TakePooledSession,
261 // and the content name, component, and ICE ufrag/pwd are updated.
262 //
263 // A subclass may need to override this method to perform additional actions,
264 // such as applying the updated information to ports and candidates.
265 virtual void UpdateIceParametersInternal() {}
266
deadbeefcbecd352015-09-23 11:50:27 -0700267 // TODO(deadbeef): Get rid of these when everyone switches to ice_ufrag and
268 // ice_pwd.
269 const std::string& username() const { return ice_ufrag_; }
270 const std::string& password() const { return ice_pwd_; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000271
deadbeefc55fb302016-05-12 12:51:38 -0700272 private:
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700273 void SetIceParameters(const std::string& content_name,
274 int component,
275 const std::string& ice_ufrag,
276 const std::string& ice_pwd) {
277 content_name_ = content_name;
278 component_ = component;
279 ice_ufrag_ = ice_ufrag;
280 ice_pwd_ = ice_pwd;
281 UpdateIceParametersInternal();
282 }
283
deadbeefc55fb302016-05-12 12:51:38 -0700284 uint32_t flags_;
285 uint32_t generation_;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700286 std::string content_name_;
287 int component_;
deadbeefcbecd352015-09-23 11:50:27 -0700288 std::string ice_ufrag_;
289 std::string ice_pwd_;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700290
291 // SetIceParameters is an implementation detail which only PortAllocator
292 // should be able to call.
293 friend class PortAllocator;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000294};
295
Taylor Brandstetterf8e65772016-06-27 17:20:15 -0700296// Every method of PortAllocator (including the destructor) must be called on
297// the same thread, except for the constructor which may be called on any
298// thread.
299//
300// This allows constructing a PortAllocator subclass on one thread and
301// passing it into an object that uses it on a different thread.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000302class PortAllocator : public sigslot::has_slots<> {
303 public:
304 PortAllocator() :
305 flags_(kDefaultPortAllocatorFlags),
306 min_port_(0),
307 max_port_(0),
308 step_delay_(kDefaultStepDelay),
309 allow_tcp_listen_(true),
310 candidate_filter_(CF_ALL) {
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000311 }
deadbeef42a42632017-03-10 15:18:00 -0800312
Peter Thatcher73ba7a62015-04-14 09:26:03 -0700313 virtual ~PortAllocator() {}
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000314
Taylor Brandstetterf8e65772016-06-27 17:20:15 -0700315 // This should be called on the PortAllocator's thread before the
316 // PortAllocator is used. Subclasses may override this if necessary.
317 virtual void Initialize() {}
318
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700319 // Set STUN and TURN servers to be used in future sessions, and set
320 // candidate pool size, as described in JSEP.
321 //
deadbeef42a42632017-03-10 15:18:00 -0800322 // If the servers are changing, and the candidate pool size is nonzero, and
323 // FreezeCandidatePool hasn't been called, existing pooled sessions will be
324 // destroyed and new ones created.
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700325 //
deadbeef42a42632017-03-10 15:18:00 -0800326 // If the servers are not changing but the candidate pool size is, and
327 // FreezeCandidatePool hasn't been called, pooled sessions will be either
328 // created or destroyed as necessary.
deadbeef6de92f92016-12-12 18:49:32 -0800329 //
330 // Returns true if the configuration could successfully be changed.
331 bool SetConfiguration(const ServerAddresses& stun_servers,
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700332 const std::vector<RelayServerConfig>& turn_servers,
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700333 int candidate_pool_size,
334 bool prune_turn_ports);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700335
336 const ServerAddresses& stun_servers() const { return stun_servers_; }
337
338 const std::vector<RelayServerConfig>& turn_servers() const {
339 return turn_servers_;
340 }
341
deadbeef6de92f92016-12-12 18:49:32 -0800342 int candidate_pool_size() const { return candidate_pool_size_; }
deadbeef653b8e02015-11-11 12:55:10 -0800343
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800344 // Sets the network types to ignore.
345 // Values are defined by the AdapterType enum.
346 // For instance, calling this with
347 // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
348 // loopback interfaces.
349 virtual void SetNetworkIgnoreMask(int network_ignore_mask) = 0;
350
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700351 std::unique_ptr<PortAllocatorSession> CreateSession(
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000352 const std::string& content_name,
353 int component,
354 const std::string& ice_ufrag,
355 const std::string& ice_pwd);
356
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700357 // Get an available pooled session and set the transport information on it.
358 //
359 // Caller takes ownership of the returned session.
360 //
361 // If no pooled sessions are available, returns null.
362 std::unique_ptr<PortAllocatorSession> TakePooledSession(
363 const std::string& content_name,
364 int component,
365 const std::string& ice_ufrag,
366 const std::string& ice_pwd);
367
368 // Returns the next session that would be returned by TakePooledSession.
369 const PortAllocatorSession* GetPooledSession() const;
370
deadbeef42a42632017-03-10 15:18:00 -0800371 // After FreezeCandidatePool is called, changing the candidate pool size will
372 // no longer be allowed, and changing ICE servers will not cause pooled
373 // sessions to be recreated.
374 //
375 // Expected to be called when SetLocalDescription is called on a
376 // PeerConnection. Can be called safely on any thread as long as not
377 // simultaneously with SetConfiguration.
378 void FreezeCandidatePool();
379
380 // Discard any remaining pooled sessions.
381 void DiscardCandidatePool();
382
Peter Boström0c4e06b2015-10-07 12:23:21 +0200383 uint32_t flags() const { return flags_; }
384 void set_flags(uint32_t flags) { flags_ = flags; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000385
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000386 // Gets/Sets the port range to use when choosing client ports.
387 int min_port() const { return min_port_; }
388 int max_port() const { return max_port_; }
389 bool SetPortRange(int min_port, int max_port) {
390 if (min_port > max_port) {
391 return false;
392 }
393
394 min_port_ = min_port;
395 max_port_ = max_port;
396 return true;
397 }
398
Peter Boström0c4e06b2015-10-07 12:23:21 +0200399 uint32_t step_delay() const { return step_delay_; }
400 void set_step_delay(uint32_t delay) { step_delay_ = delay; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000401
402 bool allow_tcp_listen() const { return allow_tcp_listen_; }
403 void set_allow_tcp_listen(bool allow_tcp_listen) {
404 allow_tcp_listen_ = allow_tcp_listen;
405 }
406
Peter Boström0c4e06b2015-10-07 12:23:21 +0200407 uint32_t candidate_filter() { return candidate_filter_; }
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700408 void set_candidate_filter(uint32_t filter) {
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000409 candidate_filter_ = filter;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000410 }
411
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700412 bool prune_turn_ports() const { return prune_turn_ports_; }
413
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000414 // Gets/Sets the Origin value used for WebRTC STUN requests.
415 const std::string& origin() const { return origin_; }
416 void set_origin(const std::string& origin) { origin_ = origin; }
417
Honghai Zhangd93f50c2016-10-05 11:47:22 -0700418 void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) {
419 metrics_observer_ = observer;
420 }
421
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000422 protected:
423 virtual PortAllocatorSession* CreateSessionInternal(
424 const std::string& content_name,
425 int component,
426 const std::string& ice_ufrag,
427 const std::string& ice_pwd) = 0;
428
Honghai Zhangd93f50c2016-10-05 11:47:22 -0700429 webrtc::MetricsObserverInterface* metrics_observer() {
430 return metrics_observer_;
431 }
432
433 const std::deque<std::unique_ptr<PortAllocatorSession>>& pooled_sessions() {
434 return pooled_sessions_;
435 }
436
Peter Boström0c4e06b2015-10-07 12:23:21 +0200437 uint32_t flags_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000438 int min_port_;
439 int max_port_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200440 uint32_t step_delay_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000441 bool allow_tcp_listen_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200442 uint32_t candidate_filter_;
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000443 std::string origin_;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700444
445 private:
446 ServerAddresses stun_servers_;
447 std::vector<RelayServerConfig> turn_servers_;
deadbeef6de92f92016-12-12 18:49:32 -0800448 int candidate_pool_size_ = 0; // Last value passed into SetConfiguration.
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700449 std::deque<std::unique_ptr<PortAllocatorSession>> pooled_sessions_;
deadbeef42a42632017-03-10 15:18:00 -0800450 bool candidate_pool_frozen_ = false;
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700451 bool prune_turn_ports_ = false;
Honghai Zhangd93f50c2016-10-05 11:47:22 -0700452
453 webrtc::MetricsObserverInterface* metrics_observer_ = nullptr;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000454};
455
456} // namespace cricket
457
458#endif // WEBRTC_P2P_BASE_PORTALLOCATOR_H_