OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 // Set to kDefaultNetworkIgnoreMask by default. | 40 // Set to kDefaultNetworkIgnoreMask by default. |
41 void SetNetworkIgnoreMask(int network_ignore_mask) override { | 41 void SetNetworkIgnoreMask(int network_ignore_mask) override { |
42 // TODO(phoglund): implement support for other types than loopback. | 42 // TODO(phoglund): implement support for other types than loopback. |
43 // See https://code.google.com/p/webrtc/issues/detail?id=4288. | 43 // See https://code.google.com/p/webrtc/issues/detail?id=4288. |
44 // Then remove set_network_ignore_list from NetworkManager. | 44 // Then remove set_network_ignore_list from NetworkManager. |
45 network_ignore_mask_ = network_ignore_mask; | 45 network_ignore_mask_ = network_ignore_mask; |
46 } | 46 } |
47 | 47 |
48 int network_ignore_mask() const { return network_ignore_mask_; } | 48 int network_ignore_mask() const { return network_ignore_mask_; } |
49 | 49 |
50 rtc::NetworkManager* network_manager() { return network_manager_; } | 50 rtc::NetworkManager* network_manager() const { return network_manager_; } |
51 | 51 |
52 // If socket_factory() is set to NULL each PortAllocatorSession | 52 // If socket_factory() is set to NULL each PortAllocatorSession |
53 // creates its own socket factory. | 53 // creates its own socket factory. |
54 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } | 54 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } |
55 | 55 |
56 PortAllocatorSession* CreateSessionInternal( | 56 PortAllocatorSession* CreateSessionInternal( |
57 const std::string& content_name, | 57 const std::string& content_name, |
58 int component, | 58 int component, |
59 const std::string& ice_ufrag, | 59 const std::string& ice_ufrag, |
60 const std::string& ice_pwd) override; | 60 const std::string& ice_pwd) override; |
(...skipping 24 matching lines...) Expand all Loading... |
85 ~BasicPortAllocatorSession(); | 85 ~BasicPortAllocatorSession(); |
86 | 86 |
87 virtual BasicPortAllocator* allocator() { return allocator_; } | 87 virtual BasicPortAllocator* allocator() { return allocator_; } |
88 rtc::Thread* network_thread() { return network_thread_; } | 88 rtc::Thread* network_thread() { return network_thread_; } |
89 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } | 89 rtc::PacketSocketFactory* socket_factory() { return socket_factory_; } |
90 | 90 |
91 void SetCandidateFilter(uint32_t filter) override; | 91 void SetCandidateFilter(uint32_t filter) override; |
92 void StartGettingPorts() override; | 92 void StartGettingPorts() override; |
93 void StopGettingPorts() override; | 93 void StopGettingPorts() override; |
94 void ClearGettingPorts() override; | 94 void ClearGettingPorts() override; |
95 bool IsGettingPorts() override { return running_; } | |
96 // These will all be cricket::Ports. | 95 // These will all be cricket::Ports. |
97 std::vector<PortInterface*> ReadyPorts() const override; | 96 std::vector<PortInterface*> ReadyPorts() const override; |
98 std::vector<Candidate> ReadyCandidates() const override; | 97 std::vector<Candidate> ReadyCandidates() const override; |
99 bool CandidatesAllocationDone() const override; | 98 bool CandidatesAllocationDone() const override; |
| 99 void RegatherOnFailedNetworks() override; |
100 | 100 |
101 protected: | 101 protected: |
102 void UpdateIceParametersInternal() override; | 102 void UpdateIceParametersInternal() override; |
103 | 103 |
104 // Starts the process of getting the port configurations. | 104 // Starts the process of getting the port configurations. |
105 virtual void GetPortConfigurations(); | 105 virtual void GetPortConfigurations(); |
106 | 106 |
107 // Adds a port configuration that is now ready. Once we have one for each | 107 // Adds a port configuration that is now ready. Once we have one for each |
108 // network (or a timeout occurs), we will start allocating ports. | 108 // network (or a timeout occurs), we will start allocating ports. |
109 virtual void ConfigReady(PortConfiguration* config); | 109 virtual void ConfigReady(PortConfiguration* config); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 private: | 149 private: |
150 enum State { | 150 enum State { |
151 STATE_INPROGRESS, // Still gathering candidates. | 151 STATE_INPROGRESS, // Still gathering candidates. |
152 STATE_COMPLETE, // All candidates allocated and ready for process. | 152 STATE_COMPLETE, // All candidates allocated and ready for process. |
153 STATE_ERROR, // Error in gathering candidates. | 153 STATE_ERROR, // Error in gathering candidates. |
154 STATE_PRUNED // Pruned by higher priority ports on the same network | 154 STATE_PRUNED // Pruned by higher priority ports on the same network |
155 // interface. Only TURN ports may be pruned. | 155 // interface. Only TURN ports may be pruned. |
156 }; | 156 }; |
157 Port* port_ = nullptr; | 157 Port* port_ = nullptr; |
158 AllocationSequence* sequence_ = nullptr; | 158 AllocationSequence* sequence_ = nullptr; |
| 159 bool has_pairable_candidate_ = false; |
159 State state_ = STATE_INPROGRESS; | 160 State state_ = STATE_INPROGRESS; |
160 bool has_pairable_candidate_ = false; | |
161 }; | 161 }; |
162 | 162 |
163 void OnConfigReady(PortConfiguration* config); | 163 void OnConfigReady(PortConfiguration* config); |
164 void OnConfigStop(); | 164 void OnConfigStop(); |
165 void AllocatePorts(); | 165 void AllocatePorts(); |
166 void OnAllocate(); | 166 void OnAllocate(); |
167 void DoAllocate(); | 167 void DoAllocate(); |
168 void OnNetworksChanged(); | 168 void OnNetworksChanged(); |
169 void OnAllocationSequenceObjectsCreated(); | 169 void OnAllocationSequenceObjectsCreated(); |
170 void DisableEquivalentPhases(rtc::Network* network, | 170 void DisableEquivalentPhases(rtc::Network* network, |
171 PortConfiguration* config, | 171 PortConfiguration* config, |
172 uint32_t* flags); | 172 uint32_t* flags); |
173 void AddAllocatedPort(Port* port, AllocationSequence* seq, | 173 void AddAllocatedPort(Port* port, AllocationSequence* seq, |
174 bool prepare_address); | 174 bool prepare_address); |
175 void OnCandidateReady(Port* port, const Candidate& c); | 175 void OnCandidateReady(Port* port, const Candidate& c); |
176 void OnPortComplete(Port* port); | 176 void OnPortComplete(Port* port); |
177 void OnPortError(Port* port); | 177 void OnPortError(Port* port); |
178 void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto); | 178 void OnProtocolEnabled(AllocationSequence* seq, ProtocolType proto); |
179 void OnPortDestroyed(PortInterface* port); | 179 void OnPortDestroyed(PortInterface* port); |
180 void MaybeSignalCandidatesAllocationDone(); | 180 void MaybeSignalCandidatesAllocationDone(); |
181 void OnPortAllocationComplete(AllocationSequence* seq); | 181 void OnPortAllocationComplete(AllocationSequence* seq); |
182 PortData* FindPort(Port* port); | 182 PortData* FindPort(Port* port); |
183 void GetNetworks(std::vector<rtc::Network*>* networks); | 183 std::vector<rtc::Network*> GetNetworks(); |
| 184 std::vector<rtc::Network*> GetFailedNetworks(); |
184 | 185 |
185 bool CheckCandidateFilter(const Candidate& c) const; | 186 bool CheckCandidateFilter(const Candidate& c) const; |
186 bool CandidatePairable(const Candidate& c, const Port* port) const; | 187 bool CandidatePairable(const Candidate& c, const Port* port) const; |
187 // Clear the related address according to the flags and candidate filter | 188 // Clear the related address according to the flags and candidate filter |
188 // in order to avoid leaking any information. | 189 // in order to avoid leaking any information. |
189 Candidate SanitizeRelatedAddress(const Candidate& c) const; | 190 Candidate SanitizeRelatedAddress(const Candidate& c) const; |
190 | 191 |
| 192 // Removes the ports and candidates on given networks. |
| 193 void RemovePortsAndCandidates(const std::vector<rtc::Network*>& networks); |
| 194 // Gets filtered and sanitized candidates generated from a port and |
| 195 // append to |candidates|. |
| 196 void GetCandidatesFromPort(const PortData& data, |
| 197 std::vector<Candidate>* candidates) const; |
191 Port* GetBestTurnPortForNetwork(const std::string& network_name) const; | 198 Port* GetBestTurnPortForNetwork(const std::string& network_name) const; |
192 // Returns true if at least one TURN port is pruned. | 199 // Returns true if at least one TURN port is pruned. |
193 bool PruneTurnPorts(Port* newly_pairable_turn_port); | 200 bool PruneTurnPorts(Port* newly_pairable_turn_port); |
194 | 201 |
195 BasicPortAllocator* allocator_; | 202 BasicPortAllocator* allocator_; |
196 rtc::Thread* network_thread_; | 203 rtc::Thread* network_thread_; |
197 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_; | 204 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_; |
198 rtc::PacketSocketFactory* socket_factory_; | 205 rtc::PacketSocketFactory* socket_factory_; |
199 bool allocation_started_; | 206 bool allocation_started_; |
200 bool network_manager_started_; | 207 bool network_manager_started_; |
201 bool running_; // set when StartGetAllPorts is called | |
202 bool allocation_sequences_created_; | 208 bool allocation_sequences_created_; |
203 std::vector<PortConfiguration*> configs_; | 209 std::vector<PortConfiguration*> configs_; |
204 std::vector<AllocationSequence*> sequences_; | 210 std::vector<AllocationSequence*> sequences_; |
205 std::vector<PortData> ports_; | 211 std::vector<PortData> ports_; |
206 uint32_t candidate_filter_ = CF_ALL; | 212 uint32_t candidate_filter_ = CF_ALL; |
207 // Whether to prune low-priority ports, taken from the port allocator. | 213 // Whether to prune low-priority ports, taken from the port allocator. |
208 bool prune_turn_ports_; | 214 bool prune_turn_ports_; |
209 | 215 |
210 friend class AllocationSequence; | 216 friend class AllocationSequence; |
211 }; | 217 }; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 | 270 |
265 // kInit --> kRunning --> {kCompleted|kStopped} | 271 // kInit --> kRunning --> {kCompleted|kStopped} |
266 }; | 272 }; |
267 AllocationSequence(BasicPortAllocatorSession* session, | 273 AllocationSequence(BasicPortAllocatorSession* session, |
268 rtc::Network* network, | 274 rtc::Network* network, |
269 PortConfiguration* config, | 275 PortConfiguration* config, |
270 uint32_t flags); | 276 uint32_t flags); |
271 ~AllocationSequence(); | 277 ~AllocationSequence(); |
272 bool Init(); | 278 bool Init(); |
273 void Clear(); | 279 void Clear(); |
274 void OnNetworkRemoved(); | 280 void OnNetworkFailed(); |
275 | 281 |
276 State state() const { return state_; } | 282 State state() const { return state_; } |
277 const rtc::Network* network() const { return network_; } | 283 rtc::Network* network() const { return network_; } |
278 bool network_removed() const { return network_removed_; } | 284 |
| 285 bool network_failed() const { return network_failed_; } |
| 286 void set_network_failed() { network_failed_ = true; } |
279 | 287 |
280 // Disables the phases for a new sequence that this one already covers for an | 288 // Disables the phases for a new sequence that this one already covers for an |
281 // equivalent network setup. | 289 // equivalent network setup. |
282 void DisableEquivalentPhases(rtc::Network* network, | 290 void DisableEquivalentPhases(rtc::Network* network, |
283 PortConfiguration* config, | 291 PortConfiguration* config, |
284 uint32_t* flags); | 292 uint32_t* flags); |
285 | 293 |
286 // Starts and stops the sequence. When started, it will continue allocating | 294 // Starts and stops the sequence. When started, it will continue allocating |
287 // new ports on its own timed schedule. | 295 // new ports on its own timed schedule. |
288 void Start(); | 296 void Start(); |
(...skipping 29 matching lines...) Expand all Loading... |
318 | 326 |
319 void OnReadPacket(rtc::AsyncPacketSocket* socket, | 327 void OnReadPacket(rtc::AsyncPacketSocket* socket, |
320 const char* data, | 328 const char* data, |
321 size_t size, | 329 size_t size, |
322 const rtc::SocketAddress& remote_addr, | 330 const rtc::SocketAddress& remote_addr, |
323 const rtc::PacketTime& packet_time); | 331 const rtc::PacketTime& packet_time); |
324 | 332 |
325 void OnPortDestroyed(PortInterface* port); | 333 void OnPortDestroyed(PortInterface* port); |
326 | 334 |
327 BasicPortAllocatorSession* session_; | 335 BasicPortAllocatorSession* session_; |
328 bool network_removed_ = false; | 336 bool network_failed_ = false; |
329 rtc::Network* network_; | 337 rtc::Network* network_; |
330 rtc::IPAddress ip_; | 338 rtc::IPAddress ip_; |
331 PortConfiguration* config_; | 339 PortConfiguration* config_; |
332 State state_; | 340 State state_; |
333 uint32_t flags_; | 341 uint32_t flags_; |
334 ProtocolList protocols_; | 342 ProtocolList protocols_; |
335 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_; | 343 std::unique_ptr<rtc::AsyncPacketSocket> udp_socket_; |
336 // There will be only one udp port per AllocationSequence. | 344 // There will be only one udp port per AllocationSequence. |
337 UDPPort* udp_port_; | 345 UDPPort* udp_port_; |
338 std::vector<TurnPort*> turn_ports_; | 346 std::vector<TurnPort*> turn_ports_; |
339 int phase_; | 347 int phase_; |
340 }; | 348 }; |
341 | 349 |
342 } // namespace cricket | 350 } // namespace cricket |
343 | 351 |
344 #endif // WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ | 352 #endif // WEBRTC_P2P_CLIENT_BASICPORTALLOCATOR_H_ |
OLD | NEW |