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