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 { | |
81 ICE_RESTART_WHEN_CONNECTED, | |
82 ICE_RESTART_WHEN_CONNECTING, | |
83 ICE_RESTART_WHEN_DISCONNECTED, | |
pthatcher2
2016/10/04 06:03:17
Shouldn't these be "_WHILE_" rather than "_WHEN_"?
honghaiz3
2016/10/05 05:01:53
renamed class and variables as suggested in other
| |
84 CONTINUAL_GATHERING_BY_NETWORK_CHANGE, | |
85 CONTINUAL_GATHERING_BY_NETWORK_FAILURE, | |
pthatcher2
2016/10/04 06:03:17
Shouldn't these be "_FOR_" rather than "_BY_"?
honghaiz3
2016/10/05 05:01:53
Renames this too.
| |
86 MAX_VALUE | |
87 }; | |
88 | |
75 const uint32_t kDefaultPortAllocatorFlags = 0; | 89 const uint32_t kDefaultPortAllocatorFlags = 0; |
76 | 90 |
77 const uint32_t kDefaultStepDelay = 1000; // 1 sec step delay. | 91 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 | 92 // 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. | 93 // internal. Less than 20ms is not acceptable. We choose 50ms as our default. |
80 const uint32_t kMinimumStepDelay = 50; | 94 const uint32_t kMinimumStepDelay = 50; |
81 | 95 |
82 // CF = CANDIDATE FILTER | 96 // CF = CANDIDATE FILTER |
83 enum { | 97 enum { |
84 CF_NONE = 0x0, | 98 CF_NONE = 0x0, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 sigslot::signal2<PortAllocatorSession*, const std::vector<PortInterface*>&> | 223 sigslot::signal2<PortAllocatorSession*, const std::vector<PortInterface*>&> |
210 SignalPortsPruned; | 224 SignalPortsPruned; |
211 sigslot::signal2<PortAllocatorSession*, | 225 sigslot::signal2<PortAllocatorSession*, |
212 const std::vector<Candidate>&> SignalCandidatesReady; | 226 const std::vector<Candidate>&> SignalCandidatesReady; |
213 // Candidates should be signaled to be removed when the port that generated | 227 // Candidates should be signaled to be removed when the port that generated |
214 // the candidates is removed. | 228 // the candidates is removed. |
215 sigslot::signal2<PortAllocatorSession*, const std::vector<Candidate>&> | 229 sigslot::signal2<PortAllocatorSession*, const std::vector<Candidate>&> |
216 SignalCandidatesRemoved; | 230 SignalCandidatesRemoved; |
217 sigslot::signal1<PortAllocatorSession*> SignalCandidatesAllocationDone; | 231 sigslot::signal1<PortAllocatorSession*> SignalCandidatesAllocationDone; |
218 | 232 |
233 sigslot::signal1<IceRegatheringReason> SignalIceRegatheringReason; | |
pthatcher2
2016/10/04 06:03:17
Would it make more sense to call this SignalIceReg
honghaiz3
2016/10/05 05:01:53
Done.
| |
234 | |
219 virtual uint32_t generation() { return generation_; } | 235 virtual uint32_t generation() { return generation_; } |
220 virtual void set_generation(uint32_t generation) { generation_ = generation; } | 236 virtual void set_generation(uint32_t generation) { generation_ = generation; } |
221 sigslot::signal1<PortAllocatorSession*> SignalDestroyed; | 237 sigslot::signal1<PortAllocatorSession*> SignalDestroyed; |
222 | 238 |
223 protected: | 239 protected: |
224 // This method is called when a pooled session (which doesn't have these | 240 // This method is called when a pooled session (which doesn't have these |
225 // properties initially) is returned by PortAllocator::TakePooledSession, | 241 // properties initially) is returned by PortAllocator::TakePooledSession, |
226 // and the content name, component, and ICE ufrag/pwd are updated. | 242 // and the content name, component, and ICE ufrag/pwd are updated. |
227 // | 243 // |
228 // A subclass may need to override this method to perform additional actions, | 244 // 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) { | 379 void set_candidate_filter(uint32_t filter) { |
364 candidate_filter_ = filter; | 380 candidate_filter_ = filter; |
365 } | 381 } |
366 | 382 |
367 bool prune_turn_ports() const { return prune_turn_ports_; } | 383 bool prune_turn_ports() const { return prune_turn_ports_; } |
368 | 384 |
369 // Gets/Sets the Origin value used for WebRTC STUN requests. | 385 // Gets/Sets the Origin value used for WebRTC STUN requests. |
370 const std::string& origin() const { return origin_; } | 386 const std::string& origin() const { return origin_; } |
371 void set_origin(const std::string& origin) { origin_ = origin; } | 387 void set_origin(const std::string& origin) { origin_ = origin; } |
372 | 388 |
389 virtual void ReportIceRegatheringReason(IceRegatheringReason reason) {} | |
390 | |
391 void set_metrics_observer(webrtc::MetricsObserverInterface* observer) { | |
392 metrics_observer_ = observer; | |
393 } | |
394 | |
373 protected: | 395 protected: |
374 virtual PortAllocatorSession* CreateSessionInternal( | 396 virtual PortAllocatorSession* CreateSessionInternal( |
375 const std::string& content_name, | 397 const std::string& content_name, |
376 int component, | 398 int component, |
377 const std::string& ice_ufrag, | 399 const std::string& ice_ufrag, |
378 const std::string& ice_pwd) = 0; | 400 const std::string& ice_pwd) = 0; |
379 | 401 |
402 webrtc::MetricsObserverInterface* metrics_observer() { | |
403 return metrics_observer_; | |
404 } | |
405 | |
380 uint32_t flags_; | 406 uint32_t flags_; |
381 std::string agent_; | 407 std::string agent_; |
382 rtc::ProxyInfo proxy_; | 408 rtc::ProxyInfo proxy_; |
383 int min_port_; | 409 int min_port_; |
384 int max_port_; | 410 int max_port_; |
385 uint32_t step_delay_; | 411 uint32_t step_delay_; |
386 bool allow_tcp_listen_; | 412 bool allow_tcp_listen_; |
387 uint32_t candidate_filter_; | 413 uint32_t candidate_filter_; |
388 std::string origin_; | 414 std::string origin_; |
389 | 415 |
390 private: | 416 private: |
391 ServerAddresses stun_servers_; | 417 ServerAddresses stun_servers_; |
392 std::vector<RelayServerConfig> turn_servers_; | 418 std::vector<RelayServerConfig> turn_servers_; |
393 // The last size passed into SetConfiguration. | 419 // The last size passed into SetConfiguration. |
394 int target_pooled_session_count_ = 0; | 420 int target_pooled_session_count_ = 0; |
395 // This variable represents the total number of pooled sessions | 421 // This variable represents the total number of pooled sessions |
396 // both owned by this class and taken by TakePooledSession. | 422 // both owned by this class and taken by TakePooledSession. |
397 int allocated_pooled_session_count_ = 0; | 423 int allocated_pooled_session_count_ = 0; |
398 std::deque<std::unique_ptr<PortAllocatorSession>> pooled_sessions_; | 424 std::deque<std::unique_ptr<PortAllocatorSession>> pooled_sessions_; |
399 bool prune_turn_ports_ = false; | 425 bool prune_turn_ports_ = false; |
426 | |
427 webrtc::MetricsObserverInterface* metrics_observer_ = nullptr; | |
400 }; | 428 }; |
401 | 429 |
402 } // namespace cricket | 430 } // namespace cricket |
403 | 431 |
404 #endif // WEBRTC_P2P_BASE_PORTALLOCATOR_H_ | 432 #endif // WEBRTC_P2P_BASE_PORTALLOCATOR_H_ |
OLD | NEW |