Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2009 Google Inc. | 3 * Copyright 2009 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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 return true; | 474 return true; |
| 475 } | 475 } |
| 476 | 476 |
| 477 /////////////////////////////////////////////////////////////////////////////// | 477 /////////////////////////////////////////////////////////////////////////////// |
| 478 // SrtpSession | 478 // SrtpSession |
| 479 | 479 |
| 480 #ifdef HAVE_SRTP | 480 #ifdef HAVE_SRTP |
| 481 | 481 |
| 482 bool SrtpSession::inited_ = false; | 482 bool SrtpSession::inited_ = false; |
| 483 | 483 |
| 484 // This lock protects SrtpSession::inited_ and SrtpSession::sessions_. | 484 // This lock protects SrtpSession::inited_. |
| 485 rtc::GlobalLockPod SrtpSession::lock_; | 485 rtc::GlobalLockPod SrtpSession::lock_; |
| 486 | 486 |
| 487 SrtpSession::SrtpSession() | 487 SrtpSession::SrtpSession() |
| 488 : session_(NULL), | 488 : session_(NULL), |
| 489 rtp_auth_tag_len_(0), | 489 rtp_auth_tag_len_(0), |
| 490 rtcp_auth_tag_len_(0), | 490 rtcp_auth_tag_len_(0), |
| 491 srtp_stat_(new SrtpStat()), | 491 srtp_stat_(new SrtpStat()), |
| 492 last_send_seq_num_(-1) { | 492 last_send_seq_num_(-1) { |
| 493 { | |
| 494 rtc::GlobalLockScope ls(&lock_); | |
| 495 sessions()->push_back(this); | |
| 496 } | |
| 497 SignalSrtpError.repeat(srtp_stat_->SignalSrtpError); | 493 SignalSrtpError.repeat(srtp_stat_->SignalSrtpError); |
| 498 } | 494 } |
| 499 | 495 |
| 500 SrtpSession::~SrtpSession() { | 496 SrtpSession::~SrtpSession() { |
| 501 { | |
| 502 rtc::GlobalLockScope ls(&lock_); | |
| 503 sessions()->erase(std::find(sessions()->begin(), sessions()->end(), this)); | |
| 504 } | |
| 505 if (session_) { | 497 if (session_) { |
| 498 session_->user_data = nullptr; | |
| 506 srtp_dealloc(session_); | 499 srtp_dealloc(session_); |
| 507 } | 500 } |
| 508 } | 501 } |
| 509 | 502 |
| 510 bool SrtpSession::SetSend(const std::string& cs, const uint8_t* key, int len) { | 503 bool SrtpSession::SetSend(const std::string& cs, const uint8_t* key, int len) { |
| 511 return SetKey(ssrc_any_outbound, cs, key, len); | 504 return SetKey(ssrc_any_outbound, cs, key, len); |
| 512 } | 505 } |
| 513 | 506 |
| 514 bool SrtpSession::SetRecv(const std::string& cs, const uint8_t* key, int len) { | 507 bool SrtpSession::SetRecv(const std::string& cs, const uint8_t* key, int len) { |
| 515 return SetKey(ssrc_any_inbound, cs, key, len); | 508 return SetKey(ssrc_any_inbound, cs, key, len); |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 #endif | 703 #endif |
| 711 policy.next = NULL; | 704 policy.next = NULL; |
| 712 | 705 |
| 713 int err = srtp_create(&session_, &policy); | 706 int err = srtp_create(&session_, &policy); |
| 714 if (err != err_status_ok) { | 707 if (err != err_status_ok) { |
| 715 session_ = NULL; | 708 session_ = NULL; |
| 716 LOG(LS_ERROR) << "Failed to create SRTP session, err=" << err; | 709 LOG(LS_ERROR) << "Failed to create SRTP session, err=" << err; |
| 717 return false; | 710 return false; |
| 718 } | 711 } |
| 719 | 712 |
| 720 | 713 session_->user_data = this; |
| 721 rtp_auth_tag_len_ = policy.rtp.auth_tag_len; | 714 rtp_auth_tag_len_ = policy.rtp.auth_tag_len; |
| 722 rtcp_auth_tag_len_ = policy.rtcp.auth_tag_len; | 715 rtcp_auth_tag_len_ = policy.rtcp.auth_tag_len; |
| 723 return true; | 716 return true; |
| 724 } | 717 } |
| 725 | 718 |
| 726 bool SrtpSession::Init() { | 719 bool SrtpSession::Init() { |
| 727 rtc::GlobalLockScope ls(&lock_); | 720 rtc::GlobalLockScope ls(&lock_); |
| 728 | 721 |
| 729 if (!inited_) { | 722 if (!inited_) { |
| 730 int err; | 723 int err; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 779 case event_packet_index_limit: | 772 case event_packet_index_limit: |
| 780 LOG(LS_INFO) << "SRTP event: reached hard packet limit (2^48 packets)"; | 773 LOG(LS_INFO) << "SRTP event: reached hard packet limit (2^48 packets)"; |
| 781 break; | 774 break; |
| 782 default: | 775 default: |
| 783 LOG(LS_INFO) << "SRTP event: unknown " << ev->event; | 776 LOG(LS_INFO) << "SRTP event: unknown " << ev->event; |
| 784 break; | 777 break; |
| 785 } | 778 } |
| 786 } | 779 } |
| 787 | 780 |
| 788 void SrtpSession::HandleEventThunk(srtp_event_data_t* ev) { | 781 void SrtpSession::HandleEventThunk(srtp_event_data_t* ev) { |
| 789 rtc::GlobalLockScope ls(&lock_); | 782 SrtpSession* session = static_cast<SrtpSession*>(ev->session->user_data); |
|
juberti
2015/11/10 01:25:59
Do we know what thread this gets invoked from? Wou
joachim
2015/11/10 16:59:56
Done.
| |
| 790 | 783 if (session) { |
| 791 for (std::list<SrtpSession*>::iterator it = sessions()->begin(); | 784 session->HandleEvent(ev); |
| 792 it != sessions()->end(); ++it) { | |
| 793 if ((*it)->session_ == ev->session) { | |
| 794 (*it)->HandleEvent(ev); | |
| 795 break; | |
| 796 } | |
| 797 } | 785 } |
| 798 } | 786 } |
| 799 | 787 |
| 800 std::list<SrtpSession*>* SrtpSession::sessions() { | |
| 801 RTC_DEFINE_STATIC_LOCAL(std::list<SrtpSession*>, sessions, ()); | |
| 802 return &sessions; | |
| 803 } | |
| 804 | |
| 805 #else // !HAVE_SRTP | 788 #else // !HAVE_SRTP |
| 806 | 789 |
| 807 // On some systems, SRTP is not (yet) available. | 790 // On some systems, SRTP is not (yet) available. |
| 808 | 791 |
| 809 SrtpSession::SrtpSession() { | 792 SrtpSession::SrtpSession() { |
| 810 LOG(WARNING) << "SRTP implementation is missing."; | 793 LOG(WARNING) << "SRTP implementation is missing."; |
| 811 } | 794 } |
| 812 | 795 |
| 813 SrtpSession::~SrtpSession() { | 796 SrtpSession::~SrtpSession() { |
| 814 } | 797 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 942 SrtpNotAvailable(__FUNCTION__); | 925 SrtpNotAvailable(__FUNCTION__); |
| 943 } | 926 } |
| 944 | 927 |
| 945 void SrtpStat::HandleSrtpResult(const SrtpStat::FailureKey& key) { | 928 void SrtpStat::HandleSrtpResult(const SrtpStat::FailureKey& key) { |
| 946 SrtpNotAvailable(__FUNCTION__); | 929 SrtpNotAvailable(__FUNCTION__); |
| 947 } | 930 } |
| 948 | 931 |
| 949 #endif // HAVE_SRTP | 932 #endif // HAVE_SRTP |
| 950 | 933 |
| 951 } // namespace cricket | 934 } // namespace cricket |
| OLD | NEW |