mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
Use is_* getters when checking the Candidate type
This removes several references across the code base that depended on the global string constants. Bug: none Change-Id: I007bd4b195c35261039f655f1a8f52e632c3691f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/335320 Commit-Queue: Tomas Gunnarsson <tommi@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#41578}
This commit is contained in:
parent
0206a971f5
commit
0a7fc84887
18 changed files with 92 additions and 108 deletions
|
@ -565,9 +565,9 @@ bool BasicIceController::ReadyToSend(const Connection* connection) const {
|
||||||
bool BasicIceController::PresumedWritable(const Connection* conn) const {
|
bool BasicIceController::PresumedWritable(const Connection* conn) const {
|
||||||
return (conn->write_state() == Connection::STATE_WRITE_INIT &&
|
return (conn->write_state() == Connection::STATE_WRITE_INIT &&
|
||||||
config_.presume_writable_when_fully_relayed &&
|
config_.presume_writable_when_fully_relayed &&
|
||||||
conn->local_candidate().type() == RELAY_PORT_TYPE &&
|
conn->local_candidate().is_relay() &&
|
||||||
(conn->remote_candidate().type() == RELAY_PORT_TYPE ||
|
(conn->remote_candidate().is_relay() ||
|
||||||
conn->remote_candidate().type() == PRFLX_PORT_TYPE));
|
conn->remote_candidate().is_prflx()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compare two connections based on their writing, receiving, and connected
|
// Compare two connections based on their writing, receiving, and connected
|
||||||
|
|
|
@ -590,10 +590,8 @@ void Connection::HandleStunBindingOrGoogPingRequest(IceMessage* msg) {
|
||||||
// This connection should now be receiving.
|
// This connection should now be receiving.
|
||||||
ReceivedPing(msg->transaction_id());
|
ReceivedPing(msg->transaction_id());
|
||||||
if (field_trials_->extra_ice_ping && last_ping_response_received_ == 0) {
|
if (field_trials_->extra_ice_ping && last_ping_response_received_ == 0) {
|
||||||
if (local_candidate().type() == RELAY_PORT_TYPE ||
|
if (local_candidate().is_relay() || local_candidate().is_prflx() ||
|
||||||
local_candidate().type() == PRFLX_PORT_TYPE ||
|
remote_candidate().is_relay() || remote_candidate().is_prflx()) {
|
||||||
remote_candidate().type() == RELAY_PORT_TYPE ||
|
|
||||||
remote_candidate().type() == PRFLX_PORT_TYPE) {
|
|
||||||
const int64_t now = rtc::TimeMillis();
|
const int64_t now = rtc::TimeMillis();
|
||||||
if (last_ping_sent_ + kMinExtraPingDelayMs <= now) {
|
if (last_ping_sent_ + kMinExtraPingDelayMs <= now) {
|
||||||
RTC_LOG(LS_INFO) << ToString()
|
RTC_LOG(LS_INFO) << ToString()
|
||||||
|
@ -1579,8 +1577,7 @@ void Connection::MaybeSetRemoteIceParametersAndGeneration(
|
||||||
|
|
||||||
void Connection::MaybeUpdatePeerReflexiveCandidate(
|
void Connection::MaybeUpdatePeerReflexiveCandidate(
|
||||||
const Candidate& new_candidate) {
|
const Candidate& new_candidate) {
|
||||||
if (remote_candidate_.type() == PRFLX_PORT_TYPE &&
|
if (remote_candidate_.is_prflx() && !new_candidate.is_prflx() &&
|
||||||
new_candidate.type() != PRFLX_PORT_TYPE &&
|
|
||||||
remote_candidate_.protocol() == new_candidate.protocol() &&
|
remote_candidate_.protocol() == new_candidate.protocol() &&
|
||||||
remote_candidate_.address() == new_candidate.address() &&
|
remote_candidate_.address() == new_candidate.address() &&
|
||||||
remote_candidate_.username() == new_candidate.username() &&
|
remote_candidate_.username() == new_candidate.username() &&
|
||||||
|
|
|
@ -1416,8 +1416,7 @@ bool P2PTransportChannel::CreateConnection(PortInterface* port,
|
||||||
|
|
||||||
if (ice_field_trials_.skip_relay_to_non_relay_connections) {
|
if (ice_field_trials_.skip_relay_to_non_relay_connections) {
|
||||||
if ((port->Type() != remote_candidate.type()) &&
|
if ((port->Type() != remote_candidate.type()) &&
|
||||||
(port->Type() == RELAY_PORT_TYPE ||
|
(port->Type() == RELAY_PORT_TYPE || remote_candidate.is_relay())) {
|
||||||
remote_candidate.type() == RELAY_PORT_TYPE)) {
|
|
||||||
RTC_LOG(LS_INFO) << ToString() << ": skip creating connection "
|
RTC_LOG(LS_INFO) << ToString() << ": skip creating connection "
|
||||||
<< port->Type() << " to " << remote_candidate.type();
|
<< port->Type() << " to " << remote_candidate.type();
|
||||||
return false;
|
return false;
|
||||||
|
@ -1708,9 +1707,9 @@ bool P2PTransportChannel::PresumedWritable(const Connection* conn) const {
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
RTC_DCHECK_RUN_ON(network_thread_);
|
||||||
return (conn->write_state() == Connection::STATE_WRITE_INIT &&
|
return (conn->write_state() == Connection::STATE_WRITE_INIT &&
|
||||||
config_.presume_writable_when_fully_relayed &&
|
config_.presume_writable_when_fully_relayed &&
|
||||||
conn->local_candidate().type() == RELAY_PORT_TYPE &&
|
conn->local_candidate().is_relay() &&
|
||||||
(conn->remote_candidate().type() == RELAY_PORT_TYPE ||
|
(conn->remote_candidate().is_relay() ||
|
||||||
conn->remote_candidate().type() == PRFLX_PORT_TYPE));
|
conn->remote_candidate().is_prflx()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void P2PTransportChannel::UpdateState() {
|
void P2PTransportChannel::UpdateState() {
|
||||||
|
@ -1757,19 +1756,18 @@ bool P2PTransportChannel::PruneConnections(
|
||||||
rtc::NetworkRoute P2PTransportChannel::ConfigureNetworkRoute(
|
rtc::NetworkRoute P2PTransportChannel::ConfigureNetworkRoute(
|
||||||
const Connection* conn) {
|
const Connection* conn) {
|
||||||
RTC_DCHECK_RUN_ON(network_thread_);
|
RTC_DCHECK_RUN_ON(network_thread_);
|
||||||
return {
|
return {.connected = ReadyToSend(conn),
|
||||||
.connected = ReadyToSend(conn),
|
.local = CreateRouteEndpointFromCandidate(
|
||||||
.local = CreateRouteEndpointFromCandidate(
|
/* local= */ true, conn->local_candidate(),
|
||||||
/* local= */ true, conn->local_candidate(),
|
/* uses_turn= */
|
||||||
/* uses_turn= */
|
conn->port()->Type() == RELAY_PORT_TYPE),
|
||||||
conn->port()->Type() == RELAY_PORT_TYPE),
|
.remote = CreateRouteEndpointFromCandidate(
|
||||||
.remote = CreateRouteEndpointFromCandidate(
|
/* local= */ false, conn->remote_candidate(),
|
||||||
/* local= */ false, conn->remote_candidate(),
|
/* uses_turn= */ conn->remote_candidate().is_relay()),
|
||||||
/* uses_turn= */ conn->remote_candidate().type() == RELAY_PORT_TYPE),
|
.last_sent_packet_id = last_sent_packet_id_,
|
||||||
.last_sent_packet_id = last_sent_packet_id_,
|
.packet_overhead =
|
||||||
.packet_overhead =
|
conn->local_candidate().address().ipaddr().overhead() +
|
||||||
conn->local_candidate().address().ipaddr().overhead() +
|
GetProtocolOverhead(conn->local_candidate().protocol())};
|
||||||
GetProtocolOverhead(conn->local_candidate().protocol())};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void P2PTransportChannel::SwitchSelectedConnection(
|
void P2PTransportChannel::SwitchSelectedConnection(
|
||||||
|
@ -2280,7 +2278,7 @@ Candidate P2PTransportChannel::SanitizeRemoteCandidate(
|
||||||
bool use_hostname_address = absl::EndsWith(c.address().hostname(), LOCAL_TLD);
|
bool use_hostname_address = absl::EndsWith(c.address().hostname(), LOCAL_TLD);
|
||||||
// Remove the address for prflx remote candidates. See
|
// Remove the address for prflx remote candidates. See
|
||||||
// https://w3c.github.io/webrtc-stats/#dom-rtcicecandidatestats.
|
// 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,
|
return c.ToSanitizedCopy(use_hostname_address,
|
||||||
false /* filter_related_address */);
|
false /* filter_related_address */);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5008,7 +5008,7 @@ class P2PTransportChannelMostLikelyToWorkFirstTest
|
||||||
Connection* conn = FindNextPingableConnectionAndPingIt(channel_.get());
|
Connection* conn = FindNextPingableConnectionAndPingIt(channel_.get());
|
||||||
ASSERT_TRUE(conn != nullptr);
|
ASSERT_TRUE(conn != nullptr);
|
||||||
EXPECT_EQ(conn->local_candidate().type(), local_candidate_type);
|
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->local_candidate().relay_protocol(), relay_protocol_type);
|
||||||
}
|
}
|
||||||
EXPECT_EQ(conn->remote_candidate().type(), remote_candidate_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_) {
|
for (const auto& candidates_data : GetEndpoint(0)->saved_candidates_) {
|
||||||
const auto& local_candidate_ep1 = candidates_data.candidate;
|
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,
|
// This is the underlying private IP address of the same candidate at ep1,
|
||||||
// and let the mock resolver of ep2 receive the correct resolution.
|
// and let the mock resolver of ep2 receive the correct resolution.
|
||||||
rtc::SocketAddress resolved_address_ep1(local_candidate_ep1.address());
|
rtc::SocketAddress resolved_address_ep1(local_candidate_ep1.address());
|
||||||
|
@ -5449,11 +5449,11 @@ TEST_F(P2PTransportChannelTest,
|
||||||
// Check the stats of ep1 seen by ep1.
|
// Check the stats of ep1 seen by ep1.
|
||||||
for (const auto& connection_info : ice_transport_stats1.connection_infos) {
|
for (const auto& connection_info : ice_transport_stats1.connection_infos) {
|
||||||
const auto& local_candidate = connection_info.local_candidate;
|
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());
|
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());
|
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
|
// The related address of the relay candidate should be equal to the
|
||||||
// srflx address. Note that NAT is not configured, hence the following
|
// srflx address. Note that NAT is not configured, hence the following
|
||||||
// expectation.
|
// expectation.
|
||||||
|
@ -5466,11 +5466,11 @@ TEST_F(P2PTransportChannelTest,
|
||||||
// Check the stats of ep1 seen by ep2.
|
// Check the stats of ep1 seen by ep2.
|
||||||
for (const auto& connection_info : ice_transport_stats2.connection_infos) {
|
for (const auto& connection_info : ice_transport_stats2.connection_infos) {
|
||||||
const auto& remote_candidate = connection_info.remote_candidate;
|
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());
|
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());
|
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(),
|
EXPECT_EQ(kPublicAddrs[0].ipaddr(),
|
||||||
remote_candidate.related_address().ipaddr());
|
remote_candidate.related_address().ipaddr());
|
||||||
} else {
|
} else {
|
||||||
|
@ -5592,7 +5592,7 @@ TEST_F(P2PTransportChannelTest,
|
||||||
ASSERT_EQ_WAIT(1u, GetEndpoint(0)->saved_candidates_.size(), kMediumTimeout);
|
ASSERT_EQ_WAIT(1u, GetEndpoint(0)->saved_candidates_.size(), kMediumTimeout);
|
||||||
const auto& candidates_data = GetEndpoint(0)->saved_candidates_[0];
|
const auto& candidates_data = GetEndpoint(0)->saved_candidates_[0];
|
||||||
const auto& local_candidate_ep1 = candidates_data.candidate;
|
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,
|
// This is the underlying private IP address of the same candidate at ep1,
|
||||||
// and let the mock resolver of ep2 receive the correct resolution.
|
// and let the mock resolver of ep2 receive the correct resolution.
|
||||||
rtc::SocketAddress resolved_address_ep1(local_candidate_ep1.address());
|
rtc::SocketAddress resolved_address_ep1(local_candidate_ep1.address());
|
||||||
|
@ -5608,12 +5608,12 @@ TEST_F(P2PTransportChannelTest,
|
||||||
|
|
||||||
const auto pair_ep1 = ep1_ch1()->GetSelectedCandidatePair();
|
const auto pair_ep1 = ep1_ch1()->GetSelectedCandidatePair();
|
||||||
ASSERT_TRUE(pair_ep1.has_value());
|
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());
|
EXPECT_TRUE(pair_ep1->local_candidate().address().IsUnresolvedIP());
|
||||||
|
|
||||||
const auto pair_ep2 = ep2_ch1()->GetSelectedCandidatePair();
|
const auto pair_ep2 = ep2_ch1()->GetSelectedCandidatePair();
|
||||||
ASSERT_TRUE(pair_ep2.has_value());
|
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());
|
EXPECT_TRUE(pair_ep2->remote_candidate().address().IsUnresolvedIP());
|
||||||
|
|
||||||
DestroyChannels();
|
DestroyChannels();
|
||||||
|
|
|
@ -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
|
// For a local host candidate, we need to conceal its IP address candidate if
|
||||||
// the mDNS obfuscation is enabled.
|
// the mDNS obfuscation is enabled.
|
||||||
bool use_hostname_address =
|
bool use_hostname_address =
|
||||||
(c.type() == LOCAL_PORT_TYPE || c.type() == PRFLX_PORT_TYPE) &&
|
(c.is_local() || c.is_prflx()) && MdnsObfuscationEnabled();
|
||||||
MdnsObfuscationEnabled();
|
|
||||||
// If adapter enumeration is disabled or host candidates are disabled,
|
// If adapter enumeration is disabled or host candidates are disabled,
|
||||||
// clear the raddr of STUN candidates to avoid local address leakage.
|
// clear the raddr of STUN candidates to avoid local address leakage.
|
||||||
bool filter_stun_related_address =
|
bool filter_stun_related_address =
|
||||||
|
@ -326,9 +325,9 @@ Candidate PortAllocator::SanitizeCandidate(const Candidate& c) const {
|
||||||
// Sanitize related_address when using MDNS.
|
// Sanitize related_address when using MDNS.
|
||||||
bool filter_prflx_related_address = MdnsObfuscationEnabled();
|
bool filter_prflx_related_address = MdnsObfuscationEnabled();
|
||||||
bool filter_related_address =
|
bool filter_related_address =
|
||||||
((c.type() == STUN_PORT_TYPE && filter_stun_related_address) ||
|
((c.is_stun() && filter_stun_related_address) ||
|
||||||
(c.type() == RELAY_PORT_TYPE && filter_turn_related_address) ||
|
(c.is_relay() && filter_turn_related_address) ||
|
||||||
(c.type() == PRFLX_PORT_TYPE && filter_prflx_related_address));
|
(c.is_prflx() && filter_prflx_related_address));
|
||||||
return c.ToSanitizedCopy(use_hostname_address, filter_related_address);
|
return c.ToSanitizedCopy(use_hostname_address, filter_related_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -285,7 +285,7 @@ Connection* UDPPort::CreateConnection(const Candidate& address,
|
||||||
//
|
//
|
||||||
// See also the definition of MdnsNameRegistrationStatus::kNotStarted in
|
// See also the definition of MdnsNameRegistrationStatus::kNotStarted in
|
||||||
// port.h.
|
// port.h.
|
||||||
RTC_DCHECK(!SharedSocket() || Candidates()[0].type() == LOCAL_PORT_TYPE ||
|
RTC_DCHECK(!SharedSocket() || Candidates()[0].is_local() ||
|
||||||
mdns_name_registration_status() !=
|
mdns_name_registration_status() !=
|
||||||
MdnsNameRegistrationStatus::kNotStarted);
|
MdnsNameRegistrationStatus::kNotStarted);
|
||||||
|
|
||||||
|
@ -616,7 +616,7 @@ bool UDPPort::HasStunCandidateWithAddress(
|
||||||
const std::vector<Candidate>& existing_candidates = Candidates();
|
const std::vector<Candidate>& existing_candidates = Candidates();
|
||||||
std::vector<Candidate>::const_iterator it = existing_candidates.begin();
|
std::vector<Candidate>::const_iterator it = existing_candidates.begin();
|
||||||
for (; it != existing_candidates.end(); ++it) {
|
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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -445,11 +445,11 @@ TEST_F(StunPortTest, TestStunCandidateGeneratedWithMdnsObfuscationEnabled) {
|
||||||
// One of the generated candidates is a local candidate and the other is a
|
// One of the generated candidates is a local candidate and the other is a
|
||||||
// stun candidate.
|
// stun candidate.
|
||||||
EXPECT_NE(port()->Candidates()[0].type(), port()->Candidates()[1].type());
|
EXPECT_NE(port()->Candidates()[0].type(), port()->Candidates()[1].type());
|
||||||
if (port()->Candidates()[0].type() == cricket::LOCAL_PORT_TYPE) {
|
if (port()->Candidates()[0].is_local()) {
|
||||||
EXPECT_EQ(port()->Candidates()[1].type(), cricket::STUN_PORT_TYPE);
|
EXPECT_TRUE(port()->Candidates()[1].is_stun());
|
||||||
} else {
|
} else {
|
||||||
EXPECT_EQ(port()->Candidates()[0].type(), cricket::STUN_PORT_TYPE);
|
EXPECT_TRUE(port()->Candidates()[0].is_stun());
|
||||||
EXPECT_EQ(port()->Candidates()[1].type(), cricket::LOCAL_PORT_TYPE);
|
EXPECT_TRUE(port()->Candidates()[1].is_local());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -585,9 +585,8 @@ Connection* TurnPort::CreateConnection(const Candidate& remote_candidate,
|
||||||
// and TURN candidate later.
|
// and TURN candidate later.
|
||||||
for (size_t index = 0; index < Candidates().size(); ++index) {
|
for (size_t index = 0; index < Candidates().size(); ++index) {
|
||||||
const Candidate& local_candidate = Candidates()[index];
|
const Candidate& local_candidate = Candidates()[index];
|
||||||
if (local_candidate.type() == RELAY_PORT_TYPE &&
|
if (local_candidate.is_relay() && local_candidate.address().family() ==
|
||||||
local_candidate.address().family() ==
|
remote_candidate.address().family()) {
|
||||||
remote_candidate.address().family()) {
|
|
||||||
ProxyConnection* conn =
|
ProxyConnection* conn =
|
||||||
new ProxyConnection(NewWeakPtr(), index, remote_candidate);
|
new ProxyConnection(NewWeakPtr(), index, remote_candidate);
|
||||||
// Create an entry, if needed, so we can get our permissions set up
|
// Create an entry, if needed, so we can get our permissions set up
|
||||||
|
|
|
@ -126,11 +126,15 @@ bool IsAllowedByCandidateFilter(const Candidate& c, uint32_t filter) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c.type() == RELAY_PORT_TYPE) {
|
if (c.is_relay()) {
|
||||||
return ((filter & CF_RELAY) != 0);
|
return ((filter & CF_RELAY) != 0);
|
||||||
} else if (c.type() == STUN_PORT_TYPE) {
|
}
|
||||||
|
|
||||||
|
if (c.is_stun()) {
|
||||||
return ((filter & CF_REFLEXIVE) != 0);
|
return ((filter & CF_REFLEXIVE) != 0);
|
||||||
} else if (c.type() == LOCAL_PORT_TYPE) {
|
}
|
||||||
|
|
||||||
|
if (c.is_local()) {
|
||||||
if ((filter & CF_REFLEXIVE) && !c.address().IsPrivateIP()) {
|
if ((filter & CF_REFLEXIVE) && !c.address().IsPrivateIP()) {
|
||||||
// We allow host candidates if the filter allows server-reflexive
|
// We allow host candidates if the filter allows server-reflexive
|
||||||
// candidates and the candidate is a public IP. Because we don't generate
|
// 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 ((filter & CF_HOST) != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2417,7 +2417,7 @@ TEST_F(BasicPortAllocatorTest, HostCandidateAddressIsReplacedByHostname) {
|
||||||
for (const auto& candidate : candidates_) {
|
for (const auto& candidate : candidates_) {
|
||||||
const auto& raddr = candidate.related_address();
|
const auto& raddr = candidate.related_address();
|
||||||
|
|
||||||
if (candidate.type() == LOCAL_PORT_TYPE) {
|
if (candidate.is_local()) {
|
||||||
EXPECT_FALSE(candidate.address().hostname().empty());
|
EXPECT_FALSE(candidate.address().hostname().empty());
|
||||||
EXPECT_TRUE(raddr.IsNil());
|
EXPECT_TRUE(raddr.IsNil());
|
||||||
if (candidate.protocol() == UDP_PROTOCOL_NAME) {
|
if (candidate.protocol() == UDP_PROTOCOL_NAME) {
|
||||||
|
@ -2425,13 +2425,13 @@ TEST_F(BasicPortAllocatorTest, HostCandidateAddressIsReplacedByHostname) {
|
||||||
} else {
|
} else {
|
||||||
++num_host_tcp_candidates;
|
++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
|
// For a srflx candidate, the related address should be set to 0.0.0.0 or
|
||||||
// ::0
|
// ::0
|
||||||
EXPECT_TRUE(IPIsAny(raddr.ipaddr()));
|
EXPECT_TRUE(IPIsAny(raddr.ipaddr()));
|
||||||
EXPECT_EQ(raddr.port(), 0);
|
EXPECT_EQ(raddr.port(), 0);
|
||||||
++num_srflx_candidates;
|
++num_srflx_candidates;
|
||||||
} else if (candidate.type() == RELAY_PORT_TYPE) {
|
} else if (candidate.is_relay()) {
|
||||||
EXPECT_EQ(kNatUdpAddr.ipaddr(), raddr.ipaddr());
|
EXPECT_EQ(kNatUdpAddr.ipaddr(), raddr.ipaddr());
|
||||||
EXPECT_EQ(kNatUdpAddr.family(), raddr.family());
|
EXPECT_EQ(kNatUdpAddr.family(), raddr.family());
|
||||||
++num_relay_candidates;
|
++num_relay_candidates;
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include "rtc_base/net_helper.h"
|
#include "rtc_base/net_helper.h"
|
||||||
#include "rtc_base/socket_address.h"
|
#include "rtc_base/socket_address.h"
|
||||||
|
|
||||||
|
using cricket::Candidate;
|
||||||
using cricket::SessionDescription;
|
using cricket::SessionDescription;
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
@ -43,13 +44,13 @@ constexpr int kPreferenceRelayed = 3;
|
||||||
constexpr char kDummyAddress[] = "0.0.0.0";
|
constexpr char kDummyAddress[] = "0.0.0.0";
|
||||||
constexpr int kDummyPort = 9;
|
constexpr int kDummyPort = 9;
|
||||||
|
|
||||||
int GetCandidatePreferenceFromType(const std::string& type) {
|
int GetCandidatePreferenceFromType(const Candidate& c) {
|
||||||
int preference = kPreferenceUnknown;
|
int preference = kPreferenceUnknown;
|
||||||
if (type == cricket::LOCAL_PORT_TYPE) {
|
if (c.is_local()) {
|
||||||
preference = kPreferenceHost;
|
preference = kPreferenceHost;
|
||||||
} else if (type == cricket::STUN_PORT_TYPE) {
|
} else if (c.is_stun()) {
|
||||||
preference = kPreferenceReflexive;
|
preference = kPreferenceReflexive;
|
||||||
} else if (type == cricket::RELAY_PORT_TYPE) {
|
} else if (c.is_relay()) {
|
||||||
preference = kPreferenceRelayed;
|
preference = kPreferenceRelayed;
|
||||||
} else {
|
} else {
|
||||||
preference = kPreferenceUnknown;
|
preference = kPreferenceUnknown;
|
||||||
|
@ -78,7 +79,7 @@ void UpdateConnectionAddress(
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const int preference =
|
const int preference =
|
||||||
GetCandidatePreferenceFromType(jsep_candidate->candidate().type());
|
GetCandidatePreferenceFromType(jsep_candidate->candidate());
|
||||||
const int family = jsep_candidate->candidate().address().ipaddr().family();
|
const int family = jsep_candidate->candidate().address().ipaddr().family();
|
||||||
// See if this candidate is more preferable then the current one if it's the
|
// 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
|
// same family. Or if the current family is IPv4 already so we could safely
|
||||||
|
@ -253,7 +254,7 @@ bool JsepSessionDescription::AddCandidate(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cricket::Candidate updated_candidate = candidate->candidate();
|
Candidate updated_candidate = candidate->candidate();
|
||||||
if (updated_candidate.username().empty()) {
|
if (updated_candidate.username().empty()) {
|
||||||
updated_candidate.set_username(transport_info->description.ice_ufrag);
|
updated_candidate.set_username(transport_info->description.ice_ufrag);
|
||||||
}
|
}
|
||||||
|
@ -278,7 +279,7 @@ bool JsepSessionDescription::AddCandidate(
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t JsepSessionDescription::RemoveCandidates(
|
size_t JsepSessionDescription::RemoveCandidates(
|
||||||
const std::vector<cricket::Candidate>& candidates) {
|
const std::vector<Candidate>& candidates) {
|
||||||
size_t num_removed = 0;
|
size_t num_removed = 0;
|
||||||
for (auto& candidate : candidates) {
|
for (auto& candidate : candidates) {
|
||||||
int mediasection_index = GetMediasectionIndex(candidate);
|
int mediasection_index = GetMediasectionIndex(candidate);
|
||||||
|
@ -352,8 +353,7 @@ bool JsepSessionDescription::GetMediasectionIndex(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int JsepSessionDescription::GetMediasectionIndex(
|
int JsepSessionDescription::GetMediasectionIndex(const Candidate& candidate) {
|
||||||
const cricket::Candidate& candidate) {
|
|
||||||
// Find the description with a matching transport name of the candidate.
|
// Find the description with a matching transport name of the candidate.
|
||||||
const std::string& transport_name = candidate.transport_name();
|
const std::string& transport_name = candidate.transport_name();
|
||||||
for (size_t i = 0; i < description_->contents().size(); ++i) {
|
for (size_t i = 0; i < description_->contents().size(); ++i) {
|
||||||
|
|
|
@ -496,17 +496,17 @@ void ExtractStatsFromList(
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
const char* IceCandidateTypeToStatsType(const std::string& candidate_type) {
|
const char* IceCandidateTypeToStatsType(const cricket::Candidate& candidate) {
|
||||||
if (candidate_type == cricket::LOCAL_PORT_TYPE) {
|
if (candidate.is_local()) {
|
||||||
return STATSREPORT_LOCAL_PORT_TYPE;
|
return STATSREPORT_LOCAL_PORT_TYPE;
|
||||||
}
|
}
|
||||||
if (candidate_type == cricket::STUN_PORT_TYPE) {
|
if (candidate.is_stun()) {
|
||||||
return STATSREPORT_STUN_PORT_TYPE;
|
return STATSREPORT_STUN_PORT_TYPE;
|
||||||
}
|
}
|
||||||
if (candidate_type == cricket::PRFLX_PORT_TYPE) {
|
if (candidate.is_prflx()) {
|
||||||
return STATSREPORT_PRFLX_PORT_TYPE;
|
return STATSREPORT_PRFLX_PORT_TYPE;
|
||||||
}
|
}
|
||||||
if (candidate_type == cricket::RELAY_PORT_TYPE) {
|
if (candidate.is_relay()) {
|
||||||
return STATSREPORT_RELAY_PORT_TYPE;
|
return STATSREPORT_RELAY_PORT_TYPE;
|
||||||
}
|
}
|
||||||
RTC_DCHECK_NOTREACHED();
|
RTC_DCHECK_NOTREACHED();
|
||||||
|
@ -844,7 +844,7 @@ StatsReport* LegacyStatsCollector::AddCandidateReport(
|
||||||
report->AddInt(StatsReport::kStatsValueNameCandidatePriority,
|
report->AddInt(StatsReport::kStatsValueNameCandidatePriority,
|
||||||
candidate.priority());
|
candidate.priority());
|
||||||
report->AddString(StatsReport::kStatsValueNameCandidateType,
|
report->AddString(StatsReport::kStatsValueNameCandidateType,
|
||||||
IceCandidateTypeToStatsType(candidate.type()));
|
IceCandidateTypeToStatsType(candidate));
|
||||||
report->AddString(StatsReport::kStatsValueNameCandidateTransportType,
|
report->AddString(StatsReport::kStatsValueNameCandidateTransportType,
|
||||||
candidate.protocol());
|
candidate.protocol());
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "absl/types/optional.h"
|
#include "absl/types/optional.h"
|
||||||
|
#include "api/candidate.h"
|
||||||
#include "api/field_trials_view.h"
|
#include "api/field_trials_view.h"
|
||||||
#include "api/legacy_stats_types.h"
|
#include "api/legacy_stats_types.h"
|
||||||
#include "api/media_stream_interface.h"
|
#include "api/media_stream_interface.h"
|
||||||
|
@ -45,7 +46,7 @@ namespace webrtc {
|
||||||
|
|
||||||
// Conversion function to convert candidate type string to the corresponding one
|
// Conversion function to convert candidate type string to the corresponding one
|
||||||
// from enum RTCStatsIceCandidateType.
|
// 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
|
// 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
|
// fitting to the general style of http://w3c.github.io/webrtc-stats. This is
|
||||||
|
|
|
@ -1391,7 +1391,7 @@ TEST_F(LegacyStatsCollectorTest, IceCandidateReport) {
|
||||||
ExtractStatsValue(StatsReport::kStatsReportTypeIceLocalCandidate, reports,
|
ExtractStatsValue(StatsReport::kStatsReportTypeIceLocalCandidate, reports,
|
||||||
StatsReport::kStatsValueNameCandidatePriority));
|
StatsReport::kStatsValueNameCandidatePriority));
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(
|
||||||
IceCandidateTypeToStatsType(cricket::LOCAL_PORT_TYPE),
|
IceCandidateTypeToStatsType(local),
|
||||||
ExtractStatsValue(StatsReport::kStatsReportTypeIceLocalCandidate, reports,
|
ExtractStatsValue(StatsReport::kStatsReportTypeIceLocalCandidate, reports,
|
||||||
StatsReport::kStatsValueNameCandidateType));
|
StatsReport::kStatsValueNameCandidateType));
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(
|
||||||
|
@ -1421,7 +1421,7 @@ TEST_F(LegacyStatsCollectorTest, IceCandidateReport) {
|
||||||
reports,
|
reports,
|
||||||
StatsReport::kStatsValueNameCandidatePriority));
|
StatsReport::kStatsValueNameCandidatePriority));
|
||||||
EXPECT_EQ(
|
EXPECT_EQ(
|
||||||
IceCandidateTypeToStatsType(cricket::PRFLX_PORT_TYPE),
|
IceCandidateTypeToStatsType(remote),
|
||||||
ExtractStatsValue(StatsReport::kStatsReportTypeIceRemoteCandidate,
|
ExtractStatsValue(StatsReport::kStatsReportTypeIceRemoteCandidate,
|
||||||
reports, StatsReport::kStatsValueNameCandidateType));
|
reports, StatsReport::kStatsValueNameCandidateType));
|
||||||
EXPECT_EQ(kNotFound,
|
EXPECT_EQ(kNotFound,
|
||||||
|
|
|
@ -164,14 +164,14 @@ std::string RTCMediaSourceStatsIDFromKindAndAttachment(
|
||||||
return sb.str();
|
return sb.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* CandidateTypeToRTCIceCandidateType(const std::string& type) {
|
const char* CandidateTypeToRTCIceCandidateType(const cricket::Candidate& c) {
|
||||||
if (type == cricket::LOCAL_PORT_TYPE)
|
if (c.is_local())
|
||||||
return "host";
|
return "host";
|
||||||
if (type == cricket::STUN_PORT_TYPE)
|
if (c.is_stun())
|
||||||
return "srflx";
|
return "srflx";
|
||||||
if (type == cricket::PRFLX_PORT_TYPE)
|
if (c.is_prflx())
|
||||||
return "prflx";
|
return "prflx";
|
||||||
if (type == cricket::RELAY_PORT_TYPE)
|
if (c.is_relay())
|
||||||
return "relay";
|
return "relay";
|
||||||
RTC_DCHECK_NOTREACHED();
|
RTC_DCHECK_NOTREACHED();
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -1001,7 +1001,7 @@ const std::string& ProduceIceCandidateStats(Timestamp timestamp,
|
||||||
candidate_stats->port = static_cast<int32_t>(candidate.address().port());
|
candidate_stats->port = static_cast<int32_t>(candidate.address().port());
|
||||||
candidate_stats->protocol = candidate.protocol();
|
candidate_stats->protocol = candidate.protocol();
|
||||||
candidate_stats->candidate_type =
|
candidate_stats->candidate_type =
|
||||||
CandidateTypeToRTCIceCandidateType(candidate.type());
|
CandidateTypeToRTCIceCandidateType(candidate);
|
||||||
candidate_stats->priority = static_cast<int32_t>(candidate.priority());
|
candidate_stats->priority = static_cast<int32_t>(candidate.priority());
|
||||||
candidate_stats->foundation = candidate.foundation();
|
candidate_stats->foundation = candidate.foundation();
|
||||||
auto related_address = candidate.related_address();
|
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
|
} // namespace webrtc
|
||||||
|
|
|
@ -322,11 +322,6 @@ class RTCStatsCollector : public rtc::RefCountInterface {
|
||||||
InternalRecord internal_record_;
|
InternalRecord internal_record_;
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* CandidateTypeToRTCIceCandidateTypeForTesting(
|
|
||||||
const std::string& type);
|
|
||||||
const char* DataStateToRTCDataChannelStateForTesting(
|
|
||||||
DataChannelInterface::DataState state);
|
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
||||||
#endif // PC_RTC_STATS_COLLECTOR_H_
|
#endif // PC_RTC_STATS_COLLECTOR_H_
|
||||||
|
|
|
@ -1115,7 +1115,7 @@ class PeerConnectionIntegrationWrapper : public PeerConnectionObserver,
|
||||||
if (remote_async_dns_resolver_) {
|
if (remote_async_dns_resolver_) {
|
||||||
const auto& local_candidate = candidate->candidate();
|
const auto& local_candidate = candidate->candidate();
|
||||||
if (local_candidate.address().IsUnresolvedIP()) {
|
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(
|
const auto resolved_ip = mdns_responder_->GetMappedAddressForName(
|
||||||
local_candidate.address().hostname());
|
local_candidate.address().hostname());
|
||||||
RTC_DCHECK(!resolved_ip.IsNil());
|
RTC_DCHECK(!resolved_ip.IsNil());
|
||||||
|
|
|
@ -771,13 +771,13 @@ static const int kPreferenceHost = 1;
|
||||||
static const int kPreferenceReflexive = 2;
|
static const int kPreferenceReflexive = 2;
|
||||||
static const int kPreferenceRelayed = 3;
|
static const int kPreferenceRelayed = 3;
|
||||||
|
|
||||||
static int GetCandidatePreferenceFromType(absl::string_view type) {
|
static int GetCandidatePreferenceFromType(const Candidate& candidate) {
|
||||||
int preference = kPreferenceUnknown;
|
int preference = kPreferenceUnknown;
|
||||||
if (type == cricket::LOCAL_PORT_TYPE) {
|
if (candidate.is_local()) {
|
||||||
preference = kPreferenceHost;
|
preference = kPreferenceHost;
|
||||||
} else if (type == cricket::STUN_PORT_TYPE) {
|
} else if (candidate.is_stun()) {
|
||||||
preference = kPreferenceReflexive;
|
preference = kPreferenceReflexive;
|
||||||
} else if (type == cricket::RELAY_PORT_TYPE) {
|
} else if (candidate.is_relay()) {
|
||||||
preference = kPreferenceRelayed;
|
preference = kPreferenceRelayed;
|
||||||
} else {
|
} else {
|
||||||
RTC_DCHECK_NOTREACHED();
|
RTC_DCHECK_NOTREACHED();
|
||||||
|
@ -810,7 +810,7 @@ static void GetDefaultDestination(const std::vector<Candidate>& candidates,
|
||||||
if (candidate.protocol() != cricket::UDP_PROTOCOL_NAME) {
|
if (candidate.protocol() != cricket::UDP_PROTOCOL_NAME) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const int preference = GetCandidatePreferenceFromType(candidate.type());
|
const int preference = GetCandidatePreferenceFromType(candidate);
|
||||||
const int family = candidate.address().ipaddr().family();
|
const int family = candidate.address().ipaddr().family();
|
||||||
// See if this candidate is more preferable then the current one if it's the
|
// 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
|
// same family. Or if the current family is IPv4 already so we could safely
|
||||||
|
@ -2005,13 +2005,13 @@ void BuildCandidate(const std::vector<Candidate>& candidates,
|
||||||
// *(SP extension-att-name SP extension-att-value)
|
// *(SP extension-att-name SP extension-att-value)
|
||||||
std::string type;
|
std::string type;
|
||||||
// Map the cricket candidate type to "host" / "srflx" / "prflx" / "relay"
|
// Map the cricket candidate type to "host" / "srflx" / "prflx" / "relay"
|
||||||
if (candidate.type() == cricket::LOCAL_PORT_TYPE) {
|
if (candidate.is_local()) {
|
||||||
type = kCandidateHost;
|
type = kCandidateHost;
|
||||||
} else if (candidate.type() == cricket::STUN_PORT_TYPE) {
|
} else if (candidate.is_stun()) {
|
||||||
type = kCandidateSrflx;
|
type = kCandidateSrflx;
|
||||||
} else if (candidate.type() == cricket::RELAY_PORT_TYPE) {
|
} else if (candidate.is_relay()) {
|
||||||
type = kCandidateRelay;
|
type = kCandidateRelay;
|
||||||
} else if (candidate.type() == cricket::PRFLX_PORT_TYPE) {
|
} else if (candidate.is_prflx()) {
|
||||||
type = kCandidatePrflx;
|
type = kCandidatePrflx;
|
||||||
// Peer reflexive candidate may be signaled for being removed.
|
// Peer reflexive candidate may be signaled for being removed.
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue