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}
This commit is contained in:
Tommi 2024-02-17 12:41:42 +01:00 committed by WebRTC LUCI CQ
parent 600503ae26
commit 0ba663c245
7 changed files with 21 additions and 33 deletions

View File

@ -112,9 +112,10 @@ std::string Candidate::ToStringInternal(bool sensitive) const {
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();
}

View File

@ -1330,11 +1330,11 @@ std::string Connection::ToString() const {
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_)]

View File

@ -1416,7 +1416,8 @@ bool P2PTransportChannel::CreateConnection(PortInterface* port,
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;
}
}

View File

@ -589,9 +589,9 @@ class P2PTransportChannelTestBase : public ::testing::Test,
// 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 @@ class P2PTransportChannelTestBase : public ::testing::Test,
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 @@ class P2PTransportChannelTestBase : public ::testing::Test,
// 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 @@ class P2PTransportChannelTestBase : public ::testing::Test,
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);

View File

@ -361,7 +361,7 @@ class PeerConnectionIceTest
<< " != " << 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()) {

View File

@ -164,19 +164,6 @@ std::string RTCMediaSourceStatsIDFromKindAndAttachment(
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 @@ const std::string& ProduceIceCandidateStats(Timestamp timestamp,
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();

View File

@ -1120,7 +1120,7 @@ bool ParseCandidate(absl::string_view message,
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;