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