Remove vestiges of GTURN

and update some usage to use the "correct" stun attribute names

BUG=webrtc:42229250

Change-Id: If0c34d1d9b399766d7073661ea2a5515100256a5
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/359440
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Philipp Hancke <phancke@meta.com>
Cr-Commit-Position: refs/heads/main@{#42810}
diff --git a/api/transport/stun.cc b/api/transport/stun.cc
index 79d632b..9a355b2 100644
--- a/api/transport/stun.cc
+++ b/api/transport/stun.cc
@@ -112,7 +112,6 @@
 const char STUN_ERROR_REASON_ROLE_CONFLICT[] = "Role Conflict";
 const char STUN_ERROR_REASON_SERVER_ERROR[] = "Server Error";
 
-const char TURN_MAGIC_COOKIE_VALUE[] = {'\x72', '\xC6', '\x4B', '\xC6'};
 const char EMPTY_TRANSACTION_ID[] = "0000000000000000";
 const uint32_t STUN_FINGERPRINT_XOR_VALUE = 0x5354554E;
 const int SERVER_NOT_REACHABLE_ERROR = 701;
@@ -1444,36 +1443,11 @@
   return copy;
 }
 
-StunAttributeValueType RelayMessage::GetAttributeValueType(int type) const {
-  switch (type) {
-    case STUN_ATTR_LIFETIME:
-      return STUN_VALUE_UINT32;
-    case STUN_ATTR_MAGIC_COOKIE:
-      return STUN_VALUE_BYTE_STRING;
-    case STUN_ATTR_BANDWIDTH:
-      return STUN_VALUE_UINT32;
-    case STUN_ATTR_DESTINATION_ADDRESS:
-      return STUN_VALUE_ADDRESS;
-    case STUN_ATTR_SOURCE_ADDRESS2:
-      return STUN_VALUE_ADDRESS;
-    case STUN_ATTR_DATA:
-      return STUN_VALUE_BYTE_STRING;
-    case STUN_ATTR_OPTIONS:
-      return STUN_VALUE_UINT32;
-    default:
-      return StunMessage::GetAttributeValueType(type);
-  }
-}
-
-StunMessage* RelayMessage::CreateNew() const {
-  return new RelayMessage();
-}
-
 StunAttributeValueType TurnMessage::GetAttributeValueType(int type) const {
   switch (type) {
     case STUN_ATTR_CHANNEL_NUMBER:
       return STUN_VALUE_UINT32;
-    case STUN_ATTR_TURN_LIFETIME:
+    case STUN_ATTR_LIFETIME:
       return STUN_VALUE_UINT32;
     case STUN_ATTR_XOR_PEER_ADDRESS:
       return STUN_VALUE_XOR_ADDRESS;
diff --git a/api/transport/stun.h b/api/transport/stun.h
index 035de89..ef5b08e 100644
--- a/api/transport/stun.h
+++ b/api/transport/stun.h
@@ -649,45 +649,6 @@
     const StunAttribute& attribute,
     rtc::ByteBufferWriter* tmp_buffer_ptr = 0);
 
-// TODO(?): Move the TURN/ICE stuff below out to separate files.
-extern const char TURN_MAGIC_COOKIE_VALUE[4];
-
-// "GTURN" STUN methods.
-// TODO(?): Rename these methods to GTURN_ to make it clear they aren't
-// part of standard STUN/TURN.
-enum RelayMessageType {
-  // For now, using the same defs from TurnMessageType below.
-  // STUN_ALLOCATE_REQUEST              = 0x0003,
-  // STUN_ALLOCATE_RESPONSE             = 0x0103,
-  // STUN_ALLOCATE_ERROR_RESPONSE       = 0x0113,
-  STUN_SEND_REQUEST = 0x0004,
-  STUN_SEND_RESPONSE = 0x0104,
-  STUN_SEND_ERROR_RESPONSE = 0x0114,
-  STUN_DATA_INDICATION = 0x0115,
-};
-
-// "GTURN"-specific STUN attributes.
-// TODO(?): Rename these attributes to GTURN_ to avoid conflicts.
-enum RelayAttributeType {
-  STUN_ATTR_LIFETIME = 0x000d,             // UInt32
-  STUN_ATTR_MAGIC_COOKIE = 0x000f,         // ByteString, 4 bytes
-  STUN_ATTR_BANDWIDTH = 0x0010,            // UInt32
-  STUN_ATTR_DESTINATION_ADDRESS = 0x0011,  // Address
-  STUN_ATTR_SOURCE_ADDRESS2 = 0x0012,      // Address
-  STUN_ATTR_DATA = 0x0013,                 // ByteString
-  STUN_ATTR_OPTIONS = 0x8001,              // UInt32
-};
-
-// A "GTURN" STUN message.
-class RelayMessage : public StunMessage {
- public:
-  using StunMessage::StunMessage;
-
- protected:
-  StunAttributeValueType GetAttributeValueType(int type) const override;
-  StunMessage* CreateNew() const override;
-};
-
 // Defined in TURN RFC 5766.
 enum TurnMessageType : uint16_t {
   STUN_ALLOCATE_REQUEST = 0x0003,
@@ -707,19 +668,15 @@
 };
 
 enum TurnAttributeType {
-  STUN_ATTR_CHANNEL_NUMBER = 0x000C,    // UInt32
-  STUN_ATTR_TURN_LIFETIME = 0x000d,     // UInt32
-  STUN_ATTR_XOR_PEER_ADDRESS = 0x0012,  // XorAddress
-  // TODO(mallinath) - Uncomment after RelayAttributes are renamed.
-  // STUN_ATTR_DATA                     = 0x0013,  // ByteString
+  STUN_ATTR_CHANNEL_NUMBER = 0x000C,       // UInt32
+  STUN_ATTR_LIFETIME = 0x000d,             // UInt32
+  STUN_ATTR_XOR_PEER_ADDRESS = 0x0012,     // XorAddress
+  STUN_ATTR_DATA = 0x0013,                 // ByteString
   STUN_ATTR_XOR_RELAYED_ADDRESS = 0x0016,  // XorAddress
   STUN_ATTR_EVEN_PORT = 0x0018,            // ByteString, 1 byte.
   STUN_ATTR_REQUESTED_TRANSPORT = 0x0019,  // UInt32
   STUN_ATTR_DONT_FRAGMENT = 0x001A,        // No content, Length = 0
   STUN_ATTR_RESERVATION_TOKEN = 0x0022,    // ByteString, 8 bytes.
-  // TODO(mallinath) - Rename STUN_ATTR_TURN_LIFETIME to STUN_ATTR_LIFETIME and
-  // STUN_ATTR_TURN_DATA to STUN_ATTR_DATA. Also rename RelayMessage attributes
-  // by appending G to attribute name.
 };
 
 // RFC 5766-defined errors.
diff --git a/api/transport/stun_unittest.cc b/api/transport/stun_unittest.cc
index 203e831..5437027 100644
--- a/api/transport/stun_unittest.cc
+++ b/api/transport/stun_unittest.cc
@@ -881,14 +881,14 @@
 
 // Test that we don't care what order we set the parts of an address
 TEST_F(StunTest, CreateAddressInArbitraryOrder) {
-  auto addr = StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS);
+  auto addr = StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS);
   // Port first
   addr->SetPort(kTestMessagePort1);
   addr->SetIP(rtc::IPAddress(kIPv4TestAddress1));
   ASSERT_EQ(kTestMessagePort1, addr->port());
   ASSERT_EQ(rtc::IPAddress(kIPv4TestAddress1), addr->ipaddr());
 
-  auto addr2 = StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS);
+  auto addr2 = StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS);
   // IP first
   addr2->SetIP(rtc::IPAddress(kIPv4TestAddress1));
   addr2->SetPort(kTestMessagePort2);
@@ -1426,154 +1426,6 @@
       reinterpret_cast<const char*>(buf1.Data()), buf1.Length()));
 }
 
-// Sample "GTURN" relay message.
-// clang-format off
-// clang formatting doesn't respect inline comments.
-static const uint8_t kRelayMessage[] = {
-  0x00, 0x01, 0x00, 88,    // message header
-  0x21, 0x12, 0xA4, 0x42,  // magic cookie
-  '0', '1', '2', '3',      // transaction id
-  '4', '5', '6', '7',
-  '8', '9', 'a', 'b',
-  0x00, 0x01, 0x00, 8,     // mapped address
-  0x00, 0x01, 0x00, 13,
-  0x00, 0x00, 0x00, 17,
-  0x00, 0x06, 0x00, 12,    // username
-  'a', 'b', 'c', 'd',
-  'e', 'f', 'g', 'h',
-  'i', 'j', 'k', 'l',
-  0x00, 0x0d, 0x00, 4,     // lifetime
-  0x00, 0x00, 0x00, 11,
-  0x00, 0x0f, 0x00, 4,     // magic cookie
-  0x72, 0xc6, 0x4b, 0xc6,
-  0x00, 0x10, 0x00, 4,     // bandwidth
-  0x00, 0x00, 0x00, 6,
-  0x00, 0x11, 0x00, 8,     // destination address
-  0x00, 0x01, 0x00, 13,
-  0x00, 0x00, 0x00, 17,
-  0x00, 0x12, 0x00, 8,     // source address 2
-  0x00, 0x01, 0x00, 13,
-  0x00, 0x00, 0x00, 17,
-  0x00, 0x13, 0x00, 7,     // data
-  'a', 'b', 'c', 'd',
-  'e', 'f', 'g', 0         // DATA must be padded per rfc5766.
-};
-// clang-format on
-
-// Test that we can read the GTURN-specific fields.
-TEST_F(StunTest, ReadRelayMessage) {
-  RelayMessage msg;
-
-  rtc::ByteBufferReader buf(kRelayMessage);
-  EXPECT_TRUE(msg.Read(&buf));
-
-  EXPECT_EQ(STUN_BINDING_REQUEST, msg.type());
-  EXPECT_EQ(sizeof(kRelayMessage) - 20, msg.length());
-  EXPECT_EQ("0123456789ab", msg.transaction_id());
-
-  RelayMessage msg2(STUN_BINDING_REQUEST, "0123456789ab");
-
-  in_addr legacy_in_addr;
-  legacy_in_addr.s_addr = htonl(17U);
-  rtc::IPAddress legacy_ip(legacy_in_addr);
-
-  const StunAddressAttribute* addr = msg.GetAddress(STUN_ATTR_MAPPED_ADDRESS);
-  ASSERT_TRUE(addr != NULL);
-  EXPECT_EQ(1, addr->family());
-  EXPECT_EQ(13, addr->port());
-  EXPECT_EQ(legacy_ip, addr->ipaddr());
-
-  auto addr2 = StunAttribute::CreateAddress(STUN_ATTR_MAPPED_ADDRESS);
-  addr2->SetPort(13);
-  addr2->SetIP(legacy_ip);
-  msg2.AddAttribute(std::move(addr2));
-
-  const StunByteStringAttribute* bytes = msg.GetByteString(STUN_ATTR_USERNAME);
-  ASSERT_TRUE(bytes != NULL);
-  EXPECT_EQ(12U, bytes->length());
-  EXPECT_EQ("abcdefghijkl", bytes->string_view());
-
-  auto bytes2 = StunAttribute::CreateByteString(STUN_ATTR_USERNAME);
-  bytes2->CopyBytes("abcdefghijkl");
-  msg2.AddAttribute(std::move(bytes2));
-
-  const StunUInt32Attribute* uval = msg.GetUInt32(STUN_ATTR_LIFETIME);
-  ASSERT_TRUE(uval != NULL);
-  EXPECT_EQ(11U, uval->value());
-
-  auto uval2 = StunAttribute::CreateUInt32(STUN_ATTR_LIFETIME);
-  uval2->SetValue(11);
-  msg2.AddAttribute(std::move(uval2));
-
-  bytes = msg.GetByteString(STUN_ATTR_MAGIC_COOKIE);
-  ASSERT_TRUE(bytes != NULL);
-  EXPECT_EQ(4U, bytes->length());
-  EXPECT_EQ(0, memcmp(bytes->array_view().data(), TURN_MAGIC_COOKIE_VALUE,
-                      sizeof(TURN_MAGIC_COOKIE_VALUE)));
-
-  bytes2 = StunAttribute::CreateByteString(STUN_ATTR_MAGIC_COOKIE);
-  bytes2->CopyBytes(reinterpret_cast<const char*>(TURN_MAGIC_COOKIE_VALUE),
-                    sizeof(TURN_MAGIC_COOKIE_VALUE));
-  msg2.AddAttribute(std::move(bytes2));
-
-  uval = msg.GetUInt32(STUN_ATTR_BANDWIDTH);
-  ASSERT_TRUE(uval != NULL);
-  EXPECT_EQ(6U, uval->value());
-
-  uval2 = StunAttribute::CreateUInt32(STUN_ATTR_BANDWIDTH);
-  uval2->SetValue(6);
-  msg2.AddAttribute(std::move(uval2));
-
-  addr = msg.GetAddress(STUN_ATTR_DESTINATION_ADDRESS);
-  ASSERT_TRUE(addr != NULL);
-  EXPECT_EQ(1, addr->family());
-  EXPECT_EQ(13, addr->port());
-  EXPECT_EQ(legacy_ip, addr->ipaddr());
-
-  addr2 = StunAttribute::CreateAddress(STUN_ATTR_DESTINATION_ADDRESS);
-  addr2->SetPort(13);
-  addr2->SetIP(legacy_ip);
-  msg2.AddAttribute(std::move(addr2));
-
-  addr = msg.GetAddress(STUN_ATTR_SOURCE_ADDRESS2);
-  ASSERT_TRUE(addr != NULL);
-  EXPECT_EQ(1, addr->family());
-  EXPECT_EQ(13, addr->port());
-  EXPECT_EQ(legacy_ip, addr->ipaddr());
-
-  addr2 = StunAttribute::CreateAddress(STUN_ATTR_SOURCE_ADDRESS2);
-  addr2->SetPort(13);
-  addr2->SetIP(legacy_ip);
-  msg2.AddAttribute(std::move(addr2));
-
-  bytes = msg.GetByteString(STUN_ATTR_DATA);
-  ASSERT_TRUE(bytes != NULL);
-  EXPECT_EQ(7U, bytes->length());
-  EXPECT_EQ("abcdefg", bytes->string_view());
-
-  bytes2 = StunAttribute::CreateByteString(STUN_ATTR_DATA);
-  bytes2->CopyBytes("abcdefg");
-  msg2.AddAttribute(std::move(bytes2));
-
-  rtc::ByteBufferWriter out;
-  EXPECT_TRUE(msg.Write(&out));
-  EXPECT_EQ(sizeof(kRelayMessage), out.Length());
-  size_t len1 = out.Length();
-  rtc::ByteBufferReader read_buf(out);
-  std::string outstring;
-  read_buf.ReadString(&outstring, len1);
-  EXPECT_EQ(0, memcmp(outstring.c_str(), kRelayMessage, len1));
-
-  rtc::ByteBufferWriter out2;
-  EXPECT_TRUE(msg2.Write(&out2));
-  EXPECT_EQ(sizeof(kRelayMessage), out2.Length());
-  size_t len2 = out2.Length();
-  rtc::ByteBufferReader read_buf2(out2);
-  std::string outstring2;
-  read_buf2.ReadString(&outstring2, len2);
-  EXPECT_EQ(0, memcmp(outstring2.c_str(), kRelayMessage, len2));
-}
-
 // Test that we can remove attribute from a message.
 TEST_F(StunTest, RemoveAttribute) {
   StunMessage msg;
diff --git a/p2p/base/turn_port.cc b/p2p/base/turn_port.cc
index e58d03e..1745019 100644
--- a/p2p/base/turn_port.cc
+++ b/p2p/base/turn_port.cc
@@ -1417,10 +1417,10 @@
   }
 
   const StunUInt32Attribute* lifetime_attr =
-      response->GetUInt32(STUN_ATTR_TURN_LIFETIME);
+      response->GetUInt32(STUN_ATTR_LIFETIME);
   if (!lifetime_attr) {
     RTC_LOG(LS_WARNING) << port_->ToString()
-                        << ": Missing STUN_ATTR_TURN_LIFETIME attribute in "
+                        << ": Missing STUN_ATTR_LIFETIME attribute in "
                            "allocate success response";
     return;
   }
@@ -1587,10 +1587,10 @@
 
   // Check mandatory attributes as indicated in RFC5766, Section 7.3.
   const StunUInt32Attribute* lifetime_attr =
-      response->GetUInt32(STUN_ATTR_TURN_LIFETIME);
+      response->GetUInt32(STUN_ATTR_LIFETIME);
   if (!lifetime_attr) {
     RTC_LOG(LS_WARNING) << port_->ToString()
-                        << ": Missing STUN_ATTR_TURN_LIFETIME attribute in "
+                        << ": Missing STUN_ATTR_LIFETIME attribute in "
                            "refresh success response.";
     return;
   }