| 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 // A Transport manages a set of named channels of the same type. | 11 // A Transport manages a set of named channels of the same type. |
| 12 // | 12 // |
| 13 // Subclasses choose the appropriate class to instantiate for each channel; | 13 // Subclasses choose the appropriate class to instantiate for each channel; |
| 14 // however, this base class keeps track of the channels by name, watches their | 14 // however, this base class keeps track of the channels by name, watches their |
| 15 // state changes (in order to update the manager's state), and forwards | 15 // state changes (in order to update the manager's state), and forwards |
| 16 // requests to begin connecting or to reset to each of the channels. | 16 // requests to begin connecting or to reset to each of the channels. |
| 17 // | 17 // |
| 18 // On Threading: Transport performs work on both the signaling and worker | 18 // On Threading: Transport performs work solely on the worker thread, and so |
| 19 // threads. For subclasses, the rule is that all signaling related calls will | 19 // its methods should only be called on the worker thread. |
| 20 // be made on the signaling thread and all channel related calls (including | |
| 21 // signaling for a channel) will be made on the worker thread. When | |
| 22 // information needs to be sent between the two threads, this class should do | |
| 23 // the work (e.g., OnRemoteCandidate). | |
| 24 // | 20 // |
| 25 // Note: Subclasses must call DestroyChannels() in their own constructors. | 21 // Note: Subclasses must call DestroyChannels() in their own destructors. |
| 26 // It is not possible to do so here because the subclass constructor will | 22 // It is not possible to do so here because the subclass destructor will |
| 27 // already have run. | 23 // already have run. |
| 28 | 24 |
| 29 #ifndef WEBRTC_P2P_BASE_TRANSPORT_H_ | 25 #ifndef WEBRTC_P2P_BASE_TRANSPORT_H_ |
| 30 #define WEBRTC_P2P_BASE_TRANSPORT_H_ | 26 #define WEBRTC_P2P_BASE_TRANSPORT_H_ |
| 31 | 27 |
| 32 #include <map> | 28 #include <map> |
| 33 #include <string> | 29 #include <string> |
| 34 #include <vector> | 30 #include <vector> |
| 35 #include "webrtc/p2p/base/candidate.h" | 31 #include "webrtc/p2p/base/candidate.h" |
| 36 #include "webrtc/p2p/base/constants.h" | 32 #include "webrtc/p2p/base/constants.h" |
| 37 #include "webrtc/p2p/base/sessiondescription.h" | 33 #include "webrtc/p2p/base/sessiondescription.h" |
| 38 #include "webrtc/p2p/base/transportinfo.h" | 34 #include "webrtc/p2p/base/transportinfo.h" |
| 39 #include "webrtc/base/criticalsection.h" | |
| 40 #include "webrtc/base/messagequeue.h" | 35 #include "webrtc/base/messagequeue.h" |
| 41 #include "webrtc/base/rtccertificate.h" | 36 #include "webrtc/base/rtccertificate.h" |
| 42 #include "webrtc/base/sigslot.h" | 37 #include "webrtc/base/sigslot.h" |
| 43 #include "webrtc/base/sslstreamadapter.h" | 38 #include "webrtc/base/sslstreamadapter.h" |
| 44 | 39 |
| 45 namespace rtc { | |
| 46 class Thread; | |
| 47 } | |
| 48 | |
| 49 namespace cricket { | 40 namespace cricket { |
| 50 | 41 |
| 51 class PortAllocator; | 42 class PortAllocator; |
| 52 class TransportChannel; | 43 class TransportChannel; |
| 53 class TransportChannelImpl; | 44 class TransportChannelImpl; |
| 54 | 45 |
| 55 typedef std::vector<Candidate> Candidates; | 46 typedef std::vector<Candidate> Candidates; |
| 56 | 47 |
| 48 // TODO(deadbeef): Unify with PeerConnectionInterface::IceConnectionState |
| 49 // once /talk/ and /webrtc/ are combined, and also switch to ENUM_NAME naming |
| 50 // style |
| 51 enum IceConnectionState { |
| 52 kIceConnectionConnecting = 0, |
| 53 kIceConnectionFailed, |
| 54 kIceConnectionConnected, // Writable, but still checking one or more |
| 55 // connections |
| 56 kIceConnectionCompleted, |
| 57 }; |
| 58 |
| 59 // TODO(deadbeef): Unify with PeerConnectionInterface::IceConnectionState |
| 60 // once /talk/ and /webrtc/ are combined, and also switch to ENUM_NAME naming |
| 61 // style |
| 62 enum IceGatheringState { |
| 63 kIceGatheringNew = 0, |
| 64 kIceGatheringGathering, |
| 65 kIceGatheringComplete, |
| 66 }; |
| 67 |
| 57 // For "writable", "readable", and "receiving", we need to differentiate between | 68 // For "writable", "readable", and "receiving", we need to differentiate between |
| 58 // none, all, and some. | 69 // none, all, and some. |
| 59 enum TransportState { | 70 enum TransportState { |
| 60 TRANSPORT_STATE_NONE = 0, | 71 TRANSPORT_STATE_NONE = 0, |
| 61 TRANSPORT_STATE_SOME, | 72 TRANSPORT_STATE_SOME, |
| 62 TRANSPORT_STATE_ALL | 73 TRANSPORT_STATE_ALL |
| 63 }; | 74 }; |
| 64 | 75 |
| 65 // When checking transport state, we need to differentiate between | 76 // When checking transport state, we need to differentiate between |
| 66 // "readable", "writable", or "receiving" check. | 77 // "readable", "writable", or "receiving" check. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 std::string srtp_cipher; | 129 std::string srtp_cipher; |
| 119 std::string ssl_cipher; | 130 std::string ssl_cipher; |
| 120 }; | 131 }; |
| 121 | 132 |
| 122 // Information about all the channels of a transport. | 133 // Information about all the channels of a transport. |
| 123 // TODO(hta): Consider if a simple vector is as good as a map. | 134 // TODO(hta): Consider if a simple vector is as good as a map. |
| 124 typedef std::vector<TransportChannelStats> TransportChannelStatsList; | 135 typedef std::vector<TransportChannelStats> TransportChannelStatsList; |
| 125 | 136 |
| 126 // Information about the stats of a transport. | 137 // Information about the stats of a transport. |
| 127 struct TransportStats { | 138 struct TransportStats { |
| 128 std::string content_name; | 139 std::string transport_name; |
| 129 TransportChannelStatsList channel_stats; | 140 TransportChannelStatsList channel_stats; |
| 130 }; | 141 }; |
| 131 | 142 |
| 132 bool BadTransportDescription(const std::string& desc, std::string* err_desc); | 143 bool BadTransportDescription(const std::string& desc, std::string* err_desc); |
| 133 | 144 |
| 134 bool IceCredentialsChanged(const std::string& old_ufrag, | 145 bool IceCredentialsChanged(const std::string& old_ufrag, |
| 135 const std::string& old_pwd, | 146 const std::string& old_pwd, |
| 136 const std::string& new_ufrag, | 147 const std::string& new_ufrag, |
| 137 const std::string& new_pwd); | 148 const std::string& new_pwd); |
| 138 | 149 |
| 139 class Transport : public rtc::MessageHandler, | 150 class Transport : public sigslot::has_slots<> { |
| 140 public sigslot::has_slots<> { | |
| 141 public: | 151 public: |
| 142 Transport(rtc::Thread* signaling_thread, | 152 Transport(const std::string& name, PortAllocator* allocator); |
| 143 rtc::Thread* worker_thread, | |
| 144 const std::string& content_name, | |
| 145 PortAllocator* allocator); | |
| 146 virtual ~Transport(); | 153 virtual ~Transport(); |
| 147 | 154 |
| 148 // Returns the signaling thread. The app talks to Transport on this thread. | 155 // Returns the name of this transport. |
| 149 rtc::Thread* signaling_thread() const { return signaling_thread_; } | 156 const std::string& name() const { return name_; } |
| 150 // Returns the worker thread. The actual networking is done on this thread. | |
| 151 rtc::Thread* worker_thread() const { return worker_thread_; } | |
| 152 | |
| 153 // Returns the content_name of this transport. | |
| 154 const std::string& content_name() const { return content_name_; } | |
| 155 | 157 |
| 156 // Returns the port allocator object for this transport. | 158 // Returns the port allocator object for this transport. |
| 157 PortAllocator* port_allocator() { return allocator_; } | 159 PortAllocator* port_allocator() { return allocator_; } |
| 158 | 160 |
| 159 // Returns the readable and states of this manager. These bits are the ORs | 161 // Returns the readable and states of this manager. These bits are the ORs |
| 160 // of the corresponding bits on the managed channels. Each time one of these | 162 // of the corresponding bits on the managed channels. Each time one of these |
| 161 // states changes, a signal is raised. | 163 // states changes, a signal is raised. |
| 162 // TODO: Replace uses of readable() and writable() with | 164 // TODO: Replace uses of readable() and writable() with |
| 163 // any_channels_readable() and any_channels_writable(). | 165 // any_channels_readable() and any_channels_writable(). |
| 164 bool readable() const { return any_channels_readable(); } | 166 bool readable() const { return any_channels_readable(); } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 175 bool all_channels_readable() const { | 177 bool all_channels_readable() const { |
| 176 return (readable_ == TRANSPORT_STATE_ALL); | 178 return (readable_ == TRANSPORT_STATE_ALL); |
| 177 } | 179 } |
| 178 bool all_channels_writable() const { | 180 bool all_channels_writable() const { |
| 179 return (writable_ == TRANSPORT_STATE_ALL); | 181 return (writable_ == TRANSPORT_STATE_ALL); |
| 180 } | 182 } |
| 181 bool any_channel_receiving() const { | 183 bool any_channel_receiving() const { |
| 182 return (receiving_ == TRANSPORT_STATE_SOME || | 184 return (receiving_ == TRANSPORT_STATE_SOME || |
| 183 receiving_ == TRANSPORT_STATE_ALL); | 185 receiving_ == TRANSPORT_STATE_ALL); |
| 184 } | 186 } |
| 187 bool ready_for_remote_candidates() const { |
| 188 return local_description_set_ && remote_description_set_; |
| 189 } |
| 190 |
| 191 bool AllChannelsCompleted() const; |
| 192 bool AnyChannelFailed() const; |
| 193 |
| 194 IceGatheringState gathering_state() const { return gathering_state_; } |
| 185 | 195 |
| 186 sigslot::signal1<Transport*> SignalReadableState; | 196 sigslot::signal1<Transport*> SignalReadableState; |
| 187 sigslot::signal1<Transport*> SignalWritableState; | 197 sigslot::signal1<Transport*> SignalWritableState; |
| 188 sigslot::signal1<Transport*> SignalReceivingState; | 198 sigslot::signal1<Transport*> SignalReceivingState; |
| 189 sigslot::signal1<Transport*> SignalCompleted; | 199 sigslot::signal1<Transport*> SignalCompleted; |
| 190 sigslot::signal1<Transport*> SignalFailed; | 200 sigslot::signal1<Transport*> SignalFailed; |
| 191 | 201 |
| 192 // Returns whether the client has requested the channels to connect. | 202 // Returns whether the client has requested the channels to connect. |
| 193 bool connect_requested() const { return connect_requested_; } | 203 bool connect_requested() const { return connect_requested_; } |
| 194 | 204 |
| 195 void SetIceRole(IceRole role); | 205 void SetIceRole(IceRole role); |
| 196 IceRole ice_role() const { return ice_role_; } | 206 IceRole ice_role() const { return ice_role_; } |
| 197 | 207 |
| 198 void SetIceTiebreaker(uint64 IceTiebreaker) { tiebreaker_ = IceTiebreaker; } | 208 void SetIceTiebreaker(uint64 IceTiebreaker) { tiebreaker_ = IceTiebreaker; } |
| 199 uint64 IceTiebreaker() { return tiebreaker_; } | 209 uint64 IceTiebreaker() { return tiebreaker_; } |
| 200 | 210 |
| 201 void SetChannelReceivingTimeout(int timeout_ms); | 211 void SetChannelReceivingTimeout(int timeout_ms); |
| 202 | 212 |
| 203 // Must be called before applying local session description. | 213 // Must be called before applying local session description. |
| 204 void SetCertificate( | 214 virtual void SetLocalCertificate( |
| 205 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); | 215 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) {} |
| 206 | 216 |
| 207 // Get a copy of the local identity provided by SetIdentity. | 217 // Get a copy of the local certificate provided by SetLocalCertificate. |
| 208 bool GetCertificate(rtc::scoped_refptr<rtc::RTCCertificate>* certificate); | 218 virtual bool GetLocalCertificate( |
| 219 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { |
| 220 return false; |
| 221 } |
| 209 | 222 |
| 210 // Get a copy of the remote certificate in use by the specified channel. | 223 // Get a copy of the remote certificate in use by the specified channel. |
| 211 bool GetRemoteCertificate(rtc::SSLCertificate** cert); | 224 bool GetRemoteCertificate(rtc::SSLCertificate** cert); |
| 212 | 225 |
| 213 // Create, destroy, and lookup the channels of this type by their components. | 226 // Create, destroy, and lookup the channels of this type by their components. |
| 214 TransportChannelImpl* CreateChannel(int component); | 227 TransportChannelImpl* CreateChannel(int component); |
| 215 // Note: GetChannel may lead to race conditions, since the mutex is not held | 228 |
| 216 // after the pointer is returned. | |
| 217 TransportChannelImpl* GetChannel(int component); | 229 TransportChannelImpl* GetChannel(int component); |
| 218 // Note: HasChannel does not lead to race conditions, unlike GetChannel. | 230 |
| 219 bool HasChannel(int component) { | 231 bool HasChannel(int component) { |
| 220 return (NULL != GetChannel(component)); | 232 return (NULL != GetChannel(component)); |
| 221 } | 233 } |
| 222 bool HasChannels(); | 234 bool HasChannels(); |
| 223 void DestroyChannel(int component); | 235 void DestroyChannel(int component); |
| 224 | 236 |
| 225 // Set the local TransportDescription to be used by TransportChannels. | 237 // Set the local TransportDescription to be used by TransportChannels. |
| 226 // This should be called before ConnectChannels(). | 238 // This calls ConnectChannels internally, kicking off candidate gathering |
| 227 bool SetLocalTransportDescription(const TransportDescription& description, | 239 bool SetLocalTransportDescription(const TransportDescription& description, |
| 228 ContentAction action, | 240 ContentAction action, |
| 229 std::string* error_desc); | 241 std::string* error_desc); |
| 230 | 242 |
| 231 // Set the remote TransportDescription to be used by TransportChannels. | 243 // Set the remote TransportDescription to be used by TransportChannels. |
| 232 bool SetRemoteTransportDescription(const TransportDescription& description, | 244 bool SetRemoteTransportDescription(const TransportDescription& description, |
| 233 ContentAction action, | 245 ContentAction action, |
| 234 std::string* error_desc); | 246 std::string* error_desc); |
| 235 | 247 |
| 236 // Tells all current and future channels to start connecting. When the first | 248 // Tells all current and future channels to start connecting. When the first |
| 237 // channel begins connecting, the following signal is raised. | 249 // channel begins connecting, the following signal is raised. |
| 238 void ConnectChannels(); | 250 void ConnectChannels(); |
| 239 sigslot::signal1<Transport*> SignalConnecting; | 251 sigslot::signal1<Transport*> SignalConnecting; |
| 240 | 252 |
| 241 // Resets all of the channels back to their initial state. They are no | 253 // Resets all of the channels back to their initial state. They are no |
| 242 // longer connecting. | 254 // longer connecting. |
| 243 void ResetChannels(); | 255 void ResetChannels(); |
| 244 | 256 |
| 245 // Destroys every channel created so far. | 257 // Destroys every channel created so far. |
| 246 void DestroyAllChannels(); | 258 void DestroyAllChannels(); |
| 247 | 259 |
| 248 bool GetStats(TransportStats* stats); | 260 bool GetStats(TransportStats* stats); |
| 249 | 261 |
| 250 // Before any stanza is sent, the manager will request signaling. Once | 262 sigslot::signal1<Transport*> SignalGatheringState; |
| 251 // signaling is available, the client should call OnSignalingReady. Once | |
| 252 // this occurs, the transport (or its channels) can send any waiting stanzas. | |
| 253 // OnSignalingReady invokes OnTransportSignalingReady and then forwards this | |
| 254 // signal to each channel. | |
| 255 sigslot::signal1<Transport*> SignalRequestSignaling; | |
| 256 void OnSignalingReady(); | |
| 257 | 263 |
| 258 // Handles sending of ready candidates and receiving of remote candidates. | 264 // Handles sending of ready candidates and receiving of remote candidates. |
| 259 sigslot::signal2<Transport*, | 265 sigslot::signal2<Transport*, const std::vector<Candidate>&> |
| 260 const std::vector<Candidate>&> SignalCandidatesReady; | 266 SignalCandidatesGathered; |
| 261 | 267 |
| 262 sigslot::signal1<Transport*> SignalCandidatesAllocationDone; | 268 // Called when one or more candidates are ready from the remote peer. |
| 263 void OnRemoteCandidates(const std::vector<Candidate>& candidates); | 269 bool AddRemoteCandidates(const std::vector<Candidate>& candidates, |
| 270 std::string* error); |
| 264 | 271 |
| 265 // If candidate is not acceptable, returns false and sets error. | 272 // If candidate is not acceptable, returns false and sets error. |
| 266 // Call this before calling OnRemoteCandidates. | 273 // Call this before calling OnRemoteCandidates. |
| 267 virtual bool VerifyCandidate(const Candidate& candidate, | 274 virtual bool VerifyCandidate(const Candidate& candidate, |
| 268 std::string* error); | 275 std::string* error); |
| 269 | 276 |
| 270 // Signals when the best connection for a channel changes. | 277 // Signals when the best connection for a channel changes. |
| 271 sigslot::signal3<Transport*, | 278 sigslot::signal3<Transport*, |
| 272 int, // component | 279 int, // component |
| 273 const Candidate&> SignalRouteChange; | 280 const Candidate&> SignalRouteChange; |
| 274 | 281 |
| 275 // Forwards the signal from TransportChannel to BaseSession. | 282 // Forwards the signal from TransportChannel to BaseSession. |
| 276 sigslot::signal0<> SignalRoleConflict; | 283 sigslot::signal0<> SignalRoleConflict; |
| 277 | 284 |
| 278 virtual bool GetSslRole(rtc::SSLRole* ssl_role) const; | 285 virtual bool GetSslRole(rtc::SSLRole* ssl_role) const { return false; } |
| 279 | 286 |
| 280 // Must be called before channel is starting to connect. | 287 // Must be called before channel is starting to connect. |
| 281 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version); | 288 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version) { |
| 289 return false; |
| 290 } |
| 282 | 291 |
| 283 protected: | 292 protected: |
| 284 // These are called by Create/DestroyChannel above in order to create or | 293 // These are called by Create/DestroyChannel above in order to create or |
| 285 // destroy the appropriate type of channel. | 294 // destroy the appropriate type of channel. |
| 286 virtual TransportChannelImpl* CreateTransportChannel(int component) = 0; | 295 virtual TransportChannelImpl* CreateTransportChannel(int component) = 0; |
| 287 virtual void DestroyTransportChannel(TransportChannelImpl* channel) = 0; | 296 virtual void DestroyTransportChannel(TransportChannelImpl* channel) = 0; |
| 288 | 297 |
| 289 // Informs the subclass that we received the signaling ready message. | |
| 290 virtual void OnTransportSignalingReady() {} | |
| 291 | |
| 292 // The current local transport description, for use by derived classes | 298 // The current local transport description, for use by derived classes |
| 293 // when performing transport description negotiation. | 299 // when performing transport description negotiation. |
| 294 const TransportDescription* local_description() const { | 300 const TransportDescription* local_description() const { |
| 295 return local_description_.get(); | 301 return local_description_.get(); |
| 296 } | 302 } |
| 297 | 303 |
| 298 // The current remote transport description, for use by derived classes | 304 // The current remote transport description, for use by derived classes |
| 299 // when performing transport description negotiation. | 305 // when performing transport description negotiation. |
| 300 const TransportDescription* remote_description() const { | 306 const TransportDescription* remote_description() const { |
| 301 return remote_description_.get(); | 307 return remote_description_.get(); |
| 302 } | 308 } |
| 303 | 309 |
| 304 virtual void SetCertificate_w( | |
| 305 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) {} | |
| 306 | |
| 307 virtual bool GetCertificate_w( | |
| 308 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { | |
| 309 return false; | |
| 310 } | |
| 311 | |
| 312 // Pushes down the transport parameters from the local description, such | 310 // Pushes down the transport parameters from the local description, such |
| 313 // as the ICE ufrag and pwd. | 311 // as the ICE ufrag and pwd. |
| 314 // Derived classes can override, but must call the base as well. | 312 // Derived classes can override, but must call the base as well. |
| 315 virtual bool ApplyLocalTransportDescription_w(TransportChannelImpl* channel, | 313 virtual bool ApplyLocalTransportDescription(TransportChannelImpl* channel, |
| 316 std::string* error_desc); | 314 std::string* error_desc); |
| 317 | 315 |
| 318 // Pushes down remote ice credentials from the remote description to the | 316 // Pushes down remote ice credentials from the remote description to the |
| 319 // transport channel. | 317 // transport channel. |
| 320 virtual bool ApplyRemoteTransportDescription_w(TransportChannelImpl* ch, | 318 virtual bool ApplyRemoteTransportDescription(TransportChannelImpl* ch, |
| 321 std::string* error_desc); | 319 std::string* error_desc); |
| 322 | 320 |
| 323 // Negotiates the transport parameters based on the current local and remote | 321 // Negotiates the transport parameters based on the current local and remote |
| 324 // transport description, such as the ICE role to use, and whether DTLS | 322 // transport description, such as the ICE role to use, and whether DTLS |
| 325 // should be activated. | 323 // should be activated. |
| 326 // Derived classes can negotiate their specific parameters here, but must call | 324 // Derived classes can negotiate their specific parameters here, but must call |
| 327 // the base as well. | 325 // the base as well. |
| 328 virtual bool NegotiateTransportDescription_w(ContentAction local_role, | 326 virtual bool NegotiateTransportDescription(ContentAction local_role, |
| 329 std::string* error_desc); | 327 std::string* error_desc); |
| 330 | 328 |
| 331 // Pushes down the transport parameters obtained via negotiation. | 329 // Pushes down the transport parameters obtained via negotiation. |
| 332 // Derived classes can set their specific parameters here, but must call the | 330 // Derived classes can set their specific parameters here, but must call the |
| 333 // base as well. | 331 // base as well. |
| 334 virtual bool ApplyNegotiatedTransportDescription_w( | 332 virtual bool ApplyNegotiatedTransportDescription( |
| 335 TransportChannelImpl* channel, std::string* error_desc); | 333 TransportChannelImpl* channel, |
| 336 | 334 std::string* error_desc); |
| 337 virtual bool GetSslRole_w(rtc::SSLRole* ssl_role) const { | |
| 338 return false; | |
| 339 } | |
| 340 | |
| 341 virtual bool SetSslMaxProtocolVersion_w(rtc::SSLProtocolVersion version) { | |
| 342 return false; | |
| 343 } | |
| 344 | 335 |
| 345 private: | 336 private: |
| 346 struct ChannelMapEntry { | 337 struct ChannelMapEntry { |
| 347 ChannelMapEntry() : impl_(NULL), candidates_allocated_(false), ref_(0) {} | 338 ChannelMapEntry() : impl_(NULL), ref_(0) {} |
| 348 explicit ChannelMapEntry(TransportChannelImpl *impl) | 339 explicit ChannelMapEntry(TransportChannelImpl *impl) |
| 349 : impl_(impl), | 340 : impl_(impl), |
| 350 candidates_allocated_(false), | |
| 351 ref_(0) { | 341 ref_(0) { |
| 352 } | 342 } |
| 353 | 343 |
| 354 void AddRef() { ++ref_; } | 344 void AddRef() { ++ref_; } |
| 355 void DecRef() { | 345 void DecRef() { |
| 356 ASSERT(ref_ > 0); | 346 ASSERT(ref_ > 0); |
| 357 --ref_; | 347 --ref_; |
| 358 } | 348 } |
| 359 int ref() const { return ref_; } | 349 int ref() const { return ref_; } |
| 360 | 350 |
| 361 TransportChannelImpl* get() const { return impl_; } | 351 TransportChannelImpl* get() const { return impl_; } |
| 362 TransportChannelImpl* operator->() const { return impl_; } | 352 TransportChannelImpl* operator->() const { return impl_; } |
| 363 void set_candidates_allocated(bool status) { | |
| 364 candidates_allocated_ = status; | |
| 365 } | |
| 366 bool candidates_allocated() const { return candidates_allocated_; } | |
| 367 | 353 |
| 368 private: | 354 private: |
| 369 TransportChannelImpl *impl_; | 355 TransportChannelImpl* impl_; |
| 370 bool candidates_allocated_; | |
| 371 int ref_; | 356 int ref_; |
| 372 }; | 357 }; |
| 373 | 358 |
| 374 // Candidate component => ChannelMapEntry | 359 // Candidate component => ChannelMapEntry |
| 375 typedef std::map<int, ChannelMapEntry> ChannelMap; | 360 typedef std::map<int, ChannelMapEntry> ChannelMap; |
| 376 | 361 |
| 377 // Called when the state of a channel changes. | 362 // Called when the state of a channel changes. |
| 378 void OnChannelReadableState(TransportChannel* channel); | 363 void OnChannelReadableState(TransportChannel* channel); |
| 379 void OnChannelWritableState(TransportChannel* channel); | 364 void OnChannelWritableState(TransportChannel* channel); |
| 380 | 365 |
| 381 // Called when the receiving state of a channel changes. | 366 // Called when the receiving state of a channel changes. |
| 382 void OnChannelReceivingState(TransportChannel* channel); | 367 void OnChannelReceivingState(TransportChannel* channel); |
| 383 | 368 |
| 384 // Called when a channel requests signaling. | 369 // Called when a channel starts finishes gathering candidates |
| 385 void OnChannelRequestSignaling(TransportChannelImpl* channel); | 370 void OnChannelGatheringState(TransportChannelImpl* channel); |
| 386 | 371 |
| 387 // Called when a candidate is ready from remote peer. | |
| 388 void OnRemoteCandidate(const Candidate& candidate); | |
| 389 // Called when a candidate is ready from channel. | 372 // Called when a candidate is ready from channel. |
| 390 void OnChannelCandidateReady(TransportChannelImpl* channel, | 373 void OnChannelCandidateGathered(TransportChannelImpl* channel, |
| 391 const Candidate& candidate); | 374 const Candidate& candidate); |
| 392 void OnChannelRouteChange(TransportChannel* channel, | 375 void OnChannelRouteChange(TransportChannel* channel, |
| 393 const Candidate& remote_candidate); | 376 const Candidate& remote_candidate); |
| 394 void OnChannelCandidatesAllocationDone(TransportChannelImpl* channel); | |
| 395 // Called when there is ICE role change. | 377 // Called when there is ICE role change. |
| 396 void OnRoleConflict(TransportChannelImpl* channel); | 378 void OnRoleConflict(TransportChannelImpl* channel); |
| 397 // Called when the channel removes a connection. | 379 // Called when the channel removes a connection. |
| 398 void OnChannelConnectionRemoved(TransportChannelImpl* channel); | 380 void OnChannelConnectionRemoved(TransportChannelImpl* channel); |
| 399 | 381 |
| 400 // Dispatches messages to the appropriate handler (below). | |
| 401 void OnMessage(rtc::Message* msg); | |
| 402 | |
| 403 // These are versions of the above methods that are called only on a | |
| 404 // particular thread (s = signaling, w = worker). The above methods post or | |
| 405 // send a message to invoke this version. | |
| 406 TransportChannelImpl* CreateChannel_w(int component); | |
| 407 void DestroyChannel_w(int component); | |
| 408 void ConnectChannels_w(); | |
| 409 void ResetChannels_w(); | |
| 410 void DestroyAllChannels_w(); | |
| 411 void OnRemoteCandidate_w(const Candidate& candidate); | |
| 412 void OnChannelReadableState_s(); | |
| 413 void OnChannelWritableState_s(); | |
| 414 void OnChannelReceivingState_s(); | |
| 415 void OnChannelRequestSignaling_s(); | |
| 416 void OnConnecting_s(); | |
| 417 void OnChannelRouteChange_s(const TransportChannel* channel, | |
| 418 const Candidate& remote_candidate); | |
| 419 void OnChannelCandidatesAllocationDone_s(); | |
| 420 | |
| 421 // Helper function that invokes the given function on every channel. | 382 // Helper function that invokes the given function on every channel. |
| 422 typedef void (TransportChannelImpl::* TransportChannelFunc)(); | 383 typedef void (TransportChannelImpl::* TransportChannelFunc)(); |
| 423 void CallChannels_w(TransportChannelFunc func); | 384 void CallChannels(TransportChannelFunc func); |
| 424 | 385 |
| 425 // Computes the AND and OR of the channel's read/write/receiving state | 386 // Computes the AND and OR of the channel's read/write/receiving state |
| 426 // (argument picks the operation). | 387 // (argument picks the operation). |
| 427 TransportState GetTransportState_s(TransportStateType type); | 388 TransportState GetTransportState(TransportStateType type); |
| 428 | |
| 429 void OnChannelCandidateReady_s(); | |
| 430 | |
| 431 void SetIceRole_w(IceRole role); | |
| 432 void SetRemoteIceMode_w(IceMode mode); | |
| 433 bool SetLocalTransportDescription_w(const TransportDescription& desc, | |
| 434 ContentAction action, | |
| 435 std::string* error_desc); | |
| 436 bool SetRemoteTransportDescription_w(const TransportDescription& desc, | |
| 437 ContentAction action, | |
| 438 std::string* error_desc); | |
| 439 bool GetStats_w(TransportStats* infos); | |
| 440 bool GetRemoteCertificate_w(rtc::SSLCertificate** cert); | |
| 441 | |
| 442 void SetChannelReceivingTimeout_w(int timeout_ms); | |
| 443 | 389 |
| 444 // Sends SignalCompleted if we are now in that state. | 390 // Sends SignalCompleted if we are now in that state. |
| 445 void MaybeCompleted_w(); | 391 void MaybeSignalCompleted(); |
| 446 | 392 |
| 447 rtc::Thread* const signaling_thread_; | 393 // Sends SignalGatheringState if gathering state changed |
| 448 rtc::Thread* const worker_thread_; | 394 void UpdateGatheringState(); |
| 449 const std::string content_name_; | 395 |
| 396 void UpdateReadableState(); |
| 397 void UpdateWritableState(); |
| 398 void UpdateReceivingState(); |
| 399 |
| 400 const std::string name_; |
| 450 PortAllocator* const allocator_; | 401 PortAllocator* const allocator_; |
| 451 bool destroyed_; | 402 bool channels_destroyed_ = false; |
| 452 TransportState readable_; | 403 TransportState readable_ = TRANSPORT_STATE_NONE; |
| 453 TransportState writable_; | 404 TransportState writable_ = TRANSPORT_STATE_NONE; |
| 454 TransportState receiving_; | 405 TransportState receiving_ = TRANSPORT_STATE_NONE; |
| 455 bool was_writable_; | 406 bool was_writable_ = false; |
| 456 bool connect_requested_; | 407 bool connect_requested_ = false; |
| 457 IceRole ice_role_; | 408 IceRole ice_role_ = ICEROLE_UNKNOWN; |
| 458 uint64 tiebreaker_; | 409 uint64 tiebreaker_ = 0; |
| 459 IceMode remote_ice_mode_; | 410 IceMode remote_ice_mode_ = ICEMODE_FULL; |
| 460 int channel_receiving_timeout_; | 411 int channel_receiving_timeout_ = -1; |
| 461 rtc::scoped_ptr<TransportDescription> local_description_; | 412 rtc::scoped_ptr<TransportDescription> local_description_; |
| 462 rtc::scoped_ptr<TransportDescription> remote_description_; | 413 rtc::scoped_ptr<TransportDescription> remote_description_; |
| 414 bool local_description_set_ = false; |
| 415 bool remote_description_set_ = false; |
| 416 IceGatheringState gathering_state_ = kIceGatheringNew; |
| 463 | 417 |
| 464 // TODO(tommi): Make sure we only use this on the worker thread. | |
| 465 ChannelMap channels_; | 418 ChannelMap channels_; |
| 466 // Buffers the ready_candidates so that SignalCanidatesReady can | 419 // Buffers the ready_candidates so that SignalCanidatesReady can |
| 467 // provide them in multiples. | 420 // provide them in multiples. |
| 468 std::vector<Candidate> ready_candidates_; | 421 std::vector<Candidate> ready_candidates_; |
| 469 // Protects changes to channels and messages | |
| 470 rtc::CriticalSection crit_; | |
| 471 | 422 |
| 472 DISALLOW_COPY_AND_ASSIGN(Transport); | 423 DISALLOW_COPY_AND_ASSIGN(Transport); |
| 473 }; | 424 }; |
| 474 | 425 |
| 475 | 426 |
| 476 } // namespace cricket | 427 } // namespace cricket |
| 477 | 428 |
| 478 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_ | 429 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_ |
| OLD | NEW |