henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 | [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 17:11:00 | [diff] [blame] | 11 | #include "p2p/base/port_allocator.h" |
Steve Anton | 6c38cc7 | 2017-11-29 18:25:58 | [diff] [blame] | 12 | |
Jonas Oreland | 1cd39fa | 2018-10-11 05:47:12 | [diff] [blame] | 13 | #include <iterator> |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 14 | #include <set> |
Steve Anton | 6c38cc7 | 2017-11-29 18:25:58 | [diff] [blame] | 15 | #include <utility> |
| 16 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 17 | #include "p2p/base/ice_credentials_iterator.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 18 | #include "rtc_base/checks.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 19 | #include "rtc_base/logging.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 | [diff] [blame] | 20 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 | [diff] [blame] | 21 | namespace cricket { |
| 22 | |
Niels Möller | 191e38f | 2019-11-04 07:49:12 | [diff] [blame] | 23 | RelayServerConfig::RelayServerConfig() {} |
Steve Anton | 7995d8c | 2017-10-30 23:23:38 | [diff] [blame] | 24 | |
| 25 | RelayServerConfig::RelayServerConfig(const rtc::SocketAddress& address, |
| 26 | const std::string& username, |
| 27 | const std::string& password, |
| 28 | ProtocolType proto) |
Niels Möller | 191e38f | 2019-11-04 07:49:12 | [diff] [blame] | 29 | : credentials(username, password) { |
Steve Anton | 7995d8c | 2017-10-30 23:23:38 | [diff] [blame] | 30 | ports.push_back(ProtocolAddress(address, proto)); |
| 31 | } |
| 32 | |
| 33 | RelayServerConfig::RelayServerConfig(const std::string& address, |
| 34 | int port, |
| 35 | const std::string& username, |
| 36 | const std::string& password, |
| 37 | ProtocolType proto) |
| 38 | : RelayServerConfig(rtc::SocketAddress(address, port), |
| 39 | username, |
| 40 | password, |
| 41 | proto) {} |
| 42 | |
| 43 | // Legacy constructor where "secure" and PROTO_TCP implies PROTO_TLS. |
| 44 | RelayServerConfig::RelayServerConfig(const std::string& address, |
| 45 | int port, |
| 46 | const std::string& username, |
| 47 | const std::string& password, |
| 48 | ProtocolType proto, |
| 49 | bool secure) |
| 50 | : RelayServerConfig(address, |
| 51 | port, |
| 52 | username, |
| 53 | password, |
| 54 | (proto == PROTO_TCP && secure ? PROTO_TLS : proto)) {} |
| 55 | |
| 56 | RelayServerConfig::RelayServerConfig(const RelayServerConfig&) = default; |
| 57 | |
| 58 | RelayServerConfig::~RelayServerConfig() = default; |
| 59 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 | [diff] [blame] | 60 | PortAllocatorSession::PortAllocatorSession(const std::string& content_name, |
| 61 | int component, |
| 62 | const std::string& ice_ufrag, |
| 63 | const std::string& ice_pwd, |
Peter Boström | 0c4e06b | 2015-10-07 10:23:21 | [diff] [blame] | 64 | uint32_t flags) |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 65 | : flags_(flags), |
deadbeef | c55fb30 | 2016-05-12 19:51:38 | [diff] [blame] | 66 | generation_(0), |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 67 | content_name_(content_name), |
| 68 | component_(component), |
deadbeef | cbecd35 | 2015-09-23 18:50:27 | [diff] [blame] | 69 | ice_ufrag_(ice_ufrag), |
| 70 | ice_pwd_(ice_pwd) { |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 71 | // Pooled sessions are allowed to be created with empty content name, |
| 72 | // component, ufrag and password. |
| 73 | RTC_DCHECK(ice_ufrag.empty() == ice_pwd.empty()); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 | [diff] [blame] | 74 | } |
| 75 | |
Steve Anton | 7995d8c | 2017-10-30 23:23:38 | [diff] [blame] | 76 | PortAllocatorSession::~PortAllocatorSession() = default; |
| 77 | |
| 78 | bool PortAllocatorSession::IsCleared() const { |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | bool PortAllocatorSession::IsStopped() const { |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | uint32_t PortAllocatorSession::generation() { |
| 87 | return generation_; |
| 88 | } |
| 89 | |
| 90 | void PortAllocatorSession::set_generation(uint32_t generation) { |
| 91 | generation_ = generation; |
| 92 | } |
| 93 | |
| 94 | PortAllocator::PortAllocator() |
| 95 | : flags_(kDefaultPortAllocatorFlags), |
| 96 | min_port_(0), |
| 97 | max_port_(0), |
| 98 | max_ipv6_networks_(kDefaultMaxIPv6Networks), |
| 99 | step_delay_(kDefaultStepDelay), |
| 100 | allow_tcp_listen_(true), |
Qingsi Wang | a2d6067 | 2018-04-11 23:57:45 | [diff] [blame] | 101 | candidate_filter_(CF_ALL) { |
| 102 | // The allocator will be attached to a thread in Initialize. |
Sebastian Jansson | c01367d | 2019-04-08 13:20:44 | [diff] [blame] | 103 | thread_checker_.Detach(); |
Qingsi Wang | a2d6067 | 2018-04-11 23:57:45 | [diff] [blame] | 104 | } |
Steve Anton | 7995d8c | 2017-10-30 23:23:38 | [diff] [blame] | 105 | |
Qingsi Wang | a2d6067 | 2018-04-11 23:57:45 | [diff] [blame] | 106 | void PortAllocator::Initialize() { |
Sebastian Jansson | c01367d | 2019-04-08 13:20:44 | [diff] [blame] | 107 | RTC_DCHECK(thread_checker_.IsCurrent()); |
Qingsi Wang | a2d6067 | 2018-04-11 23:57:45 | [diff] [blame] | 108 | initialized_ = true; |
| 109 | } |
| 110 | |
| 111 | PortAllocator::~PortAllocator() { |
| 112 | CheckRunOnValidThreadIfInitialized(); |
| 113 | } |
Steve Anton | 7995d8c | 2017-10-30 23:23:38 | [diff] [blame] | 114 | |
Jonas Oreland | 1cd39fa | 2018-10-11 05:47:12 | [diff] [blame] | 115 | void PortAllocator::set_restrict_ice_credentials_change(bool value) { |
| 116 | restrict_ice_credentials_change_ = value; |
| 117 | } |
| 118 | |
Honghai Zhang | f8998cf | 2019-10-14 18:27:50 | [diff] [blame] | 119 | // Deprecated |
deadbeef | 6de92f9 | 2016-12-13 02:49:32 | [diff] [blame] | 120 | bool PortAllocator::SetConfiguration( |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 121 | const ServerAddresses& stun_servers, |
| 122 | const std::vector<RelayServerConfig>& turn_servers, |
Honghai Zhang | b9e7b4a | 2016-07-01 03:52:02 | [diff] [blame] | 123 | int candidate_pool_size, |
Jonas Oreland | bdcee28 | 2017-10-10 12:01:40 | [diff] [blame] | 124 | bool prune_turn_ports, |
Qingsi Wang | db53f8e | 2018-02-20 22:45:49 | [diff] [blame] | 125 | webrtc::TurnCustomizer* turn_customizer, |
Danil Chapovalov | 00c71836 | 2018-06-15 13:58:38 | [diff] [blame] | 126 | const absl::optional<int>& stun_candidate_keepalive_interval) { |
Honghai Zhang | f8998cf | 2019-10-14 18:27:50 | [diff] [blame] | 127 | webrtc::PortPrunePolicy turn_port_prune_policy = |
| 128 | prune_turn_ports ? webrtc::PRUNE_BASED_ON_PRIORITY : webrtc::NO_PRUNE; |
| 129 | return SetConfiguration(stun_servers, turn_servers, candidate_pool_size, |
| 130 | turn_port_prune_policy, turn_customizer, |
| 131 | stun_candidate_keepalive_interval); |
| 132 | } |
| 133 | |
| 134 | bool PortAllocator::SetConfiguration( |
| 135 | const ServerAddresses& stun_servers, |
| 136 | const std::vector<RelayServerConfig>& turn_servers, |
| 137 | int candidate_pool_size, |
| 138 | webrtc::PortPrunePolicy turn_port_prune_policy, |
| 139 | webrtc::TurnCustomizer* turn_customizer, |
| 140 | const absl::optional<int>& stun_candidate_keepalive_interval) { |
Qingsi Wang | a2d6067 | 2018-04-11 23:57:45 | [diff] [blame] | 141 | CheckRunOnValidThreadIfInitialized(); |
Qingsi Wang | e6ded16 | 2018-10-02 23:00:41 | [diff] [blame] | 142 | // A positive candidate pool size would lead to the creation of a pooled |
| 143 | // allocator session and starting getting ports, which we should only do on |
| 144 | // the network thread. |
Sebastian Jansson | c01367d | 2019-04-08 13:20:44 | [diff] [blame] | 145 | RTC_DCHECK(candidate_pool_size == 0 || thread_checker_.IsCurrent()); |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 146 | bool ice_servers_changed = |
| 147 | (stun_servers != stun_servers_ || turn_servers != turn_servers_); |
| 148 | stun_servers_ = stun_servers; |
| 149 | turn_servers_ = turn_servers; |
Honghai Zhang | f8998cf | 2019-10-14 18:27:50 | [diff] [blame] | 150 | turn_port_prune_policy_ = turn_port_prune_policy; |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 151 | |
deadbeef | 42a4263 | 2017-03-10 23:18:00 | [diff] [blame] | 152 | if (candidate_pool_frozen_) { |
| 153 | if (candidate_pool_size != candidate_pool_size_) { |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 154 | RTC_LOG(LS_ERROR) |
Jonas Olsson | d7d762d | 2018-03-28 07:47:51 | [diff] [blame] | 155 | << "Trying to change candidate pool size after pool was frozen."; |
deadbeef | 42a4263 | 2017-03-10 23:18:00 | [diff] [blame] | 156 | return false; |
| 157 | } |
| 158 | return true; |
deadbeef | 6de92f9 | 2016-12-13 02:49:32 | [diff] [blame] | 159 | } |
deadbeef | 42a4263 | 2017-03-10 23:18:00 | [diff] [blame] | 160 | |
deadbeef | 6de92f9 | 2016-12-13 02:49:32 | [diff] [blame] | 161 | if (candidate_pool_size < 0) { |
Mirko Bonadei | 675513b | 2017-11-09 10:09:25 | [diff] [blame] | 162 | RTC_LOG(LS_ERROR) << "Can't set negative pool size."; |
deadbeef | 6de92f9 | 2016-12-13 02:49:32 | [diff] [blame] | 163 | return false; |
| 164 | } |
deadbeef | 6de92f9 | 2016-12-13 02:49:32 | [diff] [blame] | 165 | |
deadbeef | 42a4263 | 2017-03-10 23:18:00 | [diff] [blame] | 166 | candidate_pool_size_ = candidate_pool_size; |
deadbeef | 6de92f9 | 2016-12-13 02:49:32 | [diff] [blame] | 167 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 168 | // If ICE servers changed, throw away any existing pooled sessions and create |
| 169 | // new ones. |
| 170 | if (ice_servers_changed) { |
| 171 | pooled_sessions_.clear(); |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 172 | } |
| 173 | |
Jonas Oreland | bdcee28 | 2017-10-10 12:01:40 | [diff] [blame] | 174 | turn_customizer_ = turn_customizer; |
| 175 | |
deadbeef | 42a4263 | 2017-03-10 23:18:00 | [diff] [blame] | 176 | // If |candidate_pool_size_| is less than the number of pooled sessions, get |
| 177 | // rid of the extras. |
| 178 | while (candidate_pool_size_ < static_cast<int>(pooled_sessions_.size())) { |
Jonas Oreland | 1cd39fa | 2018-10-11 05:47:12 | [diff] [blame] | 179 | pooled_sessions_.back().reset(nullptr); |
| 180 | pooled_sessions_.pop_back(); |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 181 | } |
deadbeef | 6de92f9 | 2016-12-13 02:49:32 | [diff] [blame] | 182 | |
Qingsi Wang | db53f8e | 2018-02-20 22:45:49 | [diff] [blame] | 183 | // |stun_candidate_keepalive_interval_| will be used in STUN port allocation |
| 184 | // in future sessions. We also update the ready ports in the pooled sessions. |
| 185 | // Ports in sessions that are taken and owned by P2PTransportChannel will be |
| 186 | // updated there via IceConfig. |
| 187 | stun_candidate_keepalive_interval_ = stun_candidate_keepalive_interval; |
| 188 | for (const auto& session : pooled_sessions_) { |
| 189 | session->SetStunKeepaliveIntervalForReadyPorts( |
| 190 | stun_candidate_keepalive_interval_); |
| 191 | } |
| 192 | |
deadbeef | 42a4263 | 2017-03-10 23:18:00 | [diff] [blame] | 193 | // If |candidate_pool_size_| is greater than the number of pooled sessions, |
deadbeef | 6de92f9 | 2016-12-13 02:49:32 | [diff] [blame] | 194 | // create new sessions. |
deadbeef | 42a4263 | 2017-03-10 23:18:00 | [diff] [blame] | 195 | while (static_cast<int>(pooled_sessions_.size()) < candidate_pool_size_) { |
Jonas Oreland | 1cd39fa | 2018-10-11 05:47:12 | [diff] [blame] | 196 | IceParameters iceCredentials = |
| 197 | IceCredentialsIterator::CreateRandomIceCredentials(); |
| 198 | PortAllocatorSession* pooled_session = |
| 199 | CreateSessionInternal("", 0, iceCredentials.ufrag, iceCredentials.pwd); |
| 200 | pooled_session->set_pooled(true); |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 201 | pooled_session->StartGettingPorts(); |
| 202 | pooled_sessions_.push_back( |
| 203 | std::unique_ptr<PortAllocatorSession>(pooled_session)); |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 204 | } |
deadbeef | 6de92f9 | 2016-12-13 02:49:32 | [diff] [blame] | 205 | return true; |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | std::unique_ptr<PortAllocatorSession> PortAllocator::CreateSession( |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 | [diff] [blame] | 209 | const std::string& content_name, |
| 210 | int component, |
| 211 | const std::string& ice_ufrag, |
| 212 | const std::string& ice_pwd) { |
Qingsi Wang | a2d6067 | 2018-04-11 23:57:45 | [diff] [blame] | 213 | CheckRunOnValidThreadAndInitialized(); |
Taylor Brandstetter | 417eebe | 2016-05-23 23:02:19 | [diff] [blame] | 214 | auto session = std::unique_ptr<PortAllocatorSession>( |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 215 | CreateSessionInternal(content_name, component, ice_ufrag, ice_pwd)); |
Taylor Brandstetter | 417eebe | 2016-05-23 23:02:19 | [diff] [blame] | 216 | session->SetCandidateFilter(candidate_filter()); |
| 217 | return session; |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | std::unique_ptr<PortAllocatorSession> PortAllocator::TakePooledSession( |
| 221 | const std::string& content_name, |
| 222 | int component, |
| 223 | const std::string& ice_ufrag, |
| 224 | const std::string& ice_pwd) { |
Qingsi Wang | a2d6067 | 2018-04-11 23:57:45 | [diff] [blame] | 225 | CheckRunOnValidThreadAndInitialized(); |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 226 | RTC_DCHECK(!ice_ufrag.empty()); |
| 227 | RTC_DCHECK(!ice_pwd.empty()); |
| 228 | if (pooled_sessions_.empty()) { |
| 229 | return nullptr; |
| 230 | } |
Jonas Oreland | 1cd39fa | 2018-10-11 05:47:12 | [diff] [blame] | 231 | |
| 232 | IceParameters credentials(ice_ufrag, ice_pwd, false); |
| 233 | // If restrict_ice_credentials_change_ is TRUE, then call FindPooledSession |
| 234 | // with ice credentials. Otherwise call it with nullptr which means |
| 235 | // "find any" pooled session. |
| 236 | auto cit = FindPooledSession(restrict_ice_credentials_change_ ? &credentials |
| 237 | : nullptr); |
| 238 | if (cit == pooled_sessions_.end()) { |
| 239 | return nullptr; |
| 240 | } |
| 241 | |
| 242 | auto it = |
| 243 | pooled_sessions_.begin() + std::distance(pooled_sessions_.cbegin(), cit); |
| 244 | std::unique_ptr<PortAllocatorSession> ret = std::move(*it); |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 245 | ret->SetIceParameters(content_name, component, ice_ufrag, ice_pwd); |
Jonas Oreland | 1cd39fa | 2018-10-11 05:47:12 | [diff] [blame] | 246 | ret->set_pooled(false); |
| 247 | // According to JSEP, a pooled session should filter candidates only |
| 248 | // after it's taken out of the pool. |
Taylor Brandstetter | 417eebe | 2016-05-23 23:02:19 | [diff] [blame] | 249 | ret->SetCandidateFilter(candidate_filter()); |
Jonas Oreland | 1cd39fa | 2018-10-11 05:47:12 | [diff] [blame] | 250 | pooled_sessions_.erase(it); |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 251 | return ret; |
| 252 | } |
| 253 | |
Jonas Oreland | 1cd39fa | 2018-10-11 05:47:12 | [diff] [blame] | 254 | const PortAllocatorSession* PortAllocator::GetPooledSession( |
| 255 | const IceParameters* ice_credentials) const { |
Qingsi Wang | a2d6067 | 2018-04-11 23:57:45 | [diff] [blame] | 256 | CheckRunOnValidThreadAndInitialized(); |
Jonas Oreland | 1cd39fa | 2018-10-11 05:47:12 | [diff] [blame] | 257 | auto it = FindPooledSession(ice_credentials); |
| 258 | if (it == pooled_sessions_.end()) { |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 259 | return nullptr; |
Jonas Oreland | 1cd39fa | 2018-10-11 05:47:12 | [diff] [blame] | 260 | } else { |
| 261 | return it->get(); |
Taylor Brandstetter | a1c3035 | 2016-05-13 15:15:11 | [diff] [blame] | 262 | } |
Jonas Oreland | 1cd39fa | 2018-10-11 05:47:12 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | std::vector<std::unique_ptr<PortAllocatorSession>>::const_iterator |
| 266 | PortAllocator::FindPooledSession(const IceParameters* ice_credentials) const { |
| 267 | for (auto it = pooled_sessions_.begin(); it != pooled_sessions_.end(); ++it) { |
| 268 | if (ice_credentials == nullptr || |
| 269 | ((*it)->ice_ufrag() == ice_credentials->ufrag && |
| 270 | (*it)->ice_pwd() == ice_credentials->pwd)) { |
| 271 | return it; |
| 272 | } |
| 273 | } |
| 274 | return pooled_sessions_.end(); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 | [diff] [blame] | 275 | } |
| 276 | |
deadbeef | 42a4263 | 2017-03-10 23:18:00 | [diff] [blame] | 277 | void PortAllocator::FreezeCandidatePool() { |
Qingsi Wang | a2d6067 | 2018-04-11 23:57:45 | [diff] [blame] | 278 | CheckRunOnValidThreadAndInitialized(); |
deadbeef | 42a4263 | 2017-03-10 23:18:00 | [diff] [blame] | 279 | candidate_pool_frozen_ = true; |
| 280 | } |
| 281 | |
| 282 | void PortAllocator::DiscardCandidatePool() { |
Qingsi Wang | a2d6067 | 2018-04-11 23:57:45 | [diff] [blame] | 283 | CheckRunOnValidThreadIfInitialized(); |
deadbeef | 42a4263 | 2017-03-10 23:18:00 | [diff] [blame] | 284 | pooled_sessions_.clear(); |
| 285 | } |
| 286 | |
Qingsi Wang | c129c35 | 2019-04-18 17:41:58 | [diff] [blame] | 287 | void PortAllocator::SetCandidateFilter(uint32_t filter) { |
| 288 | CheckRunOnValidThreadIfInitialized(); |
| 289 | if (candidate_filter_ == filter) { |
| 290 | return; |
| 291 | } |
| 292 | uint32_t prev_filter = candidate_filter_; |
| 293 | candidate_filter_ = filter; |
| 294 | SignalCandidateFilterChanged(prev_filter, filter); |
| 295 | } |
| 296 | |
Qingsi Wang | 72a43a1 | 2018-02-21 00:03:18 | [diff] [blame] | 297 | void PortAllocator::GetCandidateStatsFromPooledSessions( |
| 298 | CandidateStatsList* candidate_stats_list) { |
Qingsi Wang | a2d6067 | 2018-04-11 23:57:45 | [diff] [blame] | 299 | CheckRunOnValidThreadAndInitialized(); |
Qingsi Wang | 72a43a1 | 2018-02-21 00:03:18 | [diff] [blame] | 300 | for (const auto& session : pooled_sessions()) { |
| 301 | session->GetCandidateStatsFromReadyPorts(candidate_stats_list); |
| 302 | } |
| 303 | } |
| 304 | |
Jonas Oreland | 1cd39fa | 2018-10-11 05:47:12 | [diff] [blame] | 305 | std::vector<IceParameters> PortAllocator::GetPooledIceCredentials() { |
| 306 | CheckRunOnValidThreadAndInitialized(); |
| 307 | std::vector<IceParameters> list; |
| 308 | for (const auto& session : pooled_sessions_) { |
| 309 | list.push_back( |
| 310 | IceParameters(session->ice_ufrag(), session->ice_pwd(), false)); |
| 311 | } |
| 312 | return list; |
| 313 | } |
| 314 | |
Qingsi Wang | 7627fdd | 2019-08-19 23:07:40 | [diff] [blame] | 315 | Candidate PortAllocator::SanitizeCandidate(const Candidate& c) const { |
| 316 | CheckRunOnValidThreadAndInitialized(); |
| 317 | // For a local host candidate, we need to conceal its IP address candidate if |
| 318 | // the mDNS obfuscation is enabled. |
| 319 | bool use_hostname_address = |
| 320 | c.type() == LOCAL_PORT_TYPE && MdnsObfuscationEnabled(); |
| 321 | // If adapter enumeration is disabled or host candidates are disabled, |
| 322 | // clear the raddr of STUN candidates to avoid local address leakage. |
| 323 | bool filter_stun_related_address = |
| 324 | ((flags() & PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION) && |
| 325 | (flags() & PORTALLOCATOR_DISABLE_DEFAULT_LOCAL_CANDIDATE)) || |
| 326 | !(candidate_filter_ & CF_HOST) || MdnsObfuscationEnabled(); |
| 327 | // If the candidate filter doesn't allow reflexive addresses, empty TURN raddr |
| 328 | // to avoid reflexive address leakage. |
| 329 | bool filter_turn_related_address = !(candidate_filter_ & CF_REFLEXIVE); |
| 330 | bool filter_related_address = |
| 331 | ((c.type() == STUN_PORT_TYPE && filter_stun_related_address) || |
| 332 | (c.type() == RELAY_PORT_TYPE && filter_turn_related_address)); |
| 333 | return c.ToSanitizedCopy(use_hostname_address, filter_related_address); |
| 334 | } |
| 335 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 | [diff] [blame] | 336 | } // namespace cricket |