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