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 #include "webrtc/p2p/base/jseptransport.h" |
| 12 |
11 #include <memory> | 13 #include <memory> |
12 #include <utility> // for std::pair | 14 #include <utility> // for std::pair |
13 | 15 |
14 #include "webrtc/p2p/base/jseptransport.h" | 16 #include "webrtc/base/bind.h" |
15 | 17 #include "webrtc/base/checks.h" |
| 18 #include "webrtc/base/logging.h" |
16 #include "webrtc/p2p/base/candidate.h" | 19 #include "webrtc/p2p/base/candidate.h" |
17 #include "webrtc/p2p/base/dtlstransportchannel.h" | 20 #include "webrtc/p2p/base/dtlstransportchannel.h" |
18 #include "webrtc/p2p/base/p2pconstants.h" | 21 #include "webrtc/p2p/base/p2pconstants.h" |
19 #include "webrtc/p2p/base/p2ptransportchannel.h" | 22 #include "webrtc/p2p/base/p2ptransportchannel.h" |
20 #include "webrtc/p2p/base/port.h" | 23 #include "webrtc/p2p/base/port.h" |
21 #include "webrtc/p2p/base/transportchannelimpl.h" | |
22 #include "webrtc/base/bind.h" | |
23 #include "webrtc/base/checks.h" | |
24 #include "webrtc/base/logging.h" | |
25 | 24 |
26 namespace cricket { | 25 namespace cricket { |
27 | 26 |
28 static bool VerifyIceParams(const TransportDescription& desc) { | 27 static bool VerifyIceParams(const TransportDescription& desc) { |
29 // For legacy protocols. | 28 // For legacy protocols. |
30 if (desc.ice_ufrag.empty() && desc.ice_pwd.empty()) | 29 if (desc.ice_ufrag.empty() && desc.ice_pwd.empty()) |
31 return true; | 30 return true; |
32 | 31 |
33 if (desc.ice_ufrag.length() < ICE_UFRAG_MIN_LENGTH || | 32 if (desc.ice_ufrag.length() < ICE_UFRAG_MIN_LENGTH || |
34 desc.ice_ufrag.length() > ICE_UFRAG_MAX_LENGTH) { | 33 desc.ice_ufrag.length() > ICE_UFRAG_MAX_LENGTH) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 } | 119 } |
121 } | 120 } |
122 return true; | 121 return true; |
123 } | 122 } |
124 | 123 |
125 JsepTransport::JsepTransport( | 124 JsepTransport::JsepTransport( |
126 const std::string& mid, | 125 const std::string& mid, |
127 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) | 126 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) |
128 : mid_(mid), certificate_(certificate) {} | 127 : mid_(mid), certificate_(certificate) {} |
129 | 128 |
130 bool JsepTransport::AddChannel(TransportChannelImpl* dtls, int component) { | 129 bool JsepTransport::AddChannel(DtlsTransportInternal* dtls, int component) { |
131 if (channels_.find(component) != channels_.end()) { | 130 if (channels_.find(component) != channels_.end()) { |
132 LOG(LS_ERROR) << "Adding channel for component " << component << " twice."; | 131 LOG(LS_ERROR) << "Adding channel for component " << component << " twice."; |
133 return false; | 132 return false; |
134 } | 133 } |
135 channels_[component] = dtls; | 134 channels_[component] = dtls; |
136 // Something's wrong if a channel is being added after a description is set. | 135 // Something's wrong if a channel is being added after a description is set. |
137 // This may currently occur if rtcp-mux is negotiated, then a new m= section | 136 // This may currently occur if rtcp-mux is negotiated, then a new m= section |
138 // is added in a later offer/answer. But this is suboptimal and should be | 137 // is added in a later offer/answer. But this is suboptimal and should be |
139 // changed; we shouldn't support going from muxed to non-muxed. | 138 // changed; we shouldn't support going from muxed to non-muxed. |
140 // TODO(deadbeef): Once this is fixed, make the warning an error, and remove | 139 // TODO(deadbeef): Once this is fixed, make the warning an error, and remove |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 278 |
280 void JsepTransport::GetSslRole(rtc::SSLRole* ssl_role) const { | 279 void JsepTransport::GetSslRole(rtc::SSLRole* ssl_role) const { |
281 RTC_DCHECK(ssl_role); | 280 RTC_DCHECK(ssl_role); |
282 *ssl_role = secure_role_; | 281 *ssl_role = secure_role_; |
283 } | 282 } |
284 | 283 |
285 bool JsepTransport::GetStats(TransportStats* stats) { | 284 bool JsepTransport::GetStats(TransportStats* stats) { |
286 stats->transport_name = mid(); | 285 stats->transport_name = mid(); |
287 stats->channel_stats.clear(); | 286 stats->channel_stats.clear(); |
288 for (auto& kv : channels_) { | 287 for (auto& kv : channels_) { |
289 TransportChannelImpl* channel = kv.second; | 288 DtlsTransportInternal* dtls_transport = kv.second; |
290 TransportChannelStats substats; | 289 TransportChannelStats substats; |
291 substats.component = kv.first; | 290 substats.component = kv.first; |
292 channel->GetSrtpCryptoSuite(&substats.srtp_crypto_suite); | 291 dtls_transport->GetSrtpCryptoSuite(&substats.srtp_crypto_suite); |
293 channel->GetSslCipherSuite(&substats.ssl_cipher_suite); | 292 dtls_transport->GetSslCipherSuite(&substats.ssl_cipher_suite); |
294 if (!channel->GetStats(&substats.connection_infos)) { | 293 if (!dtls_transport->ice_transport()->GetStats( |
| 294 &substats.connection_infos)) { |
295 return false; | 295 return false; |
296 } | 296 } |
297 stats->channel_stats.push_back(substats); | 297 stats->channel_stats.push_back(substats); |
298 } | 298 } |
299 return true; | 299 return true; |
300 } | 300 } |
301 | 301 |
302 bool JsepTransport::VerifyCertificateFingerprint( | 302 bool JsepTransport::VerifyCertificateFingerprint( |
303 const rtc::RTCCertificate* certificate, | 303 const rtc::RTCCertificate* certificate, |
304 const rtc::SSLFingerprint* fingerprint, | 304 const rtc::SSLFingerprint* fingerprint, |
(...skipping 12 matching lines...) Expand all Loading... |
317 return true; | 317 return true; |
318 } | 318 } |
319 std::ostringstream desc; | 319 std::ostringstream desc; |
320 desc << "Local fingerprint does not match identity. Expected: "; | 320 desc << "Local fingerprint does not match identity. Expected: "; |
321 desc << fp_tmp->ToString(); | 321 desc << fp_tmp->ToString(); |
322 desc << " Got: " << fingerprint->ToString(); | 322 desc << " Got: " << fingerprint->ToString(); |
323 return BadTransportDescription(desc.str(), error_desc); | 323 return BadTransportDescription(desc.str(), error_desc); |
324 } | 324 } |
325 | 325 |
326 bool JsepTransport::ApplyLocalTransportDescription( | 326 bool JsepTransport::ApplyLocalTransportDescription( |
327 TransportChannelImpl* channel, | 327 DtlsTransportInternal* dtls_transport, |
328 std::string* error_desc) { | 328 std::string* error_desc) { |
329 channel->SetIceParameters(local_description_->GetIceParameters()); | 329 dtls_transport->ice_transport()->SetIceParameters( |
| 330 local_description_->GetIceParameters()); |
330 return true; | 331 return true; |
331 } | 332 } |
332 | 333 |
333 bool JsepTransport::ApplyRemoteTransportDescription( | 334 bool JsepTransport::ApplyRemoteTransportDescription( |
334 TransportChannelImpl* channel, | 335 DtlsTransportInternal* dtls_transport, |
335 std::string* error_desc) { | 336 std::string* error_desc) { |
336 // Currently, all ICE-related calls still go through this DTLS channel. But | 337 // 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 // that will change once we get rid of TransportChannelImpl, and the DTLS |
338 // channel interface no longer includes ICE-specific methods. Then this class | 339 // channel interface no longer includes ICE-specific methods. Then this class |
339 // will need to call dtls->ice()->SetIceRole(), for example, assuming the Dtls | 340 // will need to call dtls->ice()->SetIceRole(), for example, assuming the Dtls |
340 // interface will expose its inner ICE channel. | 341 // interface will expose its inner ICE channel. |
341 channel->SetRemoteIceParameters(remote_description_->GetIceParameters()); | 342 dtls_transport->ice_transport()->SetRemoteIceParameters( |
342 channel->SetRemoteIceMode(remote_description_->ice_mode); | 343 remote_description_->GetIceParameters()); |
| 344 dtls_transport->ice_transport()->SetRemoteIceMode( |
| 345 remote_description_->ice_mode); |
343 return true; | 346 return true; |
344 } | 347 } |
345 | 348 |
346 bool JsepTransport::ApplyNegotiatedTransportDescription( | 349 bool JsepTransport::ApplyNegotiatedTransportDescription( |
347 TransportChannelImpl* channel, | 350 DtlsTransportInternal* dtls_transport, |
348 std::string* error_desc) { | 351 std::string* error_desc) { |
349 // Set SSL role. Role must be set before fingerprint is applied, which | 352 // Set SSL role. Role must be set before fingerprint is applied, which |
350 // initiates DTLS setup. | 353 // initiates DTLS setup. |
351 if (!channel->SetSslRole(secure_role_)) { | 354 if (!dtls_transport->SetSslRole(secure_role_)) { |
352 return BadTransportDescription("Failed to set SSL role for the channel.", | 355 return BadTransportDescription("Failed to set SSL role for the channel.", |
353 error_desc); | 356 error_desc); |
354 } | 357 } |
355 // Apply remote fingerprint. | 358 // Apply remote fingerprint. |
356 if (!channel->SetRemoteFingerprint( | 359 if (!dtls_transport->SetRemoteFingerprint( |
357 remote_fingerprint_->algorithm, | 360 remote_fingerprint_->algorithm, |
358 reinterpret_cast<const uint8_t*>(remote_fingerprint_->digest.data()), | 361 reinterpret_cast<const uint8_t*>(remote_fingerprint_->digest.data()), |
359 remote_fingerprint_->digest.size())) { | 362 remote_fingerprint_->digest.size())) { |
360 return BadTransportDescription("Failed to apply remote fingerprint.", | 363 return BadTransportDescription("Failed to apply remote fingerprint.", |
361 error_desc); | 364 error_desc); |
362 } | 365 } |
363 return true; | 366 return true; |
364 } | 367 } |
365 | 368 |
366 bool JsepTransport::NegotiateTransportDescription(ContentAction local_role, | 369 bool JsepTransport::NegotiateTransportDescription(ContentAction local_role, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 } | 477 } |
475 | 478 |
476 // If local is passive, local will act as server. | 479 // If local is passive, local will act as server. |
477 } | 480 } |
478 | 481 |
479 *ssl_role = is_remote_server ? rtc::SSL_CLIENT : rtc::SSL_SERVER; | 482 *ssl_role = is_remote_server ? rtc::SSL_CLIENT : rtc::SSL_SERVER; |
480 return true; | 483 return true; |
481 } | 484 } |
482 | 485 |
483 } // namespace cricket | 486 } // namespace cricket |
OLD | NEW |