blob: 50cb83d442004f53199737d0ec6e50a4797b29fb [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,
40 rtc::PacketSocketFactory* socket_factory,
41 const ServerAddresses& stun_servers);
42 BasicPortAllocator(rtc::NetworkManager* network_manager,
43 const ServerAddresses& stun_servers,
Jonas Oreland202994c2017-12-18 12:10:43 +010044 const rtc::SocketAddress& relay_address_udp,
45 const rtc::SocketAddress& relay_address_tcp,
46 const rtc::SocketAddress& relay_address_ssl);
Steve Anton7995d8c2017-10-30 16:23:38 -070047 ~BasicPortAllocator() override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000048
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -080049 // Set to kDefaultNetworkIgnoreMask by default.
Steve Anton7995d8c2017-10-30 16:23:38 -070050 void SetNetworkIgnoreMask(int network_ignore_mask) override;
Qingsi Wanga2d60672018-04-11 16:57:45 -070051 int network_ignore_mask() const {
52 CheckRunOnValidThreadIfInitialized();
53 return network_ignore_mask_;
54 }
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -080055
Qingsi Wanga2d60672018-04-11 16:57:45 -070056 rtc::NetworkManager* network_manager() const {
57 CheckRunOnValidThreadIfInitialized();
58 return network_manager_;
59 }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000060
61 // If socket_factory() is set to NULL each PortAllocatorSession
62 // creates its own socket factory.
Qingsi Wanga2d60672018-04-11 16:57:45 -070063 rtc::PacketSocketFactory* socket_factory() {
64 CheckRunOnValidThreadIfInitialized();
65 return socket_factory_;
66 }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000067
deadbeef653b8e02015-11-11 12:55:10 -080068 PortAllocatorSession* CreateSessionInternal(
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000069 const std::string& content_name,
70 int component,
71 const std::string& ice_ufrag,
deadbeef653b8e02015-11-11 12:55:10 -080072 const std::string& ice_pwd) override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000073
Taylor Brandstettera1c30352016-05-13 08:15:11 -070074 // Convenience method that adds a TURN server to the configuration.
75 void AddTurnServer(const RelayServerConfig& turn_server);
76
Jonas Oreland202994c2017-12-18 12:10:43 +010077 RelayPortFactoryInterface* relay_port_factory() {
Qingsi Wanga2d60672018-04-11 16:57:45 -070078 CheckRunOnValidThreadIfInitialized();
Jonas Oreland202994c2017-12-18 12:10:43 +010079 return relay_port_factory_;
80 }
81
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000082 private:
83 void Construct();
84
Honghai Zhangd93f50c2016-10-05 11:47:22 -070085 void OnIceRegathering(PortAllocatorSession* session,
86 IceRegatheringReason reason);
87
Jonas Oreland202994c2017-12-18 12:10:43 +010088 // This function makes sure that relay_port_factory_ is set properly.
89 void InitRelayPortFactory(RelayPortFactoryInterface* relay_port_factory);
90
Qingsi Wang7627fdd2019-08-19 16:07:40 -070091 bool MdnsObfuscationEnabled() const override;
92
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000093 rtc::NetworkManager* network_manager_;
94 rtc::PacketSocketFactory* socket_factory_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000095 bool allow_tcp_listen_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -080096 int network_ignore_mask_ = rtc::kDefaultNetworkIgnoreMask;
Jonas Oreland202994c2017-12-18 12:10:43 +010097
98 // This is the factory being used.
99 RelayPortFactoryInterface* relay_port_factory_;
100
101 // This instance is created if caller does pass a factory.
102 std::unique_ptr<RelayPortFactoryInterface> default_relay_port_factory_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000103};
104
105struct PortConfiguration;
106class AllocationSequence;
107
Honghai Zhangd8f6fc42016-07-01 17:31:12 -0700108enum class SessionState {
109 GATHERING, // Actively allocating ports and gathering candidates.
110 CLEARED, // Current allocation process has been stopped but may start
111 // new ones.
112 STOPPED // This session has completely stopped, no new allocation
113 // process will be started.
114};
115
Mirko Bonadei3b56ee72018-10-15 17:15:12 +0200116class RTC_EXPORT BasicPortAllocatorSession : public PortAllocatorSession,
117 public rtc::MessageHandler {
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000118 public:
119 BasicPortAllocatorSession(BasicPortAllocator* allocator,
120 const std::string& content_name,
121 int component,
122 const std::string& ice_ufrag,
123 const std::string& ice_pwd);
Steve Anton7995d8c2017-10-30 16:23:38 -0700124 ~BasicPortAllocatorSession() override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000125
Steve Anton7995d8c2017-10-30 16:23:38 -0700126 virtual BasicPortAllocator* allocator();
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000127 rtc::Thread* network_thread() { return network_thread_; }
128 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; }
129
Qingsi Wangc129c352019-04-18 10:41:58 -0700130 // If the new filter allows new types of candidates compared to the previous
131 // filter, gathered candidates that were discarded because of not matching the
132 // previous filter will be signaled if they match the new one.
133 //
134 // We do not perform any regathering since the port allocator flags decide
135 // the type of candidates to gather and the candidate filter only controls the
136 // signaling of candidates. As a result, with the candidate filter changed
137 // alone, all newly allowed candidates for signaling should already be
138 // gathered by the respective cricket::Port.
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700139 void SetCandidateFilter(uint32_t filter) override;
deadbeef653b8e02015-11-11 12:55:10 -0800140 void StartGettingPorts() override;
141 void StopGettingPorts() override;
142 void ClearGettingPorts() override;
Steve Anton7995d8c2017-10-30 16:23:38 -0700143 bool IsGettingPorts() override;
144 bool IsCleared() const override;
145 bool IsStopped() const override;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700146 // These will all be cricket::Ports.
147 std::vector<PortInterface*> ReadyPorts() const override;
148 std::vector<Candidate> ReadyCandidates() const override;
149 bool CandidatesAllocationDone() const override;
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700150 void RegatherOnFailedNetworks() override;
Steve Anton300bf8e2017-07-14 10:13:10 -0700151 void RegatherOnAllNetworks() override;
Qingsi Wang7627fdd2019-08-19 16:07:40 -0700152 void GetCandidateStatsFromReadyPorts(
153 CandidateStatsList* candidate_stats_list) const override;
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800154 void SetStunKeepaliveIntervalForReadyPorts(
Danil Chapovalov00c71832018-06-15 15:58:38 +0200155 const absl::optional<int>& stun_keepalive_interval) override;
Honghai Zhanga74363c2016-07-28 18:06:15 -0700156 void PruneAllPorts() override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000157
158 protected:
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700159 void UpdateIceParametersInternal() override;
160
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000161 // Starts the process of getting the port configurations.
162 virtual void GetPortConfigurations();
163
164 // Adds a port configuration that is now ready. Once we have one for each
165 // network (or a timeout occurs), we will start allocating ports.
166 virtual void ConfigReady(PortConfiguration* config);
167
168 // MessageHandler. Can be overriden if message IDs do not conflict.
deadbeef653b8e02015-11-11 12:55:10 -0800169 void OnMessage(rtc::Message* message) override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000170
171 private:
172 class PortData {
173 public:
Qingsi Wangc129c352019-04-18 10:41:58 -0700174 enum State {
175 STATE_INPROGRESS, // Still gathering candidates.
176 STATE_COMPLETE, // All candidates allocated and ready for process.
177 STATE_ERROR, // Error in gathering candidates.
178 STATE_PRUNED // Pruned by higher priority ports on the same network
179 // interface. Only TURN ports may be pruned.
180 };
181
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700182 PortData() {}
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000183 PortData(Port* port, AllocationSequence* seq)
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700184 : port_(port), sequence_(seq) {}
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000185
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700186 Port* port() const { return port_; }
187 AllocationSequence* sequence() const { return sequence_; }
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700188 bool has_pairable_candidate() const { return has_pairable_candidate_; }
Qingsi Wangc129c352019-04-18 10:41:58 -0700189 State state() const { return state_; }
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700190 bool complete() const { return state_ == STATE_COMPLETE; }
191 bool error() const { return state_ == STATE_ERROR; }
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700192 bool pruned() const { return state_ == STATE_PRUNED; }
193 bool inprogress() const { return state_ == STATE_INPROGRESS; }
194 // Returns true if this port is ready to be used.
195 bool ready() const {
196 return has_pairable_candidate_ && state_ != STATE_ERROR &&
197 state_ != STATE_PRUNED;
198 }
Honghai Zhangc67e0f52016-09-19 16:57:37 -0700199 // Sets the state to "PRUNED" and prunes the Port.
200 void Prune() {
201 state_ = STATE_PRUNED;
202 if (port()) {
203 port()->Prune();
204 }
205 }
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700206 void set_has_pairable_candidate(bool has_pairable_candidate) {
207 if (has_pairable_candidate) {
nisseede5da42017-01-12 05:15:36 -0800208 RTC_DCHECK(state_ == STATE_INPROGRESS);
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700209 }
210 has_pairable_candidate_ = has_pairable_candidate;
211 }
Qingsi Wangc129c352019-04-18 10:41:58 -0700212 void set_state(State state) {
213 RTC_DCHECK(state != STATE_ERROR || state_ == STATE_INPROGRESS);
214 state_ = state;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000215 }
216
217 private:
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700218 Port* port_ = nullptr;
219 AllocationSequence* sequence_ = nullptr;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700220 bool has_pairable_candidate_ = false;
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700221 State state_ = STATE_INPROGRESS;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000222 };
223
224 void OnConfigReady(PortConfiguration* config);
225 void OnConfigStop();
226 void AllocatePorts();
227 void OnAllocate();
Steve Anton300bf8e2017-07-14 10:13:10 -0700228 void DoAllocate(bool disable_equivalent_phases);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000229 void OnNetworksChanged();
230 void OnAllocationSequenceObjectsCreated();
231 void DisableEquivalentPhases(rtc::Network* network,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200232 PortConfiguration* config,
233 uint32_t* flags);
Yves Gerey665174f2018-06-19 15:03:05 +0200234 void AddAllocatedPort(Port* port,
235 AllocationSequence* seq,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000236 bool prepare_address);
237 void OnCandidateReady(Port* port, const Candidate& c);
Eldar Relloda13ea22019-06-01 12:23:43 +0300238 void OnCandidateError(Port* port, const IceCandidateErrorEvent& event);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000239 void OnPortComplete(Port* port);
240 void OnPortError(Port* port);
241 void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto);
242 void OnPortDestroyed(PortInterface* port);
Mirko Bonadei5f4d47b2018-08-22 17:41:22 +0000243 void MaybeSignalCandidatesAllocationDone();
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000244 void OnPortAllocationComplete(AllocationSequence* seq);
245 PortData* FindPort(Port* port);
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700246 std::vector<rtc::Network*> GetNetworks();
247 std::vector<rtc::Network*> GetFailedNetworks();
Steve Anton300bf8e2017-07-14 10:13:10 -0700248 void Regather(const std::vector<rtc::Network*>& networks,
249 bool disable_equivalent_phases,
250 IceRegatheringReason reason);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000251
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700252 bool CheckCandidateFilter(const Candidate& c) const;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700253 bool CandidatePairable(const Candidate& c, const Port* port) const;
Jeroen de Borst72d2ddd2018-11-27 13:20:39 -0800254
Honghai Zhangc67e0f52016-09-19 16:57:37 -0700255 std::vector<PortData*> GetUnprunedPorts(
256 const std::vector<rtc::Network*>& networks);
257 // Prunes ports and signal the remote side to remove the candidates that
258 // were previously signaled from these ports.
Mirko Bonadei5f4d47b2018-08-22 17:41:22 +0000259 void PrunePortsAndRemoveCandidates(
Honghai Zhangc67e0f52016-09-19 16:57:37 -0700260 const std::vector<PortData*>& port_data_list);
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700261 // Gets filtered and sanitized candidates generated from a port and
262 // append to |candidates|.
263 void GetCandidatesFromPort(const PortData& data,
264 std::vector<Candidate>* candidates) const;
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700265 Port* GetBestTurnPortForNetwork(const std::string& network_name) const;
266 // Returns true if at least one TURN port is pruned.
267 bool PruneTurnPorts(Port* newly_pairable_turn_port);
268
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000269 BasicPortAllocator* allocator_;
270 rtc::Thread* network_thread_;
kwiberg3ec46792016-04-27 07:22:53 -0700271 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000272 rtc::PacketSocketFactory* socket_factory_;
273 bool allocation_started_;
274 bool network_manager_started_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000275 bool allocation_sequences_created_;
276 std::vector<PortConfiguration*> configs_;
277 std::vector<AllocationSequence*> sequences_;
278 std::vector<PortData> ports_;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700279 uint32_t candidate_filter_ = CF_ALL;
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700280 // Whether to prune low-priority ports, taken from the port allocator.
281 bool prune_turn_ports_;
Honghai Zhangd8f6fc42016-07-01 17:31:12 -0700282 SessionState state_ = SessionState::CLEARED;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000283
284 friend class AllocationSequence;
285};
286
287// Records configuration information useful in creating ports.
deadbeef653b8e02015-11-11 12:55:10 -0800288// TODO(deadbeef): Rename "relay" to "turn_server" in this struct.
Mirko Bonadei3b56ee72018-10-15 17:15:12 +0200289struct RTC_EXPORT PortConfiguration : public rtc::MessageData {
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000290 // TODO(jiayl): remove |stun_address| when Chrome is updated.
291 rtc::SocketAddress stun_address;
292 ServerAddresses stun_servers;
293 std::string username;
294 std::string password;
295
296 typedef std::vector<RelayServerConfig> RelayList;
297 RelayList relays;
298
299 // TODO(jiayl): remove this ctor when Chrome is updated.
300 PortConfiguration(const rtc::SocketAddress& stun_address,
301 const std::string& username,
302 const std::string& password);
303
304 PortConfiguration(const ServerAddresses& stun_servers,
305 const std::string& username,
306 const std::string& password);
307
Steve Anton7995d8c2017-10-30 16:23:38 -0700308 ~PortConfiguration() override;
309
deadbeefc5d0d952015-07-16 10:22:21 -0700310 // Returns addresses of both the explicitly configured STUN servers,
311 // and TURN servers that should be used as STUN servers.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000312 ServerAddresses StunServers();
313
314 // Adds another relay server, with the given ports and modifier, to the list.
315 void AddRelay(const RelayServerConfig& config);
316
317 // Determines whether the given relay server supports the given protocol.
318 bool SupportsProtocol(const RelayServerConfig& relay,
319 ProtocolType type) const;
320 bool SupportsProtocol(RelayType turn_type, ProtocolType type) const;
321 // Helper method returns the server addresses for the matching RelayType and
322 // Protocol type.
Yves Gerey665174f2018-06-19 15:03:05 +0200323 ServerAddresses GetRelayServerAddresses(RelayType turn_type,
324 ProtocolType type) const;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000325};
326
honghaizf421bdc2015-07-17 16:21:55 -0700327class UDPPort;
328class TurnPort;
329
330// Performs the allocation of ports, in a sequenced (timed) manner, for a given
331// network and IP address.
332class AllocationSequence : public rtc::MessageHandler,
333 public sigslot::has_slots<> {
334 public:
335 enum State {
336 kInit, // Initial state.
337 kRunning, // Started allocating ports.
338 kStopped, // Stopped from running.
339 kCompleted, // All ports are allocated.
340
341 // kInit --> kRunning --> {kCompleted|kStopped}
342 };
343 AllocationSequence(BasicPortAllocatorSession* session,
344 rtc::Network* network,
345 PortConfiguration* config,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200346 uint32_t flags);
Steve Anton7995d8c2017-10-30 16:23:38 -0700347 ~AllocationSequence() override;
Honghai Zhang5048f572016-08-23 15:47:33 -0700348 void Init();
honghaizf421bdc2015-07-17 16:21:55 -0700349 void Clear();
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700350 void OnNetworkFailed();
honghaizf421bdc2015-07-17 16:21:55 -0700351
352 State state() const { return state_; }
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700353 rtc::Network* network() const { return network_; }
354
355 bool network_failed() const { return network_failed_; }
356 void set_network_failed() { network_failed_ = true; }
honghaizf421bdc2015-07-17 16:21:55 -0700357
358 // Disables the phases for a new sequence that this one already covers for an
359 // equivalent network setup.
360 void DisableEquivalentPhases(rtc::Network* network,
361 PortConfiguration* config,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200362 uint32_t* flags);
honghaizf421bdc2015-07-17 16:21:55 -0700363
364 // Starts and stops the sequence. When started, it will continue allocating
365 // new ports on its own timed schedule.
366 void Start();
367 void Stop();
368
369 // MessageHandler
Steve Anton7995d8c2017-10-30 16:23:38 -0700370 void OnMessage(rtc::Message* msg) override;
honghaizf421bdc2015-07-17 16:21:55 -0700371
honghaizf421bdc2015-07-17 16:21:55 -0700372 // Signal from AllocationSequence, when it's done with allocating ports.
373 // This signal is useful, when port allocation fails which doesn't result
374 // in any candidates. Using this signal BasicPortAllocatorSession can send
375 // its candidate discovery conclusion signal. Without this signal,
376 // BasicPortAllocatorSession doesn't have any event to trigger signal. This
377 // can also be achieved by starting timer in BPAS.
378 sigslot::signal1<AllocationSequence*> SignalPortAllocationComplete;
379
380 protected:
381 // For testing.
382 void CreateTurnPort(const RelayServerConfig& config);
383
384 private:
385 typedef std::vector<ProtocolType> ProtocolList;
386
Peter Boström0c4e06b2015-10-07 12:23:21 +0200387 bool IsFlagSet(uint32_t flag) { return ((flags_ & flag) != 0); }
honghaizf421bdc2015-07-17 16:21:55 -0700388 void CreateUDPPorts();
389 void CreateTCPPorts();
390 void CreateStunPorts();
391 void CreateRelayPorts();
392 void CreateGturnPort(const RelayServerConfig& config);
393
394 void OnReadPacket(rtc::AsyncPacketSocket* socket,
395 const char* data,
396 size_t size,
397 const rtc::SocketAddress& remote_addr,
Niels Möllere6933812018-11-05 13:01:41 +0100398 const int64_t& packet_time_us);
honghaizf421bdc2015-07-17 16:21:55 -0700399
400 void OnPortDestroyed(PortInterface* port);
401
402 BasicPortAllocatorSession* session_;
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700403 bool network_failed_ = false;
honghaizf421bdc2015-07-17 16:21:55 -0700404 rtc::Network* network_;
deadbeef5c3c1042017-08-04 15:01:57 -0700405 // Compared with the new best IP in DisableEquivalentPhases.
406 rtc::IPAddress previous_best_ip_;
honghaizf421bdc2015-07-17 16:21:55 -0700407 PortConfiguration* config_;
408 State state_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200409 uint32_t flags_;
honghaizf421bdc2015-07-17 16:21:55 -0700410 ProtocolList protocols_;
kwiberg3ec46792016-04-27 07:22:53 -0700411 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_;
honghaizf421bdc2015-07-17 16:21:55 -0700412 // There will be only one udp port per AllocationSequence.
413 UDPPort* udp_port_;
Jonas Oreland202994c2017-12-18 12:10:43 +0100414 std::vector<Port*> relay_ports_;
honghaizf421bdc2015-07-17 16:21:55 -0700415 int phase_;
416};
417
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000418} // namespace cricket
419
Steve Anton10542f22019-01-11 09:11:00 -0800420#endif // P2P_CLIENT_BASIC_PORT_ALLOCATOR_H_