Remove MessageHandler[AutoCleanup] dependency from StreamInterface.
This includes relying on related types such as MessageData and PostEvent functionality inside the StreamInterface itself. This affects mostly tests but OpenSSLStreamAdapter requires special attention. Bug: webrtc:11988 Change-Id: Ib5c895f1bdf77bb49e3162bd49718f8a98812d91 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/185505 Commit-Queue: Tommi <tommi@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32290}
This commit is contained in:
committed by
Commit Bot
parent
b33a7186e6
commit
eb79dd9ffd
@ -35,6 +35,7 @@
|
||||
#include "rtc_base/openssl_identity.h"
|
||||
#include "rtc_base/ssl_certificate.h"
|
||||
#include "rtc_base/stream.h"
|
||||
#include "rtc_base/task_utils/to_queued_task.h"
|
||||
#include "rtc_base/thread.h"
|
||||
#include "rtc_base/time_utils.h"
|
||||
#include "system_wrappers/include/field_trial.h"
|
||||
@ -51,7 +52,6 @@
|
||||
|
||||
namespace rtc {
|
||||
namespace {
|
||||
|
||||
// SRTP cipher suite table. |internal_name| is used to construct a
|
||||
// colon-separated profile strings which is needed by
|
||||
// SSL_CTX_set_tlsext_use_srtp().
|
||||
@ -284,6 +284,7 @@ bool ShouldAllowLegacyTLSProtocols() {
|
||||
OpenSSLStreamAdapter::OpenSSLStreamAdapter(
|
||||
std::unique_ptr<StreamInterface> stream)
|
||||
: SSLStreamAdapter(std::move(stream)),
|
||||
owner_(rtc::Thread::Current()),
|
||||
state_(SSL_NONE),
|
||||
role_(SSL_CLIENT),
|
||||
ssl_read_needs_write_(false),
|
||||
@ -297,6 +298,7 @@ OpenSSLStreamAdapter::OpenSSLStreamAdapter(
|
||||
support_legacy_tls_protocols_flag_(ShouldAllowLegacyTLSProtocols()) {}
|
||||
|
||||
OpenSSLStreamAdapter::~OpenSSLStreamAdapter() {
|
||||
timeout_task_.Stop();
|
||||
Cleanup(0);
|
||||
}
|
||||
|
||||
@ -802,6 +804,33 @@ void OpenSSLStreamAdapter::OnEvent(StreamInterface* stream,
|
||||
}
|
||||
}
|
||||
|
||||
void OpenSSLStreamAdapter::PostEvent(int events, int err) {
|
||||
owner_->PostTask(webrtc::ToQueuedTask(
|
||||
task_safety_, [this, events, err]() { SignalEvent(this, events, err); }));
|
||||
}
|
||||
|
||||
void OpenSSLStreamAdapter::SetTimeout(int delay_ms) {
|
||||
// We need to accept 0 delay here as well as >0 delay, because
|
||||
// DTLSv1_get_timeout seems to frequently return 0 ms.
|
||||
RTC_DCHECK_GE(delay_ms, 0);
|
||||
RTC_DCHECK(!timeout_task_.Running());
|
||||
|
||||
timeout_task_ = webrtc::RepeatingTaskHandle::DelayedStart(
|
||||
owner_, webrtc::TimeDelta::Millis(delay_ms),
|
||||
[flag = task_safety_.flag(), this]() {
|
||||
if (flag->alive()) {
|
||||
RTC_LOG(LS_INFO) << "DTLS timeout expired";
|
||||
timeout_task_.Stop();
|
||||
DTLSv1_handle_timeout(ssl_);
|
||||
ContinueSSL();
|
||||
} else {
|
||||
RTC_NOTREACHED();
|
||||
}
|
||||
// This callback will never run again (stopped above).
|
||||
return webrtc::TimeDelta::PlusInfinity();
|
||||
});
|
||||
}
|
||||
|
||||
int OpenSSLStreamAdapter::BeginSSL() {
|
||||
RTC_DCHECK(state_ == SSL_CONNECTING);
|
||||
// The underlying stream has opened.
|
||||
@ -852,7 +881,7 @@ int OpenSSLStreamAdapter::ContinueSSL() {
|
||||
RTC_DCHECK(state_ == SSL_CONNECTING);
|
||||
|
||||
// Clear the DTLS timer
|
||||
Thread::Current()->Clear(this, MSG_TIMEOUT);
|
||||
timeout_task_.Stop();
|
||||
|
||||
const int code = (role_ == SSL_CLIENT) ? SSL_connect(ssl_) : SSL_accept(ssl_);
|
||||
const int ssl_error = SSL_get_error(ssl_, code);
|
||||
@ -884,9 +913,7 @@ int OpenSSLStreamAdapter::ContinueSSL() {
|
||||
struct timeval timeout;
|
||||
if (DTLSv1_get_timeout(ssl_, &timeout)) {
|
||||
int delay = timeout.tv_sec * 1000 + timeout.tv_usec / 1000;
|
||||
|
||||
Thread::Current()->PostDelayed(RTC_FROM_HERE, delay, this, MSG_TIMEOUT,
|
||||
0);
|
||||
SetTimeout(delay);
|
||||
}
|
||||
} break;
|
||||
|
||||
@ -963,18 +990,7 @@ void OpenSSLStreamAdapter::Cleanup(uint8_t alert) {
|
||||
peer_cert_chain_.reset();
|
||||
|
||||
// Clear the DTLS timer
|
||||
Thread::Current()->Clear(this, MSG_TIMEOUT);
|
||||
}
|
||||
|
||||
void OpenSSLStreamAdapter::OnMessage(Message* msg) {
|
||||
// Process our own messages and then pass others to the superclass
|
||||
if (MSG_TIMEOUT == msg->message_id) {
|
||||
RTC_LOG(LS_INFO) << "DTLS timeout expired";
|
||||
DTLSv1_handle_timeout(ssl_);
|
||||
ContinueSSL();
|
||||
} else {
|
||||
StreamInterface::OnMessage(msg);
|
||||
}
|
||||
timeout_task_.Stop();
|
||||
}
|
||||
|
||||
SSL_CTX* OpenSSLStreamAdapter::SetupSSLContext() {
|
||||
|
||||
Reference in New Issue
Block a user