diff --git a/p2p/base/dtlstransport.cc b/p2p/base/dtlstransport.cc index 2a528a3db9..314f63ce74 100644 --- a/p2p/base/dtlstransport.cc +++ b/p2p/base/dtlstransport.cc @@ -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 network_route) { + RTC_DCHECK_RUN_ON(&thread_checker_); SignalNetworkRouteChanged(network_route); } diff --git a/p2p/base/dtlstransport.h b/p2p/base/dtlstransport.h index 4003ab6a62..609f3d7215 100644 --- a/p2p/base/dtlstransport.h +++ b/p2p/base/dtlstransport.h @@ -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 owned_ice_transport_;