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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 PORTALLOCATOR_ENABLE_STUN_RETRANSMIT_ATTRIBUTE = 0x200, | 48 PORTALLOCATOR_ENABLE_STUN_RETRANSMIT_ATTRIBUTE = 0x200, |
49 PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION = 0x400, | 49 PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION = 0x400, |
50 // When specified, a loopback candidate will be generated if | 50 // When specified, a loopback candidate will be generated if |
51 // PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified. | 51 // PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION is specified. |
52 PORTALLOCATOR_ENABLE_LOCALHOST_CANDIDATE = 0x800, | 52 PORTALLOCATOR_ENABLE_LOCALHOST_CANDIDATE = 0x800, |
53 // Disallow use of UDP when connecting to a relay server. Since proxy servers | 53 // Disallow use of UDP when connecting to a relay server. Since proxy servers |
54 // usually don't handle UDP, using UDP will leak the IP address. | 54 // usually don't handle UDP, using UDP will leak the IP address. |
55 PORTALLOCATOR_DISABLE_UDP_RELAY = 0x1000, | 55 PORTALLOCATOR_DISABLE_UDP_RELAY = 0x1000, |
56 }; | 56 }; |
57 | 57 |
58 const uint32 kDefaultPortAllocatorFlags = 0; | 58 const uint32_t kDefaultPortAllocatorFlags = 0; |
59 | 59 |
60 const uint32 kDefaultStepDelay = 1000; // 1 sec step delay. | 60 const uint32_t kDefaultStepDelay = 1000; // 1 sec step delay. |
61 // As per RFC 5245 Appendix B.1, STUN transactions need to be paced at certain | 61 // As per RFC 5245 Appendix B.1, STUN transactions need to be paced at certain |
62 // internal. Less than 20ms is not acceptable. We choose 50ms as our default. | 62 // internal. Less than 20ms is not acceptable. We choose 50ms as our default. |
63 const uint32 kMinimumStepDelay = 50; | 63 const uint32_t kMinimumStepDelay = 50; |
64 | 64 |
65 // CF = CANDIDATE FILTER | 65 // CF = CANDIDATE FILTER |
66 enum { | 66 enum { |
67 CF_NONE = 0x0, | 67 CF_NONE = 0x0, |
68 CF_HOST = 0x1, | 68 CF_HOST = 0x1, |
69 CF_REFLEXIVE = 0x2, | 69 CF_REFLEXIVE = 0x2, |
70 CF_RELAY = 0x4, | 70 CF_RELAY = 0x4, |
71 CF_ALL = 0x7, | 71 CF_ALL = 0x7, |
72 }; | 72 }; |
73 | 73 |
74 class PortAllocatorSession : public sigslot::has_slots<> { | 74 class PortAllocatorSession : public sigslot::has_slots<> { |
75 public: | 75 public: |
76 // Content name passed in mostly for logging and debugging. | 76 // Content name passed in mostly for logging and debugging. |
77 PortAllocatorSession(const std::string& content_name, | 77 PortAllocatorSession(const std::string& content_name, |
78 int component, | 78 int component, |
79 const std::string& ice_ufrag, | 79 const std::string& ice_ufrag, |
80 const std::string& ice_pwd, | 80 const std::string& ice_pwd, |
81 uint32 flags); | 81 uint32_t flags); |
82 | 82 |
83 // Subclasses should clean up any ports created. | 83 // Subclasses should clean up any ports created. |
84 virtual ~PortAllocatorSession() {} | 84 virtual ~PortAllocatorSession() {} |
85 | 85 |
86 uint32 flags() const { return flags_; } | 86 uint32_t flags() const { return flags_; } |
87 void set_flags(uint32 flags) { flags_ = flags; } | 87 void set_flags(uint32_t flags) { flags_ = flags; } |
88 std::string content_name() const { return content_name_; } | 88 std::string content_name() const { return content_name_; } |
89 int component() const { return component_; } | 89 int component() const { return component_; } |
90 | 90 |
91 // Starts gathering STUN and Relay configurations. | 91 // Starts gathering STUN and Relay configurations. |
92 virtual void StartGettingPorts() = 0; | 92 virtual void StartGettingPorts() = 0; |
93 virtual void StopGettingPorts() = 0; | 93 virtual void StopGettingPorts() = 0; |
94 // Only stop the existing gathering process but may start new ones if needed. | 94 // Only stop the existing gathering process but may start new ones if needed. |
95 virtual void ClearGettingPorts() = 0; | 95 virtual void ClearGettingPorts() = 0; |
96 // Whether the process of getting ports has been stopped. | 96 // Whether the process of getting ports has been stopped. |
97 virtual bool IsGettingPorts() = 0; | 97 virtual bool IsGettingPorts() = 0; |
98 | 98 |
99 sigslot::signal2<PortAllocatorSession*, PortInterface*> SignalPortReady; | 99 sigslot::signal2<PortAllocatorSession*, PortInterface*> SignalPortReady; |
100 sigslot::signal2<PortAllocatorSession*, | 100 sigslot::signal2<PortAllocatorSession*, |
101 const std::vector<Candidate>&> SignalCandidatesReady; | 101 const std::vector<Candidate>&> SignalCandidatesReady; |
102 sigslot::signal1<PortAllocatorSession*> SignalCandidatesAllocationDone; | 102 sigslot::signal1<PortAllocatorSession*> SignalCandidatesAllocationDone; |
103 | 103 |
104 virtual uint32 generation() { return generation_; } | 104 virtual uint32_t generation() { return generation_; } |
105 virtual void set_generation(uint32 generation) { generation_ = generation; } | 105 virtual void set_generation(uint32_t generation) { generation_ = generation; } |
106 sigslot::signal1<PortAllocatorSession*> SignalDestroyed; | 106 sigslot::signal1<PortAllocatorSession*> SignalDestroyed; |
107 | 107 |
108 const std::string& ice_ufrag() const { return ice_ufrag_; } | 108 const std::string& ice_ufrag() const { return ice_ufrag_; } |
109 const std::string& ice_pwd() const { return ice_pwd_; } | 109 const std::string& ice_pwd() const { return ice_pwd_; } |
110 | 110 |
111 protected: | 111 protected: |
112 // TODO(deadbeef): Get rid of these when everyone switches to ice_ufrag and | 112 // TODO(deadbeef): Get rid of these when everyone switches to ice_ufrag and |
113 // ice_pwd. | 113 // ice_pwd. |
114 const std::string& username() const { return ice_ufrag_; } | 114 const std::string& username() const { return ice_ufrag_; } |
115 const std::string& password() const { return ice_pwd_; } | 115 const std::string& password() const { return ice_pwd_; } |
116 | 116 |
117 std::string content_name_; | 117 std::string content_name_; |
118 int component_; | 118 int component_; |
119 | 119 |
120 private: | 120 private: |
121 uint32 flags_; | 121 uint32_t flags_; |
122 uint32 generation_; | 122 uint32_t generation_; |
123 std::string ice_ufrag_; | 123 std::string ice_ufrag_; |
124 std::string ice_pwd_; | 124 std::string ice_pwd_; |
125 }; | 125 }; |
126 | 126 |
127 class PortAllocator : public sigslot::has_slots<> { | 127 class PortAllocator : public sigslot::has_slots<> { |
128 public: | 128 public: |
129 PortAllocator() : | 129 PortAllocator() : |
130 flags_(kDefaultPortAllocatorFlags), | 130 flags_(kDefaultPortAllocatorFlags), |
131 min_port_(0), | 131 min_port_(0), |
132 max_port_(0), | 132 max_port_(0), |
133 step_delay_(kDefaultStepDelay), | 133 step_delay_(kDefaultStepDelay), |
134 allow_tcp_listen_(true), | 134 allow_tcp_listen_(true), |
135 candidate_filter_(CF_ALL) { | 135 candidate_filter_(CF_ALL) { |
136 // This will allow us to have old behavior on non webrtc clients. | 136 // This will allow us to have old behavior on non webrtc clients. |
137 } | 137 } |
138 virtual ~PortAllocator() {} | 138 virtual ~PortAllocator() {} |
139 | 139 |
140 PortAllocatorSession* CreateSession( | 140 PortAllocatorSession* CreateSession( |
141 const std::string& sid, | 141 const std::string& sid, |
142 const std::string& content_name, | 142 const std::string& content_name, |
143 int component, | 143 int component, |
144 const std::string& ice_ufrag, | 144 const std::string& ice_ufrag, |
145 const std::string& ice_pwd); | 145 const std::string& ice_pwd); |
146 | 146 |
147 uint32 flags() const { return flags_; } | 147 uint32_t flags() const { return flags_; } |
148 void set_flags(uint32 flags) { flags_ = flags; } | 148 void set_flags(uint32_t flags) { flags_ = flags; } |
149 | 149 |
150 const std::string& user_agent() const { return agent_; } | 150 const std::string& user_agent() const { return agent_; } |
151 const rtc::ProxyInfo& proxy() const { return proxy_; } | 151 const rtc::ProxyInfo& proxy() const { return proxy_; } |
152 void set_proxy(const std::string& agent, const rtc::ProxyInfo& proxy) { | 152 void set_proxy(const std::string& agent, const rtc::ProxyInfo& proxy) { |
153 agent_ = agent; | 153 agent_ = agent; |
154 proxy_ = proxy; | 154 proxy_ = proxy; |
155 } | 155 } |
156 | 156 |
157 // Gets/Sets the port range to use when choosing client ports. | 157 // Gets/Sets the port range to use when choosing client ports. |
158 int min_port() const { return min_port_; } | 158 int min_port() const { return min_port_; } |
159 int max_port() const { return max_port_; } | 159 int max_port() const { return max_port_; } |
160 bool SetPortRange(int min_port, int max_port) { | 160 bool SetPortRange(int min_port, int max_port) { |
161 if (min_port > max_port) { | 161 if (min_port > max_port) { |
162 return false; | 162 return false; |
163 } | 163 } |
164 | 164 |
165 min_port_ = min_port; | 165 min_port_ = min_port; |
166 max_port_ = max_port; | 166 max_port_ = max_port; |
167 return true; | 167 return true; |
168 } | 168 } |
169 | 169 |
170 uint32 step_delay() const { return step_delay_; } | 170 uint32_t step_delay() const { return step_delay_; } |
171 void set_step_delay(uint32 delay) { | 171 void set_step_delay(uint32_t delay) { step_delay_ = delay; } |
172 step_delay_ = delay; | |
173 } | |
174 | 172 |
175 bool allow_tcp_listen() const { return allow_tcp_listen_; } | 173 bool allow_tcp_listen() const { return allow_tcp_listen_; } |
176 void set_allow_tcp_listen(bool allow_tcp_listen) { | 174 void set_allow_tcp_listen(bool allow_tcp_listen) { |
177 allow_tcp_listen_ = allow_tcp_listen; | 175 allow_tcp_listen_ = allow_tcp_listen; |
178 } | 176 } |
179 | 177 |
180 uint32 candidate_filter() { return candidate_filter_; } | 178 uint32_t candidate_filter() { return candidate_filter_; } |
181 bool set_candidate_filter(uint32 filter) { | 179 bool set_candidate_filter(uint32_t filter) { |
182 // TODO(mallinath) - Do transition check? | 180 // TODO(mallinath) - Do transition check? |
183 candidate_filter_ = filter; | 181 candidate_filter_ = filter; |
184 return true; | 182 return true; |
185 } | 183 } |
186 | 184 |
187 // Gets/Sets the Origin value used for WebRTC STUN requests. | 185 // Gets/Sets the Origin value used for WebRTC STUN requests. |
188 const std::string& origin() const { return origin_; } | 186 const std::string& origin() const { return origin_; } |
189 void set_origin(const std::string& origin) { origin_ = origin; } | 187 void set_origin(const std::string& origin) { origin_ = origin; } |
190 | 188 |
191 protected: | 189 protected: |
192 virtual PortAllocatorSession* CreateSessionInternal( | 190 virtual PortAllocatorSession* CreateSessionInternal( |
193 const std::string& content_name, | 191 const std::string& content_name, |
194 int component, | 192 int component, |
195 const std::string& ice_ufrag, | 193 const std::string& ice_ufrag, |
196 const std::string& ice_pwd) = 0; | 194 const std::string& ice_pwd) = 0; |
197 | 195 |
198 uint32 flags_; | 196 uint32_t flags_; |
199 std::string agent_; | 197 std::string agent_; |
200 rtc::ProxyInfo proxy_; | 198 rtc::ProxyInfo proxy_; |
201 int min_port_; | 199 int min_port_; |
202 int max_port_; | 200 int max_port_; |
203 uint32 step_delay_; | 201 uint32_t step_delay_; |
204 bool allow_tcp_listen_; | 202 bool allow_tcp_listen_; |
205 uint32 candidate_filter_; | 203 uint32_t candidate_filter_; |
206 std::string origin_; | 204 std::string origin_; |
207 }; | 205 }; |
208 | 206 |
209 } // namespace cricket | 207 } // namespace cricket |
210 | 208 |
211 #endif // WEBRTC_P2P_BASE_PORTALLOCATOR_H_ | 209 #endif // WEBRTC_P2P_BASE_PORTALLOCATOR_H_ |
OLD | NEW |