Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(128)

Side by Side Diff: webrtc/p2p/base/dtlstransportchannel.cc

Issue 2620303003: Replace ASSERT by RTC_DCHECK in all non-test code. (Closed)
Patch Set: Address final nits. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/p2p/base/candidate.h ('k') | webrtc/p2p/base/jseptransport.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2011 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 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 switch (dtls_state()) { 396 switch (dtls_state()) {
397 case DTLS_TRANSPORT_NEW: 397 case DTLS_TRANSPORT_NEW:
398 // Can't send data until the connection is active. 398 // Can't send data until the connection is active.
399 // TODO(ekr@rtfm.com): assert here if dtls_ is NULL? 399 // TODO(ekr@rtfm.com): assert here if dtls_ is NULL?
400 return -1; 400 return -1;
401 case DTLS_TRANSPORT_CONNECTING: 401 case DTLS_TRANSPORT_CONNECTING:
402 // Can't send data until the connection is active. 402 // Can't send data until the connection is active.
403 return -1; 403 return -1;
404 case DTLS_TRANSPORT_CONNECTED: 404 case DTLS_TRANSPORT_CONNECTED:
405 if (flags & PF_SRTP_BYPASS) { 405 if (flags & PF_SRTP_BYPASS) {
406 ASSERT(!srtp_ciphers_.empty()); 406 RTC_DCHECK(!srtp_ciphers_.empty());
407 if (!IsRtpPacket(data, size)) { 407 if (!IsRtpPacket(data, size)) {
408 return -1; 408 return -1;
409 } 409 }
410 410
411 return channel_->SendPacket(data, size, options); 411 return channel_->SendPacket(data, size, options);
412 } else { 412 } else {
413 return (dtls_->WriteAll(data, size, NULL, NULL) == rtc::SR_SUCCESS) 413 return (dtls_->WriteAll(data, size, NULL, NULL) == rtc::SR_SUCCESS)
414 ? static_cast<int>(size) 414 ? static_cast<int>(size)
415 : -1; 415 : -1;
416 } 416 }
(...skipping 16 matching lines...) Expand all
433 // state of the underlying impl() 433 // state of the underlying impl()
434 // (2) If we're doing DTLS-SRTP: 434 // (2) If we're doing DTLS-SRTP:
435 // - Prior to the DTLS handshake, the state is neither receiving nor 435 // - Prior to the DTLS handshake, the state is neither receiving nor
436 // writable 436 // writable
437 // - When the impl goes writable for the first time we 437 // - When the impl goes writable for the first time we
438 // start the DTLS handshake 438 // start the DTLS handshake
439 // - Once the DTLS handshake completes, the state is that of the 439 // - Once the DTLS handshake completes, the state is that of the
440 // impl again 440 // impl again
441 void DtlsTransportChannelWrapper::OnWritableState( 441 void DtlsTransportChannelWrapper::OnWritableState(
442 rtc::PacketTransportInterface* transport) { 442 rtc::PacketTransportInterface* transport) {
443 ASSERT(rtc::Thread::Current() == network_thread_); 443 RTC_DCHECK(rtc::Thread::Current() == network_thread_);
444 RTC_DCHECK(transport == channel_); 444 RTC_DCHECK(transport == channel_);
445 LOG_J(LS_VERBOSE, this) 445 LOG_J(LS_VERBOSE, this)
446 << "DTLSTransportChannelWrapper: channel writable state changed to " 446 << "DTLSTransportChannelWrapper: channel writable state changed to "
447 << channel_->writable(); 447 << channel_->writable();
448 448
449 if (!dtls_active_) { 449 if (!dtls_active_) {
450 // Not doing DTLS. 450 // Not doing DTLS.
451 // Note: SignalWritableState fired by set_writable. 451 // Note: SignalWritableState fired by set_writable.
452 set_writable(channel_->writable()); 452 set_writable(channel_->writable());
453 return; 453 return;
(...skipping 12 matching lines...) Expand all
466 break; 466 break;
467 case DTLS_TRANSPORT_FAILED: 467 case DTLS_TRANSPORT_FAILED:
468 case DTLS_TRANSPORT_CLOSED: 468 case DTLS_TRANSPORT_CLOSED:
469 // Should not happen. Do nothing. 469 // Should not happen. Do nothing.
470 break; 470 break;
471 } 471 }
472 } 472 }
473 473
474 void DtlsTransportChannelWrapper::OnReceivingState( 474 void DtlsTransportChannelWrapper::OnReceivingState(
475 rtc::PacketTransportInterface* transport) { 475 rtc::PacketTransportInterface* transport) {
476 ASSERT(rtc::Thread::Current() == network_thread_); 476 RTC_DCHECK(rtc::Thread::Current() == network_thread_);
477 RTC_DCHECK(transport == channel_); 477 RTC_DCHECK(transport == channel_);
478 LOG_J(LS_VERBOSE, this) 478 LOG_J(LS_VERBOSE, this)
479 << "DTLSTransportChannelWrapper: channel receiving state changed to " 479 << "DTLSTransportChannelWrapper: channel receiving state changed to "
480 << channel_->receiving(); 480 << channel_->receiving();
481 if (!dtls_active_ || dtls_state() == DTLS_TRANSPORT_CONNECTED) { 481 if (!dtls_active_ || dtls_state() == DTLS_TRANSPORT_CONNECTED) {
482 // Note: SignalReceivingState fired by set_receiving. 482 // Note: SignalReceivingState fired by set_receiving.
483 set_receiving(channel_->receiving()); 483 set_receiving(channel_->receiving());
484 } 484 }
485 } 485 }
486 486
487 void DtlsTransportChannelWrapper::OnReadPacket( 487 void DtlsTransportChannelWrapper::OnReadPacket(
488 rtc::PacketTransportInterface* transport, 488 rtc::PacketTransportInterface* transport,
489 const char* data, 489 const char* data,
490 size_t size, 490 size_t size,
491 const rtc::PacketTime& packet_time, 491 const rtc::PacketTime& packet_time,
492 int flags) { 492 int flags) {
493 ASSERT(rtc::Thread::Current() == network_thread_); 493 RTC_DCHECK(rtc::Thread::Current() == network_thread_);
494 RTC_DCHECK(transport == channel_); 494 RTC_DCHECK(transport == channel_);
495 ASSERT(flags == 0); 495 RTC_DCHECK(flags == 0);
496 496
497 if (!dtls_active_) { 497 if (!dtls_active_) {
498 // Not doing DTLS. 498 // Not doing DTLS.
499 SignalReadPacket(this, data, size, packet_time, 0); 499 SignalReadPacket(this, data, size, packet_time, 0);
500 return; 500 return;
501 } 501 }
502 502
503 switch (dtls_state()) { 503 switch (dtls_state()) {
504 case DTLS_TRANSPORT_NEW: 504 case DTLS_TRANSPORT_NEW:
505 if (dtls_) { 505 if (dtls_) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 return; 543 return;
544 } 544 }
545 545
546 // And it had better be a SRTP packet. 546 // And it had better be a SRTP packet.
547 if (!IsRtpPacket(data, size)) { 547 if (!IsRtpPacket(data, size)) {
548 LOG_J(LS_ERROR, this) << "Received unexpected non-DTLS packet."; 548 LOG_J(LS_ERROR, this) << "Received unexpected non-DTLS packet.";
549 return; 549 return;
550 } 550 }
551 551
552 // Sanity check. 552 // Sanity check.
553 ASSERT(!srtp_ciphers_.empty()); 553 RTC_DCHECK(!srtp_ciphers_.empty());
554 554
555 // Signal this upwards as a bypass packet. 555 // Signal this upwards as a bypass packet.
556 SignalReadPacket(this, data, size, packet_time, PF_SRTP_BYPASS); 556 SignalReadPacket(this, data, size, packet_time, PF_SRTP_BYPASS);
557 } 557 }
558 break; 558 break;
559 case DTLS_TRANSPORT_FAILED: 559 case DTLS_TRANSPORT_FAILED:
560 case DTLS_TRANSPORT_CLOSED: 560 case DTLS_TRANSPORT_CLOSED:
561 // This shouldn't be happening. Drop the packet. 561 // This shouldn't be happening. Drop the packet.
562 break; 562 break;
563 } 563 }
564 } 564 }
565 565
566 void DtlsTransportChannelWrapper::OnSentPacket( 566 void DtlsTransportChannelWrapper::OnSentPacket(
567 rtc::PacketTransportInterface* transport, 567 rtc::PacketTransportInterface* transport,
568 const rtc::SentPacket& sent_packet) { 568 const rtc::SentPacket& sent_packet) {
569 ASSERT(rtc::Thread::Current() == network_thread_); 569 RTC_DCHECK(rtc::Thread::Current() == network_thread_);
570 570
571 SignalSentPacket(this, sent_packet); 571 SignalSentPacket(this, sent_packet);
572 } 572 }
573 573
574 void DtlsTransportChannelWrapper::OnReadyToSend( 574 void DtlsTransportChannelWrapper::OnReadyToSend(
575 rtc::PacketTransportInterface* transport) { 575 rtc::PacketTransportInterface* transport) {
576 if (writable()) { 576 if (writable()) {
577 SignalReadyToSend(this); 577 SignalReadyToSend(this);
578 } 578 }
579 } 579 }
580 580
581 void DtlsTransportChannelWrapper::OnDtlsEvent(rtc::StreamInterface* dtls, 581 void DtlsTransportChannelWrapper::OnDtlsEvent(rtc::StreamInterface* dtls,
582 int sig, int err) { 582 int sig, int err) {
583 ASSERT(rtc::Thread::Current() == network_thread_); 583 RTC_DCHECK(rtc::Thread::Current() == network_thread_);
584 ASSERT(dtls == dtls_.get()); 584 RTC_DCHECK(dtls == dtls_.get());
585 if (sig & rtc::SE_OPEN) { 585 if (sig & rtc::SE_OPEN) {
586 // This is the first time. 586 // This is the first time.
587 LOG_J(LS_INFO, this) << "DTLS handshake complete."; 587 LOG_J(LS_INFO, this) << "DTLS handshake complete.";
588 if (dtls_->GetState() == rtc::SS_OPEN) { 588 if (dtls_->GetState() == rtc::SS_OPEN) {
589 // The check for OPEN shouldn't be necessary but let's make 589 // The check for OPEN shouldn't be necessary but let's make
590 // sure we don't accidentally frob the state if it's closed. 590 // sure we don't accidentally frob the state if it's closed.
591 set_dtls_state(DTLS_TRANSPORT_CONNECTED); 591 set_dtls_state(DTLS_TRANSPORT_CONNECTED);
592 set_writable(true); 592 set_writable(true);
593 } 593 }
594 } 594 }
(...skipping 10 matching lines...) Expand all
605 set_writable(false); 605 set_writable(false);
606 set_dtls_state(DTLS_TRANSPORT_CLOSED); 606 set_dtls_state(DTLS_TRANSPORT_CLOSED);
607 } else if (ret == rtc::SR_ERROR) { 607 } else if (ret == rtc::SR_ERROR) {
608 // Remote peer shut down the association with an error. 608 // Remote peer shut down the association with an error.
609 LOG_J(LS_INFO, this) << "DTLS channel error, code=" << read_error; 609 LOG_J(LS_INFO, this) << "DTLS channel error, code=" << read_error;
610 set_writable(false); 610 set_writable(false);
611 set_dtls_state(DTLS_TRANSPORT_FAILED); 611 set_dtls_state(DTLS_TRANSPORT_FAILED);
612 } 612 }
613 } 613 }
614 if (sig & rtc::SE_CLOSE) { 614 if (sig & rtc::SE_CLOSE) {
615 ASSERT(sig == rtc::SE_CLOSE); // SE_CLOSE should be by itself. 615 RTC_DCHECK(sig == rtc::SE_CLOSE); // SE_CLOSE should be by itself.
616 set_writable(false); 616 set_writable(false);
617 if (!err) { 617 if (!err) {
618 LOG_J(LS_INFO, this) << "DTLS channel closed"; 618 LOG_J(LS_INFO, this) << "DTLS channel closed";
619 set_dtls_state(DTLS_TRANSPORT_CLOSED); 619 set_dtls_state(DTLS_TRANSPORT_CLOSED);
620 } else { 620 } else {
621 LOG_J(LS_INFO, this) << "DTLS channel error, code=" << err; 621 LOG_J(LS_INFO, this) << "DTLS channel error, code=" << err;
622 set_dtls_state(DTLS_TRANSPORT_FAILED); 622 set_dtls_state(DTLS_TRANSPORT_FAILED);
623 } 623 }
624 } 624 }
625 } 625 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 tmp_size -= record_len + kDtlsRecordHeaderLen; 678 tmp_size -= record_len + kDtlsRecordHeaderLen;
679 } 679 }
680 680
681 // Looks good. Pass to the SIC which ends up being passed to 681 // Looks good. Pass to the SIC which ends up being passed to
682 // the DTLS stack. 682 // the DTLS stack.
683 return downward_->OnPacketReceived(data, size); 683 return downward_->OnPacketReceived(data, size);
684 } 684 }
685 685
686 void DtlsTransportChannelWrapper::OnGatheringState( 686 void DtlsTransportChannelWrapper::OnGatheringState(
687 TransportChannelImpl* channel) { 687 TransportChannelImpl* channel) {
688 ASSERT(channel == channel_); 688 RTC_DCHECK(channel == channel_);
689 SignalGatheringState(this); 689 SignalGatheringState(this);
690 } 690 }
691 691
692 void DtlsTransportChannelWrapper::OnCandidateGathered( 692 void DtlsTransportChannelWrapper::OnCandidateGathered(
693 TransportChannelImpl* channel, 693 TransportChannelImpl* channel,
694 const Candidate& c) { 694 const Candidate& c) {
695 ASSERT(channel == channel_); 695 RTC_DCHECK(channel == channel_);
696 SignalCandidateGathered(this, c); 696 SignalCandidateGathered(this, c);
697 } 697 }
698 698
699 void DtlsTransportChannelWrapper::OnCandidatesRemoved( 699 void DtlsTransportChannelWrapper::OnCandidatesRemoved(
700 TransportChannelImpl* channel, 700 TransportChannelImpl* channel,
701 const Candidates& candidates) { 701 const Candidates& candidates) {
702 ASSERT(channel == channel_); 702 RTC_DCHECK(channel == channel_);
703 SignalCandidatesRemoved(this, candidates); 703 SignalCandidatesRemoved(this, candidates);
704 } 704 }
705 705
706 void DtlsTransportChannelWrapper::OnRoleConflict( 706 void DtlsTransportChannelWrapper::OnRoleConflict(
707 TransportChannelImpl* channel) { 707 TransportChannelImpl* channel) {
708 ASSERT(channel == channel_); 708 RTC_DCHECK(channel == channel_);
709 SignalRoleConflict(this); 709 SignalRoleConflict(this);
710 } 710 }
711 711
712 void DtlsTransportChannelWrapper::OnRouteChange( 712 void DtlsTransportChannelWrapper::OnRouteChange(
713 TransportChannel* channel, const Candidate& candidate) { 713 TransportChannel* channel, const Candidate& candidate) {
714 ASSERT(channel == channel_); 714 RTC_DCHECK(channel == channel_);
715 SignalRouteChange(this, candidate); 715 SignalRouteChange(this, candidate);
716 } 716 }
717 717
718 void DtlsTransportChannelWrapper::OnSelectedCandidatePairChanged( 718 void DtlsTransportChannelWrapper::OnSelectedCandidatePairChanged(
719 TransportChannel* channel, 719 TransportChannel* channel,
720 CandidatePairInterface* selected_candidate_pair, 720 CandidatePairInterface* selected_candidate_pair,
721 int last_sent_packet_id, 721 int last_sent_packet_id,
722 bool ready_to_send) { 722 bool ready_to_send) {
723 ASSERT(channel == channel_); 723 RTC_DCHECK(channel == channel_);
724 SignalSelectedCandidatePairChanged(this, selected_candidate_pair, 724 SignalSelectedCandidatePairChanged(this, selected_candidate_pair,
725 last_sent_packet_id, ready_to_send); 725 last_sent_packet_id, ready_to_send);
726 } 726 }
727 727
728 void DtlsTransportChannelWrapper::OnChannelStateChanged( 728 void DtlsTransportChannelWrapper::OnChannelStateChanged(
729 TransportChannelImpl* channel) { 729 TransportChannelImpl* channel) {
730 ASSERT(channel == channel_); 730 RTC_DCHECK(channel == channel_);
731 SignalStateChanged(this); 731 SignalStateChanged(this);
732 } 732 }
733 733
734 void DtlsTransportChannelWrapper::OnDtlsHandshakeError( 734 void DtlsTransportChannelWrapper::OnDtlsHandshakeError(
735 rtc::SSLHandshakeError error) { 735 rtc::SSLHandshakeError error) {
736 SignalDtlsHandshakeError(error); 736 SignalDtlsHandshakeError(error);
737 } 737 }
738 738
739 } // namespace cricket 739 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/p2p/base/candidate.h ('k') | webrtc/p2p/base/jseptransport.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698