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

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: Trying to get iOS to compile 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 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, 525 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
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_store != nullptr);
529
530 if (!InitializeCommon(options, constraints, rtc_configuration)) {
531 return false;
532 }
533
534 if (dtls_enabled_) {
535 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
536 signaling_thread(),
537 worker_thread(),
538 channel_manager_,
539 mediastream_signaling_,
540 dtls_identity_store.Pass(),
541 this,
542 id(),
543 data_channel_type_));
544 } else {
545 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
546 signaling_thread(),
547 worker_thread(),
548 channel_manager_,
549 mediastream_signaling_,
550 this,
551 id(),
552 data_channel_type_));
553 }
554 InitializeFactoryAfterConstruction(options);
555 return true;
556 }
557
558 bool WebRtcSession::Initialize(
559 const PeerConnectionFactoryInterface::Options& options,
560 const MediaConstraintsInterface* constraints,
561 const rtc::scoped_refptr<webrtc::DtlsCertificate>& certificate,
562 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
563 DCHECK(certificate.get());
564
565 // Default |dtls_enabled_| value, may get overwritten in InitializeCommon.
566 dtls_enabled_ = true;
567
568 if (!InitializeCommon(options, constraints, rtc_configuration)) {
569 return false;
570 }
571
572 if (dtls_enabled_) {
573 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
574 signaling_thread(),
575 worker_thread(),
576 channel_manager_,
577 mediastream_signaling_,
578 certificate,
579 this,
580 id(),
581 data_channel_type_));
582 } else {
583 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
584 signaling_thread(),
585 worker_thread(),
586 channel_manager_,
587 mediastream_signaling_,
588 this,
589 id(),
590 data_channel_type_));
591 }
592 InitializeFactoryAfterConstruction(options);
593 return true;
594 }
595
596 void WebRtcSession::InitializeFactoryAfterConstruction(
597 const PeerConnectionFactoryInterface::Options& options) {
598 webrtc_session_desc_factory_->SignalCertificateReady.connect(
599 this, &WebRtcSession::OnCertificateReady);
600 if (options.disable_encryption) {
601 webrtc_session_desc_factory_->SetSdesPolicy(cricket::SEC_DISABLED);
602 }
603 }
604
605 bool WebRtcSession::InitializeCommon(
606 const PeerConnectionFactoryInterface::Options& options,
607 const MediaConstraintsInterface* constraints,
608 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
528 bundle_policy_ = rtc_configuration.bundle_policy; 609 bundle_policy_ = rtc_configuration.bundle_policy;
529 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy; 610 rtcp_mux_policy_ = rtc_configuration.rtcp_mux_policy;
530 SetSslMaxProtocolVersion(options.ssl_max_version); 611 SetSslMaxProtocolVersion(options.ssl_max_version);
531 612
532 // TODO(perkj): Take |constraints| into consideration. Return false if not all 613 // TODO(perkj): Take |constraints| into consideration. Return false if not all
533 // mandatory constraints can be fulfilled. Note that |constraints| 614 // mandatory constraints can be fulfilled. Note that |constraints|
534 // can be null. 615 // can be null.
535 bool value; 616 bool value;
536 617
537 if (options.disable_encryption) { 618 if (options.disable_encryption) {
538 dtls_enabled_ = false; 619 dtls_enabled_ = false;
539 } else { 620 } else {
540 // Enable DTLS by default if we have a |dtls_identity_store|.
541 dtls_enabled_ = (dtls_identity_store != nullptr);
542 // |constraints| can override the default |dtls_enabled_| value. 621 // |constraints| can override the default |dtls_enabled_| value.
543 if (FindConstraint( 622 if (FindConstraint(
544 constraints, 623 constraints,
545 MediaConstraintsInterface::kEnableDtlsSrtp, 624 MediaConstraintsInterface::kEnableDtlsSrtp,
546 &value, NULL)) { 625 &value, nullptr)) {
547 dtls_enabled_ = value; 626 dtls_enabled_ = value;
548 } 627 }
549 } 628 }
550 629
551 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set. 630 // Enable creation of RTP data channels if the kEnableRtpDataChannels is set.
552 // It takes precendence over the disable_sctp_data_channels 631 // It takes precendence over the disable_sctp_data_channels
553 // PeerConnectionFactoryInterface::Options. 632 // PeerConnectionFactoryInterface::Options.
554 if (FindConstraint( 633 if (FindConstraint(
555 constraints, MediaConstraintsInterface::kEnableRtpDataChannels, 634 constraints, MediaConstraintsInterface::kEnableRtpDataChannels,
556 &value, NULL) && value) { 635 &value, NULL) && value) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 const cricket::VideoCodec default_codec( 732 const cricket::VideoCodec default_codec(
654 JsepSessionDescription::kDefaultVideoCodecId, 733 JsepSessionDescription::kDefaultVideoCodecId,
655 JsepSessionDescription::kDefaultVideoCodecName, 734 JsepSessionDescription::kDefaultVideoCodecName,
656 JsepSessionDescription::kMaxVideoCodecWidth, 735 JsepSessionDescription::kMaxVideoCodecWidth,
657 JsepSessionDescription::kMaxVideoCodecHeight, 736 JsepSessionDescription::kMaxVideoCodecHeight,
658 JsepSessionDescription::kDefaultVideoCodecFramerate, 737 JsepSessionDescription::kDefaultVideoCodecFramerate,
659 JsepSessionDescription::kDefaultVideoCodecPreference); 738 JsepSessionDescription::kDefaultVideoCodecPreference);
660 channel_manager_->SetDefaultVideoEncoderConfig( 739 channel_manager_->SetDefaultVideoEncoderConfig(
661 cricket::VideoEncoderConfig(default_codec)); 740 cricket::VideoEncoderConfig(default_codec));
662 741
663 webrtc_session_desc_factory_.reset(new WebRtcSessionDescriptionFactory(
664 signaling_thread(),
665 channel_manager_,
666 mediastream_signaling_,
667 dtls_identity_store.Pass(),
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( 742 port_allocator()->set_candidate_filter(
Henrik Grunell WebRTC 2015/08/12 14:46:30 Was there any reason this was done after creating
hbos 2015/08/14 14:09:39 No, looks like a simple variable setter unrelated
680 ConvertIceTransportTypeToCandidateFilter(rtc_configuration.type)); 743 ConvertIceTransportTypeToCandidateFilter(rtc_configuration.type));
681 return true; 744 return true;
682 } 745 }
683 746
684 void WebRtcSession::Terminate() { 747 void WebRtcSession::Terminate() {
685 SetState(STATE_RECEIVEDTERMINATE); 748 SetState(STATE_RECEIVEDTERMINATE);
686 RemoveUnusedChannelsAndTransports(NULL); 749 RemoveUnusedChannelsAndTransports(NULL);
687 ASSERT(!voice_channel_); 750 ASSERT(!voice_channel_);
688 ASSERT(!video_channel_); 751 ASSERT(!video_channel_);
689 ASSERT(!data_channel_); 752 ASSERT(!data_channel_);
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 } 1360 }
1298 1361
1299 bool WebRtcSession::IceRestartPending() const { 1362 bool WebRtcSession::IceRestartPending() const {
1300 return ice_restart_latch_->Get(); 1363 return ice_restart_latch_->Get();
1301 } 1364 }
1302 1365
1303 void WebRtcSession::ResetIceRestartLatch() { 1366 void WebRtcSession::ResetIceRestartLatch() {
1304 ice_restart_latch_->Reset(); 1367 ice_restart_latch_->Reset();
1305 } 1368 }
1306 1369
1307 void WebRtcSession::OnIdentityReady(rtc::SSLIdentity* identity) { 1370 void WebRtcSession::OnCertificateReady(
1308 SetIdentity(identity); 1371 const rtc::scoped_refptr<DtlsCertificate>& certificate) {
1372 certificate_ = certificate;
1373 SetCertificate(certificate_);
1309 } 1374 }
1310 1375
1311 bool WebRtcSession::waiting_for_identity() const { 1376 bool WebRtcSession::waiting_for_certificate() const {
Henrik Grunell WebRTC 2015/08/12 14:46:30 Rename to IsWaitingForCertificate since it's not a
hbos 2015/08/14 14:09:39 Done.
1312 return webrtc_session_desc_factory_->waiting_for_identity(); 1377 return webrtc_session_desc_factory_->waiting_for_certificate();
1378 }
1379
1380 rtc::scoped_refptr<DtlsCertificate> WebRtcSession::get_certificate() const {
Henrik Grunell WebRTC 2015/08/12 14:46:30 Move to header file.
hbos 2015/08/14 14:09:39 Done.
1381 return certificate_;
1313 } 1382 }
1314 1383
1315 void WebRtcSession::SetIceConnectionState( 1384 void WebRtcSession::SetIceConnectionState(
1316 PeerConnectionInterface::IceConnectionState state) { 1385 PeerConnectionInterface::IceConnectionState state) {
1317 if (ice_connection_state_ == state) { 1386 if (ice_connection_state_ == state) {
1318 return; 1387 return;
1319 } 1388 }
1320 1389
1321 // ASSERT that the requested transition is allowed. Note that 1390 // ASSERT that the requested transition is allowed. Note that
1322 // WebRtcSession does not implement "kIceConnectionClosed" (that is handled 1391 // WebRtcSession does not implement "kIceConnectionClosed" (that is handled
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 2034
1966 if (!srtp_cipher.empty()) { 2035 if (!srtp_cipher.empty()) {
1967 metrics_observer_->AddHistogramSample(srtp_name, srtp_cipher); 2036 metrics_observer_->AddHistogramSample(srtp_name, srtp_cipher);
1968 } 2037 }
1969 if (!ssl_cipher.empty()) { 2038 if (!ssl_cipher.empty()) {
1970 metrics_observer_->AddHistogramSample(ssl_name, ssl_cipher); 2039 metrics_observer_->AddHistogramSample(ssl_name, ssl_cipher);
1971 } 2040 }
1972 } 2041 }
1973 2042
1974 } // namespace webrtc 2043 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698