From af99b6d67af95615c8fc2f6dbea20983dd14385d Mon Sep 17 00:00:00 2001 From: nisse Date: Fri, 16 Jun 2017 00:57:21 -0700 Subject: [PATCH] Delete SignalSrtpError. This became unused with cl https://codereview.webrtc.org/1362913004. BUG=webrtc:4690,webrtc:6424 Review-Url: https://codereview.webrtc.org/2938013003 Cr-Commit-Position: refs/heads/master@{#18623} --- webrtc/base/BUILD.gn | 1 - webrtc/base/sigslotrepeater.h | 94 ----------------- webrtc/media/base/mediaengine.h | 1 - webrtc/pc/channel_unittest.cc | 104 ------------------- webrtc/pc/srtpfilter.cc | 111 +------------------- webrtc/pc/srtpfilter.h | 87 ---------------- webrtc/pc/srtpfilter_unittest.cc | 169 ------------------------------- 7 files changed, 1 insertion(+), 566 deletions(-) delete mode 100644 webrtc/base/sigslotrepeater.h diff --git a/webrtc/base/BUILD.gn b/webrtc/base/BUILD.gn index 10bf763296..1eecc86627 100644 --- a/webrtc/base/BUILD.gn +++ b/webrtc/base/BUILD.gn @@ -483,7 +483,6 @@ rtc_static_library("rtc_base") { "signalthread.h", "sigslot.cc", "sigslot.h", - "sigslotrepeater.h", "socket.h", "socketadapters.cc", "socketadapters.h", diff --git a/webrtc/base/sigslotrepeater.h b/webrtc/base/sigslotrepeater.h deleted file mode 100644 index d1c891e026..0000000000 --- a/webrtc/base/sigslotrepeater.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2006 The WebRTC Project Authors. All rights reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef WEBRTC_BASE_SIGSLOTREPEATER_H__ -#define WEBRTC_BASE_SIGSLOTREPEATER_H__ - -// repeaters are both signals and slots, which are designed as intermediate -// pass-throughs for signals and slots which don't know about each other (for -// modularity or encapsulation). This eliminates the need to declare a signal -// handler whose sole purpose is to fire another signal. The repeater connects -// to the originating signal using the 'repeat' method. When the repeated -// signal fires, the repeater will also fire. - -#include "webrtc/base/sigslot.h" - -namespace sigslot { - - template - class repeater0 : public signal0, - public has_slots - { - public: - typedef signal0 base_type; - typedef repeater0 this_type; - - repeater0() { } - repeater0(const this_type& s) : base_type(s) { } - - void reemit() { signal0::emit(); } - void repeat(base_type &s) { s.connect(this, &this_type::reemit); } - void stop(base_type &s) { s.disconnect(this); } - }; - - template - class repeater1 : public signal1, - public has_slots - { - public: - typedef signal1 base_type; - typedef repeater1 this_type; - - repeater1() { } - repeater1(const this_type& s) : base_type(s) { } - - void reemit(arg1_type a1) { signal1::emit(a1); } - void repeat(base_type& s) { s.connect(this, &this_type::reemit); } - void stop(base_type &s) { s.disconnect(this); } - }; - - template - class repeater2 : public signal2, - public has_slots - { - public: - typedef signal2 base_type; - typedef repeater2 this_type; - - repeater2() { } - repeater2(const this_type& s) : base_type(s) { } - - void reemit(arg1_type a1, arg2_type a2) { signal2::emit(a1,a2); } - void repeat(base_type& s) { s.connect(this, &this_type::reemit); } - void stop(base_type &s) { s.disconnect(this); } - }; - - template - class repeater3 : public signal3, - public has_slots - { - public: - typedef signal3 base_type; - typedef repeater3 this_type; - - repeater3() { } - repeater3(const this_type& s) : base_type(s) { } - - void reemit(arg1_type a1, arg2_type a2, arg3_type a3) { - signal3::emit(a1,a2,a3); - } - void repeat(base_type& s) { s.connect(this, &this_type::reemit); } - void stop(base_type &s) { s.disconnect(this); } - }; - -} // namespace sigslot - -#endif // WEBRTC_BASE_SIGSLOTREPEATER_H__ diff --git a/webrtc/media/base/mediaengine.h b/webrtc/media/base/mediaengine.h index ca704ce242..ea9ef9964c 100644 --- a/webrtc/media/base/mediaengine.h +++ b/webrtc/media/base/mediaengine.h @@ -22,7 +22,6 @@ #include "webrtc/api/audio_codecs/audio_encoder_factory.h" #include "webrtc/api/rtpparameters.h" #include "webrtc/base/fileutils.h" -#include "webrtc/base/sigslotrepeater.h" #include "webrtc/call/audio_state.h" #include "webrtc/media/base/codec.h" #include "webrtc/media/base/mediachannel.h" diff --git a/webrtc/pc/channel_unittest.cc b/webrtc/pc/channel_unittest.cc index a351e17dfc..cb7d318982 100644 --- a/webrtc/pc/channel_unittest.cc +++ b/webrtc/pc/channel_unittest.cc @@ -1756,94 +1756,6 @@ class ChannelTest : public testing::Test, public sigslot::has_slots<> { EXPECT_TRUE(CheckRtcp2()); } - void TestSrtpError(int pl_type) { - struct SrtpErrorHandler : public sigslot::has_slots<> { - SrtpErrorHandler() : - mode_(cricket::SrtpFilter::UNPROTECT), - error_(cricket::SrtpFilter::ERROR_NONE) {} - void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode, - cricket::SrtpFilter::Error error) { - mode_ = mode; - error_ = error; - } - cricket::SrtpFilter::Mode mode_; - cricket::SrtpFilter::Error error_; - } error_handler; - - // For Audio, only pl_type 0 is added to the bundle filter. - // For Video, only pl_type 97 is added to the bundle filter. - // So we need to pass in pl_type so that the packet can pass through - // the bundle filter before it can be processed by the srtp filter. - // The packet is not a valid srtp packet because it is too short. - static unsigned const char kBadPacket[] = { - 0x84, static_cast(pl_type), - 0x00, 0x01, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x00, - 0x00, 0x01}; - - // Using fake clock because this tests that SRTP errors are signaled at - // specific times based on set_signal_silent_time. - rtc::ScopedFakeClock fake_clock; - - CreateChannels(SECURE, SECURE); - // Some code uses a time of 0 as a special value, so we must start with - // a non-zero time. - // TODO(deadbeef): Fix this. - fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1)); - - EXPECT_FALSE(channel1_->secure()); - EXPECT_FALSE(channel2_->secure()); - EXPECT_TRUE(SendInitiate()); - EXPECT_TRUE(SendAccept()); - EXPECT_TRUE(channel1_->secure()); - EXPECT_TRUE(channel2_->secure()); - channel2_->srtp_filter()->set_signal_silent_time(250); - channel2_->srtp_filter()->SignalSrtpError.connect( - &error_handler, &SrtpErrorHandler::OnSrtpError); - - // Testing failures in sending packets. - media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket), - rtc::PacketOptions()); - WaitForThreads(); - // The first failure will trigger an error. - EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_); - EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_); - error_handler.error_ = cricket::SrtpFilter::ERROR_NONE; - error_handler.mode_ = cricket::SrtpFilter::UNPROTECT; - // The next 250 ms failures will not trigger an error. - media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket), - rtc::PacketOptions()); - // Wait for a while to ensure no message comes in. - WaitForThreads(); - fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200)); - EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_); - EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_); - // Wait for a little more - the error will be triggered again. - fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200)); - media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket), - rtc::PacketOptions()); - WaitForThreads(); - EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_); - EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_); - - // Testing failures in receiving packets. - error_handler.error_ = cricket::SrtpFilter::ERROR_NONE; - error_handler.mode_ = cricket::SrtpFilter::UNPROTECT; - - network_thread_->Invoke(RTC_FROM_HERE, [this] { - fake_rtp_dtls_transport2_->SignalReadPacket( - fake_rtp_dtls_transport2_.get(), - reinterpret_cast(kBadPacket), sizeof(kBadPacket), - rtc::PacketTime(), 0); - }); - EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_); - EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_); - // Terminate channels/threads before the fake clock is destroyed. - EXPECT_TRUE(Terminate()); - } - void TestOnTransportReadyToSend() { CreateChannels(0, 0); EXPECT_FALSE(media_channel1_->ready_to_send()); @@ -2355,10 +2267,6 @@ TEST_F(VoiceChannelSingleThreadTest, TestFlushRtcp) { Base::TestFlushRtcp(); } -TEST_F(VoiceChannelSingleThreadTest, TestSrtpError) { - Base::TestSrtpError(kAudioPts[0]); -} - TEST_F(VoiceChannelSingleThreadTest, TestOnTransportReadyToSend) { Base::TestOnTransportReadyToSend(); } @@ -2676,10 +2584,6 @@ TEST_F(VoiceChannelDoubleThreadTest, TestFlushRtcp) { Base::TestFlushRtcp(); } -TEST_F(VoiceChannelDoubleThreadTest, TestSrtpError) { - Base::TestSrtpError(kAudioPts[0]); -} - TEST_F(VoiceChannelDoubleThreadTest, TestOnTransportReadyToSend) { Base::TestOnTransportReadyToSend(); } @@ -2989,10 +2893,6 @@ TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) { Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true); } -TEST_F(VideoChannelSingleThreadTest, TestSrtpError) { - Base::TestSrtpError(kVideoPts[0]); -} - TEST_F(VideoChannelSingleThreadTest, TestOnTransportReadyToSend) { Base::TestOnTransportReadyToSend(); } @@ -3224,10 +3124,6 @@ TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) { Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true); } -TEST_F(VideoChannelDoubleThreadTest, TestSrtpError) { - Base::TestSrtpError(kVideoPts[0]); -} - TEST_F(VideoChannelDoubleThreadTest, TestOnTransportReadyToSend) { Base::TestOnTransportReadyToSend(); } diff --git a/webrtc/pc/srtpfilter.cc b/webrtc/pc/srtpfilter.cc index f8537f3dd6..5494105103 100644 --- a/webrtc/pc/srtpfilter.cc +++ b/webrtc/pc/srtpfilter.cc @@ -113,14 +113,10 @@ bool SrtpFilter::SetRtcpParams(int send_cs, } send_rtcp_session_.reset(new SrtpSession()); - SignalSrtpError.repeat(send_rtcp_session_->SignalSrtpError); - send_rtcp_session_->set_signal_silent_time(signal_silent_time_in_ms_); if (!send_rtcp_session_->SetRecv(send_cs, send_key, send_key_len)) return false; recv_rtcp_session_.reset(new SrtpSession()); - SignalSrtpError.repeat(recv_rtcp_session_->SignalSrtpError); - recv_rtcp_session_->set_signal_silent_time(signal_silent_time_in_ms_); if (!recv_rtcp_session_->SetRecv(recv_cs, recv_key, recv_key_len)) return false; @@ -228,20 +224,6 @@ bool SrtpFilter::IsExternalAuthActive() const { return send_session_->IsExternalAuthActive(); } -void SrtpFilter::set_signal_silent_time(int signal_silent_time_in_ms) { - signal_silent_time_in_ms_ = signal_silent_time_in_ms; - if (IsActive()) { - RTC_CHECK(send_session_); - send_session_->set_signal_silent_time(signal_silent_time_in_ms); - RTC_CHECK(recv_session_); - recv_session_->set_signal_silent_time(signal_silent_time_in_ms); - if (send_rtcp_session_) - send_rtcp_session_->set_signal_silent_time(signal_silent_time_in_ms); - if (recv_rtcp_session_) - recv_rtcp_session_->set_signal_silent_time(signal_silent_time_in_ms); - } -} - bool SrtpFilter::ExpectOffer(ContentSource source) { return ((state_ == ST_INIT) || (state_ == ST_ACTIVE) || @@ -323,11 +305,6 @@ void SrtpFilter::CreateSrtpSessions() { recv_session_.reset(new SrtpSession()); applied_recv_params_ = CryptoParams(); - SignalSrtpError.repeat(send_session_->SignalSrtpError); - SignalSrtpError.repeat(recv_session_->SignalSrtpError); - - send_session_->set_signal_silent_time(signal_silent_time_in_ms_); - recv_session_->set_signal_silent_time(signal_silent_time_in_ms_); if (external_auth_enabled_) { send_session_->EnableExternalAuth(); } @@ -466,9 +443,7 @@ bool SrtpSession::inited_ = false; // This lock protects SrtpSession::inited_. rtc::GlobalLockPod SrtpSession::lock_; -SrtpSession::SrtpSession() : srtp_stat_(new SrtpStat()) { - SignalSrtpError.repeat(srtp_stat_->SignalSrtpError); -} +SrtpSession::SrtpSession() {} SrtpSession::~SrtpSession() { if (session_) { @@ -501,10 +476,6 @@ bool SrtpSession::ProtectRtp(void* p, int in_len, int max_len, int* out_len) { *out_len = in_len; int err = srtp_protect(session_, p, out_len); - uint32_t ssrc; - if (GetRtpSsrc(p, in_len, &ssrc)) { - srtp_stat_->AddProtectRtpResult(ssrc, err); - } int seq_num; GetRtpSeqNum(p, in_len, &seq_num); if (err != srtp_err_status_ok) { @@ -544,7 +515,6 @@ bool SrtpSession::ProtectRtcp(void* p, int in_len, int max_len, int* out_len) { *out_len = in_len; int err = srtp_protect_rtcp(session_, p, out_len); - srtp_stat_->AddProtectRtcpResult(err); if (err != srtp_err_status_ok) { LOG(LS_WARNING) << "Failed to protect SRTCP packet, err=" << err; return false; @@ -561,10 +531,6 @@ bool SrtpSession::UnprotectRtp(void* p, int in_len, int* out_len) { *out_len = in_len; int err = srtp_unprotect(session_, p, out_len); - uint32_t ssrc; - if (GetRtpSsrc(p, in_len, &ssrc)) { - srtp_stat_->AddUnprotectRtpResult(ssrc, err); - } if (err != srtp_err_status_ok) { LOG(LS_WARNING) << "Failed to unprotect SRTP packet, err=" << err; return false; @@ -581,7 +547,6 @@ bool SrtpSession::UnprotectRtcp(void* p, int in_len, int* out_len) { *out_len = in_len; int err = srtp_unprotect_rtcp(session_, p, out_len); - srtp_stat_->AddUnprotectRtcpResult(err); if (err != srtp_err_status_ok) { LOG(LS_WARNING) << "Failed to unprotect SRTCP packet, err=" << err; return false; @@ -650,10 +615,6 @@ bool SrtpSession::GetSendStreamPacketIndex(void* p, return true; } -void SrtpSession::set_signal_silent_time(int signal_silent_time_in_ms) { - srtp_stat_->set_signal_silent_time(signal_silent_time_in_ms); -} - bool SrtpSession::SetKey(int type, int cs, const uint8_t* key, size_t len) { RTC_DCHECK(thread_checker_.CalledOnValidThread()); if (session_) { @@ -807,74 +768,4 @@ void SrtpSession::HandleEventThunk(srtp_event_data_t* ev) { } } -/////////////////////////////////////////////////////////////////////////////// -// SrtpStat - -SrtpStat::SrtpStat() - : signal_silent_time_(1000) { -} - -void SrtpStat::AddProtectRtpResult(uint32_t ssrc, int result) { - FailureKey key; - key.ssrc = ssrc; - key.mode = SrtpFilter::PROTECT; - switch (result) { - case srtp_err_status_ok: - key.error = SrtpFilter::ERROR_NONE; - break; - case srtp_err_status_auth_fail: - key.error = SrtpFilter::ERROR_AUTH; - break; - default: - key.error = SrtpFilter::ERROR_FAIL; - } - HandleSrtpResult(key); -} - -void SrtpStat::AddUnprotectRtpResult(uint32_t ssrc, int result) { - FailureKey key; - key.ssrc = ssrc; - key.mode = SrtpFilter::UNPROTECT; - switch (result) { - case srtp_err_status_ok: - key.error = SrtpFilter::ERROR_NONE; - break; - case srtp_err_status_auth_fail: - key.error = SrtpFilter::ERROR_AUTH; - break; - case srtp_err_status_replay_fail: - case srtp_err_status_replay_old: - key.error = SrtpFilter::ERROR_REPLAY; - break; - default: - key.error = SrtpFilter::ERROR_FAIL; - } - HandleSrtpResult(key); -} - -void SrtpStat::AddProtectRtcpResult(int result) { - AddProtectRtpResult(0U, result); -} - -void SrtpStat::AddUnprotectRtcpResult(int result) { - AddUnprotectRtpResult(0U, result); -} - -void SrtpStat::HandleSrtpResult(const SrtpStat::FailureKey& key) { - // Handle some cases where error should be signalled right away. For other - // errors, trigger error for the first time seeing it. After that, silent - // the same error for a certain amount of time (default 1 sec). - if (key.error != SrtpFilter::ERROR_NONE) { - // For errors, signal first time and wait for 1 sec. - FailureStat* stat = &(failures_[key]); - int64_t current_time = rtc::TimeMillis(); - if (stat->last_signal_time == 0 || - rtc::TimeDiff(current_time, stat->last_signal_time) > - signal_silent_time_) { - SignalSrtpError(key.ssrc, key.mode, key.error); - stat->last_signal_time = current_time; - } - } -} - } // namespace cricket diff --git a/webrtc/pc/srtpfilter.h b/webrtc/pc/srtpfilter.h index 3df787646c..18a2f6774f 100644 --- a/webrtc/pc/srtpfilter.h +++ b/webrtc/pc/srtpfilter.h @@ -20,7 +20,6 @@ #include "webrtc/base/basictypes.h" #include "webrtc/base/constructormagic.h" #include "webrtc/base/criticalsection.h" -#include "webrtc/base/sigslotrepeater.h" #include "webrtc/base/sslstreamadapter.h" #include "webrtc/base/thread_checker.h" #include "webrtc/media/base/cryptoparams.h" @@ -33,7 +32,6 @@ struct srtp_ctx_t_; namespace cricket { class SrtpSession; -class SrtpStat; void ShutdownSrtp(); @@ -127,13 +125,8 @@ class SrtpFilter { // been set. bool IsExternalAuthActive() const; - // Update the silent threshold (in ms) for signaling errors. - void set_signal_silent_time(int signal_silent_time_in_ms); - bool ResetParams(); - sigslot::repeater3 SignalSrtpError; - protected: bool ExpectOffer(ContentSource source); bool StoreParams(const std::vector& params, @@ -176,7 +169,6 @@ class SrtpFilter { ST_RECEIVEDPRANSWER }; State state_ = ST_INIT; - int signal_silent_time_in_ms_ = 0; bool external_auth_enabled_ = false; std::vector offer_params_; std::unique_ptr send_session_; @@ -233,15 +225,9 @@ class SrtpSession { // been set. bool IsExternalAuthActive() const; - // Update the silent threshold (in ms) for signaling errors. - void set_signal_silent_time(int signal_silent_time_in_ms); - // Calls srtp_shutdown if it's initialized. static void Terminate(); - sigslot::repeater3 - SignalSrtpError; - private: bool SetKey(int type, int cs, const uint8_t* key, size_t len); // Returns send stream current packet index from srtp db. @@ -255,7 +241,6 @@ class SrtpSession { srtp_ctx_t_* session_ = nullptr; int rtp_auth_tag_len_ = 0; int rtcp_auth_tag_len_ = 0; - std::unique_ptr srtp_stat_; static bool inited_; static rtc::GlobalLockPod lock_; int last_send_seq_num_ = -1; @@ -264,78 +249,6 @@ class SrtpSession { RTC_DISALLOW_COPY_AND_ASSIGN(SrtpSession); }; -// Class that collects failures of SRTP. -class SrtpStat { - public: - SrtpStat(); - - // Report RTP protection results to the handler. - void AddProtectRtpResult(uint32_t ssrc, int result); - // Report RTP unprotection results to the handler. - void AddUnprotectRtpResult(uint32_t ssrc, int result); - // Report RTCP protection results to the handler. - void AddProtectRtcpResult(int result); - // Report RTCP unprotection results to the handler. - void AddUnprotectRtcpResult(int result); - - // Get silent time (in ms) for SRTP statistics handler. - int signal_silent_time() const { return signal_silent_time_; } - // Set silent time (in ms) for SRTP statistics handler. - void set_signal_silent_time(int signal_silent_time) { - signal_silent_time_ = signal_silent_time; - } - - // Sigslot for reporting errors. - sigslot::signal3 - SignalSrtpError; - - private: - // For each different ssrc and error, we collect statistics separately. - struct FailureKey { - FailureKey() - : ssrc(0), - mode(SrtpFilter::PROTECT), - error(SrtpFilter::ERROR_NONE) { - } - FailureKey(uint32_t in_ssrc, - SrtpFilter::Mode in_mode, - SrtpFilter::Error in_error) - : ssrc(in_ssrc), mode(in_mode), error(in_error) {} - bool operator <(const FailureKey& key) const { - return - (ssrc < key.ssrc) || - (ssrc == key.ssrc && mode < key.mode) || - (ssrc == key.ssrc && mode == key.mode && error < key.error); - } - uint32_t ssrc; - SrtpFilter::Mode mode; - SrtpFilter::Error error; - }; - // For tracing conditions for signaling, currently we only use - // last_signal_time. Wrap this as a struct so that later on, if we need any - // other improvements, it will be easier. - struct FailureStat { - FailureStat() - : last_signal_time(0) { - } - explicit FailureStat(uint32_t in_last_signal_time) - : last_signal_time(in_last_signal_time) {} - void Reset() { - last_signal_time = 0; - } - int64_t last_signal_time; - }; - - // Inspect SRTP result and signal error if needed. - void HandleSrtpResult(const FailureKey& key); - - std::map failures_; - // Threshold in ms to silent the signaling errors. - int signal_silent_time_; - - RTC_DISALLOW_COPY_AND_ASSIGN(SrtpStat); -}; - } // namespace cricket #endif // WEBRTC_PC_SRTPFILTER_H_ diff --git a/webrtc/pc/srtpfilter_unittest.cc b/webrtc/pc/srtpfilter_unittest.cc index af8b69f73e..ec79b90aa1 100644 --- a/webrtc/pc/srtpfilter_unittest.cc +++ b/webrtc/pc/srtpfilter_unittest.cc @@ -841,172 +841,3 @@ TEST_F(SrtpSessionTest, TestReplay) { EXPECT_TRUE(s1_.ProtectRtp(rtp_packet_, rtp_len_, sizeof(rtp_packet_), &out_len)); } - -class SrtpStatTest - : public testing::Test, - public sigslot::has_slots<> { - public: - SrtpStatTest() - : ssrc_(0U), - mode_(-1), - error_(cricket::SrtpFilter::ERROR_NONE) { - srtp_stat_.SignalSrtpError.connect(this, &SrtpStatTest::OnSrtpError); - srtp_stat_.set_signal_silent_time(200); - } - - protected: - void OnSrtpError(uint32_t ssrc, - cricket::SrtpFilter::Mode mode, - cricket::SrtpFilter::Error error) { - ssrc_ = ssrc; - mode_ = mode; - error_ = error; - } - void Reset() { - ssrc_ = 0U; - mode_ = -1; - error_ = cricket::SrtpFilter::ERROR_NONE; - } - - cricket::SrtpStat srtp_stat_; - uint32_t ssrc_; - int mode_; - cricket::SrtpFilter::Error error_; - - private: - RTC_DISALLOW_COPY_AND_ASSIGN(SrtpStatTest); -}; - -TEST_F(SrtpStatTest, TestProtectRtpError) { - Reset(); - srtp_stat_.AddProtectRtpResult(1, srtp_err_status_ok); - EXPECT_EQ(0U, ssrc_); - EXPECT_EQ(-1, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_); - Reset(); - srtp_stat_.AddProtectRtpResult(1, srtp_err_status_auth_fail); - EXPECT_EQ(1U, ssrc_); - EXPECT_EQ(cricket::SrtpFilter::PROTECT, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_AUTH, error_); - Reset(); - srtp_stat_.AddProtectRtpResult(1, srtp_err_status_fail); - EXPECT_EQ(1U, ssrc_); - EXPECT_EQ(cricket::SrtpFilter::PROTECT, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_); - // Within 200ms, the error will not be triggered. - Reset(); - srtp_stat_.AddProtectRtpResult(1, srtp_err_status_fail); - EXPECT_EQ(0U, ssrc_); - EXPECT_EQ(-1, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_); - // Now the error will be triggered again. - Reset(); - rtc::Thread::Current()->SleepMs(210); - srtp_stat_.AddProtectRtpResult(1, srtp_err_status_fail); - EXPECT_EQ(1U, ssrc_); - EXPECT_EQ(cricket::SrtpFilter::PROTECT, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_); -} - -TEST_F(SrtpStatTest, TestUnprotectRtpError) { - Reset(); - srtp_stat_.AddUnprotectRtpResult(1, srtp_err_status_ok); - EXPECT_EQ(0U, ssrc_); - EXPECT_EQ(-1, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_); - Reset(); - srtp_stat_.AddUnprotectRtpResult(1, srtp_err_status_auth_fail); - EXPECT_EQ(1U, ssrc_); - EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_AUTH, error_); - Reset(); - srtp_stat_.AddUnprotectRtpResult(1, srtp_err_status_replay_fail); - EXPECT_EQ(1U, ssrc_); - EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_REPLAY, error_); - Reset(); - rtc::Thread::Current()->SleepMs(210); - srtp_stat_.AddUnprotectRtpResult(1, srtp_err_status_replay_old); - EXPECT_EQ(1U, ssrc_); - EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_REPLAY, error_); - Reset(); - srtp_stat_.AddUnprotectRtpResult(1, srtp_err_status_fail); - EXPECT_EQ(1U, ssrc_); - EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_); - // Within 200ms, the error will not be triggered. - Reset(); - srtp_stat_.AddUnprotectRtpResult(1, srtp_err_status_fail); - EXPECT_EQ(0U, ssrc_); - EXPECT_EQ(-1, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_); - // Now the error will be triggered again. - Reset(); - rtc::Thread::Current()->SleepMs(210); - srtp_stat_.AddUnprotectRtpResult(1, srtp_err_status_fail); - EXPECT_EQ(1U, ssrc_); - EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_); -} - -TEST_F(SrtpStatTest, TestProtectRtcpError) { - Reset(); - srtp_stat_.AddProtectRtcpResult(srtp_err_status_ok); - EXPECT_EQ(-1, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_); - Reset(); - srtp_stat_.AddProtectRtcpResult(srtp_err_status_auth_fail); - EXPECT_EQ(cricket::SrtpFilter::PROTECT, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_AUTH, error_); - Reset(); - srtp_stat_.AddProtectRtcpResult(srtp_err_status_fail); - EXPECT_EQ(cricket::SrtpFilter::PROTECT, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_); - // Within 200ms, the error will not be triggered. - Reset(); - srtp_stat_.AddProtectRtcpResult(srtp_err_status_fail); - EXPECT_EQ(-1, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_); - // Now the error will be triggered again. - Reset(); - rtc::Thread::Current()->SleepMs(210); - srtp_stat_.AddProtectRtcpResult(srtp_err_status_fail); - EXPECT_EQ(cricket::SrtpFilter::PROTECT, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_); -} - -TEST_F(SrtpStatTest, TestUnprotectRtcpError) { - Reset(); - srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_ok); - EXPECT_EQ(-1, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_); - Reset(); - srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_auth_fail); - EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_AUTH, error_); - Reset(); - srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_replay_fail); - EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_REPLAY, error_); - Reset(); - rtc::Thread::Current()->SleepMs(210); - srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_replay_fail); - EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_REPLAY, error_); - Reset(); - srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_fail); - EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_); - // Within 200ms, the error will not be triggered. - Reset(); - srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_fail); - EXPECT_EQ(-1, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_); - // Now the error will be triggered again. - Reset(); - rtc::Thread::Current()->SleepMs(210); - srtp_stat_.AddUnprotectRtcpResult(srtp_err_status_fail); - EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, mode_); - EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_); -}