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

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

Issue 1350523003: TransportController refactoring. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fixing Mac test. 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
« no previous file with comments | « webrtc/p2p/base/session_unittest.cc ('k') | webrtc/p2p/base/transport.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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" and "receiving", we need to differentiate between 68 // For "writable" 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 // "writable" or "receiving" check. 77 // "writable" or "receiving" check.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 std::string srtp_cipher; 128 std::string srtp_cipher;
118 std::string ssl_cipher; 129 std::string ssl_cipher;
119 }; 130 };
120 131
121 // Information about all the channels of a transport. 132 // Information about all the channels of a transport.
122 // TODO(hta): Consider if a simple vector is as good as a map. 133 // TODO(hta): Consider if a simple vector is as good as a map.
123 typedef std::vector<TransportChannelStats> TransportChannelStatsList; 134 typedef std::vector<TransportChannelStats> TransportChannelStatsList;
124 135
125 // Information about the stats of a transport. 136 // Information about the stats of a transport.
126 struct TransportStats { 137 struct TransportStats {
127 std::string content_name; 138 std::string transport_name;
128 TransportChannelStatsList channel_stats; 139 TransportChannelStatsList channel_stats;
129 }; 140 };
130 141
131 bool BadTransportDescription(const std::string& desc, std::string* err_desc); 142 bool BadTransportDescription(const std::string& desc, std::string* err_desc);
132 143
133 bool IceCredentialsChanged(const std::string& old_ufrag, 144 bool IceCredentialsChanged(const std::string& old_ufrag,
134 const std::string& old_pwd, 145 const std::string& old_pwd,
135 const std::string& new_ufrag, 146 const std::string& new_ufrag,
136 const std::string& new_pwd); 147 const std::string& new_pwd);
137 148
138 class Transport : public rtc::MessageHandler, 149 class Transport : public sigslot::has_slots<> {
139 public sigslot::has_slots<> {
140 public: 150 public:
141 Transport(rtc::Thread* signaling_thread, 151 Transport(const std::string& name, PortAllocator* allocator);
142 rtc::Thread* worker_thread,
143 const std::string& content_name,
144 PortAllocator* allocator);
145 virtual ~Transport(); 152 virtual ~Transport();
146 153
147 // Returns the signaling thread. The app talks to Transport on this thread. 154 // Returns the name of this transport.
148 rtc::Thread* signaling_thread() const { return signaling_thread_; } 155 const std::string& name() const { return name_; }
149 // Returns the worker thread. The actual networking is done on this thread.
150 rtc::Thread* worker_thread() const { return worker_thread_; }
151
152 // Returns the content_name of this transport.
153 const std::string& content_name() const { return content_name_; }
154 156
155 // Returns the port allocator object for this transport. 157 // Returns the port allocator object for this transport.
156 PortAllocator* port_allocator() { return allocator_; } 158 PortAllocator* port_allocator() { return allocator_; }
157 159
158 // Returns the states of this manager. These bits are the ORs 160 // Returns the states of this manager. These bits are the ORs
159 // of the corresponding bits on the managed channels. Each time one of these 161 // of the corresponding bits on the managed channels. Each time one of these
160 // states changes, a signal is raised. 162 // states changes, a signal is raised.
161 // TODO(honghaiz): Replace uses of writable() with any_channels_writable(). 163 // TODO(honghaiz): Replace uses of writable() with any_channels_writable().
162 bool writable() const { return any_channels_writable(); } 164 bool writable() const { return any_channels_writable(); }
163 bool was_writable() const { return was_writable_; } 165 bool was_writable() const { return was_writable_; }
164 bool any_channels_writable() const { 166 bool any_channels_writable() const {
165 return (writable_ == TRANSPORT_STATE_SOME || 167 return (writable_ == TRANSPORT_STATE_SOME ||
166 writable_ == TRANSPORT_STATE_ALL); 168 writable_ == TRANSPORT_STATE_ALL);
167 } 169 }
168 bool all_channels_writable() const { 170 bool all_channels_writable() const {
169 return (writable_ == TRANSPORT_STATE_ALL); 171 return (writable_ == TRANSPORT_STATE_ALL);
170 } 172 }
171 bool any_channel_receiving() const { 173 bool any_channel_receiving() const {
172 return (receiving_ == TRANSPORT_STATE_SOME || 174 return (receiving_ == TRANSPORT_STATE_SOME ||
173 receiving_ == TRANSPORT_STATE_ALL); 175 receiving_ == TRANSPORT_STATE_ALL);
174 } 176 }
177 bool ready_for_remote_candidates() const {
178 return local_description_set_ && remote_description_set_;
179 }
180
181 bool AllChannelsCompleted() const;
182 bool AnyChannelFailed() const;
183
184 IceGatheringState gathering_state() const { return gathering_state_; }
175 185
176 sigslot::signal1<Transport*> SignalWritableState; 186 sigslot::signal1<Transport*> SignalWritableState;
177 sigslot::signal1<Transport*> SignalReceivingState; 187 sigslot::signal1<Transport*> SignalReceivingState;
178 sigslot::signal1<Transport*> SignalCompleted; 188 sigslot::signal1<Transport*> SignalCompleted;
179 sigslot::signal1<Transport*> SignalFailed; 189 sigslot::signal1<Transport*> SignalFailed;
180 190
181 // Returns whether the client has requested the channels to connect. 191 // Returns whether the client has requested the channels to connect.
182 bool connect_requested() const { return connect_requested_; } 192 bool connect_requested() const { return connect_requested_; }
183 193
184 void SetIceRole(IceRole role); 194 void SetIceRole(IceRole role);
185 IceRole ice_role() const { return ice_role_; } 195 IceRole ice_role() const { return ice_role_; }
186 196
187 void SetIceTiebreaker(uint64 IceTiebreaker) { tiebreaker_ = IceTiebreaker; } 197 void SetIceTiebreaker(uint64 IceTiebreaker) { tiebreaker_ = IceTiebreaker; }
188 uint64 IceTiebreaker() { return tiebreaker_; } 198 uint64 IceTiebreaker() { return tiebreaker_; }
189 199
190 void SetChannelReceivingTimeout(int timeout_ms); 200 void SetChannelReceivingTimeout(int timeout_ms);
191 201
192 // Must be called before applying local session description. 202 // Must be called before applying local session description.
193 void SetCertificate( 203 virtual void SetLocalCertificate(
194 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); 204 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) {}
195 205
196 // Get a copy of the local identity provided by SetIdentity. 206 // Get a copy of the local certificate provided by SetLocalCertificate.
197 bool GetCertificate(rtc::scoped_refptr<rtc::RTCCertificate>* certificate); 207 virtual bool GetLocalCertificate(
208 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) {
209 return false;
210 }
198 211
199 // Get a copy of the remote certificate in use by the specified channel. 212 // Get a copy of the remote certificate in use by the specified channel.
200 bool GetRemoteSSLCertificate(rtc::SSLCertificate** cert); 213 bool GetRemoteSSLCertificate(rtc::SSLCertificate** cert);
201 214
202 // Create, destroy, and lookup the channels of this type by their components. 215 // Create, destroy, and lookup the channels of this type by their components.
203 TransportChannelImpl* CreateChannel(int component); 216 TransportChannelImpl* CreateChannel(int component);
204 // Note: GetChannel may lead to race conditions, since the mutex is not held 217
205 // after the pointer is returned.
206 TransportChannelImpl* GetChannel(int component); 218 TransportChannelImpl* GetChannel(int component);
207 // Note: HasChannel does not lead to race conditions, unlike GetChannel. 219
208 bool HasChannel(int component) { 220 bool HasChannel(int component) {
209 return (NULL != GetChannel(component)); 221 return (NULL != GetChannel(component));
210 } 222 }
211 bool HasChannels(); 223 bool HasChannels();
212 void DestroyChannel(int component); 224 void DestroyChannel(int component);
213 225
214 // Set the local TransportDescription to be used by TransportChannels. 226 // Set the local TransportDescription to be used by TransportChannels.
215 // This should be called before ConnectChannels().
216 bool SetLocalTransportDescription(const TransportDescription& description, 227 bool SetLocalTransportDescription(const TransportDescription& description,
217 ContentAction action, 228 ContentAction action,
218 std::string* error_desc); 229 std::string* error_desc);
219 230
220 // Set the remote TransportDescription to be used by TransportChannels. 231 // Set the remote TransportDescription to be used by TransportChannels.
221 bool SetRemoteTransportDescription(const TransportDescription& description, 232 bool SetRemoteTransportDescription(const TransportDescription& description,
222 ContentAction action, 233 ContentAction action,
223 std::string* error_desc); 234 std::string* error_desc);
224 235
225 // Tells all current and future channels to start connecting. When the first 236 // Tells all current and future channels to start connecting. When the first
226 // channel begins connecting, the following signal is raised. 237 // channel begins connecting, the following signal is raised.
227 void ConnectChannels(); 238 void ConnectChannels();
228 sigslot::signal1<Transport*> SignalConnecting; 239 sigslot::signal1<Transport*> SignalConnecting;
229 240
241 // Tells channels to start gathering candidates if necessary.
242 // Should be called after ConnectChannels() has been called at least once,
243 // which will happen in SetLocalTransportDescription.
244 void MaybeStartGathering();
245
230 // 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
231 // longer connecting. 247 // longer connecting.
232 void ResetChannels(); 248 void ResetChannels();
233 249
234 // Destroys every channel created so far. 250 // Destroys every channel created so far.
235 void DestroyAllChannels(); 251 void DestroyAllChannels();
236 252
237 bool GetStats(TransportStats* stats); 253 bool GetStats(TransportStats* stats);
238 254
239 // Before any stanza is sent, the manager will request signaling. Once 255 sigslot::signal1<Transport*> SignalGatheringState;
240 // signaling is available, the client should call OnSignalingReady. Once
241 // this occurs, the transport (or its channels) can send any waiting stanzas.
242 // OnSignalingReady invokes OnTransportSignalingReady and then forwards this
243 // signal to each channel.
244 sigslot::signal1<Transport*> SignalRequestSignaling;
245 void OnSignalingReady();
246 256
247 // Handles sending of ready candidates and receiving of remote candidates. 257 // Handles sending of ready candidates and receiving of remote candidates.
248 sigslot::signal2<Transport*, 258 sigslot::signal2<Transport*, const std::vector<Candidate>&>
249 const std::vector<Candidate>&> SignalCandidatesReady; 259 SignalCandidatesGathered;
250 260
251 sigslot::signal1<Transport*> SignalCandidatesAllocationDone; 261 // Called when one or more candidates are ready from the remote peer.
252 void OnRemoteCandidates(const std::vector<Candidate>& candidates); 262 bool AddRemoteCandidates(const std::vector<Candidate>& candidates,
263 std::string* error);
253 264
254 // If candidate is not acceptable, returns false and sets error. 265 // If candidate is not acceptable, returns false and sets error.
255 // Call this before calling OnRemoteCandidates. 266 // Call this before calling OnRemoteCandidates.
256 virtual bool VerifyCandidate(const Candidate& candidate, 267 virtual bool VerifyCandidate(const Candidate& candidate,
257 std::string* error); 268 std::string* error);
258 269
259 // Signals when the best connection for a channel changes. 270 // Signals when the best connection for a channel changes.
260 sigslot::signal3<Transport*, 271 sigslot::signal3<Transport*,
261 int, // component 272 int, // component
262 const Candidate&> SignalRouteChange; 273 const Candidate&> SignalRouteChange;
263 274
264 // Forwards the signal from TransportChannel to BaseSession. 275 // Forwards the signal from TransportChannel to BaseSession.
265 sigslot::signal0<> SignalRoleConflict; 276 sigslot::signal0<> SignalRoleConflict;
266 277
267 virtual bool GetSslRole(rtc::SSLRole* ssl_role) const; 278 virtual bool GetSslRole(rtc::SSLRole* ssl_role) const { return false; }
268 279
269 // Must be called before channel is starting to connect. 280 // Must be called before channel is starting to connect.
270 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version); 281 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version) {
282 return false;
283 }
271 284
272 protected: 285 protected:
273 // 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
274 // destroy the appropriate type of channel. 287 // destroy the appropriate type of channel.
275 virtual TransportChannelImpl* CreateTransportChannel(int component) = 0; 288 virtual TransportChannelImpl* CreateTransportChannel(int component) = 0;
276 virtual void DestroyTransportChannel(TransportChannelImpl* channel) = 0; 289 virtual void DestroyTransportChannel(TransportChannelImpl* channel) = 0;
277 290
278 // Informs the subclass that we received the signaling ready message.
279 virtual void OnTransportSignalingReady() {}
280
281 // The current local transport description, for use by derived classes 291 // The current local transport description, for use by derived classes
282 // when performing transport description negotiation. 292 // when performing transport description negotiation.
283 const TransportDescription* local_description() const { 293 const TransportDescription* local_description() const {
284 return local_description_.get(); 294 return local_description_.get();
285 } 295 }
286 296
287 // The current remote transport description, for use by derived classes 297 // The current remote transport description, for use by derived classes
288 // when performing transport description negotiation. 298 // when performing transport description negotiation.
289 const TransportDescription* remote_description() const { 299 const TransportDescription* remote_description() const {
290 return remote_description_.get(); 300 return remote_description_.get();
291 } 301 }
292 302
293 virtual void SetCertificate_w(
294 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) {}
295
296 virtual bool GetCertificate_w(
297 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) {
298 return false;
299 }
300
301 // Pushes down the transport parameters from the local description, such 303 // Pushes down the transport parameters from the local description, such
302 // as the ICE ufrag and pwd. 304 // as the ICE ufrag and pwd.
303 // Derived classes can override, but must call the base as well. 305 // Derived classes can override, but must call the base as well.
304 virtual bool ApplyLocalTransportDescription_w(TransportChannelImpl* channel, 306 virtual bool ApplyLocalTransportDescription(TransportChannelImpl* channel,
305 std::string* error_desc); 307 std::string* error_desc);
306 308
307 // Pushes down remote ice credentials from the remote description to the 309 // Pushes down remote ice credentials from the remote description to the
308 // transport channel. 310 // transport channel.
309 virtual bool ApplyRemoteTransportDescription_w(TransportChannelImpl* ch, 311 virtual bool ApplyRemoteTransportDescription(TransportChannelImpl* ch,
310 std::string* error_desc); 312 std::string* error_desc);
311 313
312 // Negotiates the transport parameters based on the current local and remote 314 // Negotiates the transport parameters based on the current local and remote
313 // transport description, such as the ICE role to use, and whether DTLS 315 // transport description, such as the ICE role to use, and whether DTLS
314 // should be activated. 316 // should be activated.
315 // Derived classes can negotiate their specific parameters here, but must call 317 // Derived classes can negotiate their specific parameters here, but must call
316 // the base as well. 318 // the base as well.
317 virtual bool NegotiateTransportDescription_w(ContentAction local_role, 319 virtual bool NegotiateTransportDescription(ContentAction local_role,
318 std::string* error_desc); 320 std::string* error_desc);
319 321
320 // Pushes down the transport parameters obtained via negotiation. 322 // Pushes down the transport parameters obtained via negotiation.
321 // 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
322 // base as well. 324 // base as well.
323 virtual bool ApplyNegotiatedTransportDescription_w( 325 virtual bool ApplyNegotiatedTransportDescription(
324 TransportChannelImpl* channel, std::string* error_desc); 326 TransportChannelImpl* channel,
325 327 std::string* error_desc);
326 virtual bool GetSslRole_w(rtc::SSLRole* ssl_role) const {
327 return false;
328 }
329
330 virtual bool SetSslMaxProtocolVersion_w(rtc::SSLProtocolVersion version) {
331 return false;
332 }
333 328
334 private: 329 private:
335 struct ChannelMapEntry { 330 struct ChannelMapEntry {
336 ChannelMapEntry() : impl_(NULL), candidates_allocated_(false), ref_(0) {} 331 ChannelMapEntry() : impl_(NULL), ref_(0) {}
337 explicit ChannelMapEntry(TransportChannelImpl *impl) 332 explicit ChannelMapEntry(TransportChannelImpl *impl)
338 : impl_(impl), 333 : impl_(impl),
339 candidates_allocated_(false),
340 ref_(0) { 334 ref_(0) {
341 } 335 }
342 336
343 void AddRef() { ++ref_; } 337 void AddRef() { ++ref_; }
344 void DecRef() { 338 void DecRef() {
345 ASSERT(ref_ > 0); 339 ASSERT(ref_ > 0);
346 --ref_; 340 --ref_;
347 } 341 }
348 int ref() const { return ref_; } 342 int ref() const { return ref_; }
349 343
350 TransportChannelImpl* get() const { return impl_; } 344 TransportChannelImpl* get() const { return impl_; }
351 TransportChannelImpl* operator->() const { return impl_; } 345 TransportChannelImpl* operator->() const { return impl_; }
352 void set_candidates_allocated(bool status) {
353 candidates_allocated_ = status;
354 }
355 bool candidates_allocated() const { return candidates_allocated_; }
356 346
357 private: 347 private:
358 TransportChannelImpl *impl_; 348 TransportChannelImpl* impl_;
359 bool candidates_allocated_;
360 int ref_; 349 int ref_;
361 }; 350 };
362 351
363 // Candidate component => ChannelMapEntry 352 // Candidate component => ChannelMapEntry
364 typedef std::map<int, ChannelMapEntry> ChannelMap; 353 typedef std::map<int, ChannelMapEntry> ChannelMap;
365 354
366 // Called when the write state of a channel changes. 355 // Called when the write state of a channel changes.
367 void OnChannelWritableState(TransportChannel* channel); 356 void OnChannelWritableState(TransportChannel* channel);
368 357
369 // Called when the receiving state of a channel changes. 358 // Called when the receiving state of a channel changes.
370 void OnChannelReceivingState(TransportChannel* channel); 359 void OnChannelReceivingState(TransportChannel* channel);
371 360
372 // Called when a channel requests signaling. 361 // Called when a channel starts finishes gathering candidates
373 void OnChannelRequestSignaling(TransportChannelImpl* channel); 362 void OnChannelGatheringState(TransportChannelImpl* channel);
374 363
375 // Called when a candidate is ready from remote peer.
376 void OnRemoteCandidate(const Candidate& candidate);
377 // Called when a candidate is ready from channel. 364 // Called when a candidate is ready from channel.
378 void OnChannelCandidateReady(TransportChannelImpl* channel, 365 void OnChannelCandidateGathered(TransportChannelImpl* channel,
379 const Candidate& candidate); 366 const Candidate& candidate);
380 void OnChannelRouteChange(TransportChannel* channel, 367 void OnChannelRouteChange(TransportChannel* channel,
381 const Candidate& remote_candidate); 368 const Candidate& remote_candidate);
382 void OnChannelCandidatesAllocationDone(TransportChannelImpl* channel);
383 // Called when there is ICE role change. 369 // Called when there is ICE role change.
384 void OnRoleConflict(TransportChannelImpl* channel); 370 void OnRoleConflict(TransportChannelImpl* channel);
385 // Called when the channel removes a connection. 371 // Called when the channel removes a connection.
386 void OnChannelConnectionRemoved(TransportChannelImpl* channel); 372 void OnChannelConnectionRemoved(TransportChannelImpl* channel);
387 373
388 // Dispatches messages to the appropriate handler (below).
389 void OnMessage(rtc::Message* msg);
390
391 // These are versions of the above methods that are called only on a
392 // particular thread (s = signaling, w = worker). The above methods post or
393 // send a message to invoke this version.
394 TransportChannelImpl* CreateChannel_w(int component);
395 void DestroyChannel_w(int component);
396 void ConnectChannels_w();
397 void ResetChannels_w();
398 void DestroyAllChannels_w();
399 void OnRemoteCandidate_w(const Candidate& candidate);
400 void OnChannelWritableState_s();
401 void OnChannelReceivingState_s();
402 void OnChannelRequestSignaling_s();
403 void OnConnecting_s();
404 void OnChannelRouteChange_s(const TransportChannel* channel,
405 const Candidate& remote_candidate);
406 void OnChannelCandidatesAllocationDone_s();
407
408 // Helper function that invokes the given function on every channel. 374 // Helper function that invokes the given function on every channel.
409 typedef void (TransportChannelImpl::* TransportChannelFunc)(); 375 typedef void (TransportChannelImpl::* TransportChannelFunc)();
410 void CallChannels_w(TransportChannelFunc func); 376 void CallChannels(TransportChannelFunc func);
411 377
412 // Computes the AND and OR of the channel's read/write/receiving state 378 // Computes the AND and OR of the channel's read/write/receiving state
413 // (argument picks the operation). 379 // (argument picks the operation).
414 TransportState GetTransportState_s(TransportStateType type); 380 TransportState GetTransportState(TransportStateType type);
415
416 void OnChannelCandidateReady_s();
417
418 void SetIceRole_w(IceRole role);
419 void SetRemoteIceMode_w(IceMode mode);
420 bool SetLocalTransportDescription_w(const TransportDescription& desc,
421 ContentAction action,
422 std::string* error_desc);
423 bool SetRemoteTransportDescription_w(const TransportDescription& desc,
424 ContentAction action,
425 std::string* error_desc);
426 bool GetStats_w(TransportStats* infos);
427 bool GetRemoteSSLCertificate_w(rtc::SSLCertificate** cert);
428
429 void SetChannelReceivingTimeout_w(int timeout_ms);
430 381
431 // Sends SignalCompleted if we are now in that state. 382 // Sends SignalCompleted if we are now in that state.
432 void MaybeCompleted_w(); 383 void MaybeSignalCompleted();
433 384
434 rtc::Thread* const signaling_thread_; 385 // Sends SignalGatheringState if gathering state changed
435 rtc::Thread* const worker_thread_; 386 void UpdateGatheringState();
436 const std::string content_name_; 387
388 void UpdateWritableState();
389 void UpdateReceivingState();
390
391 const std::string name_;
437 PortAllocator* const allocator_; 392 PortAllocator* const allocator_;
438 bool destroyed_; 393 bool channels_destroyed_ = false;
439 TransportState readable_; 394 TransportState readable_ = TRANSPORT_STATE_NONE;
440 TransportState writable_; 395 TransportState writable_ = TRANSPORT_STATE_NONE;
441 TransportState receiving_; 396 TransportState receiving_ = TRANSPORT_STATE_NONE;
442 bool was_writable_; 397 bool was_writable_ = false;
443 bool connect_requested_; 398 bool connect_requested_ = false;
444 IceRole ice_role_; 399 IceRole ice_role_ = ICEROLE_UNKNOWN;
445 uint64 tiebreaker_; 400 uint64 tiebreaker_ = 0;
446 IceMode remote_ice_mode_; 401 IceMode remote_ice_mode_ = ICEMODE_FULL;
447 int channel_receiving_timeout_; 402 int channel_receiving_timeout_ = -1;
448 rtc::scoped_ptr<TransportDescription> local_description_; 403 rtc::scoped_ptr<TransportDescription> local_description_;
449 rtc::scoped_ptr<TransportDescription> remote_description_; 404 rtc::scoped_ptr<TransportDescription> remote_description_;
405 bool local_description_set_ = false;
406 bool remote_description_set_ = false;
407 IceGatheringState gathering_state_ = kIceGatheringNew;
450 408
451 // TODO(tommi): Make sure we only use this on the worker thread.
452 ChannelMap channels_; 409 ChannelMap channels_;
453 // Buffers the ready_candidates so that SignalCanidatesReady can
454 // provide them in multiples.
455 std::vector<Candidate> ready_candidates_;
456 // Protects changes to channels and messages
457 rtc::CriticalSection crit_;
458 410
459 RTC_DISALLOW_COPY_AND_ASSIGN(Transport); 411 RTC_DISALLOW_COPY_AND_ASSIGN(Transport);
460 }; 412 };
461 413
462 414
463 } // namespace cricket 415 } // namespace cricket
464 416
465 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_ 417 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_
OLDNEW
« no previous file with comments | « webrtc/p2p/base/session_unittest.cc ('k') | webrtc/p2p/base/transport.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698