Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: webrtc/p2p/base/transport.h

Issue 1246913005: TransportController refactoring (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing problems with "failed" state; a channel isn't failed if it's never added a connection Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // TODO(deadbeef): unify with PeerConnectionInterface::IceConnectionState
pthatcher1 2015/08/25 18:40:39 unify => Unify Here and below
Taylor Brandstetter 2015/08/25 20:39:54 Done.
48 // once /talk/ and /webrtc/ are combined
49 enum IceConnectionState {
50 kIceConnectionConnecting = 0,
51 kIceConnectionFailed,
52 kIceConnectionConnected, // Writable, but still checking one or more
53 // connections
54 kIceConnectionCompleted,
pthatcher1 2015/08/25 18:40:39 I found out last week that the right style for enu
Taylor Brandstetter 2015/08/25 20:39:54 Done.
55 };
56
57 // TODO(deadbeef): unify with PeerConnectionInterface::IceConnectionState
58 // once /talk/ and /webrtc/ are combined
59 enum IceGatheringState {
60 kIceGatheringNew = 0,
61 kIceGatheringGathering,
62 kIceGatheringComplete,
63 };
64
56 // For "writable", "readable", and "receiving", we need to differentiate between 65 // For "writable", "readable", and "receiving", we need to differentiate between
57 // none, all, and some. 66 // none, all, and some.
58 enum TransportState { 67 enum TransportState {
59 TRANSPORT_STATE_NONE = 0, 68 TRANSPORT_STATE_NONE = 0,
60 TRANSPORT_STATE_SOME, 69 TRANSPORT_STATE_SOME,
61 TRANSPORT_STATE_ALL 70 TRANSPORT_STATE_ALL
62 }; 71 };
63 72
64 // When checking transport state, we need to differentiate between 73 // When checking transport state, we need to differentiate between
65 // "readable", "writable", or "receiving" check. 74 // "readable", "writable", or "receiving" check.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 TransportChannelStatsList channel_stats; 137 TransportChannelStatsList channel_stats;
129 }; 138 };
130 139
131 bool BadTransportDescription(const std::string& desc, std::string* err_desc); 140 bool BadTransportDescription(const std::string& desc, std::string* err_desc);
132 141
133 bool IceCredentialsChanged(const std::string& old_ufrag, 142 bool IceCredentialsChanged(const std::string& old_ufrag,
134 const std::string& old_pwd, 143 const std::string& old_pwd,
135 const std::string& new_ufrag, 144 const std::string& new_ufrag,
136 const std::string& new_pwd); 145 const std::string& new_pwd);
137 146
138 class Transport : public rtc::MessageHandler, 147 class Transport : public sigslot::has_slots<> {
139 public sigslot::has_slots<> {
140 public: 148 public:
141 Transport(rtc::Thread* signaling_thread, 149 Transport(const std::string& content_name,
142 rtc::Thread* worker_thread,
143 const std::string& content_name,
144 const std::string& type, 150 const std::string& type,
145 PortAllocator* allocator); 151 PortAllocator* allocator);
146 virtual ~Transport(); 152 virtual ~Transport();
147 153
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. 154 // Returns the content_name of this transport.
154 const std::string& content_name() const { return content_name_; } 155 const std::string& content_name() const { return content_name_; }
155 // Returns the type of this transport. 156 // Returns the type of this transport.
156 const std::string& type() const { return type_; } 157 const std::string& type() const { return type_; }
157 158
158 // Returns the port allocator object for this transport. 159 // Returns the port allocator object for this transport.
159 PortAllocator* port_allocator() { return allocator_; } 160 PortAllocator* port_allocator() { return allocator_; }
160 161
161 // Returns the readable and states of this manager. These bits are the ORs 162 // 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 163 // of the corresponding bits on the managed channels. Each time one of these
(...skipping 14 matching lines...) Expand all
177 bool all_channels_readable() const { 178 bool all_channels_readable() const {
178 return (readable_ == TRANSPORT_STATE_ALL); 179 return (readable_ == TRANSPORT_STATE_ALL);
179 } 180 }
180 bool all_channels_writable() const { 181 bool all_channels_writable() const {
181 return (writable_ == TRANSPORT_STATE_ALL); 182 return (writable_ == TRANSPORT_STATE_ALL);
182 } 183 }
183 bool any_channel_receiving() const { 184 bool any_channel_receiving() const {
184 return (receiving_ == TRANSPORT_STATE_SOME || 185 return (receiving_ == TRANSPORT_STATE_SOME ||
185 receiving_ == TRANSPORT_STATE_ALL); 186 receiving_ == TRANSPORT_STATE_ALL);
186 } 187 }
188 bool ready_for_remote_candidates() const {
189 return local_description_set_ && remote_description_set_;
190 }
191
192 bool AllChannelsCompleted() const;
193 bool AnyChannelFailed() const;
194
195 IceGatheringState gathering_state() const { return gathering_state_; }
187 196
188 sigslot::signal1<Transport*> SignalReadableState; 197 sigslot::signal1<Transport*> SignalReadableState;
189 sigslot::signal1<Transport*> SignalWritableState; 198 sigslot::signal1<Transport*> SignalWritableState;
190 sigslot::signal1<Transport*> SignalReceivingState; 199 sigslot::signal1<Transport*> SignalReceivingState;
191 sigslot::signal1<Transport*> SignalCompleted; 200 sigslot::signal1<Transport*> SignalCompleted;
192 sigslot::signal1<Transport*> SignalFailed; 201 sigslot::signal1<Transport*> SignalFailed;
193 202
194 // Returns whether the client has requested the channels to connect. 203 // Returns whether the client has requested the channels to connect.
195 bool connect_requested() const { return connect_requested_; } 204 bool connect_requested() const { return connect_requested_; }
196 205
197 void SetIceRole(IceRole role); 206 void SetIceRole(IceRole role);
198 IceRole ice_role() const { return ice_role_; } 207 IceRole ice_role() const { return ice_role_; }
199 208
200 void SetIceTiebreaker(uint64 IceTiebreaker) { tiebreaker_ = IceTiebreaker; } 209 void SetIceTiebreaker(uint64 IceTiebreaker) { tiebreaker_ = IceTiebreaker; }
201 uint64 IceTiebreaker() { return tiebreaker_; } 210 uint64 IceTiebreaker() { return tiebreaker_; }
202 211
203 void SetChannelReceivingTimeout(int timeout_ms); 212 void SetChannelReceivingTimeout(int timeout_ms);
204 213
205 // Must be called before applying local session description. 214 // Must be called before applying local session description.
206 void SetIdentity(rtc::SSLIdentity* identity); 215 virtual void SetIdentity(rtc::SSLIdentity* identity) {}
207 216
208 // Get a copy of the local identity provided by SetIdentity. 217 // Get a copy of the local identity provided by SetIdentity.
209 bool GetIdentity(rtc::SSLIdentity** identity); 218 virtual bool GetIdentity(rtc::SSLIdentity** identity) { return false; }
210 219
211 // Get a copy of the remote certificate in use by the specified channel. 220 // Get a copy of the remote certificate in use by the specified channel.
212 bool GetRemoteCertificate(rtc::SSLCertificate** cert); 221 bool GetRemoteCertificate(rtc::SSLCertificate** cert);
213 222
214 TransportProtocol protocol() const { return protocol_; } 223 TransportProtocol protocol() const { return protocol_; }
215 224
216 // Create, destroy, and lookup the channels of this type by their components. 225 // Create, destroy, and lookup the channels of this type by their components.
217 TransportChannelImpl* CreateChannel(int component); 226 TransportChannelImpl* CreateChannel(int component);
218 // Note: GetChannel may lead to race conditions, since the mutex is not held 227
219 // after the pointer is returned.
220 TransportChannelImpl* GetChannel(int component); 228 TransportChannelImpl* GetChannel(int component);
221 // Note: HasChannel does not lead to race conditions, unlike GetChannel. 229
222 bool HasChannel(int component) { 230 bool HasChannel(int component) {
223 return (NULL != GetChannel(component)); 231 return (NULL != GetChannel(component));
224 } 232 }
225 bool HasChannels(); 233 bool HasChannels();
226 void DestroyChannel(int component); 234 void DestroyChannel(int component);
227 235
228 // Set the local TransportDescription to be used by TransportChannels. 236 // Set the local TransportDescription to be used by TransportChannels.
229 // This should be called before ConnectChannels(). 237 // This should be called before ConnectChannels().
230 bool SetLocalTransportDescription(const TransportDescription& description, 238 bool SetLocalTransportDescription(const TransportDescription& description,
231 ContentAction action, 239 ContentAction action,
(...skipping 11 matching lines...) Expand all
243 251
244 // Resets all of the channels back to their initial state. They are no 252 // Resets all of the channels back to their initial state. They are no
245 // longer connecting. 253 // longer connecting.
246 void ResetChannels(); 254 void ResetChannels();
247 255
248 // Destroys every channel created so far. 256 // Destroys every channel created so far.
249 void DestroyAllChannels(); 257 void DestroyAllChannels();
250 258
251 bool GetStats(TransportStats* stats); 259 bool GetStats(TransportStats* stats);
252 260
253 // Before any stanza is sent, the manager will request signaling. Once 261 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 262
261 // Handles sending of ready candidates and receiving of remote candidates. 263 // Handles sending of ready candidates and receiving of remote candidates.
262 sigslot::signal2<Transport*, 264 sigslot::signal2<Transport*, const std::vector<Candidate>&>
263 const std::vector<Candidate>&> SignalCandidatesReady; 265 SignalCandidatesGathered;
264 266
265 sigslot::signal1<Transport*> SignalCandidatesAllocationDone; 267 // Called when one or more candidates are ready from the remote peer.
266 void OnRemoteCandidates(const std::vector<Candidate>& candidates); 268 bool AddRemoteCandidates(const std::vector<Candidate>& candidates,
269 std::string* error);
267 270
268 // If candidate is not acceptable, returns false and sets error. 271 // If candidate is not acceptable, returns false and sets error.
269 // Call this before calling OnRemoteCandidates. 272 // Call this before calling OnRemoteCandidates.
270 virtual bool VerifyCandidate(const Candidate& candidate, 273 virtual bool VerifyCandidate(const Candidate& candidate,
271 std::string* error); 274 std::string* error);
272 275
273 // Signals when the best connection for a channel changes. 276 // Signals when the best connection for a channel changes.
274 sigslot::signal3<Transport*, 277 sigslot::signal3<Transport*,
275 int, // component 278 int, // component
276 const Candidate&> SignalRouteChange; 279 const Candidate&> SignalRouteChange;
277 280
278 // Forwards the signal from TransportChannel to BaseSession. 281 // Forwards the signal from TransportChannel to BaseSession.
279 sigslot::signal0<> SignalRoleConflict; 282 sigslot::signal0<> SignalRoleConflict;
280 283
281 virtual bool GetSslRole(rtc::SSLRole* ssl_role) const; 284 virtual bool GetSslRole(rtc::SSLRole* ssl_role) const { return false; }
282 285
283 // Must be called before channel is starting to connect. 286 // Must be called before channel is starting to connect.
284 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version); 287 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version) {
288 return false;
289 }
285 290
286 protected: 291 protected:
287 // These are called by Create/DestroyChannel above in order to create or 292 // These are called by Create/DestroyChannel above in order to create or
288 // destroy the appropriate type of channel. 293 // destroy the appropriate type of channel.
289 virtual TransportChannelImpl* CreateTransportChannel(int component) = 0; 294 virtual TransportChannelImpl* CreateTransportChannel(int component) = 0;
290 virtual void DestroyTransportChannel(TransportChannelImpl* channel) = 0; 295 virtual void DestroyTransportChannel(TransportChannelImpl* channel) = 0;
291 296
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 297 // The current local transport description, for use by derived classes
296 // when performing transport description negotiation. 298 // when performing transport description negotiation.
297 const TransportDescription* local_description() const { 299 const TransportDescription* local_description() const {
298 return local_description_.get(); 300 return local_description_.get();
299 } 301 }
300 302
301 // The current remote transport description, for use by derived classes 303 // The current remote transport description, for use by derived classes
302 // when performing transport description negotiation. 304 // when performing transport description negotiation.
303 const TransportDescription* remote_description() const { 305 const TransportDescription* remote_description() const {
304 return remote_description_.get(); 306 return remote_description_.get();
305 } 307 }
306 308
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 309 // Pushes down the transport parameters from the local description, such
314 // as the ICE ufrag and pwd. 310 // as the ICE ufrag and pwd.
315 // Derived classes can override, but must call the base as well. 311 // Derived classes can override, but must call the base as well.
316 virtual bool ApplyLocalTransportDescription_w(TransportChannelImpl* channel, 312 virtual bool ApplyLocalTransportDescription(TransportChannelImpl* channel,
317 std::string* error_desc); 313 std::string* error_desc);
318 314
319 // Pushes down remote ice credentials from the remote description to the 315 // Pushes down remote ice credentials from the remote description to the
320 // transport channel. 316 // transport channel.
321 virtual bool ApplyRemoteTransportDescription_w(TransportChannelImpl* ch, 317 virtual bool ApplyRemoteTransportDescription(TransportChannelImpl* ch,
322 std::string* error_desc); 318 std::string* error_desc);
323 319
324 // Negotiates the transport parameters based on the current local and remote 320 // 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 321 // transport description, such at the version of ICE to use, and whether DTLS
326 // should be activated. 322 // should be activated.
327 // Derived classes can negotiate their specific parameters here, but must call 323 // Derived classes can negotiate their specific parameters here, but must call
328 // the base as well. 324 // the base as well.
329 virtual bool NegotiateTransportDescription_w(ContentAction local_role, 325 virtual bool NegotiateTransportDescription(ContentAction local_role,
330 std::string* error_desc); 326 std::string* error_desc);
331 327
332 // Pushes down the transport parameters obtained via negotiation. 328 // Pushes down the transport parameters obtained via negotiation.
333 // Derived classes can set their specific parameters here, but must call the 329 // Derived classes can set their specific parameters here, but must call the
334 // base as well. 330 // base as well.
335 virtual bool ApplyNegotiatedTransportDescription_w( 331 virtual bool ApplyNegotiatedTransportDescription(
336 TransportChannelImpl* channel, std::string* error_desc); 332 TransportChannelImpl* channel,
337 333 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 334
346 private: 335 private:
347 struct ChannelMapEntry { 336 struct ChannelMapEntry {
348 ChannelMapEntry() : impl_(NULL), candidates_allocated_(false), ref_(0) {} 337 ChannelMapEntry() : impl_(NULL), ref_(0) {}
349 explicit ChannelMapEntry(TransportChannelImpl *impl) 338 explicit ChannelMapEntry(TransportChannelImpl *impl)
350 : impl_(impl), 339 : impl_(impl),
351 candidates_allocated_(false),
352 ref_(0) { 340 ref_(0) {
353 } 341 }
354 342
355 void AddRef() { ++ref_; } 343 void AddRef() { ++ref_; }
356 void DecRef() { 344 void DecRef() {
357 ASSERT(ref_ > 0); 345 ASSERT(ref_ > 0);
358 --ref_; 346 --ref_;
359 } 347 }
360 int ref() const { return ref_; } 348 int ref() const { return ref_; }
361 349
362 TransportChannelImpl* get() const { return impl_; } 350 TransportChannelImpl* get() const { return impl_; }
363 TransportChannelImpl* operator->() const { return impl_; } 351 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 352
369 private: 353 private:
370 TransportChannelImpl *impl_; 354 TransportChannelImpl* impl_;
371 bool candidates_allocated_;
372 int ref_; 355 int ref_;
373 }; 356 };
374 357
375 // Candidate component => ChannelMapEntry 358 // Candidate component => ChannelMapEntry
376 typedef std::map<int, ChannelMapEntry> ChannelMap; 359 typedef std::map<int, ChannelMapEntry> ChannelMap;
377 360
378 // Called when the state of a channel changes. 361 // Called when the state of a channel changes.
379 void OnChannelReadableState(TransportChannel* channel); 362 void OnChannelReadableState(TransportChannel* channel);
380 void OnChannelWritableState(TransportChannel* channel); 363 void OnChannelWritableState(TransportChannel* channel);
381 364
382 // Called when the receiving state of a channel changes. 365 // Called when the receiving state of a channel changes.
383 void OnChannelReceivingState(TransportChannel* channel); 366 void OnChannelReceivingState(TransportChannel* channel);
384 367
385 // Called when a channel requests signaling. 368 // Called when a channel starts finishes gathering candidates
386 void OnChannelRequestSignaling(TransportChannelImpl* channel); 369 void OnChannelGatheringState(TransportChannelImpl* channel);
387 370
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. 371 // Called when a candidate is ready from channel.
391 void OnChannelCandidateReady(TransportChannelImpl* channel, 372 void OnChannelCandidateGathered(TransportChannelImpl* channel,
392 const Candidate& candidate); 373 const Candidate& candidate);
393 void OnChannelRouteChange(TransportChannel* channel, 374 void OnChannelRouteChange(TransportChannel* channel,
394 const Candidate& remote_candidate); 375 const Candidate& remote_candidate);
395 void OnChannelCandidatesAllocationDone(TransportChannelImpl* channel);
396 // Called when there is ICE role change. 376 // Called when there is ICE role change.
397 void OnRoleConflict(TransportChannelImpl* channel); 377 void OnRoleConflict(TransportChannelImpl* channel);
398 // Called when the channel removes a connection. 378 // Called when the channel removes a connection.
399 void OnChannelConnectionRemoved(TransportChannelImpl* channel); 379 void OnChannelConnectionRemoved(TransportChannelImpl* channel);
400 380
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. 381 // Helper function that invokes the given function on every channel.
423 typedef void (TransportChannelImpl::* TransportChannelFunc)(); 382 typedef void (TransportChannelImpl::* TransportChannelFunc)();
424 void CallChannels_w(TransportChannelFunc func); 383 void CallChannels(TransportChannelFunc func);
425 384
426 // Computes the AND and OR of the channel's read/write/receiving state 385 // Computes the AND and OR of the channel's read/write/receiving state
427 // (argument picks the operation). 386 // (argument picks the operation).
428 TransportState GetTransportState_s(TransportStateType type); 387 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 388
445 // Sends SignalCompleted if we are now in that state. 389 // Sends SignalCompleted if we are now in that state.
446 void MaybeCompleted_w(); 390 void CheckIfCompleted();
447 391
448 rtc::Thread* const signaling_thread_; 392 // Sends SignalGatheringState if gathering state changed
449 rtc::Thread* const worker_thread_; 393 void UpdateGatheringState();
394
395 void UpdateReadableState();
396 void UpdateWritableState();
397 void UpdateReceivingState();
398
450 const std::string content_name_; 399 const std::string content_name_;
451 const std::string type_; 400 const std::string type_;
452 PortAllocator* const allocator_; 401 PortAllocator* const allocator_;
453 bool destroyed_; 402 bool destroyed_;
454 TransportState readable_; 403 TransportState readable_;
455 TransportState writable_; 404 TransportState writable_;
456 TransportState receiving_; 405 TransportState receiving_;
457 bool was_writable_; 406 bool was_writable_;
458 bool connect_requested_; 407 bool connect_requested_;
459 IceRole ice_role_; 408 IceRole ice_role_;
460 uint64 tiebreaker_; 409 uint64 tiebreaker_;
461 TransportProtocol protocol_; 410 TransportProtocol protocol_;
462 IceMode remote_ice_mode_; 411 IceMode remote_ice_mode_;
463 int channel_receiving_timeout_; 412 int channel_receiving_timeout_;
464 rtc::scoped_ptr<TransportDescription> local_description_; 413 rtc::scoped_ptr<TransportDescription> local_description_;
465 rtc::scoped_ptr<TransportDescription> remote_description_; 414 rtc::scoped_ptr<TransportDescription> remote_description_;
415 bool local_description_set_;
416 bool remote_description_set_;
417 IceGatheringState gathering_state_;
466 418
467 // TODO(tommi): Make sure we only use this on the worker thread.
468 ChannelMap channels_; 419 ChannelMap channels_;
469 // Buffers the ready_candidates so that SignalCanidatesReady can 420 // Buffers the ready_candidates so that SignalCanidatesReady can
470 // provide them in multiples. 421 // provide them in multiples.
471 std::vector<Candidate> ready_candidates_; 422 std::vector<Candidate> ready_candidates_;
472 // Protects changes to channels and messages
473 rtc::CriticalSection crit_;
474 423
475 DISALLOW_COPY_AND_ASSIGN(Transport); 424 DISALLOW_COPY_AND_ASSIGN(Transport);
476 }; 425 };
477 426
478 // Extract a TransportProtocol from a TransportDescription. 427 // Extract a TransportProtocol from a TransportDescription.
479 TransportProtocol TransportProtocolFromDescription( 428 TransportProtocol TransportProtocolFromDescription(
480 const TransportDescription* desc); 429 const TransportDescription* desc);
481 430
482 } // namespace cricket 431 } // namespace cricket
483 432
484 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_ 433 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698