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 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 // TODO(deadbeef): Unify with PeerConnectionInterface::IceConnectionState | 59 // TODO(deadbeef): Unify with PeerConnectionInterface::IceConnectionState |
60 // once /talk/ and /webrtc/ are combined, and also switch to ENUM_NAME naming | 60 // once /talk/ and /webrtc/ are combined, and also switch to ENUM_NAME naming |
61 // style. | 61 // style. |
62 enum IceGatheringState { | 62 enum IceGatheringState { |
63 kIceGatheringNew = 0, | 63 kIceGatheringNew = 0, |
64 kIceGatheringGathering, | 64 kIceGatheringGathering, |
65 kIceGatheringComplete, | 65 kIceGatheringComplete, |
66 }; | 66 }; |
67 | 67 |
68 // For "writable" and "receiving", we need to differentiate between | |
69 // none, all, and some. | |
70 enum TransportState { | |
71 TRANSPORT_STATE_NONE = 0, | |
72 TRANSPORT_STATE_SOME, | |
73 TRANSPORT_STATE_ALL | |
74 }; | |
75 | |
76 // When checking transport state, we need to differentiate between | |
77 // "writable" or "receiving" check. | |
78 enum TransportStateType { | |
79 TRANSPORT_WRITABLE_STATE = 0, | |
80 TRANSPORT_RECEIVING_STATE | |
81 }; | |
82 | |
83 // Stats that we can return about the connections for a transport channel. | 68 // Stats that we can return about the connections for a transport channel. |
84 // TODO(hta): Rename to ConnectionStats | 69 // TODO(hta): Rename to ConnectionStats |
85 struct ConnectionInfo { | 70 struct ConnectionInfo { |
86 ConnectionInfo() | 71 ConnectionInfo() |
87 : best_connection(false), | 72 : best_connection(false), |
88 writable(false), | 73 writable(false), |
89 receiving(false), | 74 receiving(false), |
90 timeout(false), | 75 timeout(false), |
91 new_connection(false), | 76 new_connection(false), |
92 rtt(0), | 77 rtt(0), |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 public: | 143 public: |
159 Transport(const std::string& name, PortAllocator* allocator); | 144 Transport(const std::string& name, PortAllocator* allocator); |
160 virtual ~Transport(); | 145 virtual ~Transport(); |
161 | 146 |
162 // Returns the name of this transport. | 147 // Returns the name of this transport. |
163 const std::string& name() const { return name_; } | 148 const std::string& name() const { return name_; } |
164 | 149 |
165 // Returns the port allocator object for this transport. | 150 // Returns the port allocator object for this transport. |
166 PortAllocator* port_allocator() { return allocator_; } | 151 PortAllocator* port_allocator() { return allocator_; } |
167 | 152 |
168 // Returns the states of this manager. These bits are the ORs | |
169 // of the corresponding bits on the managed channels. Each time one of these | |
170 // states changes, a signal is raised. | |
171 // TODO(honghaiz): Replace uses of writable() with any_channels_writable(). | |
172 bool writable() const { return any_channels_writable(); } | |
173 bool was_writable() const { return was_writable_; } | |
174 bool any_channels_writable() const { | |
175 return (writable_ == TRANSPORT_STATE_SOME || | |
176 writable_ == TRANSPORT_STATE_ALL); | |
177 } | |
178 bool all_channels_writable() const { | |
179 return (writable_ == TRANSPORT_STATE_ALL); | |
180 } | |
181 bool any_channel_receiving() const { | |
182 return (receiving_ == TRANSPORT_STATE_SOME || | |
183 receiving_ == TRANSPORT_STATE_ALL); | |
184 } | |
185 bool ready_for_remote_candidates() const { | 153 bool ready_for_remote_candidates() const { |
186 return local_description_set_ && remote_description_set_; | 154 return local_description_set_ && remote_description_set_; |
187 } | 155 } |
188 | 156 |
189 bool AllChannelsCompleted() const; | |
190 bool AnyChannelFailed() const; | |
191 | |
192 IceGatheringState gathering_state() const { return gathering_state_; } | |
193 | |
194 sigslot::signal1<Transport*> SignalWritableState; | |
195 sigslot::signal1<Transport*> SignalReceivingState; | |
196 sigslot::signal1<Transport*> SignalCompleted; | |
197 sigslot::signal1<Transport*> SignalFailed; | |
198 | |
199 // Returns whether the client has requested the channels to connect. | 157 // Returns whether the client has requested the channels to connect. |
200 bool connect_requested() const { return connect_requested_; } | 158 bool connect_requested() const { return connect_requested_; } |
201 | 159 |
202 void SetIceRole(IceRole role); | 160 void SetIceRole(IceRole role); |
203 IceRole ice_role() const { return ice_role_; } | 161 IceRole ice_role() const { return ice_role_; } |
204 | 162 |
205 void SetIceTiebreaker(uint64 IceTiebreaker) { tiebreaker_ = IceTiebreaker; } | 163 void SetIceTiebreaker(uint64 IceTiebreaker) { tiebreaker_ = IceTiebreaker; } |
206 uint64 IceTiebreaker() { return tiebreaker_; } | 164 uint64 IceTiebreaker() { return tiebreaker_; } |
207 | 165 |
208 void SetIceConfig(const IceConfig& config); | 166 void SetIceConfig(const IceConfig& config); |
(...skipping 13 matching lines...) Expand all Loading... |
222 | 180 |
223 // Create, destroy, and lookup the channels of this type by their components. | 181 // Create, destroy, and lookup the channels of this type by their components. |
224 TransportChannelImpl* CreateChannel(int component); | 182 TransportChannelImpl* CreateChannel(int component); |
225 | 183 |
226 TransportChannelImpl* GetChannel(int component); | 184 TransportChannelImpl* GetChannel(int component); |
227 | 185 |
228 bool HasChannel(int component) { | 186 bool HasChannel(int component) { |
229 return (NULL != GetChannel(component)); | 187 return (NULL != GetChannel(component)); |
230 } | 188 } |
231 bool HasChannels(); | 189 bool HasChannels(); |
| 190 |
232 void DestroyChannel(int component); | 191 void DestroyChannel(int component); |
233 | 192 |
234 // Set the local TransportDescription to be used by TransportChannels. | 193 // Set the local TransportDescription to be used by TransportChannels. |
235 bool SetLocalTransportDescription(const TransportDescription& description, | 194 bool SetLocalTransportDescription(const TransportDescription& description, |
236 ContentAction action, | 195 ContentAction action, |
237 std::string* error_desc); | 196 std::string* error_desc); |
238 | 197 |
239 // Set the remote TransportDescription to be used by TransportChannels. | 198 // Set the remote TransportDescription to be used by TransportChannels. |
240 bool SetRemoteTransportDescription(const TransportDescription& description, | 199 bool SetRemoteTransportDescription(const TransportDescription& description, |
241 ContentAction action, | 200 ContentAction action, |
242 std::string* error_desc); | 201 std::string* error_desc); |
243 | 202 |
244 // Tells all current and future channels to start connecting. When the first | 203 // Tells all current and future channels to start connecting. |
245 // channel begins connecting, the following signal is raised. | |
246 void ConnectChannels(); | 204 void ConnectChannels(); |
247 sigslot::signal1<Transport*> SignalConnecting; | |
248 | 205 |
249 // Tells channels to start gathering candidates if necessary. | 206 // Tells channels to start gathering candidates if necessary. |
250 // Should be called after ConnectChannels() has been called at least once, | 207 // Should be called after ConnectChannels() has been called at least once, |
251 // which will happen in SetLocalTransportDescription. | 208 // which will happen in SetLocalTransportDescription. |
252 void MaybeStartGathering(); | 209 void MaybeStartGathering(); |
253 | 210 |
254 // Resets all of the channels back to their initial state. They are no | 211 // Resets all of the channels back to their initial state. They are no |
255 // longer connecting. | 212 // longer connecting. |
256 void ResetChannels(); | 213 void ResetChannels(); |
257 | 214 |
258 // Destroys every channel created so far. | 215 // Destroys every channel created so far. |
259 void DestroyAllChannels(); | 216 void DestroyAllChannels(); |
260 | 217 |
261 bool GetStats(TransportStats* stats); | 218 bool GetStats(TransportStats* stats); |
262 | 219 |
263 sigslot::signal1<Transport*> SignalGatheringState; | |
264 | |
265 // Handles sending of ready candidates and receiving of remote candidates. | |
266 sigslot::signal2<Transport*, const std::vector<Candidate>&> | |
267 SignalCandidatesGathered; | |
268 | |
269 // Called when one or more candidates are ready from the remote peer. | 220 // Called when one or more candidates are ready from the remote peer. |
270 bool AddRemoteCandidates(const std::vector<Candidate>& candidates, | 221 bool AddRemoteCandidates(const std::vector<Candidate>& candidates, |
271 std::string* error); | 222 std::string* error); |
272 | 223 |
273 // If candidate is not acceptable, returns false and sets error. | 224 // If candidate is not acceptable, returns false and sets error. |
274 // Call this before calling OnRemoteCandidates. | 225 // Call this before calling OnRemoteCandidates. |
275 virtual bool VerifyCandidate(const Candidate& candidate, | 226 virtual bool VerifyCandidate(const Candidate& candidate, |
276 std::string* error); | 227 std::string* error); |
277 | 228 |
278 // Signals when the best connection for a channel changes. | |
279 sigslot::signal3<Transport*, | |
280 int, // component | |
281 const Candidate&> SignalRouteChange; | |
282 | |
283 // Forwards the signal from TransportChannel to BaseSession. | |
284 sigslot::signal0<> SignalRoleConflict; | |
285 | |
286 virtual bool GetSslRole(rtc::SSLRole* ssl_role) const { return false; } | 229 virtual bool GetSslRole(rtc::SSLRole* ssl_role) const { return false; } |
287 | 230 |
288 // Must be called before channel is starting to connect. | 231 // Must be called before channel is starting to connect. |
289 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version) { | 232 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version) { |
290 return false; | 233 return false; |
291 } | 234 } |
292 | 235 |
293 protected: | 236 protected: |
294 // These are called by Create/DestroyChannel above in order to create or | 237 // These are called by Create/DestroyChannel above in order to create or |
295 // destroy the appropriate type of channel. | 238 // destroy the appropriate type of channel. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 std::string* error_desc); | 271 std::string* error_desc); |
329 | 272 |
330 // Pushes down the transport parameters obtained via negotiation. | 273 // Pushes down the transport parameters obtained via negotiation. |
331 // Derived classes can set their specific parameters here, but must call the | 274 // Derived classes can set their specific parameters here, but must call the |
332 // base as well. | 275 // base as well. |
333 virtual bool ApplyNegotiatedTransportDescription( | 276 virtual bool ApplyNegotiatedTransportDescription( |
334 TransportChannelImpl* channel, | 277 TransportChannelImpl* channel, |
335 std::string* error_desc); | 278 std::string* error_desc); |
336 | 279 |
337 private: | 280 private: |
338 struct ChannelMapEntry { | 281 // Candidate component => TransportChannelImpl* |
339 ChannelMapEntry() : impl_(NULL), ref_(0) {} | 282 typedef std::map<int, TransportChannelImpl*> ChannelMap; |
340 explicit ChannelMapEntry(TransportChannelImpl *impl) | |
341 : impl_(impl), | |
342 ref_(0) { | |
343 } | |
344 | |
345 void AddRef() { ++ref_; } | |
346 void DecRef() { | |
347 ASSERT(ref_ > 0); | |
348 --ref_; | |
349 } | |
350 int ref() const { return ref_; } | |
351 | |
352 TransportChannelImpl* get() const { return impl_; } | |
353 TransportChannelImpl* operator->() const { return impl_; } | |
354 | |
355 private: | |
356 TransportChannelImpl* impl_; | |
357 int ref_; | |
358 }; | |
359 | |
360 // Candidate component => ChannelMapEntry | |
361 typedef std::map<int, ChannelMapEntry> ChannelMap; | |
362 | |
363 // Called when the write state of a channel changes. | |
364 void OnChannelWritableState(TransportChannel* channel); | |
365 | |
366 // Called when the receiving state of a channel changes. | |
367 void OnChannelReceivingState(TransportChannel* channel); | |
368 | |
369 // Called when a channel starts finishes gathering candidates | |
370 void OnChannelGatheringState(TransportChannelImpl* channel); | |
371 | |
372 // Called when a candidate is ready from channel. | |
373 void OnChannelCandidateGathered(TransportChannelImpl* channel, | |
374 const Candidate& candidate); | |
375 void OnChannelRouteChange(TransportChannel* channel, | |
376 const Candidate& remote_candidate); | |
377 // Called when there is ICE role change. | |
378 void OnRoleConflict(TransportChannelImpl* channel); | |
379 // Called when the channel removes a connection. | |
380 void OnChannelConnectionRemoved(TransportChannelImpl* channel); | |
381 | 283 |
382 // Helper function that invokes the given function on every channel. | 284 // Helper function that invokes the given function on every channel. |
383 typedef void (TransportChannelImpl::* TransportChannelFunc)(); | 285 typedef void (TransportChannelImpl::* TransportChannelFunc)(); |
384 void CallChannels(TransportChannelFunc func); | 286 void CallChannels(TransportChannelFunc func); |
385 | 287 |
386 // Computes the AND and OR of the channel's read/write/receiving state | |
387 // (argument picks the operation). | |
388 TransportState GetTransportState(TransportStateType type); | |
389 | |
390 // Sends SignalCompleted if we are now in that state. | |
391 void MaybeSignalCompleted(); | |
392 | |
393 // Sends SignalGatheringState if gathering state changed | |
394 void UpdateGatheringState(); | |
395 | |
396 void UpdateWritableState(); | |
397 void UpdateReceivingState(); | |
398 | |
399 const std::string name_; | 288 const std::string name_; |
400 PortAllocator* const allocator_; | 289 PortAllocator* const allocator_; |
401 bool channels_destroyed_ = false; | 290 bool channels_destroyed_ = false; |
402 TransportState readable_ = TRANSPORT_STATE_NONE; | |
403 TransportState writable_ = TRANSPORT_STATE_NONE; | |
404 TransportState receiving_ = TRANSPORT_STATE_NONE; | |
405 bool was_writable_ = false; | |
406 bool connect_requested_ = false; | 291 bool connect_requested_ = false; |
407 IceRole ice_role_ = ICEROLE_UNKNOWN; | 292 IceRole ice_role_ = ICEROLE_UNKNOWN; |
408 uint64 tiebreaker_ = 0; | 293 uint64 tiebreaker_ = 0; |
409 IceMode remote_ice_mode_ = ICEMODE_FULL; | 294 IceMode remote_ice_mode_ = ICEMODE_FULL; |
410 IceConfig ice_config_; | 295 IceConfig ice_config_; |
411 rtc::scoped_ptr<TransportDescription> local_description_; | 296 rtc::scoped_ptr<TransportDescription> local_description_; |
412 rtc::scoped_ptr<TransportDescription> remote_description_; | 297 rtc::scoped_ptr<TransportDescription> remote_description_; |
413 bool local_description_set_ = false; | 298 bool local_description_set_ = false; |
414 bool remote_description_set_ = false; | 299 bool remote_description_set_ = false; |
415 IceGatheringState gathering_state_ = kIceGatheringNew; | |
416 | 300 |
417 ChannelMap channels_; | 301 ChannelMap channels_; |
418 | 302 |
419 RTC_DISALLOW_COPY_AND_ASSIGN(Transport); | 303 RTC_DISALLOW_COPY_AND_ASSIGN(Transport); |
420 }; | 304 }; |
421 | 305 |
422 | 306 |
423 } // namespace cricket | 307 } // namespace cricket |
424 | 308 |
425 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_ | 309 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_ |
OLD | NEW |