From 4f732f48472ae456e2e5108e7fa7f017c3bb8b5c Mon Sep 17 00:00:00 2001 From: Philipp Hancke Date: Mon, 30 Sep 2024 11:58:25 -0700 Subject: [PATCH] Constify transport stats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUG=None Change-Id: I441a46dea97d9a9022b96aaadef1d7348c6f90ee Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/364124 Commit-Queue: Philipp Hancke Reviewed-by: Harald Alvestrand Reviewed-by: Henrik Boström Cr-Commit-Position: refs/heads/main@{#43148} --- p2p/base/dtls_transport.cc | 4 ++-- p2p/base/dtls_transport.h | 4 ++-- p2p/base/dtls_transport_internal.h | 4 ++-- p2p/base/fake_dtls_transport.h | 4 ++-- pc/jsep_transport.cc | 4 ++-- pc/jsep_transport.h | 5 ++--- pc/jsep_transport_controller.cc | 5 +++-- pc/jsep_transport_controller.h | 5 +---- rtc_base/openssl_stream_adapter.cc | 4 ++-- rtc_base/openssl_stream_adapter.h | 4 ++-- rtc_base/ssl_stream_adapter.cc | 13 ------------- rtc_base/ssl_stream_adapter.h | 7 ++++--- 12 files changed, 24 insertions(+), 39 deletions(-) diff --git a/p2p/base/dtls_transport.cc b/p2p/base/dtls_transport.cc index a0a3a35100..5ed2a11438 100644 --- a/p2p/base/dtls_transport.cc +++ b/p2p/base/dtls_transport.cc @@ -225,7 +225,7 @@ bool DtlsTransport::GetDtlsRole(rtc::SSLRole* role) const { return true; } -bool DtlsTransport::GetSslCipherSuite(int* cipher) { +bool DtlsTransport::GetSslCipherSuite(int* cipher) const { if (dtls_state() != webrtc::DtlsTransportState::kConnected) { return false; } @@ -415,7 +415,7 @@ bool DtlsTransport::SetupDtls() { return true; } -bool DtlsTransport::GetSrtpCryptoSuite(int* cipher) { +bool DtlsTransport::GetSrtpCryptoSuite(int* cipher) const { if (dtls_state() != webrtc::DtlsTransportState::kConnected) { return false; } diff --git a/p2p/base/dtls_transport.h b/p2p/base/dtls_transport.h index 03a29fa75e..0a988dfe38 100644 --- a/p2p/base/dtls_transport.h +++ b/p2p/base/dtls_transport.h @@ -156,7 +156,7 @@ class DtlsTransport : public DtlsTransportInternal { // Find out which TLS version was negotiated bool GetSslVersionBytes(int* version) const override; // Find out which DTLS-SRTP cipher was negotiated - bool GetSrtpCryptoSuite(int* cipher) override; + bool GetSrtpCryptoSuite(int* cipher) const override; // Find out which signature algorithm was used by the peer. Returns values // from @@ -168,7 +168,7 @@ class DtlsTransport : public DtlsTransportInternal { bool SetDtlsRole(rtc::SSLRole role) override; // Find out which DTLS cipher was negotiated - bool GetSslCipherSuite(int* cipher) override; + bool GetSslCipherSuite(int* cipher) const override; std::optional GetTlsCipherSuiteName() const override; // Once DTLS has been established, this method retrieves the certificate diff --git a/p2p/base/dtls_transport_internal.h b/p2p/base/dtls_transport_internal.h index 2fc3ebded8..05501458f8 100644 --- a/p2p/base/dtls_transport_internal.h +++ b/p2p/base/dtls_transport_internal.h @@ -65,11 +65,11 @@ class DtlsTransportInternal : public rtc::PacketTransportInternal { virtual bool GetSslVersionBytes(int* version) const = 0; // Finds out which DTLS-SRTP cipher was negotiated. // TODO(zhihuang): Remove this once all dependencies implement this. - virtual bool GetSrtpCryptoSuite(int* cipher) = 0; + virtual bool GetSrtpCryptoSuite(int* cipher) const = 0; // Finds out which DTLS cipher was negotiated. // TODO(zhihuang): Remove this once all dependencies implement this. - virtual bool GetSslCipherSuite(int* cipher) = 0; + virtual bool GetSslCipherSuite(int* cipher) const = 0; virtual std::optional GetTlsCipherSuiteName() const = 0; // Find out which signature algorithm was used by the peer. Returns values diff --git a/p2p/base/fake_dtls_transport.h b/p2p/base/fake_dtls_transport.h index f0dba0a9f9..042d93b171 100644 --- a/p2p/base/fake_dtls_transport.h +++ b/p2p/base/fake_dtls_transport.h @@ -194,7 +194,7 @@ class FakeDtlsTransport : public DtlsTransportInternal { *version = 0x0102; return true; } - bool GetSrtpCryptoSuite(int* crypto_suite) override { + bool GetSrtpCryptoSuite(int* crypto_suite) const override { if (!do_dtls_) { return false; } @@ -203,7 +203,7 @@ class FakeDtlsTransport : public DtlsTransportInternal { } void SetSrtpCryptoSuite(int crypto_suite) { crypto_suite_ = crypto_suite; } - bool GetSslCipherSuite(int* cipher_suite) override { + bool GetSslCipherSuite(int* cipher_suite) const override { if (ssl_cipher_suite_) { *cipher_suite = *ssl_cipher_suite_; return true; diff --git a/pc/jsep_transport.cc b/pc/jsep_transport.cc index 7645360c78..31cd1b5d17 100644 --- a/pc/jsep_transport.cc +++ b/pc/jsep_transport.cc @@ -317,7 +317,7 @@ std::optional JsepTransport::GetDtlsRole() const { return std::optional(dtls_role); } -bool JsepTransport::GetStats(TransportStats* stats) { +bool JsepTransport::GetStats(TransportStats* stats) const { TRACE_EVENT0("webrtc", "JsepTransport::GetStats"); RTC_DCHECK_RUN_ON(network_thread_); stats->transport_name = mid(); @@ -634,7 +634,7 @@ webrtc::RTCError JsepTransport::NegotiateDtlsRole( bool JsepTransport::GetTransportStats(DtlsTransportInternal* dtls_transport, int component, - TransportStats* stats) { + TransportStats* stats) const { RTC_DCHECK_RUN_ON(network_thread_); RTC_DCHECK(dtls_transport); TransportChannelStats substats; diff --git a/pc/jsep_transport.h b/pc/jsep_transport.h index 4839ea7796..f0678f9dc0 100644 --- a/pc/jsep_transport.h +++ b/pc/jsep_transport.h @@ -147,8 +147,7 @@ class JsepTransport { // negotiated yet. std::optional GetDtlsRole() const; - // TODO(deadbeef): Make this const. See comment in transportcontroller.h. - bool GetStats(TransportStats* stats); + bool GetStats(TransportStats* stats) const; const JsepTransportDescription* local_description() const { RTC_DCHECK_RUN_ON(network_thread_); @@ -285,7 +284,7 @@ class JsepTransport { bool GetTransportStats(DtlsTransportInternal* dtls_transport, int component, - TransportStats* stats); + TransportStats* stats) const; // Owning thread, for safety checks const rtc::Thread* const network_thread_; diff --git a/pc/jsep_transport_controller.cc b/pc/jsep_transport_controller.cc index cb79860889..d7dbf3fc54 100644 --- a/pc/jsep_transport_controller.cc +++ b/pc/jsep_transport_controller.cc @@ -443,10 +443,11 @@ RTCError JsepTransportController::RemoveRemoteCandidates( } bool JsepTransportController::GetStats(const std::string& transport_name, - cricket::TransportStats* stats) { + cricket::TransportStats* stats) const { RTC_DCHECK_RUN_ON(network_thread_); - cricket::JsepTransport* transport = GetJsepTransportByName(transport_name); + const cricket::JsepTransport* transport = + GetJsepTransportByName(transport_name); if (!transport) { return false; } diff --git a/pc/jsep_transport_controller.h b/pc/jsep_transport_controller.h index b5e3ebf1f3..96aa6564df 100644 --- a/pc/jsep_transport_controller.h +++ b/pc/jsep_transport_controller.h @@ -247,10 +247,7 @@ class JsepTransportController : public PayloadTypeSuggester, PayloadType payload_type, const cricket::Codec& codec) override; - // TODO(deadbeef): GetStats isn't const because all the way down to - // OpenSSLStreamAdapter, GetSslCipherSuite and GetDtlsSrtpCryptoSuite are not - // const. Fix this. - bool GetStats(const std::string& mid, cricket::TransportStats* stats); + bool GetStats(const std::string& mid, cricket::TransportStats* stats) const; bool initial_offerer() const { return initial_offerer_ && *initial_offerer_; } diff --git a/rtc_base/openssl_stream_adapter.cc b/rtc_base/openssl_stream_adapter.cc index 2ad4d31604..bbad2a31ac 100644 --- a/rtc_base/openssl_stream_adapter.cc +++ b/rtc_base/openssl_stream_adapter.cc @@ -330,7 +330,7 @@ std::optional OpenSSLStreamAdapter::GetTlsCipherSuiteName() return SSL_CIPHER_standard_name(current_cipher); } -bool OpenSSLStreamAdapter::GetSslCipherSuite(int* cipher_suite) { +bool OpenSSLStreamAdapter::GetSslCipherSuite(int* cipher_suite) const { if (state_ != SSL_CONNECTED) { return false; } @@ -437,7 +437,7 @@ bool OpenSSLStreamAdapter::SetDtlsSrtpCryptoSuites( return true; } -bool OpenSSLStreamAdapter::GetDtlsSrtpCryptoSuite(int* crypto_suite) { +bool OpenSSLStreamAdapter::GetDtlsSrtpCryptoSuite(int* crypto_suite) const { RTC_DCHECK(state_ == SSL_CONNECTED); if (state_ != SSL_CONNECTED) { return false; diff --git a/rtc_base/openssl_stream_adapter.h b/rtc_base/openssl_stream_adapter.h index c14d9d7068..7ad50c690a 100644 --- a/rtc_base/openssl_stream_adapter.h +++ b/rtc_base/openssl_stream_adapter.h @@ -107,7 +107,7 @@ class OpenSSLStreamAdapter final : public SSLStreamAdapter, std::optional GetTlsCipherSuiteName() const override; - bool GetSslCipherSuite(int* cipher) override; + bool GetSslCipherSuite(int* cipher) const override; [[deprecated("Use GetSslVersionBytes")]] SSLProtocolVersion GetSslVersion() const override; bool GetSslVersionBytes(int* version) const override; @@ -123,7 +123,7 @@ class OpenSSLStreamAdapter final : public SSLStreamAdapter, // DTLS-SRTP interface bool SetDtlsSrtpCryptoSuites(const std::vector& crypto_suites) override; - bool GetDtlsSrtpCryptoSuite(int* crypto_suite) override; + bool GetDtlsSrtpCryptoSuite(int* crypto_suite) const override; bool IsTlsConnected() override; diff --git a/rtc_base/ssl_stream_adapter.cc b/rtc_base/ssl_stream_adapter.cc index 7e09bf01ca..75e3dda66c 100644 --- a/rtc_base/ssl_stream_adapter.cc +++ b/rtc_base/ssl_stream_adapter.cc @@ -87,10 +87,6 @@ std::unique_ptr SSLStreamAdapter::Create( std::move(handshake_error)); } -bool SSLStreamAdapter::GetSslCipherSuite(int* cipher_suite) { - return false; -} - bool SSLStreamAdapter::ExportKeyingMaterial(absl::string_view label, const uint8_t* context, size_t context_len, @@ -100,15 +96,6 @@ bool SSLStreamAdapter::ExportKeyingMaterial(absl::string_view label, return false; // Default is unsupported } -bool SSLStreamAdapter::SetDtlsSrtpCryptoSuites( - const std::vector& crypto_suites) { - return false; -} - -bool SSLStreamAdapter::GetDtlsSrtpCryptoSuite(int* crypto_suite) { - return false; -} - bool SSLStreamAdapter::IsBoringSsl() { return OpenSSLStreamAdapter::IsBoringSsl(); } diff --git a/rtc_base/ssl_stream_adapter.h b/rtc_base/ssl_stream_adapter.h index e16db4ad48..dcaaf3a0d1 100644 --- a/rtc_base/ssl_stream_adapter.h +++ b/rtc_base/ssl_stream_adapter.h @@ -184,7 +184,7 @@ class SSLStreamAdapter : public StreamInterface { // Retrieves the IANA registration id of the cipher suite used for the // connection (e.g. 0x2F for "TLS_RSA_WITH_AES_128_CBC_SHA"). - virtual bool GetSslCipherSuite(int* cipher_suite); + virtual bool GetSslCipherSuite(int* cipher_suite) const = 0; // Returns the name of the cipher suite used for the DTLS transport, // as defined in the "Description" column of the IANA cipher suite registry. virtual std::optional GetTlsCipherSuiteName() const = 0; @@ -220,8 +220,9 @@ class SSLStreamAdapter : public StreamInterface { virtual uint16_t GetPeerSignatureAlgorithm() const = 0; // DTLS-SRTP interface - virtual bool SetDtlsSrtpCryptoSuites(const std::vector& crypto_suites); - virtual bool GetDtlsSrtpCryptoSuite(int* crypto_suite); + virtual bool SetDtlsSrtpCryptoSuites( + const std::vector& crypto_suites) = 0; + virtual bool GetDtlsSrtpCryptoSuite(int* crypto_suite) const = 0; // Returns true if a TLS connection has been established. // The only difference between this and "GetState() == SE_OPEN" is that if