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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 class PortAllocator : public sigslot::has_slots<> { | 299 class PortAllocator : public sigslot::has_slots<> { |
300 public: | 300 public: |
301 PortAllocator() : | 301 PortAllocator() : |
302 flags_(kDefaultPortAllocatorFlags), | 302 flags_(kDefaultPortAllocatorFlags), |
303 min_port_(0), | 303 min_port_(0), |
304 max_port_(0), | 304 max_port_(0), |
305 step_delay_(kDefaultStepDelay), | 305 step_delay_(kDefaultStepDelay), |
306 allow_tcp_listen_(true), | 306 allow_tcp_listen_(true), |
307 candidate_filter_(CF_ALL) { | 307 candidate_filter_(CF_ALL) { |
308 } | 308 } |
| 309 |
309 virtual ~PortAllocator() {} | 310 virtual ~PortAllocator() {} |
310 | 311 |
311 // This should be called on the PortAllocator's thread before the | 312 // This should be called on the PortAllocator's thread before the |
312 // PortAllocator is used. Subclasses may override this if necessary. | 313 // PortAllocator is used. Subclasses may override this if necessary. |
313 virtual void Initialize() {} | 314 virtual void Initialize() {} |
314 | 315 |
315 // Set STUN and TURN servers to be used in future sessions, and set | 316 // Set STUN and TURN servers to be used in future sessions, and set |
316 // candidate pool size, as described in JSEP. | 317 // candidate pool size, as described in JSEP. |
317 // | 318 // |
318 // If the servers are changing and the candidate pool size is nonzero, | 319 // If the servers are changing, and the candidate pool size is nonzero, and |
319 // existing pooled sessions will be destroyed and new ones created. | 320 // FreezeCandidatePool hasn't been called, existing pooled sessions will be |
| 321 // destroyed and new ones created. |
320 // | 322 // |
321 // If the servers are not changing but the candidate pool size is, | 323 // If the servers are not changing but the candidate pool size is, and |
322 // pooled sessions will be either created or destroyed as necessary. | 324 // FreezeCandidatePool hasn't been called, pooled sessions will be either |
| 325 // created or destroyed as necessary. |
323 // | 326 // |
324 // Returns true if the configuration could successfully be changed. | 327 // Returns true if the configuration could successfully be changed. |
325 bool SetConfiguration(const ServerAddresses& stun_servers, | 328 bool SetConfiguration(const ServerAddresses& stun_servers, |
326 const std::vector<RelayServerConfig>& turn_servers, | 329 const std::vector<RelayServerConfig>& turn_servers, |
327 int candidate_pool_size, | 330 int candidate_pool_size, |
328 bool prune_turn_ports); | 331 bool prune_turn_ports); |
329 | 332 |
330 const ServerAddresses& stun_servers() const { return stun_servers_; } | 333 const ServerAddresses& stun_servers() const { return stun_servers_; } |
331 | 334 |
332 const std::vector<RelayServerConfig>& turn_servers() const { | 335 const std::vector<RelayServerConfig>& turn_servers() const { |
(...skipping 22 matching lines...) Expand all Loading... |
355 // If no pooled sessions are available, returns null. | 358 // If no pooled sessions are available, returns null. |
356 std::unique_ptr<PortAllocatorSession> TakePooledSession( | 359 std::unique_ptr<PortAllocatorSession> TakePooledSession( |
357 const std::string& content_name, | 360 const std::string& content_name, |
358 int component, | 361 int component, |
359 const std::string& ice_ufrag, | 362 const std::string& ice_ufrag, |
360 const std::string& ice_pwd); | 363 const std::string& ice_pwd); |
361 | 364 |
362 // Returns the next session that would be returned by TakePooledSession. | 365 // Returns the next session that would be returned by TakePooledSession. |
363 const PortAllocatorSession* GetPooledSession() const; | 366 const PortAllocatorSession* GetPooledSession() const; |
364 | 367 |
| 368 // After FreezeCandidatePool is called, changing the candidate pool size will |
| 369 // no longer be allowed, and changing ICE servers will not cause pooled |
| 370 // sessions to be recreated. |
| 371 // |
| 372 // Expected to be called when SetLocalDescription is called on a |
| 373 // PeerConnection. Can be called safely on any thread as long as not |
| 374 // simultaneously with SetConfiguration. |
| 375 void FreezeCandidatePool(); |
| 376 |
| 377 // Discard any remaining pooled sessions. |
| 378 void DiscardCandidatePool(); |
| 379 |
365 uint32_t flags() const { return flags_; } | 380 uint32_t flags() const { return flags_; } |
366 void set_flags(uint32_t flags) { flags_ = flags; } | 381 void set_flags(uint32_t flags) { flags_ = flags; } |
367 | 382 |
368 // Gets/Sets the port range to use when choosing client ports. | 383 // Gets/Sets the port range to use when choosing client ports. |
369 int min_port() const { return min_port_; } | 384 int min_port() const { return min_port_; } |
370 int max_port() const { return max_port_; } | 385 int max_port() const { return max_port_; } |
371 bool SetPortRange(int min_port, int max_port) { | 386 bool SetPortRange(int min_port, int max_port) { |
372 if (min_port > max_port) { | 387 if (min_port > max_port) { |
373 return false; | 388 return false; |
374 } | 389 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 uint32_t step_delay_; | 437 uint32_t step_delay_; |
423 bool allow_tcp_listen_; | 438 bool allow_tcp_listen_; |
424 uint32_t candidate_filter_; | 439 uint32_t candidate_filter_; |
425 std::string origin_; | 440 std::string origin_; |
426 | 441 |
427 private: | 442 private: |
428 ServerAddresses stun_servers_; | 443 ServerAddresses stun_servers_; |
429 std::vector<RelayServerConfig> turn_servers_; | 444 std::vector<RelayServerConfig> turn_servers_; |
430 int candidate_pool_size_ = 0; // Last value passed into SetConfiguration. | 445 int candidate_pool_size_ = 0; // Last value passed into SetConfiguration. |
431 std::deque<std::unique_ptr<PortAllocatorSession>> pooled_sessions_; | 446 std::deque<std::unique_ptr<PortAllocatorSession>> pooled_sessions_; |
| 447 bool candidate_pool_frozen_ = false; |
432 bool prune_turn_ports_ = false; | 448 bool prune_turn_ports_ = false; |
433 | 449 |
434 webrtc::MetricsObserverInterface* metrics_observer_ = nullptr; | 450 webrtc::MetricsObserverInterface* metrics_observer_ = nullptr; |
435 }; | 451 }; |
436 | 452 |
437 } // namespace cricket | 453 } // namespace cricket |
438 | 454 |
439 #endif // WEBRTC_P2P_BASE_PORTALLOCATOR_H_ | 455 #endif // WEBRTC_P2P_BASE_PORTALLOCATOR_H_ |
OLD | NEW |