Constify transport stats

BUG=None

Change-Id: I441a46dea97d9a9022b96aaadef1d7348c6f90ee
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/364124
Commit-Queue: Philipp Hancke <phancke@meta.com>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43148}
diff --git a/p2p/base/dtls_transport.cc b/p2p/base/dtls_transport.cc
index a0a3a35..5ed2a11 100644
--- a/p2p/base/dtls_transport.cc
+++ b/p2p/base/dtls_transport.cc
@@ -225,7 +225,7 @@
   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 @@
   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 03a29fa..0a988df 100644
--- a/p2p/base/dtls_transport.h
+++ b/p2p/base/dtls_transport.h
@@ -156,7 +156,7 @@
   // 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 @@
   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<absl::string_view> 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 2fc3ebd..0550145 100644
--- a/p2p/base/dtls_transport_internal.h
+++ b/p2p/base/dtls_transport_internal.h
@@ -65,11 +65,11 @@
   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<absl::string_view> 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 f0dba0a..042d93b 100644
--- a/p2p/base/fake_dtls_transport.h
+++ b/p2p/base/fake_dtls_transport.h
@@ -194,7 +194,7 @@
     *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 @@
   }
   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 7645360..31cd1b5 100644
--- a/pc/jsep_transport.cc
+++ b/pc/jsep_transport.cc
@@ -317,7 +317,7 @@
   return std::optional<rtc::SSLRole>(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 @@
 
 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 4839ea7..f0678f9 100644
--- a/pc/jsep_transport.h
+++ b/pc/jsep_transport.h
@@ -147,8 +147,7 @@
   // negotiated yet.
   std::optional<rtc::SSLRole> 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 @@
 
   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 cb79860..d7dbf3f 100644
--- a/pc/jsep_transport_controller.cc
+++ b/pc/jsep_transport_controller.cc
@@ -443,10 +443,11 @@
 }
 
 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 b5e3ebf..96aa656 100644
--- a/pc/jsep_transport_controller.h
+++ b/pc/jsep_transport_controller.h
@@ -247,10 +247,7 @@
                            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 2ad4d31..bbad2a3 100644
--- a/rtc_base/openssl_stream_adapter.cc
+++ b/rtc_base/openssl_stream_adapter.cc
@@ -330,7 +330,7 @@
   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 @@
   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 c14d9d7..7ad50c6 100644
--- a/rtc_base/openssl_stream_adapter.h
+++ b/rtc_base/openssl_stream_adapter.h
@@ -107,7 +107,7 @@
 
   std::optional<absl::string_view> 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 @@
 
   // DTLS-SRTP interface
   bool SetDtlsSrtpCryptoSuites(const std::vector<int>& 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 7e09bf0..75e3dda 100644
--- a/rtc_base/ssl_stream_adapter.cc
+++ b/rtc_base/ssl_stream_adapter.cc
@@ -87,10 +87,6 @@
                                                 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 @@
   return false;  // Default is unsupported
 }
 
-bool SSLStreamAdapter::SetDtlsSrtpCryptoSuites(
-    const std::vector<int>& 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 e16db4a..dcaaf3a 100644
--- a/rtc_base/ssl_stream_adapter.h
+++ b/rtc_base/ssl_stream_adapter.h
@@ -184,7 +184,7 @@
 
   // 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<absl::string_view> GetTlsCipherSuiteName() const = 0;
@@ -220,8 +220,9 @@
   virtual uint16_t GetPeerSignatureAlgorithm() const = 0;
 
   // DTLS-SRTP interface
-  virtual bool SetDtlsSrtpCryptoSuites(const std::vector<int>& crypto_suites);
-  virtual bool GetDtlsSrtpCryptoSuite(int* crypto_suite);
+  virtual bool SetDtlsSrtpCryptoSuites(
+      const std::vector<int>& 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