blob: 5d91a61dbbe1d699becdd964d1f990034bf6c737 [file] [log] [blame]
wu@webrtc.org91053e72013-08-10 07:18:04 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2013 Google Inc.
wu@webrtc.org91053e72013-08-10 07:18:04 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef TALK_APP_WEBRTC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_
29#define TALK_APP_WEBRTC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_
30
Henrik Boström5e56c592015-08-11 10:33:13 +020031#include "talk/app/webrtc/dtlsidentitystore.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000032#include "talk/app/webrtc/peerconnectioninterface.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000033#include "talk/session/media/mediasession.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020034#include "webrtc/p2p/base/transportdescriptionfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000035#include "webrtc/base/messagehandler.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000036
37namespace cricket {
wu@webrtc.org91053e72013-08-10 07:18:04 +000038class ChannelManager;
39class TransportDescriptionFactory;
wu@webrtc.org91053e72013-08-10 07:18:04 +000040} // namespace cricket
41
42namespace webrtc {
wu@webrtc.org91053e72013-08-10 07:18:04 +000043class CreateSessionDescriptionObserver;
44class MediaConstraintsInterface;
45class MediaStreamSignaling;
46class SessionDescriptionInterface;
47class WebRtcSession;
48
wu@webrtc.org91053e72013-08-10 07:18:04 +000049// DTLS identity request callback class.
Henrik Boström5e56c592015-08-11 10:33:13 +020050class WebRtcIdentityRequestObserver : public DtlsIdentityRequestObserver,
wu@webrtc.org91053e72013-08-10 07:18:04 +000051 public sigslot::has_slots<> {
52 public:
Henrik Boström5e56c592015-08-11 10:33:13 +020053 // DtlsIdentityRequestObserver overrides.
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000054 void OnFailure(int error) override;
55 void OnSuccess(const std::string& der_cert,
56 const std::string& der_private_key) override;
Henrik Boström5e56c592015-08-11 10:33:13 +020057 void OnSuccess(rtc::scoped_ptr<rtc::SSLIdentity> identity) override;
wu@webrtc.org91053e72013-08-10 07:18:04 +000058
59 sigslot::signal1<int> SignalRequestFailed;
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000060 sigslot::signal1<rtc::SSLIdentity*> SignalIdentityReady;
wu@webrtc.org91053e72013-08-10 07:18:04 +000061};
62
63struct CreateSessionDescriptionRequest {
64 enum Type {
65 kOffer,
66 kAnswer,
67 };
68
69 CreateSessionDescriptionRequest(
70 Type type,
71 CreateSessionDescriptionObserver* observer,
72 const cricket::MediaSessionOptions& options)
73 : type(type),
74 observer(observer),
75 options(options) {}
76
77 Type type;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000078 rtc::scoped_refptr<CreateSessionDescriptionObserver> observer;
wu@webrtc.org91053e72013-08-10 07:18:04 +000079 cricket::MediaSessionOptions options;
80};
81
82// This class is used to create offer/answer session description with regards to
83// the async DTLS identity generation for WebRtcSession.
84// It queues the create offer/answer request until the DTLS identity
85// request has completed, i.e. when OnIdentityRequestFailed or OnIdentityReady
86// is called.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000087class WebRtcSessionDescriptionFactory : public rtc::MessageHandler,
Henrik Boström5e56c592015-08-11 10:33:13 +020088 public sigslot::has_slots<> {
wu@webrtc.org91053e72013-08-10 07:18:04 +000089 public:
90 WebRtcSessionDescriptionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000091 rtc::Thread* signaling_thread,
wu@webrtc.org91053e72013-08-10 07:18:04 +000092 cricket::ChannelManager* channel_manager,
93 MediaStreamSignaling* mediastream_signaling,
Henrik Boström5e56c592015-08-11 10:33:13 +020094 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store,
95 // TODO(jiayl): remove the dependency on session once bug 2264 is fixed.
wu@webrtc.org91053e72013-08-10 07:18:04 +000096 WebRtcSession* session,
97 const std::string& session_id,
98 cricket::DataChannelType dct,
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +000099 bool dtls_enabled);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000100 virtual ~WebRtcSessionDescriptionFactory();
101
102 static void CopyCandidatesFromSessionDescription(
103 const SessionDescriptionInterface* source_desc,
104 SessionDescriptionInterface* dest_desc);
105
106 void CreateOffer(
107 CreateSessionDescriptionObserver* observer,
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000108 const PeerConnectionInterface::RTCOfferAnswerOptions& options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000109 void CreateAnswer(
110 CreateSessionDescriptionObserver* observer,
111 const MediaConstraintsInterface* constraints);
112
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000113 void SetSdesPolicy(cricket::SecurePolicy secure_policy);
114 cricket::SecurePolicy SdesPolicy() const;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000115
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000116 sigslot::signal1<rtc::SSLIdentity*> SignalIdentityReady;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000117
118 // For testing.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000119 bool waiting_for_identity() const {
120 return identity_request_state_ == IDENTITY_WAITING;
121 }
wu@webrtc.org91053e72013-08-10 07:18:04 +0000122
123 private:
124 enum IdentityRequestState {
125 IDENTITY_NOT_NEEDED,
126 IDENTITY_WAITING,
127 IDENTITY_SUCCEEDED,
128 IDENTITY_FAILED,
129 };
130
131 // MessageHandler implementation.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000132 virtual void OnMessage(rtc::Message* msg);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000133
134 void InternalCreateOffer(CreateSessionDescriptionRequest request);
135 void InternalCreateAnswer(CreateSessionDescriptionRequest request);
tommi0f620f42015-07-09 03:25:02 -0700136 // Posts failure notifications for all pending session description requests.
137 void FailPendingRequests(const std::string& reason);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000138 void PostCreateSessionDescriptionFailed(
139 CreateSessionDescriptionObserver* observer,
140 const std::string& error);
141 void PostCreateSessionDescriptionSucceeded(
142 CreateSessionDescriptionObserver* observer,
143 SessionDescriptionInterface* description);
144
145 void OnIdentityRequestFailed(int error);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000146 void SetIdentity(rtc::SSLIdentity* identity);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000147
148 std::queue<CreateSessionDescriptionRequest>
149 create_session_description_requests_;
tommi0f620f42015-07-09 03:25:02 -0700150 rtc::Thread* const signaling_thread_;
151 MediaStreamSignaling* const mediastream_signaling_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000152 cricket::TransportDescriptionFactory transport_desc_factory_;
153 cricket::MediaSessionDescriptionFactory session_desc_factory_;
154 uint64 session_version_;
Henrik Boström5e56c592015-08-11 10:33:13 +0200155 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store_;
tommi0f620f42015-07-09 03:25:02 -0700156 rtc::scoped_refptr<WebRtcIdentityRequestObserver> identity_request_observer_;
157 WebRtcSession* const session_;
158 const std::string session_id_;
159 const cricket::DataChannelType data_channel_type_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000160 IdentityRequestState identity_request_state_;
161
162 DISALLOW_COPY_AND_ASSIGN(WebRtcSessionDescriptionFactory);
163};
wu@webrtc.org91053e72013-08-10 07:18:04 +0000164} // namespace webrtc
165
166#endif // TALK_APP_WEBRTC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_