henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [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 | |
| 11 | #ifndef WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ |
| 12 | #define WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ |
| 13 | |
kwiberg | 3ec4679 | 2016-04-27 07:22:53 -0700 | [diff] [blame] | 14 | #include <memory> |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 18 | #include "webrtc/p2p/base/portallocator.h" |
| 19 | #include "webrtc/base/messagequeue.h" |
| 20 | #include "webrtc/base/network.h" |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 21 | #include "webrtc/base/thread.h" |
| 22 | |
| 23 | namespace cricket { |
| 24 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 25 | class BasicPortAllocator : public PortAllocator { |
| 26 | public: |
| 27 | BasicPortAllocator(rtc::NetworkManager* network_manager, |
| 28 | rtc::PacketSocketFactory* socket_factory); |
| 29 | explicit BasicPortAllocator(rtc::NetworkManager* network_manager); |
| 30 | BasicPortAllocator(rtc::NetworkManager* network_manager, |
| 31 | rtc::PacketSocketFactory* socket_factory, |
| 32 | const ServerAddresses& stun_servers); |
| 33 | BasicPortAllocator(rtc::NetworkManager* network_manager, |
| 34 | const ServerAddresses& stun_servers, |
| 35 | const rtc::SocketAddress& relay_server_udp, |
| 36 | const rtc::SocketAddress& relay_server_tcp, |
| 37 | const rtc::SocketAddress& relay_server_ssl); |
| 38 | virtual ~BasicPortAllocator(); |
| 39 | |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 40 | // Set to kDefaultNetworkIgnoreMask by default. |
| 41 | void SetNetworkIgnoreMask(int network_ignore_mask) override { |
| 42 | // TODO(phoglund): implement support for other types than loopback. |
| 43 | // See https://code.google.com/p/webrtc/issues/detail?id=4288. |
| 44 | // Then remove set_network_ignore_list from NetworkManager. |
| 45 | network_ignore_mask_ = network_ignore_mask; |
| 46 | } |
| 47 | |
| 48 | int network_ignore_mask() const { return network_ignore_mask_; } |
| 49 | |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 50 | rtc::NetworkManager* network_manager() const { return network_manager_; } |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 51 | |
| 52 | // If socket_factory() is set to NULL each PortAllocatorSession |
| 53 | // creates its own socket factory. |
| 54 | rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } |
| 55 | |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 56 | PortAllocatorSession* CreateSessionInternal( |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 57 | const std::string& content_name, |
| 58 | int component, |
| 59 | const std::string& ice_ufrag, |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 60 | const std::string& ice_pwd) override; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 61 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 62 | // Convenience method that adds a TURN server to the configuration. |
| 63 | void AddTurnServer(const RelayServerConfig& turn_server); |
| 64 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 65 | private: |
| 66 | void Construct(); |
| 67 | |
| 68 | rtc::NetworkManager* network_manager_; |
| 69 | rtc::PacketSocketFactory* socket_factory_; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 70 | bool allow_tcp_listen_; |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 71 | int network_ignore_mask_ = rtc::kDefaultNetworkIgnoreMask; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | struct PortConfiguration; |
| 75 | class AllocationSequence; |
| 76 | |
Honghai Zhang | d8f6fc4 | 2016-07-01 17:31:12 -0700 | [diff] [blame] | 77 | enum class SessionState { |
| 78 | GATHERING, // Actively allocating ports and gathering candidates. |
| 79 | CLEARED, // Current allocation process has been stopped but may start |
| 80 | // new ones. |
| 81 | STOPPED // This session has completely stopped, no new allocation |
| 82 | // process will be started. |
| 83 | }; |
| 84 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 85 | class BasicPortAllocatorSession : public PortAllocatorSession, |
| 86 | public rtc::MessageHandler { |
| 87 | public: |
| 88 | BasicPortAllocatorSession(BasicPortAllocator* allocator, |
| 89 | const std::string& content_name, |
| 90 | int component, |
| 91 | const std::string& ice_ufrag, |
| 92 | const std::string& ice_pwd); |
| 93 | ~BasicPortAllocatorSession(); |
| 94 | |
| 95 | virtual BasicPortAllocator* allocator() { return allocator_; } |
| 96 | rtc::Thread* network_thread() { return network_thread_; } |
| 97 | rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } |
| 98 | |
Taylor Brandstetter | 417eebe | 2016-05-23 16:02:19 -0700 | [diff] [blame] | 99 | void SetCandidateFilter(uint32_t filter) override; |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 100 | void StartGettingPorts() override; |
| 101 | void StopGettingPorts() override; |
| 102 | void ClearGettingPorts() override; |
Honghai Zhang | d8f6fc4 | 2016-07-01 17:31:12 -0700 | [diff] [blame] | 103 | bool IsGettingPorts() override { return state_ == SessionState::GATHERING; } |
| 104 | bool IsCleared() const override { return state_ == SessionState::CLEARED; } |
| 105 | bool IsStopped() const override { return state_ == SessionState::STOPPED; } |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 106 | // These will all be cricket::Ports. |
| 107 | std::vector<PortInterface*> ReadyPorts() const override; |
| 108 | std::vector<Candidate> ReadyCandidates() const override; |
| 109 | bool CandidatesAllocationDone() const override; |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 110 | void RegatherOnFailedNetworks() override; |
Honghai Zhang | a74363c | 2016-07-28 18:06:15 -0700 | [diff] [blame] | 111 | void PruneAllPorts() override; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 112 | |
| 113 | protected: |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 114 | void UpdateIceParametersInternal() override; |
| 115 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 116 | // Starts the process of getting the port configurations. |
| 117 | virtual void GetPortConfigurations(); |
| 118 | |
| 119 | // Adds a port configuration that is now ready. Once we have one for each |
| 120 | // network (or a timeout occurs), we will start allocating ports. |
| 121 | virtual void ConfigReady(PortConfiguration* config); |
| 122 | |
| 123 | // MessageHandler. Can be overriden if message IDs do not conflict. |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 124 | void OnMessage(rtc::Message* message) override; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 125 | |
| 126 | private: |
| 127 | class PortData { |
| 128 | public: |
Taylor Brandstetter | 417eebe | 2016-05-23 16:02:19 -0700 | [diff] [blame] | 129 | PortData() {} |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 130 | PortData(Port* port, AllocationSequence* seq) |
Taylor Brandstetter | 417eebe | 2016-05-23 16:02:19 -0700 | [diff] [blame] | 131 | : port_(port), sequence_(seq) {} |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 132 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 133 | Port* port() const { return port_; } |
| 134 | AllocationSequence* sequence() const { return sequence_; } |
Taylor Brandstetter | 417eebe | 2016-05-23 16:02:19 -0700 | [diff] [blame] | 135 | bool has_pairable_candidate() const { return has_pairable_candidate_; } |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 136 | bool complete() const { return state_ == STATE_COMPLETE; } |
| 137 | bool error() const { return state_ == STATE_ERROR; } |
Honghai Zhang | b9e7b4a | 2016-06-30 20:52:02 -0700 | [diff] [blame] | 138 | bool pruned() const { return state_ == STATE_PRUNED; } |
| 139 | bool inprogress() const { return state_ == STATE_INPROGRESS; } |
| 140 | // Returns true if this port is ready to be used. |
| 141 | bool ready() const { |
| 142 | return has_pairable_candidate_ && state_ != STATE_ERROR && |
| 143 | state_ != STATE_PRUNED; |
| 144 | } |
Honghai Zhang | c67e0f5 | 2016-09-19 16:57:37 -0700 | [diff] [blame^] | 145 | // Sets the state to "PRUNED" and prunes the Port. |
| 146 | void Prune() { |
| 147 | state_ = STATE_PRUNED; |
| 148 | if (port()) { |
| 149 | port()->Prune(); |
| 150 | } |
| 151 | } |
Taylor Brandstetter | 417eebe | 2016-05-23 16:02:19 -0700 | [diff] [blame] | 152 | void set_has_pairable_candidate(bool has_pairable_candidate) { |
| 153 | if (has_pairable_candidate) { |
| 154 | ASSERT(state_ == STATE_INPROGRESS); |
| 155 | } |
| 156 | has_pairable_candidate_ = has_pairable_candidate; |
| 157 | } |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 158 | void set_complete() { |
| 159 | state_ = STATE_COMPLETE; |
| 160 | } |
| 161 | void set_error() { |
Taylor Brandstetter | 417eebe | 2016-05-23 16:02:19 -0700 | [diff] [blame] | 162 | ASSERT(state_ == STATE_INPROGRESS); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 163 | state_ = STATE_ERROR; |
| 164 | } |
| 165 | |
| 166 | private: |
| 167 | enum State { |
Taylor Brandstetter | 417eebe | 2016-05-23 16:02:19 -0700 | [diff] [blame] | 168 | STATE_INPROGRESS, // Still gathering candidates. |
| 169 | STATE_COMPLETE, // All candidates allocated and ready for process. |
Honghai Zhang | b9e7b4a | 2016-06-30 20:52:02 -0700 | [diff] [blame] | 170 | STATE_ERROR, // Error in gathering candidates. |
| 171 | STATE_PRUNED // Pruned by higher priority ports on the same network |
| 172 | // interface. Only TURN ports may be pruned. |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 173 | }; |
Taylor Brandstetter | 417eebe | 2016-05-23 16:02:19 -0700 | [diff] [blame] | 174 | Port* port_ = nullptr; |
| 175 | AllocationSequence* sequence_ = nullptr; |
Taylor Brandstetter | 417eebe | 2016-05-23 16:02:19 -0700 | [diff] [blame] | 176 | bool has_pairable_candidate_ = false; |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 177 | State state_ = STATE_INPROGRESS; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | void OnConfigReady(PortConfiguration* config); |
| 181 | void OnConfigStop(); |
| 182 | void AllocatePorts(); |
| 183 | void OnAllocate(); |
| 184 | void DoAllocate(); |
| 185 | void OnNetworksChanged(); |
| 186 | void OnAllocationSequenceObjectsCreated(); |
| 187 | void DisableEquivalentPhases(rtc::Network* network, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 188 | PortConfiguration* config, |
| 189 | uint32_t* flags); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 190 | void AddAllocatedPort(Port* port, AllocationSequence* seq, |
| 191 | bool prepare_address); |
| 192 | void OnCandidateReady(Port* port, const Candidate& c); |
| 193 | void OnPortComplete(Port* port); |
| 194 | void OnPortError(Port* port); |
| 195 | void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto); |
| 196 | void OnPortDestroyed(PortInterface* port); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 197 | void MaybeSignalCandidatesAllocationDone(); |
| 198 | void OnPortAllocationComplete(AllocationSequence* seq); |
| 199 | PortData* FindPort(Port* port); |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 200 | std::vector<rtc::Network*> GetNetworks(); |
| 201 | std::vector<rtc::Network*> GetFailedNetworks(); |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 202 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 203 | bool CheckCandidateFilter(const Candidate& c) const; |
Taylor Brandstetter | 417eebe | 2016-05-23 16:02:19 -0700 | [diff] [blame] | 204 | bool CandidatePairable(const Candidate& c, const Port* port) const; |
| 205 | // Clear the related address according to the flags and candidate filter |
| 206 | // in order to avoid leaking any information. |
| 207 | Candidate SanitizeRelatedAddress(const Candidate& c) const; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 208 | |
Honghai Zhang | c67e0f5 | 2016-09-19 16:57:37 -0700 | [diff] [blame^] | 209 | std::vector<PortData*> GetUnprunedPorts( |
| 210 | const std::vector<rtc::Network*>& networks); |
| 211 | // Prunes ports and signal the remote side to remove the candidates that |
| 212 | // were previously signaled from these ports. |
| 213 | void PrunePortsAndRemoveCandidates( |
| 214 | const std::vector<PortData*>& port_data_list); |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 215 | // Gets filtered and sanitized candidates generated from a port and |
| 216 | // append to |candidates|. |
| 217 | void GetCandidatesFromPort(const PortData& data, |
| 218 | std::vector<Candidate>* candidates) const; |
Honghai Zhang | b9e7b4a | 2016-06-30 20:52:02 -0700 | [diff] [blame] | 219 | Port* GetBestTurnPortForNetwork(const std::string& network_name) const; |
| 220 | // Returns true if at least one TURN port is pruned. |
| 221 | bool PruneTurnPorts(Port* newly_pairable_turn_port); |
| 222 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 223 | BasicPortAllocator* allocator_; |
| 224 | rtc::Thread* network_thread_; |
kwiberg | 3ec4679 | 2016-04-27 07:22:53 -0700 | [diff] [blame] | 225 | std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 226 | rtc::PacketSocketFactory* socket_factory_; |
| 227 | bool allocation_started_; |
| 228 | bool network_manager_started_; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 229 | bool allocation_sequences_created_; |
| 230 | std::vector<PortConfiguration*> configs_; |
| 231 | std::vector<AllocationSequence*> sequences_; |
| 232 | std::vector<PortData> ports_; |
Taylor Brandstetter | 417eebe | 2016-05-23 16:02:19 -0700 | [diff] [blame] | 233 | uint32_t candidate_filter_ = CF_ALL; |
Honghai Zhang | b9e7b4a | 2016-06-30 20:52:02 -0700 | [diff] [blame] | 234 | // Whether to prune low-priority ports, taken from the port allocator. |
| 235 | bool prune_turn_ports_; |
Honghai Zhang | d8f6fc4 | 2016-07-01 17:31:12 -0700 | [diff] [blame] | 236 | SessionState state_ = SessionState::CLEARED; |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 237 | |
| 238 | friend class AllocationSequence; |
| 239 | }; |
| 240 | |
| 241 | // Records configuration information useful in creating ports. |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 242 | // TODO(deadbeef): Rename "relay" to "turn_server" in this struct. |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 243 | struct PortConfiguration : public rtc::MessageData { |
| 244 | // TODO(jiayl): remove |stun_address| when Chrome is updated. |
| 245 | rtc::SocketAddress stun_address; |
| 246 | ServerAddresses stun_servers; |
| 247 | std::string username; |
| 248 | std::string password; |
| 249 | |
| 250 | typedef std::vector<RelayServerConfig> RelayList; |
| 251 | RelayList relays; |
| 252 | |
| 253 | // TODO(jiayl): remove this ctor when Chrome is updated. |
| 254 | PortConfiguration(const rtc::SocketAddress& stun_address, |
| 255 | const std::string& username, |
| 256 | const std::string& password); |
| 257 | |
| 258 | PortConfiguration(const ServerAddresses& stun_servers, |
| 259 | const std::string& username, |
| 260 | const std::string& password); |
| 261 | |
deadbeef | c5d0d95 | 2015-07-16 10:22:21 -0700 | [diff] [blame] | 262 | // Returns addresses of both the explicitly configured STUN servers, |
| 263 | // and TURN servers that should be used as STUN servers. |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 264 | ServerAddresses StunServers(); |
| 265 | |
| 266 | // Adds another relay server, with the given ports and modifier, to the list. |
| 267 | void AddRelay(const RelayServerConfig& config); |
| 268 | |
| 269 | // Determines whether the given relay server supports the given protocol. |
| 270 | bool SupportsProtocol(const RelayServerConfig& relay, |
| 271 | ProtocolType type) const; |
| 272 | bool SupportsProtocol(RelayType turn_type, ProtocolType type) const; |
| 273 | // Helper method returns the server addresses for the matching RelayType and |
| 274 | // Protocol type. |
| 275 | ServerAddresses GetRelayServerAddresses( |
| 276 | RelayType turn_type, ProtocolType type) const; |
| 277 | }; |
| 278 | |
honghaiz | f421bdc | 2015-07-17 16:21:55 -0700 | [diff] [blame] | 279 | class UDPPort; |
| 280 | class TurnPort; |
| 281 | |
| 282 | // Performs the allocation of ports, in a sequenced (timed) manner, for a given |
| 283 | // network and IP address. |
| 284 | class AllocationSequence : public rtc::MessageHandler, |
| 285 | public sigslot::has_slots<> { |
| 286 | public: |
| 287 | enum State { |
| 288 | kInit, // Initial state. |
| 289 | kRunning, // Started allocating ports. |
| 290 | kStopped, // Stopped from running. |
| 291 | kCompleted, // All ports are allocated. |
| 292 | |
| 293 | // kInit --> kRunning --> {kCompleted|kStopped} |
| 294 | }; |
| 295 | AllocationSequence(BasicPortAllocatorSession* session, |
| 296 | rtc::Network* network, |
| 297 | PortConfiguration* config, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 298 | uint32_t flags); |
honghaiz | f421bdc | 2015-07-17 16:21:55 -0700 | [diff] [blame] | 299 | ~AllocationSequence(); |
Honghai Zhang | 5048f57 | 2016-08-23 15:47:33 -0700 | [diff] [blame] | 300 | void Init(); |
honghaiz | f421bdc | 2015-07-17 16:21:55 -0700 | [diff] [blame] | 301 | void Clear(); |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 302 | void OnNetworkFailed(); |
honghaiz | f421bdc | 2015-07-17 16:21:55 -0700 | [diff] [blame] | 303 | |
| 304 | State state() const { return state_; } |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 305 | rtc::Network* network() const { return network_; } |
| 306 | |
| 307 | bool network_failed() const { return network_failed_; } |
| 308 | void set_network_failed() { network_failed_ = true; } |
honghaiz | f421bdc | 2015-07-17 16:21:55 -0700 | [diff] [blame] | 309 | |
| 310 | // Disables the phases for a new sequence that this one already covers for an |
| 311 | // equivalent network setup. |
| 312 | void DisableEquivalentPhases(rtc::Network* network, |
| 313 | PortConfiguration* config, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 314 | uint32_t* flags); |
honghaiz | f421bdc | 2015-07-17 16:21:55 -0700 | [diff] [blame] | 315 | |
| 316 | // Starts and stops the sequence. When started, it will continue allocating |
| 317 | // new ports on its own timed schedule. |
| 318 | void Start(); |
| 319 | void Stop(); |
| 320 | |
| 321 | // MessageHandler |
| 322 | void OnMessage(rtc::Message* msg); |
| 323 | |
| 324 | void EnableProtocol(ProtocolType proto); |
| 325 | bool ProtocolEnabled(ProtocolType proto) const; |
| 326 | |
| 327 | // Signal from AllocationSequence, when it's done with allocating ports. |
| 328 | // This signal is useful, when port allocation fails which doesn't result |
| 329 | // in any candidates. Using this signal BasicPortAllocatorSession can send |
| 330 | // its candidate discovery conclusion signal. Without this signal, |
| 331 | // BasicPortAllocatorSession doesn't have any event to trigger signal. This |
| 332 | // can also be achieved by starting timer in BPAS. |
| 333 | sigslot::signal1<AllocationSequence*> SignalPortAllocationComplete; |
| 334 | |
| 335 | protected: |
| 336 | // For testing. |
| 337 | void CreateTurnPort(const RelayServerConfig& config); |
| 338 | |
| 339 | private: |
| 340 | typedef std::vector<ProtocolType> ProtocolList; |
| 341 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 342 | bool IsFlagSet(uint32_t flag) { return ((flags_ & flag) != 0); } |
honghaiz | f421bdc | 2015-07-17 16:21:55 -0700 | [diff] [blame] | 343 | void CreateUDPPorts(); |
| 344 | void CreateTCPPorts(); |
| 345 | void CreateStunPorts(); |
| 346 | void CreateRelayPorts(); |
| 347 | void CreateGturnPort(const RelayServerConfig& config); |
| 348 | |
| 349 | void OnReadPacket(rtc::AsyncPacketSocket* socket, |
| 350 | const char* data, |
| 351 | size_t size, |
| 352 | const rtc::SocketAddress& remote_addr, |
| 353 | const rtc::PacketTime& packet_time); |
| 354 | |
| 355 | void OnPortDestroyed(PortInterface* port); |
| 356 | |
| 357 | BasicPortAllocatorSession* session_; |
Honghai Zhang | 5622c5e | 2016-07-01 13:59:29 -0700 | [diff] [blame] | 358 | bool network_failed_ = false; |
honghaiz | f421bdc | 2015-07-17 16:21:55 -0700 | [diff] [blame] | 359 | rtc::Network* network_; |
| 360 | rtc::IPAddress ip_; |
| 361 | PortConfiguration* config_; |
| 362 | State state_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 363 | uint32_t flags_; |
honghaiz | f421bdc | 2015-07-17 16:21:55 -0700 | [diff] [blame] | 364 | ProtocolList protocols_; |
kwiberg | 3ec4679 | 2016-04-27 07:22:53 -0700 | [diff] [blame] | 365 | std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_; |
honghaiz | f421bdc | 2015-07-17 16:21:55 -0700 | [diff] [blame] | 366 | // There will be only one udp port per AllocationSequence. |
| 367 | UDPPort* udp_port_; |
| 368 | std::vector<TurnPort*> turn_ports_; |
| 369 | int phase_; |
| 370 | }; |
| 371 | |
henrike@webrtc.org | 269fb4b | 2014-10-28 22:20:11 +0000 | [diff] [blame] | 372 | } // namespace cricket |
| 373 | |
| 374 | #endif // WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ |