wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 11 | #ifndef WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ |
| 12 | #define WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 13 | |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 16 | #include "webrtc/api/dtlsidentitystore.h" |
| 17 | #include "webrtc/api/peerconnectioninterface.h" |
kwiberg | 4485ffb | 2016-04-26 08:14:39 -0700 | [diff] [blame] | 18 | #include "webrtc/base/constructormagic.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 19 | #include "webrtc/base/messagehandler.h" |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 20 | #include "webrtc/base/rtccertificate.h" |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame^] | 21 | #include "webrtc/base/rtccertificategenerator.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 22 | #include "webrtc/p2p/base/transportdescriptionfactory.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 23 | #include "webrtc/pc/mediasession.h" |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 24 | |
| 25 | namespace cricket { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 26 | class ChannelManager; |
| 27 | class TransportDescriptionFactory; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 28 | } // namespace cricket |
| 29 | |
| 30 | namespace webrtc { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 31 | class CreateSessionDescriptionObserver; |
| 32 | class MediaConstraintsInterface; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 33 | class SessionDescriptionInterface; |
| 34 | class WebRtcSession; |
| 35 | |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame^] | 36 | // DTLS certificate request callback class. |
| 37 | class WebRtcCertificateGeneratorCallback |
| 38 | : public rtc::RTCCertificateGeneratorCallback, |
| 39 | public sigslot::has_slots<> { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 40 | public: |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame^] | 41 | // |rtc::RTCCertificateGeneratorCallback| overrides. |
| 42 | void OnSuccess( |
| 43 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) override; |
| 44 | void OnFailure() override; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 45 | |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame^] | 46 | sigslot::signal0<> SignalRequestFailed; |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 47 | sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&> |
| 48 | SignalCertificateReady; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | struct CreateSessionDescriptionRequest { |
| 52 | enum Type { |
| 53 | kOffer, |
| 54 | kAnswer, |
| 55 | }; |
| 56 | |
| 57 | CreateSessionDescriptionRequest( |
| 58 | Type type, |
| 59 | CreateSessionDescriptionObserver* observer, |
| 60 | const cricket::MediaSessionOptions& options) |
| 61 | : type(type), |
| 62 | observer(observer), |
| 63 | options(options) {} |
| 64 | |
| 65 | Type type; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 66 | rtc::scoped_refptr<CreateSessionDescriptionObserver> observer; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 67 | cricket::MediaSessionOptions options; |
| 68 | }; |
| 69 | |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame^] | 70 | // This class is used to create offer/answer session description. Certificates |
| 71 | // for WebRtcSession/DTLS are either supplied at construction or generated |
| 72 | // asynchronously. It queues the create offer/answer request until the |
| 73 | // certificate generation has completed, i.e. when OnCertificateRequestFailed or |
| 74 | // OnCertificateReady is called. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 75 | class WebRtcSessionDescriptionFactory : public rtc::MessageHandler, |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 76 | public sigslot::has_slots<> { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 77 | public: |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame^] | 78 | // If |certificate_generator| is not null, DTLS is enabled and a default |
| 79 | // certificate is generated asynchronously; otherwise DTLS is disabled. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 80 | WebRtcSessionDescriptionFactory( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 81 | rtc::Thread* signaling_thread, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 82 | cricket::ChannelManager* channel_manager, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 83 | WebRtcSession* session, |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame^] | 84 | const std::string& session_id, |
| 85 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator); |
| 86 | // Construct with DTLS enabled using the specified |certificate|. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 87 | WebRtcSessionDescriptionFactory( |
| 88 | rtc::Thread* signaling_thread, |
| 89 | cricket::ChannelManager* channel_manager, |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 90 | WebRtcSession* session, |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame^] | 91 | const std::string& session_id, |
| 92 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 93 | virtual ~WebRtcSessionDescriptionFactory(); |
| 94 | |
| 95 | static void CopyCandidatesFromSessionDescription( |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 96 | const SessionDescriptionInterface* source_desc, |
| 97 | const std::string& content_name, |
| 98 | SessionDescriptionInterface* dest_desc); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 99 | |
| 100 | void CreateOffer( |
| 101 | CreateSessionDescriptionObserver* observer, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 102 | const PeerConnectionInterface::RTCOfferAnswerOptions& options, |
| 103 | const cricket::MediaSessionOptions& session_options); |
| 104 | void CreateAnswer(CreateSessionDescriptionObserver* observer, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 105 | const cricket::MediaSessionOptions& session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 106 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 107 | void SetSdesPolicy(cricket::SecurePolicy secure_policy); |
| 108 | cricket::SecurePolicy SdesPolicy() const; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 109 | |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 110 | sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&> |
| 111 | SignalCertificateReady; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 112 | |
| 113 | // For testing. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 114 | bool waiting_for_certificate_for_testing() const { |
| 115 | return certificate_request_state_ == CERTIFICATE_WAITING; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 116 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 117 | |
| 118 | private: |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 119 | enum CertificateRequestState { |
| 120 | CERTIFICATE_NOT_NEEDED, |
| 121 | CERTIFICATE_WAITING, |
| 122 | CERTIFICATE_SUCCEEDED, |
| 123 | CERTIFICATE_FAILED, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 124 | }; |
| 125 | |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame^] | 126 | // If |certificate_generator| or |certificate| is not null DTLS is enabled, |
| 127 | // otherwise DTLS is disabled. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 128 | WebRtcSessionDescriptionFactory( |
| 129 | rtc::Thread* signaling_thread, |
| 130 | cricket::ChannelManager* channel_manager, |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 131 | WebRtcSession* session, |
| 132 | const std::string& session_id, |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame^] | 133 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
| 134 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 135 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 136 | // MessageHandler implementation. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 137 | virtual void OnMessage(rtc::Message* msg); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 138 | |
| 139 | void InternalCreateOffer(CreateSessionDescriptionRequest request); |
| 140 | void InternalCreateAnswer(CreateSessionDescriptionRequest request); |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 141 | // Posts failure notifications for all pending session description requests. |
| 142 | void FailPendingRequests(const std::string& reason); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 143 | void PostCreateSessionDescriptionFailed( |
| 144 | CreateSessionDescriptionObserver* observer, |
| 145 | const std::string& error); |
| 146 | void PostCreateSessionDescriptionSucceeded( |
| 147 | CreateSessionDescriptionObserver* observer, |
| 148 | SessionDescriptionInterface* description); |
| 149 | |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame^] | 150 | void OnCertificateRequestFailed(); |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 151 | void SetCertificate( |
| 152 | const rtc::scoped_refptr<rtc::RTCCertificate>& certificate); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 153 | |
| 154 | std::queue<CreateSessionDescriptionRequest> |
| 155 | create_session_description_requests_; |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 156 | rtc::Thread* const signaling_thread_; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 157 | cricket::TransportDescriptionFactory transport_desc_factory_; |
| 158 | cricket::MediaSessionDescriptionFactory session_desc_factory_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 159 | uint64_t session_version_; |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame^] | 160 | const std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator_; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 161 | // TODO(jiayl): remove the dependency on session once bug 2264 is fixed. |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 162 | WebRtcSession* const session_; |
| 163 | const std::string session_id_; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 164 | CertificateRequestState certificate_request_state_; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 165 | |
henrikg | 3c089d7 | 2015-09-16 05:37:44 -0700 | [diff] [blame] | 166 | RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcSessionDescriptionFactory); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 167 | }; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 168 | } // namespace webrtc |
| 169 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 170 | #endif // WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ |