Change a few uses of Candidate::type() to Candidate::type_name()
Switch to type_name() for things like logging since `type()` will
change to returning an enumeration value.
The functional change that this has is that log statements and
Connection::ToString() (used for logging) will contain "host"
instead of "local" and "srflx" instead of "stun".
Bug: webrtc:15846
Change-Id: I35c50d026e4578a25d51765d59c6f2e01b850c94
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/339180
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41757}
diff --git a/api/candidate.cc b/api/candidate.cc
index 8969b06..0a1c359 100644
--- a/api/candidate.cc
+++ b/api/candidate.cc
@@ -112,9 +112,10 @@
std::string related_address = sensitive ? related_address_.ToSensitiveString()
: related_address_.ToString();
ost << "Cand[" << transport_name_ << ":" << foundation_ << ":" << component_
- << ":" << protocol_ << ":" << priority_ << ":" << address << ":" << type_
- << ":" << related_address << ":" << username_ << ":" << password_ << ":"
- << network_id_ << ":" << network_cost_ << ":" << generation_ << "]";
+ << ":" << protocol_ << ":" << priority_ << ":" << address << ":"
+ << type_name() << ":" << related_address << ":" << username_ << ":"
+ << password_ << ":" << network_id_ << ":" << network_cost_ << ":"
+ << generation_ << "]";
return ost.Release();
}
diff --git a/p2p/base/connection.cc b/p2p/base/connection.cc
index 3809f12..3f0c9c2 100644
--- a/p2p/base/connection.cc
+++ b/p2p/base/connection.cc
@@ -1330,11 +1330,11 @@
const Candidate& local = local_candidate();
const Candidate& remote = remote_candidate();
ss << local.id() << ":" << local.component() << ":" << local.generation()
- << ":" << local.type() << ":" << local.protocol() << ":"
+ << ":" << local.type_name() << ":" << local.protocol() << ":"
<< local.address().ToSensitiveString() << "->" << remote.id() << ":"
- << remote.component() << ":" << remote.priority() << ":" << remote.type()
- << ":" << remote.protocol() << ":" << remote.address().ToSensitiveString()
- << "|";
+ << remote.component() << ":" << remote.priority() << ":"
+ << remote.type_name() << ":" << remote.protocol() << ":"
+ << remote.address().ToSensitiveString() << "|";
ss << CONNECT_STATE_ABBREV[connected_] << RECEIVE_STATE_ABBREV[receiving_]
<< WRITE_STATE_ABBREV[write_state_] << ICESTATE[static_cast<int>(state_)]
diff --git a/p2p/base/p2p_transport_channel.cc b/p2p/base/p2p_transport_channel.cc
index 2f18f1d..eb3553b 100644
--- a/p2p/base/p2p_transport_channel.cc
+++ b/p2p/base/p2p_transport_channel.cc
@@ -1416,7 +1416,8 @@
if ((port->Type() != remote_candidate.type()) &&
(port->Type() == RELAY_PORT_TYPE || remote_candidate.is_relay())) {
RTC_LOG(LS_INFO) << ToString() << ": skip creating connection "
- << port->Type() << " to " << remote_candidate.type();
+ << port->Type() << " to "
+ << remote_candidate.type_name();
return false;
}
}
diff --git a/p2p/base/p2p_transport_channel_unittest.cc b/p2p/base/p2p_transport_channel_unittest.cc
index 79e984c..b180ab8 100644
--- a/p2p/base/p2p_transport_channel_unittest.cc
+++ b/p2p/base/p2p_transport_channel_unittest.cc
@@ -589,9 +589,9 @@
// on the local and remote candidate of ep1_ch1, match. This can be
// used in an EXPECT_TRUE_WAIT.
bool CheckCandidate1(const Result& expected) {
- const std::string& local_type = LocalCandidate(ep1_ch1())->type();
+ auto local_type = LocalCandidate(ep1_ch1())->type();
const std::string& local_protocol = LocalCandidate(ep1_ch1())->protocol();
- const std::string& remote_type = RemoteCandidate(ep1_ch1())->type();
+ auto remote_type = RemoteCandidate(ep1_ch1())->type();
const std::string& remote_protocol = RemoteCandidate(ep1_ch1())->protocol();
return (local_protocol == expected.controlling_protocol &&
remote_protocol == expected.controlled_protocol &&
@@ -608,9 +608,9 @@
return;
}
- const std::string& local_type = LocalCandidate(ep1_ch1())->type();
+ auto local_type = LocalCandidate(ep1_ch1())->type();
const std::string& local_protocol = LocalCandidate(ep1_ch1())->protocol();
- const std::string& remote_type = RemoteCandidate(ep1_ch1())->type();
+ auto remote_type = RemoteCandidate(ep1_ch1())->type();
const std::string& remote_protocol = RemoteCandidate(ep1_ch1())->protocol();
EXPECT_EQ(expected.controlling_type, local_type);
EXPECT_EQ(expected.controlled_type, remote_type);
@@ -622,9 +622,9 @@
// on the local and remote candidate of ep2_ch1, match. This can be
// used in an EXPECT_TRUE_WAIT.
bool CheckCandidate2(const Result& expected) {
- const std::string& local_type = LocalCandidate(ep2_ch1())->type();
+ auto local_type = LocalCandidate(ep2_ch1())->type();
const std::string& local_protocol = LocalCandidate(ep2_ch1())->protocol();
- const std::string& remote_type = RemoteCandidate(ep2_ch1())->type();
+ auto remote_type = RemoteCandidate(ep2_ch1())->type();
const std::string& remote_protocol = RemoteCandidate(ep2_ch1())->protocol();
return (local_protocol == expected.controlled_protocol &&
remote_protocol == expected.controlling_protocol &&
@@ -641,9 +641,9 @@
return;
}
- const std::string& local_type = LocalCandidate(ep2_ch1())->type();
+ auto local_type = LocalCandidate(ep2_ch1())->type();
const std::string& local_protocol = LocalCandidate(ep2_ch1())->protocol();
- const std::string& remote_type = RemoteCandidate(ep2_ch1())->type();
+ auto remote_type = RemoteCandidate(ep2_ch1())->type();
const std::string& remote_protocol = RemoteCandidate(ep2_ch1())->protocol();
EXPECT_EQ(expected.controlled_type, local_type);
EXPECT_EQ(expected.controlling_type, remote_type);
diff --git a/pc/peer_connection_ice_unittest.cc b/pc/peer_connection_ice_unittest.cc
index bd4848c..267cca4 100644
--- a/pc/peer_connection_ice_unittest.cc
+++ b/pc/peer_connection_ice_unittest.cc
@@ -361,7 +361,7 @@
<< " != " << b.address().ToString();
}
if (a.type() != b.type()) {
- failure_info << "\ntype: " << a.type() << " != " << b.type();
+ failure_info << "\ntype: " << a.type_name() << " != " << b.type_name();
}
std::string failure_info_str = failure_info.str();
if (failure_info_str.empty()) {
diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc
index b9492c9..a49e8ef 100644
--- a/pc/rtc_stats_collector.cc
+++ b/pc/rtc_stats_collector.cc
@@ -164,19 +164,6 @@
return sb.str();
}
-const char* CandidateTypeToRTCIceCandidateType(const cricket::Candidate& c) {
- if (c.is_local())
- return "host";
- if (c.is_stun())
- return "srflx";
- if (c.is_prflx())
- return "prflx";
- if (c.is_relay())
- return "relay";
- RTC_DCHECK_NOTREACHED();
- return nullptr;
-}
-
const char* DataStateToRTCDataChannelState(
DataChannelInterface::DataState state) {
switch (state) {
@@ -998,8 +985,7 @@
candidate_stats->address = candidate.address().ipaddr().ToString();
candidate_stats->port = static_cast<int32_t>(candidate.address().port());
candidate_stats->protocol = candidate.protocol();
- candidate_stats->candidate_type =
- CandidateTypeToRTCIceCandidateType(candidate);
+ candidate_stats->candidate_type = candidate.type_name();
candidate_stats->priority = static_cast<int32_t>(candidate.priority());
candidate_stats->foundation = candidate.foundation();
auto related_address = candidate.related_address();
diff --git a/pc/webrtc_sdp.cc b/pc/webrtc_sdp.cc
index 1069a18..ea9c858 100644
--- a/pc/webrtc_sdp.cc
+++ b/pc/webrtc_sdp.cc
@@ -1120,7 +1120,7 @@
return ParseFailed(first_line, "Unsupported transport type.", error);
}
- std::string candidate_type;
+ absl::string_view candidate_type;
const absl::string_view type = fields[7];
if (type == kCandidateHost) {
candidate_type = cricket::LOCAL_PORT_TYPE;