| 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 81 |
| 82 // CF = CANDIDATE FILTER | 82 // CF = CANDIDATE FILTER |
| 83 enum { | 83 enum { |
| 84 CF_NONE = 0x0, | 84 CF_NONE = 0x0, |
| 85 CF_HOST = 0x1, | 85 CF_HOST = 0x1, |
| 86 CF_REFLEXIVE = 0x2, | 86 CF_REFLEXIVE = 0x2, |
| 87 CF_RELAY = 0x4, | 87 CF_RELAY = 0x4, |
| 88 CF_ALL = 0x7, | 88 CF_ALL = 0x7, |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 enum class SessionState { | |
| 92 GATHERING, // Actively allocating ports and gathering candidates. | |
| 93 CLEARED, // Current allocation process has been stopped but may start | |
| 94 // new ones. | |
| 95 STOPPED // This session has completely stopped, no new allocation | |
| 96 // process will be started. | |
| 97 }; | |
| 98 | |
| 99 // TODO(deadbeef): Rename to TurnCredentials (and username to ufrag). | 91 // TODO(deadbeef): Rename to TurnCredentials (and username to ufrag). |
| 100 struct RelayCredentials { | 92 struct RelayCredentials { |
| 101 RelayCredentials() {} | 93 RelayCredentials() {} |
| 102 RelayCredentials(const std::string& username, const std::string& password) | 94 RelayCredentials(const std::string& username, const std::string& password) |
| 103 : username(username), password(password) {} | 95 : username(username), password(password) {} |
| 104 | 96 |
| 105 bool operator==(const RelayCredentials& o) const { | 97 bool operator==(const RelayCredentials& o) const { |
| 106 return username == o.username && password == o.password; | 98 return username == o.username && password == o.password; |
| 107 } | 99 } |
| 108 bool operator!=(const RelayCredentials& o) const { return !(*this == o); } | 100 bool operator!=(const RelayCredentials& o) const { return !(*this == o); } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 bool pooled() const { return ice_ufrag_.empty(); } | 152 bool pooled() const { return ice_ufrag_.empty(); } |
| 161 | 153 |
| 162 // Setting this filter should affect not only candidates gathered in the | 154 // Setting this filter should affect not only candidates gathered in the |
| 163 // future, but candidates already gathered and ports already "ready", | 155 // future, but candidates already gathered and ports already "ready", |
| 164 // which would be returned by ReadyCandidates() and ReadyPorts(). | 156 // which would be returned by ReadyCandidates() and ReadyPorts(). |
| 165 // | 157 // |
| 166 // Default filter should be CF_ALL. | 158 // Default filter should be CF_ALL. |
| 167 virtual void SetCandidateFilter(uint32_t filter) = 0; | 159 virtual void SetCandidateFilter(uint32_t filter) = 0; |
| 168 | 160 |
| 169 // Starts gathering STUN and Relay configurations. | 161 // Starts gathering STUN and Relay configurations. |
| 170 virtual void StartGettingPorts() { state_ = SessionState::GATHERING; } | 162 virtual void StartGettingPorts() = 0; |
| 171 // Completely stops the gathering process and will not start new ones. | 163 // Completely stops the gathering process and will not start new ones. |
| 172 virtual void StopGettingPorts() { state_ = SessionState::STOPPED; } | 164 virtual void StopGettingPorts() = 0; |
| 165 // Whether the session is actively getting ports. |
| 166 virtual bool IsGettingPorts() = 0; |
| 167 // ClearGettingPorts and IsCleared are used by continual gathering. |
| 173 // Only stops the existing gathering process but may start new ones if needed. | 168 // Only stops the existing gathering process but may start new ones if needed. |
| 174 virtual void ClearGettingPorts() { state_ = SessionState::CLEARED; } | 169 virtual void ClearGettingPorts() = 0; |
| 175 // Whether the session is actively getting ports. | |
| 176 bool IsGettingPorts() { return state_ == SessionState::GATHERING; } | |
| 177 // Whether it is in the state where the existing gathering process is stopped, | 170 // Whether it is in the state where the existing gathering process is stopped, |
| 178 // but new ones may be started (basically after calling ClearGettingPorts). | 171 // but new ones may be started (basically after calling ClearGettingPorts). |
| 179 bool IsCleared() { return state_ == SessionState::CLEARED; } | 172 virtual bool IsCleared() const { return false; } |
| 180 // Whether the session has completely stopped. | 173 // Whether the session has completely stopped. |
| 181 bool IsStopped() { return state_ == SessionState::STOPPED; } | 174 virtual bool IsStopped() const { return false; } |
| 182 // Re-gathers candidates on networks that do not have any connections. More | 175 // Re-gathers candidates on networks that do not have any connections. More |
| 183 // precisely, a network interface may have more than one IP addresses (e.g., | 176 // precisely, a network interface may have more than one IP addresses (e.g., |
| 184 // IPv4 and IPv6 addresses). Each address subnet will be used to create a | 177 // IPv4 and IPv6 addresses). Each address subnet will be used to create a |
| 185 // network. Only if all networks of an interface have no connection, the | 178 // network. Only if all networks of an interface have no connection, the |
| 186 // implementation should start re-gathering on all networks of that interface. | 179 // implementation should start re-gathering on all networks of that interface. |
| 187 virtual void RegatherOnFailedNetworks() {} | 180 virtual void RegatherOnFailedNetworks() {} |
| 188 // Re-gathers candidates on all networks. | 181 // Re-gathers candidates on all networks. |
| 189 // TODO(honghaiz): Implement this in BasicPortAllocator. | 182 // TODO(honghaiz): Implement this in BasicPortAllocator. |
| 190 virtual void RegatherOnAllNetworks() {} | 183 virtual void RegatherOnAllNetworks() {} |
| 191 | 184 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 ice_pwd_ = ice_pwd; | 238 ice_pwd_ = ice_pwd; |
| 246 UpdateIceParametersInternal(); | 239 UpdateIceParametersInternal(); |
| 247 } | 240 } |
| 248 | 241 |
| 249 uint32_t flags_; | 242 uint32_t flags_; |
| 250 uint32_t generation_; | 243 uint32_t generation_; |
| 251 std::string content_name_; | 244 std::string content_name_; |
| 252 int component_; | 245 int component_; |
| 253 std::string ice_ufrag_; | 246 std::string ice_ufrag_; |
| 254 std::string ice_pwd_; | 247 std::string ice_pwd_; |
| 255 SessionState state_ = SessionState::CLEARED; | |
| 256 | 248 |
| 257 // SetIceParameters is an implementation detail which only PortAllocator | 249 // SetIceParameters is an implementation detail which only PortAllocator |
| 258 // should be able to call. | 250 // should be able to call. |
| 259 friend class PortAllocator; | 251 friend class PortAllocator; |
| 260 }; | 252 }; |
| 261 | 253 |
| 262 // Every method of PortAllocator (including the destructor) must be called on | 254 // Every method of PortAllocator (including the destructor) must be called on |
| 263 // the same thread, except for the constructor which may be called on any | 255 // the same thread, except for the constructor which may be called on any |
| 264 // thread. | 256 // thread. |
| 265 // | 257 // |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 // This variable represents the total number of pooled sessions | 389 // This variable represents the total number of pooled sessions |
| 398 // both owned by this class and taken by TakePooledSession. | 390 // both owned by this class and taken by TakePooledSession. |
| 399 int allocated_pooled_session_count_ = 0; | 391 int allocated_pooled_session_count_ = 0; |
| 400 std::deque<std::unique_ptr<PortAllocatorSession>> pooled_sessions_; | 392 std::deque<std::unique_ptr<PortAllocatorSession>> pooled_sessions_; |
| 401 bool prune_turn_ports_ = false; | 393 bool prune_turn_ports_ = false; |
| 402 }; | 394 }; |
| 403 | 395 |
| 404 } // namespace cricket | 396 } // namespace cricket |
| 405 | 397 |
| 406 #endif // WEBRTC_P2P_BASE_PORTALLOCATOR_H_ | 398 #endif // WEBRTC_P2P_BASE_PORTALLOCATOR_H_ |
| OLD | NEW |