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, | |
84 CONTINUAL_GATHERING_BY_NETWORK_CHANGE, | |
85 CONTINUAL_GATHERING_BY_NETWORK_FAILURE, | |
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::signal2<PortAllocatorSession*, IceRegatheringReason> | |
234 SignalIceRegatheringReason; | |
235 | |
219 virtual uint32_t generation() { return generation_; } | 236 virtual uint32_t generation() { return generation_; } |
220 virtual void set_generation(uint32_t generation) { generation_ = generation; } | 237 virtual void set_generation(uint32_t generation) { generation_ = generation; } |
221 sigslot::signal1<PortAllocatorSession*> SignalDestroyed; | 238 sigslot::signal1<PortAllocatorSession*> SignalDestroyed; |
222 | 239 |
223 protected: | 240 protected: |
224 // This method is called when a pooled session (which doesn't have these | 241 // This method is called when a pooled session (which doesn't have these |
225 // properties initially) is returned by PortAllocator::TakePooledSession, | 242 // properties initially) is returned by PortAllocator::TakePooledSession, |
226 // and the content name, component, and ICE ufrag/pwd are updated. | 243 // and the content name, component, and ICE ufrag/pwd are updated. |
227 // | 244 // |
228 // A subclass may need to override this method to perform additional actions, | 245 // 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) { | 380 void set_candidate_filter(uint32_t filter) { |
364 candidate_filter_ = filter; | 381 candidate_filter_ = filter; |
365 } | 382 } |
366 | 383 |
367 bool prune_turn_ports() const { return prune_turn_ports_; } | 384 bool prune_turn_ports() const { return prune_turn_ports_; } |
368 | 385 |
369 // Gets/Sets the Origin value used for WebRTC STUN requests. | 386 // Gets/Sets the Origin value used for WebRTC STUN requests. |
370 const std::string& origin() const { return origin_; } | 387 const std::string& origin() const { return origin_; } |
371 void set_origin(const std::string& origin) { origin_ = origin; } | 388 void set_origin(const std::string& origin) { origin_ = origin; } |
372 | 389 |
390 void set_metrics_observer(webrtc::MetricsObserverInterface* observer) { | |
391 metrics_observer_ = observer; | |
392 } | |
Taylor Brandstetter
2016/10/03 20:33:35
It seems confusing that the metrics observer is se
honghaiz3
2016/10/04 01:03:55
The first part, really just follows a few other me
Taylor Brandstetter
2016/10/04 02:42:32
The enum definition doesn't matter too much. What
honghaiz3
2016/10/04 04:06:42
This is what I was doing in the second patch.
Taylor Brandstetter
2016/10/04 17:44:15
I'd still prefer #1, because I don't think it shou
honghaiz3
2016/10/05 05:01:53
Done.
| |
393 | |
373 protected: | 394 protected: |
374 virtual PortAllocatorSession* CreateSessionInternal( | 395 virtual PortAllocatorSession* CreateSessionInternal( |
375 const std::string& content_name, | 396 const std::string& content_name, |
376 int component, | 397 int component, |
377 const std::string& ice_ufrag, | 398 const std::string& ice_ufrag, |
378 const std::string& ice_pwd) = 0; | 399 const std::string& ice_pwd) = 0; |
379 | 400 |
401 webrtc::MetricsObserverInterface* metrics_observer() { | |
402 return metrics_observer_; | |
403 } | |
404 | |
380 uint32_t flags_; | 405 uint32_t flags_; |
381 std::string agent_; | 406 std::string agent_; |
382 rtc::ProxyInfo proxy_; | 407 rtc::ProxyInfo proxy_; |
383 int min_port_; | 408 int min_port_; |
384 int max_port_; | 409 int max_port_; |
385 uint32_t step_delay_; | 410 uint32_t step_delay_; |
386 bool allow_tcp_listen_; | 411 bool allow_tcp_listen_; |
387 uint32_t candidate_filter_; | 412 uint32_t candidate_filter_; |
388 std::string origin_; | 413 std::string origin_; |
389 | 414 |
390 private: | 415 private: |
391 ServerAddresses stun_servers_; | 416 ServerAddresses stun_servers_; |
392 std::vector<RelayServerConfig> turn_servers_; | 417 std::vector<RelayServerConfig> turn_servers_; |
393 // The last size passed into SetConfiguration. | 418 // The last size passed into SetConfiguration. |
394 int target_pooled_session_count_ = 0; | 419 int target_pooled_session_count_ = 0; |
395 // This variable represents the total number of pooled sessions | 420 // This variable represents the total number of pooled sessions |
396 // both owned by this class and taken by TakePooledSession. | 421 // both owned by this class and taken by TakePooledSession. |
397 int allocated_pooled_session_count_ = 0; | 422 int allocated_pooled_session_count_ = 0; |
398 std::deque<std::unique_ptr<PortAllocatorSession>> pooled_sessions_; | 423 std::deque<std::unique_ptr<PortAllocatorSession>> pooled_sessions_; |
399 bool prune_turn_ports_ = false; | 424 bool prune_turn_ports_ = false; |
425 | |
426 webrtc::MetricsObserverInterface* metrics_observer_ = nullptr; | |
400 }; | 427 }; |
401 | 428 |
402 } // namespace cricket | 429 } // namespace cricket |
403 | 430 |
404 #endif // WEBRTC_P2P_BASE_PORTALLOCATOR_H_ | 431 #endif // WEBRTC_P2P_BASE_PORTALLOCATOR_H_ |
OLD | NEW |