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