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 |
11 #ifndef WEBRTC_P2P_BASE_PORTALLOCATOR_H_ | 11 #ifndef WEBRTC_P2P_BASE_PORTALLOCATOR_H_ |
12 #define WEBRTC_P2P_BASE_PORTALLOCATOR_H_ | 12 #define WEBRTC_P2P_BASE_PORTALLOCATOR_H_ |
13 | 13 |
14 #include <deque> | 14 #include <deque> |
15 #include <memory> | 15 #include <memory> |
16 #include <string> | 16 #include <string> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "webrtc/p2p/base/port.h" | 19 #include "webrtc/p2p/base/port.h" |
20 #include "webrtc/p2p/base/portinterface.h" | 20 #include "webrtc/p2p/base/portinterface.h" |
21 #include "webrtc/base/helpers.h" | 21 #include "webrtc/base/helpers.h" |
22 #include "webrtc/base/proxyinfo.h" | 22 #include "webrtc/base/proxyinfo.h" |
23 #include "webrtc/base/sigslot.h" | 23 #include "webrtc/base/sigslot.h" |
24 #include "webrtc/base/thread.h" | 24 #include "webrtc/base/thread.h" |
25 | 25 |
| 26 namespace webrtc { |
| 27 class MetricsObserverInterface; |
| 28 } |
| 29 |
26 namespace cricket { | 30 namespace cricket { |
27 | 31 |
28 // PortAllocator is responsible for allocating Port types for a given | 32 // PortAllocator is responsible for allocating Port types for a given |
29 // P2PSocket. It also handles port freeing. | 33 // P2PSocket. It also handles port freeing. |
30 // | 34 // |
31 // Clients can override this class to control port allocation, including | 35 // Clients can override this class to control port allocation, including |
32 // what kinds of ports are allocated. | 36 // what kinds of ports are allocated. |
33 | 37 |
34 enum { | 38 enum { |
35 // Disable local UDP ports. This doesn't impact how we connect to relay | 39 // Disable local UDP ports. This doesn't impact how we connect to relay |
(...skipping 29 matching lines...) Expand all Loading... |
65 // high cost. So if both Wi-Fi and cellular networks exist, gather only on the | 69 // high cost. So if both Wi-Fi and cellular networks exist, gather only on the |
66 // Wi-Fi network. If a network type is "unknown", it has a cost lower than | 70 // Wi-Fi network. If a network type is "unknown", it has a cost lower than |
67 // cellular but higher than Wi-Fi/Ethernet. So if an unknown network exists, | 71 // cellular but higher than Wi-Fi/Ethernet. So if an unknown network exists, |
68 // cellular networks will not be used to gather candidates and if a Wi-Fi | 72 // cellular networks will not be used to gather candidates and if a Wi-Fi |
69 // network is present, "unknown" networks will not be usd to gather | 73 // network is present, "unknown" networks will not be usd to gather |
70 // candidates. Doing so ensures that even if a cellular network type was not | 74 // candidates. Doing so ensures that even if a cellular network type was not |
71 // detected initially, it would not be used if a Wi-Fi network is present. | 75 // detected initially, it would not be used if a Wi-Fi network is present. |
72 PORTALLOCATOR_DISABLE_COSTLY_NETWORKS = 0x2000, | 76 PORTALLOCATOR_DISABLE_COSTLY_NETWORKS = 0x2000, |
73 }; | 77 }; |
74 | 78 |
| 79 // Defines various reasons that have caused ICE regathering. |
| 80 enum class IceRegatheringReason { NETWORK_CHANGE, NETWORK_FAILURE, MAX_VALUE }; |
| 81 |
75 const uint32_t kDefaultPortAllocatorFlags = 0; | 82 const uint32_t kDefaultPortAllocatorFlags = 0; |
76 | 83 |
77 const uint32_t kDefaultStepDelay = 1000; // 1 sec step delay. | 84 const uint32_t kDefaultStepDelay = 1000; // 1 sec step delay. |
78 // As per RFC 5245 Appendix B.1, STUN transactions need to be paced at certain | 85 // As per RFC 5245 Appendix B.1, STUN transactions need to be paced at certain |
79 // internal. Less than 20ms is not acceptable. We choose 50ms as our default. | 86 // internal. Less than 20ms is not acceptable. We choose 50ms as our default. |
80 const uint32_t kMinimumStepDelay = 50; | 87 const uint32_t kMinimumStepDelay = 50; |
81 | 88 |
82 // CF = CANDIDATE FILTER | 89 // CF = CANDIDATE FILTER |
83 enum { | 90 enum { |
84 CF_NONE = 0x0, | 91 CF_NONE = 0x0, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 sigslot::signal2<PortAllocatorSession*, const std::vector<PortInterface*>&> | 216 sigslot::signal2<PortAllocatorSession*, const std::vector<PortInterface*>&> |
210 SignalPortsPruned; | 217 SignalPortsPruned; |
211 sigslot::signal2<PortAllocatorSession*, | 218 sigslot::signal2<PortAllocatorSession*, |
212 const std::vector<Candidate>&> SignalCandidatesReady; | 219 const std::vector<Candidate>&> SignalCandidatesReady; |
213 // Candidates should be signaled to be removed when the port that generated | 220 // Candidates should be signaled to be removed when the port that generated |
214 // the candidates is removed. | 221 // the candidates is removed. |
215 sigslot::signal2<PortAllocatorSession*, const std::vector<Candidate>&> | 222 sigslot::signal2<PortAllocatorSession*, const std::vector<Candidate>&> |
216 SignalCandidatesRemoved; | 223 SignalCandidatesRemoved; |
217 sigslot::signal1<PortAllocatorSession*> SignalCandidatesAllocationDone; | 224 sigslot::signal1<PortAllocatorSession*> SignalCandidatesAllocationDone; |
218 | 225 |
| 226 sigslot::signal2<PortAllocatorSession*, IceRegatheringReason> |
| 227 SignalIceRegathering; |
| 228 |
219 virtual uint32_t generation() { return generation_; } | 229 virtual uint32_t generation() { return generation_; } |
220 virtual void set_generation(uint32_t generation) { generation_ = generation; } | 230 virtual void set_generation(uint32_t generation) { generation_ = generation; } |
221 sigslot::signal1<PortAllocatorSession*> SignalDestroyed; | 231 sigslot::signal1<PortAllocatorSession*> SignalDestroyed; |
222 | 232 |
223 protected: | 233 protected: |
224 // This method is called when a pooled session (which doesn't have these | 234 // This method is called when a pooled session (which doesn't have these |
225 // properties initially) is returned by PortAllocator::TakePooledSession, | 235 // properties initially) is returned by PortAllocator::TakePooledSession, |
226 // and the content name, component, and ICE ufrag/pwd are updated. | 236 // and the content name, component, and ICE ufrag/pwd are updated. |
227 // | 237 // |
228 // A subclass may need to override this method to perform additional actions, | 238 // A subclass may need to override this method to perform additional actions, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 void set_candidate_filter(uint32_t filter) { | 373 void set_candidate_filter(uint32_t filter) { |
364 candidate_filter_ = filter; | 374 candidate_filter_ = filter; |
365 } | 375 } |
366 | 376 |
367 bool prune_turn_ports() const { return prune_turn_ports_; } | 377 bool prune_turn_ports() const { return prune_turn_ports_; } |
368 | 378 |
369 // Gets/Sets the Origin value used for WebRTC STUN requests. | 379 // Gets/Sets the Origin value used for WebRTC STUN requests. |
370 const std::string& origin() const { return origin_; } | 380 const std::string& origin() const { return origin_; } |
371 void set_origin(const std::string& origin) { origin_ = origin; } | 381 void set_origin(const std::string& origin) { origin_ = origin; } |
372 | 382 |
| 383 void SetMetricsObserver(webrtc::MetricsObserverInterface* observer) { |
| 384 metrics_observer_ = observer; |
| 385 } |
| 386 |
373 protected: | 387 protected: |
374 virtual PortAllocatorSession* CreateSessionInternal( | 388 virtual PortAllocatorSession* CreateSessionInternal( |
375 const std::string& content_name, | 389 const std::string& content_name, |
376 int component, | 390 int component, |
377 const std::string& ice_ufrag, | 391 const std::string& ice_ufrag, |
378 const std::string& ice_pwd) = 0; | 392 const std::string& ice_pwd) = 0; |
379 | 393 |
| 394 webrtc::MetricsObserverInterface* metrics_observer() { |
| 395 return metrics_observer_; |
| 396 } |
| 397 |
| 398 const std::deque<std::unique_ptr<PortAllocatorSession>>& pooled_sessions() { |
| 399 return pooled_sessions_; |
| 400 } |
| 401 |
380 uint32_t flags_; | 402 uint32_t flags_; |
381 std::string agent_; | 403 std::string agent_; |
382 rtc::ProxyInfo proxy_; | 404 rtc::ProxyInfo proxy_; |
383 int min_port_; | 405 int min_port_; |
384 int max_port_; | 406 int max_port_; |
385 uint32_t step_delay_; | 407 uint32_t step_delay_; |
386 bool allow_tcp_listen_; | 408 bool allow_tcp_listen_; |
387 uint32_t candidate_filter_; | 409 uint32_t candidate_filter_; |
388 std::string origin_; | 410 std::string origin_; |
389 | 411 |
390 private: | 412 private: |
391 ServerAddresses stun_servers_; | 413 ServerAddresses stun_servers_; |
392 std::vector<RelayServerConfig> turn_servers_; | 414 std::vector<RelayServerConfig> turn_servers_; |
393 // The last size passed into SetConfiguration. | 415 // The last size passed into SetConfiguration. |
394 int target_pooled_session_count_ = 0; | 416 int target_pooled_session_count_ = 0; |
395 // This variable represents the total number of pooled sessions | 417 // This variable represents the total number of pooled sessions |
396 // both owned by this class and taken by TakePooledSession. | 418 // both owned by this class and taken by TakePooledSession. |
397 int allocated_pooled_session_count_ = 0; | 419 int allocated_pooled_session_count_ = 0; |
398 std::deque<std::unique_ptr<PortAllocatorSession>> pooled_sessions_; | 420 std::deque<std::unique_ptr<PortAllocatorSession>> pooled_sessions_; |
399 bool prune_turn_ports_ = false; | 421 bool prune_turn_ports_ = false; |
| 422 |
| 423 webrtc::MetricsObserverInterface* metrics_observer_ = nullptr; |
400 }; | 424 }; |
401 | 425 |
402 } // namespace cricket | 426 } // namespace cricket |
403 | 427 |
404 #endif // WEBRTC_P2P_BASE_PORTALLOCATOR_H_ | 428 #endif // WEBRTC_P2P_BASE_PORTALLOCATOR_H_ |
OLD | NEW |