[StunMessage] Remove/deprecate StunMessage::SetType

Removes all remaining usage of SetType and marks the method as
deprecated.

Bug: none
Change-Id: I98dc613978ffe7ad8a4ffd951dd974d56ed92983
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/265100
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37137}
diff --git a/api/transport/stun.h b/api/transport/stun.h
index 43e2a08..9751ed1 100644
--- a/api/transport/stun.h
+++ b/api/transport/stun.h
@@ -178,7 +178,7 @@
   // is determined by the lengths of the transaction ID.
   bool IsLegacy() const;
 
-  void SetType(int type) { type_ = static_cast<uint16_t>(type); }
+  [[deprecated]] void SetType(int type) { type_ = static_cast<uint16_t>(type); }
   [[deprecated]] bool SetTransactionID(absl::string_view transaction_id) {
     if (!IsValidTransactionId(transaction_id))
       return false;
diff --git a/p2p/base/p2p_transport_channel_unittest.cc b/p2p/base/p2p_transport_channel_unittest.cc
index ccf8e4e..86e1171 100644
--- a/p2p/base/p2p_transport_channel_unittest.cc
+++ b/p2p/base/p2p_transport_channel_unittest.cc
@@ -3747,8 +3747,7 @@
 
   // Simulate a binding request being received, creating a peer reflexive
   // candidate pair while we still don't have remote ICE parameters.
-  IceMessage request;
-  request.SetType(STUN_BINDING_REQUEST);
+  IceMessage request(STUN_BINDING_REQUEST);
   request.AddAttribute(std::make_unique<StunByteStringAttribute>(
       STUN_ATTR_USERNAME, kIceUfrag[1]));
   uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
@@ -3916,8 +3915,7 @@
                    kMediumTimeout);
 
   // Create a minimal STUN message with prflx priority.
-  IceMessage request;
-  request.SetType(STUN_BINDING_REQUEST);
+  IceMessage request(STUN_BINDING_REQUEST);
   request.AddAttribute(std::make_unique<StunByteStringAttribute>(
       STUN_ATTR_USERNAME, kIceUfrag[1]));
   uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
@@ -4172,8 +4170,7 @@
   ch.SetIceRole(ICEROLE_CONTROLLED);
   ch.MaybeStartGathering();
   // A minimal STUN message with prflx priority.
-  IceMessage request;
-  request.SetType(STUN_BINDING_REQUEST);
+  IceMessage request(STUN_BINDING_REQUEST);
   request.AddAttribute(std::make_unique<StunByteStringAttribute>(
       STUN_ATTR_USERNAME, kIceUfrag[1]));
   uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
@@ -4268,8 +4265,7 @@
 
   // Now another STUN message with an unknown address and use_candidate will
   // nominate the selected connection.
-  IceMessage request;
-  request.SetType(STUN_BINDING_REQUEST);
+  IceMessage request(STUN_BINDING_REQUEST);
   request.AddAttribute(std::make_unique<StunByteStringAttribute>(
       STUN_ATTR_USERNAME, kIceUfrag[1]));
   uint32_t prflx_priority = ICE_TYPE_PREFERENCE_PRFLX << 24;
diff --git a/p2p/base/port_unittest.cc b/p2p/base/port_unittest.cc
index 5ef191b..5b2ac8a 100644
--- a/p2p/base/port_unittest.cc
+++ b/p2p/base/port_unittest.cc
@@ -3409,8 +3409,7 @@
   ASSERT_EQ(response2->type(), GOOG_PING_RESPONSE);
 
   // But rather than the RESPONSE...feedback an error.
-  StunMessage error_response;
-  error_response.SetType(GOOG_PING_ERROR_RESPONSE);
+  StunMessage error_response(GOOG_PING_ERROR_RESPONSE);
   error_response.SetTransactionIdForTesting(response2->transaction_id());
   error_response.AddMessageIntegrity32("rpass");
   rtc::ByteBufferWriter buf;
diff --git a/p2p/base/turn_port.cc b/p2p/base/turn_port.cc
index 6cb3da4..9f8c8d2 100644
--- a/p2p/base/turn_port.cc
+++ b/p2p/base/turn_port.cc
@@ -1649,7 +1649,7 @@
       this, &TurnCreatePermissionRequest::OnEntryDestroyed);
   StunMessage* message = mutable_msg();
   // Create the request as indicated in RFC5766, Section 9.1.
-  message->SetType(TURN_CREATE_PERMISSION_REQUEST);
+  RTC_DCHECK_EQ(message->type(), TURN_CREATE_PERMISSION_REQUEST);
   message->AddAttribute(std::make_unique<StunXorAddressAttribute>(
       STUN_ATTR_XOR_PEER_ADDRESS, ext_addr_));
   if (port_->field_trials_ &&
diff --git a/test/network/network_emulation_unittest.cc b/test/network/network_emulation_unittest.cc
index ccc9c72..e985ae1 100644
--- a/test/network/network_emulation_unittest.cc
+++ b/test/network/network_emulation_unittest.cc
@@ -651,8 +651,7 @@
   int port = ep->BindReceiver(0, &recv).value();
 
   // Construct a STUN BINDING.
-  cricket::StunMessage ping;
-  ping.SetType(cricket::STUN_BINDING_REQUEST);
+  cricket::StunMessage ping(cricket::STUN_BINDING_REQUEST);
   rtc::ByteBufferWriter buf;
   ping.Write(&buf);
   rtc::CopyOnWriteBuffer packet(buf.Data(), buf.Length());