Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2013 Google Inc. | 3 * Copyright 2013 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h" | 28 #include "talk/app/webrtc/webrtcsessiondescriptionfactory.h" |
| 29 | 29 |
| 30 #include "talk/app/webrtc/dtlsidentitystore.h" | 30 #include "talk/app/webrtc/dtlsidentitystore.h" |
| 31 #include "talk/app/webrtc/jsep.h" | 31 #include "talk/app/webrtc/jsep.h" |
| 32 #include "talk/app/webrtc/jsepsessiondescription.h" | 32 #include "talk/app/webrtc/jsepsessiondescription.h" |
| 33 #include "talk/app/webrtc/mediaconstraintsinterface.h" | 33 #include "talk/app/webrtc/mediaconstraintsinterface.h" |
| 34 #include "talk/app/webrtc/mediastreamsignaling.h" | 34 #include "talk/app/webrtc/mediastreamsignaling.h" |
| 35 #include "talk/app/webrtc/webrtcsession.h" | 35 #include "talk/app/webrtc/webrtcsession.h" |
| 36 #include "webrtc/base/messagequeue.h" | |
| 36 #include "webrtc/base/sslidentity.h" | 37 #include "webrtc/base/sslidentity.h" |
| 37 | 38 |
| 38 using cricket::MediaSessionOptions; | 39 using cricket::MediaSessionOptions; |
| 39 | 40 |
| 40 namespace webrtc { | 41 namespace webrtc { |
| 41 namespace { | 42 namespace { |
| 42 static const char kFailedDueToIdentityFailed[] = | 43 static const char kFailedDueToIdentityFailed[] = |
| 43 " failed because DTLS identity request failed"; | 44 " failed because DTLS identity request failed"; |
| 44 static const char kFailedDueToSessionShutdown[] = | 45 static const char kFailedDueToSessionShutdown[] = |
| 45 " failed because the session was shut down"; | 46 " failed because the session was shut down"; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 61 MediaSessionOptions::Streams sorted_streams = streams; | 62 MediaSessionOptions::Streams sorted_streams = streams; |
| 62 std::sort(sorted_streams.begin(), sorted_streams.end(), CompareStream); | 63 std::sort(sorted_streams.begin(), sorted_streams.end(), CompareStream); |
| 63 MediaSessionOptions::Streams::iterator it = | 64 MediaSessionOptions::Streams::iterator it = |
| 64 std::adjacent_find(sorted_streams.begin(), sorted_streams.end(), | 65 std::adjacent_find(sorted_streams.begin(), sorted_streams.end(), |
| 65 SameId); | 66 SameId); |
| 66 return it == sorted_streams.end(); | 67 return it == sorted_streams.end(); |
| 67 } | 68 } |
| 68 | 69 |
| 69 enum { | 70 enum { |
| 70 MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, | 71 MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, |
| 71 MSG_CREATE_SESSIONDESCRIPTION_FAILED | 72 MSG_CREATE_SESSIONDESCRIPTION_FAILED, |
| 73 MSG_USE_CONSTRUCTOR_CERTIFICATE | |
| 72 }; | 74 }; |
| 73 | 75 |
| 74 struct CreateSessionDescriptionMsg : public rtc::MessageData { | 76 struct CreateSessionDescriptionMsg : public rtc::MessageData { |
| 75 explicit CreateSessionDescriptionMsg( | 77 explicit CreateSessionDescriptionMsg( |
| 76 webrtc::CreateSessionDescriptionObserver* observer) | 78 webrtc::CreateSessionDescriptionObserver* observer) |
| 77 : observer(observer) { | 79 : observer(observer) { |
| 78 } | 80 } |
| 79 | 81 |
| 80 rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserver> observer; | 82 rtc::scoped_refptr<webrtc::CreateSessionDescriptionObserver> observer; |
| 81 std::string error; | 83 std::string error; |
| 82 rtc::scoped_ptr<webrtc::SessionDescriptionInterface> description; | 84 rtc::scoped_ptr<webrtc::SessionDescriptionInterface> description; |
| 83 }; | 85 }; |
| 84 } // namespace | 86 } // namespace |
| 85 | 87 |
| 86 void WebRtcIdentityRequestObserver::OnFailure(int error) { | 88 void WebRtcIdentityRequestObserver::OnFailure(int error) { |
| 87 SignalRequestFailed(error); | 89 SignalRequestFailed(error); |
| 88 } | 90 } |
| 89 | 91 |
| 90 void WebRtcIdentityRequestObserver::OnSuccess( | 92 void WebRtcIdentityRequestObserver::OnSuccess( |
| 91 const std::string& der_cert, const std::string& der_private_key) { | 93 const std::string& der_cert, const std::string& der_private_key) { |
| 92 std::string pem_cert = rtc::SSLIdentity::DerToPem( | 94 std::string pem_cert = rtc::SSLIdentity::DerToPem( |
| 93 rtc::kPemTypeCertificate, | 95 rtc::kPemTypeCertificate, |
| 94 reinterpret_cast<const unsigned char*>(der_cert.data()), | 96 reinterpret_cast<const unsigned char*>(der_cert.data()), |
| 95 der_cert.length()); | 97 der_cert.length()); |
| 96 std::string pem_key = rtc::SSLIdentity::DerToPem( | 98 std::string pem_key = rtc::SSLIdentity::DerToPem( |
| 97 rtc::kPemTypeRsaPrivateKey, | 99 rtc::kPemTypeRsaPrivateKey, |
| 98 reinterpret_cast<const unsigned char*>(der_private_key.data()), | 100 reinterpret_cast<const unsigned char*>(der_private_key.data()), |
| 99 der_private_key.length()); | 101 der_private_key.length()); |
| 100 rtc::SSLIdentity* identity = | 102 rtc::scoped_ptr<rtc::SSLIdentity> identity( |
| 101 rtc::SSLIdentity::FromPEMStrings(pem_key, pem_cert); | 103 rtc::SSLIdentity::FromPEMStrings(pem_key, pem_cert)); |
| 102 SignalIdentityReady(identity); | 104 SignalCertificateReady(DtlsCertificate::Create(identity.Pass())); |
| 103 } | 105 } |
| 104 | 106 |
| 105 void WebRtcIdentityRequestObserver::OnSuccess( | 107 void WebRtcIdentityRequestObserver::OnSuccess( |
| 106 rtc::scoped_ptr<rtc::SSLIdentity> identity) { | 108 rtc::scoped_ptr<rtc::SSLIdentity> identity) { |
| 107 SignalIdentityReady(identity.release()); | 109 SignalCertificateReady(DtlsCertificate::Create(identity.Pass())); |
| 108 } | 110 } |
| 109 | 111 |
| 110 // static | 112 // static |
| 111 void WebRtcSessionDescriptionFactory::CopyCandidatesFromSessionDescription( | 113 void WebRtcSessionDescriptionFactory::CopyCandidatesFromSessionDescription( |
| 112 const SessionDescriptionInterface* source_desc, | 114 const SessionDescriptionInterface* source_desc, |
| 113 SessionDescriptionInterface* dest_desc) { | 115 SessionDescriptionInterface* dest_desc) { |
| 114 if (!source_desc) | 116 if (!source_desc) |
| 115 return; | 117 return; |
| 116 for (size_t m = 0; m < source_desc->number_of_mediasections() && | 118 for (size_t m = 0; m < source_desc->number_of_mediasections() && |
| 117 m < dest_desc->number_of_mediasections(); ++m) { | 119 m < dest_desc->number_of_mediasections(); ++m) { |
| 118 const IceCandidateCollection* source_candidates = | 120 const IceCandidateCollection* source_candidates = |
| 119 source_desc->candidates(m); | 121 source_desc->candidates(m); |
| 120 const IceCandidateCollection* dest_candidates = dest_desc->candidates(m); | 122 const IceCandidateCollection* dest_candidates = dest_desc->candidates(m); |
| 121 for (size_t n = 0; n < source_candidates->count(); ++n) { | 123 for (size_t n = 0; n < source_candidates->count(); ++n) { |
| 122 const IceCandidateInterface* new_candidate = source_candidates->at(n); | 124 const IceCandidateInterface* new_candidate = source_candidates->at(n); |
| 123 if (!dest_candidates->HasCandidate(new_candidate)) | 125 if (!dest_candidates->HasCandidate(new_candidate)) |
| 124 dest_desc->AddCandidate(source_candidates->at(n)); | 126 dest_desc->AddCandidate(source_candidates->at(n)); |
| 125 } | 127 } |
| 126 } | 128 } |
| 127 } | 129 } |
| 128 | 130 |
| 131 // Private constructor called by other constructors. | |
| 129 WebRtcSessionDescriptionFactory::WebRtcSessionDescriptionFactory( | 132 WebRtcSessionDescriptionFactory::WebRtcSessionDescriptionFactory( |
| 130 rtc::Thread* signaling_thread, | 133 rtc::Thread* signaling_thread, |
| 134 rtc::Thread* worker_thread, | |
| 131 cricket::ChannelManager* channel_manager, | 135 cricket::ChannelManager* channel_manager, |
| 132 MediaStreamSignaling* mediastream_signaling, | 136 MediaStreamSignaling* mediastream_signaling, |
| 133 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | |
| 134 WebRtcSession* session, | 137 WebRtcSession* session, |
| 135 const std::string& session_id, | 138 const std::string& session_id, |
| 136 cricket::DataChannelType dct, | 139 cricket::DataChannelType dct, |
| 137 bool dtls_enabled) | 140 bool dtls_enabled) |
| 138 : signaling_thread_(signaling_thread), | 141 : signaling_thread_(signaling_thread), |
| 142 worker_thread_(worker_thread), | |
| 139 mediastream_signaling_(mediastream_signaling), | 143 mediastream_signaling_(mediastream_signaling), |
| 140 session_desc_factory_(channel_manager, &transport_desc_factory_), | 144 session_desc_factory_(channel_manager, &transport_desc_factory_), |
| 141 // RFC 4566 suggested a Network Time Protocol (NTP) format timestamp | 145 // RFC 4566 suggested a Network Time Protocol (NTP) format timestamp |
| 142 // as the session id and session version. To simplify, it should be fine | 146 // as the session id and session version. To simplify, it should be fine |
| 143 // to just use a random number as session id and start version from | 147 // to just use a random number as session id and start version from |
| 144 // |kInitSessionVersion|. | 148 // |kInitSessionVersion|. |
| 145 session_version_(kInitSessionVersion), | 149 session_version_(kInitSessionVersion), |
| 146 dtls_identity_store_(dtls_identity_store.Pass()), | |
| 147 session_(session), | 150 session_(session), |
| 148 session_id_(session_id), | 151 session_id_(session_id), |
| 149 data_channel_type_(dct), | 152 data_channel_type_(dct), |
| 150 identity_request_state_(IDENTITY_NOT_NEEDED) { | 153 certificate_request_state_(CERTIFICATE_NOT_NEEDED) { |
| 151 transport_desc_factory_.set_protocol(cricket::ICEPROTO_RFC5245); | 154 transport_desc_factory_.set_protocol(cricket::ICEPROTO_RFC5245); |
| 152 session_desc_factory_.set_add_legacy_streams(false); | 155 session_desc_factory_.set_add_legacy_streams(false); |
| 153 // SRTP-SDES is disabled if DTLS is on. | 156 // SRTP-SDES is disabled if DTLS is on. |
| 154 SetSdesPolicy(dtls_enabled ? cricket::SEC_DISABLED : cricket::SEC_REQUIRED); | 157 SetSdesPolicy(dtls_enabled ? cricket::SEC_DISABLED : cricket::SEC_REQUIRED); |
| 158 } | |
| 155 | 159 |
| 156 // If |dtls_enabled| we must have a |dtls_identity_store_|. | 160 WebRtcSessionDescriptionFactory::WebRtcSessionDescriptionFactory( |
| 157 DCHECK(!dtls_enabled || dtls_identity_store_); | 161 rtc::Thread* signaling_thread, |
| 162 rtc::Thread* worker_thread, | |
| 163 cricket::ChannelManager* channel_manager, | |
| 164 MediaStreamSignaling* mediastream_signaling, | |
| 165 WebRtcSession* session, | |
| 166 const std::string& session_id, | |
| 167 cricket::DataChannelType dct) | |
| 168 : WebRtcSessionDescriptionFactory(signaling_thread, worker_thread, | |
| 169 channel_manager, mediastream_signaling, | |
| 170 session, session_id, dct, false) { | |
| 171 } | |
| 158 | 172 |
| 159 if (dtls_enabled && dtls_identity_store_) { | 173 WebRtcSessionDescriptionFactory::WebRtcSessionDescriptionFactory( |
| 160 identity_request_observer_ = | 174 rtc::Thread* signaling_thread, |
| 161 new rtc::RefCountedObject<WebRtcIdentityRequestObserver>(); | 175 rtc::Thread* worker_thread, |
| 176 cricket::ChannelManager* channel_manager, | |
| 177 MediaStreamSignaling* mediastream_signaling, | |
| 178 rtc::scoped_ptr<DtlsIdentityStoreInterface> dtls_identity_store, | |
| 179 WebRtcSession* session, | |
| 180 const std::string& session_id, | |
| 181 cricket::DataChannelType dct) | |
| 182 : WebRtcSessionDescriptionFactory(signaling_thread, worker_thread, | |
| 183 channel_manager, mediastream_signaling, | |
| 184 session, session_id, dct, true) { | |
| 185 dtls_identity_store_.reset(dtls_identity_store.release()); | |
|
tommi (sloooow) - chröme
2015/08/18 14:49:35
dtls_identity_store_(dtls_identity_store.Pass()) i
| |
| 162 | 186 |
| 163 identity_request_observer_->SignalRequestFailed.connect( | 187 // Generate certificate. |
| 164 this, &WebRtcSessionDescriptionFactory::OnIdentityRequestFailed); | 188 certificate_request_state_ = CERTIFICATE_WAITING; |
| 165 identity_request_observer_->SignalIdentityReady.connect( | |
| 166 this, &WebRtcSessionDescriptionFactory::SetIdentity); | |
| 167 | 189 |
| 168 LOG(LS_VERBOSE) << "DTLS-SRTP enabled; sending DTLS identity request."; | 190 identity_request_observer_ = |
| 169 identity_request_state_ = IDENTITY_WAITING; | 191 new rtc::RefCountedObject<WebRtcIdentityRequestObserver>(); |
| 170 dtls_identity_store_->RequestIdentity(rtc::KT_DEFAULT, | 192 identity_request_observer_->SignalRequestFailed.connect( |
| 171 identity_request_observer_); | 193 this, &WebRtcSessionDescriptionFactory::OnIdentityRequestFailed); |
| 194 identity_request_observer_->SignalCertificateReady.connect( | |
| 195 this, &WebRtcSessionDescriptionFactory::SetCertificate); | |
| 196 | |
| 197 // If an |dtls_identity_store_| was not provided we default to using | |
| 198 // DtlsIdentityStore. | |
| 199 if (!dtls_identity_store_) { | |
| 200 dtls_identity_store_.reset( | |
| 201 new DtlsIdentityStoreImpl(signaling_thread_, worker_thread_)); | |
| 172 } | 202 } |
| 203 | |
| 204 // Request identity. This happens asynchronously, so the caller will have a | |
| 205 // chance to connect to SignalCertificateReady. | |
| 206 dtls_identity_store_->RequestIdentity(rtc::KT_DEFAULT, | |
| 207 identity_request_observer_); | |
| 208 LOG(LS_VERBOSE) << "DTLS-SRTP enabled, sent DTLS identity request."; | |
| 209 } | |
| 210 | |
| 211 WebRtcSessionDescriptionFactory::WebRtcSessionDescriptionFactory( | |
| 212 rtc::Thread* signaling_thread, | |
| 213 rtc::Thread* worker_thread, | |
| 214 cricket::ChannelManager* channel_manager, | |
| 215 MediaStreamSignaling* mediastream_signaling, | |
| 216 const rtc::scoped_refptr<DtlsCertificate>& certificate, | |
| 217 WebRtcSession* session, | |
| 218 const std::string& session_id, | |
| 219 cricket::DataChannelType dct) | |
| 220 : WebRtcSessionDescriptionFactory(signaling_thread, worker_thread, | |
| 221 channel_manager, mediastream_signaling, | |
| 222 session, session_id, dct, true) { | |
| 223 DCHECK(certificate.get()); | |
| 224 | |
| 225 LOG(LS_VERBOSE) << "DTLS-SRTP enabled; using DTLS certificate."; | |
| 226 // We already have a certificate but we wait to do SetCertificate; if we do | |
| 227 // it in the constructor then the caller has not had a chance to connect to | |
| 228 // SignalCertificateReady. | |
| 229 certificate_request_state_ = CERTIFICATE_WAITING; | |
| 230 signaling_thread_->Post(this, MSG_USE_CONSTRUCTOR_CERTIFICATE, | |
| 231 new rtc::ScopedRefMessageData<DtlsCertificate>( | |
| 232 certificate)); | |
| 173 } | 233 } |
| 174 | 234 |
| 175 WebRtcSessionDescriptionFactory::~WebRtcSessionDescriptionFactory() { | 235 WebRtcSessionDescriptionFactory::~WebRtcSessionDescriptionFactory() { |
| 176 ASSERT(signaling_thread_->IsCurrent()); | 236 ASSERT(signaling_thread_->IsCurrent()); |
| 177 | 237 |
| 178 // Fail any requests that were asked for before identity generation completed. | 238 // Fail any requests that were asked for before identity generation completed. |
| 179 FailPendingRequests(kFailedDueToSessionShutdown); | 239 FailPendingRequests(kFailedDueToSessionShutdown); |
| 180 | 240 |
| 181 // Process all pending notifications in the message queue. If we don't do | 241 // Process all pending notifications in the message queue. If we don't do |
| 182 // this, requests will linger and not know they succeeded or failed. | 242 // this, requests will linger and not know they succeeded or failed. |
| 183 rtc::MessageList list; | 243 rtc::MessageList list; |
| 184 signaling_thread_->Clear(this, rtc::MQID_ANY, &list); | 244 signaling_thread_->Clear(this, rtc::MQID_ANY, &list); |
| 185 for (auto& msg : list) | 245 for (auto& msg : list) |
| 186 OnMessage(&msg); | 246 OnMessage(&msg); |
| 187 | 247 |
| 188 transport_desc_factory_.set_identity(NULL); | 248 transport_desc_factory_.set_certificate(nullptr); |
| 189 } | 249 } |
| 190 | 250 |
| 191 void WebRtcSessionDescriptionFactory::CreateOffer( | 251 void WebRtcSessionDescriptionFactory::CreateOffer( |
| 192 CreateSessionDescriptionObserver* observer, | 252 CreateSessionDescriptionObserver* observer, |
| 193 const PeerConnectionInterface::RTCOfferAnswerOptions& options) { | 253 const PeerConnectionInterface::RTCOfferAnswerOptions& options) { |
| 194 cricket::MediaSessionOptions session_options; | 254 cricket::MediaSessionOptions session_options; |
| 195 | 255 |
| 196 std::string error = "CreateOffer"; | 256 std::string error = "CreateOffer"; |
| 197 if (identity_request_state_ == IDENTITY_FAILED) { | 257 if (certificate_request_state_ == CERTIFICATE_FAILED) { |
| 198 error += kFailedDueToIdentityFailed; | 258 error += kFailedDueToIdentityFailed; |
| 199 LOG(LS_ERROR) << error; | 259 LOG(LS_ERROR) << error; |
| 200 PostCreateSessionDescriptionFailed(observer, error); | 260 PostCreateSessionDescriptionFailed(observer, error); |
| 201 return; | 261 return; |
| 202 } | 262 } |
| 203 | 263 |
| 204 if (!mediastream_signaling_->GetOptionsForOffer(options, | 264 if (!mediastream_signaling_->GetOptionsForOffer(options, |
| 205 &session_options)) { | 265 &session_options)) { |
| 206 error += " called with invalid options."; | 266 error += " called with invalid options."; |
| 207 LOG(LS_ERROR) << error; | 267 LOG(LS_ERROR) << error; |
| 208 PostCreateSessionDescriptionFailed(observer, error); | 268 PostCreateSessionDescriptionFailed(observer, error); |
| 209 return; | 269 return; |
| 210 } | 270 } |
| 211 | 271 |
| 212 if (!ValidStreams(session_options.streams)) { | 272 if (!ValidStreams(session_options.streams)) { |
| 213 error += " called with invalid media streams."; | 273 error += " called with invalid media streams."; |
| 214 LOG(LS_ERROR) << error; | 274 LOG(LS_ERROR) << error; |
| 215 PostCreateSessionDescriptionFailed(observer, error); | 275 PostCreateSessionDescriptionFailed(observer, error); |
| 216 return; | 276 return; |
| 217 } | 277 } |
| 218 | 278 |
| 219 if (data_channel_type_ == cricket::DCT_SCTP && | 279 if (data_channel_type_ == cricket::DCT_SCTP && |
| 220 mediastream_signaling_->HasDataChannels()) { | 280 mediastream_signaling_->HasDataChannels()) { |
| 221 session_options.data_channel_type = cricket::DCT_SCTP; | 281 session_options.data_channel_type = cricket::DCT_SCTP; |
| 222 } | 282 } |
| 223 | 283 |
| 224 CreateSessionDescriptionRequest request( | 284 CreateSessionDescriptionRequest request( |
| 225 CreateSessionDescriptionRequest::kOffer, observer, session_options); | 285 CreateSessionDescriptionRequest::kOffer, observer, session_options); |
| 226 if (identity_request_state_ == IDENTITY_WAITING) { | 286 if (certificate_request_state_ == CERTIFICATE_WAITING) { |
| 227 create_session_description_requests_.push(request); | 287 create_session_description_requests_.push(request); |
| 228 } else { | 288 } else { |
| 229 ASSERT(identity_request_state_ == IDENTITY_SUCCEEDED || | 289 ASSERT(certificate_request_state_ == CERTIFICATE_SUCCEEDED || |
| 230 identity_request_state_ == IDENTITY_NOT_NEEDED); | 290 certificate_request_state_ == CERTIFICATE_NOT_NEEDED); |
| 231 InternalCreateOffer(request); | 291 InternalCreateOffer(request); |
| 232 } | 292 } |
| 233 } | 293 } |
| 234 | 294 |
| 235 void WebRtcSessionDescriptionFactory::CreateAnswer( | 295 void WebRtcSessionDescriptionFactory::CreateAnswer( |
| 236 CreateSessionDescriptionObserver* observer, | 296 CreateSessionDescriptionObserver* observer, |
| 237 const MediaConstraintsInterface* constraints) { | 297 const MediaConstraintsInterface* constraints) { |
| 238 std::string error = "CreateAnswer"; | 298 std::string error = "CreateAnswer"; |
| 239 if (identity_request_state_ == IDENTITY_FAILED) { | 299 if (certificate_request_state_ == CERTIFICATE_FAILED) { |
| 240 error += kFailedDueToIdentityFailed; | 300 error += kFailedDueToIdentityFailed; |
| 241 LOG(LS_ERROR) << error; | 301 LOG(LS_ERROR) << error; |
| 242 PostCreateSessionDescriptionFailed(observer, error); | 302 PostCreateSessionDescriptionFailed(observer, error); |
| 243 return; | 303 return; |
| 244 } | 304 } |
| 245 if (!session_->remote_description()) { | 305 if (!session_->remote_description()) { |
| 246 error += " can't be called before SetRemoteDescription."; | 306 error += " can't be called before SetRemoteDescription."; |
| 247 LOG(LS_ERROR) << error; | 307 LOG(LS_ERROR) << error; |
| 248 PostCreateSessionDescriptionFailed(observer, error); | 308 PostCreateSessionDescriptionFailed(observer, error); |
| 249 return; | 309 return; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 271 } | 331 } |
| 272 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams | 332 // RTP data channel is handled in MediaSessionOptions::AddStream. SCTP streams |
| 273 // are not signaled in the SDP so does not go through that path and must be | 333 // are not signaled in the SDP so does not go through that path and must be |
| 274 // handled here. | 334 // handled here. |
| 275 if (data_channel_type_ == cricket::DCT_SCTP) { | 335 if (data_channel_type_ == cricket::DCT_SCTP) { |
| 276 options.data_channel_type = cricket::DCT_SCTP; | 336 options.data_channel_type = cricket::DCT_SCTP; |
| 277 } | 337 } |
| 278 | 338 |
| 279 CreateSessionDescriptionRequest request( | 339 CreateSessionDescriptionRequest request( |
| 280 CreateSessionDescriptionRequest::kAnswer, observer, options); | 340 CreateSessionDescriptionRequest::kAnswer, observer, options); |
| 281 if (identity_request_state_ == IDENTITY_WAITING) { | 341 if (certificate_request_state_ == CERTIFICATE_WAITING) { |
| 282 create_session_description_requests_.push(request); | 342 create_session_description_requests_.push(request); |
| 283 } else { | 343 } else { |
| 284 ASSERT(identity_request_state_ == IDENTITY_SUCCEEDED || | 344 ASSERT(certificate_request_state_ == CERTIFICATE_SUCCEEDED || |
| 285 identity_request_state_ == IDENTITY_NOT_NEEDED); | 345 certificate_request_state_ == CERTIFICATE_NOT_NEEDED); |
| 286 InternalCreateAnswer(request); | 346 InternalCreateAnswer(request); |
| 287 } | 347 } |
| 288 } | 348 } |
| 289 | 349 |
| 290 void WebRtcSessionDescriptionFactory::SetSdesPolicy( | 350 void WebRtcSessionDescriptionFactory::SetSdesPolicy( |
| 291 cricket::SecurePolicy secure_policy) { | 351 cricket::SecurePolicy secure_policy) { |
| 292 session_desc_factory_.set_secure(secure_policy); | 352 session_desc_factory_.set_secure(secure_policy); |
| 293 } | 353 } |
| 294 | 354 |
| 295 cricket::SecurePolicy WebRtcSessionDescriptionFactory::SdesPolicy() const { | 355 cricket::SecurePolicy WebRtcSessionDescriptionFactory::SdesPolicy() const { |
| 296 return session_desc_factory_.secure(); | 356 return session_desc_factory_.secure(); |
| 297 } | 357 } |
| 298 | 358 |
| 299 void WebRtcSessionDescriptionFactory::OnMessage(rtc::Message* msg) { | 359 void WebRtcSessionDescriptionFactory::OnMessage(rtc::Message* msg) { |
| 300 switch (msg->message_id) { | 360 switch (msg->message_id) { |
| 301 case MSG_CREATE_SESSIONDESCRIPTION_SUCCESS: { | 361 case MSG_CREATE_SESSIONDESCRIPTION_SUCCESS: { |
| 302 CreateSessionDescriptionMsg* param = | 362 CreateSessionDescriptionMsg* param = |
| 303 static_cast<CreateSessionDescriptionMsg*>(msg->pdata); | 363 static_cast<CreateSessionDescriptionMsg*>(msg->pdata); |
| 304 param->observer->OnSuccess(param->description.release()); | 364 param->observer->OnSuccess(param->description.release()); |
| 305 delete param; | 365 delete param; |
| 306 break; | 366 break; |
| 307 } | 367 } |
| 308 case MSG_CREATE_SESSIONDESCRIPTION_FAILED: { | 368 case MSG_CREATE_SESSIONDESCRIPTION_FAILED: { |
| 309 CreateSessionDescriptionMsg* param = | 369 CreateSessionDescriptionMsg* param = |
| 310 static_cast<CreateSessionDescriptionMsg*>(msg->pdata); | 370 static_cast<CreateSessionDescriptionMsg*>(msg->pdata); |
| 311 param->observer->OnFailure(param->error); | 371 param->observer->OnFailure(param->error); |
| 312 delete param; | 372 delete param; |
| 313 break; | 373 break; |
| 314 } | 374 } |
| 375 case MSG_USE_CONSTRUCTOR_CERTIFICATE: { | |
| 376 rtc::ScopedRefMessageData<DtlsCertificate>* param = | |
| 377 static_cast<rtc::ScopedRefMessageData<DtlsCertificate>*>(msg->pdata); | |
| 378 LOG(LS_INFO) << "Using certificate supplied to constructor."; | |
| 379 SetCertificate(param->data()); | |
| 380 delete param; | |
| 381 break; | |
| 382 } | |
| 315 default: | 383 default: |
| 316 ASSERT(false); | 384 ASSERT(false); |
| 317 break; | 385 break; |
| 318 } | 386 } |
| 319 } | 387 } |
| 320 | 388 |
| 321 void WebRtcSessionDescriptionFactory::InternalCreateOffer( | 389 void WebRtcSessionDescriptionFactory::InternalCreateOffer( |
| 322 CreateSessionDescriptionRequest request) { | 390 CreateSessionDescriptionRequest request) { |
| 323 cricket::SessionDescription* desc( | 391 cricket::SessionDescription* desc( |
| 324 session_desc_factory_.CreateOffer( | 392 session_desc_factory_.CreateOffer( |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 SessionDescriptionInterface* description) { | 491 SessionDescriptionInterface* description) { |
| 424 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); | 492 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); |
| 425 msg->description.reset(description); | 493 msg->description.reset(description); |
| 426 signaling_thread_->Post(this, MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, msg); | 494 signaling_thread_->Post(this, MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, msg); |
| 427 } | 495 } |
| 428 | 496 |
| 429 void WebRtcSessionDescriptionFactory::OnIdentityRequestFailed(int error) { | 497 void WebRtcSessionDescriptionFactory::OnIdentityRequestFailed(int error) { |
| 430 ASSERT(signaling_thread_->IsCurrent()); | 498 ASSERT(signaling_thread_->IsCurrent()); |
| 431 | 499 |
| 432 LOG(LS_ERROR) << "Async identity request failed: error = " << error; | 500 LOG(LS_ERROR) << "Async identity request failed: error = " << error; |
| 433 identity_request_state_ = IDENTITY_FAILED; | 501 certificate_request_state_ = CERTIFICATE_FAILED; |
| 434 | 502 |
| 435 FailPendingRequests(kFailedDueToIdentityFailed); | 503 FailPendingRequests(kFailedDueToIdentityFailed); |
| 436 } | 504 } |
| 437 | 505 |
| 438 void WebRtcSessionDescriptionFactory::SetIdentity( | 506 void WebRtcSessionDescriptionFactory::SetCertificate( |
| 439 rtc::SSLIdentity* identity) { | 507 const rtc::scoped_refptr<DtlsCertificate>& certificate) { |
| 440 LOG(LS_VERBOSE) << "Setting new identity"; | 508 LOG(LS_VERBOSE) << "Setting new certificate"; |
| 441 | 509 |
| 442 identity_request_state_ = IDENTITY_SUCCEEDED; | 510 DCHECK(certificate); |
| 443 SignalIdentityReady(identity); | |
| 444 | 511 |
| 445 transport_desc_factory_.set_identity(identity); | 512 certificate_request_state_ = CERTIFICATE_SUCCEEDED; |
| 513 SignalCertificateReady(certificate); | |
| 514 | |
| 515 transport_desc_factory_.set_certificate(certificate); | |
| 446 transport_desc_factory_.set_secure(cricket::SEC_ENABLED); | 516 transport_desc_factory_.set_secure(cricket::SEC_ENABLED); |
| 447 | 517 |
| 448 while (!create_session_description_requests_.empty()) { | 518 while (!create_session_description_requests_.empty()) { |
| 449 if (create_session_description_requests_.front().type == | 519 if (create_session_description_requests_.front().type == |
| 450 CreateSessionDescriptionRequest::kOffer) { | 520 CreateSessionDescriptionRequest::kOffer) { |
| 451 InternalCreateOffer(create_session_description_requests_.front()); | 521 InternalCreateOffer(create_session_description_requests_.front()); |
| 452 } else { | 522 } else { |
| 453 InternalCreateAnswer(create_session_description_requests_.front()); | 523 InternalCreateAnswer(create_session_description_requests_.front()); |
| 454 } | 524 } |
| 455 create_session_description_requests_.pop(); | 525 create_session_description_requests_.pop(); |
| 456 } | 526 } |
| 457 } | 527 } |
| 458 } // namespace webrtc | 528 } // namespace webrtc |
| OLD | NEW |