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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef P2P_BASE_PORTALLOCATOR_H_ |
| 12 | #define P2P_BASE_PORTALLOCATOR_H_ |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "p2p/base/port.h" |
| 20 | #include "p2p/base/portinterface.h" |
| 21 | #include "rtc_base/helpers.h" |
| 22 | #include "rtc_base/proxyinfo.h" |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 23 | #include "rtc_base/sslcertificate.h" |
Artem Titov | e41c433 | 2018-07-25 15:04:28 +0200 | [diff] [blame] | 24 | #include "rtc_base/third_party/sigslot/sigslot.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 25 | #include "rtc_base/thread.h" |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 26 | #include "rtc_base/thread_checker.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 27 | |
Honghai Zhang | d93f50c | 2016-10-05 11:47:22 -0700 | [diff] [blame] | 28 | namespace webrtc { |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 29 | class TurnCustomizer; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 30 | } // namespace webrtc |
Honghai Zhang | d93f50c | 2016-10-05 11:47:22 -0700 | [diff] [blame] | 31 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 32 | namespace cricket { |
| 33 | |
| 34 | // PortAllocator is responsible for allocating Port types for a given |
| 35 | // P2PSocket. It also handles port freeing. |
| 36 | // |
| 37 | // Clients can override this class to control port allocation, including |
| 38 | // what kinds of ports are allocated. |
| 39 | |
| 40 | enum { |
Guo-wei Shieh | 13d35f6 | 2015-08-26 15:32:56 -0700 | [diff] [blame] | 41 | // Disable local UDP ports. This doesn't impact how we connect to relay |
| 42 | // servers. |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 43 | PORTALLOCATOR_DISABLE_UDP = 0x01, |
| 44 | PORTALLOCATOR_DISABLE_STUN = 0x02, |
| 45 | PORTALLOCATOR_DISABLE_RELAY = 0x04, |
Guo-wei Shieh | 13d35f6 | 2015-08-26 15:32:56 -0700 | [diff] [blame] | 46 | // Disable local TCP ports. This doesn't impact how we connect to relay |
| 47 | // servers. |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 48 | PORTALLOCATOR_DISABLE_TCP = 0x08, |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 49 | PORTALLOCATOR_ENABLE_IPV6 = 0x40, |
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, |
zhihuang | b09b3f9 | 2017-03-07 14:40:51 -0800 | [diff] [blame] | 73 | |
| 74 | // When specified, do not collect IPv6 ICE candidates on Wi-Fi. |
| 75 | PORTALLOCATOR_ENABLE_IPV6_ON_WIFI = 0x4000, |
deadbeef | 1ee2125 | 2017-06-13 15:49:45 -0700 | [diff] [blame] | 76 | |
Mirko Bonadei | 5f4d47b | 2018-08-22 17:41:22 +0000 | [diff] [blame] | 77 | // When this flag is set, ports not bound to any specific network interface |
| 78 | // will be used, in addition to normal ports bound to the enumerated |
| 79 | // interfaces. Without this flag, these "any address" ports would only be |
| 80 | // used when network enumeration fails or is disabled. But under certain |
| 81 | // conditions, these ports may succeed where others fail, so they may allow |
| 82 | // the application to work in a wider variety of environments, at the expense |
| 83 | // of having to allocate additional candidates. |
Qingsi Wang | efbcb31 | 2018-08-21 23:23:26 +0000 | [diff] [blame] | 84 | PORTALLOCATOR_ENABLE_ANY_ADDRESS_PORTS = 0x8000, |
| 85 | |
Daniel Lazarenko | 2870b0a | 2018-01-25 10:30:22 +0100 | [diff] [blame] | 86 | // Exclude link-local network interfaces |
| 87 | // from considertaion after adapter enumeration. |
Qingsi Wang | efbcb31 | 2018-08-21 23:23:26 +0000 | [diff] [blame] | 88 | PORTALLOCATOR_DISABLE_LINK_LOCAL_NETWORKS = 0x10000, |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 89 | }; |
| 90 | |
Honghai Zhang | d93f50c | 2016-10-05 11:47:22 -0700 | [diff] [blame] | 91 | // Defines various reasons that have caused ICE regathering. |
Steve Anton | 300bf8e | 2017-07-14 10:13:10 -0700 | [diff] [blame] | 92 | enum class IceRegatheringReason { |
| 93 | NETWORK_CHANGE, // Network interfaces on the device changed |
| 94 | NETWORK_FAILURE, // Regather only on networks that have failed |
| 95 | OCCASIONAL_REFRESH, // Periodic regather on all networks |
| 96 | MAX_VALUE |
| 97 | }; |
Honghai Zhang | d93f50c | 2016-10-05 11:47:22 -0700 | [diff] [blame] | 98 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 99 | const uint32_t kDefaultPortAllocatorFlags = 0; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 100 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 101 | const uint32_t kDefaultStepDelay = 1000; // 1 sec step delay. |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 102 | // As per RFC 5245 Appendix B.1, STUN transactions need to be paced at certain |
| 103 | // 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] | 104 | const uint32_t kMinimumStepDelay = 50; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 105 | |
deadbeef | 3427f53 | 2017-07-26 16:09:33 -0700 | [diff] [blame] | 106 | // Turning on IPv6 could make many IPv6 interfaces available for connectivity |
| 107 | // check and delay the call setup time. kDefaultMaxIPv6Networks is the default |
| 108 | // upper limit of IPv6 networks but could be changed by |
| 109 | // set_max_ipv6_networks(). |
| 110 | constexpr int kDefaultMaxIPv6Networks = 5; |
| 111 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 112 | // CF = CANDIDATE FILTER |
Oleh Prypin | fd7df98 | 2017-12-21 16:25:19 +0100 | [diff] [blame] | 113 | enum : uint32_t { |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 114 | CF_NONE = 0x0, |
| 115 | CF_HOST = 0x1, |
| 116 | CF_REFLEXIVE = 0x2, |
| 117 | CF_RELAY = 0x4, |
| 118 | CF_ALL = 0x7, |
| 119 | }; |
| 120 | |
Sergey Silkin | 9c147dd | 2018-09-12 10:45:38 +0000 | [diff] [blame] | 121 | // TLS certificate policy. |
| 122 | enum class TlsCertPolicy { |
| 123 | // For TLS based protocols, ensure the connection is secure by not |
| 124 | // circumventing certificate validation. |
| 125 | TLS_CERT_POLICY_SECURE, |
| 126 | // For TLS based protocols, disregard security completely by skipping |
| 127 | // certificate validation. This is insecure and should never be used unless |
| 128 | // security is irrelevant in that particular context. |
| 129 | TLS_CERT_POLICY_INSECURE_NO_CHECK, |
| 130 | }; |
| 131 | |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 132 | // TODO(deadbeef): Rename to TurnCredentials (and username to ufrag). |
| 133 | struct RelayCredentials { |
| 134 | RelayCredentials() {} |
| 135 | RelayCredentials(const std::string& username, const std::string& password) |
| 136 | : username(username), password(password) {} |
| 137 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 138 | bool operator==(const RelayCredentials& o) const { |
| 139 | return username == o.username && password == o.password; |
| 140 | } |
| 141 | bool operator!=(const RelayCredentials& o) const { return !(*this == o); } |
| 142 | |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 143 | std::string username; |
| 144 | std::string password; |
| 145 | }; |
| 146 | |
| 147 | typedef std::vector<ProtocolAddress> PortList; |
| 148 | // TODO(deadbeef): Rename to TurnServerConfig. |
| 149 | struct RelayServerConfig { |
Steve Anton | 6c38cc7 | 2017-11-29 10:25:58 -0800 | [diff] [blame] | 150 | explicit RelayServerConfig(RelayType type); |
Emad Omara | dab1d2d | 2017-06-16 15:43:11 -0700 | [diff] [blame] | 151 | RelayServerConfig(const rtc::SocketAddress& address, |
| 152 | const std::string& username, |
| 153 | const std::string& password, |
Steve Anton | 7995d8c | 2017-10-30 16:23:38 -0700 | [diff] [blame] | 154 | ProtocolType proto); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 155 | RelayServerConfig(const std::string& address, |
| 156 | int port, |
| 157 | const std::string& username, |
| 158 | const std::string& password, |
Steve Anton | 7995d8c | 2017-10-30 16:23:38 -0700 | [diff] [blame] | 159 | ProtocolType proto); |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 160 | // Legacy constructor where "secure" and PROTO_TCP implies PROTO_TLS. |
| 161 | RelayServerConfig(const std::string& address, |
| 162 | int port, |
| 163 | const std::string& username, |
| 164 | const std::string& password, |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 165 | ProtocolType proto, |
Steve Anton | 7995d8c | 2017-10-30 16:23:38 -0700 | [diff] [blame] | 166 | bool secure); |
| 167 | RelayServerConfig(const RelayServerConfig&); |
| 168 | ~RelayServerConfig(); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 169 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 170 | bool operator==(const RelayServerConfig& o) const { |
| 171 | return type == o.type && ports == o.ports && credentials == o.credentials && |
| 172 | priority == o.priority; |
| 173 | } |
| 174 | bool operator!=(const RelayServerConfig& o) const { return !(*this == o); } |
| 175 | |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 176 | RelayType type; |
| 177 | PortList ports; |
| 178 | RelayCredentials credentials; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 179 | int priority = 0; |
hnsl | 0483362 | 2017-01-09 08:35:45 -0800 | [diff] [blame] | 180 | TlsCertPolicy tls_cert_policy = TlsCertPolicy::TLS_CERT_POLICY_SECURE; |
Diogo Real | 1dca9d5 | 2017-08-29 12:18:32 -0700 | [diff] [blame] | 181 | std::vector<std::string> tls_alpn_protocols; |
Diogo Real | 7bd1f1b | 2017-09-08 12:50:41 -0700 | [diff] [blame] | 182 | std::vector<std::string> tls_elliptic_curves; |
Benjamin Wright | d6f86e8 | 2018-05-08 13:12:25 -0700 | [diff] [blame] | 183 | rtc::SSLCertificateVerifier* tls_cert_verifier = nullptr; |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 184 | }; |
| 185 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 186 | class PortAllocatorSession : public sigslot::has_slots<> { |
| 187 | public: |
| 188 | // Content name passed in mostly for logging and debugging. |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 189 | PortAllocatorSession(const std::string& content_name, |
| 190 | int component, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 191 | const std::string& ice_ufrag, |
| 192 | const std::string& ice_pwd, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 193 | uint32_t flags); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 194 | |
| 195 | // Subclasses should clean up any ports created. |
Steve Anton | 7995d8c | 2017-10-30 16:23:38 -0700 | [diff] [blame] | 196 | ~PortAllocatorSession() override; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 197 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 198 | uint32_t flags() const { return flags_; } |
| 199 | void set_flags(uint32_t flags) { flags_ = flags; } |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 200 | std::string content_name() const { return content_name_; } |
| 201 | int component() const { return component_; } |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 202 | const std::string& ice_ufrag() const { return ice_ufrag_; } |
| 203 | const std::string& ice_pwd() const { return ice_pwd_; } |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 204 | bool pooled() const { return pooled_; } |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 205 | |
Taylor Brandstetter | 417eebe | 2016-05-23 16:02:19 -0700 | [diff] [blame] | 206 | // Setting this filter should affect not only candidates gathered in the |
| 207 | // future, but candidates already gathered and ports already "ready", |
| 208 | // which would be returned by ReadyCandidates() and ReadyPorts(). |
| 209 | // |
| 210 | // Default filter should be CF_ALL. |
| 211 | virtual void SetCandidateFilter(uint32_t filter) = 0; |
| 212 | |
deadbeef | b60a819 | 2016-08-24 15:15:00 -0700 | [diff] [blame] | 213 | // Starts gathering ports and ICE candidates. |
Honghai Zhang | d8f6fc4 | 2016-07-01 17:31:12 -0700 | [diff] [blame] | 214 | virtual void StartGettingPorts() = 0; |
deadbeef | b60a819 | 2016-08-24 15:15:00 -0700 | [diff] [blame] | 215 | // Completely stops gathering. Will not gather again unless StartGettingPorts |
| 216 | // is called again. |
Honghai Zhang | d8f6fc4 | 2016-07-01 17:31:12 -0700 | [diff] [blame] | 217 | virtual void StopGettingPorts() = 0; |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 218 | // Whether the session is actively getting ports. |
Honghai Zhang | d8f6fc4 | 2016-07-01 17:31:12 -0700 | [diff] [blame] | 219 | virtual bool IsGettingPorts() = 0; |
deadbeef | b60a819 | 2016-08-24 15:15:00 -0700 | [diff] [blame] | 220 | |
| 221 | // |
| 222 | // NOTE: The group of methods below is only used for continual gathering. |
| 223 | // |
| 224 | |
| 225 | // ClearGettingPorts should have the same immediate effect as |
| 226 | // StopGettingPorts, but if the implementation supports continual gathering, |
| 227 | // ClearGettingPorts allows additional ports/candidates to be gathered if the |
| 228 | // network conditions change. |
Honghai Zhang | d8f6fc4 | 2016-07-01 17:31:12 -0700 | [diff] [blame] | 229 | virtual void ClearGettingPorts() = 0; |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 230 | // Whether it is in the state where the existing gathering process is stopped, |
| 231 | // but new ones may be started (basically after calling ClearGettingPorts). |
Steve Anton | 7995d8c | 2017-10-30 16:23:38 -0700 | [diff] [blame] | 232 | virtual bool IsCleared() const; |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 233 | // Whether the session has completely stopped. |
Steve Anton | 7995d8c | 2017-10-30 16:23:38 -0700 | [diff] [blame] | 234 | virtual bool IsStopped() const; |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 235 | // Re-gathers candidates on networks that do not have any connections. More |
| 236 | // precisely, a network interface may have more than one IP addresses (e.g., |
| 237 | // IPv4 and IPv6 addresses). Each address subnet will be used to create a |
| 238 | // network. Only if all networks of an interface have no connection, the |
| 239 | // implementation should start re-gathering on all networks of that interface. |
| 240 | virtual void RegatherOnFailedNetworks() {} |
| 241 | // Re-gathers candidates on all networks. |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 242 | virtual void RegatherOnAllNetworks() {} |
Qingsi Wang | 72a43a1 | 2018-02-20 16:03:18 -0800 | [diff] [blame] | 243 | // Get candidate-level stats from all candidates on the ready ports and return |
| 244 | // the stats to the given list. |
| 245 | virtual void GetCandidateStatsFromReadyPorts( |
| 246 | CandidateStatsList* candidate_stats_list) const; |
Qingsi Wang | db53f8e | 2018-02-20 14:45:49 -0800 | [diff] [blame] | 247 | // Set the interval at which STUN candidates will resend STUN binding requests |
| 248 | // on the underlying ports to keep NAT bindings open. |
| 249 | // The default value of the interval in implementation is restored if a null |
| 250 | // optional value is passed. |
| 251 | virtual void SetStunKeepaliveIntervalForReadyPorts( |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 252 | const absl::optional<int>& stun_keepalive_interval) {} |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 253 | // Another way of getting the information provided by the signals below. |
| 254 | // |
| 255 | // Ports and candidates are not guaranteed to be in the same order as the |
| 256 | // signals were emitted in. |
| 257 | virtual std::vector<PortInterface*> ReadyPorts() const = 0; |
| 258 | virtual std::vector<Candidate> ReadyCandidates() const = 0; |
| 259 | virtual bool CandidatesAllocationDone() const = 0; |
Honghai Zhang | a74363c | 2016-07-28 18:06:15 -0700 | [diff] [blame] | 260 | // Marks all ports in the current session as "pruned" so that they may be |
| 261 | // destroyed if no connection is using them. |
| 262 | virtual void PruneAllPorts() {} |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 263 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 264 | sigslot::signal2<PortAllocatorSession*, PortInterface*> SignalPortReady; |
Honghai Zhang | 8eeecab | 2016-07-28 13:20:15 -0700 | [diff] [blame] | 265 | // Fires this signal when the network of the ports failed (either because the |
| 266 | // interface is down, or because there is no connection on the interface), |
| 267 | // or when TURN ports are pruned because a higher-priority TURN port becomes |
| 268 | // ready(pairable). |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 269 | sigslot::signal2<PortAllocatorSession*, const std::vector<PortInterface*>&> |
Honghai Zhang | 8eeecab | 2016-07-28 13:20:15 -0700 | [diff] [blame] | 270 | SignalPortsPruned; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 271 | sigslot::signal2<PortAllocatorSession*, const std::vector<Candidate>&> |
| 272 | SignalCandidatesReady; |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 273 | // Candidates should be signaled to be removed when the port that generated |
| 274 | // the candidates is removed. |
| 275 | sigslot::signal2<PortAllocatorSession*, const std::vector<Candidate>&> |
| 276 | SignalCandidatesRemoved; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 277 | sigslot::signal1<PortAllocatorSession*> SignalCandidatesAllocationDone; |
| 278 | |
Honghai Zhang | d93f50c | 2016-10-05 11:47:22 -0700 | [diff] [blame] | 279 | sigslot::signal2<PortAllocatorSession*, IceRegatheringReason> |
| 280 | SignalIceRegathering; |
| 281 | |
Steve Anton | 7995d8c | 2017-10-30 16:23:38 -0700 | [diff] [blame] | 282 | virtual uint32_t generation(); |
| 283 | virtual void set_generation(uint32_t generation); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 284 | sigslot::signal1<PortAllocatorSession*> SignalDestroyed; |
| 285 | |
deadbeef | c55fb30 | 2016-05-12 12:51:38 -0700 | [diff] [blame] | 286 | protected: |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 287 | // This method is called when a pooled session (which doesn't have these |
| 288 | // properties initially) is returned by PortAllocator::TakePooledSession, |
| 289 | // and the content name, component, and ICE ufrag/pwd are updated. |
| 290 | // |
| 291 | // A subclass may need to override this method to perform additional actions, |
| 292 | // such as applying the updated information to ports and candidates. |
| 293 | virtual void UpdateIceParametersInternal() {} |
| 294 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 295 | // TODO(deadbeef): Get rid of these when everyone switches to ice_ufrag and |
| 296 | // ice_pwd. |
| 297 | const std::string& username() const { return ice_ufrag_; } |
| 298 | const std::string& password() const { return ice_pwd_; } |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 299 | |
deadbeef | c55fb30 | 2016-05-12 12:51:38 -0700 | [diff] [blame] | 300 | private: |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 301 | void SetIceParameters(const std::string& content_name, |
| 302 | int component, |
| 303 | const std::string& ice_ufrag, |
| 304 | const std::string& ice_pwd) { |
| 305 | content_name_ = content_name; |
| 306 | component_ = component; |
| 307 | ice_ufrag_ = ice_ufrag; |
| 308 | ice_pwd_ = ice_pwd; |
| 309 | UpdateIceParametersInternal(); |
| 310 | } |
| 311 | |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 312 | void set_pooled(bool value) { pooled_ = value; } |
| 313 | |
deadbeef | c55fb30 | 2016-05-12 12:51:38 -0700 | [diff] [blame] | 314 | uint32_t flags_; |
| 315 | uint32_t generation_; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 316 | std::string content_name_; |
| 317 | int component_; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 318 | std::string ice_ufrag_; |
| 319 | std::string ice_pwd_; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 320 | |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 321 | bool pooled_ = false; |
| 322 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 323 | // SetIceParameters is an implementation detail which only PortAllocator |
| 324 | // should be able to call. |
| 325 | friend class PortAllocator; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 326 | }; |
| 327 | |
Taylor Brandstetter | f8e6577 | 2016-06-27 17:20:15 -0700 | [diff] [blame] | 328 | // Every method of PortAllocator (including the destructor) must be called on |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 329 | // the same thread after Initialize is called. |
Taylor Brandstetter | f8e6577 | 2016-06-27 17:20:15 -0700 | [diff] [blame] | 330 | // |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 331 | // This allows a PortAllocator subclass to be constructed and configured on one |
| 332 | // thread, and passed into an object that uses it on a different thread. |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 333 | class PortAllocator : public sigslot::has_slots<> { |
| 334 | public: |
Steve Anton | 7995d8c | 2017-10-30 16:23:38 -0700 | [diff] [blame] | 335 | PortAllocator(); |
| 336 | ~PortAllocator() override; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 337 | |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 338 | // This MUST be called on the PortAllocator's thread after finishing |
| 339 | // constructing and configuring the PortAllocator subclasses. |
| 340 | virtual void Initialize(); |
Taylor Brandstetter | f8e6577 | 2016-06-27 17:20:15 -0700 | [diff] [blame] | 341 | |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 342 | // Set to true if some Ports need to know the ICE credentials when they are |
| 343 | // created. This will ensure that the PortAllocator will only match pooled |
| 344 | // allocator sessions to the ICE transport with the same credentials. |
| 345 | virtual void set_restrict_ice_credentials_change(bool value); |
| 346 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 347 | // Set STUN and TURN servers to be used in future sessions, and set |
| 348 | // candidate pool size, as described in JSEP. |
| 349 | // |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 350 | // If the servers are changing, and the candidate pool size is nonzero, and |
| 351 | // FreezeCandidatePool hasn't been called, existing pooled sessions will be |
| 352 | // destroyed and new ones created. |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 353 | // |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 354 | // If the servers are not changing but the candidate pool size is, and |
| 355 | // FreezeCandidatePool hasn't been called, pooled sessions will be either |
| 356 | // created or destroyed as necessary. |
deadbeef | 6de92f9 | 2016-12-12 18:49:32 -0800 | [diff] [blame] | 357 | // |
| 358 | // Returns true if the configuration could successfully be changed. |
| 359 | bool SetConfiguration(const ServerAddresses& stun_servers, |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 360 | const std::vector<RelayServerConfig>& turn_servers, |
Honghai Zhang | b9e7b4a | 2016-06-30 20:52:02 -0700 | [diff] [blame] | 361 | int candidate_pool_size, |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 362 | bool prune_turn_ports, |
Qingsi Wang | db53f8e | 2018-02-20 14:45:49 -0800 | [diff] [blame] | 363 | webrtc::TurnCustomizer* turn_customizer = nullptr, |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 364 | const absl::optional<int>& |
| 365 | stun_candidate_keepalive_interval = absl::nullopt); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 366 | |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 367 | const ServerAddresses& stun_servers() const { |
| 368 | CheckRunOnValidThreadIfInitialized(); |
| 369 | return stun_servers_; |
| 370 | } |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 371 | |
| 372 | const std::vector<RelayServerConfig>& turn_servers() const { |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 373 | CheckRunOnValidThreadIfInitialized(); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 374 | return turn_servers_; |
| 375 | } |
| 376 | |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 377 | int candidate_pool_size() const { |
| 378 | CheckRunOnValidThreadIfInitialized(); |
| 379 | return candidate_pool_size_; |
| 380 | } |
| 381 | |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 382 | const absl::optional<int>& stun_candidate_keepalive_interval() const { |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 383 | CheckRunOnValidThreadIfInitialized(); |
Qingsi Wang | db53f8e | 2018-02-20 14:45:49 -0800 | [diff] [blame] | 384 | return stun_candidate_keepalive_interval_; |
| 385 | } |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 386 | |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 387 | // Sets the network types to ignore. |
| 388 | // Values are defined by the AdapterType enum. |
| 389 | // For instance, calling this with |
| 390 | // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and |
| 391 | // loopback interfaces. |
| 392 | virtual void SetNetworkIgnoreMask(int network_ignore_mask) = 0; |
| 393 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 394 | std::unique_ptr<PortAllocatorSession> CreateSession( |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 395 | const std::string& content_name, |
| 396 | int component, |
| 397 | const std::string& ice_ufrag, |
| 398 | const std::string& ice_pwd); |
| 399 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 400 | // Get an available pooled session and set the transport information on it. |
| 401 | // |
| 402 | // Caller takes ownership of the returned session. |
| 403 | // |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 404 | // If restrict_ice_credentials_change is TRUE, then it will only |
| 405 | // return a pooled session with matching ice credentials. |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 406 | // If no pooled sessions are available, returns null. |
| 407 | std::unique_ptr<PortAllocatorSession> TakePooledSession( |
| 408 | const std::string& content_name, |
| 409 | int component, |
| 410 | const std::string& ice_ufrag, |
| 411 | const std::string& ice_pwd); |
| 412 | |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 413 | // Returns the next session that would be returned by TakePooledSession |
| 414 | // optionally restricting it to sessions with specified ice credentials. |
| 415 | const PortAllocatorSession* GetPooledSession( |
| 416 | const IceParameters* ice_credentials = nullptr) const; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 417 | |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 418 | // After FreezeCandidatePool is called, changing the candidate pool size will |
| 419 | // no longer be allowed, and changing ICE servers will not cause pooled |
| 420 | // sessions to be recreated. |
| 421 | // |
| 422 | // Expected to be called when SetLocalDescription is called on a |
| 423 | // PeerConnection. Can be called safely on any thread as long as not |
| 424 | // simultaneously with SetConfiguration. |
| 425 | void FreezeCandidatePool(); |
| 426 | |
| 427 | // Discard any remaining pooled sessions. |
| 428 | void DiscardCandidatePool(); |
| 429 | |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 430 | uint32_t flags() const { |
| 431 | CheckRunOnValidThreadIfInitialized(); |
| 432 | return flags_; |
| 433 | } |
| 434 | |
| 435 | void set_flags(uint32_t flags) { |
| 436 | CheckRunOnValidThreadIfInitialized(); |
| 437 | flags_ = flags; |
| 438 | } |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 439 | |
deadbeef | f137e97 | 2017-03-23 15:45:49 -0700 | [diff] [blame] | 440 | // These three methods are deprecated. If connections need to go through a |
| 441 | // proxy, the application should create a BasicPortAllocator given a custom |
| 442 | // PacketSocketFactory that creates proxy sockets. |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 443 | const std::string& user_agent() const { |
| 444 | CheckRunOnValidThreadIfInitialized(); |
| 445 | return agent_; |
| 446 | } |
| 447 | |
| 448 | const rtc::ProxyInfo& proxy() const { |
| 449 | CheckRunOnValidThreadIfInitialized(); |
| 450 | return proxy_; |
| 451 | } |
| 452 | |
deadbeef | f137e97 | 2017-03-23 15:45:49 -0700 | [diff] [blame] | 453 | void set_proxy(const std::string& agent, const rtc::ProxyInfo& proxy) { |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 454 | CheckRunOnValidThreadIfInitialized(); |
deadbeef | f137e97 | 2017-03-23 15:45:49 -0700 | [diff] [blame] | 455 | agent_ = agent; |
| 456 | proxy_ = proxy; |
| 457 | } |
| 458 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 459 | // Gets/Sets the port range to use when choosing client ports. |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 460 | int min_port() const { |
| 461 | CheckRunOnValidThreadIfInitialized(); |
| 462 | return min_port_; |
| 463 | } |
| 464 | |
| 465 | int max_port() const { |
| 466 | CheckRunOnValidThreadIfInitialized(); |
| 467 | return max_port_; |
| 468 | } |
| 469 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 470 | bool SetPortRange(int min_port, int max_port) { |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 471 | CheckRunOnValidThreadIfInitialized(); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 472 | if (min_port > max_port) { |
| 473 | return false; |
| 474 | } |
| 475 | |
| 476 | min_port_ = min_port; |
| 477 | max_port_ = max_port; |
| 478 | return true; |
| 479 | } |
| 480 | |
deadbeef | 3427f53 | 2017-07-26 16:09:33 -0700 | [diff] [blame] | 481 | // Can be used to change the default numer of IPv6 network interfaces used |
| 482 | // (5). Can set to INT_MAX to effectively disable the limit. |
| 483 | // |
| 484 | // TODO(deadbeef): Applications shouldn't have to arbitrarily limit the |
| 485 | // number of available IPv6 network interfaces just because they could slow |
| 486 | // ICE down. We should work on making our ICE logic smarter (for example, |
| 487 | // prioritizing pinging connections that are most likely to work) so that |
| 488 | // every network interface can be used without impacting ICE's speed. |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 489 | void set_max_ipv6_networks(int networks) { |
| 490 | CheckRunOnValidThreadIfInitialized(); |
| 491 | max_ipv6_networks_ = networks; |
| 492 | } |
| 493 | |
| 494 | int max_ipv6_networks() { |
| 495 | CheckRunOnValidThreadIfInitialized(); |
| 496 | return max_ipv6_networks_; |
| 497 | } |
deadbeef | 3427f53 | 2017-07-26 16:09:33 -0700 | [diff] [blame] | 498 | |
deadbeef | 1c5e6d0 | 2017-09-15 17:46:56 -0700 | [diff] [blame] | 499 | // Delay between different candidate gathering phases (UDP, TURN, TCP). |
| 500 | // Defaults to 1 second, but PeerConnection sets it to 50ms. |
| 501 | // TODO(deadbeef): Get rid of this. Its purpose is to avoid sending too many |
| 502 | // STUN transactions at once, but that's already happening if you configure |
| 503 | // multiple STUN servers or have multiple network interfaces. We should |
| 504 | // implement some global pacing logic instead if that's our goal. |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 505 | uint32_t step_delay() const { |
| 506 | CheckRunOnValidThreadIfInitialized(); |
| 507 | return step_delay_; |
| 508 | } |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 509 | |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 510 | void set_step_delay(uint32_t delay) { |
| 511 | CheckRunOnValidThreadIfInitialized(); |
| 512 | step_delay_ = delay; |
| 513 | } |
| 514 | |
| 515 | bool allow_tcp_listen() const { |
| 516 | CheckRunOnValidThreadIfInitialized(); |
| 517 | return allow_tcp_listen_; |
| 518 | } |
| 519 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 520 | void set_allow_tcp_listen(bool allow_tcp_listen) { |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 521 | CheckRunOnValidThreadIfInitialized(); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 522 | allow_tcp_listen_ = allow_tcp_listen; |
| 523 | } |
| 524 | |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 525 | uint32_t candidate_filter() { |
| 526 | CheckRunOnValidThreadIfInitialized(); |
| 527 | return candidate_filter_; |
| 528 | } |
| 529 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 530 | void set_candidate_filter(uint32_t filter) { |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 531 | CheckRunOnValidThreadIfInitialized(); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 532 | candidate_filter_ = filter; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 533 | } |
| 534 | |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 535 | bool prune_turn_ports() const { |
| 536 | CheckRunOnValidThreadIfInitialized(); |
| 537 | return prune_turn_ports_; |
| 538 | } |
Honghai Zhang | b9e7b4a | 2016-06-30 20:52:02 -0700 | [diff] [blame] | 539 | |
pthatcher@webrtc.org | 0ba1533 | 2015-01-10 00:47:02 +0000 | [diff] [blame] | 540 | // Gets/Sets the Origin value used for WebRTC STUN requests. |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 541 | const std::string& origin() const { |
| 542 | CheckRunOnValidThreadIfInitialized(); |
| 543 | return origin_; |
| 544 | } |
| 545 | |
| 546 | void set_origin(const std::string& origin) { |
| 547 | CheckRunOnValidThreadIfInitialized(); |
| 548 | origin_ = origin; |
| 549 | } |
pthatcher@webrtc.org | 0ba1533 | 2015-01-10 00:47:02 +0000 | [diff] [blame] | 550 | |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 551 | webrtc::TurnCustomizer* turn_customizer() { |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 552 | CheckRunOnValidThreadIfInitialized(); |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 553 | return turn_customizer_; |
| 554 | } |
| 555 | |
Qingsi Wang | 72a43a1 | 2018-02-20 16:03:18 -0800 | [diff] [blame] | 556 | // Collect candidate stats from pooled allocator sessions. This can be used to |
| 557 | // collect candidate stats without creating an offer/answer or setting local |
| 558 | // description. After the local description is set, the ownership of the |
| 559 | // pooled session is taken by P2PTransportChannel, and the |
| 560 | // candidate stats can be collected from P2PTransportChannel::GetStats. |
| 561 | virtual void GetCandidateStatsFromPooledSessions( |
| 562 | CandidateStatsList* candidate_stats_list); |
| 563 | |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 564 | // Return IceParameters of the pooled sessions. |
| 565 | std::vector<IceParameters> GetPooledIceCredentials(); |
| 566 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 567 | protected: |
| 568 | virtual PortAllocatorSession* CreateSessionInternal( |
| 569 | const std::string& content_name, |
| 570 | int component, |
| 571 | const std::string& ice_ufrag, |
| 572 | const std::string& ice_pwd) = 0; |
| 573 | |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 574 | const std::vector<std::unique_ptr<PortAllocatorSession>>& pooled_sessions() { |
Honghai Zhang | d93f50c | 2016-10-05 11:47:22 -0700 | [diff] [blame] | 575 | return pooled_sessions_; |
| 576 | } |
| 577 | |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 578 | // The following thread checks are only done in DCHECK for the consistency |
| 579 | // with the exsiting thread checks. |
| 580 | void CheckRunOnValidThreadIfInitialized() const { |
| 581 | RTC_DCHECK(!initialized_ || thread_checker_.CalledOnValidThread()); |
| 582 | } |
| 583 | |
| 584 | void CheckRunOnValidThreadAndInitialized() const { |
| 585 | RTC_DCHECK(initialized_ && thread_checker_.CalledOnValidThread()); |
| 586 | } |
| 587 | |
| 588 | bool initialized_ = false; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 589 | uint32_t flags_; |
deadbeef | f137e97 | 2017-03-23 15:45:49 -0700 | [diff] [blame] | 590 | std::string agent_; |
| 591 | rtc::ProxyInfo proxy_; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 592 | int min_port_; |
| 593 | int max_port_; |
deadbeef | 3427f53 | 2017-07-26 16:09:33 -0700 | [diff] [blame] | 594 | int max_ipv6_networks_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 595 | uint32_t step_delay_; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 596 | bool allow_tcp_listen_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 597 | uint32_t candidate_filter_; |
pthatcher@webrtc.org | 0ba1533 | 2015-01-10 00:47:02 +0000 | [diff] [blame] | 598 | std::string origin_; |
Qingsi Wang | a2d6067 | 2018-04-11 16:57:45 -0700 | [diff] [blame] | 599 | rtc::ThreadChecker thread_checker_; |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 600 | |
| 601 | private: |
| 602 | ServerAddresses stun_servers_; |
| 603 | std::vector<RelayServerConfig> turn_servers_; |
deadbeef | 6de92f9 | 2016-12-12 18:49:32 -0800 | [diff] [blame] | 604 | int candidate_pool_size_ = 0; // Last value passed into SetConfiguration. |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 605 | std::vector<std::unique_ptr<PortAllocatorSession>> pooled_sessions_; |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 606 | bool candidate_pool_frozen_ = false; |
Honghai Zhang | b9e7b4a | 2016-06-30 20:52:02 -0700 | [diff] [blame] | 607 | bool prune_turn_ports_ = false; |
Honghai Zhang | d93f50c | 2016-10-05 11:47:22 -0700 | [diff] [blame] | 608 | |
Jonas Oreland | bdcee28 | 2017-10-10 14:01:40 +0200 | [diff] [blame] | 609 | // Customizer for TURN messages. |
| 610 | // The instance is owned by application and will be shared among |
| 611 | // all TurnPort(s) created. |
| 612 | webrtc::TurnCustomizer* turn_customizer_ = nullptr; |
Qingsi Wang | db53f8e | 2018-02-20 14:45:49 -0800 | [diff] [blame] | 613 | |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 614 | absl::optional<int> stun_candidate_keepalive_interval_; |
Jonas Oreland | 1cd39fa | 2018-10-11 07:47:12 +0200 | [diff] [blame] | 615 | |
| 616 | // If true, TakePooledSession() will only return sessions that has same ice |
| 617 | // credentials as requested. |
| 618 | bool restrict_ice_credentials_change_ = false; |
| 619 | |
| 620 | // Returns iterator to pooled session with specified ice_credentials or first |
| 621 | // if ice_credentials is nullptr. |
| 622 | std::vector<std::unique_ptr<PortAllocatorSession>>::const_iterator |
| 623 | FindPooledSession(const IceParameters* ice_credentials = nullptr) const; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 624 | }; |
| 625 | |
| 626 | } // namespace cricket |
| 627 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 628 | #endif // P2P_BASE_PORTALLOCATOR_H_ |