| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 // TODO(deadbeef): Unify with PeerConnectionInterface::IceConnectionState | 59 // TODO(deadbeef): Unify with PeerConnectionInterface::IceConnectionState |
| 60 // once /talk/ and /webrtc/ are combined, and also switch to ENUM_NAME naming | 60 // once /talk/ and /webrtc/ are combined, and also switch to ENUM_NAME naming |
| 61 // style. | 61 // style. |
| 62 enum IceGatheringState { | 62 enum IceGatheringState { |
| 63 kIceGatheringNew = 0, | 63 kIceGatheringNew = 0, |
| 64 kIceGatheringGathering, | 64 kIceGatheringGathering, |
| 65 kIceGatheringComplete, | 65 kIceGatheringComplete, |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 // For "writable" and "receiving", we need to differentiate between | |
| 69 // none, all, and some. | |
| 70 enum TransportState { | |
| 71 TRANSPORT_STATE_NONE = 0, | |
| 72 TRANSPORT_STATE_SOME, | |
| 73 TRANSPORT_STATE_ALL | |
| 74 }; | |
| 75 | |
| 76 // When checking transport state, we need to differentiate between | |
| 77 // "writable" or "receiving" check. | |
| 78 enum TransportStateType { | |
| 79 TRANSPORT_WRITABLE_STATE = 0, | |
| 80 TRANSPORT_RECEIVING_STATE | |
| 81 }; | |
| 82 | |
| 83 // Stats that we can return about the connections for a transport channel. | 68 // Stats that we can return about the connections for a transport channel. |
| 84 // TODO(hta): Rename to ConnectionStats | 69 // TODO(hta): Rename to ConnectionStats |
| 85 struct ConnectionInfo { | 70 struct ConnectionInfo { |
| 86 ConnectionInfo() | 71 ConnectionInfo() |
| 87 : best_connection(false), | 72 : best_connection(false), |
| 88 writable(false), | 73 writable(false), |
| 89 receiving(false), | 74 receiving(false), |
| 90 timeout(false), | 75 timeout(false), |
| 91 new_connection(false), | 76 new_connection(false), |
| 92 rtt(0), | 77 rtt(0), |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 public: | 143 public: |
| 159 Transport(const std::string& name, PortAllocator* allocator); | 144 Transport(const std::string& name, PortAllocator* allocator); |
| 160 virtual ~Transport(); | 145 virtual ~Transport(); |
| 161 | 146 |
| 162 // Returns the name of this transport. | 147 // Returns the name of this transport. |
| 163 const std::string& name() const { return name_; } | 148 const std::string& name() const { return name_; } |
| 164 | 149 |
| 165 // Returns the port allocator object for this transport. | 150 // Returns the port allocator object for this transport. |
| 166 PortAllocator* port_allocator() { return allocator_; } | 151 PortAllocator* port_allocator() { return allocator_; } |
| 167 | 152 |
| 168 // Returns the states of this manager. These bits are the ORs | |
| 169 // of the corresponding bits on the managed channels. Each time one of these | |
| 170 // states changes, a signal is raised. | |
| 171 // TODO(honghaiz): Replace uses of writable() with any_channels_writable(). | |
| 172 bool writable() const { return any_channels_writable(); } | |
| 173 bool was_writable() const { return was_writable_; } | |
| 174 bool any_channels_writable() const { | |
| 175 return (writable_ == TRANSPORT_STATE_SOME || | |
| 176 writable_ == TRANSPORT_STATE_ALL); | |
| 177 } | |
| 178 bool all_channels_writable() const { | |
| 179 return (writable_ == TRANSPORT_STATE_ALL); | |
| 180 } | |
| 181 bool any_channel_receiving() const { | |
| 182 return (receiving_ == TRANSPORT_STATE_SOME || | |
| 183 receiving_ == TRANSPORT_STATE_ALL); | |
| 184 } | |
| 185 bool ready_for_remote_candidates() const { | 153 bool ready_for_remote_candidates() const { |
| 186 return local_description_set_ && remote_description_set_; | 154 return local_description_set_ && remote_description_set_; |
| 187 } | 155 } |
| 188 | 156 |
| 189 bool AllChannelsCompleted() const; | |
| 190 bool AnyChannelFailed() const; | |
| 191 | |
| 192 IceGatheringState gathering_state() const { return gathering_state_; } | |
| 193 | |
| 194 sigslot::signal1<Transport*> SignalWritableState; | |
| 195 sigslot::signal1<Transport*> SignalReceivingState; | |
| 196 sigslot::signal1<Transport*> SignalCompleted; | |
| 197 sigslot::signal1<Transport*> SignalFailed; | |
| 198 | |
| 199 // Returns whether the client has requested the channels to connect. | 157 // Returns whether the client has requested the channels to connect. |
| 200 bool connect_requested() const { return connect_requested_; } | 158 bool connect_requested() const { return connect_requested_; } |
| 201 | 159 |
| 202 void SetIceRole(IceRole role); | 160 void SetIceRole(IceRole role); |
| 203 IceRole ice_role() const { return ice_role_; } | 161 IceRole ice_role() const { return ice_role_; } |
| 204 | 162 |
| 205 void SetIceTiebreaker(uint64 IceTiebreaker) { tiebreaker_ = IceTiebreaker; } | 163 void SetIceTiebreaker(uint64 IceTiebreaker) { tiebreaker_ = IceTiebreaker; } |
| 206 uint64 IceTiebreaker() { return tiebreaker_; } | 164 uint64 IceTiebreaker() { return tiebreaker_; } |
| 207 | 165 |
| 208 void SetIceConfig(const IceConfig& config); | 166 void SetIceConfig(const IceConfig& config); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 222 | 180 |
| 223 // Create, destroy, and lookup the channels of this type by their components. | 181 // Create, destroy, and lookup the channels of this type by their components. |
| 224 TransportChannelImpl* CreateChannel(int component); | 182 TransportChannelImpl* CreateChannel(int component); |
| 225 | 183 |
| 226 TransportChannelImpl* GetChannel(int component); | 184 TransportChannelImpl* GetChannel(int component); |
| 227 | 185 |
| 228 bool HasChannel(int component) { | 186 bool HasChannel(int component) { |
| 229 return (NULL != GetChannel(component)); | 187 return (NULL != GetChannel(component)); |
| 230 } | 188 } |
| 231 bool HasChannels(); | 189 bool HasChannels(); |
| 232 void DestroyChannel(int component); | 190 |
| 191 // Returns true if channel was really destroyed, and false if its ref count |
| 192 // was just decremented, or it doesn't exist in the first place. |
| 193 bool DestroyChannel(int component); |
| 233 | 194 |
| 234 // Set the local TransportDescription to be used by TransportChannels. | 195 // Set the local TransportDescription to be used by TransportChannels. |
| 235 bool SetLocalTransportDescription(const TransportDescription& description, | 196 bool SetLocalTransportDescription(const TransportDescription& description, |
| 236 ContentAction action, | 197 ContentAction action, |
| 237 std::string* error_desc); | 198 std::string* error_desc); |
| 238 | 199 |
| 239 // Set the remote TransportDescription to be used by TransportChannels. | 200 // Set the remote TransportDescription to be used by TransportChannels. |
| 240 bool SetRemoteTransportDescription(const TransportDescription& description, | 201 bool SetRemoteTransportDescription(const TransportDescription& description, |
| 241 ContentAction action, | 202 ContentAction action, |
| 242 std::string* error_desc); | 203 std::string* error_desc); |
| 243 | 204 |
| 244 // Tells all current and future channels to start connecting. When the first | 205 // Tells all current and future channels to start connecting. |
| 245 // channel begins connecting, the following signal is raised. | |
| 246 void ConnectChannels(); | 206 void ConnectChannels(); |
| 247 sigslot::signal1<Transport*> SignalConnecting; | |
| 248 | 207 |
| 249 // Tells channels to start gathering candidates if necessary. | 208 // Tells channels to start gathering candidates if necessary. |
| 250 // Should be called after ConnectChannels() has been called at least once, | 209 // Should be called after ConnectChannels() has been called at least once, |
| 251 // which will happen in SetLocalTransportDescription. | 210 // which will happen in SetLocalTransportDescription. |
| 252 void MaybeStartGathering(); | 211 void MaybeStartGathering(); |
| 253 | 212 |
| 254 // Resets all of the channels back to their initial state. They are no | 213 // Resets all of the channels back to their initial state. They are no |
| 255 // longer connecting. | 214 // longer connecting. |
| 256 void ResetChannels(); | 215 void ResetChannels(); |
| 257 | 216 |
| 258 // Destroys every channel created so far. | 217 // Destroys every channel created so far. |
| 259 void DestroyAllChannels(); | 218 void DestroyAllChannels(); |
| 260 | 219 |
| 261 bool GetStats(TransportStats* stats); | 220 bool GetStats(TransportStats* stats); |
| 262 | 221 |
| 263 sigslot::signal1<Transport*> SignalGatheringState; | |
| 264 | |
| 265 // Handles sending of ready candidates and receiving of remote candidates. | |
| 266 sigslot::signal2<Transport*, const std::vector<Candidate>&> | |
| 267 SignalCandidatesGathered; | |
| 268 | |
| 269 // Called when one or more candidates are ready from the remote peer. | 222 // Called when one or more candidates are ready from the remote peer. |
| 270 bool AddRemoteCandidates(const std::vector<Candidate>& candidates, | 223 bool AddRemoteCandidates(const std::vector<Candidate>& candidates, |
| 271 std::string* error); | 224 std::string* error); |
| 272 | 225 |
| 273 // If candidate is not acceptable, returns false and sets error. | 226 // If candidate is not acceptable, returns false and sets error. |
| 274 // Call this before calling OnRemoteCandidates. | 227 // Call this before calling OnRemoteCandidates. |
| 275 virtual bool VerifyCandidate(const Candidate& candidate, | 228 virtual bool VerifyCandidate(const Candidate& candidate, |
| 276 std::string* error); | 229 std::string* error); |
| 277 | 230 |
| 278 // Signals when the best connection for a channel changes. | |
| 279 sigslot::signal3<Transport*, | |
| 280 int, // component | |
| 281 const Candidate&> SignalRouteChange; | |
| 282 | |
| 283 // Forwards the signal from TransportChannel to BaseSession. | |
| 284 sigslot::signal0<> SignalRoleConflict; | |
| 285 | |
| 286 virtual bool GetSslRole(rtc::SSLRole* ssl_role) const { return false; } | 231 virtual bool GetSslRole(rtc::SSLRole* ssl_role) const { return false; } |
| 287 | 232 |
| 288 // Must be called before channel is starting to connect. | 233 // Must be called before channel is starting to connect. |
| 289 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version) { | 234 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version) { |
| 290 return false; | 235 return false; |
| 291 } | 236 } |
| 292 | 237 |
| 293 protected: | 238 protected: |
| 294 // These are called by Create/DestroyChannel above in order to create or | 239 // These are called by Create/DestroyChannel above in order to create or |
| 295 // destroy the appropriate type of channel. | 240 // destroy the appropriate type of channel. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 TransportChannelImpl* operator->() const { return impl_; } | 298 TransportChannelImpl* operator->() const { return impl_; } |
| 354 | 299 |
| 355 private: | 300 private: |
| 356 TransportChannelImpl* impl_; | 301 TransportChannelImpl* impl_; |
| 357 int ref_; | 302 int ref_; |
| 358 }; | 303 }; |
| 359 | 304 |
| 360 // Candidate component => ChannelMapEntry | 305 // Candidate component => ChannelMapEntry |
| 361 typedef std::map<int, ChannelMapEntry> ChannelMap; | 306 typedef std::map<int, ChannelMapEntry> ChannelMap; |
| 362 | 307 |
| 363 // Called when the write state of a channel changes. | |
| 364 void OnChannelWritableState(TransportChannel* channel); | |
| 365 | |
| 366 // Called when the receiving state of a channel changes. | |
| 367 void OnChannelReceivingState(TransportChannel* channel); | |
| 368 | |
| 369 // Called when a channel starts finishes gathering candidates | |
| 370 void OnChannelGatheringState(TransportChannelImpl* channel); | |
| 371 | |
| 372 // Called when a candidate is ready from channel. | |
| 373 void OnChannelCandidateGathered(TransportChannelImpl* channel, | |
| 374 const Candidate& candidate); | |
| 375 void OnChannelRouteChange(TransportChannel* channel, | |
| 376 const Candidate& remote_candidate); | |
| 377 // Called when there is ICE role change. | |
| 378 void OnRoleConflict(TransportChannelImpl* channel); | |
| 379 // Called when the channel removes a connection. | |
| 380 void OnChannelConnectionRemoved(TransportChannelImpl* channel); | |
| 381 | |
| 382 // Helper function that invokes the given function on every channel. | 308 // Helper function that invokes the given function on every channel. |
| 383 typedef void (TransportChannelImpl::* TransportChannelFunc)(); | 309 typedef void (TransportChannelImpl::* TransportChannelFunc)(); |
| 384 void CallChannels(TransportChannelFunc func); | 310 void CallChannels(TransportChannelFunc func); |
| 385 | 311 |
| 386 // Computes the AND and OR of the channel's read/write/receiving state | |
| 387 // (argument picks the operation). | |
| 388 TransportState GetTransportState(TransportStateType type); | |
| 389 | |
| 390 // Sends SignalCompleted if we are now in that state. | |
| 391 void MaybeSignalCompleted(); | |
| 392 | |
| 393 // Sends SignalGatheringState if gathering state changed | |
| 394 void UpdateGatheringState(); | |
| 395 | |
| 396 void UpdateWritableState(); | |
| 397 void UpdateReceivingState(); | |
| 398 | |
| 399 const std::string name_; | 312 const std::string name_; |
| 400 PortAllocator* const allocator_; | 313 PortAllocator* const allocator_; |
| 401 bool channels_destroyed_ = false; | 314 bool channels_destroyed_ = false; |
| 402 TransportState readable_ = TRANSPORT_STATE_NONE; | |
| 403 TransportState writable_ = TRANSPORT_STATE_NONE; | |
| 404 TransportState receiving_ = TRANSPORT_STATE_NONE; | |
| 405 bool was_writable_ = false; | |
| 406 bool connect_requested_ = false; | 315 bool connect_requested_ = false; |
| 407 IceRole ice_role_ = ICEROLE_UNKNOWN; | 316 IceRole ice_role_ = ICEROLE_UNKNOWN; |
| 408 uint64 tiebreaker_ = 0; | 317 uint64 tiebreaker_ = 0; |
| 409 IceMode remote_ice_mode_ = ICEMODE_FULL; | 318 IceMode remote_ice_mode_ = ICEMODE_FULL; |
| 410 IceConfig ice_config_; | 319 IceConfig ice_config_; |
| 411 rtc::scoped_ptr<TransportDescription> local_description_; | 320 rtc::scoped_ptr<TransportDescription> local_description_; |
| 412 rtc::scoped_ptr<TransportDescription> remote_description_; | 321 rtc::scoped_ptr<TransportDescription> remote_description_; |
| 413 bool local_description_set_ = false; | 322 bool local_description_set_ = false; |
| 414 bool remote_description_set_ = false; | 323 bool remote_description_set_ = false; |
| 415 IceGatheringState gathering_state_ = kIceGatheringNew; | |
| 416 | 324 |
| 417 ChannelMap channels_; | 325 ChannelMap channels_; |
| 418 | 326 |
| 419 RTC_DISALLOW_COPY_AND_ASSIGN(Transport); | 327 RTC_DISALLOW_COPY_AND_ASSIGN(Transport); |
| 420 }; | 328 }; |
| 421 | 329 |
| 422 | 330 |
| 423 } // namespace cricket | 331 } // namespace cricket |
| 424 | 332 |
| 425 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_ | 333 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_ |
| OLD | NEW |