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 GetRemoteSSLCertificate(rtc::SSLCertificate** cert); | 224 bool GetRemoteSSLCertificate(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(). | |
227 bool SetLocalTransportDescription(const TransportDescription& description, | 238 bool SetLocalTransportDescription(const TransportDescription& description, |
228 ContentAction action, | 239 ContentAction action, |
229 std::string* error_desc); | 240 std::string* error_desc); |
230 | 241 |
231 // Set the remote TransportDescription to be used by TransportChannels. | 242 // Set the remote TransportDescription to be used by TransportChannels. |
232 bool SetRemoteTransportDescription(const TransportDescription& description, | 243 bool SetRemoteTransportDescription(const TransportDescription& description, |
233 ContentAction action, | 244 ContentAction action, |
234 std::string* error_desc); | 245 std::string* error_desc); |
235 | 246 |
236 // Tells all current and future channels to start connecting. When the first | 247 // Tells all current and future channels to start connecting. When the first |
237 // channel begins connecting, the following signal is raised. | 248 // channel begins connecting, the following signal is raised. |
238 void ConnectChannels(); | 249 void ConnectChannels(); |
239 sigslot::signal1<Transport*> SignalConnecting; | 250 sigslot::signal1<Transport*> SignalConnecting; |
240 | 251 |
| 252 // Tells channels to start gathering candidates if necessary. |
| 253 // Should be called after ConnectChannels() has been called at least once, |
| 254 // which will happen in SetLocalTransportDescription. |
| 255 void MaybeStartGathering(); |
| 256 |
241 // Resets all of the channels back to their initial state. They are no | 257 // Resets all of the channels back to their initial state. They are no |
242 // longer connecting. | 258 // longer connecting. |
243 void ResetChannels(); | 259 void ResetChannels(); |
244 | 260 |
245 // Destroys every channel created so far. | 261 // Destroys every channel created so far. |
246 void DestroyAllChannels(); | 262 void DestroyAllChannels(); |
247 | 263 |
248 bool GetStats(TransportStats* stats); | 264 bool GetStats(TransportStats* stats); |
249 | 265 |
250 // Before any stanza is sent, the manager will request signaling. Once | 266 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 | 267 |
258 // Handles sending of ready candidates and receiving of remote candidates. | 268 // Handles sending of ready candidates and receiving of remote candidates. |
259 sigslot::signal2<Transport*, | 269 sigslot::signal2<Transport*, const std::vector<Candidate>&> |
260 const std::vector<Candidate>&> SignalCandidatesReady; | 270 SignalCandidatesGathered; |
261 | 271 |
262 sigslot::signal1<Transport*> SignalCandidatesAllocationDone; | 272 // Called when one or more candidates are ready from the remote peer. |
263 void OnRemoteCandidates(const std::vector<Candidate>& candidates); | 273 bool AddRemoteCandidates(const std::vector<Candidate>& candidates, |
| 274 std::string* error); |
264 | 275 |
265 // If candidate is not acceptable, returns false and sets error. | 276 // If candidate is not acceptable, returns false and sets error. |
266 // Call this before calling OnRemoteCandidates. | 277 // Call this before calling OnRemoteCandidates. |
267 virtual bool VerifyCandidate(const Candidate& candidate, | 278 virtual bool VerifyCandidate(const Candidate& candidate, |
268 std::string* error); | 279 std::string* error); |
269 | 280 |
270 // Signals when the best connection for a channel changes. | 281 // Signals when the best connection for a channel changes. |
271 sigslot::signal3<Transport*, | 282 sigslot::signal3<Transport*, |
272 int, // component | 283 int, // component |
273 const Candidate&> SignalRouteChange; | 284 const Candidate&> SignalRouteChange; |
274 | 285 |
275 // Forwards the signal from TransportChannel to BaseSession. | 286 // Forwards the signal from TransportChannel to BaseSession. |
276 sigslot::signal0<> SignalRoleConflict; | 287 sigslot::signal0<> SignalRoleConflict; |
277 | 288 |
278 virtual bool GetSslRole(rtc::SSLRole* ssl_role) const; | 289 virtual bool GetSslRole(rtc::SSLRole* ssl_role) const { return false; } |
279 | 290 |
280 // Must be called before channel is starting to connect. | 291 // Must be called before channel is starting to connect. |
281 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version); | 292 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version) { |
| 293 return false; |
| 294 } |
282 | 295 |
283 protected: | 296 protected: |
284 // These are called by Create/DestroyChannel above in order to create or | 297 // These are called by Create/DestroyChannel above in order to create or |
285 // destroy the appropriate type of channel. | 298 // destroy the appropriate type of channel. |
286 virtual TransportChannelImpl* CreateTransportChannel(int component) = 0; | 299 virtual TransportChannelImpl* CreateTransportChannel(int component) = 0; |
287 virtual void DestroyTransportChannel(TransportChannelImpl* channel) = 0; | 300 virtual void DestroyTransportChannel(TransportChannelImpl* channel) = 0; |
288 | 301 |
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 | 302 // The current local transport description, for use by derived classes |
293 // when performing transport description negotiation. | 303 // when performing transport description negotiation. |
294 const TransportDescription* local_description() const { | 304 const TransportDescription* local_description() const { |
295 return local_description_.get(); | 305 return local_description_.get(); |
296 } | 306 } |
297 | 307 |
298 // The current remote transport description, for use by derived classes | 308 // The current remote transport description, for use by derived classes |
299 // when performing transport description negotiation. | 309 // when performing transport description negotiation. |
300 const TransportDescription* remote_description() const { | 310 const TransportDescription* remote_description() const { |
301 return remote_description_.get(); | 311 return remote_description_.get(); |
302 } | 312 } |
303 | 313 |
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 | 314 // Pushes down the transport parameters from the local description, such |
313 // as the ICE ufrag and pwd. | 315 // as the ICE ufrag and pwd. |
314 // Derived classes can override, but must call the base as well. | 316 // Derived classes can override, but must call the base as well. |
315 virtual bool ApplyLocalTransportDescription_w(TransportChannelImpl* channel, | 317 virtual bool ApplyLocalTransportDescription(TransportChannelImpl* channel, |
316 std::string* error_desc); | 318 std::string* error_desc); |
317 | 319 |
318 // Pushes down remote ice credentials from the remote description to the | 320 // Pushes down remote ice credentials from the remote description to the |
319 // transport channel. | 321 // transport channel. |
320 virtual bool ApplyRemoteTransportDescription_w(TransportChannelImpl* ch, | 322 virtual bool ApplyRemoteTransportDescription(TransportChannelImpl* ch, |
321 std::string* error_desc); | 323 std::string* error_desc); |
322 | 324 |
323 // Negotiates the transport parameters based on the current local and remote | 325 // Negotiates the transport parameters based on the current local and remote |
324 // transport description, such as the ICE role to use, and whether DTLS | 326 // transport description, such as the ICE role to use, and whether DTLS |
325 // should be activated. | 327 // should be activated. |
326 // Derived classes can negotiate their specific parameters here, but must call | 328 // Derived classes can negotiate their specific parameters here, but must call |
327 // the base as well. | 329 // the base as well. |
328 virtual bool NegotiateTransportDescription_w(ContentAction local_role, | 330 virtual bool NegotiateTransportDescription(ContentAction local_role, |
329 std::string* error_desc); | 331 std::string* error_desc); |
330 | 332 |
331 // Pushes down the transport parameters obtained via negotiation. | 333 // Pushes down the transport parameters obtained via negotiation. |
332 // Derived classes can set their specific parameters here, but must call the | 334 // Derived classes can set their specific parameters here, but must call the |
333 // base as well. | 335 // base as well. |
334 virtual bool ApplyNegotiatedTransportDescription_w( | 336 virtual bool ApplyNegotiatedTransportDescription( |
335 TransportChannelImpl* channel, std::string* error_desc); | 337 TransportChannelImpl* channel, |
336 | 338 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 | 339 |
345 private: | 340 private: |
346 struct ChannelMapEntry { | 341 struct ChannelMapEntry { |
347 ChannelMapEntry() : impl_(NULL), candidates_allocated_(false), ref_(0) {} | 342 ChannelMapEntry() : impl_(NULL), ref_(0) {} |
348 explicit ChannelMapEntry(TransportChannelImpl *impl) | 343 explicit ChannelMapEntry(TransportChannelImpl *impl) |
349 : impl_(impl), | 344 : impl_(impl), |
350 candidates_allocated_(false), | |
351 ref_(0) { | 345 ref_(0) { |
352 } | 346 } |
353 | 347 |
354 void AddRef() { ++ref_; } | 348 void AddRef() { ++ref_; } |
355 void DecRef() { | 349 void DecRef() { |
356 ASSERT(ref_ > 0); | 350 ASSERT(ref_ > 0); |
357 --ref_; | 351 --ref_; |
358 } | 352 } |
359 int ref() const { return ref_; } | 353 int ref() const { return ref_; } |
360 | 354 |
361 TransportChannelImpl* get() const { return impl_; } | 355 TransportChannelImpl* get() const { return impl_; } |
362 TransportChannelImpl* operator->() const { return impl_; } | 356 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 | 357 |
368 private: | 358 private: |
369 TransportChannelImpl *impl_; | 359 TransportChannelImpl* impl_; |
370 bool candidates_allocated_; | |
371 int ref_; | 360 int ref_; |
372 }; | 361 }; |
373 | 362 |
374 // Candidate component => ChannelMapEntry | 363 // Candidate component => ChannelMapEntry |
375 typedef std::map<int, ChannelMapEntry> ChannelMap; | 364 typedef std::map<int, ChannelMapEntry> ChannelMap; |
376 | 365 |
377 // Called when the state of a channel changes. | 366 // Called when the state of a channel changes. |
378 void OnChannelReadableState(TransportChannel* channel); | 367 void OnChannelReadableState(TransportChannel* channel); |
379 void OnChannelWritableState(TransportChannel* channel); | 368 void OnChannelWritableState(TransportChannel* channel); |
380 | 369 |
381 // Called when the receiving state of a channel changes. | 370 // Called when the receiving state of a channel changes. |
382 void OnChannelReceivingState(TransportChannel* channel); | 371 void OnChannelReceivingState(TransportChannel* channel); |
383 | 372 |
384 // Called when a channel requests signaling. | 373 // Called when a channel starts finishes gathering candidates |
385 void OnChannelRequestSignaling(TransportChannelImpl* channel); | 374 void OnChannelGatheringState(TransportChannelImpl* channel); |
386 | 375 |
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. | 376 // Called when a candidate is ready from channel. |
390 void OnChannelCandidateReady(TransportChannelImpl* channel, | 377 void OnChannelCandidateGathered(TransportChannelImpl* channel, |
391 const Candidate& candidate); | 378 const Candidate& candidate); |
392 void OnChannelRouteChange(TransportChannel* channel, | 379 void OnChannelRouteChange(TransportChannel* channel, |
393 const Candidate& remote_candidate); | 380 const Candidate& remote_candidate); |
394 void OnChannelCandidatesAllocationDone(TransportChannelImpl* channel); | |
395 // Called when there is ICE role change. | 381 // Called when there is ICE role change. |
396 void OnRoleConflict(TransportChannelImpl* channel); | 382 void OnRoleConflict(TransportChannelImpl* channel); |
397 // Called when the channel removes a connection. | 383 // Called when the channel removes a connection. |
398 void OnChannelConnectionRemoved(TransportChannelImpl* channel); | 384 void OnChannelConnectionRemoved(TransportChannelImpl* channel); |
399 | 385 |
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. | 386 // Helper function that invokes the given function on every channel. |
422 typedef void (TransportChannelImpl::* TransportChannelFunc)(); | 387 typedef void (TransportChannelImpl::* TransportChannelFunc)(); |
423 void CallChannels_w(TransportChannelFunc func); | 388 void CallChannels(TransportChannelFunc func); |
424 | 389 |
425 // Computes the AND and OR of the channel's read/write/receiving state | 390 // Computes the AND and OR of the channel's read/write/receiving state |
426 // (argument picks the operation). | 391 // (argument picks the operation). |
427 TransportState GetTransportState_s(TransportStateType type); | 392 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 GetRemoteSSLCertificate_w(rtc::SSLCertificate** cert); | |
441 | |
442 void SetChannelReceivingTimeout_w(int timeout_ms); | |
443 | 393 |
444 // Sends SignalCompleted if we are now in that state. | 394 // Sends SignalCompleted if we are now in that state. |
445 void MaybeCompleted_w(); | 395 void MaybeSignalCompleted(); |
446 | 396 |
447 rtc::Thread* const signaling_thread_; | 397 // Sends SignalGatheringState if gathering state changed |
448 rtc::Thread* const worker_thread_; | 398 void UpdateGatheringState(); |
449 const std::string content_name_; | 399 |
| 400 void UpdateReadableState(); |
| 401 void UpdateWritableState(); |
| 402 void UpdateReceivingState(); |
| 403 |
| 404 const std::string name_; |
450 PortAllocator* const allocator_; | 405 PortAllocator* const allocator_; |
451 bool destroyed_; | 406 bool channels_destroyed_ = false; |
452 TransportState readable_; | 407 TransportState readable_ = TRANSPORT_STATE_NONE; |
453 TransportState writable_; | 408 TransportState writable_ = TRANSPORT_STATE_NONE; |
454 TransportState receiving_; | 409 TransportState receiving_ = TRANSPORT_STATE_NONE; |
455 bool was_writable_; | 410 bool was_writable_ = false; |
456 bool connect_requested_; | 411 bool connect_requested_ = false; |
457 IceRole ice_role_; | 412 IceRole ice_role_ = ICEROLE_UNKNOWN; |
458 uint64 tiebreaker_; | 413 uint64 tiebreaker_ = 0; |
459 IceMode remote_ice_mode_; | 414 IceMode remote_ice_mode_ = ICEMODE_FULL; |
460 int channel_receiving_timeout_; | 415 int channel_receiving_timeout_ = -1; |
461 rtc::scoped_ptr<TransportDescription> local_description_; | 416 rtc::scoped_ptr<TransportDescription> local_description_; |
462 rtc::scoped_ptr<TransportDescription> remote_description_; | 417 rtc::scoped_ptr<TransportDescription> remote_description_; |
| 418 bool local_description_set_ = false; |
| 419 bool remote_description_set_ = false; |
| 420 IceGatheringState gathering_state_ = kIceGatheringNew; |
463 | 421 |
464 // TODO(tommi): Make sure we only use this on the worker thread. | |
465 ChannelMap channels_; | 422 ChannelMap channels_; |
466 // Buffers the ready_candidates so that SignalCanidatesReady can | |
467 // provide them in multiples. | |
468 std::vector<Candidate> ready_candidates_; | |
469 // Protects changes to channels and messages | |
470 rtc::CriticalSection crit_; | |
471 | 423 |
472 RTC_DISALLOW_COPY_AND_ASSIGN(Transport); | 424 RTC_DISALLOW_COPY_AND_ASSIGN(Transport); |
473 }; | 425 }; |
474 | 426 |
475 | 427 |
476 } // namespace cricket | 428 } // namespace cricket |
477 | 429 |
478 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_ | 430 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_ |
OLD | NEW |