blob: 2105172e4e96bbf358f4e1fed4588edbb45e4e5c [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef P2P_CLIENT_BASICPORTALLOCATOR_H_
12#define P2P_CLIENT_BASICPORTALLOCATOR_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
Jonas Orelandbdcee282017-10-10 14:01:40 +020018#include "api/turncustomizer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "p2p/base/portallocator.h"
Jonas Oreland202994c2017-12-18 12:10:43 +010020#include "p2p/client/relayportfactoryinterface.h"
Yves Gerey665174f2018-06-19 15:03:05 +020021#include "p2p/client/turnportfactory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "rtc_base/checks.h"
23#include "rtc_base/messagequeue.h"
24#include "rtc_base/network.h"
25#include "rtc_base/thread.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000026
27namespace cricket {
28
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000029class BasicPortAllocator : public PortAllocator {
30 public:
Jonas Oreland202994c2017-12-18 12:10:43 +010031 // note: The (optional) relay_port_factory is owned by caller
32 // and must have a life time that exceeds that of BasicPortAllocator.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000033 BasicPortAllocator(rtc::NetworkManager* network_manager,
Jonas Orelandbdcee282017-10-10 14:01:40 +020034 rtc::PacketSocketFactory* socket_factory,
Jonas Oreland202994c2017-12-18 12:10:43 +010035 webrtc::TurnCustomizer* customizer = nullptr,
36 RelayPortFactoryInterface* relay_port_factory = nullptr);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000037 explicit BasicPortAllocator(rtc::NetworkManager* network_manager);
38 BasicPortAllocator(rtc::NetworkManager* network_manager,
39 rtc::PacketSocketFactory* socket_factory,
40 const ServerAddresses& stun_servers);
41 BasicPortAllocator(rtc::NetworkManager* network_manager,
42 const ServerAddresses& stun_servers,
Jonas Oreland202994c2017-12-18 12:10:43 +010043 const rtc::SocketAddress& relay_address_udp,
44 const rtc::SocketAddress& relay_address_tcp,
45 const rtc::SocketAddress& relay_address_ssl);
Steve Anton7995d8c2017-10-30 16:23:38 -070046 ~BasicPortAllocator() override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000047
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -080048 // Set to kDefaultNetworkIgnoreMask by default.
Steve Anton7995d8c2017-10-30 16:23:38 -070049 void SetNetworkIgnoreMask(int network_ignore_mask) override;
Qingsi Wanga2d60672018-04-11 16:57:45 -070050 int network_ignore_mask() const {
51 CheckRunOnValidThreadIfInitialized();
52 return network_ignore_mask_;
53 }
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -080054
Qingsi Wanga2d60672018-04-11 16:57:45 -070055 rtc::NetworkManager* network_manager() const {
56 CheckRunOnValidThreadIfInitialized();
57 return network_manager_;
58 }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000059
60 // If socket_factory() is set to NULL each PortAllocatorSession
61 // creates its own socket factory.
Qingsi Wanga2d60672018-04-11 16:57:45 -070062 rtc::PacketSocketFactory* socket_factory() {
63 CheckRunOnValidThreadIfInitialized();
64 return socket_factory_;
65 }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000066
deadbeef653b8e02015-11-11 12:55:10 -080067 PortAllocatorSession* CreateSessionInternal(
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000068 const std::string& content_name,
69 int component,
70 const std::string& ice_ufrag,
deadbeef653b8e02015-11-11 12:55:10 -080071 const std::string& ice_pwd) override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000072
Taylor Brandstettera1c30352016-05-13 08:15:11 -070073 // Convenience method that adds a TURN server to the configuration.
74 void AddTurnServer(const RelayServerConfig& turn_server);
75
Jonas Oreland202994c2017-12-18 12:10:43 +010076 RelayPortFactoryInterface* relay_port_factory() {
Qingsi Wanga2d60672018-04-11 16:57:45 -070077 CheckRunOnValidThreadIfInitialized();
Jonas Oreland202994c2017-12-18 12:10:43 +010078 return relay_port_factory_;
79 }
80
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000081 private:
82 void Construct();
83
Honghai Zhangd93f50c2016-10-05 11:47:22 -070084 void OnIceRegathering(PortAllocatorSession* session,
85 IceRegatheringReason reason);
86
Jonas Oreland202994c2017-12-18 12:10:43 +010087 // This function makes sure that relay_port_factory_ is set properly.
88 void InitRelayPortFactory(RelayPortFactoryInterface* relay_port_factory);
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
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000113class BasicPortAllocatorSession : public PortAllocatorSession,
114 public rtc::MessageHandler {
115 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
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700127 void SetCandidateFilter(uint32_t filter) override;
deadbeef653b8e02015-11-11 12:55:10 -0800128 void StartGettingPorts() override;
129 void StopGettingPorts() override;
130 void ClearGettingPorts() override;
Steve Anton7995d8c2017-10-30 16:23:38 -0700131 bool IsGettingPorts() override;
132 bool IsCleared() const override;
133 bool IsStopped() const override;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700134 // These will all be cricket::Ports.
135 std::vector<PortInterface*> ReadyPorts() const override;
136 std::vector<Candidate> ReadyCandidates() const override;
137 bool CandidatesAllocationDone() const override;
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700138 void RegatherOnFailedNetworks() override;
Steve Anton300bf8e2017-07-14 10:13:10 -0700139 void RegatherOnAllNetworks() override;
Qingsi Wangdb53f8e2018-02-20 14:45:49 -0800140 void SetStunKeepaliveIntervalForReadyPorts(
Danil Chapovalov00c71832018-06-15 15:58:38 +0200141 const absl::optional<int>& stun_keepalive_interval) override;
Honghai Zhanga74363c2016-07-28 18:06:15 -0700142 void PruneAllPorts() override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000143
144 protected:
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700145 void UpdateIceParametersInternal() override;
146
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000147 // Starts the process of getting the port configurations.
148 virtual void GetPortConfigurations();
149
150 // Adds a port configuration that is now ready. Once we have one for each
151 // network (or a timeout occurs), we will start allocating ports.
152 virtual void ConfigReady(PortConfiguration* config);
153
154 // MessageHandler. Can be overriden if message IDs do not conflict.
deadbeef653b8e02015-11-11 12:55:10 -0800155 void OnMessage(rtc::Message* message) override;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000156
157 private:
158 class PortData {
159 public:
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700160 PortData() {}
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000161 PortData(Port* port, AllocationSequence* seq)
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700162 : port_(port), sequence_(seq) {}
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000163
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700164 Port* port() const { return port_; }
165 AllocationSequence* sequence() const { return sequence_; }
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700166 bool has_pairable_candidate() const { return has_pairable_candidate_; }
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700167 bool complete() const { return state_ == STATE_COMPLETE; }
168 bool error() const { return state_ == STATE_ERROR; }
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700169 bool pruned() const { return state_ == STATE_PRUNED; }
170 bool inprogress() const { return state_ == STATE_INPROGRESS; }
Mirko Bonadeib89ac622018-08-22 08:26:19 +0000171 // True if this port has been fired in SignalPortReady. This may be false
172 // even if ready() is true if the port was bound to the "any" address; see
173 // comment above SignalAnyAddressPortsAndCandidatesReadyIfNotRedundant.
174 bool signaled() const { return signaled_; }
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700175 // Returns true if this port is ready to be used.
176 bool ready() const {
177 return has_pairable_candidate_ && state_ != STATE_ERROR &&
178 state_ != STATE_PRUNED;
179 }
Honghai Zhangc67e0f52016-09-19 16:57:37 -0700180 // Sets the state to "PRUNED" and prunes the Port.
181 void Prune() {
182 state_ = STATE_PRUNED;
183 if (port()) {
184 port()->Prune();
185 }
186 }
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700187 void set_has_pairable_candidate(bool has_pairable_candidate) {
188 if (has_pairable_candidate) {
nisseede5da42017-01-12 05:15:36 -0800189 RTC_DCHECK(state_ == STATE_INPROGRESS);
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700190 }
191 has_pairable_candidate_ = has_pairable_candidate;
192 }
Yves Gerey665174f2018-06-19 15:03:05 +0200193 void set_complete() { state_ = STATE_COMPLETE; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000194 void set_error() {
nisseede5da42017-01-12 05:15:36 -0800195 RTC_DCHECK(state_ == STATE_INPROGRESS);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000196 state_ = STATE_ERROR;
197 }
Mirko Bonadeib89ac622018-08-22 08:26:19 +0000198 void set_signaled() { signaled_ = true; }
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000199
200 private:
201 enum State {
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700202 STATE_INPROGRESS, // Still gathering candidates.
203 STATE_COMPLETE, // All candidates allocated and ready for process.
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700204 STATE_ERROR, // Error in gathering candidates.
205 STATE_PRUNED // Pruned by higher priority ports on the same network
206 // interface. Only TURN ports may be pruned.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000207 };
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700208 Port* port_ = nullptr;
209 AllocationSequence* sequence_ = nullptr;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700210 bool has_pairable_candidate_ = false;
Mirko Bonadeib89ac622018-08-22 08:26:19 +0000211 bool signaled_ = false;
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700212 State state_ = STATE_INPROGRESS;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000213 };
214
215 void OnConfigReady(PortConfiguration* config);
216 void OnConfigStop();
217 void AllocatePorts();
218 void OnAllocate();
Steve Anton300bf8e2017-07-14 10:13:10 -0700219 void DoAllocate(bool disable_equivalent_phases);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000220 void OnNetworksChanged();
221 void OnAllocationSequenceObjectsCreated();
222 void DisableEquivalentPhases(rtc::Network* network,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200223 PortConfiguration* config,
224 uint32_t* flags);
Yves Gerey665174f2018-06-19 15:03:05 +0200225 void AddAllocatedPort(Port* port,
226 AllocationSequence* seq,
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000227 bool prepare_address);
228 void OnCandidateReady(Port* port, const Candidate& c);
229 void OnPortComplete(Port* port);
230 void OnPortError(Port* port);
231 void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto);
232 void OnPortDestroyed(PortInterface* port);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000233 void OnPortAllocationComplete(AllocationSequence* seq);
234 PortData* FindPort(Port* port);
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700235 std::vector<rtc::Network*> GetNetworks();
236 std::vector<rtc::Network*> GetFailedNetworks();
Steve Anton300bf8e2017-07-14 10:13:10 -0700237 void Regather(const std::vector<rtc::Network*>& networks,
238 bool disable_equivalent_phases,
239 IceRegatheringReason reason);
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000240
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700241 bool CheckCandidateFilter(const Candidate& c) const;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700242 bool CandidatePairable(const Candidate& c, const Port* port) const;
243 // Clear the related address according to the flags and candidate filter
244 // in order to avoid leaking any information.
245 Candidate SanitizeRelatedAddress(const Candidate& c) const;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000246
Honghai Zhangc67e0f52016-09-19 16:57:37 -0700247 std::vector<PortData*> GetUnprunedPorts(
248 const std::vector<rtc::Network*>& networks);
Mirko Bonadeib89ac622018-08-22 08:26:19 +0000249 // Prunes ports and removes candidates gathered from these ports locally. The
250 // list of the removed candidates are returned.
251 std::vector<Candidate> PrunePorts(
252 const std::vector<PortData*>& port_data_list);
Honghai Zhangc67e0f52016-09-19 16:57:37 -0700253 // Prunes ports and signal the remote side to remove the candidates that
254 // were previously signaled from these ports.
Mirko Bonadeib89ac622018-08-22 08:26:19 +0000255 void PrunePortsAndSignalCandidatesRemoval(
Honghai Zhangc67e0f52016-09-19 16:57:37 -0700256 const std::vector<PortData*>& port_data_list);
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700257 // Gets filtered and sanitized candidates generated from a port and
258 // append to |candidates|.
259 void GetCandidatesFromPort(const PortData& data,
260 std::vector<Candidate>* candidates) const;
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700261 Port* GetBestTurnPortForNetwork(const std::string& network_name) const;
262 // Returns true if at least one TURN port is pruned.
263 bool PruneTurnPorts(Port* newly_pairable_turn_port);
Mirko Bonadeib89ac622018-08-22 08:26:19 +0000264 // Fires signals related to aggregate status update in the allocation,
265 // including candidates allocation done, and any address ports and their
266 // candidates ready.
267 void FireAllocationStatusSignalsIfNeeded();
268 // TODO(qingsi): Rename "any address" to "wildcard address" in p2p/.
269 void SignalAnyAddressPortsAndCandidatesReadyIfNotRedundant();
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700270
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000271 BasicPortAllocator* allocator_;
272 rtc::Thread* network_thread_;
kwiberg3ec46792016-04-27 07:22:53 -0700273 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000274 rtc::PacketSocketFactory* socket_factory_;
275 bool allocation_started_;
276 bool network_manager_started_;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000277 bool allocation_sequences_created_;
278 std::vector<PortConfiguration*> configs_;
279 std::vector<AllocationSequence*> sequences_;
280 std::vector<PortData> ports_;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -0700281 uint32_t candidate_filter_ = CF_ALL;
Honghai Zhangb9e7b4a2016-06-30 20:52:02 -0700282 // Whether to prune low-priority ports, taken from the port allocator.
283 bool prune_turn_ports_;
Honghai Zhangd8f6fc42016-07-01 17:31:12 -0700284 SessionState state_ = SessionState::CLEARED;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000285
286 friend class AllocationSequence;
287};
288
289// Records configuration information useful in creating ports.
deadbeef653b8e02015-11-11 12:55:10 -0800290// TODO(deadbeef): Rename "relay" to "turn_server" in this struct.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000291struct PortConfiguration : public rtc::MessageData {
292 // TODO(jiayl): remove |stun_address| when Chrome is updated.
293 rtc::SocketAddress stun_address;
294 ServerAddresses stun_servers;
295 std::string username;
296 std::string password;
297
298 typedef std::vector<RelayServerConfig> RelayList;
299 RelayList relays;
300
301 // TODO(jiayl): remove this ctor when Chrome is updated.
302 PortConfiguration(const rtc::SocketAddress& stun_address,
303 const std::string& username,
304 const std::string& password);
305
306 PortConfiguration(const ServerAddresses& stun_servers,
307 const std::string& username,
308 const std::string& password);
309
Steve Anton7995d8c2017-10-30 16:23:38 -0700310 ~PortConfiguration() override;
311
deadbeefc5d0d952015-07-16 10:22:21 -0700312 // Returns addresses of both the explicitly configured STUN servers,
313 // and TURN servers that should be used as STUN servers.
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000314 ServerAddresses StunServers();
315
316 // Adds another relay server, with the given ports and modifier, to the list.
317 void AddRelay(const RelayServerConfig& config);
318
319 // Determines whether the given relay server supports the given protocol.
320 bool SupportsProtocol(const RelayServerConfig& relay,
321 ProtocolType type) const;
322 bool SupportsProtocol(RelayType turn_type, ProtocolType type) const;
323 // Helper method returns the server addresses for the matching RelayType and
324 // Protocol type.
Yves Gerey665174f2018-06-19 15:03:05 +0200325 ServerAddresses GetRelayServerAddresses(RelayType turn_type,
326 ProtocolType type) const;
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000327};
328
honghaizf421bdc2015-07-17 16:21:55 -0700329class UDPPort;
330class TurnPort;
331
332// Performs the allocation of ports, in a sequenced (timed) manner, for a given
333// network and IP address.
334class AllocationSequence : public rtc::MessageHandler,
335 public sigslot::has_slots<> {
336 public:
337 enum State {
338 kInit, // Initial state.
339 kRunning, // Started allocating ports.
340 kStopped, // Stopped from running.
341 kCompleted, // All ports are allocated.
342
343 // kInit --> kRunning --> {kCompleted|kStopped}
344 };
345 AllocationSequence(BasicPortAllocatorSession* session,
346 rtc::Network* network,
347 PortConfiguration* config,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200348 uint32_t flags);
Steve Anton7995d8c2017-10-30 16:23:38 -0700349 ~AllocationSequence() override;
Honghai Zhang5048f572016-08-23 15:47:33 -0700350 void Init();
honghaizf421bdc2015-07-17 16:21:55 -0700351 void Clear();
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700352 void OnNetworkFailed();
honghaizf421bdc2015-07-17 16:21:55 -0700353
354 State state() const { return state_; }
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700355 rtc::Network* network() const { return network_; }
356
357 bool network_failed() const { return network_failed_; }
358 void set_network_failed() { network_failed_ = true; }
honghaizf421bdc2015-07-17 16:21:55 -0700359
360 // Disables the phases for a new sequence that this one already covers for an
361 // equivalent network setup.
362 void DisableEquivalentPhases(rtc::Network* network,
363 PortConfiguration* config,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200364 uint32_t* flags);
honghaizf421bdc2015-07-17 16:21:55 -0700365
366 // Starts and stops the sequence. When started, it will continue allocating
367 // new ports on its own timed schedule.
368 void Start();
369 void Stop();
370
371 // MessageHandler
Steve Anton7995d8c2017-10-30 16:23:38 -0700372 void OnMessage(rtc::Message* msg) override;
honghaizf421bdc2015-07-17 16:21:55 -0700373
honghaizf421bdc2015-07-17 16:21:55 -0700374 // Signal from AllocationSequence, when it's done with allocating ports.
375 // This signal is useful, when port allocation fails which doesn't result
376 // in any candidates. Using this signal BasicPortAllocatorSession can send
377 // its candidate discovery conclusion signal. Without this signal,
378 // BasicPortAllocatorSession doesn't have any event to trigger signal. This
379 // can also be achieved by starting timer in BPAS.
380 sigslot::signal1<AllocationSequence*> SignalPortAllocationComplete;
381
382 protected:
383 // For testing.
384 void CreateTurnPort(const RelayServerConfig& config);
385
386 private:
387 typedef std::vector<ProtocolType> ProtocolList;
388
Peter Boström0c4e06b2015-10-07 12:23:21 +0200389 bool IsFlagSet(uint32_t flag) { return ((flags_ & flag) != 0); }
honghaizf421bdc2015-07-17 16:21:55 -0700390 void CreateUDPPorts();
391 void CreateTCPPorts();
392 void CreateStunPorts();
393 void CreateRelayPorts();
394 void CreateGturnPort(const RelayServerConfig& config);
395
396 void OnReadPacket(rtc::AsyncPacketSocket* socket,
397 const char* data,
398 size_t size,
399 const rtc::SocketAddress& remote_addr,
400 const rtc::PacketTime& packet_time);
401
402 void OnPortDestroyed(PortInterface* port);
403
404 BasicPortAllocatorSession* session_;
Honghai Zhang5622c5e2016-07-01 13:59:29 -0700405 bool network_failed_ = false;
honghaizf421bdc2015-07-17 16:21:55 -0700406 rtc::Network* network_;
deadbeef5c3c1042017-08-04 15:01:57 -0700407 // Compared with the new best IP in DisableEquivalentPhases.
408 rtc::IPAddress previous_best_ip_;
honghaizf421bdc2015-07-17 16:21:55 -0700409 PortConfiguration* config_;
410 State state_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200411 uint32_t flags_;
honghaizf421bdc2015-07-17 16:21:55 -0700412 ProtocolList protocols_;
kwiberg3ec46792016-04-27 07:22:53 -0700413 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_;
honghaizf421bdc2015-07-17 16:21:55 -0700414 // There will be only one udp port per AllocationSequence.
415 UDPPort* udp_port_;
Jonas Oreland202994c2017-12-18 12:10:43 +0100416 std::vector<Port*> relay_ports_;
honghaizf421bdc2015-07-17 16:21:55 -0700417 int phase_;
418};
419
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +0000420} // namespace cricket
421
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200422#endif // P2P_CLIENT_BASICPORTALLOCATOR_H_