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 25 matching lines...) Expand all Loading... | |
36 #include "webrtc/p2p/base/p2pconstants.h" | 36 #include "webrtc/p2p/base/p2pconstants.h" |
37 #include "webrtc/p2p/base/sessiondescription.h" | 37 #include "webrtc/p2p/base/sessiondescription.h" |
38 #include "webrtc/p2p/base/transportinfo.h" | 38 #include "webrtc/p2p/base/transportinfo.h" |
39 #include "webrtc/base/messagequeue.h" | 39 #include "webrtc/base/messagequeue.h" |
40 #include "webrtc/base/rtccertificate.h" | 40 #include "webrtc/base/rtccertificate.h" |
41 #include "webrtc/base/sigslot.h" | 41 #include "webrtc/base/sigslot.h" |
42 #include "webrtc/base/sslstreamadapter.h" | 42 #include "webrtc/base/sslstreamadapter.h" |
43 | 43 |
44 namespace cricket { | 44 namespace cricket { |
45 | 45 |
46 class PortAllocator; | 46 class TransportChannelImpl; |
47 class TransportChannel; | |
48 class TransportChannelImpl; | 47 class TransportChannelImpl; |
49 | 48 |
50 typedef std::vector<Candidate> Candidates; | 49 typedef std::vector<Candidate> Candidates; |
51 | 50 |
51 // TODO(deadbeef): Move all of these enums, POD types and utility methods to | |
52 // another header file. | |
53 | |
52 // TODO(deadbeef): Unify with PeerConnectionInterface::IceConnectionState | 54 // TODO(deadbeef): Unify with PeerConnectionInterface::IceConnectionState |
53 // once /talk/ and /webrtc/ are combined, and also switch to ENUM_NAME naming | 55 // once /talk/ and /webrtc/ are combined, and also switch to ENUM_NAME naming |
54 // style. | 56 // style. |
55 enum IceConnectionState { | 57 enum IceConnectionState { |
56 kIceConnectionConnecting = 0, | 58 kIceConnectionConnecting = 0, |
57 kIceConnectionFailed, | 59 kIceConnectionFailed, |
58 kIceConnectionConnected, // Writable, but still checking one or more | 60 kIceConnectionConnected, // Writable, but still checking one or more |
59 // connections | 61 // connections |
60 kIceConnectionCompleted, | 62 kIceConnectionCompleted, |
61 }; | 63 }; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 receiving_switching_delay(receiving_switching_delay_ms) {} | 237 receiving_switching_delay(receiving_switching_delay_ms) {} |
236 }; | 238 }; |
237 | 239 |
238 bool BadTransportDescription(const std::string& desc, std::string* err_desc); | 240 bool BadTransportDescription(const std::string& desc, std::string* err_desc); |
239 | 241 |
240 bool IceCredentialsChanged(const std::string& old_ufrag, | 242 bool IceCredentialsChanged(const std::string& old_ufrag, |
241 const std::string& old_pwd, | 243 const std::string& old_pwd, |
242 const std::string& new_ufrag, | 244 const std::string& new_ufrag, |
243 const std::string& new_pwd); | 245 const std::string& new_pwd); |
244 | 246 |
247 // If a candidate is not acceptable, returns false and sets error. | |
248 bool VerifyCandidate(const Candidate& candidate, std::string* error); | |
249 bool VerifyCandidates(const Candidates& candidates, std::string* error); | |
250 | |
251 // Helper class used by TransportController that processes | |
252 // TransportDescriptions. A TransportDescription represents the | |
253 // transport-specific properties of an SDP m= section, processed according to | |
254 // JSEP. Each transport consists of DTLS and ICE transport channels for RTP | |
pthatcher1
2016/11/30 01:34:35
I was hoping we could just delete this class. But
Taylor Brandstetter
2016/11/30 20:31:39
Maybe we'll do that eventually. But right now, Tra
| |
255 // (and possibly RTCP, if rtcp-mux isn't used). | |
245 class Transport : public sigslot::has_slots<> { | 256 class Transport : public sigslot::has_slots<> { |
246 public: | 257 public: |
247 Transport(const std::string& name, PortAllocator* allocator); | 258 // |name| is just used for log statements in order to identify the Transport. |
248 virtual ~Transport(); | 259 // Note that |certificate| is allowed to be null since a remote description |
260 // may be set before a local certificate is generated. | |
261 Transport(const std::string& name, | |
262 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); | |
249 | 263 |
250 // Returns the name of this transport. | 264 // Returns the name of this transport. |
251 const std::string& name() const { return name_; } | 265 const std::string& name() const { return name_; } |
252 | 266 |
253 // Returns the port allocator object for this transport. | 267 // Add or remove channels that are affected when a local/remote transport |
254 PortAllocator* port_allocator() { return allocator_; } | 268 // description is set on this transport. Need to add all channels before |
269 // setting a transport description. | |
270 bool AddChannel(TransportChannelImpl* dtls, | |
271 TransportChannelImpl* ice, | |
272 int component); | |
273 bool RemoveChannel(int component); | |
274 bool HasChannels() const; | |
255 | 275 |
256 bool ready_for_remote_candidates() const { | 276 bool ready_for_remote_candidates() const { |
257 return local_description_set_ && remote_description_set_; | 277 return local_description_set_ && remote_description_set_; |
258 } | 278 } |
259 | 279 |
260 void SetIceRole(IceRole role); | |
261 IceRole ice_role() const { return ice_role_; } | |
262 | |
263 void SetIceTiebreaker(uint64_t IceTiebreaker) { tiebreaker_ = IceTiebreaker; } | |
264 uint64_t IceTiebreaker() { return tiebreaker_; } | |
265 | |
266 void SetIceConfig(const IceConfig& config); | |
267 | |
268 // Must be called before applying local session description. | 280 // Must be called before applying local session description. |
269 virtual void SetLocalCertificate( | 281 // Needed in order to verify the local fingerprint. |
270 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) {} | 282 void SetLocalCertificate( |
283 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); | |
271 | 284 |
272 // Get a copy of the local certificate provided by SetLocalCertificate. | 285 // Get a copy of the local certificate provided by SetLocalCertificate. |
273 virtual bool GetLocalCertificate( | 286 bool GetLocalCertificate( |
274 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) { | 287 rtc::scoped_refptr<rtc::RTCCertificate>* certificate) const; |
275 return false; | |
276 } | |
277 | 288 |
278 // Get a copy of the remote certificate in use by the specified channel. | 289 // Set the local TransportDescription to be used by DTLS and ICE channels |
279 std::unique_ptr<rtc::SSLCertificate> GetRemoteSSLCertificate(); | 290 // that are part of this Transport. |
280 | |
281 // Create, destroy, and lookup the channels of this type by their components. | |
282 TransportChannelImpl* CreateChannel(int component); | |
283 | |
284 TransportChannelImpl* GetChannel(int component); | |
285 | |
286 bool HasChannel(int component) { | |
287 return (NULL != GetChannel(component)); | |
288 } | |
289 bool HasChannels(); | |
290 | |
291 void DestroyChannel(int component); | |
292 | |
293 // Set the local TransportDescription to be used by TransportChannels. | |
294 bool SetLocalTransportDescription(const TransportDescription& description, | 291 bool SetLocalTransportDescription(const TransportDescription& description, |
295 ContentAction action, | 292 ContentAction action, |
296 std::string* error_desc); | 293 std::string* error_desc); |
297 | 294 |
298 // Set the remote TransportDescription to be used by TransportChannels. | 295 // Set the remote TransportDescription to be used by DTLS and ICE channels |
296 // that are part of this Transport. | |
299 bool SetRemoteTransportDescription(const TransportDescription& description, | 297 bool SetRemoteTransportDescription(const TransportDescription& description, |
300 ContentAction action, | 298 ContentAction action, |
301 std::string* error_desc); | 299 std::string* error_desc); |
302 | 300 |
303 // Tells channels to start gathering candidates if necessary. | 301 void GetSslRole(rtc::SSLRole* ssl_role) const; |
304 // Should be called after ConnectChannels() has been called at least once, | |
305 // which will happen in SetLocalTransportDescription. | |
306 void MaybeStartGathering(); | |
307 | 302 |
308 // Resets all of the channels back to their initial state. They are no | 303 bool GetStats(TransportStats* stats) const; |
309 // longer connecting. | |
310 void ResetChannels(); | |
311 | 304 |
312 // Destroys every channel created so far. | 305 // The current local transport description, possibly used |
313 void DestroyAllChannels(); | |
314 | |
315 bool GetStats(TransportStats* stats); | |
316 | |
317 // Called when one or more candidates are ready from the remote peer. | |
318 bool AddRemoteCandidates(const std::vector<Candidate>& candidates, | |
319 std::string* error); | |
320 bool RemoveRemoteCandidates(const std::vector<Candidate>& candidates, | |
321 std::string* error); | |
322 | |
323 virtual bool GetSslRole(rtc::SSLRole* ssl_role) const { return false; } | |
324 | |
325 // Must be called before channel is starting to connect. | |
326 virtual bool SetSslMaxProtocolVersion(rtc::SSLProtocolVersion version) { | |
327 return false; | |
328 } | |
329 | |
330 // The current local transport description, for use by derived classes | |
331 // when performing transport description negotiation, and possibly used | |
332 // by the transport controller. | 306 // by the transport controller. |
333 const TransportDescription* local_description() const { | 307 const TransportDescription* local_description() const { |
334 return local_description_.get(); | 308 return local_description_.get(); |
335 } | 309 } |
336 | 310 |
337 // The current remote transport description, for use by derived classes | 311 // The current remote transport description, possibly used |
338 // when performing transport description negotiation, and possibly used | |
339 // by the transport controller. | 312 // by the transport controller. |
340 const TransportDescription* remote_description() const { | 313 const TransportDescription* remote_description() const { |
341 return remote_description_.get(); | 314 return remote_description_.get(); |
342 } | 315 } |
343 | 316 |
344 protected: | 317 // TODO(deadbeef): The methods below are only public for testing. Should make |
345 // These are called by Create/DestroyChannel above in order to create or | 318 // them utility functions or objects so they can be tested independently from |
346 // destroy the appropriate type of channel. | 319 // this class. |
347 virtual TransportChannelImpl* CreateTransportChannel(int component) = 0; | |
348 virtual void DestroyTransportChannel(TransportChannelImpl* channel) = 0; | |
349 | 320 |
350 // Pushes down the transport parameters from the local description, such | 321 // Returns false if the certificate's identity does not match the fingerprint, |
351 // as the ICE ufrag and pwd. | 322 // or either is NULL. |
352 // Derived classes can override, but must call the base as well. | 323 bool VerifyCertificateFingerprint(const rtc::RTCCertificate* certificate, |
353 virtual bool ApplyLocalTransportDescription(TransportChannelImpl* channel, | 324 const rtc::SSLFingerprint* fingerprint, |
354 std::string* error_desc); | 325 std::string* error_desc) const; |
355 | 326 |
356 // Pushes down remote ice credentials from the remote description to the | 327 // Negotiates the SSL role based off the offer and answer as specified by |
357 // transport channel. | 328 // RFC 4145, section-4.1. Returns false if the SSL role cannot be determined |
358 virtual bool ApplyRemoteTransportDescription(TransportChannelImpl* ch, | 329 // from the local description and remote description. |
359 std::string* error_desc); | 330 bool NegotiateRole(ContentAction local_role, |
331 rtc::SSLRole* ssl_role, | |
332 std::string* error_desc) const; | |
333 | |
334 private: | |
335 struct ChannelPair { | |
336 // Currently, all ICE-related calls still go through this DTLS channel. But | |
337 // that will change once we get rid of TransportChannelImpl, and the DTLS | |
338 // channel interface no longer includes ICE-specific methods. | |
339 TransportChannelImpl* dtls; | |
340 TransportChannelImpl* ice; | |
341 }; | |
342 | |
343 ChannelPair* GetChannel(int component); | |
360 | 344 |
361 // Negotiates the transport parameters based on the current local and remote | 345 // Negotiates the transport parameters based on the current local and remote |
362 // transport description, such as the ICE role to use, and whether DTLS | 346 // transport description, such as the ICE role to use, and whether DTLS |
363 // should be activated. | 347 // should be activated. |
364 // Derived classes can negotiate their specific parameters here, but must call | 348 // |
365 // the base as well. | 349 // Called when an answer TransportDescription is applied. |
366 virtual bool NegotiateTransportDescription(ContentAction local_role, | 350 bool NegotiateTransportDescription(ContentAction local_role, |
367 std::string* error_desc); | 351 std::string* error_desc); |
352 | |
353 // Pushes down the transport parameters from the local description, such | |
354 // as the ICE ufrag and pwd. | |
355 bool ApplyLocalTransportDescription(const ChannelPair& channel, | |
356 std::string* error_desc); | |
357 | |
358 // Pushes down the transport parameters from the remote description to the | |
359 // transport channel. | |
360 bool ApplyRemoteTransportDescription(const ChannelPair& channel, | |
361 std::string* error_desc); | |
368 | 362 |
369 // Pushes down the transport parameters obtained via negotiation. | 363 // Pushes down the transport parameters obtained via negotiation. |
370 // Derived classes can set their specific parameters here, but must call the | 364 bool ApplyNegotiatedTransportDescription(const ChannelPair& channel, |
371 // base as well. | 365 std::string* error_desc); |
372 virtual bool ApplyNegotiatedTransportDescription( | |
373 TransportChannelImpl* channel, | |
374 std::string* error_desc); | |
375 | 366 |
376 // Returns false if the certificate's identity does not match the fingerprint, | 367 // Candidate component => ChannelPair |
377 // or either is NULL. | 368 typedef std::map<int, ChannelPair> ChannelMap; |
378 virtual bool VerifyCertificateFingerprint( | |
379 const rtc::RTCCertificate* certificate, | |
380 const rtc::SSLFingerprint* fingerprint, | |
381 std::string* error_desc) const; | |
382 | |
383 // Negotiates the SSL role based off the offer and answer as specified by | |
384 // RFC 4145, section-4.1. Returns false if the SSL role cannot be determined | |
385 // from the local description and remote description. | |
386 virtual bool NegotiateRole(ContentAction local_role, | |
387 rtc::SSLRole* ssl_role, | |
388 std::string* error_desc) const; | |
389 | |
390 private: | |
391 // If a candidate is not acceptable, returns false and sets error. | |
392 // Call this before calling OnRemoteCandidates. | |
393 bool VerifyCandidate(const Candidate& candidate, std::string* error); | |
394 bool VerifyCandidates(const Candidates& candidates, std::string* error); | |
395 | |
396 // Candidate component => TransportChannelImpl* | |
397 typedef std::map<int, TransportChannelImpl*> ChannelMap; | |
398 | |
399 // Helper function that invokes the given function on every channel. | |
400 typedef void (TransportChannelImpl::* TransportChannelFunc)(); | |
401 void CallChannels(TransportChannelFunc func); | |
402 | 369 |
403 const std::string name_; | 370 const std::string name_; |
404 PortAllocator* const allocator_; | 371 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; |
405 bool channels_destroyed_ = false; | 372 rtc::SSLRole secure_role_ = rtc::SSL_CLIENT; |
406 IceRole ice_role_ = ICEROLE_UNKNOWN; | 373 std::unique_ptr<rtc::SSLFingerprint> remote_fingerprint_; |
407 uint64_t tiebreaker_ = 0; | |
408 IceMode remote_ice_mode_ = ICEMODE_FULL; | |
409 IceConfig ice_config_; | |
410 std::unique_ptr<TransportDescription> local_description_; | 374 std::unique_ptr<TransportDescription> local_description_; |
411 std::unique_ptr<TransportDescription> remote_description_; | 375 std::unique_ptr<TransportDescription> remote_description_; |
412 bool local_description_set_ = false; | 376 bool local_description_set_ = false; |
413 bool remote_description_set_ = false; | 377 bool remote_description_set_ = false; |
414 | 378 |
415 ChannelMap channels_; | 379 ChannelMap channels_; |
pthatcher1
2016/11/30 01:34:35
While we're in here, I've always thought this map
Taylor Brandstetter
2016/11/30 20:31:39
I can change that in a separate CL, but I don't th
| |
416 | 380 |
417 RTC_DISALLOW_COPY_AND_ASSIGN(Transport); | 381 RTC_DISALLOW_COPY_AND_ASSIGN(Transport); |
418 }; | 382 }; |
419 | 383 |
420 | 384 |
421 } // namespace cricket | 385 } // namespace cricket |
422 | 386 |
423 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_ | 387 #endif // WEBRTC_P2P_BASE_TRANSPORT_H_ |
OLD | NEW |