wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * Copyright 2013 Google Inc. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4 | * |
| 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öm | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 31 | #include "talk/app/webrtc/dtlsidentitystore.h" |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 32 | #include "talk/app/webrtc/peerconnectioninterface.h" |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 33 | #include "talk/session/media/mediasession.h" |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 34 | #include "webrtc/p2p/base/transportdescriptionfactory.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 35 | #include "webrtc/base/messagehandler.h" |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 36 | |
| 37 | namespace cricket { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 38 | class ChannelManager; |
| 39 | class TransportDescriptionFactory; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 40 | } // namespace cricket |
| 41 | |
| 42 | namespace webrtc { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 43 | class CreateSessionDescriptionObserver; |
| 44 | class MediaConstraintsInterface; |
| 45 | class MediaStreamSignaling; |
| 46 | class SessionDescriptionInterface; |
| 47 | class WebRtcSession; |
| 48 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 49 | // DTLS identity request callback class. |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 50 | class WebRtcIdentityRequestObserver : public DtlsIdentityRequestObserver, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 51 | public sigslot::has_slots<> { |
| 52 | public: |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 53 | // DtlsIdentityRequestObserver overrides. |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 +0000 | [diff] [blame] | 54 | void OnFailure(int error) override; |
| 55 | void OnSuccess(const std::string& der_cert, |
| 56 | const std::string& der_private_key) override; |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 57 | void OnSuccess(rtc::scoped_ptr<rtc::SSLIdentity> identity) override; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 58 | |
| 59 | sigslot::signal1<int> SignalRequestFailed; |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 +0000 | [diff] [blame] | 60 | sigslot::signal1<rtc::SSLIdentity*> SignalIdentityReady; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | struct 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 78 | rtc::scoped_refptr<CreateSessionDescriptionObserver> observer; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 79 | 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 87 | class WebRtcSessionDescriptionFactory : public rtc::MessageHandler, |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 88 | public sigslot::has_slots<> { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 89 | public: |
| 90 | WebRtcSessionDescriptionFactory( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 91 | rtc::Thread* signaling_thread, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 92 | cricket::ChannelManager* channel_manager, |
| 93 | MediaStreamSignaling* mediastream_signaling, |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 94 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, |
| 95 | // TODO(jiayl): remove the dependency on session once bug 2264 is fixed. |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 96 | WebRtcSession* session, |
| 97 | const std::string& session_id, |
| 98 | cricket::DataChannelType dct, |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 99 | bool dtls_enabled); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 100 | 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.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 108 | const PeerConnectionInterface::RTCOfferAnswerOptions& options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 109 | void CreateAnswer( |
| 110 | CreateSessionDescriptionObserver* observer, |
| 111 | const MediaConstraintsInterface* constraints); |
| 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 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 116 | sigslot::signal1<rtc::SSLIdentity*> SignalIdentityReady; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 117 | |
| 118 | // For testing. |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 119 | bool waiting_for_identity() const { |
| 120 | return identity_request_state_ == IDENTITY_WAITING; |
| 121 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 122 | |
| 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 132 | virtual void OnMessage(rtc::Message* msg); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 133 | |
| 134 | void InternalCreateOffer(CreateSessionDescriptionRequest request); |
| 135 | void InternalCreateAnswer(CreateSessionDescriptionRequest request); |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 136 | // Posts failure notifications for all pending session description requests. |
| 137 | void FailPendingRequests(const std::string& reason); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 138 | 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 146 | void SetIdentity(rtc::SSLIdentity* identity); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 147 | |
| 148 | std::queue<CreateSessionDescriptionRequest> |
| 149 | create_session_description_requests_; |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 150 | rtc::Thread* const signaling_thread_; |
| 151 | MediaStreamSignaling* const mediastream_signaling_; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 152 | cricket::TransportDescriptionFactory transport_desc_factory_; |
| 153 | cricket::MediaSessionDescriptionFactory session_desc_factory_; |
| 154 | uint64 session_version_; |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 155 | rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store_; |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 156 | 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.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 160 | IdentityRequestState identity_request_state_; |
| 161 | |
| 162 | DISALLOW_COPY_AND_ASSIGN(WebRtcSessionDescriptionFactory); |
| 163 | }; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 164 | } // namespace webrtc |
| 165 | |
| 166 | #endif // TALK_APP_WEBRTC_WEBRTCSESSIONDESCRIPTIONFACTORY_H_ |