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

Side by Side Diff: talk/app/webrtc/webrtcsession.cc

Issue 1269843005: Added DtlsCertificate, a ref counted object owning an SSLIdentity (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Cleanup Created 5 years, 4 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
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 SignalVoiceChannelDestroyed(); 510 SignalVoiceChannelDestroyed();
511 channel_manager_->DestroyVoiceChannel(voice_channel_.release(), nullptr); 511 channel_manager_->DestroyVoiceChannel(voice_channel_.release(), nullptr);
512 } 512 }
513 if (data_channel_) { 513 if (data_channel_) {
514 SignalDataChannelDestroyed(); 514 SignalDataChannelDestroyed();
515 channel_manager_->DestroyDataChannel(data_channel_.release()); 515 channel_manager_->DestroyDataChannel(data_channel_.release());
516 } 516 }
517 for (size_t i = 0; i < saved_candidates_.size(); ++i) { 517 for (size_t i = 0; i < saved_candidates_.size(); ++i) {
518 delete saved_candidates_[i]; 518 delete saved_candidates_[i];
519 } 519 }
520 delete identity();
521 } 520 }
522 521
523 bool WebRtcSession::Initialize( 522 bool WebRtcSession::Initialize(
524 const PeerConnectionFactoryInterface::Options& options, 523 const PeerConnectionFactoryInterface::Options& options,
525 const MediaConstraintsInterface* constraints, 524 const MediaConstraintsInterface* constraints,
526 DTLSIdentityServiceInterface* dtls_identity_service, 525 DTLSIdentityServiceInterface* dtls_identity_service,
527 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) { 526 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
527 // Default |dtls_enabled_| value, may get overwritten in InitializeCommon.
528 dtls_enabled_ = (dtls_identity_service != nullptr);
529
530 if (!InitializeCommon(options, constraints, rtc_configuration)) {
531 if (dtls_identity_service) {
532 // Since we have the ownership of |dtls_identity_service| and will not
533 // pass it to WebRtcSessionDescriptionFactory it is our job to delete it.
534 delete dtls_identity_service;
535 }
536 return false;
537 }
538
539 if (dtls_enabled_) {
540 // Note: the factory takes ownership of |dtls_identity_service|.
541 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
542 signaling_thread(),
543 worker_thread(),
544 channel_manager_,
545 mediastream_signaling_,
546 dtls_identity_service,
547 this,
548 id(),
549 data_channel_type_));
550 } else {
551 if (dtls_identity_service) {
552 // Since we have the ownership of |dtls_identity_service| and will not
553 // pass it to WebRtcSessionDescriptionFactory it is our job to delete it.
554 delete dtls_identity_service;
555 }
556
557 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
558 signaling_thread(),
559 worker_thread(),
560 channel_manager_,
561 mediastream_signaling_,
562 this,
563 id(),
564 data_channel_type_));
565 }
566 InitializeFactoryAfterConstruction(options);
567 return true;
568 }
569
570 bool WebRtcSession::Initialize(
571 const PeerConnectionFactoryInterface::Options& options,
572 const MediaConstraintsInterface* constraints,
573 rtc::scoped_refptr<webrtc::DtlsCertificate> certificate,
574 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
575 DCHECK(certificate.get());
576
577 // Default |dtls_enabled_| value, may get overwritten in InitializeCommon.
578 dtls_enabled_ = true;
579
580 if (!InitializeCommon(options, constraints, rtc_configuration)) {
581 return false;
582 }
583
584 if (dtls_enabled_) {
585 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
586 signaling_thread(),
587 worker_thread(),
588 channel_manager_,
589 mediastream_signaling_,
590 certificate,
591 this,
592 id(),
593 data_channel_type_));
594 } else {
595 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
596 signaling_thread(),
597 worker_thread(),
598 channel_manager_,
599 mediastream_signaling_,
600 this,
601 id(),
602 data_channel_type_));
603 }
604 InitializeFactoryAfterConstruction(options);
605 return true;
606 }
607
608 void WebRtcSession::InitializeFactoryAfterConstruction(
609 const PeerConnectionFactoryInterface::Options& options) {
610 webrtc_session_desc_factory_->SignalCertificateReady.connect(
611 this, &WebRtcSession::OnCertificateReady);
612 if (options.disable_encryption) {
613 webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED);
614 }
615 }
616
617 bool WebRtcSession::InitializeCommon(
618 const PeerConnectionFactoryInterface::Options& options,
619 const MediaConstraintsInterface* constraints,
620 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
528 bundle_policy_ = rtc_configuration.bundle_policy; 621 bundle_policy_ = rtc_configuration.bundle_policy;
529 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; 622 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy;
530 SetSslMaxProtocolVersion(options.ssl_max_version); 623 SetSslMaxProtocolVersion(options.ssl_max_version);
531 624
532 // TODO(perkj): Take |constraints| into consideration. Return false if not all 625 // TODO(perkj): Take |constraints| into consideration. Return false if not all
533 // mandatory constraints can be fulfilled. Note that |constraints| 626 // mandatory constraints can be fulfilled. Note that |constraints|
534 // can be null. 627 // can be null.
535 bool value; 628 bool value;
536 629
537 if (options.disable_encryption) { 630 if (options.disable_encryption) {
538 dtls_enabled_ = false; 631 dtls_enabled_ = false;
539 } else { 632 } else {
540 // Enable DTLS by default if |dtls_identity_service| is valid.
541 dtls_enabled_ = (dtls_identity_service != NULL);
542 // |constraints| can override the default |dtls_enabled_| value. 633 // |constraints| can override the default |dtls_enabled_| value.
543 if (FindConstraint( 634 if (FindConstraint(
544 constraints, 635 constraints,
545 MediaConstraintsInterface::kEnableDtlsSrtp, 636 MediaConstraintsInterface::kEnableDtlsSrtp,
546 &value, NULL)) { 637 &value, nullptr)) {
547 dtls_enabled_ = value; 638 dtls_enabled_ = value;
548 } 639 }
549 } 640 }
550 641
551 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set. 642 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set.
552 // It takes precendence over the disable_sctp_data_channels 643 // It takes precendence over the disable_sctp_data_channels
553 // PeerConnectionFactoryInterface::Options. 644 // PeerConnectionFactoryInterface::Options.
554 if (FindConstraint( 645 if (FindConstraint(
555 constraints, MediaConstraintsInterface::kEnableRtpDataChannels, 646 constraints, MediaConstraintsInterface::kEnableRtpDataChannels,
556 &value, NULL) && value) { 647 &value, NULL) && value) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 const cricket::VideoCodec default_codec( 744 const cricket::VideoCodec default_codec(
654 JsepSessionDescription::kDefaultVideoCodecId, 745 JsepSessionDescription::kDefaultVideoCodecId,
655 JsepSessionDescription::kDefaultVideoCodecName, 746 JsepSessionDescription::kDefaultVideoCodecName,
656 JsepSessionDescription::kMaxVideoCodecWidth, 747 JsepSessionDescription::kMaxVideoCodecWidth,
657 JsepSessionDescription::kMaxVideoCodecHeight, 748 JsepSessionDescription::kMaxVideoCodecHeight,
658 JsepSessionDescription::kDefaultVideoCodecFramerate, 749 JsepSessionDescription::kDefaultVideoCodecFramerate,
659 JsepSessionDescription::kDefaultVideoCodecPreference); 750 JsepSessionDescription::kDefaultVideoCodecPreference);
660 channel_manager_->SetDefaultVideoEncoderConfig( 751 channel_manager_->SetDefaultVideoEncoderConfig(
661 cricket::VideoEncoderConfig(default_codec)); 752 cricket::VideoEncoderConfig(default_codec));
662 753
663 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
664 signaling_thread(),
665 channel_manager_,
666 mediastream_signaling_,
667 dtls_identity_service,
668 this,
669 id(),
670 data_channel_type_,
671 dtls_enabled_));
672
673 webrtc_session_desc_factory_->SignalIdentityReady.connect(
674 this, &WebRtcSession::OnIdentityReady);
675
676 if (options.disable_encryption) {
677 webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED);
678 }
679 port_allocator()->set_candidate_filter( 754 port_allocator()->set_candidate_filter(
680 ConvertIceTransportTypeToCandidateFilter(rtc_configuration.type)); 755 ConvertIceTransportTypeToCandidateFilter(rtc_configuration.type));
681 return true; 756 return true;
682 } 757 }
683 758
684 void WebRtcSession::Terminate() { 759 void WebRtcSession::Terminate() {
685 SetState(STATE_RECEIVEDTERMINATE); 760 SetState(STATE_RECEIVEDTERMINATE);
686 RemoveUnusedChannelsAndTransports(NULL); 761 RemoveUnusedChannelsAndTransports(NULL);
687 ASSERT(!voice_channel_); 762 ASSERT(!voice_channel_);
688 ASSERT(!video_channel_); 763 ASSERT(!video_channel_);
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 } 1372 }
1298 1373
1299 bool WebRtcSession::IceRestartPending() const { 1374 bool WebRtcSession::IceRestartPending() const {
1300 return ice_restart_latch_->Get(); 1375 return ice_restart_latch_->Get();
1301 } 1376 }
1302 1377
1303 void WebRtcSession::ResetIceRestartLatch() { 1378 void WebRtcSession::ResetIceRestartLatch() {
1304 ice_restart_latch_->Reset(); 1379 ice_restart_latch_->Reset();
1305 } 1380 }
1306 1381
1307 void WebRtcSession::OnIdentityReady(rtc::SSLIdentity* identity) { 1382 void WebRtcSession::OnCertificateReady(
1308 SetIdentity(identity); 1383 rtc::scoped_refptr<DtlsCertificate> certificate) {
1384 certificate_ = certificate;
1385 SetCertificate(certificate_);
1309 } 1386 }
1310 1387
1311 bool WebRtcSession::waiting_for_identity() const { 1388 bool WebRtcSession::waiting_for_certificate() const {
1312 return webrtc_session_desc_factory_->waiting_for_identity(); 1389 return webrtc_session_desc_factory_->waiting_for_certificate();
1390 }
1391
1392 rtc::scoped_refptr<DtlsCertificate> WebRtcSession::get_certificate() const {
1393 return certificate_;
1313 } 1394 }
1314 1395
1315 void WebRtcSession::SetIceConnectionState( 1396 void WebRtcSession::SetIceConnectionState(
1316 PeerConnectionInterface::IceConnectionState state) { 1397 PeerConnectionInterface::IceConnectionState state) {
1317 if (ice_connection_state_ == state) { 1398 if (ice_connection_state_ == state) {
1318 return; 1399 return;
1319 } 1400 }
1320 1401
1321 // ASSERT that the requested transition is allowed. Note that 1402 // ASSERT that the requested transition is allowed. Note that
1322 // WebRtcSession does not implement "kIceConnectionClosed" (that is handled 1403 // WebRtcSession does not implement "kIceConnectionClosed" (that is handled
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 2046
1966 if (!srtp_cipher.empty()) { 2047 if (!srtp_cipher.empty()) {
1967 metrics_observer_->AddHistogramSample(srtp_name, srtp_cipher); 2048 metrics_observer_->AddHistogramSample(srtp_name, srtp_cipher);
1968 } 2049 }
1969 if (!ssl_cipher.empty()) { 2050 if (!ssl_cipher.empty()) {
1970 metrics_observer_->AddHistogramSample(ssl_name, ssl_cipher); 2051 metrics_observer_->AddHistogramSample(ssl_name, ssl_cipher);
1971 } 2052 }
1972 } 2053 }
1973 2054
1974 } // namespace webrtc 2055 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698