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