blob: ab47ce10308538e77b51fedb2ef65a0cbd451833 [file] [log] [blame]
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +00001/*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Steve Anton10542f22019-01-11 09:11:00 -080011#ifndef P2P_CLIENT_BASIC_PORT_ALLOCATOR_H_
12#define P2P_CLIENT_BASIC_PORT_ALLOCATOR_H_
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000013
kwiberg3ec46792016-04-27 07:22:53 -070014#include <memory>
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000015#include <string>
16#include <vector>
17
Steve Anton10542f22019-01-11 09:11:00 -080018#include "api/turn_customizer.h"
19#include "p2p/base/port_allocator.h"
20#include "p2p/client/relay_port_factory_interface.h"
21#include "p2p/client/turn_port_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080023#include "rtc_base/message_queue.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "rtc_base/network.h"
Mirko Bonadei3b56ee72018-10-15 17:15:12 +020025#include "rtc_base/system/rtc_export.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020026#include "rtc_base/thread.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000027
28namespace cricket {
29
Mirko Bonadei3b56ee72018-10-15 17:15:12 +020030class RTC_EXPORT BasicPortAllocator : public PortAllocator {
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000031 public:
Jonas Oreland202994c2017-12-18 12:10:43 +010032 // note: The (optional) relay_port_factory is owned by caller
33 // and must have a life time that exceeds that of BasicPortAllocator.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000034 BasicPortAllocator(rtc::NetworkManager* network_manager,
Jonas Orelandbdcee282017-10-10 14:01:40 +020035 rtc::PacketSocketFactory* socket_factory,
Jonas Oreland202994c2017-12-18 12:10:43 +010036 webrtc::TurnCustomizer* customizer = nullptr,
37 RelayPortFactoryInterface* relay_port_factory = nullptr);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000038 explicit BasicPortAllocator(rtc::NetworkManager* network_manager);
39 BasicPortAllocator(rtc::NetworkManager* network_manager,
Niels Möllera3baf2a2019-09-06 10:29:50 +020040 const ServerAddresses& stun_servers);
41 BasicPortAllocator(rtc::NetworkManager* network_manager,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000042 rtc::PacketSocketFactory* socket_factory,
43 const ServerAddresses& stun_servers);
Steve Anton7995d8c2017-10-30 16:23:38 -070044 ~BasicPortAllocator() override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000045
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -080046 // Set to kDefaultNetworkIgnoreMask by default.
Steve Anton7995d8c2017-10-30 16:23:38 -070047 void SetNetworkIgnoreMask(int network_ignore_mask) override;
Qingsi Wanga2d60672018-04-11 16:57:45 -070048 int network_ignore_mask() const {
49 CheckRunOnValidThreadIfInitialized();
50 return network_ignore_mask_;
51 }
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -080052
Qingsi Wanga2d60672018-04-11 16:57:45 -070053 rtc::NetworkManager* network_manager() const {
54 CheckRunOnValidThreadIfInitialized();
55 return network_manager_;
56 }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000057
58 // If socket_factory() is set to NULL each PortAllocatorSession
59 // creates its own socket factory.
Qingsi Wanga2d60672018-04-11 16:57:45 -070060 rtc::PacketSocketFactory* socket_factory() {
61 CheckRunOnValidThreadIfInitialized();
62 return socket_factory_;
63 }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000064
deadbeef653b8e02015-11-11 12:55:10 -080065 PortAllocatorSession* CreateSessionInternal(
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000066 const std::string& content_name,
67 int component,
68 const std::string& ice_ufrag,
deadbeef653b8e02015-11-11 12:55:10 -080069 const std::string& ice_pwd) override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000070
Taylor Brandstettera1c30352016-05-13 08:15:11 -070071 // Convenience method that adds a TURN server to the configuration.
72 void AddTurnServer(const RelayServerConfig& turn_server);
73
Jonas Oreland202994c2017-12-18 12:10:43 +010074 RelayPortFactoryInterface* relay_port_factory() {
Qingsi Wanga2d60672018-04-11 16:57:45 -070075 CheckRunOnValidThreadIfInitialized();
Jonas Oreland202994c2017-12-18 12:10:43 +010076 return relay_port_factory_;
77 }
78
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000079 private:
80 void Construct();
81
Honghai Zhangd93f50c2016-10-05 11:47:22 -070082 void OnIceRegathering(PortAllocatorSession* session,
83 IceRegatheringReason reason);
84
Jonas Oreland202994c2017-12-18 12:10:43 +010085 // This function makes sure that relay_port_factory_ is set properly.
86 void InitRelayPortFactory(RelayPortFactoryInterface* relay_port_factory);
87
Qingsi Wang7627fdd2019-08-19 16:07:40 -070088 bool MdnsObfuscationEnabled() const override;
89
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000090 rtc::NetworkManager* network_manager_;
91 rtc::PacketSocketFactory* socket_factory_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000092 bool allow_tcp_listen_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -080093 int network_ignore_mask_ = rtc::kDefaultNetworkIgnoreMask;
Jonas Oreland202994c2017-12-18 12:10:43 +010094
95 // This is the factory being used.
96 RelayPortFactoryInterface* relay_port_factory_;
97
98 // This instance is created if caller does pass a factory.
99 std::unique_ptr<RelayPortFactoryInterface> default_relay_port_factory_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000100};
101
102struct PortConfiguration;
103class AllocationSequence;
104
Honghai Zhangd8f6fc42016-07-01 17:31:12 -0700105enum class SessionState {
106 GATHERING, // Actively allocating ports and gathering candidates.
107 CLEARED, // Current allocation process has been stopped but may start
108 // new ones.
109 STOPPED // This session has completely stopped, no new allocation
110 // process will be started.
111};
112
Mirko Bonadei3b56ee72018-10-15 17:15:12 +0200113class RTC_EXPORT BasicPortAllocatorSession : public PortAllocatorSession,
114 public rtc::MessageHandler {
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000115 public:
116 BasicPortAllocatorSession(BasicPortAllocator* allocator,
117 const std::string& content_name,
118 int component,
119 const std::string& ice_ufrag,
120 const std::string& ice_pwd);
Steve Anton7995d8c2017-10-30 16:23:38 -0700121 ~BasicPortAllocatorSession() override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000122
Steve Anton7995d8c2017-10-30 16:23:38 -0700123 virtual BasicPortAllocator* allocator();
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000124 rtc::Thread* network_thread() { return network_thread_; }
125 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; }
126
Qingsi Wangc129c352019-04-18 10:41:58 -0700127 // If the new filter allows new types of candidates compared to the previous
128 // filter, gathered candidates that were discarded because of not matching the
129 // previous filter will be signaled if they match the new one.
130 //
131 // We do not perform any regathering since the port allocator flags decide
132 // the type of candidates to gather and the candidate filter only controls the
133 // signaling of candidates. As a result, with the candidate filter changed
134 // alone, all newly allowed candidates for signaling should already be
135 // gathered by the respective cricket::Port.
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700136 void SetCandidateFilter(uint32_t filter) override;
deadbeef653b8e02015-11-11 12:55:10 -0800137 void StartGettingPorts() override;
138 void StopGettingPorts() override;
139 void ClearGettingPorts() override;
Steve Anton7995d8c2017-10-30 16:23:38 -0700140 bool IsGettingPorts() override;
141 bool IsCleared() const override;
142 bool IsStopped() const override;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700143 // These will all be cricket::Ports.
144 std::vector<PortInterface*> ReadyPorts() const override;
145 std::vector<Candidate> ReadyCandidates() const override;
146 bool CandidatesAllocationDone() const override;
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700147 void RegatherOnFailedNetworks() override;
Steve Anton300bf8e2017-07-14 10:13:10 -0700148 void RegatherOnAllNetworks() override;
Qingsi Wang7627fdd2019-08-19 16:07:40 -0700149 void GetCandidateStatsFromReadyPorts(
150 CandidateStatsList* candidate_stats_list) const override;
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800151 void SetStunKeepaliveIntervalForReadyPorts(
Danil Chapovalov00c71832018-06-15 15:58:38 +0200152 const absl::optional<int>& stun_keepalive_interval) override;
Honghai Zhanga74363c2016-07-28 18:06:15 -0700153 void PruneAllPorts() override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000154
155 protected:
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700156 void UpdateIceParametersInternal() override;
157
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000158 // Starts the process of getting the port configurations.
159 virtual void GetPortConfigurations();
160
161 // Adds a port configuration that is now ready. Once we have one for each
162 // network (or a timeout occurs), we will start allocating ports.
163 virtual void ConfigReady(PortConfiguration* config);
164
165 // MessageHandler. Can be overriden if message IDs do not conflict.
deadbeef653b8e02015-11-11 12:55:10 -0800166 void OnMessage(rtc::Message* message) override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000167
168 private:
169 class PortData {
170 public:
Qingsi Wangc129c352019-04-18 10:41:58 -0700171 enum State {
172 STATE_INPROGRESS, // Still gathering candidates.
173 STATE_COMPLETE, // All candidates allocated and ready for process.
174 STATE_ERROR, // Error in gathering candidates.
175 STATE_PRUNED // Pruned by higher priority ports on the same network
176 // interface. Only TURN ports may be pruned.
177 };
178
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700179 PortData() {}
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000180 PortData(Port* port, AllocationSequence* seq)
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700181 : port_(port), sequence_(seq) {}
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000182
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700183 Port* port() const { return port_; }
184 AllocationSequence* sequence() const { return sequence_; }
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700185 bool has_pairable_candidate() const { return has_pairable_candidate_; }
Qingsi Wangc129c352019-04-18 10:41:58 -0700186 State state() const { return state_; }
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700187 bool complete() const { return state_ == STATE_COMPLETE; }
188 bool error() const { return state_ == STATE_ERROR; }
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700189 bool pruned() const { return state_ == STATE_PRUNED; }
190 bool inprogress() const { return state_ == STATE_INPROGRESS; }
191 // Returns true if this port is ready to be used.
192 bool ready() const {
193 return has_pairable_candidate_ && state_ != STATE_ERROR &&
194 state_ != STATE_PRUNED;
195 }
Honghai Zhangc67e0f52016-09-19 16:57:37 -0700196 // Sets the state to "PRUNED" and prunes the Port.
197 void Prune() {
198 state_ = STATE_PRUNED;
199 if (port()) {
200 port()->Prune();
201 }
202 }
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700203 void set_has_pairable_candidate(bool has_pairable_candidate) {
204 if (has_pairable_candidate) {
nisseede5da42017-01-12 05:15:36 -0800205 RTC_DCHECK(state_ == STATE_INPROGRESS);
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700206 }
207 has_pairable_candidate_ = has_pairable_candidate;
208 }
Qingsi Wangc129c352019-04-18 10:41:58 -0700209 void set_state(State state) {
210 RTC_DCHECK(state != STATE_ERROR || state_ == STATE_INPROGRESS);
211 state_ = state;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000212 }
213
214 private:
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700215 Port* port_ = nullptr;
216 AllocationSequence* sequence_ = nullptr;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700217 bool has_pairable_candidate_ = false;
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700218 State state_ = STATE_INPROGRESS;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000219 };
220
221 void OnConfigReady(PortConfiguration* config);
222 void OnConfigStop();
223 void AllocatePorts();
224 void OnAllocate();
Steve Anton300bf8e2017-07-14 10:13:10 -0700225 void DoAllocate(bool disable_equivalent_phases);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000226 void OnNetworksChanged();
227 void OnAllocationSequenceObjectsCreated();
228 void DisableEquivalentPhases(rtc::Network* network,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200229 PortConfiguration* config,
230 uint32_t* flags);
Yves Gerey665174f2018-06-19 15:03:05 +0200231 void AddAllocatedPort(Port* port,
232 AllocationSequence* seq,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000233 bool prepare_address);
234 void OnCandidateReady(Port* port, const Candidate& c);
Eldar Relloda13ea22019-06-01 12:23:43 +0300235 void OnCandidateError(Port* port, const IceCandidateErrorEvent& event);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000236 void OnPortComplete(Port* port);
237 void OnPortError(Port* port);
238 void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto);
239 void OnPortDestroyed(PortInterface* port);
Mirko Bonadei5f4d47b2018-08-22 17:41:22 +0000240 void MaybeSignalCandidatesAllocationDone();
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000241 void OnPortAllocationComplete(AllocationSequence* seq);
242 PortData* FindPort(Port* port);
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700243 std::vector<rtc::Network*> GetNetworks();
244 std::vector<rtc::Network*> GetFailedNetworks();
Steve Anton300bf8e2017-07-14 10:13:10 -0700245 void Regather(const std::vector<rtc::Network*>& networks,
246 bool disable_equivalent_phases,
247 IceRegatheringReason reason);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000248
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700249 bool CheckCandidateFilter(const Candidate& c) const;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700250 bool CandidatePairable(const Candidate& c, const Port* port) const;
Jeroen de Borst72d2ddd2018-11-27 13:20:39 -0800251
Honghai Zhangc67e0f52016-09-19 16:57:37 -0700252 std::vector<PortData*> GetUnprunedPorts(
253 const std::vector<rtc::Network*>& networks);
254 // Prunes ports and signal the remote side to remove the candidates that
255 // were previously signaled from these ports.
Mirko Bonadei5f4d47b2018-08-22 17:41:22 +0000256 void PrunePortsAndRemoveCandidates(
Honghai Zhangc67e0f52016-09-19 16:57:37 -0700257 const std::vector<PortData*>& port_data_list);
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700258 // Gets filtered and sanitized candidates generated from a port and
259 // append to |candidates|.
260 void GetCandidatesFromPort(const PortData& data,
261 std::vector<Candidate>* candidates) const;
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700262 Port* GetBestTurnPortForNetwork(const std::string& network_name) const;
263 // Returns true if at least one TURN port is pruned.
264 bool PruneTurnPorts(Port* newly_pairable_turn_port);
Honghai Zhangf8998cf2019-10-14 11:27:50 -0700265 bool PruneNewlyPairableTurnPort(PortData* newly_pairable_turn_port);
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700266
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000267 BasicPortAllocator* allocator_;
268 rtc::Thread* network_thread_;
kwiberg3ec46792016-04-27 07:22:53 -0700269 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000270 rtc::PacketSocketFactory* socket_factory_;
271 bool allocation_started_;
272 bool network_manager_started_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000273 bool allocation_sequences_created_;
274 std::vector<PortConfiguration*> configs_;
275 std::vector<AllocationSequence*> sequences_;
276 std::vector<PortData> ports_;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700277 uint32_t candidate_filter_ = CF_ALL;
Honghai Zhangf8998cf2019-10-14 11:27:50 -0700278 // Policy on how to prune turn ports, taken from the port allocator.
279 webrtc::PortPrunePolicy turn_port_prune_policy_;
Honghai Zhangd8f6fc42016-07-01 17:31:12 -0700280 SessionState state_ = SessionState::CLEARED;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000281
282 friend class AllocationSequence;
283};
284
285// Records configuration information useful in creating ports.
deadbeef653b8e02015-11-11 12:55:10 -0800286// TODO(deadbeef): Rename "relay" to "turn_server" in this struct.
Mirko Bonadei3b56ee72018-10-15 17:15:12 +0200287struct RTC_EXPORT PortConfiguration : public rtc::MessageData {
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000288 // TODO(jiayl): remove |stun_address| when Chrome is updated.
289 rtc::SocketAddress stun_address;
290 ServerAddresses stun_servers;
291 std::string username;
292 std::string password;
Honghai Zhang6981fb52019-10-29 12:45:34 -0700293 bool use_turn_server_as_stun_server_disabled = false;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000294
295 typedef std::vector<RelayServerConfig> RelayList;
296 RelayList relays;
297
298 // TODO(jiayl): remove this ctor when Chrome is updated.
299 PortConfiguration(const rtc::SocketAddress& stun_address,
300 const std::string& username,
301 const std::string& password);
302
303 PortConfiguration(const ServerAddresses& stun_servers,
304 const std::string& username,
305 const std::string& password);
306
Steve Anton7995d8c2017-10-30 16:23:38 -0700307 ~PortConfiguration() override;
308
deadbeefc5d0d952015-07-16 10:22:21 -0700309 // Returns addresses of both the explicitly configured STUN servers,
310 // and TURN servers that should be used as STUN servers.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000311 ServerAddresses StunServers();
312
313 // Adds another relay server, with the given ports and modifier, to the list.
314 void AddRelay(const RelayServerConfig& config);
315
316 // Determines whether the given relay server supports the given protocol.
317 bool SupportsProtocol(const RelayServerConfig& relay,
318 ProtocolType type) const;
Niels Möller191e38f2019-11-04 08:49:12 +0100319 bool SupportsProtocol(ProtocolType type) const;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000320 // Helper method returns the server addresses for the matching RelayType and
321 // Protocol type.
Niels Möller191e38f2019-11-04 08:49:12 +0100322 ServerAddresses GetRelayServerAddresses(ProtocolType type) const;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000323};
324
honghaizf421bdc2015-07-17 16:21:55 -0700325class UDPPort;
326class TurnPort;
327
328// Performs the allocation of ports, in a sequenced (timed) manner, for a given
329// network and IP address.
330class AllocationSequence : public rtc::MessageHandler,
331 public sigslot::has_slots<> {
332 public:
333 enum State {
334 kInit, // Initial state.
335 kRunning, // Started allocating ports.
336 kStopped, // Stopped from running.
337 kCompleted, // All ports are allocated.
338
339 // kInit --> kRunning --> {kCompleted|kStopped}
340 };
341 AllocationSequence(BasicPortAllocatorSession* session,
342 rtc::Network* network,
343 PortConfiguration* config,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200344 uint32_t flags);
Steve Anton7995d8c2017-10-30 16:23:38 -0700345 ~AllocationSequence() override;
Honghai Zhang5048f572016-08-23 15:47:33 -0700346 void Init();
honghaizf421bdc2015-07-17 16:21:55 -0700347 void Clear();
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700348 void OnNetworkFailed();
honghaizf421bdc2015-07-17 16:21:55 -0700349
350 State state() const { return state_; }
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700351 rtc::Network* network() const { return network_; }
352
353 bool network_failed() const { return network_failed_; }
354 void set_network_failed() { network_failed_ = true; }
honghaizf421bdc2015-07-17 16:21:55 -0700355
356 // Disables the phases for a new sequence that this one already covers for an
357 // equivalent network setup.
358 void DisableEquivalentPhases(rtc::Network* network,
359 PortConfiguration* config,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200360 uint32_t* flags);
honghaizf421bdc2015-07-17 16:21:55 -0700361
362 // Starts and stops the sequence. When started, it will continue allocating
363 // new ports on its own timed schedule.
364 void Start();
365 void Stop();
366
367 // MessageHandler
Steve Anton7995d8c2017-10-30 16:23:38 -0700368 void OnMessage(rtc::Message* msg) override;
honghaizf421bdc2015-07-17 16:21:55 -0700369
honghaizf421bdc2015-07-17 16:21:55 -0700370 // Signal from AllocationSequence, when it's done with allocating ports.
371 // This signal is useful, when port allocation fails which doesn't result
372 // in any candidates. Using this signal BasicPortAllocatorSession can send
373 // its candidate discovery conclusion signal. Without this signal,
374 // BasicPortAllocatorSession doesn't have any event to trigger signal. This
375 // can also be achieved by starting timer in BPAS.
376 sigslot::signal1<AllocationSequence*> SignalPortAllocationComplete;
377
378 protected:
379 // For testing.
380 void CreateTurnPort(const RelayServerConfig& config);
381
382 private:
383 typedef std::vector<ProtocolType> ProtocolList;
384
Peter Boström0c4e06b2015-10-07 12:23:21 +0200385 bool IsFlagSet(uint32_t flag) { return ((flags_ & flag) != 0); }
honghaizf421bdc2015-07-17 16:21:55 -0700386 void CreateUDPPorts();
387 void CreateTCPPorts();
388 void CreateStunPorts();
389 void CreateRelayPorts();
honghaizf421bdc2015-07-17 16:21:55 -0700390
391 void OnReadPacket(rtc::AsyncPacketSocket* socket,
392 const char* data,
393 size_t size,
394 const rtc::SocketAddress& remote_addr,
Niels Möllere6933812018-11-05 13:01:41 +0100395 const int64_t& packet_time_us);
honghaizf421bdc2015-07-17 16:21:55 -0700396
397 void OnPortDestroyed(PortInterface* port);
398
399 BasicPortAllocatorSession* session_;
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700400 bool network_failed_ = false;
honghaizf421bdc2015-07-17 16:21:55 -0700401 rtc::Network* network_;
deadbeef5c3c1042017-08-04 15:01:57 -0700402 // Compared with the new best IP in DisableEquivalentPhases.
403 rtc::IPAddress previous_best_ip_;
honghaizf421bdc2015-07-17 16:21:55 -0700404 PortConfiguration* config_;
405 State state_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200406 uint32_t flags_;
honghaizf421bdc2015-07-17 16:21:55 -0700407 ProtocolList protocols_;
kwiberg3ec46792016-04-27 07:22:53 -0700408 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_;
honghaizf421bdc2015-07-17 16:21:55 -0700409 // There will be only one udp port per AllocationSequence.
410 UDPPort* udp_port_;
Jonas Oreland202994c2017-12-18 12:10:43 +0100411 std::vector<Port*> relay_ports_;
honghaizf421bdc2015-07-17 16:21:55 -0700412 int phase_;
413};
414
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000415} // namespace cricket
416
Steve Anton10542f22019-01-11 09:11:00 -0800417#endif // P2P_CLIENT_BASIC_PORT_ALLOCATOR_H_