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