Change DtlsTransport to use a ThreadChecker

Bug: None
Change-Id: I7d628f6b22149e2d178ada9c07a390cbecdfc095
Reviewed-on: https://webrtc-review.googlesource.com/89681
Reviewed-by: Qingsi Wang <qingsi@webrtc.org>
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24072}
This commit is contained in:
Steve Anton 2018-07-19 15:42:17 -07:00
parent ea1bb35e27
commit f7a64ecfa3
2 changed files with 13 additions and 9 deletions

View File

@ -117,7 +117,6 @@ DtlsTransport::DtlsTransport(IceTransportInternal* ice_transport,
const rtc::CryptoOptions& crypto_options)
: transport_name_(ice_transport->transport_name()),
component_(ice_transport->component()),
network_thread_(rtc::Thread::Current()),
ice_transport_(ice_transport),
downward_(NULL),
srtp_ciphers_(GetSupportedDtlsSrtpCryptoSuites(crypto_options)),
@ -132,7 +131,6 @@ DtlsTransport::DtlsTransport(
const rtc::CryptoOptions& crypto_options)
: transport_name_(ice_transport->transport_name()),
component_(ice_transport->component()),
network_thread_(rtc::Thread::Current()),
ice_transport_(ice_transport.get()),
owned_ice_transport_(std::move(ice_transport)),
downward_(NULL),
@ -489,7 +487,7 @@ void DtlsTransport::ConnectToIceTransport() {
// - Once the DTLS handshake completes, the state is that of the
// impl again
void DtlsTransport::OnWritableState(rtc::PacketTransportInternal* transport) {
RTC_DCHECK(rtc::Thread::Current() == network_thread_);
RTC_DCHECK_RUN_ON(&thread_checker_);
RTC_DCHECK(transport == ice_transport_);
RTC_LOG(LS_VERBOSE) << ToString()
<< ": ice_transport writable state changed to "
@ -521,7 +519,7 @@ void DtlsTransport::OnWritableState(rtc::PacketTransportInternal* transport) {
}
void DtlsTransport::OnReceivingState(rtc::PacketTransportInternal* transport) {
RTC_DCHECK(rtc::Thread::Current() == network_thread_);
RTC_DCHECK_RUN_ON(&thread_checker_);
RTC_DCHECK(transport == ice_transport_);
RTC_LOG(LS_VERBOSE) << ToString()
<< ": ice_transport "
@ -538,7 +536,7 @@ void DtlsTransport::OnReadPacket(rtc::PacketTransportInternal* transport,
size_t size,
const rtc::PacketTime& packet_time,
int flags) {
RTC_DCHECK(rtc::Thread::Current() == network_thread_);
RTC_DCHECK_RUN_ON(&thread_checker_);
RTC_DCHECK(transport == ice_transport_);
RTC_DCHECK(flags == 0);
@ -619,19 +617,19 @@ void DtlsTransport::OnReadPacket(rtc::PacketTransportInternal* transport,
void DtlsTransport::OnSentPacket(rtc::PacketTransportInternal* transport,
const rtc::SentPacket& sent_packet) {
RTC_DCHECK(rtc::Thread::Current() == network_thread_);
RTC_DCHECK_RUN_ON(&thread_checker_);
SignalSentPacket(this, sent_packet);
}
void DtlsTransport::OnReadyToSend(rtc::PacketTransportInternal* transport) {
RTC_DCHECK_RUN_ON(&thread_checker_);
if (writable()) {
SignalReadyToSend(this);
}
}
void DtlsTransport::OnDtlsEvent(rtc::StreamInterface* dtls, int sig, int err) {
RTC_DCHECK(rtc::Thread::Current() == network_thread_);
RTC_DCHECK_RUN_ON(&thread_checker_);
RTC_DCHECK(dtls == dtls_.get());
if (sig & rtc::SE_OPEN) {
// This is the first time.
@ -683,6 +681,7 @@ void DtlsTransport::OnDtlsEvent(rtc::StreamInterface* dtls, int sig, int err) {
void DtlsTransport::OnNetworkRouteChanged(
absl::optional<rtc::NetworkRoute> network_route) {
RTC_DCHECK_RUN_ON(&thread_checker_);
SignalNetworkRouteChanged(network_route);
}

View File

@ -22,6 +22,7 @@
#include "rtc_base/constructormagic.h"
#include "rtc_base/sslstreamadapter.h"
#include "rtc_base/stream.h"
#include "rtc_base/thread_checker.h"
namespace rtc {
class PacketTransportInternal;
@ -83,6 +84,9 @@ class StreamInterfaceChannel : public rtc::StreamInterface {
//
// - The SSLStreamAdapter writes to downward_->Write() which translates it
// into packet writes on ice_transport_.
//
// This class is not thread safe; all methods must be called on the same thread
// as the constructor.
class DtlsTransport : public DtlsTransportInternal {
public:
// |ice_transport| is the ICE transport this DTLS transport is wrapping.
@ -210,10 +214,11 @@ class DtlsTransport : public DtlsTransportInternal {
// Sets the DTLS state, signaling if necessary.
void set_dtls_state(DtlsTransportState state);
rtc::ThreadChecker thread_checker_;
std::string transport_name_;
int component_;
DtlsTransportState dtls_state_ = DTLS_TRANSPORT_NEW;
rtc::Thread* network_thread_; // Everything should occur on this thread.
// Underlying ice_transport, not owned by this class.
IceTransportInternal* const ice_transport_;
std::unique_ptr<IceTransportInternal> owned_ice_transport_;