OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 : WebRtcSessionDescriptionFactory(signaling_thread, | 194 : WebRtcSessionDescriptionFactory(signaling_thread, |
195 channel_manager, | 195 channel_manager, |
196 session, | 196 session, |
197 session_id, | 197 session_id, |
198 nullptr, | 198 nullptr, |
199 certificate) { | 199 certificate) { |
200 RTC_DCHECK(certificate); | 200 RTC_DCHECK(certificate); |
201 } | 201 } |
202 | 202 |
203 WebRtcSessionDescriptionFactory::~WebRtcSessionDescriptionFactory() { | 203 WebRtcSessionDescriptionFactory::~WebRtcSessionDescriptionFactory() { |
204 ASSERT(signaling_thread_->IsCurrent()); | 204 RTC_DCHECK(signaling_thread_->IsCurrent()); |
205 | 205 |
206 // Fail any requests that were asked for before identity generation completed. | 206 // Fail any requests that were asked for before identity generation completed. |
207 FailPendingRequests(kFailedDueToSessionShutdown); | 207 FailPendingRequests(kFailedDueToSessionShutdown); |
208 | 208 |
209 // Process all pending notifications in the message queue. If we don't do | 209 // Process all pending notifications in the message queue. If we don't do |
210 // this, requests will linger and not know they succeeded or failed. | 210 // this, requests will linger and not know they succeeded or failed. |
211 rtc::MessageList list; | 211 rtc::MessageList list; |
212 signaling_thread_->Clear(this, rtc::MQID_ANY, &list); | 212 signaling_thread_->Clear(this, rtc::MQID_ANY, &list); |
213 for (auto& msg : list) { | 213 for (auto& msg : list) { |
214 if (msg.message_id != MSG_USE_CONSTRUCTOR_CERTIFICATE) { | 214 if (msg.message_id != MSG_USE_CONSTRUCTOR_CERTIFICATE) { |
(...skipping 27 matching lines...) Expand all Loading... |
242 LOG(LS_ERROR) << error; | 242 LOG(LS_ERROR) << error; |
243 PostCreateSessionDescriptionFailed(observer, error); | 243 PostCreateSessionDescriptionFailed(observer, error); |
244 return; | 244 return; |
245 } | 245 } |
246 | 246 |
247 CreateSessionDescriptionRequest request( | 247 CreateSessionDescriptionRequest request( |
248 CreateSessionDescriptionRequest::kOffer, observer, session_options); | 248 CreateSessionDescriptionRequest::kOffer, observer, session_options); |
249 if (certificate_request_state_ == CERTIFICATE_WAITING) { | 249 if (certificate_request_state_ == CERTIFICATE_WAITING) { |
250 create_session_description_requests_.push(request); | 250 create_session_description_requests_.push(request); |
251 } else { | 251 } else { |
252 ASSERT(certificate_request_state_ == CERTIFICATE_SUCCEEDED || | 252 RTC_DCHECK(certificate_request_state_ == CERTIFICATE_SUCCEEDED || |
253 certificate_request_state_ == CERTIFICATE_NOT_NEEDED); | 253 certificate_request_state_ == CERTIFICATE_NOT_NEEDED); |
254 InternalCreateOffer(request); | 254 InternalCreateOffer(request); |
255 } | 255 } |
256 } | 256 } |
257 | 257 |
258 void WebRtcSessionDescriptionFactory::CreateAnswer( | 258 void WebRtcSessionDescriptionFactory::CreateAnswer( |
259 CreateSessionDescriptionObserver* observer, | 259 CreateSessionDescriptionObserver* observer, |
260 const cricket::MediaSessionOptions& session_options) { | 260 const cricket::MediaSessionOptions& session_options) { |
261 std::string error = "CreateAnswer"; | 261 std::string error = "CreateAnswer"; |
262 if (certificate_request_state_ == CERTIFICATE_FAILED) { | 262 if (certificate_request_state_ == CERTIFICATE_FAILED) { |
263 error += kFailedDueToIdentityFailed; | 263 error += kFailedDueToIdentityFailed; |
(...skipping 20 matching lines...) Expand all Loading... |
284 LOG(LS_ERROR) << error; | 284 LOG(LS_ERROR) << error; |
285 PostCreateSessionDescriptionFailed(observer, error); | 285 PostCreateSessionDescriptionFailed(observer, error); |
286 return; | 286 return; |
287 } | 287 } |
288 | 288 |
289 CreateSessionDescriptionRequest request( | 289 CreateSessionDescriptionRequest request( |
290 CreateSessionDescriptionRequest::kAnswer, observer, session_options); | 290 CreateSessionDescriptionRequest::kAnswer, observer, session_options); |
291 if (certificate_request_state_ == CERTIFICATE_WAITING) { | 291 if (certificate_request_state_ == CERTIFICATE_WAITING) { |
292 create_session_description_requests_.push(request); | 292 create_session_description_requests_.push(request); |
293 } else { | 293 } else { |
294 ASSERT(certificate_request_state_ == CERTIFICATE_SUCCEEDED || | 294 RTC_DCHECK(certificate_request_state_ == CERTIFICATE_SUCCEEDED || |
295 certificate_request_state_ == CERTIFICATE_NOT_NEEDED); | 295 certificate_request_state_ == CERTIFICATE_NOT_NEEDED); |
296 InternalCreateAnswer(request); | 296 InternalCreateAnswer(request); |
297 } | 297 } |
298 } | 298 } |
299 | 299 |
300 void WebRtcSessionDescriptionFactory::SetSdesPolicy( | 300 void WebRtcSessionDescriptionFactory::SetSdesPolicy( |
301 cricket::SecurePolicy secure_policy) { | 301 cricket::SecurePolicy secure_policy) { |
302 session_desc_factory_.set_secure(secure_policy); | 302 session_desc_factory_.set_secure(secure_policy); |
303 } | 303 } |
304 | 304 |
305 cricket::SecurePolicy WebRtcSessionDescriptionFactory::SdesPolicy() const { | 305 cricket::SecurePolicy WebRtcSessionDescriptionFactory::SdesPolicy() const { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 : nullptr)); | 357 : nullptr)); |
358 // RFC 3264 | 358 // RFC 3264 |
359 // When issuing an offer that modifies the session, | 359 // When issuing an offer that modifies the session, |
360 // the "o=" line of the new SDP MUST be identical to that in the | 360 // the "o=" line of the new SDP MUST be identical to that in the |
361 // previous SDP, except that the version in the origin field MUST | 361 // previous SDP, except that the version in the origin field MUST |
362 // increment by one from the previous SDP. | 362 // increment by one from the previous SDP. |
363 | 363 |
364 // Just increase the version number by one each time when a new offer | 364 // Just increase the version number by one each time when a new offer |
365 // is created regardless if it's identical to the previous one or not. | 365 // is created regardless if it's identical to the previous one or not. |
366 // The |session_version_| is a uint64_t, the wrap around should not happen. | 366 // The |session_version_| is a uint64_t, the wrap around should not happen. |
367 ASSERT(session_version_ + 1 > session_version_); | 367 RTC_DCHECK(session_version_ + 1 > session_version_); |
368 JsepSessionDescription* offer(new JsepSessionDescription( | 368 JsepSessionDescription* offer(new JsepSessionDescription( |
369 JsepSessionDescription::kOffer)); | 369 JsepSessionDescription::kOffer)); |
370 if (!offer->Initialize(desc, session_id_, | 370 if (!offer->Initialize(desc, session_id_, |
371 rtc::ToString(session_version_++))) { | 371 rtc::ToString(session_version_++))) { |
372 delete offer; | 372 delete offer; |
373 PostCreateSessionDescriptionFailed(request.observer, | 373 PostCreateSessionDescriptionFailed(request.observer, |
374 "Failed to initialize the offer."); | 374 "Failed to initialize the offer."); |
375 return; | 375 return; |
376 } | 376 } |
377 if (session_->local_description()) { | 377 if (session_->local_description()) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 request.options, session_->local_description() | 415 request.options, session_->local_description() |
416 ? session_->local_description()->description() | 416 ? session_->local_description()->description() |
417 : nullptr)); | 417 : nullptr)); |
418 // RFC 3264 | 418 // RFC 3264 |
419 // If the answer is different from the offer in any way (different IP | 419 // If the answer is different from the offer in any way (different IP |
420 // addresses, ports, etc.), the origin line MUST be different in the answer. | 420 // addresses, ports, etc.), the origin line MUST be different in the answer. |
421 // In that case, the version number in the "o=" line of the answer is | 421 // In that case, the version number in the "o=" line of the answer is |
422 // unrelated to the version number in the o line of the offer. | 422 // unrelated to the version number in the o line of the offer. |
423 // Get a new version number by increasing the |session_version_answer_|. | 423 // Get a new version number by increasing the |session_version_answer_|. |
424 // The |session_version_| is a uint64_t, the wrap around should not happen. | 424 // The |session_version_| is a uint64_t, the wrap around should not happen. |
425 ASSERT(session_version_ + 1 > session_version_); | 425 RTC_DCHECK(session_version_ + 1 > session_version_); |
426 JsepSessionDescription* answer(new JsepSessionDescription( | 426 JsepSessionDescription* answer(new JsepSessionDescription( |
427 JsepSessionDescription::kAnswer)); | 427 JsepSessionDescription::kAnswer)); |
428 if (!answer->Initialize(desc, session_id_, | 428 if (!answer->Initialize(desc, session_id_, |
429 rtc::ToString(session_version_++))) { | 429 rtc::ToString(session_version_++))) { |
430 delete answer; | 430 delete answer; |
431 PostCreateSessionDescriptionFailed(request.observer, | 431 PostCreateSessionDescriptionFailed(request.observer, |
432 "Failed to initialize the answer."); | 432 "Failed to initialize the answer."); |
433 return; | 433 return; |
434 } | 434 } |
435 if (session_->local_description()) { | 435 if (session_->local_description()) { |
436 for (const cricket::ContentInfo& content : | 436 for (const cricket::ContentInfo& content : |
437 session_->local_description()->description()->contents()) { | 437 session_->local_description()->description()->contents()) { |
438 // Include all local ICE candidates in the SessionDescription unless | 438 // Include all local ICE candidates in the SessionDescription unless |
439 // the remote peer has requested an ICE restart. | 439 // the remote peer has requested an ICE restart. |
440 if (!request.options.transport_options[content.name].ice_restart) { | 440 if (!request.options.transport_options[content.name].ice_restart) { |
441 CopyCandidatesFromSessionDescription(session_->local_description(), | 441 CopyCandidatesFromSessionDescription(session_->local_description(), |
442 content.name, answer); | 442 content.name, answer); |
443 } | 443 } |
444 } | 444 } |
445 } | 445 } |
446 PostCreateSessionDescriptionSucceeded(request.observer, answer); | 446 PostCreateSessionDescriptionSucceeded(request.observer, answer); |
447 } | 447 } |
448 | 448 |
449 void WebRtcSessionDescriptionFactory::FailPendingRequests( | 449 void WebRtcSessionDescriptionFactory::FailPendingRequests( |
450 const std::string& reason) { | 450 const std::string& reason) { |
451 ASSERT(signaling_thread_->IsCurrent()); | 451 RTC_DCHECK(signaling_thread_->IsCurrent()); |
452 while (!create_session_description_requests_.empty()) { | 452 while (!create_session_description_requests_.empty()) { |
453 const CreateSessionDescriptionRequest& request = | 453 const CreateSessionDescriptionRequest& request = |
454 create_session_description_requests_.front(); | 454 create_session_description_requests_.front(); |
455 PostCreateSessionDescriptionFailed(request.observer, | 455 PostCreateSessionDescriptionFailed(request.observer, |
456 ((request.type == CreateSessionDescriptionRequest::kOffer) ? | 456 ((request.type == CreateSessionDescriptionRequest::kOffer) ? |
457 "CreateOffer" : "CreateAnswer") + reason); | 457 "CreateOffer" : "CreateAnswer") + reason); |
458 create_session_description_requests_.pop(); | 458 create_session_description_requests_.pop(); |
459 } | 459 } |
460 } | 460 } |
461 | 461 |
462 void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionFailed( | 462 void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionFailed( |
463 CreateSessionDescriptionObserver* observer, const std::string& error) { | 463 CreateSessionDescriptionObserver* observer, const std::string& error) { |
464 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); | 464 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); |
465 msg->error = error; | 465 msg->error = error; |
466 signaling_thread_->Post(RTC_FROM_HERE, this, | 466 signaling_thread_->Post(RTC_FROM_HERE, this, |
467 MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg); | 467 MSG_CREATE_SESSIONDESCRIPTION_FAILED, msg); |
468 LOG(LS_ERROR) << "Create SDP failed: " << error; | 468 LOG(LS_ERROR) << "Create SDP failed: " << error; |
469 } | 469 } |
470 | 470 |
471 void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionSucceeded( | 471 void WebRtcSessionDescriptionFactory::PostCreateSessionDescriptionSucceeded( |
472 CreateSessionDescriptionObserver* observer, | 472 CreateSessionDescriptionObserver* observer, |
473 SessionDescriptionInterface* description) { | 473 SessionDescriptionInterface* description) { |
474 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); | 474 CreateSessionDescriptionMsg* msg = new CreateSessionDescriptionMsg(observer); |
475 msg->description.reset(description); | 475 msg->description.reset(description); |
476 signaling_thread_->Post(RTC_FROM_HERE, this, | 476 signaling_thread_->Post(RTC_FROM_HERE, this, |
477 MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, msg); | 477 MSG_CREATE_SESSIONDESCRIPTION_SUCCESS, msg); |
478 } | 478 } |
479 | 479 |
480 void WebRtcSessionDescriptionFactory::OnCertificateRequestFailed() { | 480 void WebRtcSessionDescriptionFactory::OnCertificateRequestFailed() { |
481 ASSERT(signaling_thread_->IsCurrent()); | 481 RTC_DCHECK(signaling_thread_->IsCurrent()); |
482 | 482 |
483 LOG(LS_ERROR) << "Asynchronous certificate generation request failed."; | 483 LOG(LS_ERROR) << "Asynchronous certificate generation request failed."; |
484 certificate_request_state_ = CERTIFICATE_FAILED; | 484 certificate_request_state_ = CERTIFICATE_FAILED; |
485 | 485 |
486 FailPendingRequests(kFailedDueToIdentityFailed); | 486 FailPendingRequests(kFailedDueToIdentityFailed); |
487 } | 487 } |
488 | 488 |
489 void WebRtcSessionDescriptionFactory::SetCertificate( | 489 void WebRtcSessionDescriptionFactory::SetCertificate( |
490 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { | 490 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate) { |
491 RTC_DCHECK(certificate); | 491 RTC_DCHECK(certificate); |
492 LOG(LS_VERBOSE) << "Setting new certificate."; | 492 LOG(LS_VERBOSE) << "Setting new certificate."; |
493 | 493 |
494 certificate_request_state_ = CERTIFICATE_SUCCEEDED; | 494 certificate_request_state_ = CERTIFICATE_SUCCEEDED; |
495 SignalCertificateReady(certificate); | 495 SignalCertificateReady(certificate); |
496 | 496 |
497 transport_desc_factory_.set_certificate(certificate); | 497 transport_desc_factory_.set_certificate(certificate); |
498 transport_desc_factory_.set_secure(cricket::SEC_ENABLED); | 498 transport_desc_factory_.set_secure(cricket::SEC_ENABLED); |
499 | 499 |
500 while (!create_session_description_requests_.empty()) { | 500 while (!create_session_description_requests_.empty()) { |
501 if (create_session_description_requests_.front().type == | 501 if (create_session_description_requests_.front().type == |
502 CreateSessionDescriptionRequest::kOffer) { | 502 CreateSessionDescriptionRequest::kOffer) { |
503 InternalCreateOffer(create_session_description_requests_.front()); | 503 InternalCreateOffer(create_session_description_requests_.front()); |
504 } else { | 504 } else { |
505 InternalCreateAnswer(create_session_description_requests_.front()); | 505 InternalCreateAnswer(create_session_description_requests_.front()); |
506 } | 506 } |
507 create_session_description_requests_.pop(); | 507 create_session_description_requests_.pop(); |
508 } | 508 } |
509 } | 509 } |
510 } // namespace webrtc | 510 } // namespace webrtc |
OLD | NEW |