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}
This commit is contained in:
nisse 2017-06-16 00:57:21 -07:00 committed by Commit Bot
parent 92b607b033
commit af99b6d67a
7 changed files with 1 additions and 566 deletions

View File

@ -483,7 +483,6 @@ rtc_static_library("rtc_base") {
"signalthread.h",
"sigslot.cc",
"sigslot.h",
"sigslotrepeater.h",
"socket.h",
"socketadapters.cc",
"socketadapters.h",

View File

@ -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 mt_policy = SIGSLOT_DEFAULT_MT_POLICY>
class repeater0 : public signal0<mt_policy>,
public has_slots<mt_policy>
{
public:
typedef signal0<mt_policy> base_type;
typedef repeater0<mt_policy> this_type;
repeater0() { }
repeater0(const this_type& s) : base_type(s) { }
void reemit() { signal0<mt_policy>::emit(); }
void repeat(base_type &s) { s.connect(this, &this_type::reemit); }
void stop(base_type &s) { s.disconnect(this); }
};
template<class arg1_type, class mt_policy = SIGSLOT_DEFAULT_MT_POLICY>
class repeater1 : public signal1<arg1_type, mt_policy>,
public has_slots<mt_policy>
{
public:
typedef signal1<arg1_type, mt_policy> base_type;
typedef repeater1<arg1_type, mt_policy> this_type;
repeater1() { }
repeater1(const this_type& s) : base_type(s) { }
void reemit(arg1_type a1) { signal1<arg1_type, mt_policy>::emit(a1); }
void repeat(base_type& s) { s.connect(this, &this_type::reemit); }
void stop(base_type &s) { s.disconnect(this); }
};
template<class arg1_type, class arg2_type, class mt_policy = SIGSLOT_DEFAULT_MT_POLICY>
class repeater2 : public signal2<arg1_type, arg2_type, mt_policy>,
public has_slots<mt_policy>
{
public:
typedef signal2<arg1_type, arg2_type, mt_policy> base_type;
typedef repeater2<arg1_type, arg2_type, mt_policy> this_type;
repeater2() { }
repeater2(const this_type& s) : base_type(s) { }
void reemit(arg1_type a1, arg2_type a2) { signal2<arg1_type, arg2_type, mt_policy>::emit(a1,a2); }
void repeat(base_type& s) { s.connect(this, &this_type::reemit); }
void stop(base_type &s) { s.disconnect(this); }
};
template<class arg1_type, class arg2_type, class arg3_type,
class mt_policy = SIGSLOT_DEFAULT_MT_POLICY>
class repeater3 : public signal3<arg1_type, arg2_type, arg3_type, mt_policy>,
public has_slots<mt_policy>
{
public:
typedef signal3<arg1_type, arg2_type, arg3_type, mt_policy> base_type;
typedef repeater3<arg1_type, arg2_type, arg3_type, mt_policy> this_type;
repeater3() { }
repeater3(const this_type& s) : base_type(s) { }
void reemit(arg1_type a1, arg2_type a2, arg3_type a3) {
signal3<arg1_type, arg2_type, arg3_type, mt_policy>::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__

View File

@ -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"

View File

@ -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<unsigned char>(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<void>(RTC_FROM_HERE, [this] {
fake_rtp_dtls_transport2_->SignalReadPacket(
fake_rtp_dtls_transport2_.get(),
reinterpret_cast<const char*>(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();
}

View File

@ -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

View File

@ -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<uint32_t, Mode, Error> SignalSrtpError;
protected:
bool ExpectOffer(ContentSource source);
bool StoreParams(const std::vector<CryptoParams>& 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<CryptoParams> offer_params_;
std::unique_ptr<SrtpSession> 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<uint32_t, SrtpFilter::Mode, SrtpFilter::Error>
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<SrtpStat> 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<uint32_t, SrtpFilter::Mode, SrtpFilter::Error>
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<FailureKey, FailureStat> 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_

View File

@ -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_);
}