Delete StreamAdapterInterface
Shortens the inheritance chain between StreamInterface and OpenSSLStreamAdapter. Bug: webrtc:6424 Change-Id: I4306e27b583eb75c1a49efde3c27e1d81c117ac8 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213181 Commit-Queue: Niels Moller <nisse@webrtc.org> Reviewed-by: Taylor <deadbeef@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33755}
This commit is contained in:
parent
b291da8d03
commit
0131a4dcf3
@ -288,7 +288,7 @@ bool ShouldAllowLegacyTLSProtocols() {
|
||||
|
||||
OpenSSLStreamAdapter::OpenSSLStreamAdapter(
|
||||
std::unique_ptr<StreamInterface> stream)
|
||||
: SSLStreamAdapter(std::move(stream)),
|
||||
: stream_(std::move(stream)),
|
||||
owner_(rtc::Thread::Current()),
|
||||
state_(SSL_NONE),
|
||||
role_(SSL_CLIENT),
|
||||
@ -300,7 +300,9 @@ OpenSSLStreamAdapter::OpenSSLStreamAdapter(
|
||||
ssl_max_version_(SSL_PROTOCOL_TLS_12),
|
||||
// Default is to support legacy TLS protocols.
|
||||
// This will be changed to default non-support in M82 or M83.
|
||||
support_legacy_tls_protocols_flag_(ShouldAllowLegacyTLSProtocols()) {}
|
||||
support_legacy_tls_protocols_flag_(ShouldAllowLegacyTLSProtocols()) {
|
||||
stream_->SignalEvent.connect(this, &OpenSSLStreamAdapter::OnEvent);
|
||||
}
|
||||
|
||||
OpenSSLStreamAdapter::~OpenSSLStreamAdapter() {
|
||||
timeout_task_.Stop();
|
||||
@ -519,7 +521,7 @@ int OpenSSLStreamAdapter::StartSSL() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (StreamAdapterInterface::GetState() != SS_OPEN) {
|
||||
if (stream_->GetState() != SS_OPEN) {
|
||||
state_ = SSL_WAIT;
|
||||
return 0;
|
||||
}
|
||||
@ -561,7 +563,7 @@ StreamResult OpenSSLStreamAdapter::Write(const void* data,
|
||||
switch (state_) {
|
||||
case SSL_NONE:
|
||||
// pass-through in clear text
|
||||
return StreamAdapterInterface::Write(data, data_len, written, error);
|
||||
return stream_->Write(data, data_len, written, error);
|
||||
|
||||
case SSL_WAIT:
|
||||
case SSL_CONNECTING:
|
||||
@ -629,7 +631,7 @@ StreamResult OpenSSLStreamAdapter::Read(void* data,
|
||||
switch (state_) {
|
||||
case SSL_NONE:
|
||||
// pass-through in clear text
|
||||
return StreamAdapterInterface::Read(data, data_len, read, error);
|
||||
return stream_->Read(data, data_len, read, error);
|
||||
case SSL_WAIT:
|
||||
case SSL_CONNECTING:
|
||||
return SR_BLOCK;
|
||||
@ -733,7 +735,7 @@ void OpenSSLStreamAdapter::Close() {
|
||||
// When we're closed at SSL layer, also close the stream level which
|
||||
// performs necessary clean up. Otherwise, a new incoming packet after
|
||||
// this could overflow the stream buffer.
|
||||
StreamAdapterInterface::Close();
|
||||
stream_->Close();
|
||||
}
|
||||
|
||||
StreamState OpenSSLStreamAdapter::GetState() const {
|
||||
@ -757,7 +759,7 @@ void OpenSSLStreamAdapter::OnEvent(StreamInterface* stream,
|
||||
int err) {
|
||||
int events_to_signal = 0;
|
||||
int signal_error = 0;
|
||||
RTC_DCHECK(stream == this->stream());
|
||||
RTC_DCHECK(stream == stream_.get());
|
||||
|
||||
if ((events & SE_OPEN)) {
|
||||
RTC_DLOG(LS_VERBOSE) << "OpenSSLStreamAdapter::OnEvent SE_OPEN";
|
||||
@ -809,7 +811,9 @@ void OpenSSLStreamAdapter::OnEvent(StreamInterface* stream,
|
||||
}
|
||||
|
||||
if (events_to_signal) {
|
||||
StreamAdapterInterface::OnEvent(stream, events_to_signal, signal_error);
|
||||
// Note that the adapter presents itself as the origin of the stream events,
|
||||
// since users of the adapter may not recognize the adapted object.
|
||||
SignalEvent(this, events_to_signal, signal_error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -854,7 +858,7 @@ int OpenSSLStreamAdapter::BeginSSL() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
bio = BIO_new_stream(static_cast<StreamInterface*>(stream()));
|
||||
bio = BIO_new_stream(stream_.get());
|
||||
if (!bio) {
|
||||
return -1;
|
||||
}
|
||||
@ -912,8 +916,7 @@ int OpenSSLStreamAdapter::ContinueSSL() {
|
||||
// The caller of ContinueSSL may be the same object listening for these
|
||||
// events and may not be prepared for reentrancy.
|
||||
// PostEvent(SE_OPEN | SE_READ | SE_WRITE, 0);
|
||||
StreamAdapterInterface::OnEvent(stream(), SE_OPEN | SE_READ | SE_WRITE,
|
||||
0);
|
||||
SignalEvent(this, SE_OPEN | SE_READ | SE_WRITE, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
@ -956,7 +959,7 @@ void OpenSSLStreamAdapter::Error(const char* context,
|
||||
ssl_error_code_ = err;
|
||||
Cleanup(alert);
|
||||
if (signal) {
|
||||
StreamAdapterInterface::OnEvent(stream(), SE_CLOSE, err);
|
||||
SignalEvent(this, SE_CLOSE, err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -136,9 +136,6 @@ class OpenSSLStreamAdapter final : public SSLStreamAdapter {
|
||||
// using a fake clock.
|
||||
static void EnableTimeCallbackForTesting();
|
||||
|
||||
protected:
|
||||
void OnEvent(StreamInterface* stream, int events, int err) override;
|
||||
|
||||
private:
|
||||
enum SSLState {
|
||||
// Before calling one of the StartSSL methods, data flows
|
||||
@ -151,6 +148,8 @@ class OpenSSLStreamAdapter final : public SSLStreamAdapter {
|
||||
SSL_CLOSED // Clean close
|
||||
};
|
||||
|
||||
void OnEvent(StreamInterface* stream, int events, int err);
|
||||
|
||||
void PostEvent(int events, int err);
|
||||
void SetTimeout(int delay_ms);
|
||||
|
||||
@ -203,6 +202,8 @@ class OpenSSLStreamAdapter final : public SSLStreamAdapter {
|
||||
!peer_certificate_digest_value_.empty();
|
||||
}
|
||||
|
||||
const std::unique_ptr<StreamInterface> stream_;
|
||||
|
||||
rtc::Thread* const owner_;
|
||||
webrtc::ScopedTaskSafety task_safety_;
|
||||
webrtc::RepeatingTaskHandle timeout_task_;
|
||||
|
||||
@ -95,11 +95,6 @@ std::unique_ptr<SSLStreamAdapter> SSLStreamAdapter::Create(
|
||||
return std::make_unique<OpenSSLStreamAdapter>(std::move(stream));
|
||||
}
|
||||
|
||||
SSLStreamAdapter::SSLStreamAdapter(std::unique_ptr<StreamInterface> stream)
|
||||
: StreamAdapterInterface(stream.release()) {}
|
||||
|
||||
SSLStreamAdapter::~SSLStreamAdapter() {}
|
||||
|
||||
bool SSLStreamAdapter::GetSslCipherSuite(int* cipher_suite) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ enum { SSE_MSG_TRUNC = 0xff0001 };
|
||||
// Used to send back UMA histogram value. Logged when Dtls handshake fails.
|
||||
enum class SSLHandshakeError { UNKNOWN, INCOMPATIBLE_CIPHERSUITE, MAX_VALUE };
|
||||
|
||||
class SSLStreamAdapter : public StreamAdapterInterface {
|
||||
class SSLStreamAdapter : public StreamInterface, public sigslot::has_slots<> {
|
||||
public:
|
||||
// Instantiate an SSLStreamAdapter wrapping the given stream,
|
||||
// (using the selected implementation for the platform).
|
||||
@ -126,8 +126,8 @@ class SSLStreamAdapter : public StreamAdapterInterface {
|
||||
static std::unique_ptr<SSLStreamAdapter> Create(
|
||||
std::unique_ptr<StreamInterface> stream);
|
||||
|
||||
explicit SSLStreamAdapter(std::unique_ptr<StreamInterface> stream);
|
||||
~SSLStreamAdapter() override;
|
||||
SSLStreamAdapter() = default;
|
||||
~SSLStreamAdapter() override = default;
|
||||
|
||||
// Specify our SSL identity: key and certificate. SSLStream takes ownership
|
||||
// of the SSLIdentity object and will free it when appropriate. Should be
|
||||
|
||||
@ -49,68 +49,4 @@ bool StreamInterface::Flush() {
|
||||
|
||||
StreamInterface::StreamInterface() {}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// StreamAdapterInterface
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
StreamAdapterInterface::StreamAdapterInterface(StreamInterface* stream,
|
||||
bool owned)
|
||||
: stream_(stream), owned_(owned) {
|
||||
if (nullptr != stream_)
|
||||
stream_->SignalEvent.connect(this, &StreamAdapterInterface::OnEvent);
|
||||
}
|
||||
|
||||
StreamState StreamAdapterInterface::GetState() const {
|
||||
return stream_->GetState();
|
||||
}
|
||||
StreamResult StreamAdapterInterface::Read(void* buffer,
|
||||
size_t buffer_len,
|
||||
size_t* read,
|
||||
int* error) {
|
||||
return stream_->Read(buffer, buffer_len, read, error);
|
||||
}
|
||||
StreamResult StreamAdapterInterface::Write(const void* data,
|
||||
size_t data_len,
|
||||
size_t* written,
|
||||
int* error) {
|
||||
return stream_->Write(data, data_len, written, error);
|
||||
}
|
||||
void StreamAdapterInterface::Close() {
|
||||
stream_->Close();
|
||||
}
|
||||
|
||||
bool StreamAdapterInterface::Flush() {
|
||||
return stream_->Flush();
|
||||
}
|
||||
|
||||
void StreamAdapterInterface::Attach(StreamInterface* stream, bool owned) {
|
||||
if (nullptr != stream_)
|
||||
stream_->SignalEvent.disconnect(this);
|
||||
if (owned_)
|
||||
delete stream_;
|
||||
stream_ = stream;
|
||||
owned_ = owned;
|
||||
if (nullptr != stream_)
|
||||
stream_->SignalEvent.connect(this, &StreamAdapterInterface::OnEvent);
|
||||
}
|
||||
|
||||
StreamInterface* StreamAdapterInterface::Detach() {
|
||||
if (nullptr != stream_)
|
||||
stream_->SignalEvent.disconnect(this);
|
||||
StreamInterface* stream = stream_;
|
||||
stream_ = nullptr;
|
||||
return stream;
|
||||
}
|
||||
|
||||
StreamAdapterInterface::~StreamAdapterInterface() {
|
||||
if (owned_)
|
||||
delete stream_;
|
||||
}
|
||||
|
||||
void StreamAdapterInterface::OnEvent(StreamInterface* stream,
|
||||
int events,
|
||||
int err) {
|
||||
SignalEvent(this, events, err);
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
@ -115,50 +115,6 @@ class RTC_EXPORT StreamInterface {
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(StreamInterface);
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// StreamAdapterInterface is a convenient base-class for adapting a stream.
|
||||
// By default, all operations are pass-through. Override the methods that you
|
||||
// require adaptation. Streams should really be upgraded to reference-counted.
|
||||
// In the meantime, use the owned flag to indicate whether the adapter should
|
||||
// own the adapted stream.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class StreamAdapterInterface : public StreamInterface,
|
||||
public sigslot::has_slots<> {
|
||||
public:
|
||||
explicit StreamAdapterInterface(StreamInterface* stream, bool owned = true);
|
||||
|
||||
// Core Stream Interface
|
||||
StreamState GetState() const override;
|
||||
StreamResult Read(void* buffer,
|
||||
size_t buffer_len,
|
||||
size_t* read,
|
||||
int* error) override;
|
||||
StreamResult Write(const void* data,
|
||||
size_t data_len,
|
||||
size_t* written,
|
||||
int* error) override;
|
||||
void Close() override;
|
||||
|
||||
bool Flush() override;
|
||||
|
||||
void Attach(StreamInterface* stream, bool owned = true);
|
||||
StreamInterface* Detach();
|
||||
|
||||
protected:
|
||||
~StreamAdapterInterface() override;
|
||||
|
||||
// Note that the adapter presents itself as the origin of the stream events,
|
||||
// since users of the adapter may not recognize the adapted object.
|
||||
virtual void OnEvent(StreamInterface* stream, int events, int err);
|
||||
StreamInterface* stream() { return stream_; }
|
||||
|
||||
private:
|
||||
StreamInterface* stream_;
|
||||
bool owned_;
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(StreamAdapterInterface);
|
||||
};
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // RTC_BASE_STREAM_H_
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user