Throttle the RTP decryption error messages in the SrtpSession and SrtpTransport

In order to avoid excessive logging when a large percentage of received packets are bad (e.g. when the same packets get sent several times).

Bug: webrtc:9839
Change-Id: I2daed89b170adf7252624bf0da9af5a980bacc17
Reviewed-on: https://webrtc-review.googlesource.com/c/104624
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Commit-Queue: Erik Varga <erikvarga@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25060}
This commit is contained in:
erikvarga@webrtc.org
2018-10-09 12:31:28 +02:00
committed by Commit Bot
parent b674cd1038
commit d76a0fc5e9
4 changed files with 23 additions and 3 deletions

View File

@ -138,7 +138,15 @@ bool SrtpSession::UnprotectRtp(void* p, int in_len, int* out_len) {
*out_len = in_len;
int err = srtp_unprotect(session_, p, out_len);
if (err != srtp_err_status_ok) {
RTC_LOG(LS_WARNING) << "Failed to unprotect SRTP packet, err=" << err;
// Limit the error logging to avoid excessive logs when there are lots of
// bad packets.
const int kFailureLogThrottleCount = 100;
if (decryption_failure_count_ % kFailureLogThrottleCount == 0) {
RTC_LOG(LS_WARNING) << "Failed to unprotect SRTP packet, err=" << err
<< ", previous failure count: "
<< decryption_failure_count_;
}
++decryption_failure_count_;
RTC_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.SrtpUnprotectError",
static_cast<int>(err), kSrtpErrorCodeBoundary);
return false;

View File

@ -122,6 +122,7 @@ class SrtpSession {
int last_send_seq_num_ = -1;
bool external_auth_active_ = false;
bool external_auth_enabled_ = false;
int decryption_failure_count_ = 0;
RTC_DISALLOW_COPY_AND_ASSIGN(SrtpSession);
};

View File

@ -207,8 +207,17 @@ void SrtpTransport::OnRtpPacketReceived(rtc::CopyOnWriteBuffer* packet,
uint32_t ssrc = 0;
cricket::GetRtpSeqNum(data, len, &seq_num);
cricket::GetRtpSsrc(data, len, &ssrc);
// Limit the error logging to avoid excessive logs when there are lots of
// bad packets.
const int kFailureLogThrottleCount = 100;
if (decryption_failure_count_ % kFailureLogThrottleCount == 0) {
RTC_LOG(LS_ERROR) << "Failed to unprotect RTP packet: size=" << len
<< ", seqnum=" << seq_num << ", SSRC=" << ssrc;
<< ", seqnum=" << seq_num << ", SSRC=" << ssrc
<< ", previous failure count: "
<< decryption_failure_count_;
}
++decryption_failure_count_;
return;
}
packet->SetSize(len);

View File

@ -160,6 +160,8 @@ class SrtpTransport : public RtpTransport {
bool external_auth_enabled_ = false;
int rtp_abs_sendtime_extn_id_ = -1;
int decryption_failure_count_ = 0;
};
} // namespace webrtc