blob: a7ff949c801712916289996dfd82a1d95895b3a7 [file] [log] [blame]
wu@webrtc.org91053e72013-08-10 07:18:04 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
wu@webrtc.org91053e72013-08-10 07:18:04 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.org91053e72013-08-10 07:18:04 +00009 */
10
Henrik Kjellander15583c12016-02-10 10:53:12 +010011#ifndef WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_
12#define WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_
wu@webrtc.org91053e72013-08-10 07:18:04 +000013
wu@webrtc.org91053e72013-08-10 07:18:04 +000014#include "talk/session/media/mediasession.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010015#include "webrtc/api/dtlsidentitystore.h"
16#include "webrtc/api/peerconnectioninterface.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000017#include "webrtc/base/messagehandler.h"
Henrik Boström87713d02015-08-25 09:53:21 +020018#include "webrtc/base/rtccertificate.h"
kjellandera96e2d72016-02-04 23:52:28 -080019#include "webrtc/p2p/base/transportdescriptionfactory.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000020
21namespace cricket {
wu@webrtc.org91053e72013-08-10 07:18:04 +000022class ChannelManager;
23class TransportDescriptionFactory;
wu@webrtc.org91053e72013-08-10 07:18:04 +000024} // namespace cricket
25
26namespace webrtc {
wu@webrtc.org91053e72013-08-10 07:18:04 +000027class CreateSessionDescriptionObserver;
28class MediaConstraintsInterface;
wu@webrtc.org91053e72013-08-10 07:18:04 +000029class SessionDescriptionInterface;
30class WebRtcSession;
31
wu@webrtc.org91053e72013-08-10 07:18:04 +000032// DTLS identity request callback class.
Henrik Boström5e56c592015-08-11 10:33:13 +020033class WebRtcIdentityRequestObserver : public DtlsIdentityRequestObserver,
wu@webrtc.org91053e72013-08-10 07:18:04 +000034 public sigslot::has_slots<> {
35 public:
Henrik Boström5e56c592015-08-11 10:33:13 +020036 // DtlsIdentityRequestObserver overrides.
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000037 void OnFailure(int error) override;
38 void OnSuccess(const std::string& der_cert,
39 const std::string& der_private_key) override;
Henrik Boström5e56c592015-08-11 10:33:13 +020040 void OnSuccess(rtc::scoped_ptr<rtc::SSLIdentity> identity) override;
wu@webrtc.org91053e72013-08-10 07:18:04 +000041
42 sigslot::signal1<int> SignalRequestFailed;
Henrik Boströmd8281982015-08-27 10:12:24 +020043 sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&>
44 SignalCertificateReady;
wu@webrtc.org91053e72013-08-10 07:18:04 +000045};
46
47struct 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.orgd4e598d2014-07-29 17:36:52 +000062 rtc::scoped_refptr<CreateSessionDescriptionObserver> observer;
wu@webrtc.org91053e72013-08-10 07:18:04 +000063 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.orgd4e598d2014-07-29 17:36:52 +000071class WebRtcSessionDescriptionFactory : public rtc::MessageHandler,
Henrik Boström5e56c592015-08-11 10:33:13 +020072 public sigslot::has_slots<> {
wu@webrtc.org91053e72013-08-10 07:18:04 +000073 public:
Henrik Boström87713d02015-08-25 09:53:21 +020074 // Construct with DTLS disabled.
deadbeefcbecd352015-09-23 11:50:27 -070075 WebRtcSessionDescriptionFactory(rtc::Thread* signaling_thread,
76 cricket::ChannelManager* channel_manager,
deadbeefcbecd352015-09-23 11:50:27 -070077 WebRtcSession* session,
deadbeefab9b2d12015-10-14 11:33:11 -070078 const std::string& session_id);
Henrik Boström87713d02015-08-25 09:53:21 +020079
80 // Construct with DTLS enabled using the specified |dtls_identity_store| to
81 // generate a certificate.
wu@webrtc.org91053e72013-08-10 07:18:04 +000082 WebRtcSessionDescriptionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000083 rtc::Thread* signaling_thread,
wu@webrtc.org91053e72013-08-10 07:18:04 +000084 cricket::ChannelManager* channel_manager,
Henrik Boström5e56c592015-08-11 10:33:13 +020085 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
wu@webrtc.org91053e72013-08-10 07:18:04 +000086 WebRtcSession* session,
deadbeefab9b2d12015-10-14 11:33:11 -070087 const std::string& session_id);
Henrik Boström87713d02015-08-25 09:53:21 +020088
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öm87713d02015-08-25 09:53:21 +020094 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate,
95 WebRtcSession* session,
deadbeefab9b2d12015-10-14 11:33:11 -070096 const std::string& session_id);
wu@webrtc.org91053e72013-08-10 07:18:04 +000097 virtual ~WebRtcSessionDescriptionFactory();
98
99 static void CopyCandidatesFromSessionDescription(
100 const SessionDescriptionInterface* source_desc,
101 SessionDescriptionInterface* dest_desc);
102
103 void CreateOffer(
104 CreateSessionDescriptionObserver* observer,
deadbeefab9b2d12015-10-14 11:33:11 -0700105 const PeerConnectionInterface::RTCOfferAnswerOptions& options,
106 const cricket::MediaSessionOptions& session_options);
107 void CreateAnswer(CreateSessionDescriptionObserver* observer,
108 const MediaConstraintsInterface* constraints,
109 const cricket::MediaSessionOptions& session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000110
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000111 void SetSdesPolicy(cricket::SecurePolicy secure_policy);
112 cricket::SecurePolicy SdesPolicy() const;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000113
Henrik Boströmd8281982015-08-27 10:12:24 +0200114 sigslot::signal1<const rtc::scoped_refptr<rtc::RTCCertificate>&>
115 SignalCertificateReady;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000116
117 // For testing.
Henrik Boström87713d02015-08-25 09:53:21 +0200118 bool waiting_for_certificate_for_testing() const {
119 return certificate_request_state_ == CERTIFICATE_WAITING;
wu@webrtc.org364f2042013-11-20 21:49:41 +0000120 }
wu@webrtc.org91053e72013-08-10 07:18:04 +0000121
122 private:
Henrik Boström87713d02015-08-25 09:53:21 +0200123 enum CertificateRequestState {
124 CERTIFICATE_NOT_NEEDED,
125 CERTIFICATE_WAITING,
126 CERTIFICATE_SUCCEEDED,
127 CERTIFICATE_FAILED,
wu@webrtc.org91053e72013-08-10 07:18:04 +0000128 };
129
Henrik Boström87713d02015-08-25 09:53:21 +0200130 WebRtcSessionDescriptionFactory(
131 rtc::Thread* signaling_thread,
132 cricket::ChannelManager* channel_manager,
Henrik Boström87713d02015-08-25 09:53:21 +0200133 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
134 const rtc::scoped_refptr<WebRtcIdentityRequestObserver>&
135 identity_request_observer,
136 WebRtcSession* session,
137 const std::string& session_id,
Henrik Boström87713d02015-08-25 09:53:21 +0200138 bool dtls_enabled);
139
wu@webrtc.org91053e72013-08-10 07:18:04 +0000140 // MessageHandler implementation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000141 virtual void OnMessage(rtc::Message* msg);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000142
143 void InternalCreateOffer(CreateSessionDescriptionRequest request);
144 void InternalCreateAnswer(CreateSessionDescriptionRequest request);
tommi0f620f42015-07-09 03:25:02 -0700145 // Posts failure notifications for all pending session description requests.
146 void FailPendingRequests(const std::string& reason);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000147 void PostCreateSessionDescriptionFailed(
148 CreateSessionDescriptionObserver* observer,
149 const std::string& error);
150 void PostCreateSessionDescriptionSucceeded(
151 CreateSessionDescriptionObserver* observer,
152 SessionDescriptionInterface* description);
153
154 void OnIdentityRequestFailed(int error);
Henrik Boströmd8281982015-08-27 10:12:24 +0200155 void SetCertificate(
156 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000157
158 std::queue<CreateSessionDescriptionRequest>
159 create_session_description_requests_;
tommi0f620f42015-07-09 03:25:02 -0700160 rtc::Thread* const signaling_thread_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000161 cricket::TransportDescriptionFactory transport_desc_factory_;
162 cricket::MediaSessionDescriptionFactory session_desc_factory_;
Peter Boström0c4e06b2015-10-07 12:23:21 +0200163 uint64_t session_version_;
Henrik Boström87713d02015-08-25 09:53:21 +0200164 const rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store_;
165 const rtc::scoped_refptr<WebRtcIdentityRequestObserver>
166 identity_request_observer_;
167 // TODO(jiayl): remove the dependency on session once bug 2264 is fixed.
tommi0f620f42015-07-09 03:25:02 -0700168 WebRtcSession* const session_;
169 const std::string session_id_;
Henrik Boström87713d02015-08-25 09:53:21 +0200170 CertificateRequestState certificate_request_state_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000171
henrikg3c089d72015-09-16 05:37:44 -0700172 RTC_DISALLOW_COPY_AND_ASSIGN(WebRtcSessionDescriptionFactory);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000173};
wu@webrtc.org91053e72013-08-10 07:18:04 +0000174} // namespace webrtc
175
Henrik Kjellander15583c12016-02-10 10:53:12 +0100176#endif // WEBRTC_API_WEBRTCSESSIONDESCRIPTIONFACTORY_H_