blob: 51474297f77d1726cb1333dbceca8f3c361377d1 [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"
22#include "webrtc/base/proxyinfo.h"
23#include "webrtc/base/sigslot.h"
Taylor Brandstettera1c30352016-05-13 08:15:11 -070024#include "webrtc/base/thread.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000025
Honghai Zhangd93f50c2016-10-05 11:47:22 -070026namespace webrtc {
27class MetricsObserverInterface;
28}
29
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000030namespace cricket {
31
32// PortAllocator is responsible for allocating Port types for a given
33// P2PSocket. It also handles port freeing.
34//
35// Clients can override this class to control port allocation, including
36// what kinds of ports are allocated.
37
38enum {
Guo-wei Shieh13d35f62015-08-26 15:32:56 -070039 // Disable local UDP ports. This doesn't impact how we connect to relay
40 // servers.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000041 PORTALLOCATOR_DISABLE_UDP = 0x01,
42 PORTALLOCATOR_DISABLE_STUN = 0x02,
43 PORTALLOCATOR_DISABLE_RELAY = 0x04,
Guo-wei Shieh13d35f62015-08-26 15:32:56 -070044 // Disable local TCP ports. This doesn't impact how we connect to relay
45 // servers.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000046 PORTALLOCATOR_DISABLE_TCP = 0x08,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000047 PORTALLOCATOR_ENABLE_IPV6 = 0x40,
Peter Thatcher7cbd1882015-09-17 18:54:52 -070048 // TODO(pthatcher): Remove this once it's no longer used in:
49 // remoting/client/plugin/pepper_port_allocator.cc
50 // remoting/protocol/chromium_port_allocator.cc
51 // remoting/test/fake_port_allocator.cc
52 // It's a no-op and is no longer needed.
pthatcherfa301802015-08-11 04:12:56 -070053 PORTALLOCATOR_ENABLE_SHARED_UFRAG = 0x80,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000054 PORTALLOCATOR_ENABLE_SHARED_SOCKET = 0x100,
55 PORTALLOCATOR_ENABLE_STUN_RETRANSMIT_ATTRIBUTE = 0x200,
Guo-wei Shieh9af97f82015-11-10 14:47:39 -080056 // When specified, we'll only allocate the STUN candidate for the public
57 // interface as seen by regular http traffic and the HOST candidate associated
58 // with the default local interface.
guoweis@webrtc.orgf358aea2015-02-18 18:44:01 +000059 PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION = 0x400,
Guo-wei Shieh9af97f82015-11-10 14:47:39 -080060 // When specified along with PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION, the
61 // default local candidate mentioned above will not be allocated. Only the
62 // STUN candidate will be.
63 PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE = 0x800,
Guo-wei Shieh13d35f62015-08-26 15:32:56 -070064 // Disallow use of UDP when connecting to a relay server. Since proxy servers
65 // usually don't handle UDP, using UDP will leak the IP address.
66 PORTALLOCATOR_DISABLE_UDP_RELAY = 0x1000,
honghaiz60347052016-05-31 18:29:12 -070067
68 // When multiple networks exist, do not gather candidates on the ones with
69 // high cost. So if both Wi-Fi and cellular networks exist, gather only on the
70 // Wi-Fi network. If a network type is "unknown", it has a cost lower than
71 // cellular but higher than Wi-Fi/Ethernet. So if an unknown network exists,
72 // cellular networks will not be used to gather candidates and if a Wi-Fi
73 // network is present, "unknown" networks will not be usd to gather
74 // candidates. Doing so ensures that even if a cellular network type was not
75 // detected initially, it would not be used if a Wi-Fi network is present.
76 PORTALLOCATOR_DISABLE_COSTLY_NETWORKS = 0x2000,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000077};
78
Honghai Zhangd93f50c2016-10-05 11:47:22 -070079// Defines various reasons that have caused ICE regathering.
80enum class IceRegatheringReason { NETWORK_CHANGE, NETWORK_FAILURE, MAX_VALUE };
81
Peter Boström0c4e06b2015-10-07 12:23:21 +020082const uint32_t kDefaultPortAllocatorFlags = 0;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000083
Peter Boström0c4e06b2015-10-07 12:23:21 +020084const uint32_t kDefaultStepDelay = 1000; // 1 sec step delay.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000085// As per RFC 5245 Appendix B.1, STUN transactions need to be paced at certain
86// internal. Less than 20ms is not acceptable. We choose 50ms as our default.
Peter Boström0c4e06b2015-10-07 12:23:21 +020087const uint32_t kMinimumStepDelay = 50;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000088
89// CF = CANDIDATE FILTER
90enum {
91 CF_NONE = 0x0,
92 CF_HOST = 0x1,
93 CF_REFLEXIVE = 0x2,
94 CF_RELAY = 0x4,
95 CF_ALL = 0x7,
96};
97
hnsl04833622017-01-09 08:35:45 -080098// TLS certificate policy.
99enum class TlsCertPolicy {
100 // For TLS based protocols, ensure the connection is secure by not
101 // circumventing certificate validation.
102 TLS_CERT_POLICY_SECURE,
103 // For TLS based protocols, disregard security completely by skipping
104 // certificate validation. This is insecure and should never be used unless
105 // security is irrelevant in that particular context.
106 TLS_CERT_POLICY_INSECURE_NO_CHECK,
107};
108
deadbeef653b8e02015-11-11 12:55:10 -0800109// TODO(deadbeef): Rename to TurnCredentials (and username to ufrag).
110struct RelayCredentials {
111 RelayCredentials() {}
112 RelayCredentials(const std::string& username, const std::string& password)
113 : username(username), password(password) {}
114
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700115 bool operator==(const RelayCredentials& o) const {
116 return username == o.username && password == o.password;
117 }
118 bool operator!=(const RelayCredentials& o) const { return !(*this == o); }
119
deadbeef653b8e02015-11-11 12:55:10 -0800120 std::string username;
121 std::string password;
122};
123
124typedef std::vector<ProtocolAddress> PortList;
125// TODO(deadbeef): Rename to TurnServerConfig.
126struct RelayServerConfig {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700127 RelayServerConfig(RelayType type) : type(type) {}
deadbeef653b8e02015-11-11 12:55:10 -0800128
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800129 RelayServerConfig(const std::string& address,
130 int port,
131 const std::string& username,
132 const std::string& password,
hnsl277b2502016-12-13 05:17:23 -0800133 ProtocolType proto)
134 : type(RELAY_TURN), credentials(username, password) {
135 ports.push_back(ProtocolAddress(rtc::SocketAddress(address, port), proto));
136 }
137
138 // Legacy constructor where "secure" and PROTO_TCP implies PROTO_TLS.
139 RelayServerConfig(const std::string& address,
140 int port,
141 const std::string& username,
142 const std::string& password,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800143 ProtocolType proto,
144 bool secure)
hnsl277b2502016-12-13 05:17:23 -0800145 : RelayServerConfig(address,
146 port,
147 username,
148 password,
149 (proto == PROTO_TCP && secure ? PROTO_TLS : proto)) {}
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800150
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700151 bool operator==(const RelayServerConfig& o) const {
152 return type == o.type && ports == o.ports && credentials == o.credentials &&
153 priority == o.priority;
154 }
155 bool operator!=(const RelayServerConfig& o) const { return !(*this == o); }
156
deadbeef653b8e02015-11-11 12:55:10 -0800157 RelayType type;
158 PortList ports;
159 RelayCredentials credentials;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700160 int priority = 0;
hnsl04833622017-01-09 08:35:45 -0800161 TlsCertPolicy tls_cert_policy = TlsCertPolicy::TLS_CERT_POLICY_SECURE;
deadbeef653b8e02015-11-11 12:55:10 -0800162};
163
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000164class PortAllocatorSession : public sigslot::has_slots<> {
165 public:
166 // Content name passed in mostly for logging and debugging.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000167 PortAllocatorSession(const std::string& content_name,
168 int component,
deadbeefcbecd352015-09-23 11:50:27 -0700169 const std::string& ice_ufrag,
170 const std::string& ice_pwd,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200171 uint32_t flags);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000172
173 // Subclasses should clean up any ports created.
174 virtual ~PortAllocatorSession() {}
175
Peter Boström0c4e06b2015-10-07 12:23:21 +0200176 uint32_t flags() const { return flags_; }
177 void set_flags(uint32_t flags) { flags_ = flags; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000178 std::string content_name() const { return content_name_; }
179 int component() const { return component_; }
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700180 const std::string& ice_ufrag() const { return ice_ufrag_; }
181 const std::string& ice_pwd() const { return ice_pwd_; }
182 bool pooled() const { return ice_ufrag_.empty(); }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000183
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700184 // Setting this filter should affect not only candidates gathered in the
185 // future, but candidates already gathered and ports already "ready",
186 // which would be returned by ReadyCandidates() and ReadyPorts().
187 //
188 // Default filter should be CF_ALL.
189 virtual void SetCandidateFilter(uint32_t filter) = 0;
190
deadbeefb60a8192016-08-24 15:15:00 -0700191 // Starts gathering ports and ICE candidates.
Honghai Zhangd8f6fc42016-07-01 17:31:12 -0700192 virtual void StartGettingPorts() = 0;
deadbeefb60a8192016-08-24 15:15:00 -0700193 // Completely stops gathering. Will not gather again unless StartGettingPorts
194 // is called again.
Honghai Zhangd8f6fc42016-07-01 17:31:12 -0700195 virtual void StopGettingPorts() = 0;
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700196 // Whether the session is actively getting ports.
Honghai Zhangd8f6fc42016-07-01 17:31:12 -0700197 virtual bool IsGettingPorts() = 0;
deadbeefb60a8192016-08-24 15:15:00 -0700198
199 //
200 // NOTE: The group of methods below is only used for continual gathering.
201 //
202
203 // ClearGettingPorts should have the same immediate effect as
204 // StopGettingPorts, but if the implementation supports continual gathering,
205 // ClearGettingPorts allows additional ports/candidates to be gathered if the
206 // network conditions change.
Honghai Zhangd8f6fc42016-07-01 17:31:12 -0700207 virtual void ClearGettingPorts() = 0;
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700208 // Whether it is in the state where the existing gathering process is stopped,
209 // but new ones may be started (basically after calling ClearGettingPorts).
Honghai Zhangd8f6fc42016-07-01 17:31:12 -0700210 virtual bool IsCleared() const { return false; }
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700211 // Whether the session has completely stopped.
Honghai Zhangd8f6fc42016-07-01 17:31:12 -0700212 virtual bool IsStopped() const { return false; }
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700213 // Re-gathers candidates on networks that do not have any connections. More
214 // precisely, a network interface may have more than one IP addresses (e.g.,
215 // IPv4 and IPv6 addresses). Each address subnet will be used to create a
216 // network. Only if all networks of an interface have no connection, the
217 // implementation should start re-gathering on all networks of that interface.
218 virtual void RegatherOnFailedNetworks() {}
219 // Re-gathers candidates on all networks.
220 // TODO(honghaiz): Implement this in BasicPortAllocator.
221 virtual void RegatherOnAllNetworks() {}
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000222
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700223 // Another way of getting the information provided by the signals below.
224 //
225 // Ports and candidates are not guaranteed to be in the same order as the
226 // signals were emitted in.
227 virtual std::vector<PortInterface*> ReadyPorts() const = 0;
228 virtual std::vector<Candidate> ReadyCandidates() const = 0;
229 virtual bool CandidatesAllocationDone() const = 0;
Honghai Zhanga74363c2016-07-28 18:06:15 -0700230 // Marks all ports in the current session as "pruned" so that they may be
231 // destroyed if no connection is using them.
232 virtual void PruneAllPorts() {}
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700233
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000234 sigslot::signal2<PortAllocatorSession*, PortInterface*> SignalPortReady;
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700235 // Fires this signal when the network of the ports failed (either because the
236 // interface is down, or because there is no connection on the interface),
237 // or when TURN ports are pruned because a higher-priority TURN port becomes
238 // ready(pairable).
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700239 sigslot::signal2<PortAllocatorSession*, const std::vector<PortInterface*>&>
Honghai Zhang8eeecab2016-07-28 13:20:15 -0700240 SignalPortsPruned;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000241 sigslot::signal2<PortAllocatorSession*,
242 const std::vector<Candidate>&> SignalCandidatesReady;
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700243 // Candidates should be signaled to be removed when the port that generated
244 // the candidates is removed.
245 sigslot::signal2<PortAllocatorSession*, const std::vector<Candidate>&>
246 SignalCandidatesRemoved;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000247 sigslot::signal1<PortAllocatorSession*> SignalCandidatesAllocationDone;
248
Honghai Zhangd93f50c2016-10-05 11:47:22 -0700249 sigslot::signal2<PortAllocatorSession*, IceRegatheringReason>
250 SignalIceRegathering;
251
Peter Boström0c4e06b2015-10-07 12:23:21 +0200252 virtual uint32_t generation() { return generation_; }
253 virtual void set_generation(uint32_t generation) { generation_ = generation; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000254 sigslot::signal1<PortAllocatorSession*> SignalDestroyed;
255
deadbeefc55fb302016-05-12 12:51:38 -0700256 protected:
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700257 // This method is called when a pooled session (which doesn't have these
258 // properties initially) is returned by PortAllocator::TakePooledSession,
259 // and the content name, component, and ICE ufrag/pwd are updated.
260 //
261 // A subclass may need to override this method to perform additional actions,
262 // such as applying the updated information to ports and candidates.
263 virtual void UpdateIceParametersInternal() {}
264
deadbeefcbecd352015-09-23 11:50:27 -0700265 // TODO(deadbeef): Get rid of these when everyone switches to ice_ufrag and
266 // ice_pwd.
267 const std::string& username() const { return ice_ufrag_; }
268 const std::string& password() const { return ice_pwd_; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000269
deadbeefc55fb302016-05-12 12:51:38 -0700270 private:
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700271 void SetIceParameters(const std::string& content_name,
272 int component,
273 const std::string& ice_ufrag,
274 const std::string& ice_pwd) {
275 content_name_ = content_name;
276 component_ = component;
277 ice_ufrag_ = ice_ufrag;
278 ice_pwd_ = ice_pwd;
279 UpdateIceParametersInternal();
280 }
281
deadbeefc55fb302016-05-12 12:51:38 -0700282 uint32_t flags_;
283 uint32_t generation_;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700284 std::string content_name_;
285 int component_;
deadbeefcbecd352015-09-23 11:50:27 -0700286 std::string ice_ufrag_;
287 std::string ice_pwd_;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700288
289 // SetIceParameters is an implementation detail which only PortAllocator
290 // should be able to call.
291 friend class PortAllocator;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000292};
293
Taylor Brandstetterf8e65772016-06-27 17:20:15 -0700294// Every method of PortAllocator (including the destructor) must be called on
295// the same thread, except for the constructor which may be called on any
296// thread.
297//
298// This allows constructing a PortAllocator subclass on one thread and
299// passing it into an object that uses it on a different thread.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000300class PortAllocator : public sigslot::has_slots<> {
301 public:
302 PortAllocator() :
303 flags_(kDefaultPortAllocatorFlags),
304 min_port_(0),
305 max_port_(0),
306 step_delay_(kDefaultStepDelay),
307 allow_tcp_listen_(true),
308 candidate_filter_(CF_ALL) {
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000309 }
Peter Thatcher73ba7a62015-04-14 09:26:03 -0700310 virtual ~PortAllocator() {}
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000311
Taylor Brandstetterf8e65772016-06-27 17:20:15 -0700312 // This should be called on the PortAllocator's thread before the
313 // PortAllocator is used. Subclasses may override this if necessary.
314 virtual void Initialize() {}
315
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700316 // Set STUN and TURN servers to be used in future sessions, and set
317 // candidate pool size, as described in JSEP.
318 //
319 // If the servers are changing and the candidate pool size is nonzero,
320 // existing pooled sessions will be destroyed and new ones created.
321 //
322 // If the servers are not changing but the candidate pool size is,
323 // pooled sessions will be either created or destroyed as necessary.
deadbeef6de92f92016-12-12 18:49:32 -0800324 //
325 // Returns true if the configuration could successfully be changed.
326 bool SetConfiguration(const ServerAddresses& stun_servers,
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700327 const std::vector<RelayServerConfig>& turn_servers,
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700328 int candidate_pool_size,
329 bool prune_turn_ports);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700330
331 const ServerAddresses& stun_servers() const { return stun_servers_; }
332
333 const std::vector<RelayServerConfig>& turn_servers() const {
334 return turn_servers_;
335 }
336
deadbeef6de92f92016-12-12 18:49:32 -0800337 int candidate_pool_size() const { return candidate_pool_size_; }
deadbeef653b8e02015-11-11 12:55:10 -0800338
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800339 // Sets the network types to ignore.
340 // Values are defined by the AdapterType enum.
341 // For instance, calling this with
342 // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
343 // loopback interfaces.
344 virtual void SetNetworkIgnoreMask(int network_ignore_mask) = 0;
345
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700346 std::unique_ptr<PortAllocatorSession> CreateSession(
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000347 const std::string& content_name,
348 int component,
349 const std::string& ice_ufrag,
350 const std::string& ice_pwd);
351
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700352 // Get an available pooled session and set the transport information on it.
353 //
354 // Caller takes ownership of the returned session.
355 //
356 // If no pooled sessions are available, returns null.
357 std::unique_ptr<PortAllocatorSession> TakePooledSession(
358 const std::string& content_name,
359 int component,
360 const std::string& ice_ufrag,
361 const std::string& ice_pwd);
362
363 // Returns the next session that would be returned by TakePooledSession.
364 const PortAllocatorSession* GetPooledSession() const;
365
Peter Boström0c4e06b2015-10-07 12:23:21 +0200366 uint32_t flags() const { return flags_; }
367 void set_flags(uint32_t flags) { flags_ = flags; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000368
369 const std::string& user_agent() const { return agent_; }
370 const rtc::ProxyInfo& proxy() const { return proxy_; }
371 void set_proxy(const std::string& agent, const rtc::ProxyInfo& proxy) {
372 agent_ = agent;
373 proxy_ = proxy;
374 }
375
376 // Gets/Sets the port range to use when choosing client ports.
377 int min_port() const { return min_port_; }
378 int max_port() const { return max_port_; }
379 bool SetPortRange(int min_port, int max_port) {
380 if (min_port > max_port) {
381 return false;
382 }
383
384 min_port_ = min_port;
385 max_port_ = max_port;
386 return true;
387 }
388
Peter Boström0c4e06b2015-10-07 12:23:21 +0200389 uint32_t step_delay() const { return step_delay_; }
390 void set_step_delay(uint32_t delay) { step_delay_ = delay; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000391
392 bool allow_tcp_listen() const { return allow_tcp_listen_; }
393 void set_allow_tcp_listen(bool allow_tcp_listen) {
394 allow_tcp_listen_ = allow_tcp_listen;
395 }
396
Peter Boström0c4e06b2015-10-07 12:23:21 +0200397 uint32_t candidate_filter() { return candidate_filter_; }
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700398 void set_candidate_filter(uint32_t filter) {
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000399 candidate_filter_ = filter;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000400 }
401
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700402 bool prune_turn_ports() const { return prune_turn_ports_; }
403
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000404 // Gets/Sets the Origin value used for WebRTC STUN requests.
405 const std::string& origin() const { return origin_; }
406 void set_origin(const std::string& origin) { origin_ = origin; }
407
Honghai Zhangd93f50c2016-10-05 11:47:22 -0700408 void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) {
409 metrics_observer_ = observer;
410 }
411
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000412 protected:
413 virtual PortAllocatorSession* CreateSessionInternal(
414 const std::string& content_name,
415 int component,
416 const std::string& ice_ufrag,
417 const std::string& ice_pwd) = 0;
418
Honghai Zhangd93f50c2016-10-05 11:47:22 -0700419 webrtc::MetricsObserverInterface* metrics_observer() {
420 return metrics_observer_;
421 }
422
423 const std::deque<std::unique_ptr<PortAllocatorSession>>& pooled_sessions() {
424 return pooled_sessions_;
425 }
426
Peter Boström0c4e06b2015-10-07 12:23:21 +0200427 uint32_t flags_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000428 std::string agent_;
429 rtc::ProxyInfo proxy_;
430 int min_port_;
431 int max_port_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200432 uint32_t step_delay_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000433 bool allow_tcp_listen_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200434 uint32_t candidate_filter_;
pthatcher@webrtc.org0ba15332015-01-10 00:47:02 +0000435 std::string origin_;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700436
437 private:
438 ServerAddresses stun_servers_;
439 std::vector<RelayServerConfig> turn_servers_;
deadbeef6de92f92016-12-12 18:49:32 -0800440 int candidate_pool_size_ = 0; // Last value passed into SetConfiguration.
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700441 std::deque<std::unique_ptr<PortAllocatorSession>> pooled_sessions_;
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700442 bool prune_turn_ports_ = false;
Honghai Zhangd93f50c2016-10-05 11:47:22 -0700443
444 webrtc::MetricsObserverInterface* metrics_observer_ = nullptr;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000445};
446
447} // namespace cricket
448
449#endif // WEBRTC_P2P_BASE_PORTALLOCATOR_H_