diff --git a/p2p/base/basic_ice_controller.cc b/p2p/base/basic_ice_controller.cc index a0ff4cf144..182845cdd7 100644 --- a/p2p/base/basic_ice_controller.cc +++ b/p2p/base/basic_ice_controller.cc @@ -565,9 +565,9 @@ bool BasicIceController::ReadyToSend(const Connection* connection) const { bool BasicIceController::PresumedWritable(const Connection* conn) const { return (conn->write_state() == Connection::STATE_WRITE_INIT && config_.presume_writable_when_fully_relayed && - conn->local_candidate().type() == RELAY_PORT_TYPE && - (conn->remote_candidate().type() == RELAY_PORT_TYPE || - conn->remote_candidate().type() == PRFLX_PORT_TYPE)); + conn->local_candidate().is_relay() && + (conn->remote_candidate().is_relay() || + conn->remote_candidate().is_prflx())); } // Compare two connections based on their writing, receiving, and connected diff --git a/p2p/base/connection.cc b/p2p/base/connection.cc index d0e6f1bff8..bf07dec607 100644 --- a/p2p/base/connection.cc +++ b/p2p/base/connection.cc @@ -590,10 +590,8 @@ void Connection::HandleStunBindingOrGoogPingRequest(IceMessage* msg) { // This connection should now be receiving. ReceivedPing(msg->transaction_id()); if (field_trials_->extra_ice_ping && last_ping_response_received_ == 0) { - if (local_candidate().type() == RELAY_PORT_TYPE || - local_candidate().type() == PRFLX_PORT_TYPE || - remote_candidate().type() == RELAY_PORT_TYPE || - remote_candidate().type() == PRFLX_PORT_TYPE) { + if (local_candidate().is_relay() || local_candidate().is_prflx() || + remote_candidate().is_relay() || remote_candidate().is_prflx()) { const int64_t now = rtc::TimeMillis(); if (last_ping_sent_ + kMinExtraPingDelayMs <= now) { RTC_LOG(LS_INFO) << ToString() @@ -1579,8 +1577,7 @@ void Connection::MaybeSetRemoteIceParametersAndGeneration( void Connection::MaybeUpdatePeerReflexiveCandidate( const Candidate& new_candidate) { - if (remote_candidate_.type() == PRFLX_PORT_TYPE && - new_candidate.type() != PRFLX_PORT_TYPE && + if (remote_candidate_.is_prflx() && !new_candidate.is_prflx() && remote_candidate_.protocol() == new_candidate.protocol() && remote_candidate_.address() == new_candidate.address() && remote_candidate_.username() == new_candidate.username() && diff --git a/p2p/base/p2p_transport_channel.cc b/p2p/base/p2p_transport_channel.cc index 070a25b511..35d7f85d69 100644 --- a/p2p/base/p2p_transport_channel.cc +++ b/p2p/base/p2p_transport_channel.cc @@ -1416,8 +1416,7 @@ bool P2PTransportChannel::CreateConnection(PortInterface* port, if (ice_field_trials_.skip_relay_to_non_relay_connections) { if ((port->Type() != remote_candidate.type()) && - (port->Type() == RELAY_PORT_TYPE || - remote_candidate.type() == RELAY_PORT_TYPE)) { + (port->Type() == RELAY_PORT_TYPE || remote_candidate.is_relay())) { RTC_LOG(LS_INFO) << ToString() << ": skip creating connection " << port->Type() << " to " << remote_candidate.type(); return false; @@ -1708,9 +1707,9 @@ bool P2PTransportChannel::PresumedWritable(const Connection* conn) const { RTC_DCHECK_RUN_ON(network_thread_); return (conn->write_state() == Connection::STATE_WRITE_INIT && config_.presume_writable_when_fully_relayed && - conn->local_candidate().type() == RELAY_PORT_TYPE && - (conn->remote_candidate().type() == RELAY_PORT_TYPE || - conn->remote_candidate().type() == PRFLX_PORT_TYPE)); + conn->local_candidate().is_relay() && + (conn->remote_candidate().is_relay() || + conn->remote_candidate().is_prflx())); } void P2PTransportChannel::UpdateState() { @@ -1757,19 +1756,18 @@ bool P2PTransportChannel::PruneConnections( rtc::NetworkRoute P2PTransportChannel::ConfigureNetworkRoute( const Connection* conn) { RTC_DCHECK_RUN_ON(network_thread_); - return { - .connected = ReadyToSend(conn), - .local = CreateRouteEndpointFromCandidate( - /* local= */ true, conn->local_candidate(), - /* uses_turn= */ - conn->port()->Type() == RELAY_PORT_TYPE), - .remote = CreateRouteEndpointFromCandidate( - /* local= */ false, conn->remote_candidate(), - /* uses_turn= */ conn->remote_candidate().type() == RELAY_PORT_TYPE), - .last_sent_packet_id = last_sent_packet_id_, - .packet_overhead = - conn->local_candidate().address().ipaddr().overhead() + - GetProtocolOverhead(conn->local_candidate().protocol())}; + return {.connected = ReadyToSend(conn), + .local = CreateRouteEndpointFromCandidate( + /* local= */ true, conn->local_candidate(), + /* uses_turn= */ + conn->port()->Type() == RELAY_PORT_TYPE), + .remote = CreateRouteEndpointFromCandidate( + /* local= */ false, conn->remote_candidate(), + /* uses_turn= */ conn->remote_candidate().is_relay()), + .last_sent_packet_id = last_sent_packet_id_, + .packet_overhead = + conn->local_candidate().address().ipaddr().overhead() + + GetProtocolOverhead(conn->local_candidate().protocol())}; } void P2PTransportChannel::SwitchSelectedConnection( @@ -2280,7 +2278,7 @@ Candidate P2PTransportChannel::SanitizeRemoteCandidate( bool use_hostname_address = absl::EndsWith(c.address().hostname(), LOCAL_TLD); // Remove the address for prflx remote candidates. See // https://w3c.github.io/webrtc-stats/#dom-rtcicecandidatestats. - use_hostname_address |= c.type() == PRFLX_PORT_TYPE; + use_hostname_address |= c.is_prflx(); return c.ToSanitizedCopy(use_hostname_address, false /* filter_related_address */); } diff --git a/p2p/base/p2p_transport_channel_unittest.cc b/p2p/base/p2p_transport_channel_unittest.cc index b30b2949fe..a0446c7965 100644 --- a/p2p/base/p2p_transport_channel_unittest.cc +++ b/p2p/base/p2p_transport_channel_unittest.cc @@ -5008,7 +5008,7 @@ class P2PTransportChannelMostLikelyToWorkFirstTest Connection* conn = FindNextPingableConnectionAndPingIt(channel_.get()); ASSERT_TRUE(conn != nullptr); EXPECT_EQ(conn->local_candidate().type(), local_candidate_type); - if (conn->local_candidate().type() == RELAY_PORT_TYPE) { + if (conn->local_candidate().is_relay()) { EXPECT_EQ(conn->local_candidate().relay_protocol(), relay_protocol_type); } EXPECT_EQ(conn->remote_candidate().type(), remote_candidate_type); @@ -5420,7 +5420,7 @@ TEST_F(P2PTransportChannelTest, for (const auto& candidates_data : GetEndpoint(0)->saved_candidates_) { const auto& local_candidate_ep1 = candidates_data.candidate; - if (local_candidate_ep1.type() == LOCAL_PORT_TYPE) { + if (local_candidate_ep1.is_local()) { // This is the underlying private IP address of the same candidate at ep1, // and let the mock resolver of ep2 receive the correct resolution. rtc::SocketAddress resolved_address_ep1(local_candidate_ep1.address()); @@ -5449,11 +5449,11 @@ TEST_F(P2PTransportChannelTest, // Check the stats of ep1 seen by ep1. for (const auto& connection_info : ice_transport_stats1.connection_infos) { const auto& local_candidate = connection_info.local_candidate; - if (local_candidate.type() == LOCAL_PORT_TYPE) { + if (local_candidate.is_local()) { EXPECT_TRUE(local_candidate.address().IsUnresolvedIP()); - } else if (local_candidate.type() == STUN_PORT_TYPE) { + } else if (local_candidate.is_stun()) { EXPECT_TRUE(local_candidate.related_address().IsAnyIP()); - } else if (local_candidate.type() == RELAY_PORT_TYPE) { + } else if (local_candidate.is_relay()) { // The related address of the relay candidate should be equal to the // srflx address. Note that NAT is not configured, hence the following // expectation. @@ -5466,11 +5466,11 @@ TEST_F(P2PTransportChannelTest, // Check the stats of ep1 seen by ep2. for (const auto& connection_info : ice_transport_stats2.connection_infos) { const auto& remote_candidate = connection_info.remote_candidate; - if (remote_candidate.type() == LOCAL_PORT_TYPE) { + if (remote_candidate.is_local()) { EXPECT_TRUE(remote_candidate.address().IsUnresolvedIP()); - } else if (remote_candidate.type() == STUN_PORT_TYPE) { + } else if (remote_candidate.is_stun()) { EXPECT_TRUE(remote_candidate.related_address().IsAnyIP()); - } else if (remote_candidate.type() == RELAY_PORT_TYPE) { + } else if (remote_candidate.is_relay()) { EXPECT_EQ(kPublicAddrs[0].ipaddr(), remote_candidate.related_address().ipaddr()); } else { @@ -5592,7 +5592,7 @@ TEST_F(P2PTransportChannelTest, ASSERT_EQ_WAIT(1u, GetEndpoint(0)->saved_candidates_.size(), kMediumTimeout); const auto& candidates_data = GetEndpoint(0)->saved_candidates_[0]; const auto& local_candidate_ep1 = candidates_data.candidate; - ASSERT_TRUE(local_candidate_ep1.type() == LOCAL_PORT_TYPE); + ASSERT_TRUE(local_candidate_ep1.is_local()); // This is the underlying private IP address of the same candidate at ep1, // and let the mock resolver of ep2 receive the correct resolution. rtc::SocketAddress resolved_address_ep1(local_candidate_ep1.address()); @@ -5608,12 +5608,12 @@ TEST_F(P2PTransportChannelTest, const auto pair_ep1 = ep1_ch1()->GetSelectedCandidatePair(); ASSERT_TRUE(pair_ep1.has_value()); - EXPECT_EQ(LOCAL_PORT_TYPE, pair_ep1->local_candidate().type()); + EXPECT_TRUE(pair_ep1->local_candidate().is_local()); EXPECT_TRUE(pair_ep1->local_candidate().address().IsUnresolvedIP()); const auto pair_ep2 = ep2_ch1()->GetSelectedCandidatePair(); ASSERT_TRUE(pair_ep2.has_value()); - EXPECT_EQ(LOCAL_PORT_TYPE, pair_ep2->remote_candidate().type()); + EXPECT_TRUE(pair_ep2->remote_candidate().is_local()); EXPECT_TRUE(pair_ep2->remote_candidate().address().IsUnresolvedIP()); DestroyChannels(); diff --git a/p2p/base/port_allocator.cc b/p2p/base/port_allocator.cc index 9292319b56..16f5afe36c 100644 --- a/p2p/base/port_allocator.cc +++ b/p2p/base/port_allocator.cc @@ -312,8 +312,7 @@ Candidate PortAllocator::SanitizeCandidate(const Candidate& c) const { // For a local host candidate, we need to conceal its IP address candidate if // the mDNS obfuscation is enabled. bool use_hostname_address = - (c.type() == LOCAL_PORT_TYPE || c.type() == PRFLX_PORT_TYPE) && - MdnsObfuscationEnabled(); + (c.is_local() || c.is_prflx()) && MdnsObfuscationEnabled(); // If adapter enumeration is disabled or host candidates are disabled, // clear the raddr of STUN candidates to avoid local address leakage. bool filter_stun_related_address = @@ -326,9 +325,9 @@ Candidate PortAllocator::SanitizeCandidate(const Candidate& c) const { // Sanitize related_address when using MDNS. bool filter_prflx_related_address = MdnsObfuscationEnabled(); bool filter_related_address = - ((c.type() == STUN_PORT_TYPE && filter_stun_related_address) || - (c.type() == RELAY_PORT_TYPE && filter_turn_related_address) || - (c.type() == PRFLX_PORT_TYPE && filter_prflx_related_address)); + ((c.is_stun() && filter_stun_related_address) || + (c.is_relay() && filter_turn_related_address) || + (c.is_prflx() && filter_prflx_related_address)); return c.ToSanitizedCopy(use_hostname_address, filter_related_address); } diff --git a/p2p/base/stun_port.cc b/p2p/base/stun_port.cc index 7acaac6dbe..648933fd9e 100644 --- a/p2p/base/stun_port.cc +++ b/p2p/base/stun_port.cc @@ -285,7 +285,7 @@ Connection* UDPPort::CreateConnection(const Candidate& address, // // See also the definition of MdnsNameRegistrationStatus::kNotStarted in // port.h. - RTC_DCHECK(!SharedSocket() || Candidates()[0].type() == LOCAL_PORT_TYPE || + RTC_DCHECK(!SharedSocket() || Candidates()[0].is_local() || mdns_name_registration_status() != MdnsNameRegistrationStatus::kNotStarted); @@ -616,7 +616,7 @@ bool UDPPort::HasStunCandidateWithAddress( const std::vector& existing_candidates = Candidates(); std::vector::const_iterator it = existing_candidates.begin(); for (; it != existing_candidates.end(); ++it) { - if (it->type() == STUN_PORT_TYPE && it->address() == addr) + if (it->is_stun() && it->address() == addr) return true; } return false; diff --git a/p2p/base/stun_port_unittest.cc b/p2p/base/stun_port_unittest.cc index 04505d26ff..9167081afb 100644 --- a/p2p/base/stun_port_unittest.cc +++ b/p2p/base/stun_port_unittest.cc @@ -445,11 +445,11 @@ TEST_F(StunPortTest, TestStunCandidateGeneratedWithMdnsObfuscationEnabled) { // One of the generated candidates is a local candidate and the other is a // stun candidate. EXPECT_NE(port()->Candidates()[0].type(), port()->Candidates()[1].type()); - if (port()->Candidates()[0].type() == cricket::LOCAL_PORT_TYPE) { - EXPECT_EQ(port()->Candidates()[1].type(), cricket::STUN_PORT_TYPE); + if (port()->Candidates()[0].is_local()) { + EXPECT_TRUE(port()->Candidates()[1].is_stun()); } else { - EXPECT_EQ(port()->Candidates()[0].type(), cricket::STUN_PORT_TYPE); - EXPECT_EQ(port()->Candidates()[1].type(), cricket::LOCAL_PORT_TYPE); + EXPECT_TRUE(port()->Candidates()[0].is_stun()); + EXPECT_TRUE(port()->Candidates()[1].is_local()); } } diff --git a/p2p/base/turn_port.cc b/p2p/base/turn_port.cc index ff50636794..1fb3b38bfd 100644 --- a/p2p/base/turn_port.cc +++ b/p2p/base/turn_port.cc @@ -585,9 +585,8 @@ Connection* TurnPort::CreateConnection(const Candidate& remote_candidate, // and TURN candidate later. for (size_t index = 0; index < Candidates().size(); ++index) { const Candidate& local_candidate = Candidates()[index]; - if (local_candidate.type() == RELAY_PORT_TYPE && - local_candidate.address().family() == - remote_candidate.address().family()) { + if (local_candidate.is_relay() && local_candidate.address().family() == + remote_candidate.address().family()) { ProxyConnection* conn = new ProxyConnection(NewWeakPtr(), index, remote_candidate); // Create an entry, if needed, so we can get our permissions set up diff --git a/p2p/client/basic_port_allocator.cc b/p2p/client/basic_port_allocator.cc index a31dc7038b..e95033efeb 100644 --- a/p2p/client/basic_port_allocator.cc +++ b/p2p/client/basic_port_allocator.cc @@ -126,11 +126,15 @@ bool IsAllowedByCandidateFilter(const Candidate& c, uint32_t filter) { return false; } - if (c.type() == RELAY_PORT_TYPE) { + if (c.is_relay()) { return ((filter & CF_RELAY) != 0); - } else if (c.type() == STUN_PORT_TYPE) { + } + + if (c.is_stun()) { return ((filter & CF_REFLEXIVE) != 0); - } else if (c.type() == LOCAL_PORT_TYPE) { + } + + if (c.is_local()) { if ((filter & CF_REFLEXIVE) && !c.address().IsPrivateIP()) { // We allow host candidates if the filter allows server-reflexive // candidates and the candidate is a public IP. Because we don't generate @@ -143,6 +147,7 @@ bool IsAllowedByCandidateFilter(const Candidate& c, uint32_t filter) { return ((filter & CF_HOST) != 0); } + return false; } diff --git a/p2p/client/basic_port_allocator_unittest.cc b/p2p/client/basic_port_allocator_unittest.cc index 43d552b971..0c3bf6bc23 100644 --- a/p2p/client/basic_port_allocator_unittest.cc +++ b/p2p/client/basic_port_allocator_unittest.cc @@ -2417,7 +2417,7 @@ TEST_F(BasicPortAllocatorTest, HostCandidateAddressIsReplacedByHostname) { for (const auto& candidate : candidates_) { const auto& raddr = candidate.related_address(); - if (candidate.type() == LOCAL_PORT_TYPE) { + if (candidate.is_local()) { EXPECT_FALSE(candidate.address().hostname().empty()); EXPECT_TRUE(raddr.IsNil()); if (candidate.protocol() == UDP_PROTOCOL_NAME) { @@ -2425,13 +2425,13 @@ TEST_F(BasicPortAllocatorTest, HostCandidateAddressIsReplacedByHostname) { } else { ++num_host_tcp_candidates; } - } else if (candidate.type() == STUN_PORT_TYPE) { + } else if (candidate.is_stun()) { // For a srflx candidate, the related address should be set to 0.0.0.0 or // ::0 EXPECT_TRUE(IPIsAny(raddr.ipaddr())); EXPECT_EQ(raddr.port(), 0); ++num_srflx_candidates; - } else if (candidate.type() == RELAY_PORT_TYPE) { + } else if (candidate.is_relay()) { EXPECT_EQ(kNatUdpAddr.ipaddr(), raddr.ipaddr()); EXPECT_EQ(kNatUdpAddr.family(), raddr.family()); ++num_relay_candidates; diff --git a/pc/jsep_session_description.cc b/pc/jsep_session_description.cc index 885c1eb310..db54dbccda 100644 --- a/pc/jsep_session_description.cc +++ b/pc/jsep_session_description.cc @@ -26,6 +26,7 @@ #include "rtc_base/net_helper.h" #include "rtc_base/socket_address.h" +using cricket::Candidate; using cricket::SessionDescription; namespace webrtc { @@ -43,13 +44,13 @@ constexpr int kPreferenceRelayed = 3; constexpr char kDummyAddress[] = "0.0.0.0"; constexpr int kDummyPort = 9; -int GetCandidatePreferenceFromType(const std::string& type) { +int GetCandidatePreferenceFromType(const Candidate& c) { int preference = kPreferenceUnknown; - if (type == cricket::LOCAL_PORT_TYPE) { + if (c.is_local()) { preference = kPreferenceHost; - } else if (type == cricket::STUN_PORT_TYPE) { + } else if (c.is_stun()) { preference = kPreferenceReflexive; - } else if (type == cricket::RELAY_PORT_TYPE) { + } else if (c.is_relay()) { preference = kPreferenceRelayed; } else { preference = kPreferenceUnknown; @@ -78,7 +79,7 @@ void UpdateConnectionAddress( continue; } const int preference = - GetCandidatePreferenceFromType(jsep_candidate->candidate().type()); + GetCandidatePreferenceFromType(jsep_candidate->candidate()); const int family = jsep_candidate->candidate().address().ipaddr().family(); // See if this candidate is more preferable then the current one if it's the // same family. Or if the current family is IPv4 already so we could safely @@ -253,7 +254,7 @@ bool JsepSessionDescription::AddCandidate( return false; } - cricket::Candidate updated_candidate = candidate->candidate(); + Candidate updated_candidate = candidate->candidate(); if (updated_candidate.username().empty()) { updated_candidate.set_username(transport_info->description.ice_ufrag); } @@ -278,7 +279,7 @@ bool JsepSessionDescription::AddCandidate( } size_t JsepSessionDescription::RemoveCandidates( - const std::vector& candidates) { + const std::vector& candidates) { size_t num_removed = 0; for (auto& candidate : candidates) { int mediasection_index = GetMediasectionIndex(candidate); @@ -352,8 +353,7 @@ bool JsepSessionDescription::GetMediasectionIndex( return true; } -int JsepSessionDescription::GetMediasectionIndex( - const cricket::Candidate& candidate) { +int JsepSessionDescription::GetMediasectionIndex(const Candidate& candidate) { // Find the description with a matching transport name of the candidate. const std::string& transport_name = candidate.transport_name(); for (size_t i = 0; i < description_->contents().size(); ++i) { diff --git a/pc/legacy_stats_collector.cc b/pc/legacy_stats_collector.cc index a6a69458c7..135829abc9 100644 --- a/pc/legacy_stats_collector.cc +++ b/pc/legacy_stats_collector.cc @@ -496,17 +496,17 @@ void ExtractStatsFromList( } // namespace -const char* IceCandidateTypeToStatsType(const std::string& candidate_type) { - if (candidate_type == cricket::LOCAL_PORT_TYPE) { +const char* IceCandidateTypeToStatsType(const cricket::Candidate& candidate) { + if (candidate.is_local()) { return STATSREPORT_LOCAL_PORT_TYPE; } - if (candidate_type == cricket::STUN_PORT_TYPE) { + if (candidate.is_stun()) { return STATSREPORT_STUN_PORT_TYPE; } - if (candidate_type == cricket::PRFLX_PORT_TYPE) { + if (candidate.is_prflx()) { return STATSREPORT_PRFLX_PORT_TYPE; } - if (candidate_type == cricket::RELAY_PORT_TYPE) { + if (candidate.is_relay()) { return STATSREPORT_RELAY_PORT_TYPE; } RTC_DCHECK_NOTREACHED(); @@ -844,7 +844,7 @@ StatsReport* LegacyStatsCollector::AddCandidateReport( report->AddInt(StatsReport::kStatsValueNameCandidatePriority, candidate.priority()); report->AddString(StatsReport::kStatsValueNameCandidateType, - IceCandidateTypeToStatsType(candidate.type())); + IceCandidateTypeToStatsType(candidate)); report->AddString(StatsReport::kStatsValueNameCandidateTransportType, candidate.protocol()); } diff --git a/pc/legacy_stats_collector.h b/pc/legacy_stats_collector.h index 1c7aad0636..e0371638ee 100644 --- a/pc/legacy_stats_collector.h +++ b/pc/legacy_stats_collector.h @@ -26,6 +26,7 @@ #include #include "absl/types/optional.h" +#include "api/candidate.h" #include "api/field_trials_view.h" #include "api/legacy_stats_types.h" #include "api/media_stream_interface.h" @@ -45,7 +46,7 @@ namespace webrtc { // Conversion function to convert candidate type string to the corresponding one // from enum RTCStatsIceCandidateType. -const char* IceCandidateTypeToStatsType(const std::string& candidate_type); +const char* IceCandidateTypeToStatsType(const cricket::Candidate& candidate); // Conversion function to convert adapter type to report string which are more // fitting to the general style of http://w3c.github.io/webrtc-stats. This is diff --git a/pc/legacy_stats_collector_unittest.cc b/pc/legacy_stats_collector_unittest.cc index 3099d1188a..5f6140da54 100644 --- a/pc/legacy_stats_collector_unittest.cc +++ b/pc/legacy_stats_collector_unittest.cc @@ -1391,7 +1391,7 @@ TEST_F(LegacyStatsCollectorTest, IceCandidateReport) { ExtractStatsValue(StatsReport::kStatsReportTypeIceLocalCandidate, reports, StatsReport::kStatsValueNameCandidatePriority)); EXPECT_EQ( - IceCandidateTypeToStatsType(cricket::LOCAL_PORT_TYPE), + IceCandidateTypeToStatsType(local), ExtractStatsValue(StatsReport::kStatsReportTypeIceLocalCandidate, reports, StatsReport::kStatsValueNameCandidateType)); EXPECT_EQ( @@ -1421,7 +1421,7 @@ TEST_F(LegacyStatsCollectorTest, IceCandidateReport) { reports, StatsReport::kStatsValueNameCandidatePriority)); EXPECT_EQ( - IceCandidateTypeToStatsType(cricket::PRFLX_PORT_TYPE), + IceCandidateTypeToStatsType(remote), ExtractStatsValue(StatsReport::kStatsReportTypeIceRemoteCandidate, reports, StatsReport::kStatsValueNameCandidateType)); EXPECT_EQ(kNotFound, diff --git a/pc/rtc_stats_collector.cc b/pc/rtc_stats_collector.cc index 4555ff1328..a5a3067fa1 100644 --- a/pc/rtc_stats_collector.cc +++ b/pc/rtc_stats_collector.cc @@ -164,14 +164,14 @@ std::string RTCMediaSourceStatsIDFromKindAndAttachment( return sb.str(); } -const char* CandidateTypeToRTCIceCandidateType(const std::string& type) { - if (type == cricket::LOCAL_PORT_TYPE) +const char* CandidateTypeToRTCIceCandidateType(const cricket::Candidate& c) { + if (c.is_local()) return "host"; - if (type == cricket::STUN_PORT_TYPE) + if (c.is_stun()) return "srflx"; - if (type == cricket::PRFLX_PORT_TYPE) + if (c.is_prflx()) return "prflx"; - if (type == cricket::RELAY_PORT_TYPE) + if (c.is_relay()) return "relay"; RTC_DCHECK_NOTREACHED(); return nullptr; @@ -1001,7 +1001,7 @@ const std::string& ProduceIceCandidateStats(Timestamp timestamp, candidate_stats->port = static_cast(candidate.address().port()); candidate_stats->protocol = candidate.protocol(); candidate_stats->candidate_type = - CandidateTypeToRTCIceCandidateType(candidate.type()); + CandidateTypeToRTCIceCandidateType(candidate); candidate_stats->priority = static_cast(candidate.priority()); candidate_stats->foundation = candidate.foundation(); auto related_address = candidate.related_address(); @@ -2194,14 +2194,4 @@ void RTCStatsCollector::OnSctpDataChannelStateChanged( } } -const char* CandidateTypeToRTCIceCandidateTypeForTesting( - const std::string& type) { - return CandidateTypeToRTCIceCandidateType(type); -} - -const char* DataStateToRTCDataChannelStateForTesting( - DataChannelInterface::DataState state) { - return DataStateToRTCDataChannelState(state); -} - } // namespace webrtc diff --git a/pc/rtc_stats_collector.h b/pc/rtc_stats_collector.h index 4c68e77086..505979c5ea 100644 --- a/pc/rtc_stats_collector.h +++ b/pc/rtc_stats_collector.h @@ -322,11 +322,6 @@ class RTCStatsCollector : public rtc::RefCountInterface { InternalRecord internal_record_; }; -const char* CandidateTypeToRTCIceCandidateTypeForTesting( - const std::string& type); -const char* DataStateToRTCDataChannelStateForTesting( - DataChannelInterface::DataState state); - } // namespace webrtc #endif // PC_RTC_STATS_COLLECTOR_H_ diff --git a/pc/test/integration_test_helpers.h b/pc/test/integration_test_helpers.h index 6838712dcd..7b3f11905d 100644 --- a/pc/test/integration_test_helpers.h +++ b/pc/test/integration_test_helpers.h @@ -1115,7 +1115,7 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver, if (remote_async_dns_resolver_) { const auto& local_candidate = candidate->candidate(); if (local_candidate.address().IsUnresolvedIP()) { - RTC_DCHECK(local_candidate.type() == cricket::LOCAL_PORT_TYPE); + RTC_DCHECK(local_candidate.is_local()); const auto resolved_ip = mdns_responder_->GetMappedAddressForName( local_candidate.address().hostname()); RTC_DCHECK(!resolved_ip.IsNil()); diff --git a/pc/webrtc_sdp.cc b/pc/webrtc_sdp.cc index 5e9d5c2858..060599b3e5 100644 --- a/pc/webrtc_sdp.cc +++ b/pc/webrtc_sdp.cc @@ -771,13 +771,13 @@ static const int kPreferenceHost = 1; static const int kPreferenceReflexive = 2; static const int kPreferenceRelayed = 3; -static int GetCandidatePreferenceFromType(absl::string_view type) { +static int GetCandidatePreferenceFromType(const Candidate& candidate) { int preference = kPreferenceUnknown; - if (type == cricket::LOCAL_PORT_TYPE) { + if (candidate.is_local()) { preference = kPreferenceHost; - } else if (type == cricket::STUN_PORT_TYPE) { + } else if (candidate.is_stun()) { preference = kPreferenceReflexive; - } else if (type == cricket::RELAY_PORT_TYPE) { + } else if (candidate.is_relay()) { preference = kPreferenceRelayed; } else { RTC_DCHECK_NOTREACHED(); @@ -810,7 +810,7 @@ static void GetDefaultDestination(const std::vector& candidates, if (candidate.protocol() != cricket::UDP_PROTOCOL_NAME) { continue; } - const int preference = GetCandidatePreferenceFromType(candidate.type()); + const int preference = GetCandidatePreferenceFromType(candidate); const int family = candidate.address().ipaddr().family(); // See if this candidate is more preferable then the current one if it's the // same family. Or if the current family is IPv4 already so we could safely @@ -2005,13 +2005,13 @@ void BuildCandidate(const std::vector& candidates, // *(SP extension-att-name SP extension-att-value) std::string type; // Map the cricket candidate type to "host" / "srflx" / "prflx" / "relay" - if (candidate.type() == cricket::LOCAL_PORT_TYPE) { + if (candidate.is_local()) { type = kCandidateHost; - } else if (candidate.type() == cricket::STUN_PORT_TYPE) { + } else if (candidate.is_stun()) { type = kCandidateSrflx; - } else if (candidate.type() == cricket::RELAY_PORT_TYPE) { + } else if (candidate.is_relay()) { type = kCandidateRelay; - } else if (candidate.type() == cricket::PRFLX_PORT_TYPE) { + } else if (candidate.is_prflx()) { type = kCandidatePrflx; // Peer reflexive candidate may be signaled for being removed. } else {